Skip to content

Commit eb8413e

Browse files
authored
fix: Use lookup instead of resolve to ensure consider /etc/hosts (AztecProtocol#3720)
Please provide a paragraph or two giving a summary of the change, including relevant motivation and context. # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist).
1 parent 748e665 commit eb8413e

File tree

6 files changed

+29
-28
lines changed

6 files changed

+29
-28
lines changed

aztec-up/bin/.aztec-run

+8-6
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ if [[ -z "${SKIP_NET:-}" && "$UNAME" == "Linux" ]]; then
4444
# We're in rootless docker. Probe for the host ip and use that.
4545
ip=$(hostname -I | head | tr -d ' ')
4646
warn "WARNING: Running within rootless docker. Using $ip as host ip. Ensure listening services are listening on this interface."
47-
DOCKER_HOST_BINDS="$DOCKER_HOST_BINDS --add-host host.docker.internal:$ip"
47+
DOCKER_HOST_BINDS="--add-host host.docker.internal:$ip"
4848
else
49-
DOCKER_HOST_BINDS="$DOCKER_HOST_BINDS --add-host host.docker.internal:host-gateway"
49+
DOCKER_HOST_BINDS="--add-host host.docker.internal:host-gateway"
5050
fi
5151
fi
5252

@@ -70,10 +70,12 @@ done
7070

7171
DOCKER_ENV="-e HOME=$HOME"
7272
for env in ${ENV_VARS_TO_INJECT:-}; do
73-
# First substitute any reference to localhost with our host gateway.
74-
env=${env//localhost/host.docker.internal}
75-
# Inject into container.
76-
DOCKER_ENV+="-e $env:${!env:-} "
73+
if [ -n "${!env:-}" ]; then
74+
# First substitute any reference to localhost with our host gateway.
75+
env=${env//localhost/host.docker.internal}
76+
# Inject into container.
77+
DOCKER_ENV+=" -e $env=${!env:-}"
78+
fi
7779
done
7880

7981
# Volumes to pass to the container.

aztec-up/bin/aztec-cli

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env bash
2-
# TODO: Make compile command always be wasm. Or put nargo in container. Or probe.
3-
# TODO: Make unbox fail if trying to unbox outside of the cwd.
42
set -euo pipefail
53

64
export ENV_VARS_TO_INJECT="PXE_URL PRIVATE_KEY DEBUG"

aztec-up/bin/aztec-sandbox

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -euo pipefail
55
CMD="docker compose"
66
$CMD &>/dev/null || CMD="docker-compose"
77

8-
ARGS="-f $HOME/.aztec/bin/docker-compose.yml -p sandbox"
8+
ARGS="-f ./bin/docker-compose.yml -p sandbox"
99

1010
# Function to be executed when SIGINT is received.
1111
cleanup() {
@@ -16,6 +16,6 @@ cleanup() {
1616
trap cleanup SIGINT
1717

1818
# Change working dir, so relative volume mounts are in the right place.
19-
cd ~/.aztec
19+
cd $(dirname $0)/..
2020

2121
$CMD $ARGS up --force-recreate --remove-orphans

aztec-up/bin/docker-compose.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,33 @@ services:
66
'
77
[ -n "$$FORK_URL" ] && ARGS="$$ARGS --fork-url $$FORK_URL";
88
[ -n "$$FORK_BLOCK_NUMBER" ] && ARGS="$$ARGS --fork-block-number $$FORK_BLOCK_NUMBER";
9-
echo anvil -p 8545 --host 0.0.0.0 --chain-id 31337 --silent $$ARGS;
10-
anvil -p 8545 --host 0.0.0.0 --chain-id 31337 --silent $$ARGS
9+
echo anvil -p $$ANVIL_PORT --host 0.0.0.0 --chain-id 31337 --silent $$ARGS;
10+
anvil -p $$ANVIL_PORT --host 0.0.0.0 --chain-id 31337 --silent $$ARGS
1111
'
1212
ports:
13-
- "${SANDBOX_ANVIL_PORT:-8545}:8545"
13+
- "${ANVIL_PORT:-8545}:${ANVIL_PORT:-8545}"
1414
environment:
1515
FORK_URL:
1616
FORK_BLOCK_NUMBER:
17+
ANVIL_PORT: ${ANVIL_PORT:-8545}
1718

1819
aztec:
1920
image: "aztecprotocol/aztec-sandbox"
2021
ports:
21-
- "${SANDBOX_AZTEC_NODE_PORT:-8079}:8079"
22-
- "${SANDBOX_PXE_PORT:-8080}:8080"
22+
- "${AZTEC_NODE_PORT:-8079}:${AZTEC_NODE_PORT:-8079}"
23+
- "${PXE_PORT:-8080}:${PXE_PORT:-8080}"
2324
environment:
2425
DEBUG: # Loaded from the user shell if explicitly set
2526
HOST_WORKDIR: "${PWD}" # Loaded from the user shell to show log files absolute path in host
26-
ETHEREUM_HOST: http://ethereum:8545
27+
ETHEREUM_HOST: http://ethereum:${ANVIL_PORT:-8545}
2728
CHAIN_ID: 31337
2829
ARCHIVER_POLLING_INTERVAL_MS: 50
2930
P2P_BLOCK_CHECK_INTERVAL_MS: 50
3031
SEQ_TX_POLLING_INTERVAL_MS: 50
3132
WS_BLOCK_CHECK_INTERVAL_MS: 50
3233
PXE_BLOCK_POLLING_INTERVAL_MS: 50
3334
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
35+
AZTEC_NODE_PORT: ${AZTEC_NODE_PORT:-8079}
36+
PXE_PORT: ${PXE_PORT:-8080}
3437
volumes:
3538
- ./log:/usr/src/yarn-project/aztec-sandbox/log:rw

yarn-project/aztec-sandbox/src/bin/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { NoirCommit } from '@aztec/noir-compiler/versions';
1010
import { BootstrapNode, getP2PConfigEnvVars } from '@aztec/p2p';
1111
import { GrumpkinScalar, PXEService, createPXERpcServer } from '@aztec/pxe';
1212

13-
import { resolve as dnsResolve } from 'dns';
13+
import { lookup } from 'dns/promises';
1414
import { readFileSync } from 'fs';
1515
import http from 'http';
1616
import { dirname, resolve } from 'path';
@@ -35,11 +35,10 @@ enum SandboxMode {
3535
* If we can successfully resolve 'host.docker.internal', then we are running in a container, and we should treat
3636
* localhost as being host.docker.internal.
3737
*/
38-
function getLocalhost() {
39-
return new Promise(resolve =>
40-
dnsResolve('host.docker.internal', err => (err ? resolve('localhost') : resolve('host.docker.internal'))),
41-
);
42-
}
38+
const getLocalhost = () =>
39+
lookup('host.docker.internal')
40+
.then(() => 'host.docker.internal')
41+
.catch(() => 'localhost');
4342

4443
const LOCALHOST = await getLocalhost();
4544
const {

yarn-project/cli/src/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fileURLToPath } from '@aztec/foundation/url';
33
import { addNoirCompilerCommanderActions } from '@aztec/noir-compiler/cli';
44

55
import { Command, Option } from 'commander';
6-
import { resolve as dnsResolve } from 'dns';
6+
import { lookup } from 'dns/promises';
77
import { readFileSync } from 'fs';
88
import { dirname, resolve } from 'path';
99

@@ -27,11 +27,10 @@ import {
2727
* If we can successfully resolve 'host.docker.internal', then we are running in a container, and we should treat
2828
* localhost as being host.docker.internal.
2929
*/
30-
function getLocalhost() {
31-
return new Promise(resolve =>
32-
dnsResolve('host.docker.internal', err => (err ? resolve('localhost') : resolve('host.docker.internal'))),
33-
);
34-
}
30+
const getLocalhost = () =>
31+
lookup('host.docker.internal')
32+
.then(() => 'host.docker.internal')
33+
.catch(() => 'localhost');
3534

3635
const LOCALHOST = await getLocalhost();
3736
const { ETHEREUM_HOST = `http://${LOCALHOST}:8545`, PRIVATE_KEY, API_KEY } = process.env;

0 commit comments

Comments
 (0)