2021-03-26 06:52:01 +00:00
|
|
|
# beacon_chain
|
2022-02-21 11:55:56 +00:00
|
|
|
# Copyright (c) 2018-2022 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.
|
|
|
|
|
2021-03-26 06:52:01 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2020-07-02 15:14:11 +00:00
|
|
|
import
|
2021-10-12 11:36:52 +00:00
|
|
|
std/[sequtils, strutils, os],
|
2022-04-01 21:58:06 +00:00
|
|
|
stew/byteutils, stew/shims/macros, nimcrypto/hash,
|
2020-11-12 19:01:26 +00:00
|
|
|
eth/common/eth_types as commonEthTypes,
|
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-10-21 20:27:06 +00:00
|
|
|
ssz_serialization/navigator,
|
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
|
|
|
|
2022-04-01 21:58:06 +00:00
|
|
|
from ../consensus_object_pools/block_pools_types_light_client
|
2022-06-14 09:03:39 +00:00
|
|
|
import LightClientDataImportMode
|
2022-04-01 21:58:06 +00:00
|
|
|
|
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.
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-04-01 21:58:06 +00:00
|
|
|
Eth2NetworkConfigDefaults* = object
|
|
|
|
## Network specific config defaults
|
2022-06-07 17:01:11 +00:00
|
|
|
lightClientEnable*: bool
|
2022-06-14 09:03:39 +00:00
|
|
|
lightClientDataServe*: bool
|
|
|
|
lightClientDataImportMode*: LightClientDataImportMode
|
2022-04-01 21:58:06 +00:00
|
|
|
|
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
|
2021-09-08 12:47:48 +00:00
|
|
|
# If the eth1Network is specified, the Eth1Monitor 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.
|
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]
|
|
|
|
|
2020-11-12 19:01:26 +00:00
|
|
|
depositContractDeployedAt*: BlockHashOrNumber
|
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
|
2022-04-01 21:58:06 +00:00
|
|
|
|
|
|
|
configDefaults*: Eth2NetworkConfigDefaults
|
2020-07-09 22:08:54 +00:00
|
|
|
else:
|
|
|
|
incompatibilityDesc*: string
|
2020-07-02 15:14:11 +00:00
|
|
|
|
2022-06-24 14:57:50 +00:00
|
|
|
type DeploymentPhase* {.pure.} = enum
|
|
|
|
None,
|
|
|
|
Devnet,
|
|
|
|
Testnet,
|
|
|
|
Mainnet
|
|
|
|
|
|
|
|
func deploymentPhase*(genesisData: string): DeploymentPhase =
|
|
|
|
# SSZ processing at compile time does not work well.
|
|
|
|
#
|
|
|
|
# `BeaconState` layout:
|
|
|
|
# ```
|
|
|
|
# - genesis_time: uint64
|
|
|
|
# - genesis_validators_root: Eth2Digest
|
|
|
|
# - ...
|
|
|
|
# ```
|
|
|
|
#
|
|
|
|
# Comparing the first 40 bytes covers those two fields,
|
|
|
|
# which should identify the network with high likelihood.
|
|
|
|
# ''.join('%02X'%b for b in open("network_name/genesis.ssz", "rb").read()[:40])
|
|
|
|
if genesisData.len < 40:
|
|
|
|
return DeploymentPhase.None
|
|
|
|
|
|
|
|
const
|
|
|
|
mainnets = [
|
|
|
|
# Mainnet
|
|
|
|
"5730C65F000000004B363DB94E286120D76EB905340FDD4E54BFE9F06BF33FF6CF5AD27F511BFE95",
|
|
|
|
]
|
|
|
|
testnets = [
|
|
|
|
# Kiln
|
|
|
|
"0C572B620000000099B09FCD43E5905236C370F184056BEC6E6638CFC31A323B304FC4AA789CB4AD",
|
|
|
|
]
|
|
|
|
devnets = [
|
2022-07-05 15:02:12 +00:00
|
|
|
# Ropsten
|
|
|
|
"F0DB94620000000044F1E56283CA88B35C789F7F449E52339BC1FEFE3A45913A43A6D16EDCD33CF1",
|
2022-07-11 00:49:12 +00:00
|
|
|
# Sepolia
|
|
|
|
"607DB06200000000D8EA171F3C94AEA21EBC42A1ED61052ACF3F9209C00E4EFBAADDAC09ED9B8078",
|
2022-07-13 14:44:40 +00:00
|
|
|
# Mainnet Shadow Fork 9
|
2022-07-21 18:40:25 +00:00
|
|
|
"0C2ECC6200000000209BA2806D11E2394A9C6682815453EDCFDBA1DCE0C25D71BCFEF6363FBD3A43",
|
|
|
|
# Prater
|
|
|
|
"60F4596000000000043DB0D9A83813551EE2F33450D23797757D430911A9320530AD8A0EABC43EFB",
|
2022-06-24 14:57:50 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
let data = (genesisData[0 ..< 40].toHex())
|
|
|
|
if data in mainnets:
|
|
|
|
return DeploymentPhase.Mainnet
|
|
|
|
if data in testnets:
|
|
|
|
return DeploymentPhase.Testnet
|
|
|
|
if data in devnets:
|
|
|
|
return DeploymentPhase.Devnet
|
|
|
|
DeploymentPhase.None
|
|
|
|
|
2020-11-24 21:21:47 +00:00
|
|
|
const
|
2021-07-13 14:27:10 +00:00
|
|
|
eth2NetworksDir = currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor/eth2-networks"
|
2022-05-20 15:26:07 +00:00
|
|
|
mergeTestnetsDir = currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor/merge-testnets"
|
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"
|
|
|
|
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
|
|
|
|
|
|
|
depositContractBlock = 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
|
|
|
|
|
|
|
deployBlock = if fileExists(deployBlockPath):
|
|
|
|
readFile(deployBlockPath).strip
|
|
|
|
else:
|
|
|
|
""
|
|
|
|
|
2020-11-12 19:01:26 +00:00
|
|
|
depositContractDeployedAt = if depositContractBlock.len > 0:
|
|
|
|
BlockHashOrNumber.init(depositContractBlock)
|
2022-05-20 15:26:07 +00:00
|
|
|
elif deployBlock.len > 0:
|
|
|
|
BlockHashOrNumber.init(deployBlock)
|
2020-11-12 19:01:26 +00:00
|
|
|
else:
|
|
|
|
BlockHashOrNumber(isHash: false, number: 1)
|
|
|
|
|
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
|
|
|
|
2022-06-24 14:57:50 +00:00
|
|
|
deploymentPhase = genesisData.deploymentPhase
|
2022-04-01 21:58:06 +00:00
|
|
|
|
|
|
|
configDefaults =
|
|
|
|
Eth2NetworkConfigDefaults(
|
2022-06-07 17:01:11 +00:00
|
|
|
lightClientEnable:
|
|
|
|
false, # Only produces debug logs so far
|
2022-06-14 09:03:39 +00:00
|
|
|
lightClientDataServe:
|
2022-06-24 14:57:50 +00:00
|
|
|
deploymentPhase <= DeploymentPhase.Testnet,
|
2022-06-14 09:03:39 +00:00
|
|
|
lightClientDataImportMode:
|
2022-06-24 14:57:50 +00:00
|
|
|
if deploymentPhase <= DeploymentPhase.Testnet:
|
2022-06-14 09:03:39 +00:00
|
|
|
LightClientDataImportMode.OnlyNew
|
2022-04-01 21:58:06 +00:00
|
|
|
else:
|
2022-06-14 09:03:39 +00:00
|
|
|
LightClientDataImportMode.None
|
2022-04-01 21:58:06 +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,
|
2020-11-12 19:01:26 +00:00
|
|
|
depositContractDeployedAt: depositContractDeployedAt,
|
2020-11-24 21:21:47 +00:00
|
|
|
genesisData: genesisData,
|
2022-04-01 21:58:06 +00:00
|
|
|
genesisDepositsSnapshot: genesisDepositsSnapshot,
|
|
|
|
configDefaults: configDefaults)
|
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].} =
|
|
|
|
try:
|
|
|
|
result = loadEth2NetworkMetadata(path, eth1Network)
|
|
|
|
if result.incompatible:
|
2022-04-05 08:40:59 +00:00
|
|
|
macros.error "The current build is misconfigured. " &
|
2022-02-25 08:22:44 +00:00
|
|
|
"Attempt to load an incompatible network metadata: " &
|
|
|
|
result.incompatibilityDesc
|
|
|
|
except CatchableError as err:
|
|
|
|
macros.error "Failed to load network metadata at '" & path & "': " & err.msg
|
|
|
|
|
|
|
|
template eth2Network(path: string, eth1Network: Eth1Network): Eth2NetworkMetadata =
|
|
|
|
loadCompileTimeNetworkMetadata(eth2NetworksDir & "/" & path,
|
|
|
|
some eth1Network)
|
|
|
|
|
2022-05-20 15:26:07 +00:00
|
|
|
template mergeTestnet(path: string, eth1Network: Eth1Network): Eth2NetworkMetadata =
|
|
|
|
loadCompileTimeNetworkMetadata(mergeTestnetsDir & "/" & path,
|
|
|
|
some eth1Network)
|
|
|
|
|
2022-02-25 08:22:44 +00:00
|
|
|
when not defined(gnosisChainBinary):
|
|
|
|
when const_preset == "mainnet":
|
|
|
|
const
|
|
|
|
mainnetMetadata* = eth2Network("shared/mainnet", mainnet)
|
|
|
|
praterMetadata* = eth2Network("shared/prater", goerli)
|
2022-07-12 17:50:12 +00:00
|
|
|
ropstenMetadata* = mergeTestnet("ropsten-beacon-chain", ropsten)
|
|
|
|
sepoliaMetadata* = mergeTestnet("sepolia", sepolia)
|
2022-06-04 19:15:15 +00:00
|
|
|
static:
|
2022-06-16 14:11:26 +00:00
|
|
|
for network in [mainnetMetadata, praterMetadata, ropstenMetadata, sepoliaMetadata]:
|
2022-06-04 19:15:15 +00:00
|
|
|
checkForkConsistency(network.cfg)
|
2022-02-25 08:22:44 +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
|
|
|
|
quit 1
|
2020-09-01 09:01:57 +00:00
|
|
|
else:
|
2022-02-25 08:22:44 +00:00
|
|
|
fatal "config.yaml not found for network", networkName
|
|
|
|
quit 1
|
|
|
|
|
|
|
|
var
|
|
|
|
metadata = when const_preset == "mainnet":
|
|
|
|
case toLowerAscii(networkName)
|
|
|
|
of "mainnet":
|
|
|
|
mainnetMetadata
|
2022-07-14 20:07:16 +00:00
|
|
|
of "prater", "goerli":
|
2022-02-25 08:22:44 +00:00
|
|
|
praterMetadata
|
2022-05-20 15:26:07 +00:00
|
|
|
of "ropsten":
|
|
|
|
ropstenMetadata
|
2022-06-16 14:11:26 +00:00
|
|
|
of "sepolia":
|
|
|
|
sepoliaMetadata
|
2020-09-01 09:01:57 +00:00
|
|
|
else:
|
2022-02-25 08:22:44 +00:00
|
|
|
loadRuntimeMetadata()
|
|
|
|
else:
|
|
|
|
loadRuntimeMetadata()
|
|
|
|
|
|
|
|
if metadata.incompatible:
|
|
|
|
fatal "The selected network is not compatible with the current build",
|
|
|
|
reason = metadata.incompatibilityDesc
|
|
|
|
quit 1
|
|
|
|
metadata
|
|
|
|
|
|
|
|
proc getRuntimeConfig*(
|
|
|
|
eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} =
|
|
|
|
if eth2Network.isSome:
|
|
|
|
return getMetadataForNetwork(eth2Network.get).cfg
|
|
|
|
defaultRuntimeConfig
|
|
|
|
|
|
|
|
else:
|
|
|
|
const
|
2022-04-08 20:11:37 +00:00
|
|
|
gnosisMetadata* = loadCompileTimeNetworkMetadata(
|
|
|
|
currentSourcePath.parentDir.replace('\\', '/') & "/../../media/gnosis")
|
2022-02-25 08:22:44 +00:00
|
|
|
|
2022-06-04 19:15:15 +00:00
|
|
|
static: checkForkConsistency(gnosisMetadata.cfg)
|
|
|
|
|
2022-02-25 08:22:44 +00:00
|
|
|
proc checkNetworkParameterUse*(eth2Network: Option[string]) =
|
2022-04-08 20:11:37 +00:00
|
|
|
# Support `gnosis-chain` as network name which was used in v22.3
|
|
|
|
if eth2Network.isSome and eth2Network.get notin ["gnosis", "gnosis-chain"]:
|
|
|
|
fatal "The only supported value for the --network parameter is 'gnosis'"
|
2022-02-25 08:22:44 +00:00
|
|
|
quit 1
|
|
|
|
|
2022-04-08 20:11:37 +00:00
|
|
|
if eth2Network.isSome and eth2Network.get == "gnosis-chain":
|
|
|
|
warn "`--network:gnosis-chain` is deprecated, use `--network:gnosis` instead"
|
|
|
|
|
2022-02-25 08:22:44 +00:00
|
|
|
proc getRuntimeConfig*(eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} =
|
|
|
|
checkNetworkParameterUse eth2Network
|
2022-04-08 20:11:37 +00:00
|
|
|
gnosisMetadata.cfg
|
2020-11-27 19:48:33 +00:00
|
|
|
|
2021-12-14 15:44:34 +00:00
|
|
|
proc extractGenesisValidatorRootFromSnapshot*(
|
2021-06-16 12:45:05 +00:00
|
|
|
snapshot: string): Eth2Digest {.raises: [Defect, IOError, SszError].} =
|
2021-08-12 13:08:20 +00:00
|
|
|
sszMount(snapshot, phase0.BeaconState).genesis_validators_root[]
|