From 205c77b7da4d016e436dd1b3d2addd32c7bd7ccc Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sun, 25 Oct 2020 05:40:56 +0000 Subject: [PATCH] [viewchange] should not startNewView is not in viewChange mode Signed-off-by: Leo Chen --- consensus/view_change.go | 8 ++++++++ consensus/view_change_msg.go | 3 +++ 2 files changed, 11 insertions(+) diff --git a/consensus/view_change.go b/consensus/view_change.go index 600e72b7e..2934afa81 100644 --- a/consensus/view_change.go +++ b/consensus/view_change.go @@ -278,9 +278,17 @@ func (consensus *Consensus) startNewView(viewID uint64, newLeaderPriKey *bls.Pri consensus.mutex.Lock() defer consensus.mutex.Unlock() + if !consensus.IsViewChangingMode() { + return errors.New("not in view changing mode anymore") + } + msgToSend := consensus.constructNewViewMessage( viewID, newLeaderPriKey, ) + if msgToSend == nil { + return errors.New("failed to construct NewView message") + } + if err := consensus.msgSender.SendWithRetry( consensus.blockNum, msg_pb.MessageType_NEWVIEW, diff --git a/consensus/view_change_msg.go b/consensus/view_change_msg.go index 40a366760..4848a6864 100644 --- a/consensus/view_change_msg.go +++ b/consensus/view_change_msg.go @@ -118,6 +118,9 @@ func (consensus *Consensus) constructNewViewMessage(viewID uint64, priKey *bls.P vcMsg.Payload, vcMsg.PreparedBlock = consensus.vc.GetPreparedBlock(consensus.FBFTLog, consensus.blockHash) vcMsg.M2Aggsigs, vcMsg.M2Bitmap = consensus.vc.GetM2Bitmap(viewID) vcMsg.M3Aggsigs, vcMsg.M3Bitmap = consensus.vc.GetM3Bitmap(viewID) + if vcMsg.M3Bitmap == nil || vcMsg.M3Aggsigs == nil { + return nil + } marshaledMessage, err := consensus.signAndMarshalConsensusMessage(message, priKey.Pri) if err != nil {