Skip to content

Commit

Permalink
feat: devnet updates (#7421)
Browse files Browse the repository at this point in the history
  • Loading branch information
spypsy authored Jul 16, 2024
1 parent f2c3091 commit 103f099
Show file tree
Hide file tree
Showing 62 changed files with 479 additions and 458 deletions.
17 changes: 17 additions & 0 deletions .github/scripts/wait_for_fork.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

DEPLOY_TAG=$1
TEST_FORK_API_KEY=$2

# 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://$DEPLOY_TAG-mainnet-fork.aztec.network:8545/$TEST_FORK_API_KEY"

curl -H "Content-Type: application/json" -X POST --data '{"method":"eth_chainId","params":[],"id":49,"jsonrpc":"2.0"}' \
--connect-timeout 30 \
--retry 15 \
--retry-delay 20 \
$ETHEREUM_HOST
63 changes: 43 additions & 20 deletions .github/workflows/devnet-deploys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ env:
GIT_COMMIT: ${{ github.sha }}
DEPLOY_TAG: devnet
FILE_PATH: ./l1-contracts/addresses.txt
L1_CHAIN_ID: 677692
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# TF Vars
TF_VAR_DOCKERHUB_ACCOUNT: aztecprotocol
TF_VAR_CHAIN_ID: 31337
TF_VAR_L1_CHAIN_ID: 677692
TF_VAR_BOOTNODE_1_PRIVATE_KEY: ${{ secrets.BOOTNODE_1_PRIVATE_KEY }}
TF_VAR_BOOTNODE_2_PRIVATE_KEY: ${{ secrets.BOOTNODE_2_PRIVATE_KEY }}
TF_VAR_SEQ_1_PUBLISHER_PRIVATE_KEY: ${{ secrets.SEQ_1_PUBLISHER_PRIVATE_KEY }}
TF_VAR_SEQ_2_PUBLISHER_PRIVATE_KEY: ${{ secrets.SEQ_2_PUBLISHER_PRIVATE_KEY }}
TF_VAR_DEPLOY_TAG: devnet
TF_VAR_API_KEY: ${{ secrets.FORK_API_KEY }}
TF_VAR_FORK_MNEMONIC: ${{ secrets.FORK_MNEMONIC }}
TF_VAR_INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}

