Skip to content

Commit

Permalink
fix(migrator): no wait if there is no gap between safe and unsafe blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangssu committed Dec 27, 2024
1 parent c2dc5a2 commit ee5728e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion migration/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,19 @@ func (m *StateMigrator) FinalizeTransition(transitionBlock types.Block) {
}

func (m *StateMigrator) waitForMigrationReady(target *types.Header) {
safe := m.backend.BlockChain().CurrentSafeBlock()
// There is no gap between the safe block and the unsafe block, no waiting is required.
if safe != nil && safe.Hash() == target.Hash() {
return
}

ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
// Wait until the given target block becomes a safe block.
safe := m.backend.BlockChain().CurrentSafeBlock()
safe = m.backend.BlockChain().CurrentSafeBlock()
if safe == nil || safe.Number.Uint64() < target.Number.Uint64() {
continue
}
Expand Down

0 comments on commit ee5728e

Please sign in to comment.