mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-24 01:38:33 +00:00
Glacier Muir update
This commit is contained in:
parent
a6cde0928e
commit
6b6584c4d0
@ -140,9 +140,14 @@ template calcDifficultyByzantium*(timeStamp: EthTime, parent: BlockHeader): Diff
|
||||
template calcDifficultyConstantinople*(timeStamp: EthTime, parent: BlockHeader): DifficultyInt =
|
||||
makeDifficultyCalculator(5_000_000, timeStamp, parent)
|
||||
|
||||
template calcDifficultyGlacierMuir*(timeStamp: EthTime, parent: BlockHeader): DifficultyInt =
|
||||
makeDifficultyCalculator(9_000_000, timeStamp, parent)
|
||||
|
||||
func calcDifficulty*(timeStamp: EthTime, parent: BlockHeader): DifficultyInt =
|
||||
let next = parent.blockNumber + bigOne
|
||||
if next >= forkBlocks[FkConstantinople]:
|
||||
if next >= forkBlocks[FkGlacierMuir]:
|
||||
result = calcDifficultyGlacierMuir(timeStamp, parent)
|
||||
elif next >= forkBlocks[FkConstantinople]:
|
||||
result = calcDifficultyConstantinople(timeStamp, parent)
|
||||
elif next >= forkBlocks[FkByzantium]:
|
||||
result = calcDifficultyByzantium(timeStamp, parent)
|
||||
@ -153,6 +158,8 @@ func calcDifficulty*(timeStamp: EthTime, parent: BlockHeader): DifficultyInt =
|
||||
|
||||
func calcDifficulty*(timeStamp: EthTime, parent: BlockHeader, fork: Fork): DifficultyInt =
|
||||
case fork
|
||||
of FkGlacierMuir:
|
||||
result = calcDifficultyGlacierMuir(timeStamp, parent)
|
||||
of FkConstantinople:
|
||||
result = calcDifficultyConstantinople(timeStamp, parent)
|
||||
of FkByzantium:
|
||||
|
@ -721,7 +721,8 @@ const
|
||||
FkSpurious: SpuriousGasFees,
|
||||
FkByzantium: SpuriousGasFees,
|
||||
FkConstantinople: SpuriousGasFees,
|
||||
FkIstanbul: IstanbulGasFees
|
||||
FkIstanbul: IstanbulGasFees,
|
||||
FkGlacierMuir: IstanbulGasFees
|
||||
]
|
||||
|
||||
|
||||
|
@ -17,7 +17,8 @@ type
|
||||
FkSpurious,
|
||||
FkByzantium,
|
||||
FkConstantinople,
|
||||
FkIstanbul
|
||||
FkIstanbul,
|
||||
FkGlacierMuir
|
||||
|
||||
const
|
||||
forkBlocks*: array[Fork, BlockNumber] = [
|
||||
@ -29,7 +30,8 @@ const
|
||||
FkSpurious: 2_675_000.toBlockNumber, # 22/11/2016 18:15:44
|
||||
FkByzantium: 4_370_000.toBlockNumber, # 16/10/2017 09:22:11
|
||||
FkConstantinople: 7_280_000.toBlockNumber, # 28/02/2019 07:52:04
|
||||
FkIstanbul: 9_069_000.toBlockNumber
|
||||
FkIstanbul: 9_069_000.toBlockNumber, # 08/12/2019 12:25:09
|
||||
FkGlacierMuir: 9_200_000.toBlockNumber # 02/01/2020 08:30:49
|
||||
]
|
||||
|
||||
proc toFork*(blockNumber: BlockNumber): Fork =
|
||||
@ -50,7 +52,8 @@ proc toFork*(blockNumber: BlockNumber): Fork =
|
||||
elif blockNumber < forkBlocks[FkByzantium]: FkSpurious
|
||||
elif blockNumber < forkBlocks[FkConstantinople]: FkByzantium
|
||||
elif blockNumber < forkBlocks[FkIstanbul]: FkConstantinople
|
||||
else: FkIstanbul
|
||||
elif blockNumber < forkBlocks[FkGlacierMuir]: FkIstanbul
|
||||
else: FkGlacierMuir
|
||||
|
||||
proc `$`*(fork: Fork): string =
|
||||
case fork
|
||||
@ -63,3 +66,4 @@ proc `$`*(fork: Fork): string =
|
||||
of FkByzantium: result = "Byzantium"
|
||||
of FkConstantinople: result = "Constantinople"
|
||||
of FkIstanbul: result = "Istanbul"
|
||||
of FkGlacierMuir: result = "Glacier Muir"
|
||||
|
18034
tests/fixtures/DifficultyTests/difficultyEIP2384.json
vendored
Normal file
18034
tests/fixtures/DifficultyTests/difficultyEIP2384.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8002
tests/fixtures/DifficultyTests/difficultyEIP2384_random.json
vendored
Normal file
8002
tests/fixtures/DifficultyTests/difficultyEIP2384_random.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8002
tests/fixtures/DifficultyTests/difficultyEIP2384_random_to20M.json
vendored
Normal file
8002
tests/fixtures/DifficultyTests/difficultyEIP2384_random_to20M.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
20289
tests/fixtures/DifficultyTests/difficultyMainNetwork.json
vendored
Normal file
20289
tests/fixtures/DifficultyTests/difficultyMainNetwork.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
||||
import unittest2, strutils, tables, os, json,
|
||||
../nimbus/utils/difficulty, stint, times,
|
||||
eth/common, test_helpers, stew/byteutils
|
||||
eth/common, test_helpers, stew/byteutils,
|
||||
../nimbus/constants, ../nimbus/vm/interpreter/vm_forks
|
||||
|
||||
type
|
||||
Tester = object
|
||||
@ -34,14 +35,19 @@ proc parseTests(name: string, hex: static[bool]): Tests =
|
||||
for title, data in fixtures:
|
||||
t.parentTimestamp = hexOrInt64(data, "parentTimestamp", hex)
|
||||
t.parentDifficulty = hexOrInt256(data, "parentDifficulty", hex)
|
||||
hexToByteArray(data["parentUncles"].getStr, t.parentUncles.data)
|
||||
let pu = data.fields.getOrDefault("parentUncles")
|
||||
if pu.isNil:
|
||||
t.parentUncles = EMPTY_UNCLE_HASH
|
||||
else:
|
||||
hexToByteArray(pu.getStr, t.parentUncles.data)
|
||||
t.currentTimestamp = hexOrInt64(data, "currentTimestamp", hex)
|
||||
t.currentBlockNumber = hexOrInt256(data, "currentBlockNumber", hex)
|
||||
t.currentDifficulty = hexOrInt256(data, "currentDifficulty", hex)
|
||||
result[title] = t
|
||||
|
||||
template runTests(name: string, hex: bool, calculator: typed) =
|
||||
test name:
|
||||
let testTitle = if name == "": "Difficulty" else: name
|
||||
test testTitle:
|
||||
let data = parseTests(name, hex)
|
||||
for title, t in data:
|
||||
var p = BlockHeader(
|
||||
@ -53,11 +59,18 @@ template runTests(name: string, hex: bool, calculator: typed) =
|
||||
let diff = calculator(times.fromUnix(t.currentTimeStamp), p)
|
||||
check diff == t.currentDifficulty
|
||||
|
||||
func calcDifficultyMainNetWork(timeStamp: EthTime, parent: BlockHeader): DifficultyInt =
|
||||
calcDifficulty(timeStamp, parent, parent.blockNumber.toFork)
|
||||
|
||||
proc difficultyMain*() =
|
||||
suite "DifficultyTest":
|
||||
runTests("EIP2384_random_to20M", true, calcDifficultyGlacierMuir)
|
||||
runTests("EIP2384_random", true, calcDifficultyGlacierMuir)
|
||||
runTests("EIP2384", true, calcDifficultyGlacierMuir)
|
||||
runTests("Byzantium", true, calcDifficultyByzantium)
|
||||
runTests("Constantinople", true, calcDifficultyConstantinople)
|
||||
runTests("Homestead", true, calcDifficultyHomestead)
|
||||
runTests("MainNetwork", true, calcDifficultyMainNetwork)
|
||||
runTests("Frontier", true, calcDifficultyFrontier)
|
||||
runTests("", false, calcDifficulty)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user