2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2023 Status Research & Development GmbH
|
|
|
|
# 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.
|
|
|
|
|
2023-10-19 03:28:52 +00:00
|
|
|
import
|
|
|
|
std/[options],
|
|
|
|
eth/common,
|
|
|
|
./clmock,
|
|
|
|
./types,
|
|
|
|
../../../tools/common/helpers,
|
|
|
|
../../../nimbus/common/chain_config
|
|
|
|
|
|
|
|
func getBlockTimeIncrements*(s: BaseSpec): int =
|
|
|
|
if s.blockTimestampIncrement == 0:
|
|
|
|
return 1
|
|
|
|
return s.blockTimestampIncrement
|
|
|
|
|
|
|
|
proc configureCLMock*(s: BaseSpec, cl: CLMocker) =
|
|
|
|
if s.slotsToSafe != 0:
|
|
|
|
cl.slotsToSafe = s.slotsToSafe
|
|
|
|
|
|
|
|
if s.slotsToFinalized != 0:
|
|
|
|
cl.slotsToFinalized = s.slotsToFinalized
|
|
|
|
|
|
|
|
if s.safeSlotsToImportOptimistically != 0:
|
|
|
|
cl.safeSlotsToImportOptimistically = s.safeSlotsToImportOptimistically
|
|
|
|
|
|
|
|
cl.blockTimestampIncrement = some(s.getBlockTimeIncrements())
|
|
|
|
|
2023-10-31 03:18:37 +00:00
|
|
|
func getMainFork*(s: BaseSpec): EngineFork =
|
2023-10-19 03:28:52 +00:00
|
|
|
let mainFork = s.mainFork
|
2023-10-31 03:18:37 +00:00
|
|
|
if mainFork == ForkNone:
|
2023-10-19 03:28:52 +00:00
|
|
|
return ForkParis
|
|
|
|
return mainFork
|
|
|
|
|
|
|
|
func getGenesisTimestamp*(s: BaseSpec): uint64 =
|
|
|
|
var genesisTimestamp = GenesisTimestamp
|
|
|
|
if s.genesisTimestamp != 0:
|
|
|
|
genesisTimestamp = s.genesisTimestamp
|
|
|
|
return genesisTimestamp.uint64
|
|
|
|
|
|
|
|
func getBlockTime*(s: BaseSpec, blockNumber: uint64): uint64 =
|
|
|
|
return s.getGenesisTimestamp() + blockNumber*s.getBlockTimeIncrements().uint64
|
|
|
|
|
|
|
|
func getForkTime*(s: BaseSpec): uint64 =
|
|
|
|
var forkTime = s.forkTime
|
|
|
|
if s.forkHeight > 0:
|
|
|
|
forkTime = s.getBlockTime(s.forkHeight.uint64)
|
|
|
|
return forkTime
|
|
|
|
|
2023-10-31 03:18:37 +00:00
|
|
|
method getForkConfig*(s: BaseSpec): ChainConfig {.base.} =
|
2023-10-19 03:28:52 +00:00
|
|
|
let
|
|
|
|
forkTime = s.getForkTime()
|
|
|
|
previousForkTime = s.previousForkTime
|
|
|
|
mainFork = s.getMainFork()
|
2023-10-31 03:18:37 +00:00
|
|
|
forkConfig = getChainConfig($mainFork)
|
2023-10-19 03:28:52 +00:00
|
|
|
genesisTimestamp = s.getGenesisTimestamp()
|
|
|
|
|
|
|
|
doAssert(previousForkTime <= forkTime,
|
|
|
|
"previous fork time cannot be greater than fork time")
|
|
|
|
|
|
|
|
if mainFork == ForkParis:
|
2023-10-31 03:18:37 +00:00
|
|
|
# Cannot configure a fork before Paris, skip test
|
|
|
|
if forkTime > genesisTimestamp or previousForkTime != 0:
|
|
|
|
debugEcho "forkTime: ", forkTime
|
|
|
|
debugEcho "genesisTime: ", genesisTimestamp
|
|
|
|
return nil
|
2023-10-19 03:28:52 +00:00
|
|
|
elif mainFork == ForkShanghai:
|
2023-10-31 03:18:37 +00:00
|
|
|
# Cannot configure a fork before Shanghai
|
|
|
|
if previousForkTime != 0:
|
|
|
|
return nil
|
2023-10-19 03:28:52 +00:00
|
|
|
forkConfig.shanghaiTime = some(forkTime.EthTime)
|
|
|
|
elif mainFork == ForkCancun:
|
|
|
|
forkConfig.shanghaiTime = some(previousForkTime.EthTime)
|
|
|
|
forkConfig.cancunTime = some(forkTime.EthTime)
|
|
|
|
else:
|
2023-10-31 03:18:37 +00:00
|
|
|
doAssert(false, "unknown fork: " & $mainFork)
|
2023-10-19 03:28:52 +00:00
|
|
|
|
|
|
|
return forkConfig
|