From 9be5b9e1637ba8943f979f177c33001fa7abaa2e Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Thu, 19 Sep 2019 15:40:16 -0700 Subject: [PATCH] Verify sig every 100 blocks during state sync --- api/service/syncing/syncing.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/service/syncing/syncing.go b/api/service/syncing/syncing.go index fe62b30aa..da808a02b 100644 --- a/api/service/syncing/syncing.go +++ b/api/service/syncing/syncing.go @@ -546,9 +546,18 @@ func (ss *StateSync) updateBlockAndStatus(block *types.Block, bc *core.BlockChai // Verify block signatures // TODO chao: only when block is verified against last commit sigs, we can update the block and status if block.NumberU64() > 1 { - err := bc.Engine().VerifyHeader(bc, block.Header(), true) + verifySig := false + if block.NumberU64()%100 == 0 { + // Verify signature every 100 blocks + verifySig = true + } + err := bc.Engine().VerifyHeader(bc, block.Header(), verifySig) if err != nil { utils.Logger().Error().Err(err).Msgf("[SYNC] failed verifying signatures for new block %d", block.NumberU64()) + utils.Logger().Debug().Interface("block", bc.CurrentBlock()).Msg("[SYNC] Rolling back last 99 blocks!") + for i := 0; i < 99; i++ { + bc.Rollback([]common.Hash{bc.CurrentBlock().Hash()}) + } return false } }