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,
|
2023-05-11 11:11:00 +00:00
|
|
|
../spec/eth2_ssz_serialization
|
2020-07-02 15:14:11 +00:00
|
|
|
|
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
|
|
|
|
2023-05-19 01:08:02 +00:00
|
|
|
const
|
|
|
|
vendorDir = currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor"
|
|
|
|
|
2023-05-24 20:43:41 +00:00
|
|
|
incbinEnabled* = sizeof(pointer) == 8
|
2023-05-19 01:08:02 +00:00
|
|
|
|
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:
|
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
|
|
|
|
|
|
|
# `genesisData` will have `len == 0` for networks with a still
|
|
|
|
# unknown genesis state.
|
2023-05-19 01:08:02 +00:00
|
|
|
when incbinEnabled:
|
|
|
|
genesisData*: seq[byte]
|
|
|
|
else:
|
|
|
|
genesisData*: string
|
|
|
|
|
|
|
|
genesisDepositsSnapshot*: string
|
2020-07-09 22:08:54 +00:00
|
|
|
else:
|
|
|
|
incompatibilityDesc*: string
|
2020-07-02 15:14:11 +00:00
|
|
|
|
2023-05-19 01:08:02 +00:00
|
|
|
template genesisBytes*(metadata: Eth2NetworkMetadata): auto =
|
|
|
|
when incbinEnabled:
|
|
|
|
metadata.genesisData
|
|
|
|
else:
|
|
|
|
metadata.genesisData.toOpenArrayByte(0, metadata.genesisData.high)
|
|
|
|
|
2023-05-11 11:11:00 +00:00
|
|
|
proc readBootstrapNodes*(path: string): seq[string] {.raises: [IOError].} =
|
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
|
|
|
# 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:
|
|
|
|
@[]
|
|
|
|
|
2023-05-11 11:11:00 +00:00
|
|
|
proc readBootEnr*(path: string): seq[string] {.raises: [IOError].} =
|
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
|
|
|
# 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
|
|
|
|
2023-05-11 11:11:00 +00:00
|
|
|
proc loadEth2NetworkMetadata*(
|
|
|
|
path: string, eth1Network = none(Eth1Network), loadGenesis = true):
|
|
|
|
Eth2NetworkMetadata {.raises: [CatchableError].} =
|
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
|
|
|
|
2023-05-11 11:11:00 +00:00
|
|
|
genesisData = if loadGenesis and fileExists(genesisPath):
|
2023-05-24 20:43:41 +00:00
|
|
|
readFile(genesisPath)
|
2020-11-24 21:21:47 +00:00
|
|
|
else:
|
2023-05-19 01:08:02 +00:00
|
|
|
""
|
2020-11-24 21:21:47 +00:00
|
|
|
|
|
|
|
genesisDepositsSnapshot = if fileExists(genesisDepositsSnapshotPath):
|
2023-05-19 01:08:02 +00:00
|
|
|
readFile(genesisDepositsSnapshotPath)
|
2020-11-24 21:21:47 +00:00
|
|
|
else:
|
2023-05-19 01:08:02 +00:00
|
|
|
""
|
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,
|
2023-05-24 20:43:41 +00:00
|
|
|
genesisData:
|
|
|
|
when incbinEnabled: toBytes genesisData
|
|
|
|
else: 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,
|
2023-05-11 11:11:00 +00:00
|
|
|
eth1Network = none(Eth1Network),
|
|
|
|
loadGenesis = true): Eth2NetworkMetadata {.raises: [].} =
|
2023-04-27 10:36:22 +00:00
|
|
|
if fileExists(path & "/config.yaml"):
|
2023-04-03 15:39:12 +00:00
|
|
|
try:
|
2023-05-11 11:11:00 +00:00
|
|
|
result = loadEth2NetworkMetadata(path, eth1Network, loadGenesis)
|
2023-04-03 15:39:12 +00:00
|
|
|
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
|
|
|
|
2023-01-12 17:58:42 +00:00
|
|
|
when const_preset == "gnosis":
|
2023-05-11 11:11:00 +00:00
|
|
|
import stew/assign2
|
|
|
|
|
2023-05-19 01:08:02 +00:00
|
|
|
when incbinEnabled:
|
|
|
|
let
|
|
|
|
gnosisGenesis {.importc: "gnosis_mainnet_genesis".}: ptr UncheckedArray[byte]
|
|
|
|
gnosisGenesisSize {.importc: "gnosis_mainnet_genesis_size".}: int
|
2023-06-04 14:33:43 +00:00
|
|
|
|
2023-07-26 12:54:16 +00:00
|
|
|
chiadoGenesis {.importc: "gnosis_chiado_genesis".}: ptr UncheckedArray[byte]
|
|
|
|
chiadoGenesisSize {.importc: "gnosis_chiado_genesis_size".}: int
|
|
|
|
|
2023-06-04 14:33:43 +00:00
|
|
|
# let `.incbin` in assembly file find the binary file through search path
|
|
|
|
{.passc: "-I" & vendorDir.}
|
2023-05-19 01:08:02 +00:00
|
|
|
{.compile: "network_metadata_gnosis.S".}
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
const
|
2023-05-11 11:11:00 +00:00
|
|
|
gnosisMetadata = loadCompileTimeNetworkMetadata(
|
2023-05-19 01:08:02 +00:00
|
|
|
vendorDir & "/gnosis-chain-configs/mainnet",
|
|
|
|
none(Eth1Network), not incbinEnabled)
|
2023-07-26 12:54:16 +00:00
|
|
|
chiadoMetadata = loadCompileTimeNetworkMetadata(
|
|
|
|
vendorDir & "/gnosis-chain-configs/chiado",
|
|
|
|
none(Eth1Network), not incbinEnabled)
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
static:
|
2023-07-26 12:54:16 +00:00
|
|
|
for network in [gnosisMetadata, chiadoMetadata]:
|
|
|
|
checkForkConsistency(network.cfg)
|
|
|
|
|
|
|
|
for network in [gnosisMetadata, chiadoMetadata]:
|
|
|
|
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
|
|
|
|
doAssert network.cfg.DENEB_FORK_EPOCH == FAR_FUTURE_EPOCH
|
2022-09-19 09:25:41 +00:00
|
|
|
|
|
|
|
elif const_preset == "mainnet":
|
2023-05-11 11:11:00 +00:00
|
|
|
import stew/assign2
|
|
|
|
|
2023-05-19 01:08:02 +00:00
|
|
|
when incbinEnabled:
|
|
|
|
# Nim is very inefficent at loading large constants from binary files so we
|
|
|
|
# use this trick instead which saves significant amounts of compile time
|
|
|
|
let
|
|
|
|
mainnetGenesis {.importc: "eth2_mainnet_genesis".}: ptr UncheckedArray[byte]
|
|
|
|
mainnetGenesisSize {.importc: "eth2_mainnet_genesis_size".}: int
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2023-05-19 01:08:02 +00:00
|
|
|
praterGenesis {.importc: "eth2_goerli_genesis".}: ptr UncheckedArray[byte]
|
|
|
|
praterGenesisSize {.importc: "eth2_goerli_genesis_size".}: int
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2023-05-19 01:08:02 +00:00
|
|
|
sepoliaGenesis {.importc: "eth2_sepolia_genesis".}: ptr UncheckedArray[byte]
|
|
|
|
sepoliaGenesisSize {.importc: "eth2_sepolia_genesis_size".}: int
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2023-06-04 14:33:43 +00:00
|
|
|
# let `.incbin` in assembly file find the binary file through search path
|
|
|
|
{.passc: "-I" & vendorDir.}
|
2023-05-19 01:08:02 +00:00
|
|
|
{.compile: "network_metadata_mainnet.S".}
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
const
|
2023-05-11 11:11:00 +00:00
|
|
|
mainnetMetadata = loadCompileTimeNetworkMetadata(
|
2023-05-19 01:08:02 +00:00
|
|
|
vendorDir & "/eth2-networks/shared/mainnet", some mainnet, not incbinEnabled)
|
2023-05-11 11:11:00 +00:00
|
|
|
praterMetadata = loadCompileTimeNetworkMetadata(
|
2023-05-19 01:08:02 +00:00
|
|
|
vendorDir & "/eth2-networks/shared/prater", some goerli, not incbinEnabled)
|
2023-05-11 11:11:00 +00:00
|
|
|
sepoliaMetadata = loadCompileTimeNetworkMetadata(
|
2023-05-19 01:08:02 +00:00
|
|
|
vendorDir & "/sepolia/bepolia", some sepolia, not incbinEnabled)
|
2023-05-11 11:11:00 +00:00
|
|
|
|
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-05-10 10:20:55 +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*(
|
2023-05-11 11:11:00 +00:00
|
|
|
networkName: string): Eth2NetworkMetadata {.raises: [IOError].} =
|
2022-09-19 09:25:41 +00:00
|
|
|
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"
|
|
|
|
|
2023-05-11 11:11:00 +00:00
|
|
|
template withGenesis(metadata, genesis: untyped): untyped =
|
2023-05-19 01:08:02 +00:00
|
|
|
when incbinEnabled:
|
|
|
|
var tmp = metadata
|
2023-06-16 12:15:42 +00:00
|
|
|
case tmp.incompatible
|
|
|
|
of false:
|
|
|
|
assign(tmp.genesisData, genesis.toOpenArray(0, `genesis Size` - 1))
|
|
|
|
of true:
|
|
|
|
raiseAssert "Unreachable" # `loadCompileTimeNetworkMetadata`
|
2023-05-19 01:08:02 +00:00
|
|
|
tmp
|
|
|
|
else:
|
|
|
|
metadata
|
2023-05-11 11:11:00 +00:00
|
|
|
|
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":
|
2023-05-11 11:11:00 +00:00
|
|
|
withGenesis(gnosisMetadata, gnosisGenesis)
|
2022-09-19 09:25:41 +00:00
|
|
|
of "gnosis-chain":
|
|
|
|
warn "`--network:gnosis-chain` is deprecated, " &
|
|
|
|
"use `--network:gnosis` instead"
|
2023-05-11 11:11:00 +00:00
|
|
|
withGenesis(gnosisMetadata, gnosisGenesis)
|
2023-07-26 12:54:16 +00:00
|
|
|
of "chiado":
|
|
|
|
withGenesis(chiadoMetadata, chiadoGenesis)
|
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":
|
2023-05-11 11:11:00 +00:00
|
|
|
withGenesis(mainnetMetadata, mainnetGenesis)
|
2022-09-19 09:25:41 +00:00
|
|
|
of "prater", "goerli":
|
2023-05-11 11:11:00 +00:00
|
|
|
withGenesis(praterMetadata, praterGenesis)
|
2022-09-19 09:25:41 +00:00
|
|
|
of "sepolia":
|
2023-05-11 11:11:00 +00:00
|
|
|
withGenesis(sepoliaMetadata, sepoliaGenesis)
|
2022-09-19 09:25:41 +00:00
|
|
|
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*(
|
2023-05-11 11:11:00 +00:00
|
|
|
eth2Network: Option[string]): RuntimeConfig {.raises: [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.
|
2023-06-16 12:15:42 +00:00
|
|
|
let metadata =
|
|
|
|
if eth2Network.isSome:
|
|
|
|
getMetadataForNetwork(eth2Network.get)
|
|
|
|
else:
|
|
|
|
when const_preset == "mainnet":
|
|
|
|
mainnetMetadata
|
|
|
|
elif const_preset == "gnosis":
|
|
|
|
gnosisMetadata
|
|
|
|
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:
|
|
|
|
return defaultRuntimeConfig
|
2022-11-08 22:53:02 +00:00
|
|
|
|
2023-06-16 12:15:42 +00:00
|
|
|
return
|
|
|
|
case metadata.incompatible
|
|
|
|
of false:
|
|
|
|
metadata.cfg
|
|
|
|
of true:
|
|
|
|
# `getMetadataForNetwork` / `loadCompileTimeNetworkMetadata`
|
|
|
|
raiseAssert "Unreachable"
|