Fix usage of private methods.

pull/4377/head
frozen 2 years ago committed by Casey Gardiner
parent cd97b99506
commit 9dabe14857
  1. 5
      consensus/checks.go
  2. 4
      consensus/consensus.go
  3. 13
      consensus/consensus_service.go
  4. 5
      consensus/consensus_v2.go
  5. 14
      consensus/debug.go
  6. 2
      consensus/validator.go
  7. 12
      consensus/view_change.go
  8. 10
      consensus/view_change_msg.go
  9. 15
      core/blockchain_impl.go

@ -56,9 +56,10 @@ func (consensus *Consensus) senderKeySanityChecks(msg *msg_pb.Message, senderKey
}
func (consensus *Consensus) isRightBlockNumAndViewID(recvMsg *FBFTMessage) bool {
if recvMsg.ViewID != consensus.GetCurBlockViewID() || recvMsg.BlockNum != consensus.BlockNum() {
blockNum := consensus.getBlockNum()
if recvMsg.ViewID != consensus.getCurBlockViewID() || recvMsg.BlockNum != blockNum {
consensus.getLogger().Debug().
Uint64("blockNum", consensus.BlockNum()).
Uint64("blockNum", blockNum).
Str("recvMsg", recvMsg.String()).
Msg("BlockNum/viewID not match")
return false

@ -224,6 +224,10 @@ func (consensus *Consensus) BlockNum() uint64 {
return atomic.LoadUint64(&consensus.blockNum)
}
func (consensus *Consensus) getBlockNum() uint64 {
return atomic.LoadUint64(&consensus.blockNum)
}
// New create a new Consensus record
func New(
host p2p.Host, shard uint32, multiBLSPriKey multibls.PrivateKeys,

@ -486,6 +486,8 @@ func (consensus *Consensus) isLeader() bool {
// SetViewIDs set both current view ID and view changing ID to the height
// of the blockchain. It is used during client startup to recover the state
func (consensus *Consensus) SetViewIDs(height uint64) {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.setViewIDs(height)
}
@ -625,11 +627,18 @@ func (consensus *Consensus) NumSignaturesIncludedInBlock(block *types.Block) uin
return count
}
// GetLogger returns logger for consensus contexts added.
func (consensus *Consensus) GetLogger() *zerolog.Logger {
consensus.mutex.RLock()
defer consensus.mutex.RUnlock()
return consensus.getLogger()
}
// getLogger returns logger for consensus contexts added
func (consensus *Consensus) getLogger() *zerolog.Logger {
logger := utils.Logger().With().
Uint64("myBlock", consensus.BlockNum()).
Uint64("myViewID", consensus.GetCurBlockViewID()).
Uint64("myBlock", consensus.blockNum).
Uint64("myViewID", consensus.getCurBlockViewID()).
Str("phase", consensus.phase.String()).
Str("mode", consensus.current.Mode().String()).
Logger()

@ -46,6 +46,8 @@ const (
// IsViewChangingMode return true if curernt mode is viewchanging
func (consensus *Consensus) IsViewChangingMode() bool {
consensus.mutex.RLock()
defer consensus.mutex.RUnlock()
return consensus.isViewChangingMode()
}
@ -413,8 +415,7 @@ func (consensus *Consensus) tick() {
}
func (consensus *Consensus) BlockChannel(newBlock *types.Block) {
//consensus.ReshardingNextLeader(newBlock)
consensus.getLogger().Info().
consensus.GetLogger().Info().
Uint64("MsgBlockNum", newBlock.NumberU64()).
Msg("[ConsensusMainLoop] Received Proposed New Block!")

@ -12,10 +12,24 @@ func (consensus *Consensus) GetConsensusMode() string {
// GetCurBlockViewID returns the current view ID of the consensus
func (consensus *Consensus) GetCurBlockViewID() uint64 {
consensus.mutex.RLock()
defer consensus.mutex.RUnlock()
return consensus.getCurBlockViewID()
}
// GetCurBlockViewID returns the current view ID of the consensus
func (consensus *Consensus) getCurBlockViewID() uint64 {
return consensus.current.GetCurBlockViewID()
}
// GetViewChangingID returns the current view changing ID of the consensus
func (consensus *Consensus) GetViewChangingID() uint64 {
consensus.mutex.RLock()
defer consensus.mutex.RUnlock()
return consensus.current.GetViewChangingID()
}
// GetViewChangingID returns the current view changing ID of the consensus
func (consensus *Consensus) getViewChangingID() uint64 {
return consensus.current.GetViewChangingID()
}

@ -277,7 +277,7 @@ func (consensus *Consensus) onPrepared(recvMsg *FBFTMessage) {
if committedMsg != nil {
consensus.onCommitted(committedMsg)
}
if curBlockNum < consensus.BlockNum() {
if curBlockNum < consensus.getBlockNum() {
consensus.getLogger().Info().Msg("[OnPrepared] Successfully caught up with committed message")
break
}

@ -253,7 +253,7 @@ func (consensus *Consensus) startViewChange() {
consensus.getLogger().Warn().
Uint64("nextViewID", nextViewID).
Uint64("viewChangingID", consensus.GetViewChangingID()).
Uint64("viewChangingID", consensus.getViewChangingID()).
Dur("timeoutDuration", duration).
Str("NextLeader", consensus.LeaderPubKey.Bytes.Hex()).
Msg("[startViewChange]")
@ -270,7 +270,7 @@ func (consensus *Consensus) startViewChange() {
if err := consensus.vc.InitPayload(
consensus.FBFTLog,
nextViewID,
consensus.BlockNum(),
consensus.getBlockNum(),
consensus.priKey,
members); err != nil {
consensus.getLogger().Error().Err(err).Msg("[startViewChange] Init Payload Error")
@ -284,7 +284,7 @@ func (consensus *Consensus) startViewChange() {
}
msgToSend := consensus.constructViewChangeMessage(&key)
if err := consensus.msgSender.SendWithRetry(
consensus.BlockNum(),
consensus.getBlockNum(),
msg_pb.MessageType_VIEWCHANGE,
[]nodeconfig.GroupID{
nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID))},
@ -310,7 +310,7 @@ func (consensus *Consensus) startNewView(viewID uint64, newLeaderPriKey *bls.Pri
}
if err := consensus.msgSender.SendWithRetry(
consensus.BlockNum(),
consensus.getBlockNum(),
msg_pb.MessageType_NEWVIEW,
[]nodeconfig.GroupID{
nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID))},
@ -450,10 +450,10 @@ func (consensus *Consensus) onNewView(recvMsg *FBFTMessage) {
Msg("[onNewView] Received NewView Message")
// change view and leaderKey to keep in sync with network
if consensus.BlockNum() != recvMsg.BlockNum {
if consensus.getBlockNum() != recvMsg.BlockNum {
consensus.getLogger().Warn().
Uint64("MsgBlockNum", recvMsg.BlockNum).
Uint64("myBlockNum", consensus.BlockNum()).
Uint64("myBlockNum", consensus.getBlockNum()).
Msg("[onNewView] Invalid block number")
return
}

@ -23,8 +23,8 @@ func (consensus *Consensus) constructViewChangeMessage(priKey *bls.PrivateKeyWra
Type: msg_pb.MessageType_VIEWCHANGE,
Request: &msg_pb.Message_Viewchange{
Viewchange: &msg_pb.ViewChangeRequest{
ViewId: consensus.GetViewChangingID(),
BlockNum: consensus.BlockNum(),
ViewId: consensus.getViewChangingID(),
BlockNum: consensus.getBlockNum(),
ShardId: consensus.ShardID,
SenderPubkey: priKey.Pub.Bytes[:],
LeaderPubkey: consensus.LeaderPubKey.Bytes[:],
@ -33,7 +33,7 @@ func (consensus *Consensus) constructViewChangeMessage(priKey *bls.PrivateKeyWra
}
preparedMsgs := consensus.FBFTLog.GetMessagesByTypeSeq(
msg_pb.MessageType_PREPARED, consensus.BlockNum(),
msg_pb.MessageType_PREPARED, consensus.getBlockNum(),
)
preparedMsg := consensus.FBFTLog.FindMessageByMaxViewID(preparedMsgs)
@ -83,7 +83,7 @@ func (consensus *Consensus) constructViewChangeMessage(priKey *bls.PrivateKeyWra
}
viewIDBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(viewIDBytes, consensus.GetViewChangingID())
binary.LittleEndian.PutUint64(viewIDBytes, consensus.getViewChangingID())
sign1 := priKey.Pri.SignHash(viewIDBytes)
if sign1 != nil {
vcMsg.ViewidSig = sign1.Serialize()
@ -107,7 +107,7 @@ func (consensus *Consensus) constructNewViewMessage(viewID uint64, priKey *bls.P
Request: &msg_pb.Message_Viewchange{
Viewchange: &msg_pb.ViewChangeRequest{
ViewId: viewID,
BlockNum: consensus.BlockNum(),
BlockNum: consensus.getBlockNum(),
ShardId: consensus.ShardID,
SenderPubkey: priKey.Pub.Bytes[:],
},

@ -327,8 +327,19 @@ func VerifyBlockCrossLinks(blockchain BlockChain, block *types.Block) error {
// ReadCrossLink beacon chain usage.
cl, err := blockchain.ReadCrossLink(crossLink.ShardID(), crossLink.BlockNum())
if err == nil && cl != nil {
// Add slash for exist same blocknum but different crosslink
return errAlreadyExist
utils.Logger().Err(errAlreadyExist).
Uint64("beacon-block-number", block.NumberU64()).
Interface("remote", crossLink).
Interface("local", cl).
Msg("[CrossLinkVerification]")
// TODO Add slash for exist same blocknum but different crosslink
return errors.Wrapf(
errAlreadyExist,
"[CrossLinkVerification] shard: %d block: %d on beacon block %d",
crossLink.ShardID(),
crossLink.BlockNum(),
block.NumberU64(),
)
}
if err := VerifyCrossLink(blockchain, crossLink); err != nil {
return errors.Wrapf(err, "cannot VerifyBlockCrossLinks")

Loading…
Cancel
Save