Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom configs in Gnosis binary #4134

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions beacon_chain/conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1223,21 +1223,27 @@ proc readValue*(r: var TomlReader, a: var Address)
proc loadEth2Network*(
eth2Network: Option[string]
): Eth2NetworkMetadata {.raises: [Defect, IOError].} =
network_name.set(2, labelValues = [eth2Network.get(otherwise = "mainnet")])
when not defined(gnosisChainBinary):
if eth2Network.isSome:
getMetadataForNetwork(eth2Network.get)
const defaultName =
when defined(gnosisChainBinary) and const_preset == "mainnet":
"gnosis"
elif const_preset == "mainnet":
"mainnet"
else:
when const_preset == "mainnet":
mainnetMetadata
else:
# Presumably other configurations can have other defaults, but for now
# this simplifies the flow
echo "Must specify network on non-mainnet node"
quit 1
"(unspecified)"
network_name.set(2, labelValues = [eth2Network.get(otherwise = defaultName)])

if eth2Network.isSome:
getMetadataForNetwork(eth2Network.get)
else:
checkNetworkParameterUse eth2Network
gnosisMetadata
when defined(gnosisChainBinary) and const_preset == "mainnet":
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 =
loadEth2Network(config.eth2Network)
Expand Down
125 changes: 64 additions & 61 deletions beacon_chain/networking/network_metadata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -200,76 +200,79 @@ template mergeTestnet(path: string, eth1Network: Eth1Network): Eth2NetworkMetada
loadCompileTimeNetworkMetadata(mergeTestnetsDir & "/" & path,
some eth1Network)

when not defined(gnosisChainBinary):
when const_preset == "mainnet":
const
mainnetMetadata* = eth2Network("shared/mainnet", mainnet)
praterMetadata* = eth2Network("shared/prater", goerli)
ropstenMetadata* = mergeTestnet("ropsten-beacon-chain", ropsten)
sepoliaMetadata* = mergeTestnet("sepolia", sepolia)
static:
for network in [mainnetMetadata, praterMetadata, ropstenMetadata, sepoliaMetadata]:
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
else:
fatal "config.yaml not found for network", networkName
when defined(gnosisChainBinary) and const_preset == "mainnet":
const
gnosisMetadata* = loadCompileTimeNetworkMetadata(
currentSourcePath.parentDir.replace('\\', '/') &
"/../../media/gnosis")
static:
for network in [gnosisMetadata]:
checkForkConsistency(network.cfg)

elif const_preset == "mainnet":
const
mainnetMetadata* = eth2Network("shared/mainnet", mainnet)
praterMetadata* = eth2Network("shared/prater", goerli)
ropstenMetadata* = mergeTestnet("ropsten-beacon-chain", ropsten)
sepoliaMetadata* = mergeTestnet("sepolia", sepolia)
static:
for network in [
mainnetMetadata, praterMetadata, ropstenMetadata, sepoliaMetadata]:
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
else:
fatal "config.yaml not found for network", networkName
quit 1

var
metadata = when const_preset == "mainnet":
case toLowerAscii(networkName)
of "mainnet":
mainnetMetadata
of "prater", "goerli":
praterMetadata
of "ropsten":
ropstenMetadata
of "sepolia":
sepoliaMetadata
else:
loadRuntimeMetadata()
let metadata =
when defined(gnosisChainBinary) and const_preset == "mainnet":
case toLowerAscii(networkName)
of "gnosis":
gnosisMetadata
of "gnosis-chain":
warn "`--network:gnosis-chain` is deprecated, " &
"use `--network:gnosis` instead"
gnosisMetadata
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
gnosisMetadata* = loadCompileTimeNetworkMetadata(
currentSourcePath.parentDir.replace('\\', '/') & "/../../media/gnosis")
elif const_preset == "mainnet":
case toLowerAscii(networkName)
of "mainnet":
mainnetMetadata
of "prater", "goerli":
praterMetadata
of "ropsten":
ropstenMetadata
of "sepolia":
sepoliaMetadata
else:
loadRuntimeMetadata()

static: checkForkConsistency(gnosisMetadata.cfg)
else:
loadRuntimeMetadata()

proc checkNetworkParameterUse*(eth2Network: Option[string]) =
# 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'"
quit 1
if metadata.incompatible:
fatal "The selected network is not compatible with the current build",
reason = metadata.incompatibilityDesc
quit 1

if eth2Network.isSome and eth2Network.get == "gnosis-chain":
warn "`--network:gnosis-chain` is deprecated, use `--network:gnosis` instead"
metadata

proc getRuntimeConfig*(eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} =
checkNetworkParameterUse eth2Network
gnosisMetadata.cfg
proc getRuntimeConfig*(
Copy link
Contributor

@zah zah Sep 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be removed now and all usages can be replaced with loadEth2Network(ethNetwork).cfg (or its moral equivalent).

In particular, the use of defaultRuntimeConfig is inappropriate due to the reasoning provided in #4121 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds more like a followup rather than a part of relaxing the Gnosis specific restrictions, but generally agree that this can now be done.

eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} =
if eth2Network.isSome:
return getMetadataForNetwork(eth2Network.get).cfg
defaultRuntimeConfig

proc extractGenesisValidatorRootFromSnapshot*(
snapshot: string): Eth2Digest {.raises: [Defect, IOError, SszError].} =
Expand Down