From 4d2458d75a1ae3dfd0a9159ff09409ff4c53c42b Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Tue, 16 Jan 2024 16:55:02 -0400 Subject: [PATCH] chore: fix bootnodes handshake --- dot/sync/chain_sync.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/dot/sync/chain_sync.go b/dot/sync/chain_sync.go index 0deaedb441..17a6a587ad 100644 --- a/dot/sync/chain_sync.go +++ b/dot/sync/chain_sync.go @@ -169,18 +169,14 @@ func newChainSync(cfg chainSyncConfig) *chainSync { } } -func (cs *chainSync) retrieveTargetFromBootnodes() error { +func (cs *chainSync) waitWorkersAndTarget() { + waitPeersTimer := time.NewTimer(cs.waitPeersDuration) + highestFinalizedHeader, err := cs.blockState.GetHighestFinalisedHeader() if err != nil { - return err + panic(fmt.Sprintf("failed to get highest finalised header: %v", err)) } - return cs.network.BlockAnnounceHandshake(highestFinalizedHeader) -} - -func (cs *chainSync) waitWorkersAndTarget() { - waitPeersTimer := time.NewTimer(cs.waitPeersDuration) - for { cs.workerPool.useConnectedPeers() totalAvailable := cs.workerPool.totalWorkers() @@ -190,6 +186,11 @@ func (cs *chainSync) waitWorkersAndTarget() { return } + err := cs.network.BlockAnnounceHandshake(highestFinalizedHeader) + if err != nil && !errors.Is(err, network.ErrNoPeersConnected) { + logger.Errorf("retrieving target info from peers: %v", err) + } + select { case <-waitPeersTimer.C: waitPeersTimer.Reset(cs.waitPeersDuration) @@ -207,11 +208,6 @@ func (cs *chainSync) start() { cs.wg.Add(1) go cs.pendingBlocks.run(cs.finalisedCh, cs.stopCh, &cs.wg) - err := cs.retrieveTargetFromBootnodes() - if err != nil { - logger.Errorf("failed retrieve target from bootnodes: %v", err) - } - // wait until we have a minimal workers in the sync worker pool cs.waitWorkersAndTarget() }