2021-10-01 06:32:37 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Start all processes necessary to create a local testnet
|
|
|
|
|
2022-01-26 23:14:20 +00:00
|
|
|
set -Eeuo pipefail
|
|
|
|
|
2021-10-01 06:32:37 +00:00
|
|
|
source ./vars.env
|
|
|
|
|
2022-07-15 07:31:22 +00:00
|
|
|
# Set a higher ulimit in case we want to import 1000s of validators.
|
|
|
|
ulimit -n 65536
|
|
|
|
|
2021-10-01 06:32:37 +00:00
|
|
|
# VC_COUNT is defaulted in vars.env
|
|
|
|
DEBUG_LEVEL=${DEBUG_LEVEL:-info}
|
2022-07-30 00:22:37 +00:00
|
|
|
BUILDER_PROPOSALS=
|
2021-10-01 06:32:37 +00:00
|
|
|
|
|
|
|
# Get options
|
2022-07-30 00:22:37 +00:00
|
|
|
while getopts "v:d:ph" flag; do
|
2021-10-01 06:32:37 +00:00
|
|
|
case "${flag}" in
|
|
|
|
v) VC_COUNT=${OPTARG};;
|
|
|
|
d) DEBUG_LEVEL=${OPTARG};;
|
2022-07-30 00:22:37 +00:00
|
|
|
p) BUILDER_PROPOSALS="-p";;
|
2021-10-01 06:32:37 +00:00
|
|
|
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
|
|
|
|
echo "usage: $0 <Options>"
|
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo " -v: VC_COUNT default: $VC_COUNT"
|
|
|
|
echo " -d: DEBUG_LEVEL default: info"
|
2023-03-30 10:14:07 +00:00
|
|
|
echo " -p: enable builder proposals"
|
2021-10-01 06:32:37 +00:00
|
|
|
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"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2022-11-30 17:15:06 +00:00
|
|
|
genesis_file=${@:$OPTIND+0:1}
|
|
|
|
|
2021-10-01 06:32:37 +00:00
|
|
|
# Init some constants
|
|
|
|
PID_FILE=$TESTNET_DIR/PIDS.pid
|
|
|
|
LOG_DIR=$TESTNET_DIR
|
|
|
|
|
|
|
|
# Stop local testnet and remove $PID_FILE
|
|
|
|
./stop_local_testnet.sh
|
|
|
|
|
|
|
|
# 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
|
2022-11-30 17:15:06 +00:00
|
|
|
for (( el=1; el<=$BN_COUNT; el++ )); do
|
|
|
|
touch $LOG_DIR/geth_$el.log
|
|
|
|
done
|
2021-10-01 06:32:37 +00:00
|
|
|
for (( vc=1; vc<=$VC_COUNT; vc++ )); do
|
|
|
|
touch $LOG_DIR/validator_node_$vc.log
|
2022-01-26 23:14:20 +00:00
|
|
|
done
|
2021-10-01 06:32:37 +00:00
|
|
|
|
|
|
|
# Sleep with a message
|
|
|
|
sleeping() {
|
|
|
|
echo sleeping $1
|
|
|
|
sleep $1
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
2022-01-26 23:14:20 +00:00
|
|
|
CMD="$EX_NAME $@ >> $LOG_DIR/$LOG_NAME 2>&1"
|
2021-10-01 06:32:37 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-31 22:55:04 +00:00
|
|
|
# Setup data
|
|
|
|
echo "executing: ./setup.sh >> $LOG_DIR/setup.log"
|
|
|
|
./setup.sh >> $LOG_DIR/setup.log 2>&1
|
2021-10-01 06:32:37 +00:00
|
|
|
|
2023-11-09 04:06:10 +00:00
|
|
|
# Call setup_time.sh to update future hardforks time in the EL genesis file based on the CL genesis time
|
|
|
|
./setup_time.sh genesis.json
|
2023-05-17 05:51:54 +00:00
|
|
|
|
2021-10-01 06:32:37 +00:00
|
|
|
# Delay to let boot_enr.yaml to be created
|
|
|
|
execute_command_add_PID bootnode.log ./bootnode.sh
|
2022-12-06 13:54:46 +00:00
|
|
|
sleeping 3
|
2021-10-01 06:32:37 +00:00
|
|
|
|
2022-11-30 17:15:06 +00:00
|
|
|
execute_command_add_PID el_bootnode.log ./el_bootnode.sh
|
2022-12-06 13:54:46 +00:00
|
|
|
sleeping 3
|
2022-11-30 17:15:06 +00:00
|
|
|
|
2023-05-17 05:51:54 +00:00
|
|
|
execute_command_add_PID el_bootnode.log ./el_bootnode.sh
|
|
|
|
sleeping 1
|
|
|
|
|
2021-10-01 06:32:37 +00:00
|
|
|
# Start beacon nodes
|
|
|
|
BN_udp_tcp_base=9000
|
|
|
|
BN_http_port_base=8000
|
|
|
|
|
2022-11-30 17:15:06 +00:00
|
|
|
EL_base_network=7000
|
|
|
|
EL_base_http=6000
|
2022-12-02 14:20:43 +00:00
|
|
|
EL_base_auth_http=5000
|
2022-11-30 17:15:06 +00:00
|
|
|
|
2021-10-01 06:32:37 +00:00
|
|
|
(( $VC_COUNT < $BN_COUNT )) && SAS=-s || SAS=
|
|
|
|
|
2022-11-30 17:15:06 +00:00
|
|
|
for (( el=1; el<=$BN_COUNT; el++ )); do
|
2022-12-08 18:15:04 +00:00
|
|
|
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
|
2022-11-30 17:15:06 +00:00
|
|
|
done
|
|
|
|
|
2022-12-02 14:20:43 +00:00
|
|
|
sleeping 20
|
|
|
|
|
2022-12-07 19:04:46 +00:00
|
|
|
# Reset the `genesis.json` config file fork times.
|
2023-05-17 05:51:54 +00:00
|
|
|
sed -i 's/"shanghaiTime".*$/"shanghaiTime": 0,/g' $genesis_file
|
2023-08-19 00:12:09 +00:00
|
|
|
sed -i 's/"cancunTime".*$/"cancunTime": 0,/g' $genesis_file
|
2022-12-07 19:04:46 +00:00
|
|
|
|
2021-10-01 06:32:37 +00:00
|
|
|
for (( bn=1; bn<=$BN_COUNT; bn++ )); do
|
2022-12-02 14:20:43 +00:00
|
|
|
secret=$DATADIR/geth_datadir$bn/geth/jwtsecret
|
|
|
|
echo $secret
|
2023-09-15 03:07:24 +00:00
|
|
|
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
|
2021-10-01 06:32:37 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Start requested number of validator clients
|
|
|
|
for (( vc=1; vc<=$VC_COUNT; vc++ )); do
|
2022-07-30 00:22:37 +00:00
|
|
|
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))
|
2021-10-01 06:32:37 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "Started!"
|