jobs:
setup:
Expand All @@ -33,6 +38,9 @@ jobs:
build:
needs: setup
runs-on: ${{ github.actor }}-x86
outputs:
l1_contracts_changed: ${{ steps.check_l1_changes.outputs.result }}
mainnet_fork_changed: ${{ steps.check_fork_changes.outputs.result }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -46,10 +54,11 @@ jobs:
timeout-minutes: 40
# Run the build steps for each image with version and arch, push to dockerhub
run: |
earthly-ci --no-output --push ./yarn-project+export-aztec-arch --DIST_TAG=${{ env.DEPLOY_TAG }}
earthly-ci \
--no-output --push ./yarn-project+export-aztec-arch --DIST_TAG=${{ env.DEPLOY_TAG }}
- name: Check if L1 contracts need deployment
id: check_changes_build
id: check_l1_changes
uses: actions/github-script@v7
with:
script: |
Expand All @@ -58,6 +67,16 @@ jobs:
const fileChanged = changedFiles.includes('l1-contracts/REDEPLOY');
return fileChanged
- name: Check if mainnet fork needs deployment
id: check_fork_changes
uses: actions/github-script@v7
with:
script: |
const { execSync } = require('child_process');
const changedFiles = execSync('git diff --name-only ${{ github.event.before }} ${{ github.sha }}').toString().split('\n');
const fileChanged = changedFiles.some(file => file.startsWith('iac/mainnet-fork'));
return fileChanged
terraform_deploy:
runs-on: ubuntu-latest
needs: build
Expand All @@ -76,29 +95,33 @@ jobs:
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
aws-region: eu-west-2

- name: Deploy mainnet fork
if: needs.build.outputs.mainnet_fork_changed == 'true'
working-directory: ./iac/mainnet-fork/terraform
run: |
terraform init -input=false -backend-config="key=${{ env.DEPLOY_TAG }}/mainnet-fork"
terraform apply -input=false -auto-approve -replace="aws_ecs_service.aztec_mainnet_fork" -replace="aws_efs_file_system.aztec_mainnet_fork_data_store"
- name: Wait for mainnet fork deployment
if: needs.build.outputs.mainnet_fork_changed == 'true'
run: |
./.github/scripts/wait_for_fork.sh ${{ env.DEPLOY_TAG }} ${{ secrets.FORK_API_KEY }}
- name: Check if L1 contracts need deployment
id: check_changes_release
uses: actions/github-script@v7
with:
script: |
const { execSync } = require('child_process');
const changedFiles = execSync('git diff --name-only ${{ github.event.before }} ${{ github.sha }}').toString().split('\n');
const fileChanged = changedFiles.includes('l1-contracts/REDEPLOY');
return fileChanged
- name: Deploy L1 Contracts
if: steps.check_changes_release.outputs.result == 'true'
if: needs.build.outputs.l1_contracts_changed == 'true' || needs.build.outputs.mainnet_fork_changed == 'true'
run: |
docker pull aztecprotocol/aztec:${{ env.DEPLOY_TAG }}
docker run aztecprotocol/aztec:${{ env.DEPLOY_TAG }} \
deploy-l1-contracts -p ${{ secrets.SEQ_1_PUBLISHER_PRIVATE_KEY }} \
-u https://${{ env.DEPLOY_TAG }}-mainnet-fork.aztec.network:8545/${{ secrets.FORK_API_KEY }} \
docker run aztecprotocol/aztec:${{ env.DEPLOY_TAG }} deploy-l1-contracts \
--private-key ${{ secrets.SEQ_1_PUBLISHER_PRIVATE_KEY }} \
--rpc-url https://${{ env.DEPLOY_TAG }}-mainnet-fork.aztec.network:8545/${{ secrets.FORK_API_KEY }} \
--chain-id ${{ env.L1_CHAIN_ID }} \
| tee ${{ env.FILE_PATH }}
./.github/scripts/extract_l1_addresses.sh ${{ env.FILE_PATH }}
- name: Apply l1-contracts Terraform
if: steps.check_changes_release.outputs.result == 'true'
if: needs.build.outputs.l1_contracts_changed == 'true' || needs.build.outputs.mainnet_fork_changed == 'true'
working-directory: ./l1-contracts/terraform
run: |
terraform init -input=false -backend-config="key=${{ env.DEPLOY_TAG }}/l1-contracts"
Expand All @@ -116,10 +139,10 @@ jobs:
terraform init -input=false -backend-config="key=${{ env.DEPLOY_TAG }}/aztec-node"
- name: Taint node filesystem if L1 contracts are redeployed
if: steps.check_changes_release.outputs.result == 'true'
if: needs.build.outputs.l1_contracts_changed == 'true'
working-directory: ./yarn-project/aztec/terraform/node
run: |
terraform state list | grep 'aws_efs_file_system.node_data_store' | xargs -n1 terraform taint
terraform taint aws_efs_file_system.node_data_store
- name: Deploy Aztec Nodes
working-directory: ./yarn-project/aztec/terraform/node
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ cmake-build-debug
.arg
.secret
.bb_tmp

# Terraform
*.tfvars
6 changes: 3 additions & 3 deletions aztec-up/bin/docker-compose.sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ services:
DEBUG: # Loaded from the user shell if explicitly set
HOST_WORKDIR: "${PWD}" # Loaded from the user shell to show log files absolute path in host
ETHEREUM_HOST: ${ETHEREUM_HOST:-http://ethereum:${ANVIL_PORT:-8545}}
CHAIN_ID: 31337
L1_CHAIN_ID: 31337
ARCHIVER_POLLING_INTERVAL_MS: 50
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
PXE_PORT: ${PXE_PORT:-8080}
PORT: ${AZTEC_NODE_PORT:-8080}
PORT: ${AZTEC_NODE_PORT:-8080}
TEST_ACCOUNTS: ${TEST_ACCOUNTS:-true}
volumes:
- ./log:/usr/src/yarn-project/aztec/log:rw
depends_on:
- ethereum
command: "start --sandbox"
command: "start --sandbox"
6 changes: 3 additions & 3 deletions boxes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ services:

aztec:
image: aztecprotocol/aztec:${AZTEC_DOCKER_TAG:-latest}
command: 'start --sandbox'
command: "start --sandbox"
environment:
ETHEREUM_HOST: http://ethereum:8545
CHAIN_ID: 31337
L1_CHAIN_ID: 31337
ARCHIVER_POLLING_INTERVAL_MS: 50
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
Expand All @@ -29,7 +29,7 @@ services:
DEBUG: "aztec:*"
DEBUG_COLORS: "true"
ETHEREUM_HOST: http://ethereum:8545
CHAIN_ID: 31337
L1_CHAIN_ID: 31337
PXE_URL: http://aztec:8080
BOX: ${BOX:-vanilla}
CI: ${CI:-}
Expand Down
2 changes: 1 addition & 1 deletion build-system/scripts/deploy_terraform
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export TF_VAR_DOCKERHUB_ACCOUNT=$DOCKERHUB_ACCOUNT
export TF_VAR_FORK_MNEMONIC=$FORK_MNEMONIC
export TF_VAR_INFURA_API_KEY=$INFURA_API_KEY
export TF_VAR_API_KEY=$FORK_API_KEY
export TF_VAR_CHAIN_ID=$CHAIN_ID
export TF_VAR_L1_CHAIN_ID=$CHAIN_ID

# If given a repository name, use it to construct and set/override the backend key.
# Otherwise use the key as specified in the terraform.
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-info}
DEBUG: ${DEBUG:-aztec:*,-json-rpc:*,-aztec:circuits:artifact_hash,-aztec:randomness_singleton}
DEBUG_COLORS: 1
CHAIN_ID: 31337
L1_CHAIN_ID: 31337
VERSION: 1
PXE_PROVER_ENABLED: ${PXE_PROVER_ENABLED:-1}
PXE_DATA_DIRECTORY: /var/lib/aztec/pxe
Expand Down Expand Up @@ -39,7 +39,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-info}
DEBUG: ${DEBUG:-aztec:*,-json-rpc:*,-aztec:circuits:artifact_hash,-aztec:randomness_singleton,-aztec:avm_simulator:*}
DEBUG_COLORS: 1
CHAIN_ID: 31337
L1_CHAIN_ID: 31337
VERSION: 1
NODE_NO_WARNINGS: 1
PROVER_REAL_PROOFS: ${PROVER_REAL_PROOFS:-1}
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/sandbox_reference/sandbox-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To change them, you can open `~/.aztec/docker-compose.yml` and edit them directl
DEBUG=aztec:* # The level of debugging logs to be displayed. using "aztec:*" will log everything.
HOST_WORKDIR='${PWD}' # The location to store log outpus. Will use ~/.aztec where the docker-compose.yml file is stored by default.
ETHEREUM_HOST=http://ethereum:8545 # The Ethereum JSON RPC URL. We use an anvil instance that runs in parallel to the sandbox on docker by default.
CHAIN_ID=31337 # The Chain ID that the Ethereum host is using.
L1_CHAIN_ID=31337 # The Chain ID that the Ethereum host is using.
TEST_ACCOUNTS='true' # Option to deploy 3 test account when sandbox starts. (default: true)
MODE='sandbox' # Option to start the sandbox or a standalone part of the system. (default: sandbox)
PXE_PORT=8080 # The port that the PXE will be listening to (default: 8080)
Expand Down
4 changes: 2 additions & 2 deletions iac/mainnet-fork/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ build:
# Expose port 80
EXPOSE 80

