Skip to content

Fix and test fork revert logic #5100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: unstable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions scripts/local_testnet/beacon_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:"
Expand All @@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions scripts/local_testnet/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ source ./vars.env
if [ -d $DATADIR ]; then
rm -rf $DATADIR
fi

./clean_genesis.sh genesis.json
8 changes: 8 additions & 0 deletions scripts/local_testnet/clean_genesis.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions scripts/local_testnet/download_geth_stale.sh
Original file line number Diff line number Diff line change
@@ -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
83 changes: 83 additions & 0 deletions scripts/local_testnet/download_lighthouse.sh
Original file line number Diff line number Diff line change
@@ -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 <Options> "
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}"
55 changes: 55 additions & 0 deletions scripts/local_testnet/fork_revert.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions scripts/local_testnet/geth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion scripts/local_testnet/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
21 changes: 13 additions & 8 deletions scripts/local_testnet/start_local_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions scripts/local_testnet/transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
web3.personal.importRawKey('115fe42a60e5ef45f5490e599add1f03c73aeaca129c2c41451eca6cf8ff9e04', 'password')
web3.personal.unlockAccount('0x7b8c3a386c0eea54693ffb0da17373ffc9228139', 'password', 3000)
web3.eth.sendTransaction({from: '0x7b8c3a386c0eea54693ffb0da17373ffc9228139', to: '0x0000000000000000000000000000000000000000', value: 1000})
6 changes: 6 additions & 0 deletions scripts/local_testnet/transaction.sh
Original file line number Diff line number Diff line change
@@ -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