From 6767c9588727f6b0eca29ced17a102a2c6c58300 Mon Sep 17 00:00:00 2001 From: Christopher Franko Date: Thu, 24 Sep 2015 10:59:49 -0400 Subject: [PATCH 1/4] make the diff adjustments better --- core/chain_util.go | 8 +++++++- params/protocol_params.go | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/chain_util.go b/core/chain_util.go index 4412137e3388..7e99c7d4c1a7 100644 --- a/core/chain_util.go +++ b/core/chain_util.go @@ -40,7 +40,13 @@ var ( // given the parent block's time and difficulty. func CalcDifficulty(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { diff := new(big.Int) - adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor) + + if parentNumber <= 23000 { + adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor) + } else { + adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor2) + } + bigTime := new(big.Int) bigParentTime := new(big.Int) diff --git a/params/protocol_params.go b/params/protocol_params.go index 1721c597b9b4..ca4a2001c77a 100755 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -30,6 +30,7 @@ var ( TxGas = big.NewInt(21000) // Per transaction. NOTE: Not payable on data of calls between transactions. TxDataZeroGas = big.NewInt(4) // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations. + DifficultyBoundDivisor2 = big.NewInt(512) // Difficulty should adjust faster. QuadCoeffDiv = big.NewInt(512) // Divisor for the quadratic particle of the memory cost equation. GenesisDifficulty = big.NewInt(131072) // Difficulty of the Genesis block. DurationLimit = big.NewInt(60) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. From 78c48ad90370e3547115105e1ff8fe46ca107366 Mon Sep 17 00:00:00 2001 From: Christopher Franko Date: Thu, 24 Sep 2015 15:28:37 -0400 Subject: [PATCH 2/4] added fork block number --- core/chain_util.go | 2 +- params/protocol_params.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/chain_util.go b/core/chain_util.go index 7e99c7d4c1a7..3078fcc1dff6 100644 --- a/core/chain_util.go +++ b/core/chain_util.go @@ -41,7 +41,7 @@ var ( func CalcDifficulty(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { diff := new(big.Int) - if parentNumber <= 23000 { + if parentNumber <= params.HardFork1 { adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor) } else { adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor2) diff --git a/params/protocol_params.go b/params/protocol_params.go index ca4a2001c77a..e3b89f22b16e 100755 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -31,6 +31,7 @@ var ( TxDataZeroGas = big.NewInt(4) // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations. DifficultyBoundDivisor2 = big.NewInt(512) // Difficulty should adjust faster. + HardFork1 = big.NewInt(23000) // fork at this block number QuadCoeffDiv = big.NewInt(512) // Divisor for the quadratic particle of the memory cost equation. GenesisDifficulty = big.NewInt(131072) // Difficulty of the Genesis block. DurationLimit = big.NewInt(60) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. From 3cb6e7745ceab0569d2031130cd32707a1aeb5f1 Mon Sep 17 00:00:00 2001 From: Christopher Franko Date: Thu, 24 Sep 2015 15:33:08 -0400 Subject: [PATCH 3/4] quickfix --- core/chain_util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/chain_util.go b/core/chain_util.go index 3078fcc1dff6..6ce13af54169 100644 --- a/core/chain_util.go +++ b/core/chain_util.go @@ -41,7 +41,7 @@ var ( func CalcDifficulty(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { diff := new(big.Int) - if parentNumber <= params.HardFork1 { + if parentNumber.Cmp(params.HardFork1) < 0 { adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor) } else { adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor2) From bfc916c6e364de10ef88769fe10800e52d2498e2 Mon Sep 17 00:00:00 2001 From: Christopher Franko Date: Thu, 24 Sep 2015 15:34:44 -0400 Subject: [PATCH 4/4] qf2 --- core/chain_util.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/chain_util.go b/core/chain_util.go index 6ce13af54169..680355e5b711 100644 --- a/core/chain_util.go +++ b/core/chain_util.go @@ -40,11 +40,12 @@ var ( // given the parent block's time and difficulty. func CalcDifficulty(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { diff := new(big.Int) + adjust := new(big.Int) if parentNumber.Cmp(params.HardFork1) < 0 { - adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor) + adjust = new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor) } else { - adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor2) + adjust = new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor2) } bigTime := new(big.Int)