2021-03-26 06:52:01 +00:00
|
|
|
# beacon_chain
|
2024-01-02 15:15:44 +00:00
|
|
|
# Copyright (c) 2018-2024 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
|
2024-03-26 21:47:42 +00:00
|
|
|
std/os,
|
2022-12-19 17:19:48 +00:00
|
|
|
stew/[byteutils, objects], stew/shims/macros, nimcrypto/hash,
|
2023-12-12 15:15:00 +00:00
|
|
|
web3/[conversions],
|
|
|
|
web3/primitives as web3types,
|
2020-09-01 09:01:57 +00:00
|
|
|
chronicles,
|
2021-03-26 14:11:06 +00:00
|
|
|
eth/common/eth_types_json_serialization,
|
2023-09-08 05:53:27 +00:00
|
|
|
../spec/[eth2_ssz_serialization, forks]
|
2020-07-02 15:14:11 +00:00
|
|
|
|
2024-03-26 21:47:42 +00:00
|
|
|
from std/sequtils import deduplicate, filterIt, mapIt
|
|
|
|
from std/strutils import
|
|
|
|
escape, parseBiggestUInt, replace, splitLines, startsWith, strip,
|
|
|
|
toLowerAscii
|
|
|
|
|
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
|
2023-12-12 15:15:00 +00:00
|
|
|
web3types, 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
|
2024-10-08 01:54:02 +00:00
|
|
|
Eth1BlockHash* = web3types.Hash32
|
2020-07-02 15:14:11 +00:00
|
|
|
|
|
|
|
Eth1Network* = enum
|
|
|
|
mainnet
|
2022-06-16 14:11:26 +00:00
|
|
|
sepolia
|
2023-09-08 05:53:27 +00:00
|
|
|
holesky
|
|
|
|
|
|
|
|
GenesisMetadataKind* = enum
|
|
|
|
NoGenesis
|
|
|
|
UserSuppliedFile
|
|
|
|
BakedIn
|
|
|
|
BakedInUrl
|
|
|
|
|
|
|
|
DownloadInfo* = object
|
|
|
|
url: string
|
|
|
|
digest: Eth2Digest
|
|
|
|
|
|
|
|
GenesisMetadata* = object
|
|
|
|
case kind*: GenesisMetadataKind
|
|
|
|
of NoGenesis:
|
|
|
|
discard
|
|
|
|
of UserSuppliedFile:
|
|
|
|
path*: string
|
|
|
|
of BakedIn:
|
|
|
|
networkName*: string
|
|
|
|
of BakedInUrl:
|
|
|
|
url*: string
|
|
|
|
digest*: Eth2Digest
|
2020-07-02 15:14:11 +00:00
|
|
|
|
|
|
|
Eth2NetworkMetadata* = object
|
2023-09-22 21:45:24 +00:00
|
|
|
# If the eth1Network is specified, the ELManager will perform some
|
|
|
|
# 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.
|
2024-06-12 01:46:39 +00:00
|
|
|
eth1Network*: Opt[Eth1Network]
|
2023-09-22 21:45:24 +00:00
|
|
|
cfg*: RuntimeConfig
|
|
|
|
|
|
|
|
# Parsing `enr.Records` is still not possible at compile-time
|
|
|
|
bootstrapNodes*: seq[string]
|
|
|
|
|
|
|
|
depositContractBlock*: uint64
|
|
|
|
depositContractBlockHash*: Eth2Digest
|
|
|
|
|
|
|
|
genesis*: GenesisMetadata
|
2020-07-02 15:14:11 +00:00
|
|
|
|
2023-09-08 05:53:27 +00:00
|
|
|
func hasGenesis*(metadata: Eth2NetworkMetadata): bool =
|
|
|
|
metadata.genesis.kind != NoGenesis
|
2023-05-19 01:08:02 +00:00
|
|
|
|
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*(
|
2023-09-08 05:53:27 +00:00
|
|
|
path: string,
|
2024-06-12 01:46:39 +00:00
|
|
|
eth1Network = Opt.none(Eth1Network),
|
2023-09-08 05:53:27 +00:00
|
|
|
isCompileTime = false,
|
2024-06-12 01:46:39 +00:00
|
|
|
downloadGenesisFrom = Opt.none(DownloadInfo),
|
|
|
|
useBakedInGenesis = Opt.none(string)
|
2023-09-22 21:45:24 +00:00
|
|
|
): Result[Eth2NetworkMetadata, string] {.raises: [IOError, PresetFileError].} =
|
2024-05-30 09:28:16 +00:00
|
|
|
# Load data in mainnet format
|
|
|
|
# https://github.com/eth-clients/mainnet
|
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"
|
|
|
|
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-09-22 21:45:24 +00:00
|
|
|
ok Eth2NetworkMetadata(
|
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-09-08 05:53:27 +00:00
|
|
|
genesis:
|
|
|
|
if downloadGenesisFrom.isSome:
|
|
|
|
GenesisMetadata(kind: BakedInUrl,
|
|
|
|
url: downloadGenesisFrom.get.url,
|
|
|
|
digest: downloadGenesisFrom.get.digest)
|
|
|
|
elif useBakedInGenesis.isSome:
|
|
|
|
GenesisMetadata(kind: BakedIn, networkName: useBakedInGenesis.get)
|
|
|
|
elif fileExists(genesisPath) and not isCompileTime:
|
|
|
|
GenesisMetadata(kind: UserSuppliedFile, path: genesisPath)
|
|
|
|
else:
|
2024-03-08 13:22:03 +00:00
|
|
|
GenesisMetadata(kind: NoGenesis))
|
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:
|
2023-09-22 21:45:24 +00:00
|
|
|
err err.msg
|
|
|
|
|
|
|
|
except ValueError as err:
|
|
|
|
raise (ref PresetFileError)(msg: err.msg)
|
2020-07-02 15:14:11 +00:00
|
|
|
|
2022-02-25 08:22:44 +00:00
|
|
|
proc loadCompileTimeNetworkMetadata(
|
|
|
|
path: string,
|
2024-06-12 01:46:39 +00:00
|
|
|
eth1Network = Opt.none(Eth1Network),
|
|
|
|
useBakedInGenesis = Opt.none(string),
|
|
|
|
downloadGenesisFrom = Opt.none(DownloadInfo)): Eth2NetworkMetadata =
|
2023-04-27 10:36:22 +00:00
|
|
|
if fileExists(path & "/config.yaml"):
|
2023-04-03 15:39:12 +00:00
|
|
|
try:
|
2023-09-22 21:45:24 +00:00
|
|
|
let res = loadEth2NetworkMetadata(
|
|
|
|
path, eth1Network, isCompileTime = true,
|
|
|
|
downloadGenesisFrom = downloadGenesisFrom,
|
|
|
|
useBakedInGenesis = useBakedInGenesis)
|
|
|
|
if res.isErr:
|
2023-04-03 15:39:12 +00:00
|
|
|
macros.error "The current build is misconfigured. " &
|
|
|
|
"Attempt to load an incompatible network metadata: " &
|
2023-09-22 21:45:24 +00:00
|
|
|
res.error
|
|
|
|
return res.get
|
|
|
|
except IOError as err:
|
|
|
|
macros.error "Failed to load network metadata at '" & path & "': " &
|
|
|
|
"IOError - " & err.msg
|
|
|
|
except PresetFileError as err:
|
|
|
|
macros.error "Failed to load network metadata at '" & path & "': " &
|
|
|
|
"PresetFileError - " & err.msg
|
2023-04-03 15:39:12 +00:00
|
|
|
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-19 01:08:02 +00:00
|
|
|
when incbinEnabled:
|
|
|
|
let
|
2023-09-08 05:53:27 +00:00
|
|
|
gnosisGenesis* {.importc: "gnosis_mainnet_genesis".}: ptr UncheckedArray[byte]
|
|
|
|
gnosisGenesisSize* {.importc: "gnosis_mainnet_genesis_size".}: int
|
2023-06-04 14:33:43 +00:00
|
|
|
|
2023-09-08 05:53:27 +00:00
|
|
|
chiadoGenesis* {.importc: "gnosis_chiado_genesis".}: ptr UncheckedArray[byte]
|
|
|
|
chiadoGenesisSize* {.importc: "gnosis_chiado_genesis_size".}: int
|
2023-07-26 12:54:16 +00:00
|
|
|
|
2023-06-04 14:33:43 +00:00
|
|
|
# let `.incbin` in assembly file find the binary file through search path
|
2024-03-26 21:47:42 +00:00
|
|
|
{.passc: "-I" & escape(vendorDir).}
|
2023-05-19 01:08:02 +00:00
|
|
|
{.compile: "network_metadata_gnosis.S".}
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2023-09-08 05:53:27 +00:00
|
|
|
else:
|
|
|
|
const
|
|
|
|
gnosisGenesis* = slurp(
|
|
|
|
vendorDir & "/gnosis-chain-configs/mainnet/genesis.ssz")
|
|
|
|
|
|
|
|
chiadoGenesis* = slurp(
|
|
|
|
vendorDir & "/gnosis-chain-configs/chiado/genesis.ssz")
|
|
|
|
|
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",
|
2024-06-12 01:46:39 +00:00
|
|
|
Opt.none(Eth1Network),
|
|
|
|
useBakedInGenesis = Opt.some "gnosis")
|
2023-09-08 05:53:27 +00:00
|
|
|
|
2023-07-26 12:54:16 +00:00
|
|
|
chiadoMetadata = loadCompileTimeNetworkMetadata(
|
|
|
|
vendorDir & "/gnosis-chain-configs/chiado",
|
2024-06-12 01:46:39 +00:00
|
|
|
Opt.none(Eth1Network),
|
|
|
|
useBakedInGenesis = Opt.some "chiado")
|
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]:
|
2024-01-12 10:31:07 +00:00
|
|
|
doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH
|
2024-02-26 06:49:12 +00:00
|
|
|
doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
|
2024-09-12 09:11:08 +00:00
|
|
|
doAssert ConsensusFork.high == ConsensusFork.Electra
|
2022-09-19 09:25:41 +00:00
|
|
|
|
|
|
|
elif const_preset == "mainnet":
|
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
|
2023-10-04 08:19:05 +00:00
|
|
|
{.push hint[GlobalVar]:off.}
|
2023-05-19 01:08:02 +00:00
|
|
|
let
|
2023-09-08 05:53:27 +00:00
|
|
|
mainnetGenesis* {.importc: "eth2_mainnet_genesis".}: ptr UncheckedArray[byte]
|
|
|
|
mainnetGenesisSize* {.importc: "eth2_mainnet_genesis_size".}: int
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2023-09-08 05:53:27 +00:00
|
|
|
sepoliaGenesis* {.importc: "eth2_sepolia_genesis".}: ptr UncheckedArray[byte]
|
|
|
|
sepoliaGenesisSize* {.importc: "eth2_sepolia_genesis_size".}: int
|
2023-10-04 08:19:05 +00:00
|
|
|
{.pop.}
|
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
|
2024-03-26 21:47:42 +00:00
|
|
|
{.passc: "-I" & escape(vendorDir).}
|
2023-05-19 01:08:02 +00:00
|
|
|
{.compile: "network_metadata_mainnet.S".}
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2023-09-08 05:53:27 +00:00
|
|
|
else:
|
|
|
|
const
|
|
|
|
mainnetGenesis* = slurp(
|
2024-05-30 09:28:16 +00:00
|
|
|
vendorDir & "/mainnet/metadata/genesis.ssz")
|
2023-09-08 05:53:27 +00:00
|
|
|
|
|
|
|
sepoliaGenesis* = slurp(
|
2024-07-11 05:13:37 +00:00
|
|
|
vendorDir & "/sepolia/metadata/genesis.ssz")
|
2023-09-08 05:53:27 +00:00
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
const
|
2023-05-11 11:11:00 +00:00
|
|
|
mainnetMetadata = loadCompileTimeNetworkMetadata(
|
2024-05-30 09:28:16 +00:00
|
|
|
vendorDir & "/mainnet/metadata",
|
2024-06-12 01:46:39 +00:00
|
|
|
Opt.some mainnet,
|
|
|
|
useBakedInGenesis = Opt.some "mainnet")
|
2023-09-08 05:53:27 +00:00
|
|
|
|
|
|
|
holeskyMetadata = loadCompileTimeNetworkMetadata(
|
2024-06-21 21:51:25 +00:00
|
|
|
vendorDir & "/holesky/metadata",
|
2024-06-12 01:46:39 +00:00
|
|
|
Opt.some holesky,
|
|
|
|
downloadGenesisFrom = Opt.some DownloadInfo(
|
2023-09-25 20:24:13 +00:00
|
|
|
url: "https://github.com/status-im/nimbus-eth2/releases/download/v23.9.1/holesky-genesis.ssz.sz",
|
|
|
|
digest: Eth2Digest.fromHex "0x0ea3f6f9515823b59c863454675fefcd1d8b4f2dbe454db166206a41fda060a0"))
|
2023-09-08 05:53:27 +00:00
|
|
|
|
2023-05-11 11:11:00 +00:00
|
|
|
sepoliaMetadata = loadCompileTimeNetworkMetadata(
|
2024-07-11 05:13:37 +00:00
|
|
|
vendorDir & "/sepolia/metadata",
|
2024-06-12 01:46:39 +00:00
|
|
|
Opt.some sepolia,
|
|
|
|
useBakedInGenesis = Opt.some "sepolia")
|
2023-05-11 11:11:00 +00:00
|
|
|
|
2022-09-19 09:25:41 +00:00
|
|
|
static:
|
2024-04-03 23:25:36 +00:00
|
|
|
for network in [mainnetMetadata, sepoliaMetadata, holeskyMetadata]:
|
2022-09-19 09:25:41 +00:00
|
|
|
checkForkConsistency(network.cfg)
|
2023-02-15 14:44:09 +00:00
|
|
|
|
2024-04-03 23:25:36 +00:00
|
|
|
for network in [mainnetMetadata, sepoliaMetadata, holeskyMetadata]:
|
2024-01-02 21:39:55 +00:00
|
|
|
doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH
|
2024-02-26 06:49:12 +00:00
|
|
|
doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
|
2024-09-12 09:11:08 +00:00
|
|
|
doAssert ConsensusFork.high == ConsensusFork.Electra
|
2022-09-19 09:25:41 +00:00
|
|
|
|
2023-09-22 21:45:24 +00:00
|
|
|
proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata =
|
2022-09-19 09:25:41 +00:00
|
|
|
template loadRuntimeMetadata(): auto =
|
|
|
|
if fileExists(networkName / "config.yaml"):
|
|
|
|
try:
|
2023-09-22 21:45:24 +00:00
|
|
|
let res = loadEth2NetworkMetadata(networkName)
|
|
|
|
res.valueOr:
|
|
|
|
fatal "The selected network is not compatible with the current build",
|
|
|
|
reason = res.error
|
|
|
|
quit 1
|
|
|
|
except IOError as exc:
|
|
|
|
fatal "Cannot load network: IOError", msg = exc.msg, networkName
|
|
|
|
quit 1
|
|
|
|
except PresetFileError as exc:
|
|
|
|
fatal "Cannot load network: PresetFileError", 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
|
|
|
|
2024-02-19 10:09:39 +00:00
|
|
|
if networkName in ["goerli", "prater"]:
|
2024-07-06 22:32:50 +00:00
|
|
|
warn "Goerli is deprecated and unsupported; https://blog.ethereum.org/2023/11/30/goerli-lts-update suggests migrating to Holesky or Sepolia"
|
2022-12-05 09:15: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-09-08 05:53:27 +00:00
|
|
|
gnosisMetadata
|
2022-09-19 09:25:41 +00:00
|
|
|
of "gnosis-chain":
|
|
|
|
warn "`--network:gnosis-chain` is deprecated, " &
|
|
|
|
"use `--network:gnosis` instead"
|
2023-09-08 05:53:27 +00:00
|
|
|
gnosisMetadata
|
2023-07-26 12:54:16 +00:00
|
|
|
of "chiado":
|
2023-09-08 05:53:27 +00:00
|
|
|
chiadoMetadata
|
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-09-08 05:53:27 +00:00
|
|
|
mainnetMetadata
|
|
|
|
of "holesky":
|
|
|
|
holeskyMetadata
|
2022-09-19 09:25:41 +00:00
|
|
|
of "sepolia":
|
2023-09-08 05:53:27 +00:00
|
|
|
sepoliaMetadata
|
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
|
|
|
metadata
|
2022-04-08 20:11:37 +00:00
|
|
|
|
2023-09-22 21:45:24 +00:00
|
|
|
proc getRuntimeConfig*(eth2Network: Option[string]): RuntimeConfig =
|
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-09-22 21:45:24 +00:00
|
|
|
metadata.cfg
|
2023-09-08 05:53:27 +00:00
|
|
|
|
2024-01-20 21:36:01 +00:00
|
|
|
when const_preset in ["mainnet", "gnosis"]:
|
|
|
|
template bakedInGenesisStateAsBytes(networkName: untyped): untyped =
|
|
|
|
when incbinEnabled:
|
|
|
|
`networkName Genesis`.toOpenArray(0, `networkName GenesisSize` - 1)
|
|
|
|
else:
|
|
|
|
`networkName Genesis`.toOpenArrayByte(0, `networkName Genesis`.high)
|
2023-09-08 05:53:27 +00:00
|
|
|
|
2024-01-20 21:36:01 +00:00
|
|
|
const
|
|
|
|
availableOnlyInMainnetBuild =
|
|
|
|
"Baked-in genesis states for the official Ethereum " &
|
|
|
|
"networks are available only in the mainnet build of Nimbus"
|
2023-09-08 05:53:27 +00:00
|
|
|
|
2024-01-20 21:36:01 +00:00
|
|
|
availableOnlyInGnosisBuild =
|
|
|
|
"Baked-in genesis states for the Gnosis network " &
|
|
|
|
"are available only in the gnosis build of Nimbus"
|
2023-09-08 05:53:27 +00:00
|
|
|
|
|
|
|
template bakedBytes*(metadata: GenesisMetadata): auto =
|
|
|
|
case metadata.networkName
|
|
|
|
of "mainnet":
|
|
|
|
when const_preset == "mainnet":
|
|
|
|
bakedInGenesisStateAsBytes mainnet
|
|
|
|
else:
|
|
|
|
raiseAssert availableOnlyInMainnetBuild
|
|
|
|
of "sepolia":
|
|
|
|
when const_preset == "mainnet":
|
|
|
|
bakedInGenesisStateAsBytes sepolia
|
|
|
|
else:
|
|
|
|
raiseAssert availableOnlyInMainnetBuild
|
|
|
|
of "gnosis":
|
|
|
|
when const_preset == "gnosis":
|
|
|
|
bakedInGenesisStateAsBytes gnosis
|
|
|
|
else:
|
|
|
|
raiseAssert availableOnlyInGnosisBuild
|
|
|
|
of "chiado":
|
|
|
|
when const_preset == "gnosis":
|
|
|
|
bakedInGenesisStateAsBytes chiado
|
|
|
|
else:
|
|
|
|
raiseAssert availableOnlyInGnosisBuild
|
|
|
|
else:
|
|
|
|
raiseAssert "The baked network metadata should use one of the name above"
|
|
|
|
|
|
|
|
func bakedGenesisValidatorsRoot*(metadata: Eth2NetworkMetadata): Opt[Eth2Digest] =
|
2023-10-04 08:19:05 +00:00
|
|
|
case metadata.genesis.kind
|
|
|
|
of BakedIn:
|
2023-09-08 05:53:27 +00:00
|
|
|
try:
|
|
|
|
let header = SSZ.decode(
|
|
|
|
toOpenArray(metadata.genesis.bakedBytes, 0, sizeof(BeaconStateHeader) - 1),
|
|
|
|
BeaconStateHeader)
|
|
|
|
Opt.some header.genesis_validators_root
|
2023-11-01 04:53:09 +00:00
|
|
|
except SerializationError:
|
2023-09-08 05:53:27 +00:00
|
|
|
raiseAssert "Invalid baken-in genesis state"
|
|
|
|
else:
|
|
|
|
Opt.none Eth2Digest
|
|
|
|
else:
|
|
|
|
func bakedBytes*(metadata: GenesisMetadata): seq[byte] =
|
|
|
|
raiseAssert "Baked genesis states are not available in the current build mode"
|
|
|
|
|
|
|
|
func bakedGenesisValidatorsRoot*(metadata: Eth2NetworkMetadata): Opt[Eth2Digest] =
|
|
|
|
Opt.none Eth2Digest
|