Skip to content

Commit

Permalink
Merge branch 'master' into janb/field-note
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Oct 25, 2023
2 parents 128686e + 058de1e commit 65f20be
Show file tree
Hide file tree
Showing 27 changed files with 517 additions and 118 deletions.
25 changes: 25 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ jobs:
name: "Build"
command: cond_spot_run_build barretenberg-x86_64-linux-clang-assert 128

barretenberg-x86_64-linux-clang-sol:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Build"
command: cond_spot_run_build barretenberg-x86_64-linux-clang-sol 32

barretenberg-stdlib-tests:
docker:
- image: aztecprotocol/alpine-build-image
Expand Down Expand Up @@ -465,6 +476,17 @@ jobs:
name: "Build and test"
command: build aztec-node | add_timestamps

mainnet-fork:
machine:
image: ubuntu-2204:2023.07.2
resource_class: large
steps:
- *checkout
- *setup_env
- run:
name: "Build"
command: build mainnet-fork | add_timestamps

aztec-faucet:
machine:
image: ubuntu-2204:2023.07.2
Expand Down Expand Up @@ -1143,6 +1165,7 @@ workflows:
- barretenberg-x86_64-linux-clang-assert: *defaults
- barretenberg-x86_64-linux-clang-fuzzing: *defaults
- barretenberg-wasm-linux-clang: *defaults
- barretenberg-x86_64-linux-clang-sol: *defaults
- barretenberg-proof-system-tests: *bb_test
- barretenberg-honk-tests: *bb_test
- barretenberg-dsl-tests: *bb_test
Expand Down Expand Up @@ -1211,6 +1234,8 @@ workflows:
- l1-contracts: *defaults
- noir-contracts-build: *defaults

- mainnet-fork: *defaults

# Yarn Project
- yarn-project-base:
requires:
Expand Down
3 changes: 3 additions & 0 deletions barretenberg/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ sol/cache
sol/out
sol/Dockerfile
sol/lib
sol/.foundry
sol/cache
sol/out
cpp/build
cpp/srs_db/ignition
.gitmodules
2 changes: 1 addition & 1 deletion barretenberg/sol/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ out/
.vscode/settings.json
.foundry

