aboutsummaryrefslogtreecommitdiffstats
path: root/core/round-based-config.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-02-20 12:53:18 +0800
committerGitHub <noreply@github.com>2019-02-20 12:53:18 +0800
commit8ef4fc213703620fbfa13890dee042d40eea8545 (patch)
treeba9a07d2423314396e5677b7294122caa505ae9a /core/round-based-config.go
parent2cf18fd299ea0fc270b213343314cab652cac271 (diff)
downloaddexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.gz
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.bz2
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.lz
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.xz
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.tar.zst
dexon-consensus-8ef4fc213703620fbfa13890dee042d40eea8545.zip
core: switch round by block height (#450)
Diffstat (limited to 'core/round-based-config.go')
-rw-r--r--core/round-based-config.go27
1 files changed, 13 insertions, 14 deletions
diff --git a/core/round-based-config.go b/core/round-based-config.go
index 67779a6..f2cfc82 100644
--- a/core/round-based-config.go
+++ b/core/round-based-config.go
@@ -18,20 +18,16 @@
package core
import (
- "time"
+ "fmt"
"github.com/dexon-foundation/dexon-consensus/core/types"
)
type roundBasedConfig struct {
- roundID uint64
-
- // roundBeginTime is the beginning of round, as local time.
- roundBeginTime time.Time
- roundInterval time.Duration
-
- // roundEndTime is a cache for begin + interval.
- roundEndTime time.Time
+ roundID uint64
+ roundBeginHeight uint64
+ roundEndHeight uint64
+ roundInterval uint64
}
func (config *roundBasedConfig) setupRoundBasedFields(
@@ -40,13 +36,16 @@ func (config *roundBasedConfig) setupRoundBasedFields(
config.roundInterval = cfg.RoundInterval
}
-func (config *roundBasedConfig) setRoundBeginTime(begin time.Time) {
- config.roundBeginTime = begin
- config.roundEndTime = begin.Add(config.roundInterval)
+func (config *roundBasedConfig) setRoundBeginHeight(begin uint64) {
+ config.roundBeginHeight = begin
+ config.roundEndHeight = begin + config.roundInterval
}
// isLastBlock checks if a block is the last block of this round.
func (config *roundBasedConfig) isLastBlock(b *types.Block) bool {
- return b.Position.Round == config.roundID &&
- b.Timestamp.After(config.roundEndTime)
+ if b.Position.Round != config.roundID {
+ panic(fmt.Errorf("attempt to compare by different round: %s, %d",
+ b, config.roundID))
+ }
+ return b.Position.Height+1 == config.roundEndHeight
}