|
|
|
@ -274,7 +274,7 @@ func (consensus *Consensus) startViewChange() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// startNewView stops the current view change
|
|
|
|
|
func (consensus *Consensus) startNewView(viewID uint64, newLeaderPriKey *bls.PrivateKeyWrapper) error { |
|
|
|
|
func (consensus *Consensus) startNewView(viewID uint64, newLeaderPriKey *bls.PrivateKeyWrapper, reset bool) error { |
|
|
|
|
consensus.mutex.Lock() |
|
|
|
|
defer consensus.mutex.Unlock() |
|
|
|
|
|
|
|
|
@ -317,7 +317,9 @@ func (consensus *Consensus) startNewView(viewID uint64, newLeaderPriKey *bls.Pri |
|
|
|
|
Msg("[startNewView] viewChange stopped. I am the New Leader") |
|
|
|
|
|
|
|
|
|
// TODO: consider make ResetState unified and only called in one place like finalizeCommit()
|
|
|
|
|
if reset { |
|
|
|
|
consensus.ResetState() |
|
|
|
|
} |
|
|
|
|
consensus.LeaderPubKey = newLeaderPriKey.Pub |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
@ -389,7 +391,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) { |
|
|
|
|
// no previous prepared message, go straight to normal mode
|
|
|
|
|
// and start proposing new block
|
|
|
|
|
if consensus.vc.IsM1PayloadEmpty() { |
|
|
|
|
if err := consensus.startNewView(recvMsg.ViewID, newLeaderPriKey); err != nil { |
|
|
|
|
if err := consensus.startNewView(recvMsg.ViewID, newLeaderPriKey, true); err != nil { |
|
|
|
|
consensus.getLogger().Error().Err(err).Msg("[onViewChange] startNewView failed") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
@ -405,12 +407,10 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) { |
|
|
|
|
consensus.getLogger().Error().Err(err).Msg("[onViewChange] self commit failed") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if err := consensus.startNewView(recvMsg.ViewID, newLeaderPriKey); err != nil { |
|
|
|
|
if err := consensus.startNewView(recvMsg.ViewID, newLeaderPriKey, false); err != nil { |
|
|
|
|
consensus.getLogger().Error().Err(err).Msg("[onViewChange] startNewView failed") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
// Have to keep the block hash so the leader can finish the commit phase of prepared block
|
|
|
|
|
copy(consensus.blockHash[:], payload[:32]) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|