Skip to content

Commit

Permalink
use Deneb genesis for local testnet; add Electra forking support to l…
Browse files Browse the repository at this point in the history
…ocal tesnet (#6634)

* use Deneb genesis for local testnet; add Electra forking support to local tesnet

* deneb -> electra in ncli_testnet help
  • Loading branch information
tersec authored Oct 10, 2024
1 parent 9ba31fb commit 181f5f9
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 60 deletions.
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ local-testnet-minimal:
--signer-nodes 1 \
--remote-validators-count 512 \
--signer-type $(SIGNER_TYPE) \
--capella-fork-epoch 0 \
--deneb-fork-epoch 2 \
--deneb-fork-epoch 0 \
--stop-at-epoch 6 \
--disable-htop \
--enable-payload-builder \
Expand Down Expand Up @@ -267,8 +266,7 @@ local-testnet-mainnet:
./scripts/launch_local_testnet.sh \
--data-dir $@ \
--nodes 2 \
--capella-fork-epoch 0 \
--deneb-fork-epoch 2 \
--deneb-fork-epoch 0 \
--stop-at-epoch 6 \
--disable-htop \
--enable-logtrace \
Expand Down
3 changes: 2 additions & 1 deletion beacon_chain/spec/forks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ type
ForkyExecutionPayloadHeader* =
bellatrix.ExecutionPayloadHeader |
capella.ExecutionPayloadHeader |
deneb.ExecutionPayloadHeader
deneb.ExecutionPayloadHeader |
electra.ExecutionPayloadHeader

ForkyBeaconBlockBody* =
phase0.BeaconBlockBody |
Expand Down
28 changes: 27 additions & 1 deletion ncli/ncli_testnet.nim
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ type
desc: "The epoch of the Deneb hard-fork"
name: "deneb-fork-epoch" .}: Epoch

electraForkEpoch* {.
defaultValue: FAR_FUTURE_EPOCH
desc: "The epoch of the Electra hard-fork"
name: "electra-fork-epoch" .}: Epoch

outputGenesis* {.
desc: "Output file where to write the initial state snapshot"
name: "output-genesis" .}: OutFile
Expand Down Expand Up @@ -342,6 +347,25 @@ func `as`(blk: BlockObject, T: type deneb.ExecutionPayloadHeader): T =
blob_gas_used: uint64 blk.blobGasUsed.getOrDefault(),
excess_blob_gas: uint64 blk.excessBlobGas.getOrDefault())

func `as`(blk: BlockObject, T: type electra.ExecutionPayloadHeader): T =
T(parent_hash: blk.parentHash as Eth2Digest,
fee_recipient: blk.miner as ExecutionAddress,
state_root: blk.stateRoot as Eth2Digest,
receipts_root: blk.receiptsRoot as Eth2Digest,
logs_bloom: BloomLogs(data: distinctBase(blk.logsBloom)),
prev_randao: Eth2Digest(data: blk.difficulty.toByteArrayBE),
block_number: uint64 blk.number,
gas_limit: uint64 blk.gasLimit,
gas_used: uint64 blk.gasUsed,
timestamp: uint64 blk.timestamp,
extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(blk.extraData.bytes),
base_fee_per_gas: blk.baseFeePerGas.getOrDefault(),
block_hash: blk.hash as Eth2Digest,
transactions_root: blk.transactionsRoot as Eth2Digest,
withdrawals_root: blk.withdrawalsRoot.getOrDefault() as Eth2Digest,
blob_gas_used: uint64 blk.blobGasUsed.getOrDefault(),
excess_blob_gas: uint64 blk.excessBlobGas.getOrDefault())

