diff --git a/.github/ci-setup-action/action.yml b/.github/ci-setup-action/action.yml index 15df4df1a28..0c6fee9bbb5 100644 --- a/.github/ci-setup-action/action.yml +++ b/.github/ci-setup-action/action.yml @@ -18,7 +18,7 @@ runs: id: cache-submodules uses: actions/cache@v3 with: - path: .git + path: .git/modules key: submodules-${{ hashFiles('.gitmodules') }} - name: Checkout Submodules diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d42849a778a..b282d649ee7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,6 @@ jobs: - name: Build working-directory: ./yarn-project run: | - # push to registry earthly-cloud build x86 --push +build-end-to-end # We base our e2e list used in e2e-x86 off the targets in ./yarn-project/end-to-end @@ -111,14 +110,14 @@ jobs: run: | docker pull aztecprotocol/aztec-cache:$(git rev-parse HEAD) docker pull aztecprotocol/end-to-end-cache:$(git rev-parse HEAD) + docker pull aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-amd64:latest docker tag aztecprotocol/aztec-cache:$(git rev-parse HEAD) aztecprotocol/aztec:latest docker tag aztecprotocol/end-to-end-cache:$(git rev-parse HEAD) aztecprotocol/end-to-end:latest - + docker tag aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-amd64:latest aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-amd64:latest - name: Test working-directory: ./yarn-project/end-to-end/ run: | - # we blank earthly token just to be sure this is a pure local run - EARTHLY_TOKEN="" earthly -P --no-output +${{ matrix.test }} --e2e_mode=cache + earthly -P --no-output +${{ matrix.test }} --e2e_mode=cache # barretenberg (prover) native tests bb-native-tests: diff --git a/Earthfile b/Earthfile index 299c6e4de4d..8ecbc266c06 100644 --- a/Earthfile +++ b/Earthfile @@ -13,7 +13,7 @@ build-ci: BUILD ./noir/+packages BUILD ./noir/+nargo BUILD ./noir-projects/+build - BUILD ./yarn-project/+end-to-end-minimal + BUILD ./yarn-project/+end-to-end BUILD ./yarn-project/+aztec build-ci-small: diff --git a/bootstrap.sh b/bootstrap.sh index e6d67f21f65..cdecd4a065a 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -63,6 +63,7 @@ git submodule update --init --recursive PROJECTS=( barretenberg noir + foundry l1-contracts avm-transpiler noir-projects diff --git a/foundry/.gitignore b/foundry/.gitignore new file mode 100644 index 00000000000..532fb7016f2 --- /dev/null +++ b/foundry/.gitignore @@ -0,0 +1,2 @@ +bin +foundry-repo \ No newline at end of file diff --git a/foundry/Dockerfile b/foundry/Dockerfile deleted file mode 100644 index 65171755174..00000000000 --- a/foundry/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM alpine:3.18 as build-environment - -ARG TARGETARCH -WORKDIR /opt - -RUN apk add clang lld curl build-base linux-headers git \ - && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh \ - && chmod +x ./rustup.sh \ - && ./rustup.sh -y - -RUN [[ "$TARGETARCH" = "arm64" ]] && echo "export CFLAGS=-mno-outline-atomics" >> $HOME/.profile || true - -WORKDIR /opt -RUN git clone --depth 1 --branch nightly-de33b6af53005037b463318d2628b5cfcaf39916 https://github.com/foundry-rs/foundry.git -WORKDIR /opt/foundry - -RUN source $HOME/.profile && cargo build --release \ - && mkdir out \ - && mv target/release/forge out/forge \ - && mv target/release/cast out/cast \ - && mv target/release/anvil out/anvil \ - && mv target/release/chisel out/chisel \ - && strip out/forge \ - && strip out/cast \ - && strip out/chisel \ - && strip out/anvil; - -FROM alpine:3.18 as foundry-client -RUN apk add --no-cache linux-headers git -COPY --from=build-environment /opt/foundry/out/forge /usr/local/bin/forge -COPY --from=build-environment /opt/foundry/out/cast /usr/local/bin/cast -COPY --from=build-environment /opt/foundry/out/anvil /usr/local/bin/anvil -COPY --from=build-environment /opt/foundry/out/chisel /usr/local/bin/chisel -RUN adduser -Du 1000 foundry -ENTRYPOINT ["/bin/sh", "-c"] \ No newline at end of file diff --git a/foundry/Earthfile b/foundry/Earthfile index 383d946407c..f14a5502e5a 100644 --- a/foundry/Earthfile +++ b/foundry/Earthfile @@ -1,18 +1,22 @@ VERSION 0.8 +builder: + FROM rust:bookworm + ARG TARGETARCH + WORKDIR /usr/src/foundry + COPY bootstrap.sh bootstrap.sh + RUN ./bootstrap.sh && rm -rf foundry-repo + SAVE ARTIFACT bin /usr/src/foundry/bin + build: + FROM ubuntu:lunar ARG TARGETARCH - FROM DOCKERFILE . + COPY --dir +builder/usr/src/foundry/bin /usr/src/foundry/bin + SAVE ARTIFACT /usr/src/foundry/bin /usr/src/foundry/bin SAVE IMAGE --push aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-$TARGETARCH:latest -# Relies on both steps being published -build-multiplatform: - FROM --platform=linux/amd64 aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-amd64:latest - SAVE IMAGE --push aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991:latest - FROM --platform=linux/arm64 aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-arm64:latest - SAVE IMAGE --push aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991:latest - -get: - ARG TARGETARCH - # If this is failing, we need to run earthly --push +build on both archs then earthly --push +build-multiplatform on any runner - FROM aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991:latest +build-save-local: + # for renaming the image as a local image, used with e2e runners + ARG image + FROM +build + SAVE IMAGE $image \ No newline at end of file diff --git a/foundry/bootstrap.sh b/foundry/bootstrap.sh new file mode 100755 index 00000000000..446ddd6228e --- /dev/null +++ b/foundry/bootstrap.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eu + +cd $(dirname $0) + +rm -rf bin share + +[ "${TARGETARCH:-$(uname -m)}" = "arm64" ] && echo "export CFLAGS=-mno-outline-atomics" >> $HOME/.profile || true + +if [ ! -d './foundry-repo' ]; then + git clone --depth 1 --branch nightly-de33b6af53005037b463318d2628b5cfcaf39916 \ + https://github.com/foundry-rs/foundry.git foundry-repo +fi + +(cd foundry-repo && cargo build --profile local) + +mkdir bin \ + && mv foundry-repo/target/local/forge bin/forge \ + && mv foundry-repo/target/local/cast bin/cast \ + && mv foundry-repo/target/local/anvil bin/anvil \ + && mv foundry-repo/target/local/chisel bin/chisel \ + && strip bin/forge \ + && strip bin/cast \ + && strip bin/chisel \ + && strip bin/anvil; \ No newline at end of file diff --git a/l1-contracts/Earthfile b/l1-contracts/Earthfile index 7943106fa41..efa14c84819 100644 --- a/l1-contracts/Earthfile +++ b/l1-contracts/Earthfile @@ -1,23 +1,23 @@ VERSION 0.8 -FROM ubuntu:lunar -RUN apt update && apt install curl git jq bash nodejs npm python3.11-full python3-pip -y -# Use virtualenv, do not try to use pipx, it's not working. -RUN python3 -m venv /root/.venv -RUN /root/.venv/bin/pip3 install slither-analyzer==0.10.0 slitherin==0.5.0 -RUN curl -L https://foundry.paradigm.xyz | bash +build: + FROM ubuntu:lunar + RUN apt update && apt install curl git jq bash nodejs npm python3.11-full python3-pip -y -# Set env variables for foundry and venv -ENV PATH="${PATH}:/root/.foundry/bin:/root/.venv/bin" -RUN foundryup --version nightly-de33b6af53005037b463318d2628b5cfcaf39916 + # Use virtualenv, do not try to use pipx, it's not working. + RUN python3 -m venv /root/.venv + RUN /root/.venv/bin/pip3 install slither-analyzer==0.10.0 slitherin==0.5.0 + ENV PATH="${PATH}:/root/.venv/bin" -# Install yarn and solhint. -RUN npm install --global yarn solhint + # Install yarn and solhint. + RUN npm install --global yarn solhint -WORKDIR /usr/src -COPY --dir lib scripts src terraform test *.json *.toml *.sh . + # Install our build of foundry. + COPY --dir ../foundry/+build/usr/src/foundry/bin /usr/src/foundry/bin + ENV PATH="${PATH}:/usr/src/foundry/bin" -build: + WORKDIR /usr/src/l1-contracts + COPY --dir lib scripts src terraform test *.json *.toml *.sh . RUN git init && git add . && yarn lint && yarn slither && yarn slither-has-diff RUN forge clean && forge fmt --check && forge build && forge test --no-match-contract UniswapPortalTest - SAVE ARTIFACT out + SAVE ARTIFACT /usr/src/l1-contracts /usr/src/l1-contracts \ No newline at end of file diff --git a/l1-contracts/bootstrap.sh b/l1-contracts/bootstrap.sh index 547735ef7a2..7274d3dac7d 100755 --- a/l1-contracts/bootstrap.sh +++ b/l1-contracts/bootstrap.sh @@ -19,17 +19,14 @@ fi # Attempt to just pull artefacts from CI and exit on success. [ -n "${USE_CACHE:-}" ] && ./bootstrap_cache.sh && exit -# Install foundry. -. ./scripts/install_foundry.sh - # Clean rm -rf broadcast cache out serve # Install -forge install --no-commit +../foundry/bin/forge install --no-commit # Ensure libraries are at the correct version git submodule update --init --recursive ./lib # Compile contracts -forge build +../foundry/bin/forge build diff --git a/l1-contracts/package.json b/l1-contracts/package.json index 52841e0aa30..bd9aab6899d 100644 --- a/l1-contracts/package.json +++ b/l1-contracts/package.json @@ -7,9 +7,9 @@ "solhint": "https://github.com/LHerskind/solhint#master" }, "scripts": { - "format": "./.foundry/bin/forge fmt", + "format": "../foundry/bin/forge fmt", "lint": "solhint --config ./.solhint.json --fix \"src/**/*.sol\"", - "slither": "forge clean && forge build --build-info --skip '*/test/**' --force && slither . --checklist --ignore-compile --show-ignored-findings --config-file ./slither.config.json | tee slither_output.md", + "slither": "../foundry/bin/forge clean && ../foundry/bin/forge build --build-info --skip '*/test/**' --force && slither . --checklist --ignore-compile --show-ignored-findings --config-file ./slither.config.json | tee slither_output.md", "slither-has-diff": "./slither_has_diff.sh" } } diff --git a/l1-contracts/scripts/install_foundry.sh b/l1-contracts/scripts/install_foundry.sh deleted file mode 100755 index e1866372587..00000000000 --- a/l1-contracts/scripts/install_foundry.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -set -eu - -export FOUNDRY_DIR="$PWD/.foundry" -FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin" -BIN_URL="https://raw.githubusercontent.com/foundry-rs/foundry/master/foundryup/foundryup" -BIN_PATH="$FOUNDRY_BIN_DIR/foundryup" -FOUNDRY_MAN_DIR="$FOUNDRY_DIR/share/man/man1" -FOUNDRY_VERSION="nightly-de33b6af53005037b463318d2628b5cfcaf39916" -FOUNDRY_SHORT_VERSION=$(echo "${FOUNDRY_VERSION#*-}" | cut -c1-6) -echo "$FOUNDRY_SHORT_VERSION" - -# Check if forge is installed and matches the expected version -if command -v "forge" > /dev/null 2>&1 && [[ "$(forge --version)" == *"$FOUNDRY_SHORT_VERSION"* ]]; then - echo "Foundry is already installed and at the correct version." -else - # Clean - rm -rf $FOUNDRY_DIR - - # Install foundryup. - mkdir -p $FOUNDRY_BIN_DIR - mkdir -p $FOUNDRY_MAN_DIR - curl -# -L $BIN_URL -o $BIN_PATH - chmod +x $BIN_PATH - export PATH=$FOUNDRY_BIN_DIR:$PATH - - # Use version. - foundryup --version $FOUNDRY_VERSION -fi diff --git a/yarn-project/Earthfile b/yarn-project/Earthfile index e37d7332233..e083b45865b 100644 --- a/yarn-project/Earthfile +++ b/yarn-project/Earthfile @@ -1,89 +1,89 @@ VERSION 0.8 -FROM node:18.19.0 -RUN apt update && apt install -y jq curl perl && rm -rf /var/lib/apt/lists/* && apt-get clean -# copy bb-js and noir-packages -COPY ../barretenberg/ts/+build/build /usr/src/barretenberg/ts -COPY ../noir/+packages/packages /usr/src/noir/packages -# install acvm binary -COPY ../noir/+nargo/acvm /usr/bin/acvm -COPY --dir ../noir-projects/+build/. /usr/src/noir-projects -COPY ../l1-contracts/+build/out /usr/src/l1-contracts/out +deps: + LOCALLY + LET packages = $(git ls-files "**/package*.json" package*.json) + LET tsconfigs = $(git ls-files "**/tsconfig*.json" tsconfig*.json) + FROM node:18.19.0 + # copy bb-js and noir-packages + COPY ../barretenberg/ts/+build/build /usr/src/barretenberg/ts + COPY ../noir/+packages/packages /usr/src/noir/packages + WORKDIR /usr/src/yarn-project + COPY --dir .yarn .yarnrc.yml yarn.lock . + FOR file IN $packages + COPY $file $file + END + RUN yarn install --immutable + FOR file IN $tsconfigs + COPY $file $file + END + COPY scripts/update_package_jsons.mjs scripts/update_package_jsons.mjs + RUN yarn prepare:check -WORKDIR /usr/src/yarn-project -# copy source -COPY --dir * *.json .yarn .yarnrc.yml . + # We install a symlink to yarn-project's node_modules at a location that all portalled packages can find as they + # walk up the tree as part of module resolution. The supposedly idiomatic way of supporting module resolution + # correctly for portalled packages, is to use --preserve-symlinks when running node. + # This does kind of work, but jest doesn't honor it correctly, so this seems like a neat workaround. + # Also, --preserve-symlinks causes duplication of portalled instances such as bb.js, and breaks the singleton logic + # by initialising the module more than once. So at present I don't see a viable alternative. + RUN ln -s /usr/src/yarn-project/node_modules /usr/src/node_modules -# We install a symlink to yarn-project's node_modules at a location that all portalled packages can find as they -# walk up the tree as part of module resolution. The supposedly idiomatic way of supporting module resolution -# correctly for portalled packages, is to use --preserve-symlinks when running node. -# This does kind of work, but jest doesn't honor it correctly, so this seems like a neat workaround. -# Also, --preserve-symlinks causes duplication of portalled instances such as bb.js, and breaks the singleton logic -# by initialising the module more than once. So at present I don't see a viable alternative. -RUN ln -s /usr/src/yarn-project/node_modules /usr/src/node_modules - -# Target for main build process build: - FROM +source - ARG EARTHLY_CI - # TODO: Replace puppeteer with puppeteer-core to avoid this. + FROM +deps + RUN apt update && apt install -y jq curl perl && rm -rf /var/lib/apt/lists/* && apt-get clean + + COPY ../barretenberg/cpp/+preset-release/bin/bb /usr/src/barretenberg/cpp/build/bin/bb + COPY ../noir/+nargo/acvm /usr/bin/acvm + COPY --dir ../noir-projects/+build/. /usr/src/noir-projects + COPY ../l1-contracts/+build/usr/src/l1-contracts /usr/src/l1-contracts + + WORKDIR /usr/src/yarn-project + COPY . . ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true - RUN ./bootstrap.sh && yarn workspaces focus @aztec/cli @aztec/aztec --production - SAVE ARTIFACT /usr/src + RUN ./bootstrap.sh full -# TODO versioning flow at end before publish? -# ENV COMMIT_TAG=$EARTHLY_BUILD_SHA -# RUN ./scripts/version_packages.sh +aztec-prod: + FROM +build + RUN yarn workspaces focus @aztec/cli @aztec/aztec --production && yarn cache clean + SAVE ARTIFACT /usr/src /usr/src -# run: -# FROM node:18.19.1-slim -# ARG COMMIT_TAG="" -# ENV COMMIT_TAG=$COMMIT_TAG -# COPY --from=builder /usr/src /usr/src -# WORKDIR /usr/src/yarn-project -# ENTRYPOINT ["yarn"] +aztec-prod-slim: + FROM node:18.19.1-slim + COPY +aztec-prod/usr/src /usr/src aztec: - FROM +build - # ENV vars for using native ACVM simulation - ENV ACVM_BINARY_PATH="/usr/bin/acvm" ACVM_WORKING_DIRECTORY="/tmp/acvm" + FROM +aztec-prod-slim ENTRYPOINT ["node", "--no-warnings", "/usr/src/yarn-project/aztec/dest/bin/index.js"] EXPOSE 8080 - # TODO(AD) the following are the biggest node modules bundled, should they be deleted as they are build tools? - # 25840 @jest - # 31544 typescript - # 62368 @types -source: - # for debugging rebuilds - RUN echo CONTENT HASH $(find . -type f -exec sha256sum {} ';' | sort | sha256sum | awk '{print $1}') | tee .content-hash +cli: + FROM +aztec-prod-slim + ENTRYPOINT ["node", "--no-warnings", "/usr/src/yarn-project/cli/dest/bin/index.js"] + EXPOSE 8080 -end-to-end: - FROM +source - # compilation artifacts for end-to-end - # TODO encapsulate in bash script for cleanliness - RUN ./bootstrap.sh && \ - yarn workspace @aztec/end-to-end run build:web && \ - yarn workspaces focus @aztec/end-to-end --production \ - && yarn cache clean - # Build web bundle for browser tests - RUN yarn workspace @aztec/end-to-end run build:web +end-to-end-prod: + FROM +build RUN yarn workspaces focus @aztec/end-to-end --production && yarn cache clean - SAVE ARTIFACT /usr/src/* + SAVE ARTIFACT /usr/src /usr/src -end-to-end-minimal: - # end to end test runner - BUILD +aztec +end-to-end: FROM node:18.19.1-slim RUN apt-get update && apt-get install jq chromium netcat-openbsd -y ENV CHROME_BIN="/usr/bin/chromium" - COPY +end-to-end/. /usr/src + COPY +end-to-end-prod/usr/src /usr/src WORKDIR /usr/src/yarn-project/end-to-end ENTRYPOINT ["yarn", "test"] +all: + BUILD +aztec + BUILD +cli + BUILD +end-to-end + build-end-to-end: ARG EARTHLY_GIT_HASH - FROM +end-to-end-minimal + # pushes the foundry image + BUILD ../foundry/+build + FROM +end-to-end SAVE IMAGE --push aztecprotocol/end-to-end-cache:$EARTHLY_GIT_HASH FROM +aztec SAVE IMAGE --push aztecprotocol/aztec-cache:$EARTHLY_GIT_HASH \ No newline at end of file diff --git a/yarn-project/archiver/src/archiver/config.ts b/yarn-project/archiver/src/archiver/config.ts index fe1fb79e848..6badf1a7dc8 100644 --- a/yarn-project/archiver/src/archiver/config.ts +++ b/yarn-project/archiver/src/archiver/config.ts @@ -81,7 +81,7 @@ export function getConfigEnvVars(): ArchiverConfig { : EthAddress.ZERO, }; return { - rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/', + rpcUrl: ETHEREUM_HOST || '', archiverPollingIntervalMS: ARCHIVER_POLLING_INTERVAL_MS ? +ARCHIVER_POLLING_INTERVAL_MS : 1_000, viemPollingIntervalMS: ARCHIVER_VIEM_POLLING_INTERVAL_MS ? +ARCHIVER_VIEM_POLLING_INTERVAL_MS : 1_000, apiKey: API_KEY, diff --git a/yarn-project/bootstrap.sh b/yarn-project/bootstrap.sh index 8af45e5a19c..a4ac9c35137 100755 --- a/yarn-project/bootstrap.sh +++ b/yarn-project/bootstrap.sh @@ -23,14 +23,16 @@ cd "$(dirname "$0")" CMD=${1:-} -if [ -n "$CMD" ]; then - if [ "$CMD" = "clean" ]; then - git clean -fdx - exit 0 - else - echo "Unknown command: $CMD" - exit 1 - fi +if [ "$CMD" = "clean" ]; then + git clean -fdx + exit 0 +elif [ "$CMD" = "full" ]; then + yarn install --immutable + yarn build + exit 0 +elif [[ -n "$CMD" && "$CMD" != "fast" ]]; then + echo "Unknown command: $CMD" + exit 1 fi # Fast build does not delete everything first. diff --git a/yarn-project/end-to-end/Earthfile b/yarn-project/end-to-end/Earthfile index e5ad686c60e..0d7dbdba34c 100644 --- a/yarn-project/end-to-end/Earthfile +++ b/yarn-project/end-to-end/Earthfile @@ -15,8 +15,8 @@ E2E_TEST_LOCAL: ENV DEBUG="$debug" WITH DOCKER \ --load aztecprotocol/aztec:latest=../+aztec \ - --load aztecprotocol/end-to-end:latest=../+end-to-end-minimal \ - --load ghcr.io/foundry-rs/foundry:nightly-de33b6af53005037b463318d2628b5cfcaf39916=../../foundry/+get + --load aztecprotocol/end-to-end:latest=../+end-to-end \ + --load ghcr.io/foundry-rs/foundry:nightly-de33b6af53005037b463318d2628b5cfcaf39916=../../foundry/+build # Run our docker compose, ending whenever sandbox ends, filtering out noisy eth_getLogs RUN docker compose -f $compose_file up --exit-code-from=end-to-end --force-recreate END @@ -50,8 +50,8 @@ E2E_TEST_FROM_BUILD: # For ARM, we do use WITH DOCKER as we don't have many e2e tests, but note E2E_TEST_FROM_DOCKERHUB WITH DOCKER \ --load aztecprotocol/aztec:latest=../+aztec \ - --load aztecprotocol/end-to-end:latest=../+end-to-end-minimal \ - --load ghcr.io/foundry-rs/foundry:nightly-de33b6af53005037b463318d2628b5cfcaf39916=../../foundry/+get + --load aztecprotocol/end-to-end:latest=../+end-to-end \ + --load ghcr.io/foundry-rs/foundry:nightly-de33b6af53005037b463318d2628b5cfcaf39916=../../foundry/+build # Run our docker compose, ending whenever sandbox ends, filtering out noisy eth_getLogs RUN docker compose -f $compose_file up --exit-code-from=end-to-end --force-recreate END diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 091c8ca0c1d..27df3c3cada 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -54,8 +54,10 @@ "@types/lodash.every": "^4.6.7", "@types/memdown": "^3.0.3", "@types/node": "^18.7.23", + "@viem/anvil": "^0.0.9", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", + "get-port": "^7.1.0", "glob": "^10.3.10", "jest": "^29.5.0", "jest-mock-extended": "^3.0.5", diff --git a/yarn-project/end-to-end/scripts/anvil_kill_wrapper.sh b/yarn-project/end-to-end/scripts/anvil_kill_wrapper.sh new file mode 100755 index 00000000000..ddeea389ef2 --- /dev/null +++ b/yarn-project/end-to-end/scripts/anvil_kill_wrapper.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Find the parent of this script. +PARENT_PID=$(awk '{print $4}' /proc/$$/stat) + +# Start anvil in the background. +../../foundry/bin/anvil $@ & +CHILD_PID=$! + +cleanup() { + kill $CHILD_PID +} + +trap cleanup EXIT + +# Continuously check if the parent process is still alive. +while [ -d /proc/$PARENT_PID ]; do + sleep 1 +done \ No newline at end of file diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index c9db9da05b2..6e97bcbfd4f 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -49,7 +49,9 @@ import { getCanonicalGasToken, getCanonicalGasTokenAddress } from '@aztec/protoc import { PXEService, type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; import { type SequencerClient } from '@aztec/sequencer-client'; +import { type Anvil, createAnvil } from '@viem/anvil'; import * as fs from 'fs/promises'; +import getPort from 'get-port'; import * as path from 'path'; import { type Account, @@ -323,6 +325,17 @@ export async function setup( ): Promise { const config = { ...getConfigEnvVars(), ...opts }; + let anvil: Anvil | undefined; + + if (!config.rpcUrl) { + // Start anvil. + // We go via a wrapper script to ensure if the parent dies, anvil dies. + const ethereumHostPort = await getPort(); + config.rpcUrl = `http://localhost:${ethereumHostPort}`; + const anvil = createAnvil({ anvilBinary: './scripts/anvil_kill_wrapper.sh', port: ethereumHostPort }); + await anvil.start(); + } + // Enable logging metrics to a local file named after the test suite if (isMetricsLoggingRequested()) { const filename = path.join('log', getJobName() + '.jsonl'); @@ -382,6 +395,8 @@ export async function setup( logger(`Cleaning up ACVM temp directory ${acvmConfig.directoryToCleanup}`); await fs.rm(acvmConfig.directoryToCleanup, { recursive: true, force: true }); } + + await anvil?.stop(); }; return { diff --git a/yarn-project/ethereum/src/deploy_l1_contracts.ts b/yarn-project/ethereum/src/deploy_l1_contracts.ts index 6df49139bd9..1bb21fd76c0 100644 --- a/yarn-project/ethereum/src/deploy_l1_contracts.ts +++ b/yarn-project/ethereum/src/deploy_l1_contracts.ts @@ -232,7 +232,7 @@ export async function deployL1Contract( args, }); - const receipt = await publicClient.waitForTransactionReceipt({ hash }); + const receipt = await publicClient.waitForTransactionReceipt({ hash, pollingInterval: 100 }); const contractAddress = receipt.contractAddress; if (!contractAddress) { throw new Error(`No contract address found in receipt: ${JSON.stringify(receipt)}`); diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index e8cafc9ef00..722f749f9e6 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -400,9 +400,11 @@ __metadata: "@types/lodash.every": ^4.6.7 "@types/memdown": ^3.0.3 "@types/node": ^18.7.23 + "@viem/anvil": ^0.0.9 buffer: ^6.0.3 concurrently: ^7.6.0 crypto-browserify: ^3.12.0 + get-port: ^7.1.0 glob: ^10.3.10 jest: ^29.5.0 jest-mock-extended: ^3.0.5 @@ -4055,6 +4057,18 @@ __metadata: languageName: node linkType: hard +"@viem/anvil@npm:^0.0.9": + version: 0.0.9 + resolution: "@viem/anvil@npm:0.0.9" + dependencies: + execa: ^7.1.1 + get-port: ^6.1.2 + http-proxy: ^1.18.1 + ws: ^8.13.0 + checksum: 14c9f6593d860e889ade36daadd2e7d5e17d0bcb1254c18b85dbc81391488f570c2ef9b08a5736f2ca9666001fa1001fff84626817ab75cadbacff11c8628ebf + languageName: node + linkType: hard + "@webassemblyjs/ast@npm:1.11.6, @webassemblyjs/ast@npm:^1.11.5": version: 1.11.6 resolution: "@webassemblyjs/ast@npm:1.11.6" @@ -6838,6 +6852,13 @@ __metadata: languageName: node linkType: hard +"eventemitter3@npm:^4.0.0": + version: 4.0.7 + resolution: "eventemitter3@npm:4.0.7" + checksum: 1875311c42fcfe9c707b2712c32664a245629b42bb0a5a84439762dd0fd637fc54d078155ea83c2af9e0323c9ac13687e03cfba79b03af9f40c89b4960099374 + languageName: node + linkType: hard + "eventemitter3@npm:^5.0.1": version: 5.0.1 resolution: "eventemitter3@npm:5.0.1" @@ -7151,6 +7172,16 @@ __metadata: languageName: node linkType: hard +"follow-redirects@npm:^1.0.0": + version: 1.15.6 + resolution: "follow-redirects@npm:1.15.6" + peerDependenciesMeta: + debug: + optional: true + checksum: a62c378dfc8c00f60b9c80cab158ba54e99ba0239a5dd7c81245e5a5b39d10f0c35e249c3379eae719ff0285fff88c365dd446fab19dee771f1d76252df1bbf5 + languageName: node + linkType: hard + "for-each@npm:^0.3.3": version: 0.3.3 resolution: "for-each@npm:0.3.3" @@ -7396,6 +7427,20 @@ __metadata: languageName: node linkType: hard +"get-port@npm:^6.1.2": + version: 6.1.2 + resolution: "get-port@npm:6.1.2" + checksum: e3c3d591492a11393455ef220f24c812a28f7da56ec3e4a2512d931a1f196d42850b50ac6138349a44622eda6dc3c0ccd8495cd91376d968e2d9e6f6f849e0a9 + languageName: node + linkType: hard + +"get-port@npm:^7.1.0": + version: 7.1.0 + resolution: "get-port@npm:7.1.0" + checksum: f4d23b43026124007663a899578cc87ff37bfcf645c5c72651e9810ebafc759857784e409fb8e0ada9b90e5c5db089b0ae2f5f6b49fba1ce2e0aff86094ab17d + languageName: node + linkType: hard + "get-stream@npm:^5.1.0": version: 5.2.0 resolution: "get-stream@npm:5.2.0" @@ -7781,6 +7826,17 @@ __metadata: languageName: node linkType: hard +"http-proxy@npm:^1.18.1": + version: 1.18.1 + resolution: "http-proxy@npm:1.18.1" + dependencies: + eventemitter3: ^4.0.0 + follow-redirects: ^1.0.0 + requires-port: ^1.0.0 + checksum: f5bd96bf83e0b1e4226633dbb51f8b056c3e6321917df402deacec31dd7fe433914fc7a2c1831cf7ae21e69c90b3a669b8f434723e9e8b71fd68afe30737b6a5 + languageName: node + linkType: hard + "https-proxy-agent@npm:^7.0.1, https-proxy-agent@npm:^7.0.2": version: 7.0.2 resolution: "https-proxy-agent@npm:7.0.2" @@ -11666,6 +11722,13 @@ __metadata: languageName: node linkType: hard +"requires-port@npm:^1.0.0": + version: 1.0.0 + resolution: "requires-port@npm:1.0.0" + checksum: eee0e303adffb69be55d1a214e415cf42b7441ae858c76dfc5353148644f6fd6e698926fc4643f510d5c126d12a705e7c8ed7e38061113bdf37547ab356797ff + languageName: node + linkType: hard + "resolve-cwd@npm:^3.0.0": version: 3.0.0 resolution: "resolve-cwd@npm:3.0.0"