2023-05-15 05:05:12 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2023-05-15 05:05:12 +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.
|
|
|
|
|
2021-05-28 12:42:39 +00:00
|
|
|
import
|
2023-03-05 01:40:21 +00:00
|
|
|
std/[json, strutils, times, sequtils],
|
2021-05-28 12:42:39 +00:00
|
|
|
chronos, confutils, chronicles,
|
2023-12-12 15:15:00 +00:00
|
|
|
web3, web3/primitives,
|
2021-05-28 12:42:39 +00:00
|
|
|
eth/async_utils,
|
2023-03-05 01:40:21 +00:00
|
|
|
../beacon_chain/beacon_chain_db,
|
2021-05-28 12:42:39 +00:00
|
|
|
../beacon_chain/networking/network_metadata,
|
2023-05-15 05:05:12 +00:00
|
|
|
../beacon_chain/el/el_manager,
|
2023-03-05 01:40:21 +00:00
|
|
|
../beacon_chain/spec/[presets, helpers]
|
2021-05-28 12:42:39 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
CliFlags = object
|
2023-03-14 15:40:37 +00:00
|
|
|
network* {.
|
2023-03-05 01:40:21 +00:00
|
|
|
defaultValue: "mainnet"
|
|
|
|
name: "network".}: string
|
2023-03-14 15:40:37 +00:00
|
|
|
elUrls* {.
|
2023-03-05 01:40:21 +00:00
|
|
|
name: "el".}: seq[EngineApiUrlConfigValue]
|
2023-03-14 15:40:37 +00:00
|
|
|
jwtSecret* {.
|
2023-03-05 01:40:21 +00:00
|
|
|
name: "jwt-secret".}: Option[InputFile]
|
2023-03-14 15:40:37 +00:00
|
|
|
outDepositsFile* {.
|
2023-03-05 01:40:21 +00:00
|
|
|
name: "out-deposits-file".}: Option[OutFile]
|
2023-03-14 15:40:37 +00:00
|
|
|
configFile* {.
|
|
|
|
desc: "Loads the configuration from a TOML file"
|
|
|
|
name: "config-file" .}: Option[InputFile]
|
2021-05-28 12:42:39 +00:00
|
|
|
|
|
|
|
proc main(flags: CliFlags) {.async.} =
|
2023-03-05 01:40:21 +00:00
|
|
|
let
|
|
|
|
db = BeaconChainDB.new("", inMemory = true)
|
|
|
|
metadata = getMetadataForNetwork(flags.network)
|
|
|
|
beaconTimeFn = proc(): BeaconTime =
|
|
|
|
# BEWARE of this hack
|
|
|
|
# The EL manager consults the current time in order to determine when the
|
|
|
|
# transition configuration exchange should start. We assume Bellatrix has
|
|
|
|
# just arrived which should trigger the configuration exchange and allow
|
|
|
|
# the downloader to connect to ELs serving the Engine API.
|
|
|
|
start_beacon_time(Slot(metadata.cfg.BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH))
|
|
|
|
|
|
|
|
let
|
|
|
|
elManager = ELManager.new(
|
|
|
|
metadata.cfg,
|
|
|
|
metadata.depositContractBlock,
|
|
|
|
metadata.depositContractBlockHash,
|
|
|
|
db,
|
|
|
|
toFinalEngineApiUrls(flags.elUrls, flags.jwtSecret),
|
|
|
|
eth1Network = metadata.eth1Network)
|
|
|
|
|
|
|
|
elManager.start()
|
|
|
|
|
|
|
|
var depositsFile: File
|
|
|
|
if flags.outDepositsFile.isSome:
|
|
|
|
depositsFile = open(string flags.outDepositsFile.get, fmWrite)
|
|
|
|
depositsFile.write(
|
|
|
|
"block", ",",
|
|
|
|
"validatorKey", ",",
|
|
|
|
"withdrawalCredentials", "\n")
|
|
|
|
depositsFile.flushFile()
|
|
|
|
|
|
|
|
var blockIdx = 0
|
|
|
|
while not elManager.isSynced():
|
|
|
|
await sleepAsync chronos.seconds(1)
|
|
|
|
|
|
|
|
if flags.outDepositsFile.isSome and
|
|
|
|
elManager.eth1ChainBlocks.len > blockIdx:
|
|
|
|
for i in blockIdx ..< elManager.eth1ChainBlocks.len:
|
|
|
|
for deposit in elManager.eth1ChainBlocks[i].deposits:
|
2021-05-28 12:42:39 +00:00
|
|
|
depositsFile.write(
|
2023-03-05 01:40:21 +00:00
|
|
|
$elManager.eth1ChainBlocks[i].number, ",",
|
|
|
|
$deposit.pubkey, ",",
|
|
|
|
$deposit.withdrawal_credentials, "\n")
|
2021-05-28 12:42:39 +00:00
|
|
|
depositsFile.flushFile()
|
|
|
|
|
2023-03-05 01:40:21 +00:00
|
|
|
blockIdx = elManager.eth1ChainBlocks.len
|
2021-05-28 12:42:39 +00:00
|
|
|
|
2023-03-05 01:40:21 +00:00
|
|
|
info "All deposits downloaded"
|
2021-05-28 12:42:39 +00:00
|
|
|
|
2023-03-14 15:40:37 +00:00
|
|
|
waitFor main(
|
|
|
|
load(CliFlags,
|
2023-07-19 18:26:30 +00:00
|
|
|
secondarySources = proc (
|
|
|
|
config: CliFlags, sources: ref SecondarySources
|
|
|
|
) {.raises: [ConfigurationError].} =
|
2023-03-14 15:40:37 +00:00
|
|
|
if config.configFile.isSome:
|
|
|
|
sources.addConfigFile(Toml, config.configFile.get)))
|