Fix consensus stability

pull/1053/head
Rongjian Lan 5 years ago
parent 1fbfa61bfa
commit 23cdabc182
  1. 173
      api/proto/message/message.pb.go
  2. 33
      api/proto/message/message.proto
  3. 3
      api/service/syncing/syncing.go
  4. 1
      consensus/consensus_service.go
  5. 18
      consensus/consensus_v2.go
  6. 6
      drand/drand_leader.go
  7. 1
      drand/drand_leader_msg.go
  8. 2
      drand/drand_validator_msg.go
  9. 7
      node/node_handler.go
  10. 22
      node/node_newblock.go

@ -523,9 +523,10 @@ func (m *StakingRequest) GetNodeId() string {
type ConsensusRequest struct {
ViewId uint32 `protobuf:"varint,1,opt,name=view_id,json=viewId,proto3" json:"view_id,omitempty"`
BlockNum uint64 `protobuf:"varint,2,opt,name=block_num,json=blockNum,proto3" json:"block_num,omitempty"`
BlockHash []byte `protobuf:"bytes,3,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"`
SenderPubkey []byte `protobuf:"bytes,4,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"`
Payload []byte `protobuf:"bytes,5,opt,name=payload,proto3" json:"payload,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"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -570,6 +571,13 @@ func (m *ConsensusRequest) GetBlockNum() uint64 {
return 0
}
func (m *ConsensusRequest) GetShardId() uint32 {
if m != nil {
return m.ShardId
}
return 0
}
func (m *ConsensusRequest) GetBlockHash() []byte {
if m != nil {
return m.BlockHash
@ -592,9 +600,10 @@ func (m *ConsensusRequest) GetPayload() []byte {
}
type DrandRequest struct {
SenderPubkey []byte `protobuf:"bytes,1,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"`
BlockHash []byte `protobuf:"bytes,2,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"`
Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
ShardId uint32 `protobuf:"varint,1,opt,name=shard_id,json=shardId,proto3" json:"shard_id,omitempty"`
SenderPubkey []byte `protobuf:"bytes,2,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"`
BlockHash []byte `protobuf:"bytes,3,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"`
Payload []byte `protobuf:"bytes,4,opt,name=payload,proto3" json:"payload,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -625,6 +634,13 @@ func (m *DrandRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_DrandRequest proto.InternalMessageInfo
func (m *DrandRequest) GetShardId() uint32 {
if m != nil {
return m.ShardId
}
return 0
}
func (m *DrandRequest) GetSenderPubkey() []byte {
if m != nil {
return m.SenderPubkey
@ -649,17 +665,18 @@ func (m *DrandRequest) GetPayload() []byte {
type ViewChangeRequest struct {
ViewId uint32 `protobuf:"varint,1,opt,name=view_id,json=viewId,proto3" json:"view_id,omitempty"`
BlockNum uint64 `protobuf:"varint,2,opt,name=block_num,json=blockNum,proto3" json:"block_num,omitempty"`
SenderPubkey []byte `protobuf:"bytes,3,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"`
LeaderPubkey []byte `protobuf:"bytes,4,opt,name=leader_pubkey,json=leaderPubkey,proto3" json:"leader_pubkey,omitempty"`
Payload []byte `protobuf:"bytes,5,opt,name=payload,proto3" json:"payload,omitempty"`
ViewchangeSig []byte `protobuf:"bytes,6,opt,name=viewchange_sig,json=viewchangeSig,proto3" json:"viewchange_sig,omitempty"`
ViewidSig []byte `protobuf:"bytes,7,opt,name=viewid_sig,json=viewidSig,proto3" json:"viewid_sig,omitempty"`
ShardId uint32 `protobuf:"varint,3,opt,name=shard_id,json=shardId,proto3" json:"shard_id,omitempty"`
SenderPubkey []byte `protobuf:"bytes,4,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"`
LeaderPubkey []byte `protobuf:"bytes,5,opt,name=leader_pubkey,json=leaderPubkey,proto3" json:"leader_pubkey,omitempty"`
Payload []byte `protobuf:"bytes,6,opt,name=payload,proto3" json:"payload,omitempty"`
ViewchangeSig []byte `protobuf:"bytes,7,opt,name=viewchange_sig,json=viewchangeSig,proto3" json:"viewchange_sig,omitempty"`
ViewidSig []byte `protobuf:"bytes,8,opt,name=viewid_sig,json=viewidSig,proto3" json:"viewid_sig,omitempty"`
// below is for newview message only
// only need 1 valid m1 type message which is in payload
M2Aggsigs []byte `protobuf:"bytes,8,opt,name=m2_aggsigs,json=m2Aggsigs,proto3" json:"m2_aggsigs,omitempty"`
M2Bitmap []byte `protobuf:"bytes,9,opt,name=m2_bitmap,json=m2Bitmap,proto3" json:"m2_bitmap,omitempty"`
M3Aggsigs []byte `protobuf:"bytes,10,opt,name=m3_aggsigs,json=m3Aggsigs,proto3" json:"m3_aggsigs,omitempty"`
M3Bitmap []byte `protobuf:"bytes,11,opt,name=m3_bitmap,json=m3Bitmap,proto3" json:"m3_bitmap,omitempty"`
M2Aggsigs []byte `protobuf:"bytes,9,opt,name=m2_aggsigs,json=m2Aggsigs,proto3" json:"m2_aggsigs,omitempty"`
M2Bitmap []byte `protobuf:"bytes,10,opt,name=m2_bitmap,json=m2Bitmap,proto3" json:"m2_bitmap,omitempty"`
M3Aggsigs []byte `protobuf:"bytes,11,opt,name=m3_aggsigs,json=m3Aggsigs,proto3" json:"m3_aggsigs,omitempty"`
M3Bitmap []byte `protobuf:"bytes,12,opt,name=m3_bitmap,json=m3Bitmap,proto3" json:"m3_bitmap,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -704,6 +721,13 @@ func (m *ViewChangeRequest) GetBlockNum() uint64 {
return 0
}
func (m *ViewChangeRequest) GetShardId() uint32 {
if m != nil {
return m.ShardId
}
return 0
}
func (m *ViewChangeRequest) GetSenderPubkey() []byte {
if m != nil {
return m.SenderPubkey
@ -784,65 +808,66 @@ func init() {
func init() { proto.RegisterFile("message.proto", fileDescriptor_33c57e4bae7b9afd) }
var fileDescriptor_33c57e4bae7b9afd = []byte{
// 914 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x95, 0xcd, 0x8e, 0xe2, 0x46,
0x10, 0xc7, 0x31, 0x30, 0x18, 0x97, 0x0d, 0xd3, 0xdb, 0x49, 0x76, 0x9d, 0xc9, 0x46, 0x19, 0xb1,
0x8a, 0x34, 0x5a, 0x29, 0xa3, 0x15, 0x1c, 0xa2, 0x48, 0xb9, 0x30, 0xa6, 0xb5, 0x58, 0x33, 0x63,
0x48, 0x63, 0x76, 0x94, 0x93, 0x65, 0xa0, 0xc5, 0x58, 0x63, 0x6c, 0xe2, 0x36, 0xb3, 0xe2, 0x85,
0x72, 0xc9, 0x3d, 0xe7, 0xe4, 0x79, 0xf2, 0x12, 0x51, 0xb7, 0x6d, 0xcc, 0xc7, 0x46, 0x91, 0x72,
0xc8, 0x8d, 0xfa, 0x57, 0xfd, 0xaa, 0xab, 0xcb, 0x5d, 0x05, 0xb4, 0x56, 0x8c, 0x73, 0x7f, 0xc9,
0xae, 0xd7, 0x49, 0x9c, 0xc6, 0x58, 0xcd, 0xcd, 0xce, 0xef, 0x35, 0x50, 0xef, 0xb3, 0xdf, 0xf8,
0x7b, 0x30, 0x38, 0x4b, 0x9e, 0x83, 0x39, 0xf3, 0xd2, 0xed, 0x9a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0xae, 0x8f, 0x00, 0x23, 0xb0, 0x75,
0x9c, 0xaf, 0x66, 0xe1, 0x2f, 0xe0, 0xf8, 0x66, 0xe8, 0xfb, 0x84, 0xfe, 0x12, 0x50, 0xf2, 0xf3,
0x1d, 0x19, 0xfb, 0xc8, 0xee, 0xf4, 0xa0, 0xd9, 0x9f, 0x45, 0x3c, 0xce, 0x72, 0x4f, 0xf0, 0x7b,
0x30, 0x47, 0x69, 0x32, 0xe1, 0x42, 0x60, 0xb4, 0xff, 0x66, 0x9f, 0xbc, 0xd8, 0x28, 0xeb, 0x67,
0xb5, 0x5d, 0x7a, 0xa8, 0xa9, 0xff, 0xfd, 0xee, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x60,
0x9a, 0xe1, 0x08, 0x08, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.

@ -82,31 +82,34 @@ message StakingRequest {
message ConsensusRequest {
uint32 view_id = 1;
uint64 block_num = 2;
bytes block_hash = 3;
bytes sender_pubkey = 4;
bytes payload = 5;
uint32 shard_id = 3;
bytes block_hash = 4;
bytes sender_pubkey = 5;
bytes payload = 6;
}
message DrandRequest {
bytes sender_pubkey = 1;
bytes block_hash = 2;
bytes payload = 3;
uint32 shard_id = 1;
bytes sender_pubkey = 2;
bytes block_hash = 3;
bytes payload = 4;
}
message ViewChangeRequest {
uint32 view_id = 1;
uint64 block_num = 2;
bytes sender_pubkey = 3;
bytes leader_pubkey = 4;
bytes payload = 5; // message payload: either m1 type or m2 type
bytes viewchange_sig = 6; // signature on payload
bytes viewid_sig = 7; // signature on view_id
uint32 shard_id = 3;
bytes sender_pubkey = 4;
bytes leader_pubkey = 5;
bytes payload = 6; // message payload: either m1 type or m2 type
bytes viewchange_sig = 7; // signature on payload
bytes viewid_sig = 8; // signature on view_id
// below is for newview message only
// only need 1 valid m1 type message which is in payload
bytes m2_aggsigs = 8; // m2: |nil|
bytes m2_bitmap = 9;
bytes m3_aggsigs = 10; // m3: |viewID|
bytes m3_bitmap= 11;
bytes m2_aggsigs = 9; // m2: |nil|
bytes m2_bitmap = 10;
bytes m3_aggsigs = 11; // m3: |viewID|
bytes m3_bitmap= 12;
}

@ -476,6 +476,9 @@ func (ss *StateSync) updateBlockAndStatus(block *types.Block, bc *core.BlockChai
_, err := bc.InsertChain([]*types.Block{block})
if err != nil {
utils.GetLogInstance().Debug("Error adding new block to blockchain", "Error", err)
utils.GetLogInstance().Debug("Rolling back current block!", "block", bc.CurrentBlock())
bc.Rollback([]common.Hash{bc.CurrentBlock().Hash()})
return false
}
ss.syncMux.Lock()

@ -101,6 +101,7 @@ func (consensus *Consensus) Prepare(chain consensus_engine.ChainReader, header *
func (consensus *Consensus) populateMessageFields(request *msg_pb.ConsensusRequest) {
request.ViewId = consensus.viewID
request.BlockNum = consensus.blockNum
request.ShardId = consensus.ShardID
// 32 byte block hash
request.BlockHash = consensus.blockHash[:]

@ -37,6 +37,11 @@ func (consensus *Consensus) handleMessageUpdate(payload []byte) {
return
}
if msg.GetConsensus().ShardId != consensus.ShardID {
consensus.getLogger().Warn("Received consensus message from different shard",
"myShardId", consensus.ShardID, "receivedShardId", msg.GetConsensus().ShardId)
return
}
switch msg.Type {
case msg_pb.MessageType_ANNOUNCE:
consensus.onAnnounce(msg)
@ -57,14 +62,14 @@ func (consensus *Consensus) handleMessageUpdate(payload []byte) {
}
// TODO: move to consensus_leader.go later
func (consensus *Consensus) tryAnnounce(block *types.Block) {
func (consensus *Consensus) announce(block *types.Block) {
blockHash := block.Hash()
copy(consensus.blockHash[:], blockHash[:])
// prepare message and broadcast to validators
encodedBlock, err := rlp.EncodeToBytes(block)
if err != nil {
consensus.getLogger().Debug("tryAnnounce Failed encoding block")
consensus.getLogger().Debug("announce Failed encoding block")
return
}
consensus.block = encodedBlock
@ -77,7 +82,7 @@ func (consensus *Consensus) tryAnnounce(block *types.Block) {
_ = protobuf.Unmarshal(msgPayload, msg)
pbftMsg, err := ParsePbftMessage(msg)
if err != nil {
consensus.getLogger().Warn("tryAnnounce unable to parse pbft message", "error", err)
consensus.getLogger().Warn("announce unable to parse pbft message", "error", err)
return
}
@ -174,13 +179,13 @@ func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) {
consensus.getLogger().Debug("viewID check failed", "msgViewID", recvMsg.ViewID, "msgBlockNum", recvMsg.BlockNum)
return
}
consensus.tryPrepare(&blockObj)
consensus.prepare(&blockObj)
return
}
// tryPrepare will try to send prepare message
func (consensus *Consensus) tryPrepare(block *types.Block) {
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
@ -780,7 +785,6 @@ func (consensus *Consensus) Start(blockChannel chan *types.Block, stopChan chan
break
}
}
case <-consensus.syncReadyChan:
consensus.SetBlockNum(consensus.ChainReader.CurrentHeader().Number.Uint64() + 1)
consensus.ignoreViewIDCheck = true
@ -817,7 +821,7 @@ func (consensus *Consensus) Start(blockChannel chan *types.Block, stopChan chan
startTime = time.Now()
consensus.getLogger().Debug("STARTING CONSENSUS", "numTxs", len(newBlock.Transactions()), "consensus", consensus, "startTime", startTime, "publicKeys", len(consensus.PublicKeys))
consensus.tryAnnounce(newBlock)
consensus.announce(newBlock)
case msg := <-consensus.MsgChan:
consensus.handleMessageUpdate(msg)

@ -89,6 +89,12 @@ func (dRand *DRand) ProcessMessageLeader(payload []byte) {
utils.GetLogInstance().Error("Failed to unmarshal message payload.", "err", err, "dRand", dRand)
}
if message.GetDrand().ShardId != dRand.ShardID {
utils.GetLogInstance().Warn("Received drand message from different shard",
"myShardId", dRand.ShardID, "receivedShardId", message.GetDrand().ShardId)
return
}
switch message.Type {
case msg_pb.MessageType_DRAND_COMMIT:
dRand.processCommitMessage(message)

@ -19,6 +19,7 @@ func (dRand *DRand) constructInitMessage() []byte {
drandMsg := message.GetDrand()
drandMsg.SenderPubkey = dRand.pubKey.Serialize()
drandMsg.BlockHash = dRand.blockHash[:]
drandMsg.ShardId = dRand.ShardID
// Don't need the payload in init message
marshaledMessage, err := dRand.signAndMarshalDRandMessage(message)
if err != nil {

@ -19,7 +19,7 @@ func (dRand *DRand) constructCommitMessage(vrf [32]byte, proof []byte) []byte {
drandMsg := message.GetDrand()
drandMsg.SenderPubkey = dRand.pubKey.Serialize()
drandMsg.BlockHash = dRand.blockHash[:]
drandMsg.BlockHash = dRand.blockHash[:]
drandMsg.ShardId = dRand.ShardID
drandMsg.Payload = append(vrf[:], proof...)
// Adding the public key into payload so leader can verify the vrf
// TODO: change the curve to follow the same curve with consensus, so the public key doesn't need to be attached.

@ -805,10 +805,5 @@ func getBinaryPath() (argv0 string, err error) {
// ConsensusMessageHandler passes received message in node_handler to consensus
func (node *Node) ConsensusMessageHandler(msgPayload []byte) {
select {
case node.Consensus.MsgChan <- msgPayload:
case <-time.After(consensusTimeout):
//utils.GetLogInstance().Debug("[Consensus] ConsensusMessageHandler timeout", "duration", consensusTimeout, "msgPayload", len(msgPayload))
}
return
node.Consensus.MsgChan <- msgPayload
}

@ -17,7 +17,7 @@ import (
const (
DefaultThreshold = 1
FirstTimeThreshold = 2
ConsensusTimeOut = 10
ConsensusTimeOut = 30
PeriodicBlock = 1 * time.Second
BlockPeriod = 10 * time.Second
)
@ -34,13 +34,22 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch
time.Sleep(30 * time.Second) // Wait for other nodes to be ready (test-only)
firstTime := true
timeoutCount := 0
var newBlock *types.Block
for {
// keep waiting for Consensus ready
select {
case <-stopChan:
utils.GetLogInstance().Debug("Consensus propose new block: STOPPED!")
utils.GetLogInstance().Debug("Consensus new block proposal: STOPPED!")
return
case <-time.After(ConsensusTimeOut * time.Second):
node.Consensus.ResetState()
timeoutCount++
if newBlock != nil {
utils.GetLogInstance().Debug("Consensus timeout, retry!", "count", timeoutCount)
// Send the new block to Consensus so it can be confirmed.
node.BlockChannel <- newBlock
}
case <-readySignal:
firstTry := true
deadline := time.Now().Add(BlockPeriod)
@ -68,19 +77,18 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch
ctxerror.New("cannot commit transactions").
WithCause(err))
}
block, err := node.Worker.Commit()
newBlock, err := node.Worker.Commit()
if err != nil {
ctxerror.Log15(utils.GetLogger().Error,
ctxerror.New("cannot commit new block").
WithCause(err))
continue
} else if err := node.proposeShardState(block); err != nil {
} else if err := node.proposeShardState(newBlock); err != nil {
ctxerror.Log15(utils.GetLogger().Error,
ctxerror.New("cannot add shard state").
WithCause(err))
} else {
newBlock := block
utils.GetLogInstance().Debug("Successfully proposed new block", "blockNum", block.NumberU64(), "numTxs", block.Transactions().Len())
utils.GetLogInstance().Debug("Successfully proposed new block", "blockNum", newBlock.NumberU64(), "numTxs", newBlock.Transactions().Len())
// Send the new block to Consensus so it can be confirmed.
node.BlockChannel <- newBlock

Loading…
Cancel
Save