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/beacon_clock,
|
|
|
|
beacon_chain/conf
|
|
|
|
|
2024-10-30 11:51:00 +00:00
|
|
|
export beacon_clock, network_metadata
|
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
type NetworkInitData* = object
|
|
|
|
clock*: BeaconClock
|
|
|
|
metadata*: Eth2NetworkMetadata
|
|
|
|
forks*: ForkDigests
|
|
|
|
genesis_validators_root*: Eth2Digest
|
2022-12-27 14:57:10 +00:00
|
|
|
|
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:
|
2024-02-28 17:31:45 +00:00
|
|
|
template genesisData(): auto =
|
|
|
|
metadata.genesis.bakedBytes
|
|
|
|
|
|
|
|
newClone(
|
|
|
|
readSszForkedHashedBeaconState(
|
|
|
|
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
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
genesis_validators_root = getStateField(genesisState[], genesis_validators_root)
|
2022-12-27 14:57:10 +00:00
|
|
|
|
|
|
|
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[],
|
2024-02-28 17:31:45 +00:00
|
|
|
genesis_validators_root: genesis_validators_root,
|
2022-12-27 14:57:10 +00:00
|
|
|
)
|