Skip to content

Commit

Permalink
Force verify all sign. (#4601)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozen authored Jan 10, 2024
1 parent 50a1a75 commit f576910
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions api/service/legacysync/syncing.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,11 +860,12 @@ func (ss *StateSync) getBlockFromLastMileBlocksByParentHash(parentHash common.Ha
}

// UpdateBlockAndStatus ...
func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain, verifyAllSig bool) error {
func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain) error {
if block.NumberU64() != bc.CurrentBlock().NumberU64()+1 {
utils.Logger().Debug().Uint64("curBlockNum", bc.CurrentBlock().NumberU64()).Uint64("receivedBlockNum", block.NumberU64()).Msg("[SYNC] Inappropriate block number, ignore!")
return nil
}
verifyAllSig := true

haveCurrentSig := len(block.GetCurrentCommitSig()) != 0
// Verify block signatures
Expand Down Expand Up @@ -954,8 +955,8 @@ func (ss *StateSync) generateNewState(bc core.BlockChain) error {
break
}
// Enforce sig check for the last block in a batch
enforceSigCheck := !commonIter.HasNext()
err = ss.UpdateBlockAndStatus(block, bc, enforceSigCheck)
_ = !commonIter.HasNext()
err = ss.UpdateBlockAndStatus(block, bc)
if err != nil {
break
}
Expand All @@ -972,7 +973,7 @@ func (ss *StateSync) generateNewState(bc core.BlockChain) error {
if block == nil {
break
}
err = ss.UpdateBlockAndStatus(block, bc, true)
err = ss.UpdateBlockAndStatus(block, bc)
if err != nil {
break
}
Expand All @@ -993,7 +994,7 @@ func (ss *StateSync) generateNewState(bc core.BlockChain) error {
if block == nil {
break
}
err = ss.UpdateBlockAndStatus(block, bc, false)
err = ss.UpdateBlockAndStatus(block, bc)
if err != nil {
break
}
Expand Down
4 changes: 2 additions & 2 deletions api/service/stagedsync/stage_lastmile.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (lm *StageLastMile) Exec(firstCycle bool, invalidBlockRevert bool, s *Stage
if block == nil {
break
}
err = s.state.UpdateBlockAndStatus(block, bc, true)
err = s.state.UpdateBlockAndStatus(block, bc)
if err != nil {
break
}
Expand All @@ -70,7 +70,7 @@ func (lm *StageLastMile) Exec(firstCycle bool, invalidBlockRevert bool, s *Stage
if block == nil {
break
}
err = s.state.UpdateBlockAndStatus(block, bc, false)
err = s.state.UpdateBlockAndStatus(block, bc)
if err != nil {
break
}
Expand Down
3 changes: 2 additions & 1 deletion api/service/stagedsync/stagedsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,14 +1035,15 @@ func (ss *StagedSync) getBlockFromLastMileBlocksByParentHash(parentHash common.H
}

// UpdateBlockAndStatus updates block and its status in db
func (ss *StagedSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain, verifyAllSig bool) error {
func (ss *StagedSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain) error {
if block.NumberU64() != bc.CurrentBlock().NumberU64()+1 {
utils.Logger().Debug().
Uint64("curBlockNum", bc.CurrentBlock().NumberU64()).
Uint64("receivedBlockNum", block.NumberU64()).
Msg("[STAGED_SYNC] Inappropriate block number, ignore!")
return nil
}
verifyAllSig := true

haveCurrentSig := len(block.GetCurrentCommitSig()) != 0
// Verify block signatures
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type syncConfig struct {
}

type ISync interface {
UpdateBlockAndStatus(block *types.Block, bc core.BlockChain, verifyAllSig bool) error
UpdateBlockAndStatus(block *types.Block, bc core.BlockChain) error
AddLastMileBlock(block *types.Block)
GetActivePeerNumber() int
CreateSyncConfig(peers []p2p.Peer, shardID uint32, selfPeerID libp2p_peer.ID, waitForEachPeerToConnect bool) error
Expand Down

0 comments on commit f576910

Please sign in to comment.