Skip to content

Commit

Permalink
feat: add script to support sequencer (#37) (#40)
Browse files Browse the repository at this point in the history
* feat: add script to support sequencer (#37)

* refactor: refactor pos script

* chore: update gitignore

* chore: install lighthouse with specified commit id

* fix: fix tx filter

* refactor: refactor script, remove validator keys and genesis config

* refactor: refactor scripts

* fix: fix scripts

* fix: fix the Absolute Path for scripts

* refactor: refactor scripts
  • Loading branch information
captainlee1024 authored Aug 10, 2024
1 parent 35d99f3 commit 447d871
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# Ignore the el-cl-genesis-data and validator-keys directories under testdata/layer2/pos
testdata/layer2/pos/el-cl-genesis-data/
testdata/layer2/pos/validator-keys/
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,37 @@ fix: ## Automatically apply lint suggestions. This flag implies `--no-deps` and
test: ## Run tests for all the workspace members
@cargo test --release --all

install: ## Install the binary for eigen-zeth project using cargo
@cargo install --path . --force

generate_genesis_data: ## Generate genesis data
@cd scripts && sh ./generate-genesis-data.sh

build_eth2_validator_tools: ## Build eth2 validator tools
@cd scripts && sh ./build-eth2-validator-tools.sh

generate_eth2_validator_keys: ## Generate eth2 validator keys
@cd scripts && sh ./generate-eth2-validator-keys.sh

init_eigen_zeth_genesis: ## Initialize eigen zeth genesis
@cd scripts && sh ./init-eigen-zeth-genesis.sh

launch_pos_eigen_zeth_node: ## Launch a single eigen_zeth node using PoS consensus algorithm
@cd scripts && sh ./launch-pos-eigen-zeth-node.sh

stop_pos_eigen_zeth_node: ## Stop eigen zeth node
@pkill lighthouse
@pkill eigen-zeth

clean_pos_eigen_zeth_network_data: ## Clean eigen zeth network data
@rm -rf tmp/layer2/consensus-data
@rm -rf tmp/layer2/execution-data
@rm -rf tmp/operator
@rm tmp/zeth.log
@rm tmp/beacon.log
@rm tmp/validator.log

build_lighthouse: ## Build and install lighthouse
@cd scripts && sh ./build-and-install-lighthouse.sh

.PHONY: clippy fmt test
28 changes: 28 additions & 0 deletions scripts/build-and-install-lighthouse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
set -e

CURRENT_PATH=$( cd "$( dirname "$0" )" && pwd )
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
echo "PROJECT_PATH: ${PROJECT_PATH}"

LIGHTHOUSE_SOURCE_PATH="${PROJECT_PATH}/tmp/lighthouse-source"
echo "LIGHTHOUSE_SOURCE_PATH: ${LIGHTHOUSE_SOURCE_PATH}"

if [ ! -d "${LIGHTHOUSE_SOURCE_PATH}" ]; then
mkdir -p "${LIGHTHOUSE_SOURCE_PATH}"
fi

cd ${LIGHTHOUSE_SOURCE_PATH}

echo "Removing existing lighthouse source"
rm -rf ./*

echo "Cloning lighthouse source"
git clone https://github.com/sigp/lighthouse.git
cd lighthouse

## lighthouse tag: v5.2.1
echo "Checkout lighthouse commit: 9e12c21f268c80a3f002ae0ca27477f9f512eb6f"
git checkout 9e12c21f268c80a3f002ae0ca27477f9f512eb6f

echo "Build and Install lighthouse"
make install
26 changes: 26 additions & 0 deletions scripts/build-eth2-validator-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set -e

CURRENT_PATH=$( cd "$( dirname "$0" )" && pwd )
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
echo "PROJECT_PATH: ${PROJECT_PATH}"

INSTALL_PATH="${PROJECT_PATH}/tmp/tools/bin"
echo "Tools INSTALL_PATH: ${INSTALL_PATH}"
if [ ! -d "${PROJECT_PATH}/tmp/tools" ]; then
mkdir -p "${PROJECT_PATH}/tmp/tools"
fi

cd "${PROJECT_PATH}/tmp/tools"

echo "Removing existing eth2-val-tools"
rm -rf ./*

echo "Cloning eth2-val-tools"
git clone https://github.com/protolambda/eth2-val-tools.git
cd eth2-val-tools

echo "Checkout eth2-val-tools commit: 0d6d1ddb36479e73d7d876b29ac2d10ab3988e85"
git checkout 0d6d1ddb36479e73d7d876b29ac2d10ab3988e85

echo "Build eth2-val-tools, target path: ${INSTALL_PATH}"
go build -o ${INSTALL_PATH}/eth2-val-tools
29 changes: 29 additions & 0 deletions scripts/generate-eth2-validator-keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
set -e

CURRENT_PATH=$( cd "$( dirname "$0" )" && pwd )
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
echo "PROJECT_PATH: ${PROJECT_PATH}"

VALIDATOR_KEYS_PATH="${PROJECT_PATH}/testdata/layer2/pos/validator-keys"
echo "VALIDATOR_KEYS_PATH: ${VALIDATOR_KEYS_PATH}"

echo "Removing existing validator keys"
rm -rf ${VALIDATOR_KEYS_PATH}

DEFAULT_MNEMONIC="giant issue aisle success illegal bike spike question tent bar rely arctic volcano long crawl hungry vocal artwork sniff fantasy very lucky have athlete"
echo "Default mnemonic: ${DEFAULT_MNEMONIC}"

DEFAULT_TOOLS_BIN_PATH="${PROJECT_PATH}/tmp/tools/bin/eth2-val-tools"
echo "DEFAULT_TOOLS_BIN_PATH: ${DEFAULT_TOOLS_BIN_PATH}"
if [ ! -f "${DEFAULT_TOOLS_BIN_PATH}" ]; then
echo "eth2-val-tools binary not found: ${DEFAULT_TOOLS_BIN_PATH}, please run make build_eth2_validator_tools or scripts/build-eth2-validator-tools.sh"
exit 1
fi

${DEFAULT_TOOLS_BIN_PATH} keystores \
--insecure \
--prysm-pass password \
--out-loc ${VALIDATOR_KEYS_PATH} \
--source-mnemonic "${DEFAULT_MNEMONIC}" \
--source-min 0 \
--source-max 64
41 changes: 41 additions & 0 deletions scripts/generate-genesis-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
set -e

#CURRENT_PATH=$(pwd)
CURRENT_PATH=$( cd "$( dirname "$0" )" && pwd )
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
echo "PROJECT_PATH: ${PROJECT_PATH}"

GENESIS_PATH="${PROJECT_PATH}/testdata/layer2/pos/el-cl-genesis-data"
echo "GENESIS_PATH: ${GENESIS_PATH}"

echo "Removing existing genesis data: ${GENESIS_PATH}"
rm -rf ${GENESIS_PATH}

FILE_DIR="${PROJECT_PATH}/testdata/layer2/pos"
FILE_PATH="${FILE_DIR}/values.env"
echo "Updating GENESIS_TIMESTAMP in ${FILE_PATH}"

current_utc_timestamp=$(date -u +%s)
echo "current_utc_timestamp: ${current_utc_timestamp}"
OS="$(uname -s)"
case "${OS}" in
Linux*)
echo "Running on Linux"
sed -i "s/GENESIS_TIMESTAMP=[0-9]*/GENESIS_TIMESTAMP=$current_utc_timestamp/" $FILE_PATH
;;
Darwin*)
echo "Running on macOS"
sed -i '' "s/GENESIS_TIMESTAMP=[0-9]*/GENESIS_TIMESTAMP=$current_utc_timestamp/" $FILE_PATH
;;
*)
echo "Unknown OS: ${OS}"
exit 1
;;
esac

