diff --git a/spv/sync.go b/spv/sync.go index 6d23bd32f..5bbdcfda9 100644 --- a/spv/sync.go +++ b/spv/sync.go @@ -75,10 +75,6 @@ type Syncer struct { sidechains wallet.SidechainForest sidechainMu sync.Mutex - currentLocators []*chainhash.Hash - locatorGeneration uint - locatorMu sync.Mutex - // Holds all potential callbacks used to notify clients notifications *Notifications @@ -333,12 +329,6 @@ func (s *Syncer) Run(ctx context.Context) error { log.Infof("Transactions synced through block %v height %d", &tipHash, tipHeight) } - locators, err := s.wallet.BlockLocators(ctx, nil) - if err != nil { - return err - } - s.currentLocators = locators - s.lp.AddrManager().Start() defer func() { err := s.lp.AddrManager().Stop() @@ -1299,13 +1289,6 @@ func (s *Syncer) handleBlockAnnouncements(ctx context.Context, rp *p2p.RemotePee return err } - if len(bestChain) != 0 { - s.locatorMu.Lock() - s.currentLocators = nil - s.locatorGeneration++ - s.locatorMu.Unlock() - } - // Log connected blocks. for _, n := range bestChain { log.Infof("Connected block %v, height %d, %d wallet transaction(s)", @@ -1358,22 +1341,6 @@ var hashStop chainhash.Hash // getHeaders fetches headers from peers until the wallet is up to date with // all connected peers. This is part of the startup sync process. func (s *Syncer) getHeaders(ctx context.Context) error { - var locators []*chainhash.Hash - var generation uint - var err error - s.locatorMu.Lock() - locators = s.currentLocators - generation = s.locatorGeneration - if len(locators) == 0 { - locators, err = s.wallet.BlockLocators(ctx, nil) - if err != nil { - s.locatorMu.Unlock() - return err - } - s.currentLocators = locators - s.locatorGeneration++ - } - s.locatorMu.Unlock() cnet := s.wallet.ChainParams().Net @@ -1396,6 +1363,11 @@ nextbatch: return nil } + // Request headers from the selected peer. + locators, err := s.wallet.BlockLocators(ctx, nil) + if err != nil { + return err + } headers, err := rp.Headers(ctx, locators, &hashStop) if err != nil { continue nextbatch @@ -1502,21 +1474,6 @@ nextbatch: if added == 0 { s.sidechainMu.Unlock() - s.locatorMu.Lock() - if s.locatorGeneration > generation { - locators = s.currentLocators - } - if len(locators) == 0 { - locators, err = s.wallet.BlockLocators(ctx, nil) - if err != nil { - s.locatorMu.Unlock() - return err - } - s.currentLocators = locators - s.locatorGeneration++ - generation = s.locatorGeneration - } - s.locatorMu.Unlock() continue nextbatch } s.fetchHeadersProgress(headers[len(headers)-1]) @@ -1531,7 +1488,7 @@ nextbatch: } if len(bestChain) == 0 { s.sidechainMu.Unlock() - continue + continue nextbatch } prevChain, err := s.wallet.ChainSwitch(ctx, &s.sidechains, bestChain, nil) @@ -1561,17 +1518,6 @@ nextbatch: // Peers should not be significantly behind the new tip. s.setRequiredHeight(int32(tip.Header.Height)) s.disconnectStragglers(int32(tip.Header.Height)) - - // Generate new locators - s.locatorMu.Lock() - locators, err = s.wallet.BlockLocators(ctx, nil) - if err != nil { - s.locatorMu.Unlock() - return err - } - s.currentLocators = locators - s.locatorGeneration++ - s.locatorMu.Unlock() } return ctx.Err()