Rebased on dev.

pull/4509/head
frozen 2 years ago committed by Casey Gardiner
parent 661b937fd7
commit 900be09cfa
  1. 6
      consensus/consensus.go
  2. 16
      consensus/consensus_service.go
  3. 20
      consensus/consensus_v2.go
  4. 14
      consensus/view_change.go

@ -191,12 +191,6 @@ func (consensus *Consensus) getLeaderPubKey() *bls_cosi.PublicKeyWrapper {
return consensus.LeaderPubKey
}
func (consensus *Consensus) SetLeaderPubKey(pub *bls_cosi.PublicKeyWrapper) {
consensus.pubKeyLock.Lock()
consensus.LeaderPubKey = pub
consensus.pubKeyLock.Unlock()
}
func (consensus *Consensus) getLeaderPubKey() *bls_cosi.PublicKeyWrapper {
return consensus.LeaderPubKey
}

@ -111,7 +111,7 @@ func (consensus *Consensus) updatePublicKeys(pubKeys, allowlist []bls_cosi.Publi
// do not reset view change state if it is in view changing mode
if !consensus.isViewChangingMode() {
consensus.ResetViewChangeState()
consensus.resetViewChangeState()
}
return consensus.Decider.ParticipantsCount()
}
@ -501,19 +501,6 @@ func (consensus *Consensus) SetCurBlockViewID(viewID uint64) uint64 {
return consensus.current.SetCurBlockViewID(viewID)
}
// SetLeaderIndex set the leader index.
func (consensus *Consensus) SetLeaderIndex(f func(int) int) (current int) {
consensus.pubKeyLock.Lock()
defer consensus.pubKeyLock.Unlock()
consensus.LeaderIndex = f(consensus.LeaderIndex)
return consensus.LeaderIndex
}
func (consensus *Consensus) GetLeaderIndex() int {
consensus.pubKeyLock.Lock()
defer consensus.pubKeyLock.Unlock()
return consensus.LeaderIndex
}
// SetCurBlockViewID set the current view ID
func (consensus *Consensus) setCurBlockViewID(viewID uint64) {
consensus.current.SetCurBlockViewID(viewID)
@ -524,7 +511,6 @@ func (consensus *Consensus) SetViewChangingID(viewID uint64) {
consensus.current.SetViewChangingID(viewID)
}
// SetViewChangingID set the current view change ID
func (consensus *Consensus) setViewChangingID(viewID uint64) {
consensus.current.SetViewChangingID(viewID)

@ -414,18 +414,18 @@ func (consensus *Consensus) tick() {
func (consensus *Consensus) BlockChannel(newBlock *types.Block) {
//consensus.ReshardingNextLeader(newBlock)
consensus.getLogger().Info().
Uint64("MsgBlockNum", newBlock.NumberU64()).
Msg("[ConsensusMainLoop] Received Proposed New Block!")
consensus.getLogger().Info().
Uint64("MsgBlockNum", newBlock.NumberU64()).
Msg("[ConsensusMainLoop] Received Proposed New Block!")
if newBlock.NumberU64() < consensus.BlockNum() {
consensus.getLogger().Warn().Uint64("newBlockNum", newBlock.NumberU64()).
Msg("[ConsensusMainLoop] received old block, abort")
return
}
// Sleep to wait for the full block time
consensus.getLogger().Info().Msg("[ConsensusMainLoop] Waiting for Block Time")
time.AfterFunc(time.Until(consensus.NextBlockDue), func() {
}
// Sleep to wait for the full block time
consensus.getLogger().Info().Msg("[ConsensusMainLoop] Waiting for Block Time")
time.AfterFunc(time.Until(consensus.NextBlockDue), func() {
consensus.StartFinalityCount()
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
@ -750,12 +750,6 @@ func (consensus *Consensus) setupForNewConsensus(blk *types.Block, committedMsg
} else {
epoch = blk.Epoch()
}
var epoch *big.Int
if blk.IsLastBlockInEpoch() {
epoch = new(big.Int).Add(blk.Epoch(), common.Big1)
} else {
epoch = blk.Epoch()
}
if consensus.Blockchain.Config().IsLeaderRotation(epoch) {
consensus.rotateLeader(epoch)
}

@ -327,8 +327,8 @@ func (consensus *Consensus) startNewView(viewID uint64, newLeaderPriKey *bls.Pri
consensus.current.SetMode(Normal)
consensus.consensusTimeout[timeoutViewChange].Stop()
consensus.SetViewIDs(viewID)
consensus.ResetViewChangeState()
consensus.setViewIDs(viewID)
consensus.resetViewChangeState()
consensus.consensusTimeout[timeoutConsensus].Start()
consensus.getLogger().Info().
@ -340,7 +340,6 @@ func (consensus *Consensus) startNewView(viewID uint64, newLeaderPriKey *bls.Pri
if reset {
consensus.resetState()
}
fmt.Println("[startNewView]", newLeaderPriKey.Pub.Bytes.Hex())
consensus.setLeaderPubKey(newLeaderPriKey.Pub)
return nil
@ -532,7 +531,7 @@ func (consensus *Consensus) onNewView(recvMsg *FBFTMessage) {
// newView message verified success, override my state
consensus.setViewIDs(recvMsg.ViewID)
consensus.LeaderPubKey = senderKey
consensus.ResetViewChangeState()
consensus.resetViewChangeState()
consensus.msgSender.StopRetry(msg_pb.MessageType_VIEWCHANGE)
@ -553,6 +552,13 @@ func (consensus *Consensus) onNewView(recvMsg *FBFTMessage) {
// ResetViewChangeState resets the view change structure
func (consensus *Consensus) ResetViewChangeState() {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.resetViewChangeState()
}
// ResetViewChangeState resets the view change structure
func (consensus *Consensus) resetViewChangeState() {
consensus.getLogger().Info().
Str("Phase", consensus.phase.String()).
Msg("[ResetViewChangeState] Resetting view change state")

Loading…
Cancel
Save