@ -120,8 +120,12 @@ func (consensus *Consensus) switchPhase(desired FBFTPhase, override bool) {
}
// GetNextLeaderKey uniquely determine who is the leader for given viewID
func ( consensus * Consensus ) GetNextLeaderKey ( ) * bls . PublicKeyWrapper {
wasFound , next := consensus . Decider . NextAfter ( consensus . LeaderPubKey )
func ( consensus * Consensus ) GetNextLeaderKey ( viewID uint64 ) * bls . PublicKeyWrapper {
gap := 1
if viewID > consensus . GetCurViewID ( ) {
gap = int ( viewID - consensus . GetCurViewID ( ) )
}
wasFound , next := consensus . Decider . NextAfter ( consensus . LeaderPubKey , gap )
if ! wasFound {
consensus . getLogger ( ) . Warn ( ) .
Str ( "key" , consensus . LeaderPubKey . Bytes . Hex ( ) ) .
@ -163,20 +167,20 @@ func (consensus *Consensus) startViewChange(viewID uint64) {
consensus . consensusTimeout [ timeoutBootstrap ] . Stop ( )
consensus . current . SetMode ( ViewChanging )
consensus . SetViewChangingID ( viewID )
consensus . LeaderPubKey = consensus . GetNextLeaderKey ( )
nextLeaderPubKey : = consensus . GetNextLeaderKey ( viewID )
duration := consensus . current . GetViewChangeDuraion ( )
consensus . getLogger ( ) . Warn ( ) .
Uint64 ( "viewChangingID" , consensus . GetViewChangingID ( ) ) .
Dur ( "timeoutDuration" , duration ) .
Str ( "NextLeader" , consensus . LeaderPubKey . Bytes . Hex ( ) ) .
Str ( "NextLeader" , next LeaderPubKey. Bytes . Hex ( ) ) .
Msg ( "[startViewChange]" )
for _ , key := range consensus . priKey {
if ! consensus . IsValidatorInCommittee ( key . Pub . Bytes ) {
continue
}
msgToSend := consensus . constructViewChangeMessage ( & key )
msgToSend := consensus . constructViewChangeMessage ( & key , nextLeaderPubKey )
consensus . host . SendMessageToGroups ( [ ] nodeconfig . GroupID {
nodeconfig . NewGroupIDByShardID ( nodeconfig . ShardID ( consensus . ShardID ) ) ,
} ,
@ -680,8 +684,6 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
consensus . getLogger ( ) . Info ( ) .
Str ( "newLeaderKey" , consensus . LeaderPubKey . Bytes . Hex ( ) ) .
Msg ( "new leader changed" )
consensus . getLogger ( ) . Info ( ) .
Msg ( "validator start consensus timer and stop view change timer" )
consensus . consensusTimeout [ timeoutConsensus ] . Start ( )
consensus . consensusTimeout [ timeoutViewChange ] . Stop ( )
}