From 713bdd317d68b835bc21b7c359fa467a03da1d8d Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Tue, 10 Jan 2023 19:17:11 +0200 Subject: [PATCH] Bugfix: Handle networks with TTD=0 (e.g. withdrawal devnets) --- beacon_chain/eth1/eth1_monitor.nim | 7 +++- .../run-nimbus-eth2-in-withdrawal-testnet.sh | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 scripts/run-nimbus-eth2-in-withdrawal-testnet.sh diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index 75baa1cc8..1a17ec9a6 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -1458,9 +1458,12 @@ proc findTerminalBlock(provider: Web3DataProviderRef, provider.web3.provider.eth_getBlockByNumber("latest", false)) b = await next(a) + if a.number.uint64 == 0 and a.totalDifficulty >= ttd: + return a + while true: - let one = a.totalDifficulty > ttd - let two = b.totalDifficulty > ttd + let one = a.totalDifficulty >= ttd + let two = b.totalDifficulty >= ttd if one != two: step = step div -2i64 if step == 0: diff --git a/scripts/run-nimbus-eth2-in-withdrawal-testnet.sh b/scripts/run-nimbus-eth2-in-withdrawal-testnet.sh new file mode 100755 index 000000000..589ecea9e --- /dev/null +++ b/scripts/run-nimbus-eth2-in-withdrawal-testnet.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +if [ -z "$1" ]; then + echo "Usage: run-nimbus-eth2-in-withdrawal-testnet.sh " + exit 1 +fi + +if [ ! -d "$1" ]; then + echo "Please supply a valid network metadata directory" + exit 1 +fi + +set -Eeu + +NETWORK=$(cd "$1"; pwd) + +cd $(dirname "$0") + +source repo_paths.sh + +DATA_DIR="$(create_data_dir_for_network "$NETWORK")" + +JWT_TOKEN="$DATA_DIR/jwt-token" +create_jwt_token "$JWT_TOKEN" + +"$BUILD_DIR/nimbus_beacon_node" \ + --non-interactive \ + --udp-port=19000 \ + --tcp-port=19000 \ + --network="$NETWORK" \ + --log-level=DEBUG \ + --data-dir="$DATA_DIR/nimbus_bn" \ + --el=http://localhost:18550/ \ + --rest:on \ + --rest-port=15052 \ + --metrics=on \ + --metrics-port=18008 \ + --doppelganger-detection=no \ + --jwt-secret="$JWT_TOKEN"