[viewchange] update view ID slower than view change timeout

so that node init view change at different timeslot can converge on the
same view ID

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3448/head
Leo Chen 4 years ago
parent 1e4b55a7cc
commit e891ca68dc
  1. 4
      consensus/config.go
  2. 2
      consensus/view_change.go

@ -6,6 +6,10 @@ import "time"
const ( const (
// default timeout configuration is shorten to 45 seconds as the consensus is 5s // default timeout configuration is shorten to 45 seconds as the consensus is 5s
viewChangeTimeout = 45 viewChangeTimeout = 45
// viewChangeSlot means every 90 seconds, the view change ID will be advanced.
// so that the nodes init view change process within the 90 seconds range will
// be have the same view change ID
viewChangeSlot = 90
// The duration of viewChangeTimeout for each view change // The duration of viewChangeTimeout for each view change
viewChangeDuration time.Duration = viewChangeTimeout * time.Second viewChangeDuration time.Duration = viewChangeTimeout * time.Second

@ -133,7 +133,7 @@ func (consensus *Consensus) getNextViewID() (uint64, time.Duration) {
return consensus.fallbackNextViewID() return consensus.fallbackNextViewID()
} }
// diff only increases // diff only increases
diff := uint64((curTimestamp - blockTimestamp) / viewChangeTimeout) diff := uint64((curTimestamp - blockTimestamp) / viewChangeSlot)
nextViewID := diff + lastBlockViewID nextViewID := diff + lastBlockViewID
consensus.getLogger().Info(). consensus.getLogger().Info().

Loading…
Cancel
Save