Fix usage of private methods.

pull/4377/head
frozen 2 years ago committed by Casey Gardiner
parent 60fc56d1f3
commit ccff38e304
  1. 12
      consensus/checks.go
  2. 4
      consensus/consensus_service.go
  3. 10
      consensus/consensus_v2.go

@ -152,7 +152,7 @@ func (consensus *Consensus) onViewChangeSanityCheck(recvMsg *FBFTMessage) bool {
Interface("SendPubKeys", recvMsg.SenderPubkeys). Interface("SendPubKeys", recvMsg.SenderPubkeys).
Msg("[onViewChangeSanityCheck]") Msg("[onViewChangeSanityCheck]")
if consensus.BlockNum() > recvMsg.BlockNum { if consensus.getBlockNum() > recvMsg.BlockNum {
consensus.getLogger().Debug(). consensus.getLogger().Debug().
Msg("[onViewChange] Message BlockNum Is Low") Msg("[onViewChange] Message BlockNum Is Low")
return false return false
@ -163,13 +163,13 @@ func (consensus *Consensus) onViewChangeSanityCheck(recvMsg *FBFTMessage) bool {
return false return false
} }
if consensus.isViewChangingMode() && if consensus.isViewChangingMode() &&
consensus.GetCurBlockViewID() > recvMsg.ViewID { consensus.getCurBlockViewID() > recvMsg.ViewID {
consensus.getLogger().Debug().Uint64("curBlockViewID", consensus.GetCurBlockViewID()). consensus.getLogger().Debug().Uint64("curBlockViewID", consensus.getCurBlockViewID()).
Uint64("msgViewID", recvMsg.ViewID). Uint64("msgViewID", recvMsg.ViewID).
Msg("[onViewChangeSanityCheck] ViewChanging ID Is Low") Msg("[onViewChangeSanityCheck] ViewChanging ID Is Low")
return false return false
} }
if recvMsg.ViewID > consensus.GetViewChangingID() && recvMsg.ViewID-consensus.GetViewChangingID() > MaxViewIDDiff { if recvMsg.ViewID > consensus.getViewChangingID() && recvMsg.ViewID-consensus.getViewChangingID() > MaxViewIDDiff {
consensus.getLogger().Debug(). consensus.getLogger().Debug().
Msg("[onViewChangeSanityCheck] Received viewID that is MaxViewIDDiff (249) further from the current viewID!") Msg("[onViewChangeSanityCheck] Received viewID that is MaxViewIDDiff (249) further from the current viewID!")
return false return false
@ -194,9 +194,9 @@ func (consensus *Consensus) onViewChangeSanityCheck(recvMsg *FBFTMessage) bool {
// TODO: leo: move the sanity check to p2p message validation // TODO: leo: move the sanity check to p2p message validation
func (consensus *Consensus) onNewViewSanityCheck(recvMsg *FBFTMessage) bool { func (consensus *Consensus) onNewViewSanityCheck(recvMsg *FBFTMessage) bool {
if recvMsg.ViewID < consensus.GetCurBlockViewID() { if recvMsg.ViewID < consensus.getCurBlockViewID() {
consensus.getLogger().Warn(). consensus.getLogger().Warn().
Uint64("LastSuccessfulConsensusViewID", consensus.GetCurBlockViewID()). Uint64("LastSuccessfulConsensusViewID", consensus.getCurBlockViewID()).
Uint64("MsgViewChangingID", recvMsg.ViewID). Uint64("MsgViewChangingID", recvMsg.ViewID).
Msg("[onNewView] ViewID should be larger than the viewID of the last successful consensus") Msg("[onNewView] ViewID should be larger than the viewID of the last successful consensus")
return false return false

@ -248,9 +248,9 @@ func (consensus *Consensus) checkViewID(msg *FBFTMessage) error {
Str("leaderKey", consensus.LeaderPubKey.Bytes.Hex()). Str("leaderKey", consensus.LeaderPubKey.Bytes.Hex()).
Msg("[checkViewID] Start consensus timer") Msg("[checkViewID] Start consensus timer")
return nil return nil
} else if msg.ViewID > consensus.GetCurBlockViewID() { } else if msg.ViewID > consensus.getCurBlockViewID() {
return consensus_engine.ErrViewIDNotMatch return consensus_engine.ErrViewIDNotMatch
} else if msg.ViewID < consensus.GetCurBlockViewID() { } else if msg.ViewID < consensus.getCurBlockViewID() {
return errors.New("view ID belongs to the past") return errors.New("view ID belongs to the past")
} }
return nil return nil

@ -144,7 +144,7 @@ func (consensus *Consensus) finalCommit() {
consensus.getLogger().Info(). consensus.getLogger().Info().
Int64("NumCommits", numCommits). Int64("NumCommits", numCommits).
Msg("[finalCommit] Finalizing Consensus") Msg("[finalCommit] Finalizing Consensus")
beforeCatchupNum := consensus.BlockNum() beforeCatchupNum := consensus.getBlockNum()
leaderPriKey, err := consensus.getConsensusLeaderPrivateKey() leaderPriKey, err := consensus.getConsensusLeaderPrivateKey()
if err != nil { if err != nil {
@ -345,16 +345,16 @@ func (consensus *Consensus) StartChannel() {
func (consensus *Consensus) syncReadyChan() { func (consensus *Consensus) syncReadyChan() {
consensus.getLogger().Info().Msg("[ConsensusMainLoop] syncReadyChan") consensus.getLogger().Info().Msg("[ConsensusMainLoop] syncReadyChan")
if consensus.BlockNum() < consensus.Blockchain().CurrentHeader().Number().Uint64()+1 { if consensus.getBlockNum() < consensus.Blockchain().CurrentHeader().Number().Uint64()+1 {
consensus.SetBlockNum(consensus.Blockchain().CurrentHeader().Number().Uint64() + 1) consensus.setBlockNum(consensus.Blockchain().CurrentHeader().Number().Uint64() + 1)
consensus.SetViewIDs(consensus.Blockchain().CurrentHeader().ViewID().Uint64() + 1) consensus.setViewIDs(consensus.Blockchain().CurrentHeader().ViewID().Uint64() + 1)
mode := consensus.updateConsensusInformation() mode := consensus.updateConsensusInformation()
consensus.current.SetMode(mode) consensus.current.SetMode(mode)
consensus.getLogger().Info().Msg("[syncReadyChan] Start consensus timer") consensus.getLogger().Info().Msg("[syncReadyChan] Start consensus timer")
consensus.consensusTimeout[timeoutConsensus].Start() consensus.consensusTimeout[timeoutConsensus].Start()
consensus.getLogger().Info().Str("Mode", mode.String()).Msg("Node is IN SYNC") consensus.getLogger().Info().Str("Mode", mode.String()).Msg("Node is IN SYNC")
consensusSyncCounterVec.With(prometheus.Labels{"consensus": "in_sync"}).Inc() consensusSyncCounterVec.With(prometheus.Labels{"consensus": "in_sync"}).Inc()
} else if consensus.Mode() == Syncing { } else if consensus.mode() == Syncing {
// Corner case where sync is triggered before `onCommitted` and there is a race // Corner case where sync is triggered before `onCommitted` and there is a race
// for block insertion between consensus and downloader. // for block insertion between consensus and downloader.
mode := consensus.updateConsensusInformation() mode := consensus.updateConsensusInformation()

Loading…
Cancel
Save