aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2018-09-17 17:49:39 +0800
committerMartin Holst Swende <martin@swende.se>2018-09-17 17:53:36 +0800
commit7efb12d29b9c8134ab8ec8c3753b7aa5e503a157 (patch)
tree7eb22ea5ab303e5e9400a35bf32849d2a219844c
parent3df7df0386a78a6d818fb6dfbbbcf07ddedc658f (diff)
downloadgo-tangerine-7efb12d29b9c8134ab8ec8c3753b7aa5e503a157.tar
go-tangerine-7efb12d29b9c8134ab8ec8c3753b7aa5e503a157.tar.gz
go-tangerine-7efb12d29b9c8134ab8ec8c3753b7aa5e503a157.tar.bz2
go-tangerine-7efb12d29b9c8134ab8ec8c3753b7aa5e503a157.tar.lz
go-tangerine-7efb12d29b9c8134ab8ec8c3753b7aa5e503a157.tar.xz
go-tangerine-7efb12d29b9c8134ab8ec8c3753b7aa5e503a157.tar.zst
go-tangerine-7efb12d29b9c8134ab8ec8c3753b7aa5e503a157.zip
ethash: documentation + cleanup
-rw-r--r--consensus/ethash/consensus.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go
index 0394c37bb..548c57cd9 100644
--- a/consensus/ethash/consensus.go
+++ b/consensus/ethash/consensus.go
@@ -46,13 +46,16 @@ var (
// calcDifficultyConstantinople is the difficulty adjustment algorithm for Constantinople.
// It returns the difficulty that a new block should have when created at time given the
- // parent block's time and difficulty. The calculation uses the Byzantium rules, but with bomb offset 5M.
- calcDifficultyConstantinople = makeDifficultyCalculator(big.NewInt(4999999))
+ // parent block's time and difficulty. The calculation uses the Byzantium rules, but with
+ // bomb offset 5M.
+ // Specification EIP-1234: https://eips.ethereum.org/EIPS/eip-1234
+ calcDifficultyConstantinople = makeDifficultyCalculator(big.NewInt(5000000))
// calcDifficultyByzantium is the difficulty adjustment algorithm. It returns
// the difficulty that a new block should have when created at time given the
// parent block's time and difficulty. The calculation uses the Byzantium rules.
- calcDifficultyByzantium = makeDifficultyCalculator(big.NewInt(2999999))
+ // Specification EIP-649: https://eips.ethereum.org/EIPS/eip-649
+ calcDifficultyByzantium = makeDifficultyCalculator(big.NewInt(3000000))
)
// Various error messages to mark blocks invalid. These should be private to
@@ -335,6 +338,9 @@ var (
// the difficulty is calculated with Byzantium rules, which differs from Homestead in
// how uncles affect the calculation
func makeDifficultyCalculator(bombDelay *big.Int) func(time uint64, parent *types.Header) *big.Int {
+ // Note, the calculations below looks at the parent number, which is 1 below
+ // the block number. Thus we remove one from the delay given
+ bombDelayFromParent := new(big.Int).Sub(bombDelay, big1)
return func(time uint64, parent *types.Header) *big.Int {
// https://github.com/ethereum/EIPs/issues/100.
// algorithm:
@@ -370,12 +376,11 @@ func makeDifficultyCalculator(bombDelay *big.Int) func(time uint64, parent *type
if x.Cmp(params.MinimumDifficulty) < 0 {
x.Set(params.MinimumDifficulty)
}
- // calculate a fake block number for the ice-age delay:
- // https://github.com/ethereum/EIPs/pull/669
- // fake_block_number = max(0, block.number - 3_000_000)
+ // calculate a fake block number for the ice-age delay
+ // Specification: https://eips.ethereum.org/EIPS/eip-1234
fakeBlockNumber := new(big.Int)
- if parent.Number.Cmp(bombDelay) >= 0 {
- fakeBlockNumber = fakeBlockNumber.Sub(parent.Number, bombDelay) // Note, parent is 1 less than the actual block number
+ if parent.Number.Cmp(bombDelayFromParent) >= 0 {
+ fakeBlockNumber = fakeBlockNumber.Sub(parent.Number, bombDelayFromParent)
}
// for the exponential factor
periodCount := fakeBlockNumber