2024-01-25 10:04:09 +00:00
|
|
|
# fluffy
|
2024-01-12 21:06:19 +00:00
|
|
|
# Copyright (c) 2022-2024 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
|
2024-01-12 21:06:19 +00:00
|
|
|
chronicles,
|
2022-12-27 14:57:10 +00:00
|
|
|
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
|
2024-01-25 10:04:09 +00:00
|
|
|
metadata*: Eth2NetworkMetadata
|
2022-12-27 14:57:10 +00:00
|
|
|
forks*: ForkDigests
|
|
|
|
genesis_validators_root*: Eth2Digest
|
|
|
|
|
2024-01-25 10:04:09 +00:00
|
|
|
proc loadNetworkData*(networkName: string): NetworkInitData =
|
2022-12-27 14:57:10 +00:00
|
|
|
let
|
2024-01-25 10:04:09 +00:00
|
|
|
metadata = loadEth2Network(some("mainnet"))
|
2022-12-27 14:57:10 +00:00
|
|
|
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)))
|
2024-01-25 10:04:09 +00:00
|
|
|
except SerializationError as err:
|
2022-12-27 14:57:10 +00:00
|
|
|
raiseAssert "Invalid baked-in state: " & err.msg
|
|
|
|
|
2024-01-12 21:06:19 +00:00
|
|
|
genesisTime = getStateField(genesisState[], genesis_time)
|
|
|
|
beaconClock = BeaconClock.init(genesisTime).valueOr:
|
|
|
|
error "Invalid genesis time in state", genesisTime
|
|
|
|
quit QuitFailure
|
2022-12-27 14:57:10 +00:00
|
|
|
|
|
|
|
genesis_validators_root =
|
|
|
|
getStateField(genesisState[], genesis_validators_root)
|
|
|
|
|
|
|
|
forks = newClone ForkDigests.init(metadata.cfg, genesis_validators_root)
|
|
|
|
|
|
|
|
return NetworkInitData(
|
|
|
|
clock: beaconClock,
|
2024-01-25 10:04:09 +00:00
|
|
|
metadata: metadata,
|
2022-12-27 14:57:10 +00:00
|
|
|
forks: forks[],
|
|
|
|
genesis_validators_root: genesis_validators_root
|
|
|
|
)
|