Skip to content

Commit

Permalink
chore: fix bootnodes handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Jan 16, 2024
1 parent d972609 commit 4d2458d
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions dot/sync/chain_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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()
}
Expand Down

0 comments on commit 4d2458d

Please sign in to comment.