# generate genesis data
echo "Generating genesis data: ${GENESIS_PATH}"
docker run --rm -it \
-v ${GENESIS_PATH}:/data \
-v ${FILE_PATH}:/config/values.env \
ethpandaops/ethereum-genesis-generator:3.2.1 all
7 changes: 7 additions & 0 deletions scripts/init-eigen-zeth-genesis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set -e

CURRENT_PATH=$( cd "$( dirname "$0" )" && pwd )
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
cd "${PROJECT_PATH}/testdata/layer2/pos"

eigen-zeth init --datadir ../../../tmp/layer2/execution-data --chain el-cl-genesis-data/metadata/genesis.json
61 changes: 61 additions & 0 deletions scripts/launch-pos-eigen-zeth-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
set -e

#CURRENT_PATH=$(pwd)
CURRENT_PATH=$( cd "$( dirname "$0" )" && pwd )
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
echo "PROJECT_PATH: ${PROJECT_PATH}"

GENESIS_PATH="${PROJECT_PATH}/testdata/layer2/pos/el-cl-genesis-data"
if [ ! -d "${GENESIS_PATH}" ]; then
echo "Genesis directory not found at ${GENESIS_PATH}"
exit 1
fi
echo "GENESIS_PATH: ${GENESIS_PATH}"

