Skip to content

Commit

Permalink
fix: Use lookup instead of resolve to ensure consider /etc/hosts (Azt…
Browse files Browse the repository at this point in the history
…ecProtocol#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).
  • Loading branch information
charlielye authored Dec 16, 2023
1 parent fe38a11 commit acb4dc9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
14 changes: 8 additions & 6 deletions aztec-up/bin/.aztec-run
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ if [[ -z "${SKIP_NET:-}" && "$UNAME" == "Linux" ]]; then
# We're in rootless docker. Probe for the host ip and use that.
ip=$(hostname -I | head | tr -d ' ')
warn "WARNING: Running within rootless docker. Using $ip as host ip. Ensure listening services are listening on this interface."
DOCKER_HOST_BINDS="$DOCKER_HOST_BINDS --add-host host.docker.internal:$ip"
DOCKER_HOST_BINDS="--add-host host.docker.internal:$ip"
else
DOCKER_HOST_BINDS="$DOCKER_HOST_BINDS --add-host host.docker.internal:host-gateway"
DOCKER_HOST_BINDS="--add-host host.docker.internal:host-gateway"
fi
fi

Expand All @@ -70,10 +70,12 @@ done

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

# Volumes to pass to the container.
Expand Down
2 changes: 0 additions & 2 deletions aztec-up/bin/aztec-cli
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env bash
# TODO: Make compile command always be wasm. Or put nargo in container. Or probe.
# TODO: Make unbox fail if trying to unbox outside of the cwd.
set -euo pipefail

export ENV_VARS_TO_INJECT="PXE_URL PRIVATE_KEY DEBUG"
Expand Down
4 changes: 2 additions & 2 deletions aztec-up/bin/aztec-sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
CMD="docker compose"
$CMD &>/dev/null || CMD="docker-compose"

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

# Function to be executed when SIGINT is received.
cleanup() {
Expand All @@ -16,6 +16,6 @@ cleanup() {
trap cleanup SIGINT

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

$CMD $ARGS up --force-recreate --remove-orphans
15 changes: 9 additions & 6 deletions aztec-up/bin/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,33 @@ services:
'
[ -n "$$FORK_URL" ] && ARGS="$$ARGS --fork-url $$FORK_URL";
[ -n "$$FORK_BLOCK_NUMBER" ] && ARGS="$$ARGS --fork-block-number $$FORK_BLOCK_NUMBER";
echo anvil -p 8545 --host 0.0.0.0 --chain-id 31337 --silent $$ARGS;
anvil -p 8545 --host 0.0.0.0 --chain-id 31337 --silent $$ARGS
echo anvil -p $$ANVIL_PORT --host 0.0.0.0 --chain-id 31337 --silent $$ARGS;
anvil -p $$ANVIL_PORT --host 0.0.0.0 --chain-id 31337 --silent $$ARGS
'
ports:
- "${SANDBOX_ANVIL_PORT:-8545}:8545"
- "${ANVIL_PORT:-8545}:${ANVIL_PORT:-8545}"
environment:
FORK_URL:
FORK_BLOCK_NUMBER:
ANVIL_PORT: ${ANVIL_PORT:-8545}

aztec:
image: "aztecprotocol/aztec-sandbox"
ports:
- "${SANDBOX_AZTEC_NODE_PORT:-8079}:8079"
- "${SANDBOX_PXE_PORT:-8080}:8080"
- "${AZTEC_NODE_PORT:-8079}:${AZTEC_NODE_PORT:-8079}"
- "${PXE_PORT:-8080}:${PXE_PORT:-8080}"
environment:
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: http://ethereum:8545
ETHEREUM_HOST: http://ethereum:${ANVIL_PORT:-8545}
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
AZTEC_NODE_PORT: ${AZTEC_NODE_PORT:-8079}
PXE_PORT: ${PXE_PORT:-8080}
volumes:
- ./log:/usr/src/yarn-project/aztec-sandbox/log:rw
11 changes: 5 additions & 6 deletions yarn-project/aztec-sandbox/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { NoirCommit } from '@aztec/noir-compiler/versions';
import { BootstrapNode, getP2PConfigEnvVars } from '@aztec/p2p';
import { GrumpkinScalar, PXEService, createPXERpcServer } from '@aztec/pxe';

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

const LOCALHOST = await getLocalhost();
const {
Expand Down
11 changes: 5 additions & 6 deletions yarn-project/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fileURLToPath } from '@aztec/foundation/url';
import { addNoirCompilerCommanderActions } from '@aztec/noir-compiler/cli';

import { Command, Option } from 'commander';
import { resolve as dnsResolve } from 'dns';
import { lookup } from 'dns/promises';
import { readFileSync } from 'fs';
import { dirname, resolve } from 'path';

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

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

0 comments on commit acb4dc9

Please sign in to comment.