Skip to content

Commit

Permalink
make network specific testing more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
etan-status committed Jun 24, 2022
1 parent d16047d commit c8e1cd7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
vanityLogs = default(VanityLogs)): ChainDAGRef =
cfg.checkForkConsistency()

doAssert updateFlags - {verifyFinalization, enableTestnetFeatures} == {},
doAssert updateFlags - {verifyFinalization, enableTestFeatures} == {},
"Other flags not supported in ChainDAG"

# TODO we require that the db contains both a head and a tail block -
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/extras.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type
## When process_slots() is being called as part of a state_transition(),
## the hash_tree_root() from the block will fill in the state.root so it
## should skip calculating that last state root.
enableTestnetFeatures ##\
## Whether to opt into testnet specific logic.
enableTestFeatures ##\
## Whether to enable extra features for testing.

UpdateFlags* = set[UpdateFlag]
53 changes: 38 additions & 15 deletions beacon_chain/networking/network_metadata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ type
else:
incompatibilityDesc*: string

func shouldEnableTestnetFeatures*(genesisData: string): bool =
type DeploymentPhase* {.pure.} = enum
None,
Devnet,
Testnet,
Mainnet

func deploymentPhase*(genesisData: string): DeploymentPhase =
# SSZ processing at compile time does not work well.
#
# `BeaconState` layout:
Expand All @@ -101,18 +107,35 @@ func shouldEnableTestnetFeatures*(genesisData: string): bool =
# 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 false
return DeploymentPhase.None

const
mainnets = [
# Mainnet
"5730C65F000000004B363DB94E286120D76EB905340FDD4E54BFE9F06BF33FF6CF5AD27F511BFE95",
]
testnets = [
# Kiln
"0C572B620000000099B09FCD43E5905236C370F184056BEC6E6638CFC31A323B304FC4AA789CB4AD",
# Ropsten
"F0DB94620000000044F1E56283CA88B35C789F7F449E52339BC1FEFE3A45913A43A6D16EDCD33CF1",
# Prater
"60F4596000000000043DB0D9A83813551EE2F33450D23797757D430911A9320530AD8A0EABC43EFB",
# Sepolia
"607DB06200000000D8EA171F3C94AEA21EBC42A1ED61052ACF3F9209C00E4EFBAADDAC09ED9B8078",
]
devnets = [
"placeholder",
]

let data = (genesisData[0 ..< 40].toHex())
data in [
# Kiln
"0C572B620000000099B09FCD43E5905236C370F184056BEC6E6638CFC31A323B304FC4AA789CB4AD",
# Ropsten
"F0DB94620000000044F1E56283CA88B35C789F7F449E52339BC1FEFE3A45913A43A6D16EDCD33CF1",
# Prater
"60F4596000000000043DB0D9A83813551EE2F33450D23797757D430911A9320530AD8A0EABC43EFB",
# Sepolia
"607DB06200000000D8EA171F3C94AEA21EBC42A1ED61052ACF3F9209C00E4EFBAADDAC09ED9B8078",
]
if data in mainnets:
return DeploymentPhase.Mainnet
if data in testnets:
return DeploymentPhase.Testnet
if data in devnets:
return DeploymentPhase.Devnet
DeploymentPhase.None

const
eth2NetworksDir = currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor/eth2-networks"
Expand Down Expand Up @@ -193,16 +216,16 @@ proc loadEth2NetworkMetadata*(path: string, eth1Network = none(Eth1Network)): Et
else:
""

shouldEnableTestnetFeatures = genesisData.shouldEnableTestnetFeatures
deploymentPhase = genesisData.deploymentPhase

configDefaults =
Eth2NetworkConfigDefaults(
lightClientEnable:
false, # Only produces debug logs so far
lightClientDataServe:
shouldEnableTestnetFeatures,
deploymentPhase <= DeploymentPhase.Testnet,
lightClientDataImportMode:
if shouldEnableTestnetFeatures:
if deploymentPhase <= DeploymentPhase.Testnet:
LightClientDataImportMode.OnlyNew
else:
LightClientDataImportMode.None
Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ proc loadChainDag(
eventBus: EventBus,
validatorMonitor: ref ValidatorMonitor,
networkGenesisValidatorsRoot: Option[Eth2Digest],
shouldEnableTestnetFeatures: bool): ChainDAGRef =
shouldEnableTestFeatures: bool): ChainDAGRef =
var dag: ChainDAGRef
info "Loading block DAG from database", path = config.databaseDir

Expand All @@ -175,7 +175,7 @@ proc loadChainDag(

let
extraFlags =
if shouldEnableTestnetFeatures: {enableTestnetFeatures}
if shouldEnableTestFeatures: {enableTestFeatures}
else: {}
chainDagFlags =
if config.verifyFinalization: {verifyFinalization}
Expand Down Expand Up @@ -585,7 +585,7 @@ proc init*(T: type BeaconNode,
dag = loadChainDag(
config, cfg, db, eventBus,
validatorMonitor, networkGenesisValidatorsRoot,
genesisStateContents.shouldEnableTestnetFeatures)
genesisStateContents.deploymentPhase <= DeploymentPhase.Devnet)
genesisTime = getStateField(dag.headState, genesis_time)
beaconClock = BeaconClock.init(genesisTime)
getBeaconTime = beaconClock.getBeaconTimeFn()
Expand Down

0 comments on commit c8e1cd7

Please sign in to comment.