From 85aeb899f6010c4389da77b288d6ee8f79f0c103 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 21 Aug 2024 20:19:45 +0800 Subject: [PATCH] Fix the l3node (#41) * Fix the L3 node * Add comments for l3node with espresso mode * Fix smoke test * Add l3 node test in smoke test * Separate the l3 test bash * Add flake.nix --------- Co-authored-by: sveitser --- .envrc | 7 +++ .github/workflows/smoke-test.yml | 9 +++- docker-compose.yaml | 13 ++++++ flake.lock | 75 ++++++++++++++++++++++++++++++++ flake.nix | 40 +++++++++++++++++ scripts/config.ts | 13 +++++- smoke-test-l3.bash | 31 +++++++++++++ smoke-test.bash | 4 +- test-node.bash | 23 +++++++--- 9 files changed, 205 insertions(+), 10 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100755 smoke-test-l3.bash diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..5cb534cc --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +if ! has nix_direnv_version || ! nix_direnv_version 3.0.5; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-RuwIS+QKFj/T9M2TFXScjBsLR6V3A17YVoEW/Q6AZ1w=" +fi + +use nix +watch_file flake.nix +watch_file flake.lock diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index 9f4b74f6..9c275fd6 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -17,6 +17,11 @@ concurrency: jobs: smoke_test: + + strategy: + matrix: + test-script: [ ./smoke-test.bash, ./smoke-test-l3.bash ] + runs-on: ubuntu-24.04 steps: @@ -61,7 +66,7 @@ jobs: build-args: | TOKEN_BRIDGE_BRANCH=v1.2.2 - - name: Start Smoke Test with Latest Espresso Image + - name: Smoke Test with Latest Espresso Image run: | - ./smoke-test.bash + ${{ matrix.test-script }} timeout-minutes: 30 diff --git a/docker-compose.yaml b/docker-compose.yaml index c4c5b3f4..a8d2aecd 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -306,6 +306,7 @@ services: depends_on: - sequencer - validation_node + - espresso-dev-node validation_node: pid: host # allow debugging @@ -376,6 +377,18 @@ services: - ESPRESSO_DEV_NODE_PORT - RUST_LOG=info - RUST_LOG_FORMAT + - ESPRESSO_DEPLOYER_ALT_CHAIN_PROVIDERS + - ESPRESSO_DEPLOYER_ALT_MNEMONICS + - ESPRESSO_SEQUENCER_DEPLOYER_ALT_INDICES + depends_on: + - geth + - sequencer + healthcheck: + test: ["CMD-SHELL", "curl -fL http://localhost:$ESPRESSO_DEV_NODE_PORT || exit 1"] + interval: 30s + timeout: 10s + retries: 5 + start_period: 40s extra_hosts: - "host.docker.internal:host-gateway" diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..a7cc8d2d --- /dev/null +++ b/flake.lock @@ -0,0 +1,75 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "foundry": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1722676286, + "narHash": "sha256-wEDJdvwRZF2ErQ33nQ0Lqn/48XrPbaadv56/bM2MSZU=", + "owner": "shazow", + "repo": "foundry.nix", + "rev": "d84c83b1c1722c8742b3d2d84c9386814d75384e", + "type": "github" + }, + "original": { + "owner": "shazow", + "ref": "monthly", + "repo": "foundry.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1666753130, + "narHash": "sha256-Wff1dGPFSneXJLI2c0kkdWTgxnQ416KE6X4KnFkgPYQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f540aeda6f677354f1e7144ab04352f61aaa0118", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1721379653, + "narHash": "sha256-8MUgifkJ7lkZs3u99UDZMB4kbOxvMEXQZ31FO3SopZ0=", + "rev": "1d9c2c9b3e71b9ee663d11c5d298727dace8d374", + "revCount": 655136, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.655136%2Brev-1d9c2c9b3e71b9ee663d11c5d298727dace8d374/0190cd4f-c0eb-72cb-834b-ac854aa282dc/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.%2A.tar.gz" + } + }, + "root": { + "inputs": { + "foundry": "foundry", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..5b9f07d8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "A Nix-flake-based Node.js development environment"; + + inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; + inputs.foundry.url = "github:shazow/foundry.nix/monthly"; # Use monthly branch for permanent releases + + outputs = { self, nixpkgs, foundry }: + let + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { + pkgs = import nixpkgs { + inherit system; overlays = [ + foundry.overlay + self.overlays.default + ]; + }; + }); + in + { + overlays.default = final: prev: rec { + nodejs = prev.nodejs; + yarn = (prev.yarn.override { inherit nodejs; }); + }; + + devShells = forEachSupportedSystem ({ pkgs }: { + default = pkgs.mkShell { + packages = with pkgs; [ + nodejs + yarn + openssl # used by test-node.bash + foundry-bin + ]; + shellHook = '' + yarn install --cwd "$PWD/scripts" + export PATH="$PWD/scripts/node_modules/.bin:$PATH" + ''; + }; + }); + }; +} diff --git a/scripts/config.ts b/scripts/config.ts index be84b412..16eb273e 100644 --- a/scripts/config.ts +++ b/scripts/config.ts @@ -334,6 +334,12 @@ function writeConfigs(argv: any) { l3Config.node["delayed-sequencer"]["use-merge-finality"] = false l3Config.node["batch-poster"].enable = true l3Config.node["batch-poster"]["redis-url"] = "" + if (argv.espresso) { + l3Config.execution.sequencer.espresso = true + l3Config.execution.sequencer["hotshot-url"] = argv.espressoUrl + l3Config.node.feed.output.enable = true + l3Config.node.dangerous["no-sequencer-coordinator"] = true + } fs.writeFileSync(path.join(consts.configpath, "l3node_config.json"), JSON.stringify(l3Config)) let validationNodeConfig = JSON.parse(JSON.stringify({ @@ -405,6 +411,7 @@ function writeL3ChainConfig(argv: any) { "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "eip155Block": 0, "eip158Block": 0, + "espresso": argv.espresso, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0, @@ -422,9 +429,13 @@ function writeL3ChainConfig(argv: any) { "DataAvailabilityCommittee": false, "InitialArbOSVersion": 30, "InitialChainOwner": argv.l2owner, - "GenesisBlockNum": 0 + "GenesisBlockNum": 0, + "EnableEspresso": false } } + if (argv.espresso) { + l3ChainConfig.arbitrum.EnableEspresso = true + } const l3ChainConfigJSON = JSON.stringify(l3ChainConfig) fs.writeFileSync(path.join(consts.configpath, "l3_chain_config.json"), l3ChainConfigJSON) } diff --git a/smoke-test-l3.bash b/smoke-test-l3.bash new file mode 100755 index 00000000..b992cc7c --- /dev/null +++ b/smoke-test-l3.bash @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +./test-node.bash --init-force --espresso --latest-espresso-image --l3node --l3-token-bridge --l3-fee-token --detach + +echo "Sending L3 transaction" +user=user_l3 +./test-node.bash script send-l3 --ethamount 5 --to $user --wait +userAddress=$(docker compose run scripts print-address --account $user | tail -n 1 | tr -d '\r\n') + +balance=$(cast balance $userAddress --rpc-url http://localhost:3347) + +if [ "$balance" -eq 0 ]; then + echo "Transfer failed in l3 node" + exit 1 +fi + +rollupAddress=$(docker compose run --entrypoint sh poster -c "jq -r '.[0].rollup.rollup' /config/deployed_l3_chain_info.json | tail -n 1 | tr -d '\r\n'") +while true; do + confirmed=$(cast call --rpc-url http://localhost:8547 $rollupAddress 'latestConfirmed()(uint256)') + echo "Number of confirmed staking nodes: $confirmed" + if [ "$confirmed" -gt 0 ]; then + break + else + echo "Waiting for more confirmed nodes ..." + fi + sleep 5 +done + +echo "Smoke test succeeded." +docker compose down diff --git a/smoke-test.bash b/smoke-test.bash index 5411af2c..89b36720 100755 --- a/smoke-test.bash +++ b/smoke-test.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -./test-node.bash --espresso --latest-espresso-image --validate --tokenbridge --init --detach +./test-node.bash --espresso --latest-espresso-image --validate --tokenbridge --init-force --detach # Sending L2 transaction ./test-node.bash script send-l2 --ethamount 100 --to user_l2user --wait @@ -18,4 +18,4 @@ while true; do sleep 5 done -echo "Smoke test succeeded" +docker compose down diff --git a/test-node.bash b/test-node.bash index 3e4db1d8..3d8a231c 100755 --- a/test-node.bash +++ b/test-node.bash @@ -45,9 +45,11 @@ l3node=false consensusclient=false redundantsequencers=0 lightClientAddr=0xb6eb235fa509e3206f959761d11e3777e16d0e98 +lightClientAddrForL3=0x5e36aa9caaf5f708fca5c04d2d4c776a62b2b258 dev_build_nitro=false dev_build_blockscout=false espresso=false +l2_espresso=false latest_espresso_image=false l3_custom_fee_token=false l3_token_bridge=false @@ -96,6 +98,7 @@ while [[ $# -gt 0 ]]; do --espresso) simple=false espresso=true + l2_espresso=true shift ;; --latest-espresso-image) @@ -277,13 +280,21 @@ elif ! $simple; then fi if $l3node; then NODES="$NODES l3node" + export ESPRESSO_DEPLOYER_ALT_CHAIN_PROVIDERS="http://sequencer:8547" + export ESPRESSO_DEPLOYER_ALT_MNEMONICS="indoor dish desk flag debris potato excuse depart ticket judge file exit" + export ESPRESSO_SEQUENCER_DEPLOYER_ALT_INDICES="6" fi if $blockscout; then NODES="$NODES blockscout" fi if $espresso; then - if $force_build; then + if $l3node; then + # If we run the `l3node` with enabling espresso mode, then the + # l2 node will run without `espresso` mode. + l2_espresso=false + fi + if $force_build && $l2_espresso; then INITIAL_SEQ_NODES="$INITIAL_SEQ_NODES espresso-dev-node" else NODES="$NODES espresso-dev-node" @@ -396,9 +407,10 @@ if $force_init; then docker compose run scripts send-l1 --ethamount 0.0001 --from user_l1user --to user_l1user_b --wait --delay 500 --times 1000000 > /dev/null & l2ownerAddress=`docker compose run scripts print-address --account l2owner | tail -n 1 | tr -d '\r\n'` + echo $l2ownerAddress echo == Writing l2 chain config - docker compose run scripts --l2owner $l2ownerAddress write-l2-chain-config --espresso $espresso + docker compose run scripts --l2owner $l2ownerAddress write-l2-chain-config --espresso $l2_espresso sequenceraddress=`docker compose run scripts print-address --account sequencer | tail -n 1 | tr -d '\r\n'` l2ownerKey=`docker compose run scripts print-private-key --account l2owner | tail -n 1 | tr -d '\r\n'` @@ -407,13 +419,14 @@ if $force_init; then echo == Deploying L2 chain docker compose run -e PARENT_CHAIN_RPC="http://geth:8545" -e DEPLOYER_PRIVKEY=$l2ownerKey -e PARENT_CHAIN_ID=$l1chainid -e CHILD_CHAIN_NAME="arb-dev-test" -e MAX_DATA_SIZE=117964 -e OWNER_ADDRESS=$l2ownerAddress -e WASM_MODULE_ROOT=$wasmroot -e SEQUENCER_ADDRESS=$sequenceraddress -e AUTHORIZE_VALIDATORS=10 -e CHILD_CHAIN_CONFIG_PATH="/config/l2_chain_config.json" -e CHAIN_DEPLOYMENT_INFO="/config/deployment.json" -e CHILD_CHAIN_INFO="/config/deployed_chain_info.json" -e LIGHT_CLIENT_ADDR=$lightClientAddr rollupcreator create-rollup-testnode docker compose run --entrypoint sh rollupcreator -c "jq [.[]] /config/deployed_chain_info.json > /config/l2_chain_info.json" + docker compose run --entrypoint sh rollupcreator -c "cat /config/l2_chain_info.json" if $simple; then echo == Writing configs docker compose run scripts write-config --simple else echo == Writing configs - docker compose run scripts write-config --espresso $espresso --lightClientAddress $lightClientAddr + docker compose run scripts write-config --espresso $l2_espresso --lightClientAddress $lightClientAddr echo == Initializing redis docker compose up --wait redis @@ -460,7 +473,7 @@ if $force_init; then echo == Writing l3 chain config l3owneraddress=`docker compose run scripts print-address --account l3owner | tail -n 1 | tr -d '\r\n'` echo l3owneraddress $l3owneraddress - docker compose run scripts --l2owner $l3owneraddress write-l3-chain-config + docker compose run scripts --l2owner $l3owneraddress write-l3-chain-config --espresso $espresso if $l3_custom_fee_token; then echo == Deploying custom fee token @@ -474,7 +487,7 @@ if $force_init; then l3ownerkey=`docker compose run scripts print-private-key --account l3owner | tail -n 1 | tr -d '\r\n'` l3sequenceraddress=`docker compose run scripts print-address --account l3sequencer | tail -n 1 | tr -d '\r\n'` - docker compose run -e DEPLOYER_PRIVKEY=$l3ownerkey -e PARENT_CHAIN_RPC="http://sequencer:8547" -e PARENT_CHAIN_ID=412346 -e CHILD_CHAIN_NAME="orbit-dev-test" -e MAX_DATA_SIZE=104857 -e OWNER_ADDRESS=$l3owneraddress -e WASM_MODULE_ROOT=$wasmroot -e SEQUENCER_ADDRESS=$l3sequenceraddress -e AUTHORIZE_VALIDATORS=10 -e CHILD_CHAIN_CONFIG_PATH="/config/l3_chain_config.json" -e CHAIN_DEPLOYMENT_INFO="/config/l3deployment.json" -e CHILD_CHAIN_INFO="/config/deployed_l3_chain_info.json" $EXTRA_L3_DEPLOY_FLAG rollupcreator create-rollup-testnode + docker compose run -e DEPLOYER_PRIVKEY=$l3ownerkey -e PARENT_CHAIN_RPC="http://sequencer:8547" -e PARENT_CHAIN_ID=412346 -e CHILD_CHAIN_NAME="orbit-dev-test" -e MAX_DATA_SIZE=104857 -e OWNER_ADDRESS=$l3owneraddress -e WASM_MODULE_ROOT=$wasmroot -e SEQUENCER_ADDRESS=$l3sequenceraddress -e AUTHORIZE_VALIDATORS=10 -e CHILD_CHAIN_CONFIG_PATH="/config/l3_chain_config.json" -e CHAIN_DEPLOYMENT_INFO="/config/l3deployment.json" -e CHILD_CHAIN_INFO="/config/deployed_l3_chain_info.json" -e LIGHT_CLIENT_ADDR=$lightClientAddrForL3 $EXTRA_L3_DEPLOY_FLAG rollupcreator create-rollup-testnode docker compose run --entrypoint sh rollupcreator -c "jq [.[]] /config/deployed_l3_chain_info.json > /config/l3_chain_info.json" echo == Funding l3 funnel and dev key