# Set entrypoint
# Set entrypoint.
ENTRYPOINT ["sh", "-c", "./scripts/run_nginx_anvil.sh"]

export-mainnet-fork:
FROM +build
ARG DIST_TAG="aztec-dev"
ARG ARCH
SAVE IMAGE --push spypsy/mainnet-fork:${DIST_TAG}${ARCH:+-$ARCH}
SAVE IMAGE --push aztecprotocol/mainnet-fork:${DIST_TAG}${ARCH:+-$ARCH}
6 changes: 5 additions & 1 deletion iac/mainnet-fork/scripts/run_nginx_anvil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ trap 'kill $(jobs -p)' SIGTERM
HOST="0.0.0.0"
PORT=8544
ETHEREUM_HOST=$HOST:$PORT
# Stripping double quotations from the mnemonic seed phrase
echo "stripping double quotations from the mnemonic seed phrase: ${MNEMONIC:0:10}..."
MNEMONIC_STRIPPED=${MNEMONIC//\"/}
echo "result: ${MNEMONIC_STRIPPED:0:10}..."

# 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 &
.foundry/bin/anvil --silent --host $HOST -p $PORT -m "$MNEMONIC_STRIPPED" -f=https://mainnet.infura.io/v3/$INFURA_API_KEY --chain-id=$L1_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
Expand Down
98 changes: 48 additions & 50 deletions iac/mainnet-fork/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,57 +113,55 @@ resource "aws_ecs_task_definition" "aztec_mainnet_fork" {
}
}

