Re-wire the sending of deposits by the 'deposits create' command
This commit is contained in:
parent
384e512031
commit
62e4efe34b
|
@ -7,7 +7,7 @@
|
|||
|
||||
import
|
||||
# Standard library
|
||||
algorithm, os, tables, random, strutils, times, math, terminal,
|
||||
algorithm, os, tables, strutils, times, math, terminal,
|
||||
|
||||
# Nimble packages
|
||||
stew/[objects, byteutils], stew/shims/macros,
|
||||
|
@ -1233,33 +1233,25 @@ programMain:
|
|||
createDir(config.outValidatorsDir)
|
||||
createDir(config.outSecretsDir)
|
||||
|
||||
discard generateDeposits(
|
||||
let deposits = generateDeposits(
|
||||
config.totalDeposits,
|
||||
config.outValidatorsDir,
|
||||
config.outSecretsDir)
|
||||
|
||||
if deposits.isErr:
|
||||
fatal "Failed to generate deposits", err = deposits.error
|
||||
quit 1
|
||||
|
||||
if not config.dontSend:
|
||||
waitFor sendDeposits(config, deposits.value)
|
||||
|
||||
of DepositsCmd.send:
|
||||
if config.minDelay > config.maxDelay:
|
||||
echo "The minimum delay should not be larger than the maximum delay"
|
||||
quit 1
|
||||
|
||||
let deposits = loadDeposits(config.depositsDir)
|
||||
|
||||
var delayGenerator: DelayGenerator
|
||||
if config.maxDelay > 0.0:
|
||||
delayGenerator = proc (): chronos.Duration {.gcsafe.} =
|
||||
chronos.milliseconds (rand(config.minDelay..config.maxDelay)*1000).int
|
||||
|
||||
info "Sending deposits",
|
||||
web3 = config.web3Url,
|
||||
depositContract = config.depositContractAddress
|
||||
|
||||
waitFor sendDeposits(
|
||||
deposits,
|
||||
config.web3Url,
|
||||
config.depositContractAddress,
|
||||
config.depositPrivateKey,
|
||||
delayGenerator)
|
||||
waitFor sendDeposits(config, deposits)
|
||||
|
||||
of DepositsCmd.status:
|
||||
# TODO
|
||||
|
|
|
@ -282,6 +282,11 @@ type
|
|||
discard
|
||||
|
||||
of deposits:
|
||||
depositPrivateKey* {.
|
||||
defaultValue: ""
|
||||
desc: "Private key of the controlling (sending) account",
|
||||
name: "deposit-private-key" }: string
|
||||
|
||||
case depositsCmd* {.command.}: DepositsCmd
|
||||
of DepositsCmd.create:
|
||||
totalDeposits* {.
|
||||
|
@ -303,11 +308,6 @@ type
|
|||
desc: "Output folder for randomly generated keystore passphrases"
|
||||
name: "out-secrets-dir" }: string
|
||||
|
||||
depositPrivateKey* {.
|
||||
defaultValue: ""
|
||||
desc: "Private key of the controlling (sending) account",
|
||||
name: "deposit-private-key" }: string
|
||||
|
||||
dontSend* {.
|
||||
defaultValue: false,
|
||||
desc: "By default, all created deposits are also immediately sent " &
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import
|
||||
os, strutils, terminal,
|
||||
os, strutils, terminal, random,
|
||||
chronicles, chronos, blscurve, nimcrypto, json_serialization, serialization,
|
||||
web3, stint, eth/keys, confutils,
|
||||
spec/[datatypes, digest, crypto, keystore], conf, ssz/merkleization, merkle_minimal
|
||||
|
@ -162,6 +162,8 @@ proc loadDeposits*(depositsDir: string): seq[Deposit] =
|
|||
|
||||
{.pop.}
|
||||
|
||||
# TODO: async functions should note take `seq` inputs because
|
||||
# this leads to full copies.
|
||||
proc sendDeposits*(deposits: seq[Deposit],
|
||||
web3Url, depositContractAddress, privateKey: string,
|
||||
delayGenerator: DelayGenerator = nil) {.async.} =
|
||||
|
@ -190,3 +192,21 @@ proc sendDeposits*(deposits: seq[Deposit],
|
|||
if delayGenerator != nil:
|
||||
await sleepAsync(delayGenerator())
|
||||
|
||||
proc sendDeposits*(config: BeaconNodeConf,
|
||||
deposits: seq[Deposit]) {.async.} =
|
||||
var delayGenerator: DelayGenerator
|
||||
if config.maxDelay > 0.0:
|
||||
delayGenerator = proc (): chronos.Duration {.gcsafe.} =
|
||||
chronos.milliseconds (rand(config.minDelay..config.maxDelay)*1000).int
|
||||
|
||||
info "Sending deposits",
|
||||
web3 = config.web3Url,
|
||||
depositContract = config.depositContractAddress
|
||||
|
||||
await sendDeposits(
|
||||
deposits,
|
||||
config.web3Url,
|
||||
config.depositContractAddress,
|
||||
config.depositPrivateKey,
|
||||
delayGenerator)
|
||||
|
||||
|
|
Loading…
Reference in New Issue