diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-05 05:46:38 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-05 19:09:09 +0800 |
commit | 71d32f54f70917c53fd3a691cface3bc73ffa1b7 (patch) | |
tree | 71d50e187595fc6a57001599bcb22c389d96d174 /core/chain_util.go | |
parent | 56219a5e7a9ed4762870a891bf962558ee846b74 (diff) | |
download | go-tangerine-71d32f54f70917c53fd3a691cface3bc73ffa1b7.tar.gz go-tangerine-71d32f54f70917c53fd3a691cface3bc73ffa1b7.tar.zst go-tangerine-71d32f54f70917c53fd3a691cface3bc73ffa1b7.zip |
core, miner: added difficulty bomb
Diffstat (limited to 'core/chain_util.go')
-rw-r--r-- | core/chain_util.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/core/chain_util.go b/core/chain_util.go index 104670195..34f6c8d0a 100644 --- a/core/chain_util.go +++ b/core/chain_util.go @@ -30,14 +30,15 @@ import ( ) var ( - blockHashPre = []byte("block-hash-") - blockNumPre = []byte("block-num-") + blockHashPre = []byte("block-hash-") + blockNumPre = []byte("block-num-") + expDiffPeriod = big.NewInt(100000) ) // 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, parentTime uint64, parentDiff *big.Int) *big.Int { +func CalcDifficulty(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { diff := new(big.Int) adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor) bigTime := new(big.Int) @@ -52,8 +53,19 @@ func CalcDifficulty(time, parentTime uint64, parentDiff *big.Int) *big.Int { diff.Sub(parentDiff, adjust) } if diff.Cmp(params.MinimumDifficulty) < 0 { - return params.MinimumDifficulty + diff = params.MinimumDifficulty } + + periodCount := new(big.Int).Add(parentNumber, common.Big1) + periodCount.Div(periodCount, expDiffPeriod) + if periodCount.Cmp(common.Big1) > 0 { + // diff = diff + 2^(periodCount - 2) + expDiff := periodCount.Sub(periodCount, common.Big2) + expDiff.Exp(common.Big2, expDiff, nil) + diff.Add(diff, expDiff) + diff = common.BigMax(diff, params.MinimumDifficulty) + } + return diff } |