2022-11-25 05:26:29 +00:00
|
|
|
# Nimbus
|
2024-02-21 09:14:20 +00:00
|
|
|
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
2022-11-25 05:26:29 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
|
|
|
import
|
2022-12-02 04:39:12 +00:00
|
|
|
../../nimbus/common/common,
|
2022-11-25 05:26:29 +00:00
|
|
|
./types
|
|
|
|
|
|
|
|
export
|
|
|
|
types
|
|
|
|
|
2023-02-16 11:40:07 +00:00
|
|
|
const
|
2024-06-14 07:31:08 +00:00
|
|
|
BlockNumberZero = 0.BlockNumber
|
|
|
|
BlockNumberFive = 5.BlockNumber
|
2023-10-18 02:16:11 +00:00
|
|
|
TimeZero = EthTime(0)
|
2023-02-16 11:40:07 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
proc createForkTransitionTable(transitionFork: HardFork,
|
|
|
|
b: Opt[BlockNumber],
|
|
|
|
t: Opt[EthTime],
|
|
|
|
ttd: Opt[DifficultyInt]): ForkTransitionTable =
|
2023-09-21 15:21:21 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
proc blockNumberToUse(f: HardFork): Opt[BlockNumber] =
|
2023-02-16 11:40:07 +00:00
|
|
|
if f < transitionFork:
|
2024-06-14 07:31:08 +00:00
|
|
|
Opt.some(BlockNumberZero)
|
2023-02-16 11:40:07 +00:00
|
|
|
elif f == transitionFork:
|
|
|
|
b
|
|
|
|
else:
|
2024-06-14 07:31:08 +00:00
|
|
|
Opt.none(BlockNumber)
|
2023-09-21 15:21:21 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
proc timeToUse(f: HardFork): Opt[EthTime] =
|
2023-02-16 11:40:07 +00:00
|
|
|
if f < transitionFork:
|
2024-06-14 07:31:08 +00:00
|
|
|
Opt.some(TimeZero)
|
2023-02-16 11:40:07 +00:00
|
|
|
elif f == transitionFork:
|
|
|
|
t
|
|
|
|
else:
|
2024-06-14 07:31:08 +00:00
|
|
|
Opt.none(EthTime)
|
2023-09-21 15:21:21 +00:00
|
|
|
|
2023-02-16 11:40:07 +00:00
|
|
|
for f in low(HardFork) .. lastPurelyBlockNumberBasedFork:
|
|
|
|
result.blockNumberThresholds[f] = blockNumberToUse(f)
|
2022-11-25 05:26:29 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
result.mergeForkTransitionThreshold.number = blockNumberToUse(HardFork.MergeFork)
|
2023-02-16 11:40:07 +00:00
|
|
|
result.mergeForkTransitionThreshold.ttd = ttd
|
2023-09-21 15:21:21 +00:00
|
|
|
|
2023-02-16 11:40:07 +00:00
|
|
|
for f in firstTimeBasedFork .. high(HardFork):
|
|
|
|
result.timeThresholds[f] = timeToUse(f)
|
2022-11-25 05:26:29 +00:00
|
|
|
|
2023-02-16 11:40:07 +00:00
|
|
|
proc assignNumber(c: ChainConfig, transitionFork: HardFork, n: BlockNumber) =
|
2024-06-14 07:31:08 +00:00
|
|
|
let table = createForkTransitionTable(transitionFork,
|
|
|
|
Opt.some(n), Opt.none(EthTime), Opt.none(DifficultyInt))
|
2023-02-16 11:40:07 +00:00
|
|
|
c.populateFromForkTransitionTable(table)
|
2022-11-25 05:26:29 +00:00
|
|
|
|
2023-02-16 11:40:07 +00:00
|
|
|
proc assignTime(c: ChainConfig, transitionFork: HardFork, t: EthTime) =
|
2024-06-14 07:31:08 +00:00
|
|
|
let table = createForkTransitionTable(transitionFork,
|
|
|
|
Opt.none(BlockNumber), Opt.some(t), Opt.none(DifficultyInt))
|
2023-02-16 11:40:07 +00:00
|
|
|
c.populateFromForkTransitionTable(table)
|
2024-07-17 10:05:53 +00:00
|
|
|
c.terminalTotalDifficulty = Opt.some(0.u256)
|
2023-02-16 11:40:07 +00:00
|
|
|
|
|
|
|
func getChainConfig*(network: string, c: ChainConfig) =
|
2022-11-25 05:26:29 +00:00
|
|
|
c.daoForkSupport = false
|
|
|
|
c.chainId = 1.ChainId
|
2024-06-14 07:31:08 +00:00
|
|
|
c.terminalTotalDifficulty = Opt.none(UInt256)
|
2022-11-25 05:26:29 +00:00
|
|
|
|
|
|
|
case network
|
|
|
|
of $TestFork.Frontier:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Frontier, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.Homestead:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Homestead, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.EIP150:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Tangerine, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.EIP158:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Spurious, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.Byzantium:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Byzantium, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.Constantinople:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Constantinople, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.ConstantinopleFix:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Petersburg, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.Istanbul:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Istanbul, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.FrontierToHomesteadAt5:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Homestead, BlockNumberFive)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.HomesteadToEIP150At5:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Tangerine, BlockNumberFive)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.HomesteadToDaoAt5:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.DAOFork, BlockNumberFive)
|
2022-11-25 05:26:29 +00:00
|
|
|
c.daoForkSupport = true
|
|
|
|
of $TestFork.EIP158ToByzantiumAt5:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Byzantium, BlockNumberFive)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.ByzantiumToConstantinopleAt5:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Constantinople, BlockNumberFive)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.ByzantiumToConstantinopleFixAt5:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Petersburg, BlockNumberFive)
|
2024-06-14 07:31:08 +00:00
|
|
|
c.constantinopleBlock = Opt.some(BlockNumberFive)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.ConstantinopleFixToIstanbulAt5:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Istanbul, BlockNumberFive)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.Berlin:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.Berlin, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.BerlinToLondonAt5:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.London, BlockNumberFive)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.London:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.London, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.ArrowGlacier:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.ArrowGlacier, BlockNumberZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.GrayGlacier:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.GrayGlacier, BlockNumberZero)
|
2024-02-21 16:04:44 +00:00
|
|
|
of $TestFork.Merge, $TestFork.Paris:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.MergeFork, BlockNumberZero)
|
2024-07-17 10:05:53 +00:00
|
|
|
c.terminalTotalDifficulty = Opt.some(0.u256)
|
2024-02-21 09:14:20 +00:00
|
|
|
of $TestFork.ArrowGlacierToParisAtDiffC0000:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignNumber(HardFork.GrayGlacier, BlockNumberZero)
|
2024-06-14 07:31:08 +00:00
|
|
|
c.terminalTotalDifficulty = Opt.some(0xC0000.u256)
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.Shanghai:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignTime(HardFork.Shanghai, TimeZero)
|
2024-02-21 09:14:20 +00:00
|
|
|
of $TestFork.ParisToShanghaiAtTime15k:
|
2023-10-18 02:16:11 +00:00
|
|
|
c.assignTime(HardFork.Shanghai, EthTime(15000))
|
2022-11-25 05:26:29 +00:00
|
|
|
of $TestFork.Cancun:
|
2023-02-16 11:40:07 +00:00
|
|
|
c.assignTime(HardFork.Cancun, TimeZero)
|
2023-09-21 15:21:21 +00:00
|
|
|
of $TestFork.ShanghaiToCancunAtTime15k:
|
2023-10-18 02:16:11 +00:00
|
|
|
c.assignTime(HardFork.Cancun, EthTime(15000))
|
2024-07-04 13:48:36 +00:00
|
|
|
of $TestFork.Prague:
|
|
|
|
c.assignTime(HardFork.Prague, TimeZero)
|
2022-11-25 05:26:29 +00:00
|
|
|
else:
|
|
|
|
raise newException(ValueError, "unsupported network " & network)
|
|
|
|
|
|
|
|
func getChainConfig*(network: string): ChainConfig =
|
|
|
|
let c = ChainConfig()
|
|
|
|
getChainConfig(network, c)
|
|
|
|
result = c
|