From 3784d6a56404a81831db043dacd47df07a69355d Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 14 Oct 2020 08:06:49 +0000 Subject: [PATCH] [viewchange] simplify onNewView function Signed-off-by: Leo Chen --- consensus/view_change.go | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/consensus/view_change.go b/consensus/view_change.go index 9553e31a4..d2d8ffc50 100644 --- a/consensus/view_change.go +++ b/consensus/view_change.go @@ -9,7 +9,6 @@ import ( "github.com/ethereum/go-ethereum/common" msg_pb "github.com/harmony-one/harmony/api/proto/message" "github.com/harmony-one/harmony/consensus/quorum" - "github.com/harmony-one/harmony/consensus/signature" nodeconfig "github.com/harmony-one/harmony/internal/configs/node" "github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/p2p" @@ -381,6 +380,8 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) { return } + consensus.consensusTimeout[timeoutViewChange].Stop() + // newView message verified success, override my state consensus.SetViewIDs(recvMsg.ViewID) consensus.LeaderPubKey = recvMsg.SenderPubkey @@ -388,31 +389,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) { // NewView message is verified, change state to normal consensus if preparedBlock != nil { - // Construct and send the commit message - commitPayload := signature.ConstructCommitPayload(consensus.ChainReader, - preparedBlock.Epoch(), preparedBlock.Hash(), preparedBlock.NumberU64(), preparedBlock.Header().ViewID().Uint64()) - groupID := []nodeconfig.GroupID{ - nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID))} - for _, key := range consensus.priKey { - if !consensus.IsValidatorInCommittee(key.Pub.Bytes) { - continue - } - network, err := consensus.construct( - msg_pb.MessageType_COMMIT, - commitPayload, - &key, - ) - if err != nil { - consensus.getLogger().Err(err).Msg("could not create commit message") - continue - } - msgToSend := network.Bytes - consensus.getLogger().Info().Msg("onNewView === commit") - consensus.host.SendMessageToGroups( - groupID, - p2p.ConstructMessage(msgToSend), - ) - } + consensus.sendCommitMessages(preparedBlock) consensus.switchPhase("onNewView", FBFTCommit) } else { consensus.ResetState() @@ -422,7 +399,6 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) { Str("newLeaderKey", consensus.LeaderPubKey.Bytes.Hex()). Msg("new leader changed") consensus.consensusTimeout[timeoutConsensus].Start() - consensus.consensusTimeout[timeoutViewChange].Stop() } // ResetViewChangeState resets the view change structure