func createDepositContractSnapshot(
deposits: seq[DepositData],
blockHash: Eth2Digest,
Expand Down Expand Up @@ -464,7 +488,9 @@ proc doCreateTestnet*(config: CliConfig,
initialState[].genesis_validators_root

let genesisValidatorsRoot =
if config.denebForkEpoch == 0:
if config.electraForkEpoch == 0:
createAndSaveState(genesisBlock as electra.ExecutionPayloadHeader)
elif config.denebForkEpoch == 0:
createAndSaveState(genesisBlock as deneb.ExecutionPayloadHeader)
elif config.capellaForkEpoch == 0:
createAndSaveState(genesisBlock as capella.ExecutionPayloadHeader)
Expand Down
1 change: 1 addition & 0 deletions scripts/execution_genesis.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"londonBlock":0,
"shanghaiTime":SHANGHAI_FORK_TIME,
"cancunTime":CANCUN_FORK_TIME,
"pragueTime":PRAGUE_FORK_TIME,
"mergeForkBlock":0,
"mergeNetsplitBlock":0,
"terminalTotalDifficulty":0,
Expand Down
45 changes: 22 additions & 23 deletions scripts/launch_local_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CURL_BINARY="$(command -v curl)" || { echo "Curl not installed. Aborting."; exit
JQ_BINARY="$(command -v jq)" || { echo "jq not installed. Aborting."; exit 1; }

OPTS="ht:n:d:g"
LONGOPTS="help,preset:,nodes:,data-dir:,remote-validators-count:,threshold:,signer-nodes:,signer-type:,with-ganache,stop-at-epoch:,disable-htop,use-vc:,disable-vc,enable-payload-builder,enable-logtrace,log-level:,base-port:,base-rest-port:,base-metrics-port:,base-vc-metrics-port:,base-vc-keymanager-port:,base-remote-signer-port:,base-remote-signer-metrics-port:,base-el-net-port:,base-el-rpc-port:,base-el-ws-port:,base-el-auth-rpc-port:,el-port-offset:,reuse-existing-data-dir,reuse-binaries,timeout:,kill-old-processes,eth2-docker-image:,lighthouse-vc-nodes:,run-geth,dl-geth,dl-nimbus-eth1,dl-nimbus-eth2,light-clients:,run-nimbus-eth1,verbose,altair-fork-epoch:,bellatrix-fork-epoch:,capella-fork-epoch:,deneb-fork-epoch:"
LONGOPTS="help,preset:,nodes:,data-dir:,remote-validators-count:,threshold:,signer-nodes:,signer-type:,with-ganache,stop-at-epoch:,disable-htop,use-vc:,disable-vc,enable-payload-builder,enable-logtrace,log-level:,base-port:,base-rest-port:,base-metrics-port:,base-vc-metrics-port:,base-vc-keymanager-port:,base-remote-signer-port:,base-remote-signer-metrics-port:,base-el-net-port:,base-el-rpc-port:,base-el-ws-port:,base-el-auth-rpc-port:,el-port-offset:,reuse-existing-data-dir,reuse-binaries,timeout:,kill-old-processes,eth2-docker-image:,lighthouse-vc-nodes:,run-geth,dl-geth,dl-nimbus-eth1,dl-nimbus-eth2,light-clients:,run-nimbus-eth1,verbose,deneb-fork-epoch:,electra-fork-epoch:"

# default values
BINARIES=""
Expand Down Expand Up @@ -103,8 +103,8 @@ DL_GETH="0"
: ${NIMBUS_ETH2_REVISION:=6c0d756d}

: ${BEACON_NODE_COMMAND:="./build/nimbus_beacon_node$EXE_EXTENSION"}
: ${CAPELLA_FORK_EPOCH:=0}
: ${DENEB_FORK_EPOCH:=50}
: ${DENEB_FORK_EPOCH:=0}
: ${ELECTRA_FORK_EPOCH:=5000}

#NIMBUS EL VARS
RUN_NIMBUS_ETH1="0"
Expand Down Expand Up @@ -212,10 +212,6 @@ while true; do
CONST_PRESET="$2"
shift 2
;;
--capella-fork-epoch)
CAPELLA_FORK_EPOCH="$2"
shift 2
;;
--deneb-fork-epoch)
DENEB_FORK_EPOCH="$2"
shift 2
Expand Down Expand Up @@ -826,8 +822,9 @@ fi
GENESIS_OFFSET=60 # See `Scheduling first slot action` > `startTime`
NOW_UNIX_TIMESTAMP=$(date +%s)
GENESIS_TIME=$((NOW_UNIX_TIMESTAMP + GENESIS_OFFSET))
SHANGHAI_FORK_TIME=$((GENESIS_TIME + SECONDS_PER_SLOT * SLOTS_PER_EPOCH * CAPELLA_FORK_EPOCH))
SHANGHAI_FORK_TIME=${GENESIS_TIME}
CANCUN_FORK_TIME=$((GENESIS_TIME + SECONDS_PER_SLOT * SLOTS_PER_EPOCH * DENEB_FORK_EPOCH))
PRAGUE_FORK_TIME=$((GENESIS_TIME + SECONDS_PER_SLOT * SLOTS_PER_EPOCH * ELECTRA_FORK_EPOCH))

EXECUTION_GENESIS_JSON="${DATA_DIR}/execution_genesis.json"
EXECUTION_GENESIS_BLOCK_JSON="${DATA_DIR}/execution_genesis_block.json"
Expand All @@ -836,7 +833,7 @@ EXECUTION_GENESIS_BLOCK_JSON="${DATA_DIR}/execution_genesis_block.json"
# currently hard-codes some merkle branches that won't match the random deposits generated
# by this simulation. This doesn't happen to produce problems only by accident. If we enable
# the `deposit_root` safety-checks in the deposit downloader, it will detect the discrepancy.
sed "s/SHANGHAI_FORK_TIME/${SHANGHAI_FORK_TIME}/g; s/CANCUN_FORK_TIME/${CANCUN_FORK_TIME}/g" \
sed "s/SHANGHAI_FORK_TIME/${SHANGHAI_FORK_TIME}/g; s/CANCUN_FORK_TIME/${CANCUN_FORK_TIME}/g; s/PRAGUE_FORK_TIME/${PRAGUE_FORK_TIME}/g" \
"${SCRIPTS_DIR}/execution_genesis.json.template" > "$EXECUTION_GENESIS_JSON"

DEPOSIT_CONTRACT_ADDRESS="0x4242424242424242424242424242424242424242"
Expand Down Expand Up @@ -904,8 +901,9 @@ done
--netkey-file=$CONTAINER_BOOTSTRAP_NETWORK_KEYFILE \
--insecure-netkey-password=true \
--genesis-time=$GENESIS_TIME \
--capella-fork-epoch=$CAPELLA_FORK_EPOCH \
--capella-fork-epoch=0 \
--deneb-fork-epoch=$DENEB_FORK_EPOCH \
--electra-fork-epoch=$ELECTRA_FORK_EPOCH \
--execution-genesis-block="$EXECUTION_GENESIS_BLOCK_JSON"

DIRECTPEER_ENR=$(
Expand All @@ -919,8 +917,8 @@ DIRECTPEER_ENR=$(
)

./scripts/make_prometheus_config.sh \
--nodes ${NUM_NODES} \
--base-metrics-port ${BASE_METRICS_PORT} \
--nodes "${NUM_NODES}" \
--base-metrics-port "${BASE_METRICS_PORT}" \
--config-file "${DATA_DIR}/prometheus.yml" || true # TODO: this currently fails on macOS,
# but it can be considered non-critical

Expand All @@ -936,8 +934,9 @@ DEPOSIT_CONTRACT_ADDRESS: ${DEPOSIT_CONTRACT_ADDRESS}
ETH1_FOLLOW_DISTANCE: 1
ALTAIR_FORK_EPOCH: 0
BELLATRIX_FORK_EPOCH: 0
CAPELLA_FORK_EPOCH: ${CAPELLA_FORK_EPOCH}
CAPELLA_FORK_EPOCH: 0
DENEB_FORK_EPOCH: ${DENEB_FORK_EPOCH}
ELECTRA_FORK_EPOCH: ${ELECTRA_FORK_EPOCH}
TERMINAL_TOTAL_DIFFICULTY: 0
EOF

Expand Down Expand Up @@ -1046,7 +1045,7 @@ for NUM_NODE in $(seq 1 $NUM_NODES); do
fi
done

for NUM_LC in $(seq 1 $LC_NODES); do
for NUM_LC in $(seq 1 "${LC_NODES}"); do
LC_DATA_DIR="${DATA_DIR}/lc${NUM_LC}"
rm -rf "${LC_DATA_DIR}"
scripts/makedir.sh "${LC_DATA_DIR}" 2>&1
Expand Down Expand Up @@ -1085,7 +1084,7 @@ fi
# give each node time to load keys
sleep 10

for NUM_NODE in $(seq 1 $NUM_NODES); do
for NUM_NODE in $(seq 1 "${NUM_NODES}"); do
NODE_DATA_DIR="${DATA_DIR}/node${NUM_NODE}"
CONTAINER_NODE_DATA_DIR="${CONTAINER_DATA_DIR}/node${NUM_NODE}"
VALIDATOR_DATA_DIR="${DATA_DIR}/validator${NUM_NODE}"
Expand Down Expand Up @@ -1137,7 +1136,7 @@ for NUM_NODE in $(seq 1 $NUM_NODES); do
--max-peers=$(( NUM_NODES + LC_NODES - 1 )) \
--data-dir="${CONTAINER_NODE_DATA_DIR}" \
${BOOTSTRAP_ARG} \
--jwt-secret=${JWT_FILE} \
--jwt-secret="${JWT_FILE}" \
"${WEB3_ARG[@]}" \
--payload-builder=${USE_PAYLOAD_BUILDER} \
--payload-builder-url="http://${PAYLOAD_BUILDER_HOST}:${PAYLOAD_BUILDER_PORT}" \
Expand Down Expand Up @@ -1241,7 +1240,7 @@ if [ "$LC_NODES" -ge "1" ]; then
LC_TRUSTED_BLOCK_ROOT="$(
"${CURL_BINARY}" -s "http://localhost:${BASE_REST_PORT}/eth/v1/beacon/headers/finalized" | \
"${JQ_BINARY}" -r '.data.root')"
for NUM_LC in $(seq 1 $LC_NODES); do
for NUM_LC in $(seq 1 "${LC_NODES}"); do
LC_DATA_DIR="${DATA_DIR}/lc${NUM_LC}"

WEB3_ARG=()
Expand Down Expand Up @@ -1297,18 +1296,18 @@ if [[ "$USE_HTOP" == "1" ]]; then
else
FAILED=0
for PID in $(echo "$PIDS_TO_WAIT" | tr ',' ' '); do
wait "$PID" || FAILED="$(( FAILED += 1 ))"
echo $PID has completed
wait "${PID}" || FAILED="$(( FAILED += 1 ))"
echo "${PID}" has completed
done
if [[ "$FAILED" != "0" ]]; then
echo "${FAILED} child processes had non-zero exit codes (or exited early)."
dump_logs
dump_logtrace
if [[ "${TIMEOUT_DURATION}" != "0" ]]; then
if uname | grep -qiE "mingw|msys"; then
taskkill //F //PID ${WATCHER_PID}
taskkill //F //PID "${WATCHER_PID}"
else
pkill -HUP -P ${WATCHER_PID}
pkill -HUP -P "${WATCHER_PID}"
fi
fi
exit 1
Expand All @@ -1319,9 +1318,9 @@ dump_logtrace

if [[ "${TIMEOUT_DURATION}" != "0" ]]; then
if uname | grep -qiE "mingw|msys"; then
taskkill //F //PID ${WATCHER_PID}
taskkill //F //PID "${WATCHER_PID}"
else
pkill -HUP -P ${WATCHER_PID}
pkill -HUP -P "${WATCHER_PID}"
fi
fi

Expand Down
20 changes: 3 additions & 17 deletions scripts/mainnet-non-overriden-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,9 @@ CAPELLA_FORK_VERSION: 0x03000000
# Deneb
DENEB_FORK_VERSION: 0x04000000
# (overriden in launch_local_testnet.sh) DENEB_FORK_EPOCH: 18446744073709551615

# EIP6110
EIP6110_FORK_VERSION: 0x05000000 # temporary stub
EIP6110_FORK_EPOCH: 18446744073709551615
# EIP7002
EIP7002_FORK_VERSION: 0x05000000 # temporary stub
EIP7002_FORK_EPOCH: 18446744073709551615
# WHISK
WHISK_FORK_VERSION: 0x06000000 # temporary stub
WHISK_FORK_EPOCH: 18446744073709551615

# Electra
ELECTRA_FORK_VERSION: 0x05000000
# (overriden in launch_local_testnet.sh) ELECTRA_FORK_EPOCH: 18446744073709551615

# Time parameters
# ---------------------------------------------------------------
Expand Down Expand Up @@ -156,9 +148,3 @@ MAX_REQUEST_BLOB_SIDECARS: 768
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096
# `6`
BLOB_SIDECAR_SUBNET_COUNT: 6

# Whisk
# `Epoch(2**8)`
WHISK_EPOCHS_PER_SHUFFLING_PHASE: 256
# `Epoch(2)`
WHISK_PROPOSER_SELECTION_GAP: 2
17 changes: 3 additions & 14 deletions scripts/minimal-non-overriden-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,9 @@ CAPELLA_FORK_VERSION: 0x03000001
# Deneb
DENEB_FORK_VERSION: 0x04000001
# (overriden in launch_local_testnet.sh) DENEB_FORK_EPOCH: 18446744073709551615

# EIP6110
EIP6110_FORK_VERSION: 0x05000001
EIP6110_FORK_EPOCH: 18446744073709551615
# EIP7002
EIP7002_FORK_VERSION: 0x05000001
EIP7002_FORK_EPOCH: 18446744073709551615
# WHISK
WHISK_FORK_VERSION: 0x06000001
WHISK_FORK_EPOCH: 18446744073709551615
# Electra
ELECTRA_FORK_VERSION: 0x05000001
# (overriden in launch_local_testnet.sh) ELECTRA_FORK_EPOCH: 18446744073709551615

# Time parameters
# ---------------------------------------------------------------
Expand Down Expand Up @@ -155,7 +148,3 @@ MAX_REQUEST_BLOB_SIDECARS: 768
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096
# `6`
BLOB_SIDECAR_SUBNET_COUNT: 6

# Whisk
WHISK_EPOCHS_PER_SHUFFLING_PHASE: 4
WHISK_PROPOSER_SELECTION_GAP: 1

0 comments on commit 181f5f9

Please sign in to comment.