Fix block sync rollback logic

When block verification fails during syncing, the last 99 blocks are to
be rolled back.  Originally we called bc.Rollback() once for each block
being rolled back; a change introduced in e75b4a4 tried to batch this by
calling bc.Rollback() once with 99 hashes, but the hash list
construction had a bug which caused the same tip hash to be added 99
times, instead of the last 99 hashes.

Revert to the old logic, which at least functions correctly, albeit
slower than batched rollback.
pull/1920/head
Eugene Kim 5 years ago
parent b73b4c008c
commit 470018e7a0
  1. 4
      api/service/syncing/syncing.go

@ -545,11 +545,9 @@ func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc *core.BlockChai
utils.Logger().Error().Err(err).Msgf("[SYNC] UpdateBlockAndStatus: failed verifying signatures for new block %d", block.NumberU64()) utils.Logger().Error().Err(err).Msgf("[SYNC] UpdateBlockAndStatus: failed verifying signatures for new block %d", block.NumberU64())
utils.Logger().Debug().Interface("block", bc.CurrentBlock()).Msg("[SYNC] UpdateBlockAndStatus: Rolling back last 99 blocks!") utils.Logger().Debug().Interface("block", bc.CurrentBlock()).Msg("[SYNC] UpdateBlockAndStatus: Rolling back last 99 blocks!")
var hashes []common.Hash
for i := uint64(0); i < verifyHeaderBatchSize-1; i++ { for i := uint64(0); i < verifyHeaderBatchSize-1; i++ {
hashes = append(hashes, bc.CurrentBlock().Hash()) bc.Rollback([]common.Hash{bc.CurrentBlock().Hash()})
} }
bc.Rollback(hashes)
return err return err
} }
} }

Loading…
Cancel
Save