2021-03-26 06:52:01 +00:00
|
|
|
# beacon_chain
|
2023-01-20 14:14:37 +00:00
|
|
|
# Copyright (c) 2018-2023 Status Research & Development GmbH
|
2021-02-02 22:31:01 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2023-01-20 14:14:37 +00:00
|
|
|
{.push raises: [].}
|
2021-03-26 06:52:01 +00:00
|
|
|
|
2020-07-02 15:14:11 +00:00
|
|
|
import
|
2021-10-12 11:36:52 +00:00
|
|
|
std/[sequtils, strutils, os],
|
2022-12-19 17:19:48 +00:00
|
|
|
stew/[byteutils, objects], stew/shims/macros, nimcrypto/hash,
|
2020-07-09 22:08:54 +00:00
|
|
|
web3/[ethtypes, conversions],
|
2020-09-01 09:01:57 +00:00
|
|
|
chronicles,
|
2021-03-26 14:11:06 +00:00
|
|
|
eth/common/eth_types_json_serialization,
|
2021-08-18 18:57:58 +00:00
|
|
|
../spec/eth2_ssz_serialization,
|
2021-08-12 13:08:20 +00:00
|
|
|
../spec/datatypes/phase0
|
2020-07-02 15:14:11 +00:00
|
|
|
|
|
|
|
# ATTENTION! This file will produce a large C file, because we are inlining
|
|
|
|
# genesis states as C literals in the generated code (and blobs in the final
|
|
|
|
# binary). It makes sense to keep the file small and separated from the rest
|
|
|
|
# of the module in order go gain maximum efficiency in incremental compilation.
|
|
|
|
#
|
2020-11-10 18:41:04 +00:00
|
|
|
# TODO(zah):
|
2020-07-02 15:14:11 +00:00
|
|
|
# We can compress the embedded states with snappy before embedding them here.
|
|
|
|
|
2023-04-27 10:36:22 +00:00
|
|
|
# ATTENTION! This file is intentionally avoiding the Nim `/` operator for
|
|
|
|
# constructing paths. The standard operator is relying the `DirSep` constant
|
|
|
|
# which depends on the selected target OS (when doing cross-compilation), so
|
|
|
|
# the compile-time manipulation of paths performed here will break (e.g. when
|
|
|
|
# cross-compiling for Windows from Linux)
|
|
|
|
#
|
|
|
|
# Nim seems to need a more general solution for detecting the host OS during
|
|
|
|
# compilation, so a host OS specific separator can be used when deriving paths
|
|
|
|
# from `currentSourcePath`.
|
|
|
|
|
2020-07-02 15:14:11 +00:00
|
|
|
export
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
ethtypes, conversions, RuntimeConfig
|
2020-07-02 15:14:11 +00:00
|
|
|
|
|
|
|
type
|
2020-07-09 22:08:54 +00:00
|
|
|
Eth1BlockHash* = ethtypes.BlockHash
|
2020-07-02 15:14:11 +00:00
|
|
|
|
|
|
|
Eth1Network* = enum
|
|
|
|
mainnet
|
2022-05-20 15:26:07 +00:00
|
|
|
ropsten
|
2020-07-02 15:14:11 +00:00
|
|
|
rinkeby
|
|
|
|
goerli
|
2022-06-16 14:11:26 +00:00
|
|
|
sepolia
|
2020-07-02 15:14:11 +00:00
|
|
|
|
|
|
|
Eth2NetworkMetadata* = object
|
2020-07-09 22:08:54 +00:00
|
|
|
case incompatible*: bool
|
|
|
|
of false:
|
2020-11-06 21:45:56 +00:00
|
|
|
# TODO work-around a Nim codegen issue where upon constant assignment
|
|
|
|
# the compiler will copy `incompatibilityDesc` even when the case
|
|
|
|
# branch is not active and thus it will override the first variable
|
|
|
|
# in this branch.
|
|
|
|
dummy: string
|
2023-03-05 01:40:21 +00:00
|
|
|
# If the eth1Network is specified, the ELManager will perform some
|
2021-09-08 12:47:48 +00:00
|
|
|
# additional checks to ensure we are connecting to a web3 provider
|
|
|
|
# serving data for the same network. The value can be set to `None`
|
|
|
|
# for custom networks and testing purposes.
|
2020-07-09 22:08:54 +00:00
|
|
|
eth1Network*: Option[Eth1Network]
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg*: RuntimeConfig
|
2020-07-09 22:08:54 +00:00
|
|
|
|
|
|
|
# Parsing `enr.Records` is still not possible at compile-time
|
|
|
|
bootstrapNodes*: seq[string]
|
|
|
|
|
2022-12-19 17:19:48 +00:00
|
|
|
depositContractBlock*: uint64
|
|
|
|
depositContractBlockHash*: Eth2Digest
|
2020-07-09 22:08:54 +00:00
|
|
|
|
|
|
|
# Please note that we are using `string` here because SSZ.decode
|
|
|
|
# is not currently usable at compile time and we want to load the
|
|
|
|
# network metadata into a constant.
|
|
|
|
#
|
|
|
|
# We could have also used `seq[byte]`, but this results in a lot
|
|
|
|
# more generated code that slows down compilation. The impact on
|
|
|
|
# compilation times of embedding the genesis as a string is roughly
|
|
|
|
# 0.1s on my machine (you can test this by choosing an invalid name
|
|
|
|
# for the genesis file below).
|
|
|
|
#
|
|
|
|
# `genesisData` will have `len == 0` for networks with a still
|
|
|
|
# unknown genesis state.
|
|
|
|
genesisData*: string
|
2020-11-24 21:21:47 +00:00
|
|
|
genesisDepositsSnapshot*: string
|
2020-07-09 22:08:54 +00:00
|
|
|
else:
|
|
|
|
incompatibilityDesc*: string
|
2020-07-02 15:14:11 +00:00
|
|
|
|
2020-11-24 21:21:47 +00:00
|
|
|
const
|
2021-07-13 14:27:10 +00:00
|
|
|
eth2NetworksDir = currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor/eth2-networks"
|
2023-03-29 08:37:14 +00:00
|
|
|
sepoliaDir = currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor/sepolia"
|
2020-11-24 21:21:47 +00:00
|
|
|
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
proc readBootstrapNodes*(path: string): seq[string] {.raises: [IOError, Defect].} =
|
|
|
|
# Read a list of ENR values from a YAML file containing a flat list of entries
|
|
|
|
if fileExists(path):
|
|
|
|
splitLines(readFile(path)).
|
|
|
|
filterIt(it.startsWith("enr:")).
|
|
|
|
mapIt(it.strip())
|
|
|
|
else:
|
|
|
|
@[]
|
|
|
|
|
|
|
|
proc readBootEnr*(path: string): seq[string] {.raises: [IOError, Defect].} =
|
|
|
|
# Read a list of ENR values from a YAML file containing a flat list of entries
|
|
|
|
if fileExists(path):
|
|
|
|
splitLines(readFile(path)).
|
|
|
|
filterIt(it.startsWith("- enr:")).
|
|
|
|
mapIt(it[2..^1].strip())
|
|
|
|
else:
|
|
|
|
@[]
|
2020-07-03 19:29:23 +00:00
|
|
|
|
2022-02-25 08:22:44 +00:00
|
|
|
proc loadEth2NetworkMetadata*(path: string, eth1Network = none(Eth1Network)): Eth2NetworkMetadata
|
2020-07-02 15:14:11 +00:00
|
|
|
{.raises: [CatchableError, Defect].} =
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
# Load data in eth2-networks format
|
2022-03-11 15:03:47 +00:00
|
|
|
# https://github.com/eth-clients/eth2-networks
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
|
2020-07-09 22:08:54 +00:00
|
|
|
try:
|
|
|
|
let
|
2021-02-02 22:31:01 +00:00
|
|
|
genesisPath = path & "/genesis.ssz"
|
|
|
|
genesisDepositsSnapshotPath = path & "/genesis_deposit_contract_snapshot.ssz"
|
|
|
|
configPath = path & "/config.yaml"
|
2022-05-20 15:26:07 +00:00
|
|
|
deployBlockPath = path & "/deploy_block.txt"
|
2021-02-02 22:31:01 +00:00
|
|
|
depositContractBlockPath = path & "/deposit_contract_block.txt"
|
2022-12-19 17:19:48 +00:00
|
|
|
depositContractBlockHashPath = path & "/deposit_contract_block_hash.txt"
|
2021-02-02 22:31:01 +00:00
|
|
|
bootstrapNodesPath = path & "/bootstrap_nodes.txt"
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
bootEnrPath = path & "/boot_enr.yaml"
|
|
|
|
runtimeConfig = if fileExists(configPath):
|
|
|
|
let (cfg, unknowns) = readRuntimeConfig(configPath)
|
|
|
|
if unknowns.len > 0:
|
|
|
|
when nimvm:
|
|
|
|
# TODO better printing
|
|
|
|
echo "Unknown constants in file: " & unknowns
|
|
|
|
else:
|
|
|
|
warn "Unknown constants in config file", unknowns
|
|
|
|
cfg
|
2020-07-10 14:31:24 +00:00
|
|
|
else:
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
defaultRuntimeConfig
|
2020-07-10 14:31:24 +00:00
|
|
|
|
2022-12-19 17:19:48 +00:00
|
|
|
depositContractBlockStr = if fileExists(depositContractBlockPath):
|
2020-07-28 13:36:11 +00:00
|
|
|
readFile(depositContractBlockPath).strip
|
2020-07-10 14:31:24 +00:00
|
|
|
else:
|
2020-07-28 13:36:11 +00:00
|
|
|
""
|
2022-05-20 15:26:07 +00:00
|
|
|
|
2022-12-19 17:19:48 +00:00
|
|
|
depositContractBlockHashStr = if fileExists(depositContractBlockHashPath):
|
|
|
|
readFile(depositContractBlockHashPath).strip
|
|
|
|
else:
|
|
|
|
""
|
|
|
|
|
|
|
|
deployBlockStr = if fileExists(deployBlockPath):
|
2022-05-20 15:26:07 +00:00
|
|
|
readFile(deployBlockPath).strip
|
|
|
|
else:
|
|
|
|
""
|
|
|
|
|
2022-12-19 17:19:48 +00:00
|
|
|
depositContractBlock = if depositContractBlockStr.len > 0:
|
|
|
|
parseBiggestUInt depositContractBlockStr
|
|
|
|
elif deployBlockStr.len > 0:
|
|
|
|
parseBiggestUInt deployBlockStr
|
|
|
|
elif not runtimeConfig.DEPOSIT_CONTRACT_ADDRESS.isDefaultValue:
|
|
|
|
raise newException(ValueError,
|
|
|
|
"A network with deposit contract should specify the " &
|
|
|
|
"deposit contract deployment block in a file named " &
|
|
|
|
"deposit_contract_block.txt or deploy_block.txt")
|
2020-11-12 19:01:26 +00:00
|
|
|
else:
|
2022-12-19 17:19:48 +00:00
|
|
|
1'u64
|
|
|
|
|
|
|
|
depositContractBlockHash = if depositContractBlockHashStr.len > 0:
|
|
|
|
Eth2Digest.strictParse(depositContractBlockHashStr)
|
2023-01-13 10:21:58 +00:00
|
|
|
elif not runtimeConfig.DEPOSIT_CONTRACT_ADDRESS.isDefaultValue:
|
2022-12-19 17:19:48 +00:00
|
|
|
raise newException(ValueError,
|
|
|
|
"A network with deposit contract should specify the " &
|
|
|
|
"deposit contract deployment block hash in a file " &
|
|
|
|
"name deposit_contract_block_hash.txt")
|
|
|
|
else:
|
|
|
|
default(Eth2Digest)
|
2020-11-12 19:01:26 +00:00
|
|
|
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
bootstrapNodes = deduplicate(
|
|
|
|
readBootstrapNodes(bootstrapNodesPath) &
|
|
|
|
readBootEnr(bootEnrPath))
|
2020-07-28 10:46:22 +00:00
|
|
|
|
2020-11-24 21:21:47 +00:00
|
|
|
genesisData = if fileExists(genesisPath):
|
|
|
|
readFile(genesisPath)
|
|
|
|
else:
|
|
|
|
""
|
|
|
|
|
|
|
|
genesisDepositsSnapshot = if fileExists(genesisDepositsSnapshotPath):
|
|
|
|
readFile(genesisDepositsSnapshotPath)
|
|
|
|
else:
|
|
|
|
""
|
2020-07-09 22:08:54 +00:00
|
|
|
|
|
|
|
Eth2NetworkMetadata(
|
|
|
|
incompatible: false,
|
2022-02-25 08:22:44 +00:00
|
|
|
eth1Network: eth1Network,
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg: runtimeConfig,
|
2020-07-28 10:46:22 +00:00
|
|
|
bootstrapNodes: bootstrapNodes,
|
2022-12-19 17:19:48 +00:00
|
|
|
depositContractBlock: depositContractBlock,
|
|
|
|
depositContractBlockHash: depositContractBlockHash,
|
2020-11-24 21:21:47 +00:00
|
|
|
genesisData: genesisData,
|
2022-07-29 08:45:39 +00:00
|
|
|
genesisDepositsSnapshot: genesisDepositsSnapshot)
|
2020-07-10 14:31:24 +00:00
|
|
|
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
except PresetIncompatibleError as err:
|
2020-07-09 22:08:54 +00:00
|
|
|
Eth2NetworkMetadata(incompatible: true,
|
|
|
|
incompatibilityDesc: err.msg)
|
2020-07-02 15:14:11 +00:00
|
|
|
|
2022-02-25 08:22:44 +00:00
|
|
|
proc loadCompileTimeNetworkMetadata(
|
|
|
|
path: string,
|
|
|
|
eth1Network = none(Eth1Network)): Eth2NetworkMetadata {.raises: [Defect].} =
|
2023-04-27 10:36:22 +00:00
|
|
|
if fileExists(path & "/config.yaml"):
|
2023-04-03 15:39:12 +00:00
|
|
|
try:
|
|
|
|
result = loadEth2NetworkMetadata(path, eth1Network)
|
|
|
|
if result.incompatible:
|
|
|
|
macros.error "The current build is misconfigured. " &
|
|
|
|
"Attempt to load an incompatible network metadata: " &
|
|
|
|
result.incompatibilityDesc
|
|
|
|
except CatchableError as err:
|
|
|
|
macros.error "Failed to load network metadata at '" & path & "': " & err.msg
|
|
|
|
else:
|
|
|
|
macros.error "config.yaml not found for network '" & path
|
2022-02-25 08:22:44 +00:00
|
|
|
|
|
|
|
template eth2Network(path: string, eth1Network: Eth1Network): Eth2NetworkMetadata =
|
|
|
|
loadCompileTimeNetworkMetadata(eth2NetworksDir & "/" & path,
|
|
|
|
some eth1Network)
|
|
|
|
|
2023-01-12 17:58:42 +00:00
|
|
|
when const_preset == "gnosis":
|
2022-09-19 09:25:41 +00:00
|
|
|
const
|
|
|
|
gnosisMetadata* = loadCompileTimeNetworkMetadata(
|
|
|
|
currentSourcePath.parentDir.replace('\\', '/') &
|
2023-01-12 17:58:42 +00:00
|
|
|
"/../../vendor/gnosis-chain-configs/mainnet")
|
2022-09-19 09:25:41 +00:00
|
|
|
static:
|
2023-01-05 12:48:51 +00:00
|
|
|
checkForkConsistency(gnosisMetadata.cfg)
|
|
|
|
doAssert gnosisMetadata.cfg.CAPELLA_FORK_EPOCH == FAR_FUTURE_EPOCH
|
2023-02-15 14:44:09 +00:00
|
|
|
doAssert gnosisMetadata.cfg.DENEB_FORK_EPOCH == FAR_FUTURE_EPOCH
|
2022-09-19 09:25:41 +00:00
|
|
|
|
|
|
|
elif const_preset == "mainnet":
|
|
|
|
const
|
|
|
|
mainnetMetadata* = eth2Network("shared/mainnet", mainnet)
|
|
|
|
praterMetadata* = eth2Network("shared/prater", goerli)
|
2023-03-29 08:37:14 +00:00
|
|
|
sepoliaMetadata* =
|
|
|
|
loadCompileTimeNetworkMetadata(sepoliaDir & "/bepolia", some sepolia)
|
2022-09-19 09:25:41 +00:00
|
|
|
static:
|
2023-02-15 14:44:09 +00:00
|
|
|
for network in [mainnetMetadata, praterMetadata, sepoliaMetadata]:
|
2022-09-19 09:25:41 +00:00
|
|
|
checkForkConsistency(network.cfg)
|
2023-02-15 14:44:09 +00:00
|
|
|
|
2023-03-29 08:37:14 +00:00
|
|
|
for network in [mainnetMetadata, praterMetadata, sepoliaMetaData]:
|
2023-04-03 15:39:12 +00:00
|
|
|
doAssert network.cfg.ALTAIR_FORK_EPOCH < FAR_FUTURE_EPOCH
|
|
|
|
doAssert network.cfg.BELLATRIX_FORK_EPOCH < FAR_FUTURE_EPOCH
|
|
|
|
doAssert network.cfg.CAPELLA_FORK_EPOCH < FAR_FUTURE_EPOCH
|
2023-02-15 14:44:09 +00:00
|
|
|
doAssert network.cfg.DENEB_FORK_EPOCH == FAR_FUTURE_EPOCH
|
2022-09-19 09:25:41 +00:00
|
|
|
|
|
|
|
proc getMetadataForNetwork*(
|
|
|
|
networkName: string): Eth2NetworkMetadata {.raises: [Defect, IOError].} =
|
|
|
|
template loadRuntimeMetadata(): auto =
|
|
|
|
if fileExists(networkName / "config.yaml"):
|
|
|
|
try:
|
|
|
|
loadEth2NetworkMetadata(networkName)
|
|
|
|
except CatchableError as exc:
|
|
|
|
fatal "Cannot load network", msg = exc.msg, networkName
|
2022-02-25 08:22:44 +00:00
|
|
|
quit 1
|
2022-09-19 09:25:41 +00:00
|
|
|
else:
|
|
|
|
fatal "config.yaml not found for network", networkName
|
|
|
|
quit 1
|
2022-02-25 08:22:44 +00:00
|
|
|
|
2022-12-05 09:15:00 +00:00
|
|
|
if networkName == "ropsten":
|
|
|
|
warn "Ropsten is unsupported; https://blog.ethereum.org/2022/11/30/ropsten-shutdown-announcement suggests migrating to Goerli or Sepolia"
|
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
let metadata =
|
2023-01-12 17:58:42 +00:00
|
|
|
when const_preset == "gnosis":
|
2022-09-19 09:25:41 +00:00
|
|
|
case toLowerAscii(networkName)
|
|
|
|
of "gnosis":
|
|
|
|
gnosisMetadata
|
|
|
|
of "gnosis-chain":
|
|
|
|
warn "`--network:gnosis-chain` is deprecated, " &
|
|
|
|
"use `--network:gnosis` instead"
|
|
|
|
gnosisMetadata
|
2022-02-25 08:22:44 +00:00
|
|
|
else:
|
|
|
|
loadRuntimeMetadata()
|
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
elif const_preset == "mainnet":
|
|
|
|
case toLowerAscii(networkName)
|
|
|
|
of "mainnet":
|
|
|
|
mainnetMetadata
|
|
|
|
of "prater", "goerli":
|
|
|
|
praterMetadata
|
|
|
|
of "sepolia":
|
|
|
|
sepoliaMetadata
|
|
|
|
else:
|
|
|
|
loadRuntimeMetadata()
|
2022-02-25 08:22:44 +00:00
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
else:
|
|
|
|
loadRuntimeMetadata()
|
2022-06-04 19:15:15 +00:00
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
if metadata.incompatible:
|
|
|
|
fatal "The selected network is not compatible with the current build",
|
|
|
|
reason = metadata.incompatibilityDesc
|
|
|
|
quit 1
|
2022-02-25 08:22:44 +00:00
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
metadata
|
2022-04-08 20:11:37 +00:00
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
proc getRuntimeConfig*(
|
|
|
|
eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} =
|
2022-11-08 22:53:02 +00:00
|
|
|
## Returns the run-time config for a network specified on the command line
|
|
|
|
## If the network is not explicitly specified, the function will act as the
|
|
|
|
## regular Nimbus binary, returning the mainnet config.
|
|
|
|
##
|
|
|
|
## TODO the assumption that the input variable is a CLI config option is not
|
|
|
|
## quite appropriate in such as low-level function. The "assume mainnet by
|
|
|
|
## default" behavior is something that should be handled closer to the `conf`
|
|
|
|
## layer.
|
2022-09-19 09:25:41 +00:00
|
|
|
if eth2Network.isSome:
|
|
|
|
return getMetadataForNetwork(eth2Network.get).cfg
|
2022-11-08 22:53:02 +00:00
|
|
|
|
|
|
|
when const_preset == "mainnet":
|
2023-01-12 17:58:42 +00:00
|
|
|
mainnetMetadata.cfg
|
|
|
|
elif const_preset == "gnosis":
|
|
|
|
gnosisMetadata.cfg
|
2022-11-08 22:53:02 +00:00
|
|
|
else:
|
|
|
|
# This is a non-standard build (i.e. minimal), and the function was most
|
|
|
|
# likely executed in a test. The best we can do is return a fully default
|
|
|
|
# config:
|
|
|
|
defaultRuntimeConfig
|