Skip to content

Commit c0bc141

Browse files
authored
fix(node): race on caught up (#3133)
feat: add `Syncer.PendingCount` and use it to ensure the sync pipeline is drained before marking the node as caught up in failover.
1 parent 2c75e9e commit c0bc141

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

block/internal/syncing/syncer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ func (s *Syncer) fetchDAUntilCaughtUp(ctx context.Context) error {
467467
}
468468
}
469469

470+
// PendingCount returns the number of unprocessed height events in the pipeline.
471+
func (s *Syncer) PendingCount() int {
472+
return len(s.heightInCh)
473+
}
474+
470475
func (s *Syncer) pendingWorkerLoop(ctx context.Context) {
471476
defer s.wg.Done()
472477

node/failover.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ func (f *failoverState) waitForCatchup(ctx context.Context) (bool, error) {
315315
p2pCaughtUp = true
316316
}
317317

318-
if daCaughtUp && p2pCaughtUp {
318+
pipelineDrained := f.bc.Syncer == nil || f.bc.Syncer.PendingCount() == 0
319+
if daCaughtUp && p2pCaughtUp && pipelineDrained {
319320
f.logger.Info().
320321
Uint64("store_height", storeHeight).
321322
Uint64("max_p2p_height", maxP2PHeight).

0 commit comments

Comments
 (0)