2021-11-15 11:48:19 +00:00
#!/usr/bin/env bash
2020-01-20 22:28:48 +00:00
2022-02-07 05:12:36 +00:00
# Copyright (c) 2020-2022 Status Research & Development GmbH. Licensed under
2020-02-18 23:33:26 +00:00
# either of:
# - Apache License, version 2.0
# - MIT license
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
2020-01-20 22:28:48 +00:00
# Mostly a duplication of "tests/simulation/{start.sh,run_node.sh}", but with a focus on
2020-02-13 12:19:12 +00:00
# replicating testnets as closely as possible, which means following the Docker execution labyrinth.
2020-01-20 22:28:48 +00:00
set -e
cd " $( dirname " ${ BASH_SOURCE [0] } " ) " /..
2020-02-18 23:33:26 +00:00
####################
# argument parsing #
####################
2020-07-29 12:08:27 +00:00
GETOPT_BINARY = "getopt"
if uname | grep -qi darwin; then
# macOS
2021-11-30 18:56:22 +00:00
GETOPT_BINARY = $( find /opt/homebrew/opt/gnu-getopt/bin/getopt /usr/local/opt/gnu-getopt/bin/getopt 2> /dev/null || true )
2020-07-30 00:46:10 +00:00
[ [ -f " $GETOPT_BINARY " ] ] || { echo "GNU getopt not installed. Please run 'brew install gnu-getopt'. Aborting." ; exit 1; }
2020-07-29 12:08:27 +00:00
fi
! ${ GETOPT_BINARY } --test > /dev/null
2020-02-18 23:33:26 +00:00
if [ ${ PIPESTATUS [0] } != 4 ] ; then
2022-02-12 11:27:43 +00:00
# shellcheck disable=2016
2020-07-30 00:46:10 +00:00
echo '`getopt --test` failed in this environment.'
exit 1
2020-02-18 23:33:26 +00:00
fi
2021-02-02 18:02:52 +00:00
OPTS = "ht:n:d:g"
2022-02-12 11:27:43 +00:00
LONGOPTS = "help,preset:,nodes:,data-dir:,with-ganache,stop-at-epoch:,disable-htop,disable-vc,enable-logtrace,log-level:,base-port:,base-rest-port:,base-metrics-port:,reuse-existing-data-dir,timeout:,kill-old-processes,eth2-docker-image:"
2020-01-20 22:28:48 +00:00
2020-02-18 23:33:26 +00:00
# default values
NUM_NODES = "10"
2020-01-20 22:28:48 +00:00
DATA_DIR = "local_testnet_data"
2020-02-18 23:33:26 +00:00
USE_HTOP = "1"
2020-09-01 13:38:34 +00:00
USE_VC = "1"
2020-06-22 18:22:45 +00:00
USE_GANACHE = "0"
2021-08-13 14:12:40 +00:00
LOG_LEVEL = "DEBUG; TRACE:networking"
2020-05-14 17:34:47 +00:00
BASE_PORT = "9000"
BASE_METRICS_PORT = "8008"
2022-02-12 11:27:43 +00:00
BASE_REST_PORT = "7500"
2020-07-30 00:46:10 +00:00
REUSE_EXISTING_DATA_DIR = "0"
2020-08-16 09:12:19 +00:00
ENABLE_LOGTRACE = "0"
2020-09-01 13:38:34 +00:00
STOP_AT_EPOCH_FLAG = ""
2021-02-02 18:02:52 +00:00
TIMEOUT_DURATION = "0"
2021-07-16 10:02:27 +00:00
CONST_PRESET = "mainnet"
2021-07-27 15:57:16 +00:00
KILL_OLD_PROCESSES = "0"
2021-11-30 18:56:22 +00:00
ETH2_DOCKER_IMAGE = ""
2020-02-18 23:33:26 +00:00
print_help( ) {
2020-07-30 00:46:10 +00:00
cat <<EOF
2021-07-16 10:02:27 +00:00
Usage: $( basename " $0 " ) [ OPTIONS] -- [ BEACON NODE OPTIONS]
E.g.: $( basename " $0 " ) --nodes ${ NUM_NODES } --stop-at-epoch 5 --data-dir " ${ DATA_DIR } " # defaults
2020-09-01 13:38:34 +00:00
CI run: $( basename " $0 " ) --disable-htop -- --verify-finalization
2020-02-18 23:33:26 +00:00
2020-07-30 00:46:10 +00:00
-h, --help this help message
-n, --nodes number of nodes to launch ( default: ${ NUM_NODES } )
-g, --with-ganache simulate a genesis event based on a deposit contract
2020-09-01 13:38:34 +00:00
-s, --stop-at-epoch stop simulation at epoch ( default: infinite)
2020-07-30 00:46:10 +00:00
-d, --data-dir directory where all the node data and logs will end up
( default: " ${ DATA_DIR } " )
2021-07-16 10:02:27 +00:00
--preset Const preset to be ( default: mainnet)
2020-07-30 00:46:10 +00:00
--base-port bootstrap node' s Eth2 traffic port ( default: ${ BASE_PORT } )
2022-02-12 11:27:43 +00:00
--base-rest-port bootstrap node' s REST port ( default: ${ BASE_REST_PORT } )
2020-07-30 00:46:10 +00:00
--base-metrics-port bootstrap node' s metrics server port ( default: ${ BASE_METRICS_PORT } )
2020-11-07 18:00:31 +00:00
--disable-htop don' t use "htop" to see the nimbus_beacon_node processes
2020-09-01 13:38:34 +00:00
--disable-vc don' t use validator client binaries for validators ( by default validators are split 50/50 between beacon nodes and validator clients)
2021-08-06 21:25:30 +00:00
--enable-logtrace display logtrace aggasr analysis
2020-07-30 00:46:10 +00:00
--log-level set the log level ( default: ${ LOG_LEVEL } )
--reuse-existing-data-dir instead of deleting and recreating the data dir, keep it and reuse everything we can from it
2021-02-02 18:02:52 +00:00
--timeout timeout in seconds ( default: ${ TIMEOUT_DURATION } - no timeout)
2021-07-27 15:57:16 +00:00
--kill-old-processes if any process is found listening on a port we use, kill it ( default: disabled)
2021-11-30 18:56:22 +00:00
--eth2-docker-image use docker image instead of compiling the beacon node
2020-02-18 23:33:26 +00:00
EOF
}
2020-07-29 12:08:27 +00:00
! PARSED = $( ${ GETOPT_BINARY } --options= ${ OPTS } --longoptions= ${ LONGOPTS } --name " $0 " -- " $@ " )
2020-02-18 23:33:26 +00:00
if [ ${ PIPESTATUS [0] } != 0 ] ; then
2020-07-30 00:46:10 +00:00
# getopt has complained about wrong arguments to stdout
exit 1
2020-02-18 23:33:26 +00:00
fi
# read getopt's output this way to handle the quoting right
eval set -- " $PARSED "
while true; do
2020-07-30 00:46:10 +00:00
case " $1 " in
-h| --help)
print_help
exit
; ;
-n| --nodes)
NUM_NODES = " $2 "
shift 2
; ;
-d| --data-dir)
DATA_DIR = " $2 "
shift 2
; ;
2021-02-02 18:02:52 +00:00
-g| --with-ganache)
USE_GANACHE = "1"
shift
; ;
2021-07-16 10:02:27 +00:00
--preset)
CONST_PRESET = " $2 "
shift 2
; ;
2021-02-02 18:02:52 +00:00
--stop-at-epoch)
STOP_AT_EPOCH_FLAG = " --stop-at-epoch= $2 "
shift 2
; ;
2020-07-30 00:46:10 +00:00
--disable-htop)
USE_HTOP = "0"
shift
; ;
2020-09-01 13:38:34 +00:00
--disable-vc)
USE_VC = "0"
shift
; ;
2021-02-02 18:02:52 +00:00
--enable-logtrace)
ENABLE_LOGTRACE = "1"
2020-07-30 00:46:10 +00:00
shift
; ;
--log-level)
LOG_LEVEL = " $2 "
shift 2
; ;
--base-port)
BASE_PORT = " $2 "
shift 2
; ;
2022-02-12 11:27:43 +00:00
--base-rest-port)
BASE_REST_PORT = " $2 "
2020-09-01 13:38:34 +00:00
shift 2
; ;
2020-07-30 00:46:10 +00:00
--base-metrics-port)
BASE_METRICS_PORT = " $2 "
shift 2
; ;
--reuse-existing-data-dir)
REUSE_EXISTING_DATA_DIR = "1"
shift
; ;
2021-02-02 18:02:52 +00:00
--timeout)
TIMEOUT_DURATION = " $2 "
shift 2
2020-08-16 09:12:19 +00:00
; ;
2021-07-27 15:57:16 +00:00
--kill-old-processes)
KILL_OLD_PROCESSES = "1"
shift
; ;
2021-11-30 18:56:22 +00:00
--eth2-docker-image)
ETH2_DOCKER_IMAGE = " $2 "
shift 2
# TODO The validator client is still not being shipped with
# our docker images, so we must disable it:
echo "warning: --eth-docker-image implies --disable-vc"
USE_VC = "0"
; ;
2020-07-30 00:46:10 +00:00
--)
shift
break
; ;
*)
echo "argument parsing error"
print_help
exit 1
esac
2020-02-18 23:33:26 +00:00
done
2020-02-26 00:14:20 +00:00
# when sourcing env.sh, it will try to execute $@, so empty it
EXTRA_ARGS = " $@ "
if [ [ $# != 0 ] ] ; then
2020-07-30 00:46:10 +00:00
shift $#
2020-02-26 00:14:20 +00:00
fi
2020-02-18 23:33:26 +00:00
2020-07-30 00:46:10 +00:00
if [ [ " $REUSE_EXISTING_DATA_DIR " = = "0" ] ] ; then
rm -rf " ${ DATA_DIR } "
fi
2020-06-01 19:48:20 +00:00
2021-07-13 11:15:07 +00:00
scripts/makedir.sh " ${ DATA_DIR } "
2020-08-25 13:16:45 +00:00
2020-07-27 19:26:30 +00:00
VALIDATORS_DIR = " ${ DATA_DIR } /validators "
2021-07-13 11:15:07 +00:00
scripts/makedir.sh " ${ VALIDATORS_DIR } "
2020-06-01 19:48:20 +00:00
SECRETS_DIR = " ${ DATA_DIR } /secrets "
2021-07-13 11:15:07 +00:00
scripts/makedir.sh " ${ SECRETS_DIR } "
2020-06-01 19:48:20 +00:00
2021-07-16 10:02:27 +00:00
USER_VALIDATORS = 8
TOTAL_VALIDATORS = 128
2021-08-05 08:49:34 +00:00
HAVE_LSOF = 0
2020-01-20 22:28:48 +00:00
2020-02-18 23:33:26 +00:00
# Windows detection
if uname | grep -qiE "mingw|msys" ; then
2020-07-30 00:46:10 +00:00
MAKE = "mingw32-make"
2020-02-18 23:33:26 +00:00
else
2020-07-30 00:46:10 +00:00
MAKE = "make"
2021-08-05 08:49:34 +00:00
which lsof & >/dev/null && HAVE_LSOF = 1 || { echo "'lsof' not installed and we need it to check for ports already in use. Aborting." ; exit 1; }
2020-02-18 23:33:26 +00:00
fi
2021-02-11 18:28:37 +00:00
# number of CPU cores
if uname | grep -qi darwin; then
NPROC = " $( sysctl -n hw.logicalcpu) "
else
NPROC = " $( nproc) "
fi
2021-07-27 15:57:16 +00:00
# kill lingering processes from a previous run
2021-08-05 08:49:34 +00:00
if [ [ " ${ HAVE_LSOF } " = = "1" ] ] ; then
for NUM_NODE in $( seq 0 $(( NUM_NODES - 1 )) ) ; do
2022-02-12 11:27:43 +00:00
for PORT in $(( BASE_PORT + NUM_NODE )) $(( BASE_METRICS_PORT + NUM_NODE )) $(( BASE_REST_PORT + NUM_NODE )) ; do
2021-08-05 08:49:34 +00:00
for PID in $( lsof -n -i tcp:${ PORT } -sTCP:LISTEN -t) ; do
echo -n " Found old process listening on port ${ PORT } , with PID ${ PID } . "
if [ [ " ${ KILL_OLD_PROCESSES } " = = "1" ] ] ; then
echo "Killing it."
kill -9 ${ PID } || true
else
echo "Aborting."
exit 1
fi
done
2021-07-27 15:57:16 +00:00
done
done
2021-08-05 08:49:34 +00:00
fi
2021-07-27 15:57:16 +00:00
2020-11-27 01:29:06 +00:00
# Build the binaries
2021-11-30 18:56:22 +00:00
BINARIES = "nimbus_validator_client deposit_contract"
2020-08-16 09:12:19 +00:00
if [ [ " $ENABLE_LOGTRACE " = = "1" ] ] ; then
2020-11-27 01:29:06 +00:00
BINARIES = " ${ BINARIES } logtrace "
2020-08-16 09:12:19 +00:00
fi
2021-07-16 10:02:27 +00:00
2022-02-12 11:27:43 +00:00
if [ [ -n " $ETH2_DOCKER_IMAGE " ] ] ; then
2021-11-30 18:56:22 +00:00
DATA_DIR_FULL_PATH = $( cd " ${ DATA_DIR } " ; pwd )
# CONTAINER_DATA_DIR must be used everywhere where paths are supplied to BEACON_NODE_COMMAND executions.
# We'll use the CONTAINER_ prefix throughout the file to indicate such paths.
CONTAINER_DATA_DIR = /home/user/nimbus-eth2/testnet
BEACON_NODE_COMMAND = " docker run -v /etc/passwd:/etc/passwd -u $( id -u) : $( id -g) --net=host -v ${ DATA_DIR_FULL_PATH } : ${ CONTAINER_DATA_DIR } :rw $ETH2_DOCKER_IMAGE "
else
# When docker is not used CONTAINER_DATA_DIR is just an alias for DATA_DIR
CONTAINER_DATA_DIR = $DATA_DIR
BEACON_NODE_COMMAND = "./build/nimbus_beacon_node"
BINARIES = " ${ BINARIES } nimbus_beacon_node "
fi
2021-11-02 17:06:36 +00:00
$MAKE -j ${ NPROC } LOG_LEVEL = TRACE NIMFLAGS = " ${ NIMFLAGS } -d:local_testnet -d:const_preset= ${ CONST_PRESET } " ${ BINARIES }
2020-01-20 22:28:48 +00:00
2021-08-03 10:12:21 +00:00
# Kill child processes on Ctrl-C/SIGTERM/exit, passing the PID of this shell
# instance as the parent and the target process name as a pattern to the
# "pkill" command.
cleanup( ) {
pkill -f -P $$ nimbus_beacon_node & >/dev/null || true
pkill -f -P $$ nimbus_validator_client & >/dev/null || true
sleep 2
pkill -f -9 -P $$ nimbus_beacon_node & >/dev/null || true
pkill -f -9 -P $$ nimbus_validator_client & >/dev/null || true
# Delete the binaries we just built, because these are unusable outside this
# local testnet.
for BINARY in ${ BINARIES } ; do
rm build/${ BINARY }
done
2021-11-30 18:56:22 +00:00
2022-02-12 11:27:43 +00:00
if [ [ -n " $ETH2_DOCKER_IMAGE " ] ] ; then
2021-11-30 18:56:22 +00:00
docker rm $( docker stop $( docker ps -a -q --filter ancestor = $ETH2_DOCKER_IMAGE --format= "{{.ID}}" ) )
fi
2021-08-03 10:12:21 +00:00
}
trap 'cleanup' SIGINT SIGTERM EXIT
# timeout - implemented with a background job
timeout_reached( ) {
echo -e "\nTimeout reached. Aborting.\n"
cleanup
}
trap 'timeout_reached' SIGALRM
if [ [ " ${ TIMEOUT_DURATION } " != "0" ] ] ; then
export PARENT_PID = $$
( sleep ${ TIMEOUT_DURATION } && kill -ALRM ${ PARENT_PID } ) 2>/dev/null & WATCHER_PID = $!
fi
# deposit and testnet creation
2020-06-22 18:22:45 +00:00
PIDS = ""
WEB3_ARG = ""
2020-07-23 20:51:56 +00:00
BOOTSTRAP_TIMEOUT = 30 # in seconds
2020-07-09 22:08:54 +00:00
DEPOSIT_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000000"
DEPOSIT_CONTRACT_BLOCK = "0x0000000000000000000000000000000000000000000000000000000000000000"
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
RUNTIME_CONFIG_FILE = " ${ DATA_DIR } /config.yaml "
2020-09-01 13:38:34 +00:00
NUM_JOBS = ${ NUM_NODES }
2020-06-22 18:22:45 +00:00
2021-11-30 18:56:22 +00:00
DEPOSITS_FILE = " ${ DATA_DIR } /deposits.json "
CONTAINER_DEPOSITS_FILE = " ${ CONTAINER_DATA_DIR } /deposits.json "
2020-07-30 00:46:10 +00:00
if [ [ " $REUSE_EXISTING_DATA_DIR " = = "0" ] ] ; then
./build/deposit_contract generateSimulationDeposits \
--count= ${ TOTAL_VALIDATORS } \
--out-validators-dir= " ${ VALIDATORS_DIR } " \
--out-secrets-dir= " ${ SECRETS_DIR } " \
--out-deposits-file= " ${ DEPOSITS_FILE } "
fi
2020-01-20 22:28:48 +00:00
2020-06-22 18:22:45 +00:00
if [ [ $USE_GANACHE = = "0" ] ] ; then
2020-07-30 00:46:10 +00:00
GENESIS_OFFSET = 30
BOOTSTRAP_IP = "127.0.0.1"
2021-11-30 18:56:22 +00:00
$BEACON_NODE_COMMAND createTestnet \
--data-dir= " ${ CONTAINER_DATA_DIR } " \
--deposits-file= " ${ CONTAINER_DEPOSITS_FILE } " \
2020-07-30 00:46:10 +00:00
--total-validators= ${ TOTAL_VALIDATORS } \
2021-11-30 18:56:22 +00:00
--output-genesis= " ${ CONTAINER_DATA_DIR } /genesis.ssz " \
--output-bootstrap-file= " ${ CONTAINER_DATA_DIR } /bootstrap_nodes.txt " \
2020-07-30 00:46:10 +00:00
--bootstrap-address= ${ BOOTSTRAP_IP } \
--bootstrap-port= ${ BASE_PORT } \
2020-08-25 12:49:05 +00:00
--netkey-file= network_key.json \
--insecure-netkey-password= true \
2020-07-30 00:46:10 +00:00
--genesis-offset= ${ GENESIS_OFFSET } # Delay in seconds
2020-06-22 18:22:45 +00:00
else
2020-07-30 00:46:10 +00:00
echo "Launching ganache"
ganache-cli --blockTime 17 --gasLimit 100000000 -e 100000 --verbose > " ${ DATA_DIR } /log_ganache.txt " 2>& 1 &
PIDS = " ${ PIDS } , $! "
2020-06-22 18:22:45 +00:00
2020-07-30 00:46:10 +00:00
WEB3_ARG = "--web3-url=ws://localhost:8545"
2020-07-09 22:08:54 +00:00
2020-07-30 00:46:10 +00:00
echo "Deploying deposit contract"
DEPLOY_CMD_OUTPUT = $( ./build/deposit_contract deploy $WEB3_ARG )
# https://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash
OUTPUT_PIECES = ( ${ DEPLOY_CMD_OUTPUT //;/ } )
DEPOSIT_CONTRACT_ADDRESS = ${ OUTPUT_PIECES [0] }
DEPOSIT_CONTRACT_BLOCK = ${ OUTPUT_PIECES [1] }
2020-07-09 22:08:54 +00:00
2020-08-17 06:36:29 +00:00
echo Contract deployed at " $DEPOSIT_CONTRACT_ADDRESS " :" $DEPOSIT_CONTRACT_BLOCK "
2020-06-11 13:31:35 +00:00
2020-07-30 00:46:10 +00:00
MIN_DELAY = 1
MAX_DELAY = 5
2020-06-22 18:22:45 +00:00
2020-07-30 00:46:10 +00:00
BOOTSTRAP_TIMEOUT = $(( MAX_DELAY * TOTAL_VALIDATORS ))
2020-06-22 18:22:45 +00:00
2020-07-30 00:46:10 +00:00
./build/deposit_contract sendDeposits \
--deposits-file= " ${ DEPOSITS_FILE } " \
--min-delay= $MIN_DELAY --max-delay= $MAX_DELAY \
$WEB3_ARG \
--deposit-contract= ${ DEPOSIT_CONTRACT_ADDRESS } > " ${ DATA_DIR } /log_deposit_maker.txt " 2>& 1 &
2020-06-22 18:22:45 +00:00
2020-07-30 00:46:10 +00:00
PIDS = " ${ PIDS } , $! "
2020-06-22 18:22:45 +00:00
fi
2020-01-20 22:28:48 +00:00
2020-06-10 15:21:32 +00:00
./scripts/make_prometheus_config.sh \
2020-07-30 00:46:10 +00:00
--nodes ${ NUM_NODES } \
--base-metrics-port ${ BASE_METRICS_PORT } \
--config-file " ${ DATA_DIR } /prometheus.yml " || true # TODO: this currently fails on macOS,
# but it can be considered non-critical
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
echo Wrote $RUNTIME_CONFIG_FILE :
2021-08-10 20:46:35 +00:00
# TODO the runtime config file should be used during deposit generation as well!
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
tee " $RUNTIME_CONFIG_FILE " <<EOF
2021-07-16 10:02:27 +00:00
PRESET_BASE: ${ CONST_PRESET }
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: ${ TOTAL_VALIDATORS }
MIN_GENESIS_TIME: 0
GENESIS_DELAY: 10
DEPOSIT_CONTRACT_ADDRESS: ${ DEPOSIT_CONTRACT_ADDRESS }
ETH1_FOLLOW_DISTANCE: 1
2022-01-26 12:21:29 +00:00
ALTAIR_FORK_EPOCH: 1
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
EOF
2020-05-01 22:09:04 +00:00
dump_logs( ) {
2020-07-30 00:46:10 +00:00
LOG_LINES = 20
for LOG in " ${ DATA_DIR } " /log*.txt; do
echo " Last ${ LOG_LINES } lines of ${ LOG } : "
tail -n ${ LOG_LINES } " ${ LOG } "
echo "======"
done
2020-05-01 22:09:04 +00:00
}
2020-08-16 09:12:19 +00:00
dump_logtrace( ) {
if [ [ " $ENABLE_LOGTRACE " = = "1" ] ] ; then
2021-08-06 21:25:30 +00:00
find " ${ DATA_DIR } " -maxdepth 1 -type f -regex '.*/log[0-9]+.txt' | sed -e" s/ ${ DATA_DIR } \//--nodes=/ " | sort | xargs ./build/logtrace aggasr --log-dir= " ${ DATA_DIR } " || true
2020-08-16 09:12:19 +00:00
fi
}
2020-02-21 13:19:34 +00:00
NODES_WITH_VALIDATORS = ${ NODES_WITH_VALIDATORS :- 4 }
2020-07-16 17:04:57 +00:00
BOOTSTRAP_NODE = 0
2020-06-03 11:40:14 +00:00
SYSTEM_VALIDATORS = $(( TOTAL_VALIDATORS - USER_VALIDATORS ))
VALIDATORS_PER_NODE = $(( SYSTEM_VALIDATORS / NODES_WITH_VALIDATORS ))
2020-09-01 13:38:34 +00:00
if [ " ${ USE_VC :- } " = = "1" ] ; then
# if using validator client binaries in addition to beacon nodes we will
# split the keys for this instance in half between the BN and the VC
# and the validators for the BNs will be from the first half of all validators
VALIDATORS_PER_NODE = $(( VALIDATORS_PER_NODE / 2 ))
NUM_JOBS = $(( NUM_JOBS * 2 ))
fi
VALIDATORS_PER_VALIDATOR = $(( ( SYSTEM_VALIDATORS / NODES_WITH_VALIDATORS) / 2 ))
VALIDATOR_OFFSET = $(( SYSTEM_VALIDATORS / 2 ))
2021-11-30 18:56:22 +00:00
2020-07-30 00:46:10 +00:00
BOOTSTRAP_ENR = " ${ DATA_DIR } /node ${ BOOTSTRAP_NODE } /beacon_node.enr "
2021-11-30 18:56:22 +00:00
CONTAINER_BOOTSTRAP_ENR = " ${ CONTAINER_DATA_DIR } /node ${ BOOTSTRAP_NODE } /beacon_node.enr "
CONTAINER_NETWORK_KEYFILE = "network_key.json"
2020-02-21 13:19:34 +00:00
2020-07-16 17:04:57 +00:00
for NUM_NODE in $( seq 0 $(( NUM_NODES - 1 )) ) ; do
2021-07-13 11:15:07 +00:00
# Copy validators to individual nodes.
# The first $NODES_WITH_VALIDATORS nodes split them equally between them,
# after skipping the first $USER_VALIDATORS.
NODE_DATA_DIR = " ${ DATA_DIR } /node ${ NUM_NODE } "
rm -rf " ${ NODE_DATA_DIR } "
scripts/makedir.sh " ${ NODE_DATA_DIR } " 2>& 1
scripts/makedir.sh " ${ NODE_DATA_DIR } /validators " 2>& 1
scripts/makedir.sh " ${ NODE_DATA_DIR } /secrets " 2>& 1
if [ [ $NUM_NODE -lt $NODES_WITH_VALIDATORS ] ] ; then
if [ " ${ USE_VC :- } " = = "1" ] ; then
VALIDATOR_DATA_DIR = " ${ DATA_DIR } /validator ${ NUM_NODE } "
rm -rf " ${ VALIDATOR_DATA_DIR } "
scripts/makedir.sh " ${ VALIDATOR_DATA_DIR } " 2>& 1
scripts/makedir.sh " ${ VALIDATOR_DATA_DIR } /validators " 2>& 1
scripts/makedir.sh " ${ VALIDATOR_DATA_DIR } /secrets " 2>& 1
for VALIDATOR in $( ls " ${ VALIDATORS_DIR } " | tail -n +$(( $USER_VALIDATORS + ( $VALIDATORS_PER_VALIDATOR * $NUM_NODE ) + 1 + $VALIDATOR_OFFSET )) | head -n $VALIDATORS_PER_VALIDATOR ) ; do
cp -a " ${ VALIDATORS_DIR } / ${ VALIDATOR } " " ${ VALIDATOR_DATA_DIR } /validators/ " 2>& 1
cp -a " ${ SECRETS_DIR } / ${ VALIDATOR } " " ${ VALIDATOR_DATA_DIR } /secrets/ " 2>& 1
done
if [ [ $OS = "Windows_NT" ] ] ; then
find " ${ VALIDATOR_DATA_DIR } " -type f \( -iname "*.json" -o ! -iname "*.*" \) -exec icacls "{}" /inheritance:r /grant:r ${ USERDOMAIN } \\ ${ USERNAME } :\( F\) \;
fi
fi
for VALIDATOR in $( ls " ${ VALIDATORS_DIR } " | tail -n +$(( $USER_VALIDATORS + ( $VALIDATORS_PER_NODE * $NUM_NODE ) + 1 )) | head -n $VALIDATORS_PER_NODE ) ; do
cp -a " ${ VALIDATORS_DIR } / ${ VALIDATOR } " " ${ NODE_DATA_DIR } /validators/ " 2>& 1
cp -a " ${ SECRETS_DIR } / ${ VALIDATOR } " " ${ NODE_DATA_DIR } /secrets/ " 2>& 1
done
if [ [ $OS = "Windows_NT" ] ] ; then
find " ${ NODE_DATA_DIR } " -type f \( -iname "*.json" -o ! -iname "*.*" \) -exec icacls "{}" /inheritance:r /grant:r ${ USERDOMAIN } \\ ${ USERNAME } :\( F\) \;
fi
fi
done
for NUM_NODE in $( seq 0 $(( NUM_NODES - 1 )) ) ; do
NODE_DATA_DIR = " ${ DATA_DIR } /node ${ NUM_NODE } "
2021-11-30 18:56:22 +00:00
CONTAINER_NODE_DATA_DIR = " ${ CONTAINER_DATA_DIR } /node ${ NUM_NODE } "
2021-07-13 11:15:07 +00:00
VALIDATOR_DATA_DIR = " ${ DATA_DIR } /validator ${ NUM_NODE } "
2020-07-30 00:46:10 +00:00
if [ [ ${ NUM_NODE } = = ${ BOOTSTRAP_NODE } ] ] ; then
2021-07-26 17:34:13 +00:00
# Due to star topology, the bootstrap node must relay all attestations,
# even if it itself is not interested. --subscribe-all-subnets could be
# removed by switching to a fully-connected topology.
2021-11-30 18:56:22 +00:00
BOOTSTRAP_ARG = " --netkey-file= ${ CONTAINER_NETWORK_KEYFILE } --insecure-netkey-password=true --subscribe-all-subnets "
2020-07-30 00:46:10 +00:00
else
2021-11-30 18:56:22 +00:00
BOOTSTRAP_ARG = " --bootstrap-file= ${ CONTAINER_BOOTSTRAP_ENR } "
2021-08-20 14:41:16 +00:00
if [ [ " ${ CONST_PRESET } " = = "minimal" ] ] ; then
# The fast epoch and slot times in the minimal config might cause the
# mesh to break down due to re-subscriptions happening within the prune
# backoff time
BOOTSTRAP_ARG = " ${ BOOTSTRAP_ARG } --subscribe-all-subnets "
fi
2020-07-30 00:46:10 +00:00
# Wait for the master node to write out its address file
START_TIMESTAMP = $( date +%s)
while [ [ ! -f " ${ BOOTSTRAP_ENR } " ] ] ; do
sleep 0.1
NOW_TIMESTAMP = $( date +%s)
if [ [ " $(( NOW_TIMESTAMP - START_TIMESTAMP - GENESIS_OFFSET )) " -ge " $BOOTSTRAP_TIMEOUT " ] ] ; then
echo " Bootstrap node failed to start in ${ BOOTSTRAP_TIMEOUT } seconds. Aborting. "
dump_logs
exit 1
fi
done
fi
2021-11-30 18:56:22 +00:00
$BEACON_NODE_COMMAND \
2020-07-30 00:46:10 +00:00
--non-interactive \
--nat:extip:127.0.0.1 \
2021-11-30 18:56:22 +00:00
--network= " ${ CONTAINER_DATA_DIR } " \
2020-07-30 00:46:10 +00:00
--log-level= " ${ LOG_LEVEL } " \
2021-11-10 09:02:18 +00:00
--log-format= json \
2020-07-30 00:46:10 +00:00
--tcp-port= $(( BASE_PORT + NUM_NODE )) \
--udp-port= $(( BASE_PORT + NUM_NODE )) \
2021-01-29 07:56:02 +00:00
--max-peers= $(( NUM_NODES - 1 )) \
2021-11-30 18:56:22 +00:00
--data-dir= " ${ CONTAINER_NODE_DATA_DIR } " \
2020-07-30 00:46:10 +00:00
${ BOOTSTRAP_ARG } \
${ WEB3_ARG } \
2020-09-01 13:38:34 +00:00
${ STOP_AT_EPOCH_FLAG } \
2021-07-13 11:15:07 +00:00
--rest \
--rest-address= "127.0.0.1" \
2022-02-12 11:27:43 +00:00
--rest-port= " $(( BASE_REST_PORT + NUM_NODE )) " \
2020-07-30 00:46:10 +00:00
--metrics \
--metrics-address= "127.0.0.1" \
--metrics-port= " $(( BASE_METRICS_PORT + NUM_NODE )) " \
${ EXTRA_ARGS } \
> " ${ DATA_DIR } /log ${ NUM_NODE } .txt " 2>& 1 &
if [ [ " ${ PIDS } " = = "" ] ] ; then
PIDS = " $! "
else
PIDS = " ${ PIDS } , $! "
fi
2020-09-01 13:38:34 +00:00
if [ " ${ USE_VC :- } " = = "1" ] ; then
2020-11-07 18:00:31 +00:00
./build/nimbus_validator_client \
2020-09-01 13:38:34 +00:00
--log-level= " ${ LOG_LEVEL } " \
${ STOP_AT_EPOCH_FLAG } \
--data-dir= " ${ VALIDATOR_DATA_DIR } " \
2022-02-12 11:27:43 +00:00
--beacon-node= " http://127.0.0.1: $(( BASE_REST_PORT + NUM_NODE)) " \
2021-02-02 18:02:52 +00:00
> " ${ DATA_DIR } /log_val ${ NUM_NODE } .txt " 2>& 1 &
2020-09-01 13:38:34 +00:00
fi
2020-01-20 22:28:48 +00:00
done
2020-05-01 18:57:12 +00:00
# give the regular nodes time to crash
sleep 5
2020-07-29 12:08:27 +00:00
BG_JOBS = " $( jobs | wc -l | tr -d ' ' ) "
2021-08-03 10:12:21 +00:00
if [ [ " ${ TIMEOUT_DURATION } " != "0" ] ] ; then
BG_JOBS = $(( BG_JOBS - 1 )) # minus the timeout bg job
fi
2020-09-01 13:38:34 +00:00
if [ [ " $BG_JOBS " != " $NUM_JOBS " ] ] ; then
2020-11-07 18:00:31 +00:00
echo " $(( NUM_JOBS - BG_JOBS )) nimbus_beacon_node/nimbus_validator_client instance(s) exited early. Aborting. "
2020-07-30 00:46:10 +00:00
dump_logs
2020-08-16 09:12:19 +00:00
dump_logtrace
2020-07-30 00:46:10 +00:00
exit 1
2020-05-01 18:57:12 +00:00
fi
2021-02-02 18:02:52 +00:00
# launch htop or wait for background jobs
2020-02-18 23:33:26 +00:00
if [ [ " $USE_HTOP " = = "1" ] ] ; then
2020-07-30 00:46:10 +00:00
htop -p " $PIDS "
cleanup
2020-02-18 23:33:26 +00:00
else
2020-07-30 00:46:10 +00:00
FAILED = 0
for PID in $( echo " $PIDS " | tr ',' ' ' ) ; do
2020-08-17 06:36:29 +00:00
wait " $PID " || FAILED = " $(( FAILED += 1 )) "
2020-07-30 00:46:10 +00:00
done
if [ [ " $FAILED " != "0" ] ] ; then
echo " ${ FAILED } child processes had non-zero exit codes (or exited early). "
dump_logs
2020-08-16 09:12:19 +00:00
dump_logtrace
2021-02-02 18:02:52 +00:00
if [ [ " ${ TIMEOUT_DURATION } " != "0" ] ] ; then
2021-07-13 11:15:07 +00:00
if uname | grep -qiE "mingw|msys" ; then
taskkill //F //PID ${ WATCHER_PID }
else
pkill -HUP -P ${ WATCHER_PID }
fi
2021-02-02 18:02:52 +00:00
fi
2020-07-30 00:46:10 +00:00
exit 1
fi
2020-02-18 23:33:26 +00:00
fi
2020-08-16 09:12:19 +00:00
dump_logtrace
2021-02-02 18:02:52 +00:00
if [ [ " ${ TIMEOUT_DURATION } " != "0" ] ] ; then
2021-07-13 11:15:07 +00:00
if uname | grep -qiE "mingw|msys" ; then
taskkill //F //PID ${ WATCHER_PID }
else
pkill -HUP -P ${ WATCHER_PID }
fi
2021-02-02 18:02:52 +00:00
fi