TESTNET_DIR="${GENESIS_PATH}/metadata"
echo "TESTNET_DIR: ${TESTNET_DIR}"

CHAIN_SPEC_PATH="${TESTNET_DIR}/genesis.json"
echo "CHAIN_SPEC_PATH: ${CHAIN_SPEC_PATH}"

CHAIN_DATA_PATH_PREFIX="${PROJECT_PATH}/tmp/layer2"
echo "CHAIN_DATA_PATH_PREFIX: ${CHAIN_DATA_PATH_PREFIX}"

EXECUTION_DATA_PATH="${CHAIN_DATA_PATH_PREFIX}/execution-data"
echo "EXECUTION_DATA_PATH: ${EXECUTION_DATA_PATH}"

CONSENSUS_DATA_PATH="${CHAIN_DATA_PATH_PREFIX}/consensus-data"
echo "CONSENSUS_DATA_PATH: ${CONSENSUS_DATA_PATH}"

VALIDATOR_BASE_PATH="${CONSENSUS_DATA_PATH}/validators"
echo "VALIDATOR_BASE_PATH: ${VALIDATOR_BASE_PATH}"
VALIDATOR_KEYS_PATH="${VALIDATOR_BASE_PATH}/keys"
VALIDATOR_SECRETS_PATH="${VALIDATOR_BASE_PATH}/secrets"

JWT_SECRET_PATH="${GENESIS_PATH}/jwt/jwtsecret"
echo "JWT_SECRET_PATH: ${JWT_SECRET_PATH}"

VALIDATOR_SOURCE_PATH="${PROJECT_PATH}/testdata/layer2/pos/validator-keys"

ZETH_LOG_FILE="${PROJECT_PATH}/tmp/zeth.log"
BEACON_LOG_FILE="${PROJECT_PATH}/tmp/beacon.log"
VALIDATOR_LOG_FILE="${PROJECT_PATH}/tmp/validator.log"

DEFAULT_SETTLEMENT="ethereum" # default settlement layer
DEFAULT_SETTLEMENT_CONFIG_FILE="${PROJECT_PATH}/configs/settlement.toml"
DEFAULT_CUSTOM_NODE_CONFIG_FILE="${PROJECT_PATH}/configs/custom_node_config.toml"
DEFAULT_DATABASE_CONFIG_FILE="${PROJECT_PATH}/configs/database.toml"

# start the zeth node
PROVER_ADDR=http://localhost:50061 RUST_LOG="debug,evm=trace,consensus::auto=trace,consensus::engine=trace,rpc::eth=trace" nohup eigen-zeth run --database mdbx --database-conf $DEFAULT_DATABASE_CONFIG_FILE --custom-node-conf $DEFAULT_CUSTOM_NODE_CONFIG_FILE --settlement $DEFAULT_SETTLEMENT --settlement-conf $DEFAULT_SETTLEMENT_CONFIG_FILE --chain $CHAIN_SPEC_PATH --datadir $EXECUTION_DATA_PATH --http --http.addr 0.0.0.0 --http.port 48546 --http.api debug,eth,net,trace,web3,rpc --authrpc.jwtsecret $JWT_SECRET_PATH --authrpc.addr 0.0.0.0 --authrpc.port 48552 --port 40304 --full > $ZETH_LOG_FILE 2>&1 &
# start the beacon node
nohup lighthouse bn --debug-level=info --datadir=$CONSENSUS_DATA_PATH --disable-enr-auto-update --enr-address=172.20.0.3 --enr-udp-port=9000 --enr-tcp-port=9000 --listen-address=0.0.0.0 --port=9000 --http --http-address=0.0.0.0 --http-port=4000 --slots-per-restore-point=32 --disable-packet-filter --execution-endpoints=http://localhost:48552 --jwt-secrets=$JWT_SECRET_PATH --suggested-fee-recipient=0x8943545177806ED17B9F23F0a21ee5948eCaa776 --subscribe-all-subnets --enable-private-discovery --testnet-dir=$TESTNET_DIR >> $BEACON_LOG_FILE 2>&1 &
# start the validator client
if [ ! -d "${VALIDATOR_BASE_PATH}" ]; then
mkdir -p ${VALIDATOR_BASE_PATH}
fi

