Remove MergeForkBlock alias and use MergeNetSplitBlock only (#2947)

This commit is contained in:
andri lim 2024-12-17 18:42:13 +07:00 committed by GitHub
parent f8a6ed4f5f
commit b8932d9519
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 15 additions and 31 deletions

View File

@ -70,7 +70,7 @@ type
# - `EthTime` uses std/times while chronos Moment is sufficient and more
# sensible
ChainConfig* = object
mergeForkBlock*: uint64
mergeNetsplitBlock*: uint64
shanghaiTime*: Opt[Moment]
cancunTime*: Opt[Moment]
@ -81,7 +81,7 @@ const
mergeBlockNumber* {.intdefine.}: uint64 = 15537394
chainConfig* = ChainConfig(
mergeForkBlock: mergeBlockNumber,
mergeNetsplitBlock: mergeBlockNumber,
shanghaiTime: Opt.some(Moment.init(1681338455'i64, Second)),
cancunTime: Opt.none(Moment),
)
@ -93,7 +93,7 @@ func isTimestampForked(forkTime: Opt[Moment], timestamp: Moment): bool =
forkTime.get() <= timestamp
func isPoSBlock*(c: ChainConfig, blockNumber: uint64): bool =
c.mergeForkBlock <= blockNumber
c.mergeNetsplitBlock <= blockNumber
func isShanghai*(c: ChainConfig, timestamp: Moment): bool =
isTimestampForked(c.shanghaiTime, timestamp)

View File

@ -40,7 +40,7 @@ method getForkConfig*(cs: ForkIDSpec): ChainConfig =
# Merge fork happen at block 0
let mainFork = cs.getMainFork()
if mainFork == ForkParis:
forkConfig.mergeForkBlock = Opt.some(0'u64)
forkConfig.mergeNetsplitBlock = Opt.some(0'u64)
return forkConfig
method execute(cs: ForkIDSpec, env: TestEnv): bool =

View File

@ -31,7 +31,7 @@ method getForkConfig*(cs: NonZeroPreMergeFork): ChainConfig =
# Merge fork & pre-merge happen at block 1
forkConfig.londonBlock = Opt.some(1'u64)
forkConfig.mergeForkBlock = Opt.some(1'u64)
forkConfig.mergeNetsplitBlock = Opt.some(1'u64)
# Post-merge fork happens at block 2
let mainFork = BaseSpec(cs).getMainFork()

View File

@ -307,10 +307,6 @@ func toHardFork*(map: ForkTransitionTable, forkDeterminer: ForkDeterminationInfo
proc validateChainConfig*(conf: ChainConfig): bool =
result = true
if conf.mergeNetsplitBlock.isSome:
# geth compatibility
conf.mergeForkBlock = conf.mergeNetsplitBlock
# FIXME: factor this to remove the duplication between the
# block-based ones and the time-based ones.
@ -491,7 +487,7 @@ func chainConfigForNetwork*(id: NetworkId): ChainConfig =
muirGlacierBlock: Opt.some(0.BlockNumber),
berlinBlock: Opt.some(0.BlockNumber),
londonBlock: Opt.some(0.BlockNumber),
mergeForkBlock: Opt.some(1450409.BlockNumber),
mergeNetsplitBlock: Opt.some(1450409.BlockNumber),
terminalTotalDifficulty: Opt.some(sepoliaTTD),
shanghaiTime: Opt.some(1_677_557_088.EthTime),
cancunTime: Opt.some(1_706_655_072.EthTime), # 2024-01-30 22:51:12
@ -512,7 +508,7 @@ func chainConfigForNetwork*(id: NetworkId): ChainConfig =
istanbulBlock: Opt.some(0.BlockNumber),
berlinBlock: Opt.some(0.BlockNumber),
londonBlock: Opt.some(0.BlockNumber),
mergeForkBlock: Opt.some(0.BlockNumber),
mergeNetsplitBlock: Opt.some(0.BlockNumber),
terminalTotalDifficulty: Opt.some(0.u256),
shanghaiTime: Opt.some(1_696_000_704.EthTime),
cancunTime: Opt.some(1_707_305_664.EthTime), # 2024-02-07 11:34:24

View File

@ -336,8 +336,8 @@ proc proofOfStake*(com: CommonRef, header: Header): bool =
if com.config.posBlock.isSome:
# see comments of posBlock in common/hardforks.nim
header.number >= com.config.posBlock.get
elif com.config.mergeForkBlock.isSome:
header.number >= com.config.mergeForkBlock.get
elif com.config.mergeNetsplitBlock.isSome:
header.number >= com.config.mergeNetsplitBlock.get
else:
# This costly check is only executed from test suite
com.isBlockAfterTtd(header)

View File

@ -163,11 +163,8 @@ type
posBlock*
{.dontSerialize.} : Opt[BlockNumber]
# mergeNetsplitBlock is an alias to mergeForkBlock
# and is used for geth compatibility layer
mergeNetsplitBlock* : Opt[BlockNumber]
mergeForkBlock* : Opt[BlockNumber]
shanghaiTime* : Opt[EthTime]
cancunTime* : Opt[EthTime]
pragueTime* : Opt[EthTime]
@ -194,11 +191,7 @@ func countTimeFields(): int {.compileTime.} =
func countBlockFields(): int {.compileTime.} =
var z = ChainConfig()
for name, _ in fieldPairs(z[]):
if name == "mergeNetsplitBlock":
# skip mergeForkBlock alias
# continue is not supported
discard
elif name.endsWith("Block"):
if name.endsWith("Block"):
inc result
const
@ -217,11 +210,7 @@ func collectBlockFields(): array[blockFieldsCount, string] =
var z = ChainConfig()
var i = 0
for name, _ in fieldPairs(z[]):
if name == "mergeNetsplitBlock":
# skip mergeForkBlock alias
# continue is not supported
discard
elif name.endsWith("Block"):
if name.endsWith("Block"):
result[i] = name
inc i
@ -235,7 +224,7 @@ const
func mergeForkTransitionThreshold*(conf: ChainConfig): MergeForkTransitionThreshold =
MergeForkTransitionThreshold(
number: conf.mergeForkBlock,
number: conf.mergeNetsplitBlock,
ttd: conf.terminalTotalDifficulty,
)
@ -280,7 +269,7 @@ func populateFromForkTransitionTable*(conf: ChainConfig, t: ForkTransitionTable)
conf.arrowGlacierBlock = t.blockNumberThresholds[HardFork.ArrowGlacier]
conf.grayGlacierBlock = t.blockNumberThresholds[HardFork.GrayGlacier]
conf.mergeForkBlock = t.mergeForkTransitionThreshold.number
conf.mergeNetsplitBlock = t.mergeForkTransitionThreshold.number
conf.terminalTotalDifficulty = t.mergeForkTransitionThreshold.ttd
conf.shanghaiTime = t.timeThresholds[HardFork.Shanghai]

View File

@ -96,7 +96,7 @@ func config(shanghai, cancun: uint64): ChainConfig =
berlinBlock: Opt.some(0'u64),
londonBlock: Opt.some(0'u64),
terminalTotalDifficulty: Opt.some(0.u256),
mergeForkBlock: Opt.some(0'u64),
mergeNetsplitBlock: Opt.some(0'u64),
shanghaiTime: Opt.some(shanghai.EthTime),
cancunTime: Opt.some(cancun.EthTime),
)

View File

@ -109,7 +109,6 @@ proc customGenesisTest() =
check com.proofOfStake(com.genesisHeader) == false
check cg.config.mergeNetsplitBlock.isSome
check cg.config.mergeNetsplitBlock.get == 14660963.BlockNumber
check cg.config.mergeNetsplitBlock == cg.config.mergeForkBlock
test "Holesky":
var cg: NetworkParams

View File

@ -113,7 +113,7 @@ proc initEnv(envFork: HardFork): TestEnv =
conf.networkParams.genesis.alloc[recipient] = GenesisAccount(code: contractCode)
if envFork >= MergeFork:
conf.networkParams.config.mergeForkBlock = Opt.some(0'u64)
conf.networkParams.config.mergeNetsplitBlock = Opt.some(0'u64)
conf.networkParams.config.terminalTotalDifficulty = Opt.some(100.u256)
if envFork >= Shanghai: