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,
|
|
|
|
web3, web3/ethtypes as web3Types,
|
|
|
|
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,
|
|
|
|
../beacon_chain/eth1/eth1_monitor,
|
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,
|
|
|
|
secondarySources = proc (config: CliFlags, sources: auto) =
|
|
|
|
if config.configFile.isSome:
|
|
|
|
sources.addConfigFile(Toml, config.configFile.get)))
|