From f5dea3995b92196034f0b742730b0f669b2cda53 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Sat, 4 Dec 2021 19:59:33 -0800 Subject: [PATCH] fix block decode issue and add more nil check (#3953) --- consensus/validator.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/consensus/validator.go b/consensus/validator.go index d8ea8133d..977cdd82f 100644 --- a/consensus/validator.go +++ b/consensus/validator.go @@ -84,7 +84,7 @@ func (consensus *Consensus) validateNewBlock(recvMsg *FBFTMessage) (*types.Block blockObj = consensus.FBFTLog.GetBlockByHash(recvMsg.BlockHash) if blockObj == nil { - if err := rlp.DecodeBytes(recvMsg.Block, &blockObj); err != nil { + if err := rlp.DecodeBytes(recvMsg.Block, blockObj); err != nil { consensus.getLogger().Warn(). Err(err). Uint64("MsgBlockNum", recvMsg.BlockNum). @@ -157,7 +157,7 @@ func (consensus *Consensus) prepare() { // sendCommitMessages send out commit messages to leader func (consensus *Consensus) sendCommitMessages(blockObj *types.Block) { - if consensus.IsBackup() { + if consensus.IsBackup() || blockObj == nil { return } @@ -269,6 +269,9 @@ func (consensus *Consensus) onPrepared(recvMsg *FBFTMessage) { go func() { // Try process future committed messages and process them in case of receiving committed before prepared + if blockObj == nil { + return + } curBlockNum := consensus.blockNum for _, committedMsg := range consensus.FBFTLog.GetNotVerifiedCommittedMessages(blockObj.NumberU64(), blockObj.Header().ViewID().Uint64(), blockObj.Hash()) { if committedMsg != nil {