@ -197,9 +197,6 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
consensus . vcLock . Lock ( )
consensus . vcLock . Lock ( )
defer consensus . vcLock . Unlock ( )
defer consensus . vcLock . Unlock ( )
consensus . mode . SetMode ( ViewChanging )
consensus . mode . SetViewID ( recvMsg . ViewID )
// add self m1 or m2 type message signature and bitmap
// add self m1 or m2 type message signature and bitmap
_ , ok1 := consensus . nilSigs [ consensus . SelfAddress ]
_ , ok1 := consensus . nilSigs [ consensus . SelfAddress ]
_ , ok2 := consensus . bhpSigs [ consensus . SelfAddress ]
_ , ok2 := consensus . bhpSigs [ consensus . SelfAddress ]
@ -227,7 +224,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
consensus . viewIDBitmap . SetKey ( consensus . PubKey , true )
consensus . viewIDBitmap . SetKey ( consensus . PubKey , true )
}
}
if ( len ( consensus . bhpSigs ) + len ( consensus . nilSigs ) ) >= consensus . Quorum ( ) {
if len ( consensus . viewIDSigs ) >= consensus . Quorum ( ) {
return
return
}
}
@ -296,14 +293,12 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
}
}
consensus . viewIDSigs [ validatorAddress ] = recvMsg . ViewidSig
consensus . viewIDSigs [ validatorAddress ] = recvMsg . ViewidSig
consensus . viewIDBitmap . SetKey ( recvMsg . SenderPubkey , true ) // Set the bitmap indicating that this validator signed.
consensus . viewIDBitmap . SetKey ( recvMsg . SenderPubkey , true ) // Set the bitmap indicating that this validator signed.
utils . GetLogger ( ) . Debug ( "hehe1" )
if len ( consensus . viewIDSigs ) >= consensus . Quorum ( ) {
if len ( consensus . viewIDSigs ) >= consensus . Quorum ( ) {
utils . GetLogger ( ) . Debug ( "hehe1" )
consensus . mode . SetMode ( Normal )
consensus . mode . SetMode ( Normal )
consensus . LeaderPubKey = consensus . PubKey
consensus . LeaderPubKey = consensus . PubKey
consensus . ResetState ( )
if len ( consensus . m1Payload ) == 0 {
if len ( consensus . m1Payload ) == 0 {
consensus . phase = Announce
go func ( ) {
go func ( ) {
consensus . ReadySignal <- struct { } { }
consensus . ReadySignal <- struct { } { }
} ( )
} ( )
@ -322,18 +317,18 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
consensus . commitSigs [ consensus . SelfAddress ] = consensus . priKey . SignHash ( consensus . m1Payload [ 32 : ] )
consensus . commitSigs [ consensus . SelfAddress ] = consensus . priKey . SignHash ( consensus . m1Payload [ 32 : ] )
}
}
consensus . mode . SetViewID ( recvMsg . ViewID )
msgToSend := consensus . constructNewViewMessage ( )
msgToSend := consensus . constructNewViewMessage ( )
utils . GetLogInstance ( ) . Warn ( "onViewChange" , "sent newview message" , len ( msgToSend ) )
utils . GetLogInstance ( ) . Warn ( "onViewChange" , "sent newview message" , len ( msgToSend ) )
consensus . host . SendMessageToGroups ( [ ] p2p . GroupID { p2p . NewGroupIDByShardID ( p2p . ShardID ( consensus . ShardID ) ) } , host . ConstructP2pMessage ( byte ( 17 ) , msgToSend ) )
consensus . host . SendMessageToGroups ( [ ] p2p . GroupID { p2p . NewGroupIDByShardID ( p2p . ShardID ( consensus . ShardID ) ) } , host . ConstructP2pMessage ( byte ( 17 ) , msgToSend ) )
consensus . viewID = consensus . mode . GetViewID ( )
consensus . viewID = recvMsg . ViewID
consensus . ResetViewChangeState ( )
consensus . ResetViewChangeState ( )
consensus . ResetState ( )
consensus . consensusTimeout [ timeoutViewChange ] . Stop ( )
consensus . consensusTimeout [ timeoutViewChange ] . Stop ( )
consensus . consensusTimeout [ timeoutConsensus ] . Start ( )
}
}
utils . GetLogInstance ( ) . Debug ( "onViewChange hehe viewIDSigs" , "numSigs" , len ( consensus . viewIDSigs ) , "needed" , consensus . Quorum ( ) )
utils . GetLogInstance ( ) . Debug ( "onViewChange" , "numSigs" , len ( consensus . viewIDSigs ) , "needed" , consensus . Quorum ( ) )
utils . GetLogInstance ( ) . Debug ( "onViewChange hehe sumSigs" , "numSigs" , len ( consensus . bhpSigs ) + len ( consensus . nilSigs ) , "needed" , consensus . Quorum ( ) )
}
}
// TODO: move to consensus_leader.go later
// TODO: move to consensus_leader.go later
@ -370,7 +365,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
binary . LittleEndian . PutUint32 ( viewIDHash , recvMsg . ViewID )
binary . LittleEndian . PutUint32 ( viewIDHash , recvMsg . ViewID )
// TODO check total number of sigs >= 2f+1
// TODO check total number of sigs >= 2f+1
if ! m3Sig . VerifyHash ( m3Mask . AggregatePublic , viewIDHash ) {
if ! m3Sig . VerifyHash ( m3Mask . AggregatePublic , viewIDHash ) {
utils . GetLogInstance ( ) . Warn ( "onNewView unable to verify aggregated signature of m3 payload" )
utils . GetLogInstance ( ) . Warn ( "onNewView unable to verify aggregated signature of m3 payload" , "m3Sig" , m3Sig . GetHexString ( ) [ : 10 ] , "m3Mask" , m3Mask . Bitmap , "viewID" , recvMsg . ViewID )
return
return
}
}
if recvMsg . M2AggSig != nil {
if recvMsg . M2AggSig != nil {
@ -413,21 +408,20 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
return
return
}
}
consensus . viewID = consensus . mode . GetViewID ( )
// Construct and send the commit message
// Construct and send the commit message
multiSigAndBitmap := append ( aggSig . Serialize ( ) , mask . Bitmap ... )
multiSigAndBitmap := append ( aggSig . Serialize ( ) , mask . Bitmap ... )
msgToSend := consensus . constructCommitMessage ( multiSigAndBitmap )
msgToSend := consensus . constructCommitMessage ( multiSigAndBitmap )
utils . GetLogInstance ( ) . Info ( "onNewView === commit" , "sent commit message" , len ( msgToSend ) )
utils . GetLogInstance ( ) . Info ( "onNewView === commit" , "sent commit message" , len ( msgToSend ) , "viewID" , consensus . viewID )
consensus . host . SendMessageToGroups ( [ ] p2p . GroupID { p2p . NewGroupIDByShardID ( p2p . ShardID ( consensus . ShardID ) ) } , host . ConstructP2pMessage ( byte ( 17 ) , msgToSend ) )
consensus . host . SendMessageToGroups ( [ ] p2p . GroupID { p2p . NewGroupIDByShardID ( p2p . ShardID ( consensus . ShardID ) ) } , host . ConstructP2pMessage ( byte ( 17 ) , msgToSend ) )
consensus . phase = Commit
consensus . phase = Commit
} else {
} else {
consensus . phase = Announce
consensus . ResetState ( )
utils . GetLogInstance ( ) . Info ( "onNewView === announce" )
utils . GetLogInstance ( ) . Info ( "onNewView === announce" )
}
}
consensus . viewID = consensus . mode . GetViewID ( )
consensus . LeaderPubKey = senderKey
consensus . LeaderPubKey = senderKey
consensus . viewID = consensus . mode . GetViewID ( )
consensus . ResetViewChangeState ( )
consensus . ResetViewChangeState ( )
consensus . ResetState ( )
consensus . consensusTimeout [ timeoutConsensus ] . Start ( )
consensus . consensusTimeout [ timeoutConsensus ] . Start ( )
consensus . consensusTimeout [ timeoutViewChange ] . Stop ( )
consensus . consensusTimeout [ timeoutViewChange ] . Stop ( )
}
}