[viewchange] use last known viewID from blockchain

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3451/head
Leo Chen 4 years ago
parent 91cf0026ae
commit 0f02ec9bf1
  1. 5
      consensus/view_change.go

@ -125,6 +125,7 @@ func (consensus *Consensus) getNextViewID() (uint64, time.Duration) {
return consensus.fallbackNextViewID()
}
blockTimestamp := curHeader.Time().Int64()
lastBlockViewID := curHeader.ViewID().Uint64()
curTimestamp := time.Now().Unix()
// timestamp messed up in current validator node
@ -133,13 +134,13 @@ func (consensus *Consensus) getNextViewID() (uint64, time.Duration) {
}
// diff only increases
diff := uint64((curTimestamp - blockTimestamp) / viewChangeTimeout)
nextViewID := diff + consensus.GetCurBlockViewID()
nextViewID := diff + lastBlockViewID
consensus.getLogger().Info().
Int64("curTimestamp", curTimestamp).
Int64("blockTimestamp", blockTimestamp).
Uint64("nextViewID", nextViewID).
Uint64("curViewID", consensus.GetCurBlockViewID()).
Uint64("lastBlockViewID", lastBlockViewID).
Msg("[getNextViewID]")
// duration is always the fixed view change duration for synchronous view change

Loading…
Cancel
Save