From c19321e578c89c5c76953a38475acc41b9586c25 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 1 Jul 2020 12:13:56 +0300 Subject: [PATCH] Fix the 'maxDelay' FieldError problem during the initial deposit making when joining a testnet --- beacon_chain/beacon_node.nim | 9 +++++++-- beacon_chain/keystore_management.nim | 10 +++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 99a5e8c81..23bceb33d 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -7,7 +7,7 @@ import # Standard library - algorithm, os, tables, strutils, times, math, terminal, + algorithm, os, tables, strutils, times, math, terminal, random, # Nimble packages stew/[objects, byteutils], stew/shims/macros, @@ -1235,12 +1235,17 @@ programMain: waitFor sendDeposits(config, deposits.value) of DepositsCmd.send: + var delayGenerator: DelayGenerator + if config.maxDelay > 0.0: + delayGenerator = proc (): chronos.Duration {.gcsafe.} = + chronos.milliseconds (rand(config.minDelay..config.maxDelay)*1000).int + if config.minDelay > config.maxDelay: echo "The minimum delay should not be larger than the maximum delay" quit 1 let deposits = loadDeposits(config.depositsDir) - waitFor sendDeposits(config, deposits) + waitFor sendDeposits(config, deposits, delayGenerator) of DepositsCmd.status: # TODO diff --git a/beacon_chain/keystore_management.nim b/beacon_chain/keystore_management.nim index b0240bcf3..10a13e5c4 100644 --- a/beacon_chain/keystore_management.nim +++ b/beacon_chain/keystore_management.nim @@ -1,5 +1,5 @@ import - os, strutils, terminal, random, + os, strutils, terminal, chronicles, chronos, blscurve, nimcrypto, json_serialization, serialization, web3, stint, eth/keys, confutils, spec/[datatypes, digest, crypto, keystore], conf, ssz/merkleization, merkle_minimal @@ -193,12 +193,8 @@ proc sendDeposits*(deposits: seq[Deposit], 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 - + deposits: seq[Deposit], + delayGenerator: DelayGenerator = nil) {.async.} = info "Sending deposits", web3 = config.web3Url, depositContract = config.depositContractAddress