diff --git a/aztec-up/bin/.aztec-run b/aztec-up/bin/.aztec-run index d374e63ded73..53044ad1d960 100755 --- a/aztec-up/bin/.aztec-run +++ b/aztec-up/bin/.aztec-run @@ -113,18 +113,10 @@ done arg_port_assignment="" # Dynamic port assignment. -if [ -n "${AZTEC_PORT:-}" ]; then - arg_port_assignment+=" -p $AZTEC_PORT:$AZTEC_PORT " -fi - -if [ -n "${P2P_TCP_LISTEN_ADDR:-}" ]; then - P2P_TCP_PORT=${P2P_TCP_LISTEN_ADDR#*:} - arg_port_assignment+=" -p $P2P_TCP_PORT:$P2P_TCP_PORT " -fi - -if [ -n "${P2P_UDP_LISTEN_ADDR:-}" ]; then - P2P_UDP_PORT=${P2P_UDP_LISTEN_ADDR#*:} - arg_port_assignment+=" -p $P2P_UDP_PORT:$P2P_UDP_PORT/udp " +if [ -n "${PORTS_TO_EXPOSE:-}" ]; then + for port in ${PORTS_TO_EXPOSE}; do + arg_port_assignment+=" -p $port " + done fi # For debugging the aztec-up scripts, can be useful to mount local code into container. diff --git a/aztec-up/bin/aztec b/aztec-up/bin/aztec index 273190110e7f..864d862bcbd8 100755 --- a/aztec-up/bin/aztec +++ b/aztec-up/bin/aztec @@ -13,6 +13,11 @@ while [ "$#" -gt 0 ]; do AZTEC_PORT="$2" shift 2 ;; + -a | --anvil-port) + # Override default port exposed on container. + ANVIL_PORT="$2" + shift 2 + ;; --pxe.network) # Set version to user-specified network (e.g. 'devnet') VERSION="$2" @@ -49,8 +54,11 @@ case ${1:-} in ;; start) export ENV_VARS_TO_INJECT="$(get_env_vars)" - # Opens the requested port on the container. - export AZTEC_PORT=${AZTEC_PORT:-8080} + + # Dynamic port assignments, .aztec-run will expose the array PORTS_TO_EXPOSE as a space-separated string. + AZTEC_PORT=${AZTEC_PORT:-8080} + export PORTS_TO_EXPOSE="$AZTEC_PORT:$AZTEC_PORT" + if [ "${2:-}" == "--sandbox" ]; then # TODO: This entire special case should go away. # Sandbox mode should start it's own anvil. @@ -67,11 +75,32 @@ case ${1:-} in export ARCHIVER_VIEM_POLLING_INTERVAL_MS=500 export TEST_ACCOUNTS=${TEST_ACCOUNTS:-true} export LOG_LEVEL=${LOG_LEVEL:-info} + + ANVIL_PORT=${ANVIL_PORT:-8545} + anvil_port_assignment="$ANVIL_PORT:8545" + + PORTS_TO_EXPOSE="${PORTS_TO_EXPOSE:-} $anvil_port_assignment" + exec $(dirname $0)/.aztec-run aztec-sandbox bash -c " anvil --host 0.0.0.0 --silent & node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js start --sandbox " else + # Export p2p port forwarding only if set in env vars + if [ -n "${P2P_TCP_LISTEN_ADDR:-}" ]; then + P2P_TCP_PORT=${P2P_TCP_LISTEN_ADDR##*:} + P2P_TCP_LISTEN_MAPPING="$P2P_TCP_PORT:$P2P_TCP_PORT" + + PORTS_TO_EXPOSE="${PORTS_TO_EXPOSE:-} $P2P_TCP_LISTEN_MAPPING" + fi + + if [ -n "${P2P_UDP_LISTEN_ADDR:-}" ]; then + P2P_UDP_PORT=${P2P_UDP_LISTEN_ADDR##*:} + P2P_UDP_LISTEN_MAPPING="$P2P_UDP_PORT:$P2P_UDP_PORT/udp" + + PORTS_TO_EXPOSE="${PORTS_TO_EXPOSE:-} $P2P_UDP_LISTEN_MAPPING" + fi + exec $(dirname $0)/.aztec-run aztec-start \ node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js "$@" fi diff --git a/docs/docs/developers/reference/environment_reference/sandbox-reference.md b/docs/docs/developers/reference/environment_reference/sandbox-reference.md index 22ab9ff46781..6ded6186fc15 100644 --- a/docs/docs/developers/reference/environment_reference/sandbox-reference.md +++ b/docs/docs/developers/reference/environment_reference/sandbox-reference.md @@ -14,24 +14,19 @@ For a quick start, follow the [guide](../../getting_started.md) to install the s There are various environment variables you can use when running the whole sandbox or when running on of the available modes. -To change them, you can open `~/.aztec/docker-compose.sandbox.yml` and edit them directly. - **Sandbox** ```sh LOG_LEVEL=debug # Options are 'fatal', 'error', 'warn', 'info', 'verbose', 'debug', 'trace' HOST_WORKDIR='${PWD}' # The location to store log outputs. Will use ~/.aztec where the docker-compose.yml file is stored by default. -ETHEREUM_HOSTS=http://ethereum:8545 # List of Ethereum JSON RPC URLs. We use an anvil instance that runs in parallel to the sandbox on docker by default. +ETHEREUM_HOSTS=http://127.0.0.1:8545 # List of Ethereum JSON RPC URLs. We use an anvil instance that runs in parallel to the sandbox on docker by default. +ANVIL_PORT=8545 # The port that docker will forward to the anvil instance (default: 8545) 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) AZTEC_NODE_PORT=8080 # The port that Aztec Node will be listening to (default: 8080) -# Ethereum Forking (Optional: not enabled by default) # -FORK_BLOCK_NUMBER=0 # The block number to fork from -FORK_URL="" # The URL of the Ethereum node to fork from - ## Polling intervals ## ARCHIVER_POLLING_INTERVAL_MS=50 P2P_BLOCK_CHECK_INTERVAL_MS=50