[sync] fixed beacon sync signature verification

pull/3612/head
Jacky Wang 4 years ago
parent ec71ca5625
commit 9a27b46bb8
No known key found for this signature in database
GPG Key ID: 1085CE5F4FF5842C
  1. 20
      api/service/legacysync/syncing.go
  2. 2
      node/node_syncing.go

@ -802,7 +802,7 @@ func (ss *StateSync) getBlockFromLastMileBlocksByParentHash(parentHash common.Ha
} }
// UpdateBlockAndStatus ... // UpdateBlockAndStatus ...
func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc *core.BlockChain, worker *worker.Worker, verifyAllSig bool) error { func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc *core.BlockChain, verifyAllSig, haveCurrentSig bool) error {
if block.NumberU64() != bc.CurrentBlock().NumberU64()+1 { if block.NumberU64() != bc.CurrentBlock().NumberU64()+1 {
utils.Logger().Info().Uint64("curBlockNum", bc.CurrentBlock().NumberU64()).Uint64("receivedBlockNum", block.NumberU64()).Msg("[SYNC] Inappropriate block number, ignore!") utils.Logger().Info().Uint64("curBlockNum", bc.CurrentBlock().NumberU64()).Uint64("receivedBlockNum", block.NumberU64()).Msg("[SYNC] Inappropriate block number, ignore!")
return nil return nil
@ -811,11 +811,9 @@ func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc *core.BlockChai
// Verify block signatures // Verify block signatures
if block.NumberU64() > 1 { if block.NumberU64() > 1 {
// Verify signature every 100 blocks // Verify signature every 100 blocks
verifySig := block.NumberU64()%verifyHeaderBatchSize == 0 verifySeal := block.NumberU64()%verifyHeaderBatchSize == 0 || verifyAllSig
if verifyAllSig { verifyCurrentSig := verifyAllSig && verifySeal
verifySig = true if haveCurrentSig {
}
if verifySig {
sig, bitmap, err := chain.ParseCommitSigAndBitmap(block.GetCurrentCommitSig()) sig, bitmap, err := chain.ParseCommitSigAndBitmap(block.GetCurrentCommitSig())
if err != nil { if err != nil {
return errors.Wrap(err, "parse commitSigAndBitmap") return errors.Wrap(err, "parse commitSigAndBitmap")
@ -824,7 +822,7 @@ func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc *core.BlockChai
return errors.Wrapf(err, "verify header signature %v", block.Hash().String()) return errors.Wrapf(err, "verify header signature %v", block.Hash().String())
} }
} }
err := bc.Engine().VerifyHeader(bc, block.Header(), verifySig) err := bc.Engine().VerifyHeader(bc, block.Header(), verifySeal)
if err == engine.ErrUnknownAncestor { if err == engine.ErrUnknownAncestor {
return err return err
} else if err != nil { } else if err != nil {
@ -861,7 +859,7 @@ func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc *core.BlockChai
Uint32("ShardID", block.ShardID()). Uint32("ShardID", block.ShardID()).
Msg("[SYNC] UpdateBlockAndStatus: New Block Added to Blockchain") Msg("[SYNC] UpdateBlockAndStatus: New Block Added to Blockchain")
if verifyAllSig { if verifyAllSig && haveCurrentSig {
if err := bc.WriteCommitSig(block.NumberU64(), block.GetCurrentCommitSig()); err != nil { if err := bc.WriteCommitSig(block.NumberU64(), block.GetCurrentCommitSig()); err != nil {
return err return err
} }
@ -890,7 +888,7 @@ func (ss *StateSync) generateNewState(bc *core.BlockChain, worker *worker.Worker
} }
// Enforce sig check for the last block in a batch // Enforce sig check for the last block in a batch
enforceSigCheck := !commonIter.HasNext() enforceSigCheck := !commonIter.HasNext()
err = ss.UpdateBlockAndStatus(block, bc, worker, enforceSigCheck) err = ss.UpdateBlockAndStatus(block, bc, enforceSigCheck, true)
if err != nil { if err != nil {
break break
} }
@ -907,7 +905,7 @@ func (ss *StateSync) generateNewState(bc *core.BlockChain, worker *worker.Worker
if block == nil { if block == nil {
break break
} }
err = ss.UpdateBlockAndStatus(block, bc, worker, true) err = ss.UpdateBlockAndStatus(block, bc, true, true)
if err != nil { if err != nil {
break break
} }
@ -928,7 +926,7 @@ func (ss *StateSync) generateNewState(bc *core.BlockChain, worker *worker.Worker
if block == nil { if block == nil {
break break
} }
err = ss.UpdateBlockAndStatus(block, bc, worker, false) err = ss.UpdateBlockAndStatus(block, bc, false, false)
if err != nil { if err != nil {
break break
} }

@ -200,7 +200,7 @@ func (node *Node) doBeaconSyncing() {
for beaconBlock := range node.BeaconBlockChannel { for beaconBlock := range node.BeaconBlockChannel {
if node.beaconSync != nil { if node.beaconSync != nil {
err := node.beaconSync.UpdateBlockAndStatus( err := node.beaconSync.UpdateBlockAndStatus(
beaconBlock, node.Beaconchain(), node.BeaconWorker, true, beaconBlock, node.Beaconchain(), true, false,
) )
if err != nil { if err != nil {
node.beaconSync.AddLastMileBlock(beaconBlock) node.beaconSync.AddLastMileBlock(beaconBlock)

Loading…
Cancel
Save