aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_util.go
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-07-08 19:21:06 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-07-08 19:21:06 +0800
commit5d6d40f329410f20d9ceb92d31985a883d94cb24 (patch)
treeda3fb90259dece012c9f4daa972b76542d4870d8 /core/chain_util.go
parentb08abe64e4d2e3fa8d10c89647595226d6b31b19 (diff)
downloaddexon-5d6d40f329410f20d9ceb92d31985a883d94cb24.tar.gz
dexon-5d6d40f329410f20d9ceb92d31985a883d94cb24.tar.zst
dexon-5d6d40f329410f20d9ceb92d31985a883d94cb24.zip
Use uint64 on ts in chain_manager, block_processor
Diffstat (limited to 'core/chain_util.go')
-rw-r--r--core/chain_util.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/core/chain_util.go b/core/chain_util.go
index 96c9a03d8..7e3d8eba8 100644
--- a/core/chain_util.go
+++ b/core/chain_util.go
@@ -31,10 +31,16 @@ import (
// CalcDifficulty is the difficulty adjustment algorithm. It returns
// the difficulty that a new block b should have when created at time
// given the parent block's time and difficulty.
-func CalcDifficulty(time int64, parentTime int64, parentDiff *big.Int) *big.Int {
+func CalcDifficulty(time, parentTime uint64, parentDiff *big.Int) *big.Int {
diff := new(big.Int)
adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor)
- if big.NewInt(time-parentTime).Cmp(params.DurationLimit) < 0 {
+ bigTime := new(big.Int)
+ bigParentTime := new(big.Int)
+
+ bigTime.SetUint64(time)
+ bigParentTime.SetUint64(parentTime)
+
+ if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
diff.Add(parentDiff, adjust)
} else {
diff.Sub(parentDiff, adjust)