echo "Copying validator keys and secrets"
cp -rn "${VALIDATOR_SOURCE_PATH}/keys" ${VALIDATOR_BASE_PATH}
cp -rn "${VALIDATOR_SOURCE_PATH}/secrets" ${VALIDATOR_BASE_PATH}
nohup lighthouse vc --debug-level=info --testnet-dir=$TESTNET_DIR --validators-dir=$VALIDATOR_KEYS_PATH --secrets-dir=$VALIDATOR_SECRETS_PATH --init-slashing-protection --beacon-nodes=http://localhost:4000 --suggested-fee-recipient=0x8943545177806ED17B9F23F0a21ee5948eCaa776 >> $VALIDATOR_LOG_FILE 2>&1 &
18 changes: 12 additions & 6 deletions src/custom_reth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ use reth_node_core::primitives::U256;
use reth_primitives::constants::eip4844::MAX_DATA_GAS_PER_BLOCK;
use reth_primitives::constants::BEACON_NONCE;
use reth_primitives::eip4844::calculate_excess_blob_gas;
use reth_primitives::hex::{FromHex, ToHex};
use reth_primitives::revm::env::tx_env_with_recovered;
use reth_revm::database::StateProviderDatabase;
use reth_revm::db::states::bundle_state::BundleRetention;
use reth_revm::{revm, EvmProcessorFactory, State};
use revm_primitives::db::DatabaseCommit;
use revm_primitives::{db::DatabaseCommit, hex::ToHexExt};
use revm_primitives::{EVMError, EnvWithHandlerCfg, InvalidTransaction, ResultAndState};

pub(crate) mod eigen;
Expand Down Expand Up @@ -519,12 +518,19 @@ where
return true;
}

// 0x647c576c000000000000000000000000000000000000000000000000000000000000000 &[u8]
let tx_input = tx.transaction.input();
// When calling the built-in method of eth, the input is 0x
let tx_input_bytes: Vec<u8> = Vec::from_hex(tx_input).expect("err msg");
let function_selector = &tx_input_bytes[0..4];
let function_selector_str: String = function_selector.encode_hex();
let _parameters_data = &tx_input_bytes[4..];
// let tx_input_bytes: Vec<u8> = Vec::from_hex(tx_input).expect("err msg");
let function_selector = &tx_input[0..4];

// let function_selector_str: String = function_selector.encode_hex();

// let mut function_selector_str: String = String::new();
// _ = function_selector.read_to_string(&mut function_selector_str);
let function_selector_str = function_selector.encode_hex_with_prefix();

let _parameters_data = &tx_input[4..];
tracing::info!(target: "consensus::auto-seal::miner::pool-tx-filter","tx function selector: {:?}", function_selector_str);

// check if the transaction is a bridge asset transaction
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions testdata/layer2/pos/values.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export PRESET_BASE="mainnet"
export CHAIN_ID="12345"
export DEPOSIT_CONTRACT_ADDRESS="0x4242424242424242424242424242424242424242"
export EL_AND_CL_MNEMONIC="giant issue aisle success illegal bike spike question tent bar rely arctic volcano long crawl hungry vocal artwork sniff fantasy very lucky have athlete"
export CL_EXEC_BLOCK="0"
export SLOT_DURATION_IN_SECONDS=12
export DEPOSIT_CONTRACT_BLOCK="0x0000000000000000000000000000000000000000000000000000000000000000"
export NUMBER_OF_VALIDATORS=64
export GENESIS_FORK_VERSION="0x10000038"
export ALTAIR_FORK_VERSION="0x20000038"
export BELLATRIX_FORK_VERSION="0x30000038"
export CAPELLA_FORK_VERSION="0x40000038"
export DENEB_FORK_VERSION="0x50000038"
export DENEB_FORK_EPOCH="0"
export ELECTRA_FORK_VERSION="0x60000038"
export ELECTRA_FORK_EPOCH="100000000"
export EIP7594_FORK_EPOCH="100000001"
export EIP7594_FORK_VERSION="0x70000038"
export WITHDRAWAL_TYPE="0x00"
export WITHDRAWAL_ADDRESS=0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134
export GENESIS_TIMESTAMP=1723253345
export GENESIS_DELAY=60
export MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT=8
export CHURN_LIMIT_QUOTIENT=65536
export EJECTION_BALANCE=16000000000
export ETH1_FOLLOW_DISTANCE=2048
export SHADOW_FORK_FILE=
export MIN_VALIDATOR_WITHDRAWABILITY_DELAY=256
export SHARD_COMMITTEE_PERIOD=256
export DATA_COLUMN_SIDECAR_SUBNET_COUNT=32
export SAMPLES_PER_SLOT=8
export CUSTODY_REQUIREMENT=1
export TARGET_NUMBER_OF_PEERS=70
export ADDITIONAL_PRELOADED_CONTRACTS={}

0 comments on commit 447d871

Please sign in to comment.