allow custom configs in Gnosis binary (#4134)

When running as Gnosis-chain binary the config was no longer adjustable.
Restores loading custom configs when running as Gnosis-chain binary,
as long as the following keys remain same:
- SLOTS_PER_EPOCH=16
- SECONDS_PER_SLOT=5
- BASE_REWARD_FACTOR=25
- EPOCHS_PER_SYNC_COMMITTEE_PERIOD=512

This allows running the Gnosis-chain binary on custom test networks.
This commit is contained in:
Etan Kissling 2022-09-19 11:25:41 +02:00 committed by GitHub
parent ca871a5435
commit abd6581b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 73 deletions

View File

@ -1223,21 +1223,27 @@ proc readValue*(r: var TomlReader, a: var Address)
proc loadEth2Network*( proc loadEth2Network*(
eth2Network: Option[string] eth2Network: Option[string]
): Eth2NetworkMetadata {.raises: [Defect, IOError].} = ): Eth2NetworkMetadata {.raises: [Defect, IOError].} =
network_name.set(2, labelValues = [eth2Network.get(otherwise = "mainnet")]) const defaultName =
when not defined(gnosisChainBinary): when defined(gnosisChainBinary) and const_preset == "mainnet":
if eth2Network.isSome: "gnosis"
getMetadataForNetwork(eth2Network.get) elif const_preset == "mainnet":
"mainnet"
else: else:
when const_preset == "mainnet": "(unspecified)"
mainnetMetadata network_name.set(2, labelValues = [eth2Network.get(otherwise = defaultName)])
else:
# Presumably other configurations can have other defaults, but for now if eth2Network.isSome:
# this simplifies the flow getMetadataForNetwork(eth2Network.get)
echo "Must specify network on non-mainnet node"
quit 1
else: else:
checkNetworkParameterUse eth2Network when defined(gnosisChainBinary) and const_preset == "mainnet":
gnosisMetadata gnosisMetadata
elif const_preset == "mainnet":
mainnetMetadata
else:
# Presumably other configurations can have other defaults, but for now
# this simplifies the flow
fatal "Must specify network on non-mainnet node"
quit 1
template loadEth2Network*(config: BeaconNodeConf): Eth2NetworkMetadata = template loadEth2Network*(config: BeaconNodeConf): Eth2NetworkMetadata =
loadEth2Network(config.eth2Network) loadEth2Network(config.eth2Network)

View File

@ -200,76 +200,79 @@ template mergeTestnet(path: string, eth1Network: Eth1Network): Eth2NetworkMetada
loadCompileTimeNetworkMetadata(mergeTestnetsDir & "/" & path, loadCompileTimeNetworkMetadata(mergeTestnetsDir & "/" & path,
some eth1Network) some eth1Network)
when not defined(gnosisChainBinary): when defined(gnosisChainBinary) and const_preset == "mainnet":
when const_preset == "mainnet": const
const gnosisMetadata* = loadCompileTimeNetworkMetadata(
mainnetMetadata* = eth2Network("shared/mainnet", mainnet) currentSourcePath.parentDir.replace('\\', '/') &
praterMetadata* = eth2Network("shared/prater", goerli) "/../../media/gnosis")
ropstenMetadata* = mergeTestnet("ropsten-beacon-chain", ropsten) static:
sepoliaMetadata* = mergeTestnet("sepolia", sepolia) for network in [gnosisMetadata]:
static: checkForkConsistency(network.cfg)
for network in [mainnetMetadata, praterMetadata, ropstenMetadata, sepoliaMetadata]:
checkForkConsistency(network.cfg)
proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata {.raises: [Defect, IOError].} = elif const_preset == "mainnet":
template loadRuntimeMetadata: auto = const
if fileExists(networkName / "config.yaml"): mainnetMetadata* = eth2Network("shared/mainnet", mainnet)
try: praterMetadata* = eth2Network("shared/prater", goerli)
loadEth2NetworkMetadata(networkName) ropstenMetadata* = mergeTestnet("ropsten-beacon-chain", ropsten)
except CatchableError as exc: sepoliaMetadata* = mergeTestnet("sepolia", sepolia)
fatal "Cannot load network", msg = exc.msg, networkName static:
quit 1 for network in [
else: mainnetMetadata, praterMetadata, ropstenMetadata, sepoliaMetadata]:
fatal "config.yaml not found for network", networkName checkForkConsistency(network.cfg)
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 quit 1
else:
fatal "config.yaml not found for network", networkName
quit 1
var let metadata =
metadata = when const_preset == "mainnet": when defined(gnosisChainBinary) and const_preset == "mainnet":
case toLowerAscii(networkName) case toLowerAscii(networkName)
of "mainnet": of "gnosis":
mainnetMetadata gnosisMetadata
of "prater", "goerli": of "gnosis-chain":
praterMetadata warn "`--network:gnosis-chain` is deprecated, " &
of "ropsten": "use `--network:gnosis` instead"
ropstenMetadata gnosisMetadata
of "sepolia":
sepoliaMetadata
else:
loadRuntimeMetadata()
else: else:
loadRuntimeMetadata() loadRuntimeMetadata()
if metadata.incompatible: elif const_preset == "mainnet":
fatal "The selected network is not compatible with the current build", case toLowerAscii(networkName)
reason = metadata.incompatibilityDesc of "mainnet":
quit 1 mainnetMetadata
metadata of "prater", "goerli":
praterMetadata
of "ropsten":
ropstenMetadata
of "sepolia":
sepoliaMetadata
else:
loadRuntimeMetadata()
proc getRuntimeConfig*( else:
eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} = loadRuntimeMetadata()
if eth2Network.isSome:
return getMetadataForNetwork(eth2Network.get).cfg
defaultRuntimeConfig
else: if metadata.incompatible:
const fatal "The selected network is not compatible with the current build",
gnosisMetadata* = loadCompileTimeNetworkMetadata( reason = metadata.incompatibilityDesc
currentSourcePath.parentDir.replace('\\', '/') & "/../../media/gnosis") quit 1
static: checkForkConsistency(gnosisMetadata.cfg) metadata
proc checkNetworkParameterUse*(eth2Network: Option[string]) = proc getRuntimeConfig*(
# Support `gnosis-chain` as network name which was used in v22.3 eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} =
if eth2Network.isSome and eth2Network.get notin ["gnosis", "gnosis-chain"]: if eth2Network.isSome:
fatal "The only supported value for the --network parameter is 'gnosis'" return getMetadataForNetwork(eth2Network.get).cfg
quit 1 defaultRuntimeConfig
if eth2Network.isSome and eth2Network.get == "gnosis-chain":
warn "`--network:gnosis-chain` is deprecated, use `--network:gnosis` instead"
proc getRuntimeConfig*(eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} =
checkNetworkParameterUse eth2Network
gnosisMetadata.cfg
proc extractGenesisValidatorRootFromSnapshot*( proc extractGenesisValidatorRootFromSnapshot*(
snapshot: string): Eth2Digest {.raises: [Defect, IOError, SszError].} = snapshot: string): Eth2Digest {.raises: [Defect, IOError, SszError].} =