container_definitions = <<DEFINITION
[
{
"name": "${var.DEPLOY_TAG}-mainnet-fork",
"image": "${var.DOCKERHUB_ACCOUNT}/mainnet-fork:aztec-dev",
"essential": true,
"environment": [
{
"name": "API_KEY",
"value": "${var.API_KEY}"
},
{
"name": "MNEMONIC",
"value": "${var.FORK_MNEMONIC}"
},
{
"name": "INFURA_API_KEY",
"value": "${var.INFURA_API_KEY}"
},
{
"name": "CHAIN_ID",
"value": "31337"
},
{
"name": "SNAPSHOT_FREQUENCY",
"value": "15"
container_definitions = jsonencode([
{
name = "${var.DEPLOY_TAG}-mainnet-fork"
image = "${var.DOCKERHUB_ACCOUNT}/mainnet-fork:${var.DEPLOY_TAG}"
essential = true
environment = [
{
name = "API_KEY"
value = "${var.API_KEY}"
},
{
name = "MNEMONIC"
value = "${var.FORK_MNEMONIC}"
},
{
name = "INFURA_API_KEY"
value = "${var.INFURA_API_KEY}"
},
{
name = "L1_CHAIN_ID"
value = "${var.L1_CHAIN_ID}"
},
{
name = "SNAPSHOT_FREQUENCY"
value = "15"
}
]
mountPoints = [
{
containerPath = "/data"
sourceVolume = "efs-data-store"
}
]
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "${aws_cloudwatch_log_group.aztec_mainnet_fork_logs.name}"
awslogs-region = "eu-west-2"
awslogs-stream-prefix = "ecs"
}
}
],
"mountPoints": [
{
"containerPath": "/data",
"sourceVolume": "efs-data-store"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "${aws_cloudwatch_log_group.aztec_mainnet_fork_logs.name}",
"awslogs-region": "eu-west-2",
"awslogs-stream-prefix": "ecs"
}
},
"portMappings": [
{
"containerPort": 80,
"hostPort": 80
}
]
}
]
DEFINITION
portMappings = [
{
containerPort = 80
hostPort = 80
}
]
}
])
}


Expand Down
4 changes: 4 additions & 0 deletions iac/mainnet-fork/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ variable "DOCKERHUB_ACCOUNT" {
variable "DEPLOY_TAG" {
type = string
}

variable "L1_CHAIN_ID" {
type = string
}
4 changes: 2 additions & 2 deletions l1-contracts/REDEPLOY
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Append value to force redeploy
1
# Change value to force redeploy
2
Loading

0 comments on commit 103f099

Please sign in to comment.