nimbus-eth1/hive_integration/nodocker/engine/base_spec.nim

85 lines
2.6 KiB
Nim
Raw Normal View History

2023-11-01 03:32:09 +00:00
# Nimbus
# Copyright (c) 2023-2024 Status Research & Development GmbH
2023-11-01 03:32:09 +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
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 = Opt.some(s.getBlockTimeIncrements())
2023-10-31 03:18:37 +00:00
func getMainFork*(s: BaseSpec): EngineFork =
let mainFork = s.mainFork
2023-10-31 03:18:37 +00:00
if mainFork == ForkNone:
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.} =
let
forkTime = s.getForkTime()
previousForkTime = s.previousForkTime
mainFork = s.getMainFork()
2023-10-31 03:18:37 +00:00
forkConfig = getChainConfig($mainFork)
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
elif mainFork == ForkShanghai:
2023-10-31 03:18:37 +00:00
# Cannot configure a fork before Shanghai
if previousForkTime != 0:
return nil
forkConfig.shanghaiTime = Opt.some(forkTime.EthTime)
elif mainFork == ForkCancun:
forkConfig.shanghaiTime = Opt.some(previousForkTime.EthTime)
forkConfig.cancunTime = Opt.some(forkTime.EthTime)
else:
2023-10-31 03:18:37 +00:00
doAssert(false, "unknown fork: " & $mainFork)
return forkConfig