aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/round-based-config.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/round-based-config.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/round-based-config.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/round-based-config.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/round-based-config.go
index 67779a63c..4f3a4cbf9 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/round-based-config.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/round-based-config.go
@@ -18,35 +18,34 @@
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(
roundID uint64, cfg *types.Config) {
config.roundID = roundID
- config.roundInterval = cfg.RoundInterval
+ config.roundInterval = cfg.RoundLength
}
-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
}