diff --git a/scripts/local_testnet/beacon_node.sh b/scripts/local_testnet/beacon_node.sh index 940fe2b8581..c78edbb26ab 100755 --- a/scripts/local_testnet/beacon_node.sh +++ b/scripts/local_testnet/beacon_node.sh @@ -11,10 +11,13 @@ source ./vars.env SUBSCRIBE_ALL_SUBNETS= DEBUG_LEVEL=${DEBUG_LEVEL:-info} +lighthouse_binary=lighthouse + # Get options -while getopts "d:sh" flag; do +while getopts "d:b:sh" flag; do case "${flag}" in d) DEBUG_LEVEL=${OPTARG};; + b) lighthouse_binary=${OPTARG};; s) SUBSCRIBE_ALL_SUBNETS="--subscribe-all-subnets";; h) echo "Start a beacon node" @@ -24,6 +27,7 @@ while getopts "d:sh" flag; do echo "Options:" echo " -s: pass --subscribe-all-subnets to 'lighthouse bn ...', default is not passed" echo " -d: DEBUG_LEVEL, default info" + echo " -b: lighthouse binary name, default is lighthouse" echo " -h: this help" echo echo "Positional arguments:" @@ -44,15 +48,14 @@ quic_port=${@:$OPTIND+2:1} http_port=${@:$OPTIND+3:1} execution_endpoint=${@:$OPTIND+4:1} execution_jwt=${@:$OPTIND+5:1} - -lighthouse_binary=lighthouse +testnet_dir=${@:$OPTIND+6:1} exec $lighthouse_binary \ --debug-level $DEBUG_LEVEL \ bn \ $SUBSCRIBE_ALL_SUBNETS \ --datadir $data_dir \ - --testnet-dir $TESTNET_DIR \ + --testnet-dir $testnet_dir \ --enable-private-discovery \ --disable-peer-scoring \ --staking \ diff --git a/scripts/local_testnet/clean.sh b/scripts/local_testnet/clean.sh index cd915e470d6..bf79acfa945 100755 --- a/scripts/local_testnet/clean.sh +++ b/scripts/local_testnet/clean.sh @@ -11,3 +11,5 @@ source ./vars.env if [ -d $DATADIR ]; then rm -rf $DATADIR fi + +./clean_genesis.sh genesis.json diff --git a/scripts/local_testnet/clean_genesis.sh b/scripts/local_testnet/clean_genesis.sh new file mode 100755 index 00000000000..06bfee42fed --- /dev/null +++ b/scripts/local_testnet/clean_genesis.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +genesis_file=$1 + +# 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 diff --git a/scripts/local_testnet/download_geth_stale.sh b/scripts/local_testnet/download_geth_stale.sh new file mode 100755 index 00000000000..2fef7bd4811 --- /dev/null +++ b/scripts/local_testnet/download_geth_stale.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Get is cancun enabled for versions > 1.13.12. So we install 1.13.11. +cd ~ +curl -LO https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.13.11-8f7eb9cc.tar.gz +tar xvf geth-linux-amd64-1.13.11-8f7eb9cc.tar.gz +cd geth-linux-amd64-1.13.11-8f7eb9cc/ +cp geth ~/.cargo/bin/geth-stale # .cargo/bin to avoid permissions problems +cd ~ +rm -r geth-linux-amd64-1.13.11-8f7eb9cc geth-linux-amd64-1.13.11-8f7eb9cc.tar.gz diff --git a/scripts/local_testnet/download_lighthouse.sh b/scripts/local_testnet/download_lighthouse.sh new file mode 100755 index 00000000000..ee1d5fa8f03 --- /dev/null +++ b/scripts/local_testnet/download_lighthouse.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +# Download the Lighthouse version passed as the first argument. +# OS is picked automatically using uname +# Example: +# $ ./download_lighthouse.sh v5.0.0 -b lighthouse-deneb -p ~/.cargo/bin/ +# ... +# $ ls ~/.cargo/bin/ +# lighthouse-deneb + +version=$1 +shift + +install_path=~/.cargo/bin/ +installed_binary_name=lighthouse + +# Required commands check +for cmd in curl tar uname; do + command -v "$cmd" >/dev/null 2>&1 || { echo >&2 "This script requires $cmd but it's not installed. Aborting."; exit 1; } +done + +# Check OS and set binary_name accordingly +OS=$(uname -s) +case "$OS" in + Linux) binary_name="lighthouse-${version}-x86_64-unknown-linux-gnu.tar.gz" ;; + Darwin) binary_name="lighthouse-${version}-x86_64-apple-darwin.tar.gz" ;; + *) echo "Unsupported OS: $OS"; exit 1 ;; +esac + +# Get options +while getopts "b:p:h" flag; do + case "${flag}" in + b) installed_binary_name=${OPTARG};; + p) + install_path=${OPTARG} + # Ensure install_path ends with a slash + install_path="${install_path%/}/";; + h) + echo "Download Lighthouse." + echo + echo "usage: $0 vX.X.X " + echo + echo "The first argument must be the version of Lighthouse you wish to download," + echo "specified as 'vX.X.X', where X.X.X is the version number." + echo + echo "Options:" + echo " -b: binary name, specify the output binary name, default: lighthouse" + echo " -p: install path, specify the installation path, default: ~/.cargo/bin/" + echo " -h: this help" + echo "Example:" + echo "$ ./download_lighthouse.sh v5.0.0 -b lighthouse-deneb -p ~/.cargo/bin/" + echo "..." + echo "$ ls ~/.cargo/bin/" + echo "lighthouse-deneb" + exit + ;; + esac +done + +# Download and extract the release +echo "Downloading ${binary_name}" +if ! curl -LO "https://github.com/sigp/lighthouse/releases/download/${version}/${binary_name}"; then + echo "Failed to download ${binary_name}" + exit 1 +fi + +if ! tar -xzf "${binary_name}"; then + echo "Failed to extract ${binary_name}" + exit 1 +fi + +# Remove the tarball +echo "Removing downloaded tarball ${binary_name}" +rm "${binary_name}" + +# Move the binary only if install_path is different from current directory +echo "Installing Lighthouse to ${install_path}${installed_binary_name}" +if ! mv lighthouse "${install_path}${installed_binary_name}"; then + echo "Failed to move Lighthouse to ${install_path}${installed_binary_name}" + exit 1 +fi + +echo "Lighthouse ${version} installed successfully at ${install_path}${installed_binary_name}" diff --git a/scripts/local_testnet/fork_revert.sh b/scripts/local_testnet/fork_revert.sh new file mode 100755 index 00000000000..80cade01ba2 --- /dev/null +++ b/scripts/local_testnet/fork_revert.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +source ./start_local_testnet.sh genesis.json + +./download_lighthouse.sh v4.6.0 -b lh-stale + +n=2 +node_id=$(($BN_COUNT+1)) + +stale_testnet_dir=$DATADIR/stale_testnet + +cp -r $TESTNET_DIR $stale_testnet_dir + +sed -i '/DENEB_FORK_VERSION/d' $stale_testnet_dir/config.yaml +sed -i '/DENEB_FORK_EPOCH/d' $stale_testnet_dir/config.yaml +sed -i '/MAX_REQUEST_BLOCKS_DENEB/d' $stale_testnet_dir/config.yaml + +for ((i = 0; i < n; i++)); do + current_id=$(($node_id+i)) + execute_command_add_PID geth_$current_id.log ./geth.sh $DATADIR/geth_datadir$current_id $((EL_base_network + $current_id)) $((EL_base_http + current_id)) $((EL_base_auth_http + $current_id)) $genesis_file +done + +sleeping 20 + +for ((i = 0; i < n; i++)); do + current_id=$(($node_id+i)) + secret=$DATADIR/geth_datadir$current_id/geth/jwtsecret + echo $secret + execute_command_add_PID beacon_node_$current_id.log ./beacon_node.sh $SAS -d $DEBUG_LEVEL $DATADIR/node_$current_id $((BN_udp_tcp_base + $current_id)) $((BN_udp_tcp_base + $current_id + 100)) $((BN_http_port_base + $current_id)) http://localhost:$((EL_base_auth_http + $current_id)) $secret $stale_testnet_dir -b lh-stale + + execute_command_add_PID validator_node_$current_id.log ./validator_client.sh $BUILDER_PROPOSALS -d $DEBUG_LEVEL $DATADIR/node_$current_id http://localhost:$((BN_http_port_base + $current_id)) + + tail ~/.lighthouse/local-testnet/testnet/PIDS.pid --lines 2 >> $stale_testnet_dir/stale_pids.pid +done + +# Wait for the two chains to split +sleeping $(($DENEB_FORK_EPOCH*32*$SECONDS_PER_SLOT)) + +echo "Sending a transaction on the stale chain" +./transaction.sh + +sleeping 30 + +./kill_processes.sh $stale_testnet_dir/stale_pids.pid + +sleeping 5 + +for ((i = 0; i < n; i++)); do + current_id=$(($node_id+i)) + secret=$DATADIR/geth_datadir$current_id/geth/jwtsecret + echo $secret + execute_command_add_PID beacon_node_$current_id.log ./beacon_node.sh $SAS -d $DEBUG_LEVEL $DATADIR/node_$current_id $((BN_udp_tcp_base + $current_id)) $((BN_udp_tcp_base + $current_id + 100)) $((BN_http_port_base + $current_id)) http://localhost:$((EL_base_auth_http + $current_id)) $secret $TESTNET_DIR + + execute_command_add_PID validator_node_$current_id.log ./validator_client.sh $BUILDER_PROPOSALS -d $DEBUG_LEVEL $DATADIR/node_$current_id http://localhost:$((BN_http_port_base + $current_id)) +done diff --git a/scripts/local_testnet/geth.sh b/scripts/local_testnet/geth.sh index 5dc4575cf0a..aeb5bca4acf 100755 --- a/scripts/local_testnet/geth.sh +++ b/scripts/local_testnet/geth.sh @@ -3,9 +3,10 @@ set -Eeuo pipefail source ./vars.env # Get options -while getopts "d:sh" flag; do +while getopts "d:b:sh" flag; do case "${flag}" in d) DEBUG_LEVEL=${OPTARG};; + b) GETH_BINARY=${OPTARG};; s) SUBSCRIBE_ALL_SUBNETS="--subscribe-all-subnets";; h) echo "Start a geth node" @@ -44,7 +45,8 @@ exec $GETH_BINARY \ --datadir $data_dir \ --ipcdisable \ --http \ - --http.api="engine,eth,web3,net,debug" \ + --http.api="engine,eth,web3,personal,net,debug" \ + --allow-insecure-unlock \ --networkid=$CHAIN_ID \ --syncmode=full \ --bootnodes $EL_BOOTNODE_ENODE \ diff --git a/scripts/local_testnet/setup.sh b/scripts/local_testnet/setup.sh index 419cba19ed9..d7a6016aa80 100755 --- a/scripts/local_testnet/setup.sh +++ b/scripts/local_testnet/setup.sh @@ -29,7 +29,6 @@ lcli \ --bellatrix-fork-epoch $BELLATRIX_FORK_EPOCH \ --capella-fork-epoch $CAPELLA_FORK_EPOCH \ --deneb-fork-epoch $DENEB_FORK_EPOCH \ - --electra-fork-epoch $ELECTRA_FORK_EPOCH \ --ttd $TTD \ --eth1-block-hash $ETH1_BLOCK_HASH \ --eth1-id $CHAIN_ID \ diff --git a/scripts/local_testnet/start_local_testnet.sh b/scripts/local_testnet/start_local_testnet.sh index be91d069985..05b2d7adef1 100755 --- a/scripts/local_testnet/start_local_testnet.sh +++ b/scripts/local_testnet/start_local_testnet.sh @@ -53,6 +53,7 @@ LOG_DIR=$TESTNET_DIR # user can "tail -f" right after starting this script # even before its done. ./clean.sh +./clean_genesis.sh $genesis_file mkdir -p $LOG_DIR for (( bn=1; bn<=$BN_COUNT; bn++ )); do touch $LOG_DIR/beacon_node_$bn.log @@ -66,8 +67,17 @@ done # Sleep with a message sleeping() { - echo sleeping $1 - sleep $1 + local sleep_time=$1 + local start_time=$(date +%s) + local end_time=$((start_time + sleep_time)) + + while [ $(date +%s) -lt $end_time ]; do + local current_time=$(date +%s) + local time_left=$((end_time - current_time)) + echo -ne "Sleeping for $time_left more seconds...\r" + sleep 1 + done + echo -ne "\n" } # Execute the command with logs saved to a file. @@ -128,15 +138,10 @@ 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 + 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 $TESTNET_DIR done # Start requested number of validator clients diff --git a/scripts/local_testnet/transaction.js b/scripts/local_testnet/transaction.js new file mode 100644 index 00000000000..7f5bda1f399 --- /dev/null +++ b/scripts/local_testnet/transaction.js @@ -0,0 +1,3 @@ +web3.personal.importRawKey('115fe42a60e5ef45f5490e599add1f03c73aeaca129c2c41451eca6cf8ff9e04', 'password') +web3.personal.unlockAccount('0x7b8c3a386c0eea54693ffb0da17373ffc9228139', 'password', 3000) +web3.eth.sendTransaction({from: '0x7b8c3a386c0eea54693ffb0da17373ffc9228139', to: '0x0000000000000000000000000000000000000000', value: 1000}) diff --git a/scripts/local_testnet/transaction.sh b/scripts/local_testnet/transaction.sh new file mode 100755 index 00000000000..726c9aa42f6 --- /dev/null +++ b/scripts/local_testnet/transaction.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Define the node endpoint +NODE_ENDPOINT="http://localhost:6005" + +# Import the private key +geth --jspath "./" --exec 'loadScript("transaction.js")' attach $NODE_ENDPOINT