build/
**/build*/*
7 changes: 7 additions & 0 deletions barretenberg/sol/.rebuild_patterns
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
^barretenberg/cpp/.*\.(cpp|cc|cxx|c\+\+|h|hpp|hxx|h\+\+|c|h|inl|inc|ipp|tpp|cmake)$
^barretenberg/cpp/.*CMakeLists\.txt$
^barretenberg/cpp/.*Dockerfile.*$
^barretenberg/cpp/scripts/
^barretenberg/sol/src/
^barretenberg/sol/scripts/
^barretenberg/sol/test/
7 changes: 4 additions & 3 deletions barretenberg/sol/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM alpine:3.17
FROM alpine:3.18
RUN apk update \
&& apk upgrade \
&& apk add --no-cache \
build-base \
clang15 \
clang16 \
openmp-dev \
cmake \
ninja \
Expand All @@ -15,7 +15,7 @@ WORKDIR /usr/src/barretenberg/cpp

COPY ./cpp .
# Build everything to ensure everything builds. All tests will be run from the result of this build.
RUN cmake --preset default && cmake --build --preset default --target solidity_key_gen solidity_proof_gen
RUN cmake --preset clang16 && cmake --build --preset clang16 --target solidity_key_gen solidity_proof_gen

FROM docker.io/frolvlad/alpine-glibc:alpine-3.17_glibc-2.34 as builder
RUN apk update && apk add git curl build-base openmp-dev bash
Expand All @@ -38,4 +38,5 @@ RUN cd ../cpp/srs_db && ./download_ignition.sh 3 && cd ../../sol

RUN ./scripts/init.sh

# TestBase is excluded as it is just boilerplate
RUN forge test --no-match-contract TestBase
9 changes: 9 additions & 0 deletions build_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ barretenberg-wasm-linux-clang:
dockerfile: dockerfiles/Dockerfile.wasm-linux-clang
rebuildPatterns: .rebuild_patterns

barretenberg-x86_64-linux-clang-sol:
buildDir: barretenberg
dockerfile: sol/Dockerfile
rebuildPatterns: sol/.rebuild_patterns

bb.js:
buildDir: barretenberg/ts
dependencies:
Expand Down Expand Up @@ -174,6 +179,10 @@ p2p-bootstrap:
dependencies:
- yarn-project

mainnet-fork:
buildDir: iac/mainnet-fork
projectDir: iac/mainnet-fork

docs:
buildDir: .
dockerfile: docs/Dockerfile
Expand Down
18 changes: 18 additions & 0 deletions iac/mainnet-fork/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:focal

# Install nginx
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get update && apt install -y git curl nginx

# Copy nginx config
COPY . .
COPY nginx/gateway.conf /etc/nginx/gateway.conf
COPY nginx/nginx.conf /etc/nginx/nginx.conf

# Install foundry
RUN ./scripts/install_foundry.sh
ENV PATH="./foundry/bin:${PATH}"

# Run anvil and nginx
EXPOSE 80
ENTRYPOINT ["sh", "-c", "./scripts/run_nginx_anvil.sh"]
14 changes: 14 additions & 0 deletions iac/mainnet-fork/nginx/gateway.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server {
listen 80 default_server;
listen 8545;

location = /{{API_KEY}} {
proxy_pass http://0.0.0.0:8544;
rewrite ^/{{API_KEY}}(.*) /$1 break;
}

# Error responses
error_page 404 = @400; # Treat invalid paths as bad requests
proxy_intercept_errors on; # Do not send backend errors to client
default_type application/json; # If no content-type, assume JSON
}
53 changes: 53 additions & 0 deletions iac/mainnet-fork/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;


include /etc/nginx/gateway.conf;
include /etc/nginx/conf.d/*.conf;
}

21 changes: 21 additions & 0 deletions iac/mainnet-fork/scripts/install_foundry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
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"

# 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
28 changes: 28 additions & 0 deletions iac/mainnet-fork/scripts/run_nginx_anvil.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -eum pipefail

# Replace API_KEY in nginx config
echo "Replacing api key with $API_KEY in nginx config..."
sed -i 's/{{API_KEY}}/'$API_KEY'/' /etc/nginx/gateway.conf

# Run nginx and anvil alongside each other
trap 'kill $(jobs -p)' SIGTERM

# Anvil defaults - Nginx assumes these values to be as they are
HOST="0.0.0.0"
PORT=8544
ETHEREUM_HOST=$HOST:$PORT

# Data directory for anvil state
mkdir -p /data

# Run anvil silently
.foundry/bin/anvil --silent --host $HOST -p $PORT -m "$MNEMONIC" -f=https://mainnet.infura.io/v3/$INFURA_API_KEY --chain-id=$CHAIN_ID --fork-block-number=15918000 --block-base-fee-per-gas=10 -s=$SNAPSHOT_FREQUENCY --state=./data/state --balance=1000000000000000000 >/dev/null &

echo "Waiting for ethereum host at $ETHEREUM_HOST..."
while ! curl -s $ETHEREUM_HOST >/dev/null; do sleep 1; done

echo "Starting nginx..."
nginx &
wait
15 changes: 15 additions & 0 deletions iac/mainnet-fork/scripts/wait_for_fork
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

# When destroying and applying mainnet fork terraform, it may not be
# ready for a while, as it must register with DNS etc.
# This script waits on a healthy status from the fork - a valid response to the chainid request
# We retry every 20 seconds, and wait for a total of 5 minutes (15 times)

export ETHEREUM_HOST="https://aztec-mainnet-fork.aztec.network:8545/$FORK_API_KEY"

curl -H "Content-Type: application/json" -X POST --data '{"method":"eth_chainId","params":[],"id":33,"jsonrpc":"2.0"}' \
--connect-timeout 30 \
--retry 15 \
--retry-delay 20 \
$ETHEREUM_HOST
Loading

0 comments on commit 65f20be

Please sign in to comment.