2022-12-02 04:39:12 +00:00
|
|
|
# Nimbus
|
2024-01-12 21:06:19 +00:00
|
|
|
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
2022-12-02 04:39:12 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
|
|
|
|
import
|
2024-06-14 07:31:08 +00:00
|
|
|
std/[strutils],
|
2022-12-02 04:39:12 +00:00
|
|
|
eth/common,
|
2023-09-13 02:32:38 +00:00
|
|
|
stew/endians2,
|
2022-12-02 04:39:12 +00:00
|
|
|
json_serialization,
|
|
|
|
../utils/utils,
|
|
|
|
./evmforks
|
|
|
|
|
2023-01-31 01:32:17 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
type
|
|
|
|
ConsensusType* {.pure.} = enum
|
|
|
|
# Proof of Work
|
|
|
|
# algorithm: Ethash
|
|
|
|
POW
|
|
|
|
|
|
|
|
# Proof of Stake
|
|
|
|
# algorithm: Casper
|
|
|
|
POS
|
|
|
|
|
|
|
|
HardFork* = enum
|
|
|
|
Frontier
|
|
|
|
Homestead
|
|
|
|
DAOFork
|
|
|
|
Tangerine # a.k.a. EIP150
|
|
|
|
Spurious # a.k.a. EIP158
|
|
|
|
Byzantium
|
|
|
|
Constantinople
|
|
|
|
Petersburg # a.k.a. ConstantinopleFix
|
|
|
|
Istanbul
|
|
|
|
MuirGlacier
|
|
|
|
Berlin
|
|
|
|
London
|
|
|
|
ArrowGlacier
|
|
|
|
GrayGlacier
|
|
|
|
MergeFork # a.k.a. Paris
|
|
|
|
Shanghai
|
|
|
|
Cancun
|
2024-03-28 06:47:02 +00:00
|
|
|
Prague
|
2022-12-02 04:39:12 +00:00
|
|
|
|
2023-02-16 11:40:07 +00:00
|
|
|
const lastPurelyBlockNumberBasedFork* = GrayGlacier
|
|
|
|
# MergeFork is special because of TTD.
|
|
|
|
const firstTimeBasedFork* = Shanghai
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
MergeForkTransitionThreshold* = object
|
2024-06-14 07:31:08 +00:00
|
|
|
number*: Opt[BlockNumber]
|
|
|
|
ttd*: Opt[DifficultyInt]
|
|
|
|
ttdPassed*: Opt[bool]
|
2023-02-16 11:40:07 +00:00
|
|
|
|
|
|
|
ForkTransitionTable* = object
|
2024-06-14 07:31:08 +00:00
|
|
|
blockNumberThresholds*: array[Frontier..GrayGlacier, Opt[BlockNumber]]
|
2023-02-16 11:40:07 +00:00
|
|
|
mergeForkTransitionThreshold*: MergeForkTransitionThreshold
|
2024-06-14 07:31:08 +00:00
|
|
|
timeThresholds*: array[Shanghai..Prague, Opt[EthTime]]
|
2023-02-16 11:40:07 +00:00
|
|
|
|
|
|
|
# Starting with Shanghai, forking is based on timestamp
|
|
|
|
# rather than block number.
|
|
|
|
#
|
|
|
|
# I'm not sure what to call this type, but we used to pass
|
|
|
|
# just the block number into various places that need to
|
|
|
|
# determine which fork we're on, and now we need to pass
|
|
|
|
# around both block number and also time. And the config
|
|
|
|
# info for each individual fork will be either a block
|
|
|
|
# number or a time.
|
|
|
|
#
|
|
|
|
# Note that time and TD are optional. TD being optional
|
|
|
|
# is because it's perfectly fine, if mergeForkBlock is
|
|
|
|
# set, to not bother with TTD anymore. But I'm not sure
|
|
|
|
# it makes sense to allow time to be optional. See the
|
2023-10-24 10:39:19 +00:00
|
|
|
# comment below on forkDeterminationInfo.
|
2023-02-16 11:40:07 +00:00
|
|
|
ForkDeterminationInfo* = object
|
2024-06-14 07:31:08 +00:00
|
|
|
number*: BlockNumber
|
2024-06-07 21:39:58 +00:00
|
|
|
time*: Opt[EthTime]
|
|
|
|
td*: Opt[DifficultyInt]
|
2023-02-16 11:40:07 +00:00
|
|
|
|
2023-10-24 10:39:19 +00:00
|
|
|
func forkDeterminationInfo*(n: BlockNumber): ForkDeterminationInfo =
|
2023-02-16 11:40:07 +00:00
|
|
|
# FIXME: All callers of this function are suspect; I'm guess we should
|
|
|
|
# always be using both block number and time. But we have a few places,
|
|
|
|
# like various tests, where we only have block number and the tests are
|
|
|
|
# meant for pre-Merge forks, so maybe those are okay.
|
2024-06-07 21:39:58 +00:00
|
|
|
ForkDeterminationInfo(
|
2024-06-14 07:31:08 +00:00
|
|
|
number: n, time: Opt.none(EthTime), td: Opt.none(DifficultyInt))
|
2023-02-16 11:40:07 +00:00
|
|
|
|
|
|
|
func forkDeterminationInfo*(n: BlockNumber, t: EthTime): ForkDeterminationInfo =
|
2024-06-07 21:39:58 +00:00
|
|
|
ForkDeterminationInfo(
|
2024-06-14 07:31:08 +00:00
|
|
|
number: n, time: Opt.some(t), td: Opt.none(DifficultyInt))
|
2023-02-16 11:40:07 +00:00
|
|
|
|
2023-10-24 10:39:19 +00:00
|
|
|
func forkDeterminationInfo*(header: BlockHeader): ForkDeterminationInfo =
|
|
|
|
# FIXME-Adam-mightAlsoNeedTTD?
|
2024-06-14 07:31:08 +00:00
|
|
|
forkDeterminationInfo(header.number, header.timestamp)
|
2023-10-24 10:39:19 +00:00
|
|
|
|
2024-05-28 05:10:10 +00:00
|
|
|
func adjustForNextBlock*(n: BlockNumber): BlockNumber =
|
2023-02-16 11:40:07 +00:00
|
|
|
n + 1
|
|
|
|
|
|
|
|
func adjustForNextBlock*(t: EthTime): EthTime =
|
|
|
|
# FIXME-Adam: what's the right thing to do here?
|
|
|
|
# How do we calculate "the timestamp for the block
|
|
|
|
# after this one"?
|
|
|
|
#
|
|
|
|
# If this makes no sense, what should the callers
|
|
|
|
# do instead?
|
2023-10-18 02:16:11 +00:00
|
|
|
t + 12
|
2023-02-16 11:40:07 +00:00
|
|
|
|
|
|
|
func adjustForNextBlock*(f: ForkDeterminationInfo): ForkDeterminationInfo =
|
|
|
|
ForkDeterminationInfo(
|
2024-06-14 07:31:08 +00:00
|
|
|
number: adjustForNextBlock(f.number),
|
2023-02-16 11:40:07 +00:00
|
|
|
time: f.time.map(adjustForNextBlock),
|
|
|
|
td: f.td
|
|
|
|
)
|
|
|
|
|
|
|
|
# This function is awkward because there are various different ways now of
|
|
|
|
# doing a hard-fork transition (block number, ttd, time, block number *or*
|
|
|
|
# time). We used to have a simple array called forkToBlock that mapped each
|
|
|
|
# HardFork to a BlockNumber; now we have this ForkTransitionTable, which
|
|
|
|
# contains a couple of arrays and also special cases for MergeBlock and
|
|
|
|
# Shanghai.
|
|
|
|
func isGTETransitionThreshold*(map: ForkTransitionTable, forkDeterminer: ForkDeterminationInfo, fork: HardFork): bool =
|
|
|
|
if fork <= lastPurelyBlockNumberBasedFork:
|
2024-06-14 07:31:08 +00:00
|
|
|
map.blockNumberThresholds[fork].isSome and forkDeterminer.number >= map.blockNumberThresholds[fork].get
|
2023-02-16 11:40:07 +00:00
|
|
|
elif fork == MergeFork:
|
|
|
|
# MergeFork is a special case that can use either block number or ttd;
|
2023-08-06 07:55:11 +00:00
|
|
|
# ttdPassed > block number > ttd takes precedence.
|
2023-02-16 11:40:07 +00:00
|
|
|
let t = map.mergeForkTransitionThreshold
|
2023-08-06 07:55:11 +00:00
|
|
|
if t.ttdPassed.isSome:
|
|
|
|
t.ttdPassed.get
|
2024-06-14 07:31:08 +00:00
|
|
|
elif t.number.isSome:
|
|
|
|
forkDeterminer.number >= t.number.get
|
2023-02-16 11:40:07 +00:00
|
|
|
elif t.ttd.isSome and forkDeterminer.td.isSome:
|
|
|
|
forkDeterminer.td.get >= t.ttd.get
|
|
|
|
else:
|
|
|
|
false
|
|
|
|
elif fork <= HardFork.high:
|
|
|
|
map.timeThresholds[fork].isSome and forkDeterminer.time.isSome and forkDeterminer.time.get >= map.timeThresholds[fork].get
|
|
|
|
else:
|
|
|
|
raise newException(Defect, "Why is this hard fork not in one of the above categories?")
|
|
|
|
|
|
|
|
type
|
2022-12-02 04:39:12 +00:00
|
|
|
# if you add more fork block
|
|
|
|
# please update forkBlockField constant too
|
|
|
|
ChainConfig* = ref object
|
|
|
|
chainId* : ChainId
|
2024-06-14 07:31:08 +00:00
|
|
|
homesteadBlock* : Opt[BlockNumber]
|
|
|
|
daoForkBlock* : Opt[BlockNumber]
|
2022-12-02 04:39:12 +00:00
|
|
|
daoForkSupport* : bool
|
2024-06-14 07:31:08 +00:00
|
|
|
eip150Block* : Opt[BlockNumber]
|
2022-12-02 04:39:12 +00:00
|
|
|
eip150Hash* : Hash256
|
2024-06-14 07:31:08 +00:00
|
|
|
eip155Block* : Opt[BlockNumber]
|
|
|
|
eip158Block* : Opt[BlockNumber]
|
|
|
|
byzantiumBlock* : Opt[BlockNumber]
|
|
|
|
constantinopleBlock*: Opt[BlockNumber]
|
|
|
|
petersburgBlock* : Opt[BlockNumber]
|
|
|
|
istanbulBlock* : Opt[BlockNumber]
|
|
|
|
muirGlacierBlock* : Opt[BlockNumber]
|
|
|
|
berlinBlock* : Opt[BlockNumber]
|
|
|
|
londonBlock* : Opt[BlockNumber]
|
|
|
|
arrowGlacierBlock* : Opt[BlockNumber]
|
|
|
|
grayGlacierBlock* : Opt[BlockNumber]
|
2023-11-29 02:03:19 +00:00
|
|
|
|
|
|
|
# mergeNetsplitBlock is an alias to mergeForkBlock
|
|
|
|
# and is used for geth compatibility layer
|
2024-06-14 07:31:08 +00:00
|
|
|
mergeNetsplitBlock* : Opt[BlockNumber]
|
2023-11-29 02:03:19 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
mergeForkBlock* : Opt[BlockNumber]
|
|
|
|
shanghaiTime* : Opt[EthTime]
|
|
|
|
cancunTime* : Opt[EthTime]
|
|
|
|
pragueTime* : Opt[EthTime]
|
2022-12-02 04:39:12 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
terminalTotalDifficulty*: Opt[UInt256]
|
|
|
|
terminalTotalDifficultyPassed*: Opt[bool]
|
2022-12-02 04:39:12 +00:00
|
|
|
consensusType*
|
|
|
|
{.dontSerialize.} : ConsensusType
|
|
|
|
|
2023-02-16 11:40:07 +00:00
|
|
|
# These are used for checking that the values of the fields
|
|
|
|
# are in a valid order.
|
|
|
|
BlockNumberBasedForkOptional* = object
|
2022-12-02 04:39:12 +00:00
|
|
|
name*: string
|
2024-06-14 07:31:08 +00:00
|
|
|
number*: Opt[BlockNumber]
|
2023-02-16 11:40:07 +00:00
|
|
|
TimeBasedForkOptional* = object
|
|
|
|
name*: string
|
2024-06-14 07:31:08 +00:00
|
|
|
time*: Opt[EthTime]
|
2023-02-16 11:40:07 +00:00
|
|
|
|
2023-10-24 05:51:37 +00:00
|
|
|
func countTimeFields(): int {.compileTime.} =
|
2024-01-12 21:06:19 +00:00
|
|
|
var z = ChainConfig()
|
2023-10-24 05:51:37 +00:00
|
|
|
for name, _ in fieldPairs(z[]):
|
|
|
|
if name.endsWith("Time"):
|
|
|
|
inc result
|
2023-02-16 11:40:07 +00:00
|
|
|
|
2023-10-24 05:51:37 +00:00
|
|
|
func countBlockFields(): int {.compileTime.} =
|
2024-01-12 21:06:19 +00:00
|
|
|
var z = ChainConfig()
|
2023-10-24 05:51:37 +00:00
|
|
|
for name, _ in fieldPairs(z[]):
|
2023-11-29 02:03:19 +00:00
|
|
|
if name == "mergeNetsplitBlock":
|
|
|
|
# skip mergeForkBlock alias
|
|
|
|
# continue is not supported
|
|
|
|
discard
|
|
|
|
elif name.endsWith("Block"):
|
2023-10-24 05:51:37 +00:00
|
|
|
inc result
|
|
|
|
|
|
|
|
const
|
|
|
|
timeFieldsCount = countTimeFields()
|
|
|
|
blockFieldsCount = countBlockFields()
|
|
|
|
|
|
|
|
func collectTimeFields(): array[timeFieldsCount, string] =
|
2024-01-12 21:06:19 +00:00
|
|
|
var z = ChainConfig()
|
2023-10-24 05:51:37 +00:00
|
|
|
var i = 0
|
|
|
|
for name, _ in fieldPairs(z[]):
|
|
|
|
if name.endsWith("Time"):
|
|
|
|
result[i] = name
|
|
|
|
inc i
|
|
|
|
|
|
|
|
func collectBlockFields(): array[blockFieldsCount, string] =
|
2024-01-12 21:06:19 +00:00
|
|
|
var z = ChainConfig()
|
2023-10-24 05:51:37 +00:00
|
|
|
var i = 0
|
|
|
|
for name, _ in fieldPairs(z[]):
|
2023-11-29 02:03:19 +00:00
|
|
|
if name == "mergeNetsplitBlock":
|
|
|
|
# skip mergeForkBlock alias
|
|
|
|
# continue is not supported
|
|
|
|
discard
|
|
|
|
elif name.endsWith("Block"):
|
2023-10-24 05:51:37 +00:00
|
|
|
result[i] = name
|
|
|
|
inc i
|
2022-12-02 04:39:12 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
# this table is used for generate
|
|
|
|
# code at compile time to check
|
|
|
|
# the order of blok number in ChainConfig
|
2023-10-24 05:51:37 +00:00
|
|
|
forkBlockField* = collectBlockFields()
|
|
|
|
forkTimeField* = collectTimeFields()
|
2022-12-02 04:39:12 +00:00
|
|
|
|
2023-02-16 11:40:07 +00:00
|
|
|
|
|
|
|
func mergeForkTransitionThreshold*(conf: ChainConfig): MergeForkTransitionThreshold =
|
2023-08-06 07:55:11 +00:00
|
|
|
MergeForkTransitionThreshold(
|
2024-06-14 07:31:08 +00:00
|
|
|
number: conf.mergeForkBlock,
|
2023-08-06 07:55:11 +00:00
|
|
|
ttd: conf.terminalTotalDifficulty,
|
|
|
|
ttdPassed: conf.terminalTotalDifficultyPassed
|
|
|
|
)
|
2023-02-16 11:40:07 +00:00
|
|
|
|
2024-05-28 05:10:10 +00:00
|
|
|
func toForkTransitionTable*(conf: ChainConfig): ForkTransitionTable =
|
2023-02-16 11:40:07 +00:00
|
|
|
# We used to auto-generate this code from a list of
|
|
|
|
# field names, but it doesn't seem worthwhile anymore
|
|
|
|
# (now that there's irregularity due to block-based vs
|
|
|
|
# timestamp-based forking).
|
2024-06-14 07:31:08 +00:00
|
|
|
result.blockNumberThresholds[Frontier ] = Opt.some(0.BlockNumber)
|
2023-02-16 11:40:07 +00:00
|
|
|
result.blockNumberThresholds[Homestead ] = conf.homesteadBlock
|
|
|
|
result.blockNumberThresholds[DAOFork ] = conf.daoForkBlock
|
|
|
|
result.blockNumberThresholds[Tangerine ] = conf.eip150Block
|
|
|
|
result.blockNumberThresholds[Spurious ] = conf.eip158Block
|
|
|
|
result.blockNumberThresholds[Byzantium ] = conf.byzantiumBlock
|
|
|
|
result.blockNumberThresholds[Constantinople] = conf.constantinopleBlock
|
|
|
|
result.blockNumberThresholds[Petersburg ] = conf.petersburgBlock
|
|
|
|
result.blockNumberThresholds[Istanbul ] = conf.istanbulBlock
|
|
|
|
result.blockNumberThresholds[MuirGlacier ] = conf.muirGlacierBlock
|
|
|
|
result.blockNumberThresholds[Berlin ] = conf.berlinBlock
|
|
|
|
result.blockNumberThresholds[London ] = conf.londonBlock
|
|
|
|
result.blockNumberThresholds[ArrowGlacier ] = conf.arrowGlacierBlock
|
|
|
|
result.blockNumberThresholds[GrayGlacier ] = conf.grayGlacierBlock
|
|
|
|
result.mergeForkTransitionThreshold = conf.mergeForkTransitionThreshold
|
|
|
|
result.timeThresholds[Shanghai] = conf.shanghaiTime
|
|
|
|
result.timeThresholds[Cancun] = conf.cancunTime
|
2024-03-28 06:47:02 +00:00
|
|
|
result.timeThresholds[Prague] = conf.pragueTime
|
2023-02-16 11:40:07 +00:00
|
|
|
|
2024-05-28 05:10:10 +00:00
|
|
|
func populateFromForkTransitionTable*(conf: ChainConfig, t: ForkTransitionTable) =
|
2023-02-16 11:40:07 +00:00
|
|
|
conf.homesteadBlock = t.blockNumberThresholds[HardFork.Homestead]
|
|
|
|
conf.daoForkBlock = t.blockNumberThresholds[HardFork.DAOFork]
|
|
|
|
conf.eip150Block = t.blockNumberThresholds[HardFork.Tangerine]
|
|
|
|
conf.eip155Block = t.blockNumberThresholds[HardFork.Spurious]
|
|
|
|
conf.eip158Block = t.blockNumberThresholds[HardFork.Spurious]
|
|
|
|
conf.byzantiumBlock = t.blockNumberThresholds[HardFork.Byzantium]
|
|
|
|
conf.constantinopleBlock = t.blockNumberThresholds[HardFork.Constantinople]
|
|
|
|
conf.petersburgBlock = t.blockNumberThresholds[HardFork.Petersburg]
|
|
|
|
conf.istanbulBlock = t.blockNumberThresholds[HardFork.Istanbul]
|
|
|
|
conf.muirGlacierBlock = t.blockNumberThresholds[HardFork.MuirGlacier]
|
|
|
|
conf.berlinBlock = t.blockNumberThresholds[HardFork.Berlin]
|
|
|
|
conf.londonBlock = t.blockNumberThresholds[HardFork.London]
|
|
|
|
conf.arrowGlacierBlock = t.blockNumberThresholds[HardFork.ArrowGlacier]
|
|
|
|
conf.grayGlacierBlock = t.blockNumberThresholds[HardFork.GrayGlacier]
|
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
conf.mergeForkBlock = t.mergeForkTransitionThreshold.number
|
2023-02-16 11:40:07 +00:00
|
|
|
conf.terminalTotalDifficulty = t.mergeForkTransitionThreshold.ttd
|
2023-08-06 07:55:11 +00:00
|
|
|
conf.terminalTotalDifficultyPassed = t.mergeForkTransitionThreshold.ttdPassed
|
|
|
|
|
2023-02-16 11:40:07 +00:00
|
|
|
conf.shanghaiTime = t.timeThresholds[HardFork.Shanghai]
|
|
|
|
conf.cancunTime = t.timeThresholds[HardFork.Cancun]
|
2024-03-28 06:47:02 +00:00
|
|
|
conf.pragueTime = t.timeThresholds[HardFork.Prague]
|
2023-02-16 11:40:07 +00:00
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Map HardFork to EVM/EVMC Fork
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const
|
|
|
|
ToEVMFork*: array[HardFork, EVMFork] = [
|
|
|
|
FkFrontier, # Frontier
|
|
|
|
FkHomestead, # Homestead
|
|
|
|
FkHomestead, # DAOFork
|
|
|
|
FkTangerine, # Tangerine
|
|
|
|
FkSpurious, # Spurious
|
|
|
|
FkByzantium, # Byzantium
|
|
|
|
FkConstantinople, # Constantinople
|
|
|
|
FkPetersburg, # Petersburg
|
|
|
|
FkIstanbul, # Istanbul
|
|
|
|
FkIstanbul, # MuirGlacier
|
|
|
|
FkBerlin, # Berlin
|
|
|
|
FkLondon, # London
|
|
|
|
FkLondon, # ArrowGlacier
|
|
|
|
FkLondon, # GrayGlacier
|
|
|
|
FkParis, # MergeFork
|
|
|
|
FkShanghai, # Shanghai
|
|
|
|
FkCancun, # Cancun
|
2024-03-28 06:47:02 +00:00
|
|
|
FkPrague, # Prague
|
2022-12-02 04:39:12 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Fork ID helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-24 10:39:19 +00:00
|
|
|
type
|
|
|
|
ForkIdCalculator* = object
|
|
|
|
byBlock: seq[uint64]
|
|
|
|
byTime: seq[uint64]
|
|
|
|
genesisCRC: uint32
|
|
|
|
|
|
|
|
func newID*(calc: ForkIdCalculator, head, time: uint64): ForkID =
|
|
|
|
var hash = calc.genesisCRC
|
|
|
|
for fork in calc.byBlock:
|
|
|
|
if fork <= head:
|
|
|
|
# Fork already passed, checksum the previous hash and the fork number
|
|
|
|
hash = crc32(hash, fork.toBytesBE)
|
|
|
|
continue
|
|
|
|
return (hash, fork)
|
|
|
|
|
|
|
|
for fork in calc.byTime:
|
|
|
|
if fork <= time:
|
|
|
|
# Fork already passed, checksum the previous hash and fork timestamp
|
|
|
|
hash = crc32(hash, fork.toBytesBE)
|
|
|
|
continue
|
|
|
|
return (hash, fork)
|
|
|
|
|
|
|
|
(hash, 0'u64)
|
|
|
|
|
|
|
|
func initForkIdCalculator*(map: ForkTransitionTable,
|
|
|
|
genesisCRC: uint32,
|
|
|
|
genesisTime: uint64): ForkIdCalculator =
|
|
|
|
|
|
|
|
# Extract the fork rule block number aggregate it
|
|
|
|
var forksByBlock: seq[uint64]
|
|
|
|
for fork, val in map.blockNumberThresholds:
|
|
|
|
if val.isNone: continue
|
2024-06-14 07:31:08 +00:00
|
|
|
let val64 = val.get
|
2023-10-24 10:39:19 +00:00
|
|
|
if forksByBlock.len == 0:
|
|
|
|
forksByBlock.add val64
|
|
|
|
elif forksByBlock[^1] != val64:
|
|
|
|
# Deduplicate fork identifiers applying multiple forks
|
|
|
|
forksByBlock.add val64
|
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
if map.mergeForkTransitionThreshold.number.isSome:
|
|
|
|
let val64 = map.mergeForkTransitionThreshold.number.get
|
2023-10-24 10:39:19 +00:00
|
|
|
if forksByBlock.len == 0:
|
|
|
|
forksByBlock.add val64
|
|
|
|
elif forksByBlock[^1] != val64:
|
|
|
|
# Deduplicate fork identifiers applying multiple forks
|
|
|
|
forksByBlock.add val64
|
|
|
|
|
|
|
|
# Skip any forks in block 0, that's the genesis ruleset
|
|
|
|
if forksByBlock.len > 0 and forksByBlock[0] == 0:
|
|
|
|
forksByBlock.delete(0)
|
|
|
|
|
|
|
|
# Extract the fork rule timestamp number aggregate it
|
|
|
|
var forksByTime: seq[uint64]
|
|
|
|
for fork, val in map.timeThresholds:
|
|
|
|
if val.isNone: continue
|
|
|
|
let val64 = val.get.uint64
|
|
|
|
if forksByTime.len == 0:
|
|
|
|
forksByTime.add val64
|
|
|
|
elif forksByTime[^1] != val64:
|
|
|
|
forksByTime.add val64
|
|
|
|
|
|
|
|
# Skip any forks before genesis.
|
|
|
|
while forksByTime.len > 0 and forksByTime[0] <= genesisTime:
|
|
|
|
forksByTime.delete(0)
|
|
|
|
|
|
|
|
result.genesisCRC = genesisCRC
|
|
|
|
result.byBlock = system.move(forksByBlock)
|
|
|
|
result.byTime = system.move(forksByTime)
|
2022-12-02 04:39:12 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|