|
|
@ -177,20 +177,6 @@ func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: remove it after shard0 fix
|
|
|
|
|
|
|
|
if consensus.NeedsBlockRecovery(recvMsg.BlockNum) { |
|
|
|
|
|
|
|
consensus.getLogger().Debug(). |
|
|
|
|
|
|
|
Uint64("MsgViewID", recvMsg.ViewID). |
|
|
|
|
|
|
|
Uint64("MsgBlockNum", recvMsg.BlockNum). |
|
|
|
|
|
|
|
Msg("[OnAnnounce] Announce message Added") |
|
|
|
|
|
|
|
consensus.PbftLog.AddMessage(recvMsg) |
|
|
|
|
|
|
|
consensus.mutex.Lock() |
|
|
|
|
|
|
|
defer consensus.mutex.Unlock() |
|
|
|
|
|
|
|
consensus.blockHash = recvMsg.BlockHash |
|
|
|
|
|
|
|
consensus.prepare() |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// verify validity of block header object
|
|
|
|
// verify validity of block header object
|
|
|
|
blockHeader := recvMsg.Payload |
|
|
|
blockHeader := recvMsg.Payload |
|
|
|
var headerObj types.Header |
|
|
|
var headerObj types.Header |
|
|
@ -439,56 +425,6 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) { |
|
|
|
Uint64("MsgViewID", recvMsg.ViewID). |
|
|
|
Uint64("MsgViewID", recvMsg.ViewID). |
|
|
|
Msg("[OnPrepared] Received prepared message") |
|
|
|
Msg("[OnPrepared] Received prepared message") |
|
|
|
|
|
|
|
|
|
|
|
// TODO: remove it after fix
|
|
|
|
|
|
|
|
if consensus.NeedsBlockRecovery(recvMsg.BlockNum) { |
|
|
|
|
|
|
|
block := recvMsg.Block |
|
|
|
|
|
|
|
var blockObj types.Block |
|
|
|
|
|
|
|
err = rlp.DecodeBytes(block, &blockObj) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
consensus.getLogger().Warn(). |
|
|
|
|
|
|
|
Err(err). |
|
|
|
|
|
|
|
Uint64("MsgBlockNum", recvMsg.BlockNum). |
|
|
|
|
|
|
|
Msg("[OnPrepared] Unparseable block header data") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
consensus.PbftLog.AddBlock(&blockObj) |
|
|
|
|
|
|
|
recvMsg.Block = []byte{} // save memory space
|
|
|
|
|
|
|
|
consensus.PbftLog.AddMessage(recvMsg) |
|
|
|
|
|
|
|
consensus.getLogger().Debug(). |
|
|
|
|
|
|
|
Uint64("MsgViewID", recvMsg.ViewID). |
|
|
|
|
|
|
|
Uint64("MsgBlockNum", recvMsg.BlockNum). |
|
|
|
|
|
|
|
Bytes("blockHash", recvMsg.BlockHash[:]). |
|
|
|
|
|
|
|
Msg("[OnPrepared] Prepared message and block added") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add block field
|
|
|
|
|
|
|
|
blockPayload := make([]byte, len(block)) |
|
|
|
|
|
|
|
copy(blockPayload[:], block[:]) |
|
|
|
|
|
|
|
consensus.block = blockPayload |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Construct and send the commit message
|
|
|
|
|
|
|
|
blockNumBytes := make([]byte, 8) |
|
|
|
|
|
|
|
binary.LittleEndian.PutUint64(blockNumBytes, consensus.blockNum) |
|
|
|
|
|
|
|
commitPayload := append(blockNumBytes, consensus.blockHash[:]...) |
|
|
|
|
|
|
|
msgToSend := consensus.constructCommitMessage(commitPayload) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := consensus.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(p2p.ShardID(consensus.ShardID))}, host.ConstructP2pMessage(byte(17), msgToSend)); err != nil { |
|
|
|
|
|
|
|
consensus.getLogger().Warn(). |
|
|
|
|
|
|
|
Msg("[OnPrepared] Cannot send commit message!!") |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
consensus.getLogger().Info(). |
|
|
|
|
|
|
|
Bytes("BlockHash", consensus.blockHash[:]). |
|
|
|
|
|
|
|
Uint64("BlockNum", consensus.blockNum). |
|
|
|
|
|
|
|
Msg("[OnPrepared] Sent Commit Message!!") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
consensus.getLogger().Debug(). |
|
|
|
|
|
|
|
Str("From", string(consensus.phase)). |
|
|
|
|
|
|
|
Str("To", string(Commit)). |
|
|
|
|
|
|
|
Msg("[OnPrepared] Switching phase") |
|
|
|
|
|
|
|
consensus.switchPhase(Commit, true) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if recvMsg.BlockNum < consensus.blockNum { |
|
|
|
if recvMsg.BlockNum < consensus.blockNum { |
|
|
|
consensus.getLogger().Debug().Uint64("MsgBlockNum", recvMsg.BlockNum).Msg("Old Block Received, ignoring!!") |
|
|
|
consensus.getLogger().Debug().Uint64("MsgBlockNum", recvMsg.BlockNum).Msg("Old Block Received, ignoring!!") |
|
|
|
return |
|
|
|
return |
|
|
@ -885,28 +821,6 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: remove it after fix
|
|
|
|
|
|
|
|
if consensus.NeedsBlockRecovery(recvMsg.BlockNum) { |
|
|
|
|
|
|
|
consensus.PbftLog.AddMessage(recvMsg) |
|
|
|
|
|
|
|
consensus.getLogger().Debug(). |
|
|
|
|
|
|
|
Uint64("MsgViewID", recvMsg.ViewID). |
|
|
|
|
|
|
|
Uint64("MsgBlockNum", recvMsg.BlockNum). |
|
|
|
|
|
|
|
Msg("[OnCommitted] Committed message added") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
consensus.tryCatchup() |
|
|
|
|
|
|
|
if consensus.consensusTimeout[timeoutBootstrap].IsActive() { |
|
|
|
|
|
|
|
consensus.consensusTimeout[timeoutBootstrap].Stop() |
|
|
|
|
|
|
|
consensus.getLogger().Debug(). |
|
|
|
|
|
|
|
Msg("[OnCommitted] Start consensus timer; stop bootstrap timer only once") |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
consensus.getLogger().Debug(). |
|
|
|
|
|
|
|
Msg("[OnCommitted] Start consensus timer") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
consensus.consensusTimeout[timeoutConsensus].Start() |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if recvMsg.BlockNum < consensus.blockNum { |
|
|
|
if recvMsg.BlockNum < consensus.blockNum { |
|
|
|
consensus.getLogger().Info(). |
|
|
|
consensus.getLogger().Info(). |
|
|
|
Uint64("MsgBlockNum", recvMsg.BlockNum). |
|
|
|
Uint64("MsgBlockNum", recvMsg.BlockNum). |
|
|
@ -1036,23 +950,6 @@ func (consensus *Consensus) tryCatchup() { |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if consensus.NeedsBlockRecovery(block.NumberU64()) && block.NumberU64() == consensus.ChainReader.CurrentHeader().Number.Uint64() { |
|
|
|
|
|
|
|
consensus.getLogger().Info().Msg("[TryCatchup] Skip Commit ReProposeBlock") |
|
|
|
|
|
|
|
consensus.blockNum = block.NumberU64() + 1 |
|
|
|
|
|
|
|
consensus.viewID = msgs[0].ViewID + 1 |
|
|
|
|
|
|
|
consensus.ResetState() |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if consensus.NeedsBlockRecovery(block.NumberU64()) && block.NumberU64() != consensus.ChainReader.CurrentHeader().Number.Uint64() { |
|
|
|
|
|
|
|
consensus.getLogger().Info().Msg("[TryCatchup] Commit ReProposeBlock") |
|
|
|
|
|
|
|
consensus.blockNum = block.NumberU64() + 1 |
|
|
|
|
|
|
|
consensus.viewID = msgs[0].ViewID + 1 |
|
|
|
|
|
|
|
consensus.OnConsensusDone(block) |
|
|
|
|
|
|
|
consensus.ResetState() |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if consensus.BlockVerifier == nil { |
|
|
|
if consensus.BlockVerifier == nil { |
|
|
|
// do nothing
|
|
|
|
// do nothing
|
|
|
|
} else if err := consensus.BlockVerifier(block); err != nil { |
|
|
|
} else if err := consensus.BlockVerifier(block); err != nil { |
|
|
|