|
|
@ -1,7 +1,6 @@ |
|
|
|
package consensus |
|
|
|
package consensus |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"math/big" |
|
|
|
"math/big" |
|
|
|
"sync" |
|
|
|
"sync" |
|
|
|
"time" |
|
|
|
"time" |
|
|
@ -162,7 +161,6 @@ func (consensus *Consensus) getNextViewID() (uint64, time.Duration) { |
|
|
|
Uint64("stuckBlockViewID", stuckBlockViewID). |
|
|
|
Uint64("stuckBlockViewID", stuckBlockViewID). |
|
|
|
Msg("[getNextViewID]") |
|
|
|
Msg("[getNextViewID]") |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("end getNextViewID: ", nextViewID, viewChangeDuration) |
|
|
|
|
|
|
|
// duration is always the fixed view change duration for synchronous view change
|
|
|
|
// duration is always the fixed view change duration for synchronous view change
|
|
|
|
return nextViewID, viewChangeDuration |
|
|
|
return nextViewID, viewChangeDuration |
|
|
|
} |
|
|
|
} |
|
|
@ -235,7 +233,6 @@ func (consensus *Consensus) getNextLeaderKey(viewID uint64) *bls.PublicKeyWrappe |
|
|
|
lastLeaderPubKey, |
|
|
|
lastLeaderPubKey, |
|
|
|
gap) |
|
|
|
gap) |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Println("wasfoundNext", consensus.Blockchain.Config().IsAllowlistEpoch(epoch), wasFound, next.Bytes.Hex(), lastLeaderPubKey.Bytes.Hex()) |
|
|
|
|
|
|
|
if !wasFound { |
|
|
|
if !wasFound { |
|
|
|
consensus.getLogger().Warn(). |
|
|
|
consensus.getLogger().Warn(). |
|
|
|
Str("key", consensus.LeaderPubKey.Bytes.Hex()). |
|
|
|
Str("key", consensus.LeaderPubKey.Bytes.Hex()). |
|
|
@ -257,7 +254,6 @@ func createTimeout() map[TimeoutType]*utils.Timeout { |
|
|
|
|
|
|
|
|
|
|
|
// startViewChange start the view change process
|
|
|
|
// startViewChange start the view change process
|
|
|
|
func (consensus *Consensus) startViewChange() { |
|
|
|
func (consensus *Consensus) startViewChange() { |
|
|
|
fmt.Printf("Message to send leader111: %d %s \n", utils.GetPort(), consensus.LeaderPubKey.Bytes.Hex()) |
|
|
|
|
|
|
|
if consensus.disableViewChange || consensus.IsBackup() { |
|
|
|
if consensus.disableViewChange || consensus.IsBackup() { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -268,7 +264,6 @@ func (consensus *Consensus) startViewChange() { |
|
|
|
consensus.consensusTimeout[timeoutBootstrap].Stop() |
|
|
|
consensus.consensusTimeout[timeoutBootstrap].Stop() |
|
|
|
consensus.current.SetMode(ViewChanging) |
|
|
|
consensus.current.SetMode(ViewChanging) |
|
|
|
nextViewID, duration := consensus.getNextViewID() |
|
|
|
nextViewID, duration := consensus.getNextViewID() |
|
|
|
//fmt.Println("startViewChange", nextViewID)
|
|
|
|
|
|
|
|
consensus.SetViewChangingID(nextViewID) |
|
|
|
consensus.SetViewChangingID(nextViewID) |
|
|
|
// TODO: set the Leader PubKey to the next leader for view change
|
|
|
|
// TODO: set the Leader PubKey to the next leader for view change
|
|
|
|
// this is dangerous as the leader change is not succeeded yet
|
|
|
|
// this is dangerous as the leader change is not succeeded yet
|
|
|
@ -312,9 +307,7 @@ func (consensus *Consensus) startViewChange() { |
|
|
|
if !consensus.IsValidatorInCommittee(key.Pub.Bytes) { |
|
|
|
if !consensus.IsValidatorInCommittee(key.Pub.Bytes) { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
// Тут уже другой leader
|
|
|
|
|
|
|
|
msgToSend := consensus.constructViewChangeMessage(&key) |
|
|
|
msgToSend := consensus.constructViewChangeMessage(&key) |
|
|
|
fmt.Println("Message to send leader222: ", consensus.LeaderPubKey.Bytes.Hex()) |
|
|
|
|
|
|
|
if err := consensus.msgSender.SendWithRetry( |
|
|
|
if err := consensus.msgSender.SendWithRetry( |
|
|
|
consensus.BlockNum(), |
|
|
|
consensus.BlockNum(), |
|
|
|
msg_pb.MessageType_VIEWCHANGE, |
|
|
|
msg_pb.MessageType_VIEWCHANGE, |
|
|
@ -372,7 +365,6 @@ func (consensus *Consensus) startNewView(viewID uint64, newLeaderPriKey *bls.Pri |
|
|
|
if reset { |
|
|
|
if reset { |
|
|
|
consensus.ResetState() |
|
|
|
consensus.ResetState() |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Println("[startNewView]", newLeaderPriKey.Pub.Bytes.Hex()) |
|
|
|
|
|
|
|
consensus.SetLeaderPubKey(newLeaderPriKey.Pub) |
|
|
|
consensus.SetLeaderPubKey(newLeaderPriKey.Pub) |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
@ -490,8 +482,6 @@ func (consensus *Consensus) onNewView(recvMsg *FBFTMessage) { |
|
|
|
consensus.mutex.Lock() |
|
|
|
consensus.mutex.Lock() |
|
|
|
defer consensus.mutex.Unlock() |
|
|
|
defer consensus.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("[onNewView] received new view message from %+v\n", recvMsg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
consensus.getLogger().Info(). |
|
|
|
consensus.getLogger().Info(). |
|
|
|
Uint64("viewID", recvMsg.ViewID). |
|
|
|
Uint64("viewID", recvMsg.ViewID). |
|
|
|
Uint64("blockNum", recvMsg.BlockNum). |
|
|
|
Uint64("blockNum", recvMsg.BlockNum). |
|
|
@ -580,7 +570,6 @@ func (consensus *Consensus) onNewView(recvMsg *FBFTMessage) { |
|
|
|
// newView message verified success, override my state
|
|
|
|
// newView message verified success, override my state
|
|
|
|
consensus.SetViewIDs(recvMsg.ViewID) |
|
|
|
consensus.SetViewIDs(recvMsg.ViewID) |
|
|
|
consensus.pubKeyLock.Lock() |
|
|
|
consensus.pubKeyLock.Lock() |
|
|
|
fmt.Println("[onNewView1221] new leader key cur:", consensus.LeaderPubKey.Bytes.Hex(), " new: ", senderKey.Bytes.Hex()) |
|
|
|
|
|
|
|
consensus.LeaderPubKey = senderKey |
|
|
|
consensus.LeaderPubKey = senderKey |
|
|
|
consensus.pubKeyLock.Unlock() |
|
|
|
consensus.pubKeyLock.Unlock() |
|
|
|
consensus.ResetViewChangeState() |
|
|
|
consensus.ResetViewChangeState() |
|
|
|