Merge branch 'master' of github.com:harmony-one/harmony into rj_fork

pull/1096/head
Rongjian Lan 6 years ago
commit dd67389671
  1. 133
      api/proto/message/message.pb.go
  2. 5
      api/proto/message/message.proto
  3. 2
      consensus/config.go
  4. 4
      consensus/consensus.go
  5. 5
      consensus/consensus_leader_msg.go
  6. 6
      consensus/consensus_service.go
  7. 237
      consensus/consensus_v2.go
  8. 4
      consensus/pbft_log.go
  9. 4
      consensus/view_change.go

@ -525,8 +525,9 @@ type ConsensusRequest struct {
BlockNum uint64 `protobuf:"varint,2,opt,name=block_num,json=blockNum,proto3" json:"block_num,omitempty"`
ShardId uint32 `protobuf:"varint,3,opt,name=shard_id,json=shardId,proto3" json:"shard_id,omitempty"`
BlockHash []byte `protobuf:"bytes,4,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"`
SenderPubkey []byte `protobuf:"bytes,5,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"`
Payload []byte `protobuf:"bytes,6,opt,name=payload,proto3" json:"payload,omitempty"`
Block []byte `protobuf:"bytes,5,opt,name=block,proto3" json:"block,omitempty"`
SenderPubkey []byte `protobuf:"bytes,6,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"`
Payload []byte `protobuf:"bytes,7,opt,name=payload,proto3" json:"payload,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -585,6 +586,13 @@ func (m *ConsensusRequest) GetBlockHash() []byte {
return nil
}
func (m *ConsensusRequest) GetBlock() []byte {
if m != nil {
return m.Block
}
return nil
}
func (m *ConsensusRequest) GetSenderPubkey() []byte {
if m != nil {
return m.SenderPubkey
@ -808,66 +816,67 @@ func init() {
func init() { proto.RegisterFile("message.proto", fileDescriptor_33c57e4bae7b9afd) }
var fileDescriptor_33c57e4bae7b9afd = []byte{
// 934 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0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01, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x60,
0x9a, 0xe1, 0x08, 0x08, 0x00, 0x00,
// 948 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0xdd, 0x6e, 0xe2, 0x46,
0x14, 0xc6, 0x40, 0x30, 0x1c, 0x1b, 0x32, 0x3b, 0xdd, 0xee, 0x7a, 0xd3, 0xad, 0x1a, 0xb1, 0xaa,
0x14, 0xad, 0xd4, 0x68, 0x05, 0x17, 0x55, 0xa5, 0xde, 0x10, 0x18, 0x25, 0x56, 0x12, 0x43, 0x07,
0x67, 0xa3, 0x5e, 0x59, 0x13, 0x3c, 0x22, 0x56, 0xc0, 0xa6, 0x1e, 0x93, 0x15, 0x2f, 0xd0, 0x3e,
0x4c, 0xef, 0x7b, 0xdd, 0x3e, 0x45, 0x5f, 0xa7, 0x9a, 0x19, 0x83, 0xf9, 0xd9, 0xde, 0x55, 0xbd,
0xe3, 0xfb, 0xce, 0xf9, 0xce, 0x9c, 0xf3, 0x79, 0xce, 0x08, 0x68, 0xce, 0xb9, 0x10, 0x6c, 0xca,
0xcf, 0x17, 0x69, 0x92, 0x25, 0xd8, 0xcc, 0x61, 0xfb, 0x8f, 0x0a, 0x98, 0xb7, 0xfa, 0x37, 0xfe,
0x1e, 0x6c, 0xc1, 0xd3, 0xe7, 0x68, 0xc2, 0x83, 0x6c, 0xb5, 0xe0, 0x8e, 0x71, 0x6a, 0x9c, 0xb5,
0x3a, 0x2f, 0xcf, 0xd7, 0xd2, 0xb1, 0x0e, 0xfa, 0xab, 0x05, 0xa7, 0x96, 0x28, 0x00, 0x3e, 0x83,
0xaa, 0x12, 0x94, 0xf7, 0x04, 0x79, 0x61, 0x25, 0x50, 0x19, 0xf8, 0x2d, 0x34, 0x44, 0x34, 0x8d,
0x59, 0xb6, 0x4c, 0xb9, 0x53, 0x39, 0x35, 0xce, 0x6c, 0x5a,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, 0xc1, 0x1f, 0xc0, 0x1c,
0xa5, 0xc9, 0x84, 0x0b, 0x81, 0xd1, 0xfe, 0x4b, 0x7e, 0xf2, 0x62, 0xc3, 0xac, 0x1f, 0xdb, 0x76,
0xe9, 0xa1, 0xa6, 0xfe, 0x0d, 0x74, 0xff, 0x09, 0x00, 0x00, 0xff, 0xff, 0x3b, 0x51, 0x67, 0xf4,
0x1e, 0x08, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.

@ -84,8 +84,9 @@ message ConsensusRequest {
uint64 block_num = 2;
uint32 shard_id = 3;
bytes block_hash = 4;
bytes sender_pubkey = 5;
bytes payload = 6;
bytes block = 5;
bytes sender_pubkey = 6;
bytes payload = 7;
}
message DrandRequest {

@ -14,7 +14,7 @@ const (
bootstrapDuration time.Duration = 300 * time.Second
maxLogSize uint32 = 1000
// threshold between received consensus message blockNum and my blockNum
consensusBlockNumBuffer uint64 = 10
consensusBlockNumBuffer uint64 = 2
)
// TimeoutType is the type of timeout in view change protocol

@ -19,6 +19,7 @@ import (
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/genesis"
"github.com/harmony-one/harmony/internal/memprofiling"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
)
@ -103,6 +104,8 @@ type Consensus struct {
blockHash [32]byte
// Block to run consensus on
block []byte
// BlockHeader to run consensus on
blockHeader []byte
// Array of block hashes.
blockHashes [][32]byte
// Shard Id which this node belongs to
@ -275,6 +278,7 @@ func New(host p2p.Host, ShardID uint32, leader p2p.Peer, blsPriKey *bls.SecretKe
consensus.uniqueIDInstance = utils.GetUniqueValidatorIDInstance()
memprofiling.GetMemProfiling().Add("consensus.pbftLog", consensus.pbftLog)
return &consensus, nil
}

@ -21,8 +21,7 @@ func (consensus *Consensus) constructAnnounceMessage() []byte {
}
consensusMsg := message.GetConsensus()
consensus.populateMessageFields(consensusMsg)
// n byte of block header
consensusMsg.Payload = consensus.block // TODO: send only block header in the announce phase.
consensusMsg.Payload = consensus.blockHeader
marshaledMessage, err := consensus.signAndMarshalConsensusMessage(message)
if err != nil {
@ -43,6 +42,8 @@ func (consensus *Consensus) constructPreparedMessage() ([]byte, *bls.Sign) {
consensusMsg := message.GetConsensus()
consensus.populateMessageFields(consensusMsg)
// add block content in prepared message for slow validators to catchup
consensusMsg.Block = consensus.block
//// Payload
buffer := bytes.NewBuffer([]byte{})

@ -331,11 +331,13 @@ func (consensus *Consensus) ResetState() {
consensus.getLogger().Debug("[ResetState] Resetting consensus state", "Phase", consensus.phase)
consensus.switchPhase(Announce, true)
consensus.blockHash = [32]byte{}
consensus.blockHeader = []byte{}
consensus.block = []byte{}
consensus.prepareSigs = map[string]*bls.Sign{}
consensus.commitSigs = map[string]*bls.Sign{}
prepareBitmap, _ := bls_cosi.NewMask(consensus.PublicKeys, consensus.LeaderPubKey)
commitBitmap, _ := bls_cosi.NewMask(consensus.PublicKeys, consensus.LeaderPubKey)
prepareBitmap, _ := bls_cosi.NewMask(consensus.PublicKeys, nil)
commitBitmap, _ := bls_cosi.NewMask(consensus.PublicKeys, nil)
consensus.prepareBitmap = prepareBitmap
consensus.commitBitmap = commitBitmap
consensus.aggregatedPrepareSig = nil

@ -3,6 +3,7 @@ package consensus
import (
"bytes"
"encoding/binary"
"encoding/hex"
"time"
"github.com/ethereum/go-ethereum/common"
@ -14,7 +15,6 @@ import (
"github.com/harmony-one/harmony/api/service/explorer"
"github.com/harmony-one/harmony/core/types"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/host"
@ -82,10 +82,15 @@ func (consensus *Consensus) announce(block *types.Block) {
consensus.getLogger().Debug("[Announce] Failed encoding block")
return
}
encodedBlockHeader, err := rlp.EncodeToBytes(block.Header())
if err != nil {
consensus.getLogger().Debug("[Announce] Failed encoding block header")
return
}
consensus.block = encodedBlock
consensus.blockHeader = encodedBlockHeader
msgToSend := consensus.constructAnnounceMessage()
consensus.getLogger().Debug("[Announce] Switching phase", "From", consensus.phase, "To", Prepare)
consensus.switchPhase(Prepare, true)
// save announce message to pbftLog
msgPayload, _ := proto.GetConsensusMessagePayload(msgToSend)
@ -102,6 +107,10 @@ func (consensus *Consensus) announce(block *types.Block) {
// Leader sign the block hash itself
consensus.prepareSigs[consensus.PubKey.SerializeToHexStr()] = consensus.priKey.SignHash(consensus.blockHash[:])
if err := consensus.prepareBitmap.SetKey(consensus.PubKey, true); err != nil {
consensus.getLogger().Warn("[Announce] Leader prepareBitmap SetKey failed", "error", err)
return
}
// Construct broadcast p2p message
if err := consensus.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(p2p.ShardID(consensus.ShardID))}, host.ConstructP2pMessage(byte(17), msgToSend)); err != nil {
@ -109,6 +118,9 @@ func (consensus *Consensus) announce(block *types.Block) {
} else {
consensus.getLogger().Debug("[Announce] Sent Announce Message!!", "BlockHash", block.Hash(), "BlockNum", block.NumberU64())
}
consensus.getLogger().Debug("[Announce] Switching phase", "From", consensus.phase, "To", Prepare)
consensus.switchPhase(Prepare, true)
}
func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) {
@ -136,83 +148,71 @@ func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) {
consensus.getLogger().Debug("[OnAnnounce] Unparseable leader message", "error", err, "MsgBlockNum", recvMsg.BlockNum)
return
}
block := recvMsg.Payload
// check block header is valid
var blockObj types.Block
err = rlp.DecodeBytes(block, &blockObj)
// verify validity of block header object
blockHeader := recvMsg.Payload
var headerObj types.Header
err = rlp.DecodeBytes(blockHeader, &headerObj)
if err != nil {
consensus.getLogger().Warn("[OnAnnounce] Unparseable block header data", "error", err, "MsgBlockNum", recvMsg.BlockNum, "MsgPayloadBlockNum", blockObj.NumberU64())
consensus.getLogger().Warn("[OnAnnounce] Unparseable block header data", "error", err, "MsgBlockNum", recvMsg.BlockNum)
return
}
if blockObj.NumberU64() != recvMsg.BlockNum || recvMsg.BlockNum < consensus.blockNum {
consensus.getLogger().Warn("[OnAnnounce] BlockNum not match", "MsgBlockNum", recvMsg.BlockNum, "blockNum", blockObj.NumberU64())
if recvMsg.BlockNum < consensus.blockNum || recvMsg.BlockNum != headerObj.Number.Uint64() {
consensus.getLogger().Debug("[OnAnnounce] BlockNum not match", "MsgBlockNum", recvMsg.BlockNum, "BlockNum", headerObj.Number)
return
}
if consensus.mode.Mode() == Normal {
// skip verify header when node is in Syncing mode
if err := consensus.VerifyHeader(consensus.ChainReader, blockObj.Header(), false); err != nil {
consensus.getLogger().Warn("[OnAnnounce] Block content is not verified successfully", "error", err, "inChain", consensus.ChainReader.CurrentHeader().Number, "MsgBlockNum", blockObj.Header().Number)
if err = consensus.VerifyHeader(consensus.ChainReader, &headerObj, false); err != nil {
consensus.getLogger().Warn("[OnAnnounce] Block content is not verified successfully", "error", err, "inChain", consensus.ChainReader.CurrentHeader().Number, "MsgBlockNum", headerObj.Number)
return
}
}
//blockObj.Logger(consensus.getLogger()).Debug("received announce", "viewID", recvMsg.ViewID, "msgBlockNum", recvMsg.BlockNum)
logMsgs := consensus.pbftLog.GetMessagesByTypeSeqView(msg_pb.MessageType_ANNOUNCE, recvMsg.BlockNum, recvMsg.ViewID)
if len(logMsgs) > 0 {
if logMsgs[0].BlockHash != blockObj.Header().Hash() {
if logMsgs[0].BlockHash != recvMsg.BlockHash {
consensus.getLogger().Debug("[OnAnnounce] Leader is malicious", "leaderKey", consensus.LeaderPubKey.SerializeToHexStr())
consensus.startViewChange(consensus.viewID + 1)
}
return
}
blockPayload := make([]byte, len(block))
copy(blockPayload[:], block[:])
consensus.block = blockPayload
consensus.blockHash = recvMsg.BlockHash
consensus.getLogger().Debug("[OnAnnounce] Announce Block Added", "MsgViewID", recvMsg.ViewID, "MsgBlockNum", recvMsg.BlockNum)
consensus.getLogger().Debug("[OnAnnounce] Announce message Added", "MsgViewID", recvMsg.ViewID, "MsgBlockNum", recvMsg.BlockNum)
consensus.pbftLog.AddMessage(recvMsg)
consensus.pbftLog.AddBlock(&blockObj)
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.blockHash = recvMsg.BlockHash
// we have already added message and block, skip check viewID and send prepare message if is in ViewChanging mode
if consensus.mode.Mode() == ViewChanging {
consensus.getLogger().Debug("[OnAnnounce] Still in ViewChanging Mode, Exiting !!")
return
}
consensus.tryCatchup()
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
if consensus.checkViewID(recvMsg) != nil {
consensus.getLogger().Debug("[OnAnnounce] ViewID check failed", "MsgViewID", recvMsg.ViewID, "msgBlockNum", recvMsg.BlockNum)
return
}
consensus.prepare(&blockObj)
consensus.prepare()
return
}
// tryPrepare will try to send prepare message
func (consensus *Consensus) prepare(block *types.Block) {
// if consensus.blockNum != block.NumberU64() || !consensus.pbftLog.HasMatchingViewAnnounce(consensus.blockNum, consensus.viewID, hash) {
// consensus.getLogger().Debug("blockNum or announce message not match")
// return
// }
consensus.getLogger().Debug("[Announce] Switching Phase", "From", consensus.phase, "To", Prepare)
consensus.switchPhase(Prepare, true)
func (consensus *Consensus) prepare() {
// Construct and send prepare message
msgToSend := consensus.constructPrepareMessage()
// TODO: this will not return immediatey, may block
if err := consensus.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(p2p.ShardID(consensus.ShardID))}, host.ConstructP2pMessage(byte(17), msgToSend)); err != nil {
consensus.getLogger().Warn("[OnAnnounce] Cannot send prepare message")
} else {
consensus.getLogger().Info("[OnAnnounce] Sent Prepare Message!!", "BlockHash", block.Hash(), "BlockNum", block.NumberU64())
consensus.getLogger().Info("[OnAnnounce] Sent Prepare Message!!", "BlockHash", hex.EncodeToString(consensus.blockHash[:]))
}
consensus.getLogger().Debug("[Announce] Switching Phase", "From", consensus.phase, "To", Prepare)
consensus.switchPhase(Prepare, true)
}
// TODO: move to consensus_leader.go later
@ -284,7 +284,8 @@ func (consensus *Consensus) onPrepare(msg *msg_pb.Message) {
prepareSigs[validatorPubKey] = &sign
// Set the bitmap indicating that this validator signed.
if err := prepareBitmap.SetKey(recvMsg.SenderPubkey, true); err != nil {
ctxerror.Warn(consensus.getLogger(), err, "[OnPrepare] prepareBitmap.SetKey failed")
consensus.getLogger().Warn("[OnPrepare] prepareBitmap.SetKey failed", "error", err)
return
}
if len(prepareSigs) >= consensus.Quorum() {
@ -293,7 +294,7 @@ func (consensus *Consensus) onPrepare(msg *msg_pb.Message) {
msgToSend, aggSig := consensus.constructPreparedMessage()
consensus.aggregatedPrepareSig = aggSig
// add prepared message to log
//leader adds prepared message to log
msgPayload, _ := proto.GetConsensusMessagePayload(msgToSend)
msg := &msg_pb.Message{}
_ = protobuf.Unmarshal(msgPayload, msg)
@ -304,14 +305,6 @@ func (consensus *Consensus) onPrepare(msg *msg_pb.Message) {
}
consensus.pbftLog.AddMessage(pbftMsg)
if err := consensus.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(p2p.ShardID(consensus.ShardID))}, host.ConstructP2pMessage(byte(17), msgToSend)); err != nil {
consensus.getLogger().Warn("[OnPrepare] Cannot send prepared message")
} else {
consensus.getLogger().Debug("[OnPrepare] Sent Prepared Message!!", "BlockHash", consensus.blockHash, "BlockNum", consensus.blockNum)
}
consensus.getLogger().Debug("[OnPrepare] Switching phase", "From", consensus.phase, "To", Commit)
consensus.switchPhase(Commit, true)
// Leader add commit phase signature
blockNumHash := make([]byte, 8)
binary.LittleEndian.PutUint64(blockNumHash, consensus.blockNum)
@ -319,7 +312,16 @@ func (consensus *Consensus) onPrepare(msg *msg_pb.Message) {
consensus.commitSigs[consensus.PubKey.SerializeToHexStr()] = consensus.priKey.SignHash(commitPayload)
if err := consensus.commitBitmap.SetKey(consensus.PubKey, true); err != nil {
consensus.getLogger().Debug("[OnPrepare] Leader commit bitmap set failed")
return
}
if err := consensus.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(p2p.ShardID(consensus.ShardID))}, host.ConstructP2pMessage(byte(17), msgToSend)); err != nil {
consensus.getLogger().Warn("[OnPrepare] Cannot send prepared message")
} else {
consensus.getLogger().Debug("[OnPrepare] Sent Prepared Message!!", "BlockHash", consensus.blockHash, "BlockNum", consensus.blockNum)
}
consensus.getLogger().Debug("[OnPrepare] Switching phase", "From", consensus.phase, "To", Commit)
consensus.switchPhase(Commit, true)
}
return
}
@ -357,22 +359,17 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
return
}
// check validity of prepared signature
blockHash := recvMsg.BlockHash
aggSig, mask, err := consensus.readSignatureBitmapPayload(recvMsg.Payload, 0)
if err != nil {
consensus.getLogger().Error("ReadSignatureBitmapPayload failed!!", "error", err)
return
}
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
// check has 2f+1 signatures
if count := utils.CountOneBits(mask.Bitmap); count < consensus.Quorum() {
consensus.getLogger().Debug("Not enough signatures in the Prepared msg", "Need", consensus.Quorum(), "Got", count)
return
}
if !aggSig.VerifyHash(mask.AggregatePublic, blockHash[:]) {
myBlockHash := common.Hash{}
myBlockHash.SetBytes(consensus.blockHash[:])
@ -380,16 +377,49 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
return
}
consensus.getLogger().Debug("[OnPrepared] Prepared message added", "MsgViewID", recvMsg.ViewID, "MsgBlockNum", recvMsg.BlockNum)
// check validity of block
block := recvMsg.Block
var blockObj types.Block
err = rlp.DecodeBytes(block, &blockObj)
if err != nil {
consensus.getLogger().Warn("[OnPrepared] Unparseable block header data", "error", err, "MsgBlockNum", recvMsg.BlockNum)
return
}
if blockObj.NumberU64() != recvMsg.BlockNum || recvMsg.BlockNum < consensus.blockNum {
consensus.getLogger().Warn("[OnPrepared] BlockNum not match", "MsgBlockNum", recvMsg.BlockNum, "blockNum", blockObj.NumberU64())
return
}
if blockObj.Header().Hash() != recvMsg.BlockHash {
consensus.getLogger().Warn("[OnPrepared] BlockHash not match", "MsgBlockNum", recvMsg.BlockNum, "MsgBlockHash", recvMsg.BlockHash, "blockObjHash", blockObj.Header().Hash())
return
}
if consensus.mode.Mode() == Normal {
if err := consensus.VerifyHeader(consensus.ChainReader, blockObj.Header(), false); err != nil {
consensus.getLogger().Warn("[OnPrepared] Block header is not verified successfully", "error", err, "inChain", consensus.ChainReader.CurrentHeader().Number, "MsgBlockNum", blockObj.Header().Number)
return
}
if consensus.BlockVerifier == nil {
// do nothing
} else if err := consensus.BlockVerifier(&blockObj); err != nil {
consensus.getLogger().Info("[OnPrepared] Block verification faied")
return
}
}
consensus.pbftLog.AddBlock(&blockObj)
recvMsg.Block = []byte{} // save memory space
consensus.pbftLog.AddMessage(recvMsg)
consensus.getLogger().Debug("[OnPrepared] Prepared message and block added", "MsgViewID", recvMsg.ViewID, "MsgBlockNum", recvMsg.BlockNum, "blockHash", recvMsg.BlockHash)
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.tryCatchup()
if consensus.mode.Mode() == ViewChanging {
consensus.getLogger().Debug("[OnPrepared] Exiting after viewchange!!")
consensus.getLogger().Debug("[OnPrepared] Still in ViewChanging mode, Exiting !!")
return
}
consensus.tryCatchup()
if consensus.checkViewID(recvMsg) != nil {
consensus.getLogger().Debug("[OnPrepared] ViewID check failed", "MsgViewID", recvMsg.ViewID, "MsgBlockNum", recvMsg.BlockNum)
return
@ -400,10 +430,16 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
return
}
// add block field
blockPayload := make([]byte, len(block))
copy(blockPayload[:], block[:])
consensus.block = blockPayload
// add preparedSig field
consensus.aggregatedPrepareSig = aggSig
consensus.prepareBitmap = mask
// Optimistically sign on the blockhash of prepare message
// Optimistically add blockhash field of prepare message
emptyHash := [32]byte{}
if bytes.Compare(consensus.blockHash[:], emptyHash[:]) == 0 {
copy(consensus.blockHash[:], blockHash[:])
@ -512,7 +548,8 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) {
commitSigs[validatorPubKey] = &sign
// Set the bitmap indicating that this validator signed.
if err := commitBitmap.SetKey(recvMsg.SenderPubkey, true); err != nil {
ctxerror.Warn(consensus.getLogger(), err, "[OnCommit] commitBitmap.SetKey failed")
consensus.getLogger().Warn("[OnCommit] commitBitmap.SetKey failed", "error", err)
return
}
quorumIsMet := len(commitSigs) >= consensus.Quorum()
@ -538,47 +575,49 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) {
func (consensus *Consensus) finalizeCommits() {
consensus.getLogger().Info("[Finalizing] Finalizing Block", "NumCommits", len(consensus.commitSigs))
// Construct and broadcast committed message
msgToSend, aggSig := consensus.constructCommittedMessage()
consensus.aggregatedCommitSig = aggSig
beforeCatchupNum := consensus.blockNum
beforeCatchupViewID := consensus.viewID
if err := consensus.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(p2p.ShardID(consensus.ShardID))}, host.ConstructP2pMessage(byte(17), msgToSend)); err != nil {
ctxerror.Warn(consensus.getLogger(), err, "[Finalizing] Cannot send committed message")
} else {
consensus.getLogger().Debug("[Finalizing] Sent Committed Message", "BlockHash", consensus.blockHash, "BlockNum", consensus.blockNum)
}
// Construct committed message
msgToSend, aggSig := consensus.constructCommittedMessage()
consensus.aggregatedCommitSig = aggSig // this may not needed
consensus.getLogger().Debug("[Finalizing] Switching phase", "From", consensus.phase, "To", Announce)
consensus.switchPhase(Announce, true)
var blockObj types.Block
err := rlp.DecodeBytes(consensus.block, &blockObj)
// leader adds committed message to log
msgPayload, _ := proto.GetConsensusMessagePayload(msgToSend)
msg := &msg_pb.Message{}
_ = protobuf.Unmarshal(msgPayload, msg)
pbftMsg, err := ParsePbftMessage(msg)
if err != nil {
consensus.getLogger().Debug("[Finalizing] failed to construct the new block after consensus")
consensus.getLogger().Warn("[FinalizeCommits] Unable to parse pbft message", "error", err)
return
}
consensus.pbftLog.AddMessage(pbftMsg)
// Sign the block
blockObj.SetPrepareSig(
consensus.aggregatedPrepareSig.Serialize(),
consensus.prepareBitmap.Bitmap)
blockObj.SetCommitSig(
consensus.aggregatedCommitSig.Serialize(),
consensus.commitBitmap.Bitmap)
select {
case consensus.VerifiedNewBlock <- &blockObj:
default:
consensus.getLogger().Info("[SYNC] Failed to send consensus verified block for state sync", "blockHash", blockObj.Hash())
// find correct block content
block := consensus.pbftLog.GetBlockByHash(consensus.blockHash)
if block == nil {
consensus.getLogger().Warn("[FinalizeCommits] Cannot find block by hash", "blockHash", hex.EncodeToString(consensus.blockHash[:]))
return
}
consensus.tryCatchup()
if consensus.blockNum-beforeCatchupNum != 1 {
consensus.getLogger().Warn("[FinalizeCommits] Leader cannot provide the correct block for committed message", "beforeCatchupBlockNum", beforeCatchupNum)
return
}
// if leader success finalize the block, send committed message to validators
if err := consensus.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(p2p.ShardID(consensus.ShardID))}, host.ConstructP2pMessage(byte(17), msgToSend)); err != nil {
consensus.getLogger().Warn("[Finalizing] Cannot send committed message", "error", err)
} else {
consensus.getLogger().Debug("[Finalizing] Sent Committed Message", "BlockHash", consensus.blockHash, "BlockNum", consensus.blockNum)
}
consensus.reportMetrics(blockObj)
// Dump new block into level db.
explorer.GetStorageInstance(consensus.leader.IP, consensus.leader.Port, true).Dump(&blockObj, consensus.viewID)
consensus.reportMetrics(*block)
// Reset state to Finished, and clear other data.
consensus.ResetState()
consensus.viewID++
consensus.blockNum++
// Dump new block into level db
// In current code, we add signatures in block in tryCatchup, the block dump to explorer does not contains signatures
// but since explorer doesn't need signatures, it should be fine
// in future, we will move signatures to next block
explorer.GetStorageInstance(consensus.leader.IP, consensus.leader.Port, true).Dump(block, beforeCatchupViewID)
if consensus.consensusTimeout[timeoutBootstrap].IsActive() {
consensus.consensusTimeout[timeoutBootstrap].Stop()
@ -588,8 +627,7 @@ func (consensus *Consensus) finalizeCommits() {
}
consensus.consensusTimeout[timeoutConsensus].Start()
consensus.OnConsensusDone(&blockObj)
consensus.getLogger().Info("HOORAY!!!!!!! CONSENSUS REACHED!!!!!!!", "numOfSignatures", len(consensus.commitSigs), "BlockNum", consensus.blockNum-1, "ViewId", consensus.viewID-1, "BlockHash", blockObj.Hash())
consensus.getLogger().Info("HOORAY!!!!!!! CONSENSUS REACHED!!!!!!!", "BlockNum", beforeCatchupNum, "ViewId", beforeCatchupViewID, "BlockHash", block.Hash(), "index", consensus.getIndexOfPubKey(consensus.PubKey))
// TODO: wait for validators receive committed message; remove this temporary delay
time.Sleep(time.Second)
@ -649,13 +687,14 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) {
return
}
consensus.pbftLog.AddMessage(recvMsg)
consensus.getLogger().Debug("[OnCommitted] Committed message added", "MsgViewID", recvMsg.ViewID, "MsgBlockNum", recvMsg.BlockNum)
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.aggregatedCommitSig = aggSig
consensus.commitBitmap = mask
consensus.getLogger().Debug("[OnCommitted] Committed message added", "MsgViewID", recvMsg.ViewID, "MsgBlockNum", recvMsg.BlockNum)
consensus.pbftLog.AddMessage(recvMsg)
if recvMsg.BlockNum-consensus.blockNum > consensusBlockNumBuffer {
consensus.getLogger().Debug("[OnCommitted] out of sync", "MsgBlockNum", recvMsg.BlockNum)
@ -678,6 +717,10 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) {
// }
consensus.tryCatchup()
if consensus.mode.Mode() == ViewChanging {
consensus.getLogger().Debug("[OnCommitted] Still in ViewChanging mode, Exiting !!")
return
}
if consensus.consensusTimeout[timeoutBootstrap].IsActive() {
consensus.consensusTimeout[timeoutBootstrap].Stop()

@ -27,6 +27,7 @@ type PbftMessage struct {
ViewID uint32
BlockNum uint64
BlockHash common.Hash
Block []byte
SenderPubkey *bls.PublicKey
LeaderPubkey *bls.PublicKey
Payload []byte
@ -217,6 +218,9 @@ func ParsePbftMessage(msg *msg_pb.Message) (*PbftMessage, error) {
copy(pbftMsg.BlockHash[:], consensusMsg.BlockHash[:])
pbftMsg.Payload = make([]byte, len(consensusMsg.Payload))
copy(pbftMsg.Payload[:], consensusMsg.Payload[:])
pbftMsg.Block = make([]byte, len(consensusMsg.Block))
copy(pbftMsg.Block[:], consensusMsg.Block[:])
pubKey, err := bls_cosi.BytesToBlsPublicKey(consensusMsg.SenderPubkey)
if err != nil {
return nil, err

@ -367,6 +367,10 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
binary.LittleEndian.PutUint64(blockNumBytes, consensus.blockNum)
commitPayload := append(blockNumBytes, consensus.blockHash[:]...)
consensus.commitSigs[consensus.PubKey.SerializeToHexStr()] = consensus.priKey.SignHash(commitPayload)
if err = consensus.commitBitmap.SetKey(consensus.PubKey, true); err != nil {
consensus.getLogger().Debug("[OnViewChange] New Leader commit bitmap set failed")
return
}
}
consensus.mode.SetViewID(recvMsg.ViewID)

Loading…
Cancel
Save