2022-12-27 14:57:10 +00:00
|
|
|
# Nimbus - Portal Network
|
2023-01-31 12:38:08 +00:00
|
|
|
# Copyright (c) 2022-2023 Status Research & Development GmbH
|
2022-12-27 14:57:10 +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-31 12:38:08 +00:00
|
|
|
{.push raises: [].}
|
2022-12-27 14:57:10 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
beacon_chain/networking/network_metadata,
|
|
|
|
beacon_chain/spec/forks,
|
|
|
|
beacon_chain/spec/datatypes/altair,
|
|
|
|
beacon_chain/beacon_clock,
|
|
|
|
beacon_chain/conf
|
|
|
|
|
|
|
|
type
|
|
|
|
NetworkInitData* = object
|
|
|
|
clock*: BeaconClock
|
|
|
|
metaData*: Eth2NetworkMetadata
|
|
|
|
forks*: ForkDigests
|
|
|
|
genesis_validators_root*: Eth2Digest
|
|
|
|
|
2023-02-26 18:18:03 +00:00
|
|
|
proc loadNetworkData*(
|
|
|
|
networkName: string): NetworkInitData {.raises: [CatchableError].} =
|
2022-12-27 14:57:10 +00:00
|
|
|
let
|
|
|
|
metadata =
|
|
|
|
try:
|
|
|
|
loadEth2Network(some("mainnet"))
|
|
|
|
except CatchableError as exc:
|
|
|
|
raiseAssert(exc.msg)
|
|
|
|
|
|
|
|
genesisState =
|
|
|
|
try:
|
2023-09-13 02:32:38 +00:00
|
|
|
template genesisData(): auto = metadata.genesis.bakedBytes
|
2022-12-27 14:57:10 +00:00
|
|
|
newClone(readSszForkedHashedBeaconState(
|
2023-06-04 06:00:50 +00:00
|
|
|
metadata.cfg, genesisData.toOpenArray(genesisData.low, genesisData.high)))
|
2022-12-27 14:57:10 +00:00
|
|
|
except CatchableError as err:
|
|
|
|
raiseAssert "Invalid baked-in state: " & err.msg
|
|
|
|
|
|
|
|
beaconClock = BeaconClock.init(getStateField(genesisState[], genesis_time))
|
|
|
|
|
|
|
|
genesis_validators_root =
|
|
|
|
getStateField(genesisState[], genesis_validators_root)
|
|
|
|
|
|
|
|
forks = newClone ForkDigests.init(metadata.cfg, genesis_validators_root)
|
|
|
|
|
|
|
|
return NetworkInitData(
|
|
|
|
clock: beaconClock,
|
|
|
|
metaData: metaData,
|
|
|
|
forks: forks[],
|
|
|
|
genesis_validators_root: genesis_validators_root
|
|
|
|
)
|