|
|
@ -182,8 +182,8 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) { |
|
|
|
|
|
|
|
|
|
|
|
// TODO: remove NIL type message
|
|
|
|
// TODO: remove NIL type message
|
|
|
|
// add self m1 or m2 type message signature and bitmap
|
|
|
|
// add self m1 or m2 type message signature and bitmap
|
|
|
|
_, ok1 := consensus.nilSigs[recvMsg.ViewID][consensus.PubKey.SerializeToHexStr()] |
|
|
|
_, ok1 := consensus.nilSigs[recvMsg.ViewID][newLeaderKey.SerializeToHexStr()] |
|
|
|
_, ok2 := consensus.bhpSigs[recvMsg.ViewID][consensus.PubKey.SerializeToHexStr()] |
|
|
|
_, ok2 := consensus.bhpSigs[recvMsg.ViewID][newLeaderKey.SerializeToHexStr()] |
|
|
|
if !(ok1 || ok2) { |
|
|
|
if !(ok1 || ok2) { |
|
|
|
// add own signature for newview message
|
|
|
|
// add own signature for newview message
|
|
|
|
preparedMsgs := consensus.FBFTLog.GetMessagesByTypeSeq( |
|
|
|
preparedMsgs := consensus.FBFTLog.GetMessagesByTypeSeq( |
|
|
@ -192,22 +192,31 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) { |
|
|
|
preparedMsg := consensus.FBFTLog.FindMessageByMaxViewID(preparedMsgs) |
|
|
|
preparedMsg := consensus.FBFTLog.FindMessageByMaxViewID(preparedMsgs) |
|
|
|
if preparedMsg == nil { |
|
|
|
if preparedMsg == nil { |
|
|
|
consensus.getLogger().Debug().Msg("[onViewChange] add my M2(NIL) type messaage") |
|
|
|
consensus.getLogger().Debug().Msg("[onViewChange] add my M2(NIL) type messaage") |
|
|
|
consensus.nilSigs[recvMsg.ViewID][consensus.PubKey.SerializeToHexStr()] = newLeaderPriKey.SignHash(NIL) |
|
|
|
for i, key := range consensus.PubKey.PublicKey { |
|
|
|
consensus.nilBitmap[recvMsg.ViewID].SetKey(newLeaderKey, true) |
|
|
|
priKey := consensus.priKey.PrivateKey[i] |
|
|
|
|
|
|
|
consensus.nilSigs[recvMsg.ViewID][key.SerializeToHexStr()] = priKey.SignHash(NIL) |
|
|
|
|
|
|
|
consensus.nilBitmap[recvMsg.ViewID].SetKey(key, true) |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
consensus.getLogger().Debug().Msg("[onViewChange] add my M1 type messaage") |
|
|
|
consensus.getLogger().Debug().Msg("[onViewChange] add my M1 type messaage") |
|
|
|
msgToSign := append(preparedMsg.BlockHash[:], preparedMsg.Payload...) |
|
|
|
msgToSign := append(preparedMsg.BlockHash[:], preparedMsg.Payload...) |
|
|
|
consensus.bhpSigs[recvMsg.ViewID][consensus.PubKey.SerializeToHexStr()] = newLeaderPriKey.SignHash(msgToSign) |
|
|
|
for i, key := range consensus.PubKey.PublicKey { |
|
|
|
consensus.bhpBitmap[recvMsg.ViewID].SetKey(newLeaderKey, true) |
|
|
|
priKey := consensus.priKey.PrivateKey[i] |
|
|
|
|
|
|
|
consensus.bhpSigs[recvMsg.ViewID][key.SerializeToHexStr()] = priKey.SignHash(msgToSign) |
|
|
|
|
|
|
|
consensus.bhpBitmap[recvMsg.ViewID].SetKey(key, true) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// add self m3 type message signature and bitmap
|
|
|
|
// add self m3 type message signature and bitmap
|
|
|
|
_, ok3 := consensus.viewIDSigs[recvMsg.ViewID][consensus.PubKey.SerializeToHexStr()] |
|
|
|
_, ok3 := consensus.viewIDSigs[recvMsg.ViewID][newLeaderKey.SerializeToHexStr()] |
|
|
|
if !ok3 { |
|
|
|
if !ok3 { |
|
|
|
viewIDBytes := make([]byte, 8) |
|
|
|
viewIDBytes := make([]byte, 8) |
|
|
|
binary.LittleEndian.PutUint64(viewIDBytes, recvMsg.ViewID) |
|
|
|
binary.LittleEndian.PutUint64(viewIDBytes, recvMsg.ViewID) |
|
|
|
consensus.viewIDSigs[recvMsg.ViewID][consensus.PubKey.SerializeToHexStr()] = newLeaderPriKey.SignHash(viewIDBytes) |
|
|
|
for i, key := range consensus.PubKey.PublicKey { |
|
|
|
consensus.viewIDBitmap[recvMsg.ViewID].SetKey(newLeaderKey, true) |
|
|
|
priKey := consensus.priKey.PrivateKey[i] |
|
|
|
|
|
|
|
consensus.viewIDSigs[recvMsg.ViewID][key.SerializeToHexStr()] = priKey.SignHash(viewIDBytes) |
|
|
|
|
|
|
|
consensus.viewIDBitmap[recvMsg.ViewID].SetKey(key, true) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// m2 type message
|
|
|
|
// m2 type message
|
|
|
@ -356,10 +365,12 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) { |
|
|
|
blockNumBytes := [8]byte{} |
|
|
|
blockNumBytes := [8]byte{} |
|
|
|
binary.LittleEndian.PutUint64(blockNumBytes[:], consensus.blockNum) |
|
|
|
binary.LittleEndian.PutUint64(blockNumBytes[:], consensus.blockNum) |
|
|
|
commitPayload := append(blockNumBytes[:], consensus.blockHash[:]...) |
|
|
|
commitPayload := append(blockNumBytes[:], consensus.blockHash[:]...) |
|
|
|
|
|
|
|
for i, key := range consensus.PubKey.PublicKey { |
|
|
|
|
|
|
|
priKey := consensus.priKey.PrivateKey[i] |
|
|
|
if _, err := consensus.Decider.SubmitVote( |
|
|
|
if _, err := consensus.Decider.SubmitVote( |
|
|
|
quorum.Commit, |
|
|
|
quorum.Commit, |
|
|
|
newLeaderKey, |
|
|
|
key, |
|
|
|
newLeaderPriKey.SignHash(commitPayload), |
|
|
|
priKey.SignHash(commitPayload), |
|
|
|
common.BytesToHash(consensus.blockHash[:]), |
|
|
|
common.BytesToHash(consensus.blockHash[:]), |
|
|
|
consensus.blockNum, |
|
|
|
consensus.blockNum, |
|
|
|
recvMsg.ViewID, |
|
|
|
recvMsg.ViewID, |
|
|
@ -368,12 +379,13 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := consensus.commitBitmap.SetKey(newLeaderKey, true); err != nil { |
|
|
|
if err := consensus.commitBitmap.SetKey(key, true); err != nil { |
|
|
|
consensus.getLogger().Debug(). |
|
|
|
consensus.getLogger().Debug(). |
|
|
|
Msg("[OnViewChange] New Leader commit bitmap set failed") |
|
|
|
Msg("[OnViewChange] New Leader commit bitmap set failed") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
consensus.current.SetViewID(recvMsg.ViewID) |
|
|
|
consensus.current.SetViewID(recvMsg.ViewID) |
|
|
|
msgToSend := consensus.constructNewViewMessage( |
|
|
|
msgToSend := consensus.constructNewViewMessage( |
|
|
@ -403,7 +415,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) { |
|
|
|
Uint64("viewChangingID", consensus.current.ViewID()). |
|
|
|
Uint64("viewChangingID", consensus.current.ViewID()). |
|
|
|
Msg("[onViewChange] New Leader Start Consensus Timer and Stop View Change Timer") |
|
|
|
Msg("[onViewChange] New Leader Start Consensus Timer and Stop View Change Timer") |
|
|
|
consensus.getLogger().Debug(). |
|
|
|
consensus.getLogger().Debug(). |
|
|
|
Str("myKey", consensus.PubKey.SerializeToHexStr()). |
|
|
|
Str("myKey", newLeaderKey.SerializeToHexStr()). |
|
|
|
Uint64("viewID", consensus.viewID). |
|
|
|
Uint64("viewID", consensus.viewID). |
|
|
|
Uint64("block", consensus.blockNum). |
|
|
|
Uint64("block", consensus.blockNum). |
|
|
|
Msg("[onViewChange] I am the New Leader") |
|
|
|
Msg("[onViewChange] I am the New Leader") |
|
|
|