mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Replace local testnet script with Kurtosis (#5865)
* Kurtosis local testnet.
* Remove unused `lcli` subcommands
* Migrate doppelganger_protection test to kurtosis and further cleanup.
* Fix lint
* Add missing download image step and remove unused `lcli` dependencies.
* doppelganger success case working
* Run tests on hosted runner and improve error handling.
* Start the dp vc only after epoch 1
* Add more logging to test results.
* Fix exit code and speed up docker build.
* Fix incorrect exit codes and split doppelganger tests on CI.
* Missing the escape for double quotes 😫
* Remove unnecessary vc params in kurtosis config.
This commit is contained in:
@@ -1,147 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
# Start all processes necessary to create a local testnet
|
||||
|
||||
# Requires `docker`, `kurtosis`, `yq`
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
source ./vars.env
|
||||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
ENCLAVE_NAME=local-testnet
|
||||
NETWORK_PARAMS_FILE=$SCRIPT_DIR/network_params.yaml
|
||||
|
||||
# Set a higher ulimit in case we want to import 1000s of validators.
|
||||
ulimit -n 65536
|
||||
|
||||
# VC_COUNT is defaulted in vars.env
|
||||
DEBUG_LEVEL=${DEBUG_LEVEL:-info}
|
||||
BUILDER_PROPOSALS=
|
||||
BUILD_IMAGE=true
|
||||
BUILDER_PROPOSALS=false
|
||||
CI=false
|
||||
|
||||
# Get options
|
||||
while getopts "v:d:ph" flag; do
|
||||
while getopts "e:b:n:phc" flag; do
|
||||
case "${flag}" in
|
||||
v) VC_COUNT=${OPTARG};;
|
||||
d) DEBUG_LEVEL=${OPTARG};;
|
||||
p) BUILDER_PROPOSALS="-p";;
|
||||
e) ENCLAVE_NAME=${OPTARG};;
|
||||
b) BUILD_IMAGE=${OPTARG};;
|
||||
n) NETWORK_PARAMS_FILE=${OPTARG};;
|
||||
p) BUILDER_PROPOSALS=true;;
|
||||
c) CI=true;;
|
||||
h)
|
||||
validators=$(( $VALIDATOR_COUNT / $BN_COUNT ))
|
||||
echo "Start local testnet, defaults: 1 eth1 node, $BN_COUNT beacon nodes,"
|
||||
echo "and $VC_COUNT validator clients with each vc having $validators validators."
|
||||
echo "Start a local testnet with kurtosis."
|
||||
echo
|
||||
echo "usage: $0 <Options>"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -v: VC_COUNT default: $VC_COUNT"
|
||||
echo " -d: DEBUG_LEVEL default: info"
|
||||
echo " -p: enable builder proposals"
|
||||
echo " -h: this help"
|
||||
echo " -e: enclave name default: $ENCLAVE_NAME"
|
||||
echo " -b: whether to build Lighthouse docker image default: $BUILD_IMAGE"
|
||||
echo " -n: kurtosis network params file path default: $NETWORK_PARAMS_FILE"
|
||||
echo " -p: enable builder proposals"
|
||||
echo " -c: CI mode, run without other additional services like Grafana and Dora explorer"
|
||||
echo " -h: this help"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if (( $VC_COUNT > $BN_COUNT )); then
|
||||
echo "Error $VC_COUNT is too large, must be <= BN_COUNT=$BN_COUNT"
|
||||
LH_IMAGE_NAME=$(yq eval ".participants[0].cl_image" $NETWORK_PARAMS_FILE)
|
||||
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Docker is not installed. Please install Docker and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v kurtosis &> /dev/null; then
|
||||
echo "kurtosis command not found. Please install kurtosis and try again."
|
||||
exit
|
||||
fi
|
||||
|
||||
genesis_file=${@:$OPTIND+0:1}
|
||||
if ! command -v yq &> /dev/null; then
|
||||
echo "yq not found. Please install yq and try again."
|
||||
fi
|
||||
|
||||
# Init some constants
|
||||
PID_FILE=$TESTNET_DIR/PIDS.pid
|
||||
LOG_DIR=$TESTNET_DIR
|
||||
if [ "$BUILDER_PROPOSALS" = true ]; then
|
||||
yq eval '.participants[0].vc_extra_params = ["--builder-proposals"]' -i $NETWORK_PARAMS_FILE
|
||||
echo "--builder-proposals VC flag added to network_params.yaml"
|
||||
fi
|
||||
|
||||
# Stop local testnet and remove $PID_FILE
|
||||
./stop_local_testnet.sh
|
||||
if [ "$CI" = true ]; then
|
||||
# TODO: run assertoor tests
|
||||
yq eval '.additional_services = []' -i $NETWORK_PARAMS_FILE
|
||||
echo "Running without additional services (CI mode)."
|
||||
else
|
||||
yq eval '.additional_services = ["dora", "prometheus_grafana"]' -i $NETWORK_PARAMS_FILE
|
||||
echo "Additional services dora and prometheus_grafana added to network_params.yaml"
|
||||
fi
|
||||
|
||||
# Clean $DATADIR and create empty log files so the
|
||||
# user can "tail -f" right after starting this script
|
||||
# even before its done.
|
||||
./clean.sh
|
||||
mkdir -p $LOG_DIR
|
||||
for (( bn=1; bn<=$BN_COUNT; bn++ )); do
|
||||
touch $LOG_DIR/beacon_node_$bn.log
|
||||
done
|
||||
for (( el=1; el<=$BN_COUNT; el++ )); do
|
||||
touch $LOG_DIR/geth_$el.log
|
||||
done
|
||||
for (( vc=1; vc<=$VC_COUNT; vc++ )); do
|
||||
touch $LOG_DIR/validator_node_$vc.log
|
||||
done
|
||||
if [ "$BUILD_IMAGE" = true ]; then
|
||||
echo "Building Lighthouse Docker image."
|
||||
ROOT_DIR="$SCRIPT_DIR/../.."
|
||||
docker build --build-arg FEATURES=portable -f $ROOT_DIR/Dockerfile -t $LH_IMAGE_NAME $ROOT_DIR
|
||||
else
|
||||
echo "Not rebuilding Lighthouse Docker image."
|
||||
fi
|
||||
|
||||
# Sleep with a message
|
||||
sleeping() {
|
||||
echo sleeping $1
|
||||
sleep $1
|
||||
}
|
||||
# Stop local testnet
|
||||
kurtosis enclave rm -f $ENCLAVE_NAME 2>/dev/null || true
|
||||
|
||||
# Execute the command with logs saved to a file.
|
||||
#
|
||||
# First parameter is log file name
|
||||
# Second parameter is executable name
|
||||
# Remaining parameters are passed to executable
|
||||
execute_command() {
|
||||
LOG_NAME=$1
|
||||
EX_NAME=$2
|
||||
shift
|
||||
shift
|
||||
CMD="$EX_NAME $@ >> $LOG_DIR/$LOG_NAME 2>&1"
|
||||
echo "executing: $CMD"
|
||||
echo "$CMD" > "$LOG_DIR/$LOG_NAME"
|
||||
eval "$CMD &"
|
||||
}
|
||||
|
||||
# Execute the command with logs saved to a file
|
||||
# and is PID is saved to $PID_FILE.
|
||||
#
|
||||
# First parameter is log file name
|
||||
# Second parameter is executable name
|
||||
# Remaining parameters are passed to executable
|
||||
execute_command_add_PID() {
|
||||
execute_command $@
|
||||
echo "$!" >> $PID_FILE
|
||||
}
|
||||
|
||||
|
||||
# Setup data
|
||||
echo "executing: ./setup.sh >> $LOG_DIR/setup.log"
|
||||
./setup.sh >> $LOG_DIR/setup.log 2>&1
|
||||
|
||||
# Call setup_time.sh to update future hardforks time in the EL genesis file based on the CL genesis time
|
||||
./setup_time.sh $genesis_file
|
||||
|
||||
# Delay to let boot_enr.yaml to be created
|
||||
execute_command_add_PID bootnode.log ./bootnode.sh
|
||||
sleeping 3
|
||||
|
||||
execute_command_add_PID el_bootnode.log ./el_bootnode.sh
|
||||
sleeping 3
|
||||
|
||||
# Start beacon nodes
|
||||
BN_udp_tcp_base=9000
|
||||
BN_http_port_base=8000
|
||||
|
||||
EL_base_network=7000
|
||||
EL_base_http=6000
|
||||
EL_base_auth_http=5000
|
||||
|
||||
(( $VC_COUNT < $BN_COUNT )) && SAS=-s || SAS=
|
||||
|
||||
for (( el=1; el<=$BN_COUNT; el++ )); do
|
||||
execute_command_add_PID geth_$el.log ./geth.sh $DATADIR/geth_datadir$el $((EL_base_network + $el)) $((EL_base_http + $el)) $((EL_base_auth_http + $el)) $genesis_file
|
||||
done
|
||||
|
||||
sleeping 20
|
||||
|
||||
# Reset the `genesis.json` config file fork times.
|
||||
sed -i 's/"shanghaiTime".*$/"shanghaiTime": 0,/g' $genesis_file
|
||||
sed -i 's/"cancunTime".*$/"cancunTime": 0,/g' $genesis_file
|
||||
sed -i 's/"pragueTime".*$/"pragueTime": 0,/g' $genesis_file
|
||||
|
||||
for (( bn=1; bn<=$BN_COUNT; bn++ )); do
|
||||
secret=$DATADIR/geth_datadir$bn/geth/jwtsecret
|
||||
echo $secret
|
||||
execute_command_add_PID beacon_node_$bn.log ./beacon_node.sh $SAS -d $DEBUG_LEVEL $DATADIR/node_$bn $((BN_udp_tcp_base + $bn)) $((BN_udp_tcp_base + $bn + 100)) $((BN_http_port_base + $bn)) http://localhost:$((EL_base_auth_http + $bn)) $secret
|
||||
done
|
||||
|
||||
# Start requested number of validator clients
|
||||
for (( vc=1; vc<=$VC_COUNT; vc++ )); do
|
||||
execute_command_add_PID validator_node_$vc.log ./validator_client.sh $BUILDER_PROPOSALS -d $DEBUG_LEVEL $DATADIR/node_$vc http://localhost:$((BN_http_port_base + $vc))
|
||||
done
|
||||
kurtosis run --enclave $ENCLAVE_NAME github.com/kurtosis-tech/ethereum-package --args-file $NETWORK_PARAMS_FILE
|
||||
|
||||
echo "Started!"
|
||||
|
||||
Reference in New Issue
Block a user