From a6f356b386d09367bd7841ee5e0dce571017114b Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Wed, 10 Mar 2021 14:59:21 -0800 Subject: [PATCH 1/2] avoid unnecessary header sig checking --- consensus/consensus_v2.go | 5 +++-- consensus/leader.go | 1 + node/node_explorer.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index a4bd9024f..cc1074d21 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -588,7 +588,7 @@ func (consensus *Consensus) preCommitAndPropose(blk *types.Block) error { go func() { blk.SetCurrentCommitSig(bareMinimumCommit) - if _, err := consensus.Blockchain.InsertChain([]*types.Block{blk}, true); err != nil { + if _, err := consensus.Blockchain.InsertChain([]*types.Block{blk}, !consensus.FBFTLog.IsBlockVerified(blk)); err != nil { consensus.getLogger().Error().Err(err).Msg("[preCommitAndPropose] Failed to add block to chain") return } @@ -690,7 +690,8 @@ func (consensus *Consensus) tryCatchup() error { func (consensus *Consensus) commitBlock(blk *types.Block, committedMsg *FBFTMessage) error { if consensus.Blockchain.CurrentBlock().NumberU64() < blk.NumberU64() { - if _, err := consensus.Blockchain.InsertChain([]*types.Block{blk}, true); err != nil { + consensus.FBFTLog.IsBlockVerified(blk) + if _, err := consensus.Blockchain.InsertChain([]*types.Block{blk}, !consensus.FBFTLog.IsBlockVerified(blk)); err != nil { consensus.getLogger().Error().Err(err).Msg("[commitBlock] Failed to add block to chain") return err } diff --git a/consensus/leader.go b/consensus/leader.go index 3e8646131..abf07adcf 100644 --- a/consensus/leader.go +++ b/consensus/leader.go @@ -296,6 +296,7 @@ func (consensus *Consensus) onCommit(recvMsg *FBFTMessage) { if !quorumWasMet && quorumIsMet { logger.Info().Msg("[OnCommit] 2/3 Enough commits received") + consensus.FBFTLog.MarkBlockVerified(blockObj) if !blockObj.IsLastBlockInEpoch() { // only do early commit if it's not epoch block to avoid problems diff --git a/node/node_explorer.go b/node/node_explorer.go index d90556a11..a10c0cf9d 100644 --- a/node/node_explorer.go +++ b/node/node_explorer.go @@ -122,7 +122,7 @@ func (node *Node) explorerMessageHandler(ctx context.Context, msg *msg_pb.Messag // AddNewBlockForExplorer add new block for explorer. func (node *Node) AddNewBlockForExplorer(block *types.Block) { utils.Logger().Info().Uint64("blockHeight", block.NumberU64()).Msg("[Explorer] Adding new block for explorer node") - if _, err := node.Blockchain().InsertChain([]*types.Block{block}, true); err == nil { + if _, err := node.Blockchain().InsertChain([]*types.Block{block}, false); err == nil { if block.IsLastBlockInEpoch() { node.Consensus.UpdateConsensusInformation() } From 68bc2b70781bb336833cdb657178cd56fe0d2ce8 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Wed, 10 Mar 2021 15:05:18 -0800 Subject: [PATCH 2/2] remove unused line --- consensus/consensus_v2.go | 1 - 1 file changed, 1 deletion(-) diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index cc1074d21..31be69473 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -690,7 +690,6 @@ func (consensus *Consensus) tryCatchup() error { func (consensus *Consensus) commitBlock(blk *types.Block, committedMsg *FBFTMessage) error { if consensus.Blockchain.CurrentBlock().NumberU64() < blk.NumberU64() { - consensus.FBFTLog.IsBlockVerified(blk) if _, err := consensus.Blockchain.InsertChain([]*types.Block{blk}, !consensus.FBFTLog.IsBlockVerified(blk)); err != nil { consensus.getLogger().Error().Err(err).Msg("[commitBlock] Failed to add block to chain") return err