Repository navigation
feat(node): iroh relay support + disposable anvil internal-testnet rig - #794
alpergundogdu wants to merge 6 commits into
Conversation
Stand up the full deCDN contract surface on a VPS for internal testing using anvil, isolated under contracts/local/ so it can be scrapped in one move. No new Solidity: reuse the tested recipe from anvil_settlement_e2e (deploy test-only MintableUSDC, then run the production DeployProtocol.s.sol). - docker-compose.yml: anvil with persistent state, bound to the WireGuard interface only (never 0.0.0.0; Docker bypasses host firewalls). - deploy.sh: mock USDC + production deploy wrapper, 1h timelock floor. - .env.example, .gitignore, README.md runbook (security, funding, node wiring, time control, scrap, and the iroh-relay caveat). Zero production-audit-surface impact: nothing under src/ or script/, so forge build/aderyn/slither/gas-snapshot and the TestnetFaucet boundary gate are untouched. Manifest uses a gitignored 3133769x chain id.
Gas snapshotGas changes vs baseRun: 26891112146 |
Contracts coverageLine coverage: 88.96% (1797/2020 lines) |
There was a problem hiding this comment.
Code Review
This pull request introduces a local internal-testnet rig using anvil, Docker, and WireGuard to stand up the full deCDN contract surface for testing. Feedback on the changes includes replacing the external seq utility in deploy.sh with a native bash loop for portability, updating the fallback sed pattern to handle optional whitespace in JSON output, and replacing angle-bracket placeholders in the README.md shell commands to prevent shell redirection errors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| } | ||
|
|
||
| echo "==> waiting for anvil at $RPC_URL" | ||
| for i in $(seq 1 30); do |
There was a problem hiding this comment.
Using the external seq utility is less portable and spawns an unnecessary subprocess. In bash, you can use the native shell arithmetic loop for ((i=1; i<=30; i++)) which is more efficient and fully portable across all environments running bash.
| for i in $(seq 1 30); do | |
| for ((i=1; i<=30; i++)); do |
| --rpc-url "$RPC_URL" --private-key "$DEPLOYER_KEY" --broadcast --json)" | ||
| usdc="$(printf '%s' "$usdc_json" | { jq -r '.deployedTo' 2>/dev/null || true; })" | ||
| if [[ -z "$usdc" || "$usdc" == "null" ]]; then | ||
| usdc="$(printf '%s' "$usdc_json" | sed -n 's/.*"deployedTo":"\([^"]*\)".*/\1/p')" |
There was a problem hiding this comment.
If jq is not installed, the script falls back to sed to extract the deployed address. However, standard JSON formatters (and some versions of Foundry) output a space after the colon (e.g., "deployedTo": "0x..."). The current sed pattern expects no spaces ("deployedTo":"), which will fail to match if whitespace is present. Allowing optional whitespace makes the fallback significantly more robust.
| usdc="$(printf '%s' "$usdc_json" | sed -n 's/.*"deployedTo":"\([^"]*\)".*/\1/p')" | |
| usdc="$(printf '%s' "$usdc_json" | sed -n 's/.*"deployedTo":[[:space:]]*"\([^"]*\)".*/\1/p')" |
| cast send "$USDC" "mint(address,uint256)" <addr> 1000000000 \ | ||
| --rpc-url "$RPC" --private-key "$DEPLOYER_KEY" | ||
|
|
||
| # Send 100,000 TOKEN (18 decimals) from the genesis holder to an operator | ||
| # (needs ≥ MIN_BOND = 50,000 TOKEN to stake): | ||
| cast send "$TOKEN" "transfer(address,uint256)" <operator> 100000000000000000000000 \ | ||
| --rpc-url "$RPC" --private-key "$DEPLOYER_KEY" | ||
|
|
||
| # Gas for a fresh EOA (anvil cheat method): | ||
| cast rpc anvil_setBalance <addr> 0xde0b6b3a7640000 --rpc-url "$RPC" |
There was a problem hiding this comment.
Using <addr> and <operator> as placeholders in raw bash commands will be interpreted by the shell as input/output redirection operators (e.g., < redirects standard input). If a user copy-pastes these commands directly, the shell will attempt to read from files named addr or operator and fail with a No such file or directory error. Use standard uppercase placeholders without angle brackets instead.
| cast send "$USDC" "mint(address,uint256)" <addr> 1000000000 \ | |
| --rpc-url "$RPC" --private-key "$DEPLOYER_KEY" | |
| # Send 100,000 TOKEN (18 decimals) from the genesis holder to an operator | |
| # (needs ≥ MIN_BOND = 50,000 TOKEN to stake): | |
| cast send "$TOKEN" "transfer(address,uint256)" <operator> 100000000000000000000000 \ | |
| --rpc-url "$RPC" --private-key "$DEPLOYER_KEY" | |
| # Gas for a fresh EOA (anvil cheat method): | |
| cast rpc anvil_setBalance <addr> 0xde0b6b3a7640000 --rpc-url "$RPC" | |
| cast send "$USDC" "mint(address,uint256)" YOUR_ADDRESS 1000000000 \ | |
| --rpc-url "$RPC" --private-key "$DEPLOYER_KEY" | |
| # Send 100,000 TOKEN (18 decimals) from the genesis holder to an operator | |
| # (needs ≥ MIN_BOND = 50,000 TOKEN to stake): | |
| cast send "$TOKEN" "transfer(address,uint256)" OPERATOR_ADDRESS 100000000000000000000000 \ | |
| --rpc-url "$RPC" --private-key "$DEPLOYER_KEY" | |
| # Gas for a fresh EOA (anvil cheat method): | |
| cast rpc anvil_setBalance YOUR_ADDRESS 0xde0b6b3a7640000 --rpc-url "$RPC" |
| ```bash | ||
| cd contracts/local | ||
| docker compose down -v # stop anvil + delete the state volume | ||
| rm -f contracts/deployments/<chainId>.json # if it lingers (gitignored anyway) |
There was a problem hiding this comment.
Using <chainId> in the rm command will be interpreted as a redirection operator by the shell, causing the command to fail or behave unexpectedly. Use a standard uppercase placeholder like YOUR_CHAIN_ID instead.
| rm -f contracts/deployments/<chainId>.json # if it lingers (gitignored anyway) | |
| rm -f contracts/deployments/YOUR_CHAIN_ID.json # if it lingers (gitignored anyway) |
There was a problem hiding this comment.
Pull request overview
Adds a disposable, self-contained “local internal-testnet” rig under contracts/local/ to deploy and exercise the full deCDN contract surface on a VPS using dockerized anvil, with access restricted to a WireGuard interface. This supports internal end-to-end testing while keeping the production Solidity surface unchanged.
Changes:
- Added a Docker Compose setup to run
anvilwith persisted chain state and WireGuard-only port publishing. - Added a
deploy.shwrapper to deploy mock USDC and then run the productionDeployProtocol.s.sol, emitting a deployment manifest + addresses. - Added a runbook (
README.md) plus.env.exampleand.gitignorefor operator workflow and safety guidance.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| contracts/local/README.md | Operator runbook for bringing up the rig, deploying, funding accounts, and scrapping it. |
| contracts/local/docker-compose.yml | Docker Compose definition for a persistent, wg-bound anvil service (plus commented relay stub). |
| contracts/local/deploy.sh | Host-side deployment script: deploys MintableUSDC, then runs the production deploy script and prints addresses. |
| contracts/local/.gitignore | Ignores local rig artifacts (e.g., .env). |
| contracts/local/.env.example | Example environment configuration for networking, chain id, block time, and deploy parameters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ```bash | ||
| cd contracts/local | ||
| docker compose down -v # stop anvil + delete the state volume | ||
| rm -f contracts/deployments/<chainId>.json # if it lingers (gitignored anyway) |
| with `cast send`. | ||
|
|
||
| ```bash | ||
| RPC=http://<WG_BIND_IP>:8545 |
| > Note: the node's `chain id` is currently bound to Arbitrum Sepolia in | ||
| > `load_eth_signer` (see the comment in `crates/node/src/runtime/mod.rs`). Using | ||
| > a different `CHAIN_ID` here may require threading the chain id through | ||
| > `ResolvedBlockchain` first. Either set `CHAIN_ID` to the value the node | ||
| > expects, or make that change before wiring real nodes. |
…probe Wire the configured `[network] relay_url` (DECDN_RELAY_URL) into the node's iroh endpoint: when set, swap the n0 default relay map for a single self-hosted relay via RelayMode::Custom, keeping n0 DNS address-lookup for NodeId discovery. A TCP reachability probe (probe_relay) runs at bring-up so a down/mistyped relay fails fast instead of degrading into silent connection failures. Multi-relay + self-hosted discovery tracked in #795. Activate the opt-in `relay` service in the contracts/local rig (profile "relay", operator-supplied IROH_RELAY_IMAGE) and document wiring nodes to it. Address PR review: - deploy.sh: native bash arithmetic loop instead of `seq`; tolerate optional whitespace in the jq-less `deployedTo` sed fallback. - README: copy-paste-safe placeholders (no `<...>` shell-redirection traps), reference RPC_PORT, fix the scrap path relative to contracts/local, and correct the chain-id note (node binds the configured blockchain.chain_id, not a hardcoded Arbitrum Sepolia id — set it to match CHAIN_ID).
|
/gemini review Generated by Claude Code |
There was a problem hiding this comment.
Code Review
This pull request introduces a local internal-testnet rig under contracts/local/ utilizing anvil, Docker, and WireGuard, and updates the node runtime to support a custom self-hosted iroh relay with a fail-fast reachability probe. Feedback on these changes includes resolving an issue where IPv6 relay URLs with square brackets fail TCP connection probes, dynamically constructing the default RPC_URL in deploy.sh to prevent connection failures when binding to a specific VPN IP, and correcting a misleading comment in .env.example regarding localhost connectivity.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| let host = relay | ||
| .host_str() | ||
| .ok_or_else(|| anyhow::anyhow!("relay url {relay} has no host"))?; |
There was a problem hiding this comment.
When parsing a RelayUrl (which is based on url::Url), calling .host_str() on an IPv6 address returns the host with square brackets (e.g., "[::1]"). Passing a host string with square brackets to tokio::net::TcpStream::connect via (host, port) will fail to parse as an IP address and fail DNS resolution, causing the connection to fail.
To support IPv6 relay URLs (such as those used in WireGuard VPNs), we should strip the square brackets from the host string if they are present. Additionally, avoid including the raw URL in the error message to prevent potential credential leakage.
let host = relay
.host_str()
.ok_or_else(|| anyhow::anyhow!("relay url has no host"))?;
let host = host
.strip_prefix('[')
.and_then(|h| h.strip_suffix(']'))
.unwrap_or(host);References
- Avoid including raw URLs that may contain credentials (e.g., RPC URLs with basic auth) in error messages to prevent credential leakage.
| RPC_URL="${RPC_URL:-http://127.0.0.1:8545}" | ||
| CHAIN_ID="${CHAIN_ID:-31337699}" | ||
| TIMELOCK_DELAY="${TIMELOCK_DELAY:-3600}" |
There was a problem hiding this comment.
If WG_BIND_IP is configured to a specific VPN IP (e.g., 10.0.0.1) in .env, the dockerized anvil will only bind and listen on that interface. In this case, the default RPC_URL of http://127.0.0.1:8545 will fail to connect even when running the script on the VPS itself.
We can make the default RPC_URL dynamically construct from WG_BIND_IP and RPC_PORT so that it automatically uses the correct interface IP when they are configured in .env.
| RPC_URL="${RPC_URL:-http://127.0.0.1:8545}" | |
| CHAIN_ID="${CHAIN_ID:-31337699}" | |
| TIMELOCK_DELAY="${TIMELOCK_DELAY:-3600}" | |
| WG_BIND_IP="${WG_BIND_IP:-127.0.0.1}" | |
| RPC_PORT="${RPC_PORT:-8545}" | |
| RPC_URL="${RPC_URL:-http://${WG_BIND_IP}:${RPC_PORT}}" | |
| CHAIN_ID="${CHAIN_ID:-31337699}" | |
| TIMELOCK_DELAY="${TIMELOCK_DELAY:-3600}" |
| # RPC the deploy script targets. On the VPS itself this is localhost; from a | ||
| # laptop on the wg mesh, use http://<WG_BIND_IP>:<RPC_PORT>. | ||
| RPC_URL=http://127.0.0.1:8545 |
There was a problem hiding this comment.
The comment stating "On the VPS itself this is localhost" is misleading when WG_BIND_IP is set to a specific VPN IP (like 10.0.0.1). Since Docker binds the port specifically to that IP, connecting to 127.0.0.1 will result in a connection refusal even on the VPS itself.
Let's update the comment to clarify that the VPN IP must be used if WG_BIND_IP is set to a non-loopback address.
# RPC the deploy script targets. If WG_BIND_IP is set to a specific VPN IP,
# you must use http://<WG_BIND_IP>:<RPC_PORT> even on the VPS itself.
RPC_URL=http://127.0.0.1:8545
Coverage reportTotal: 86.59% (was 86.63%, ▼ 0.03%) — 27557/31823 lines
History
|
Address PR review (gemini): - probe_relay: strip the brackets url::Url::host_str adds to IPv6 literals (`[::1]` → `::1`) before TcpStream::connect, which rejects the bracketed form — IPv6 relay URLs (common on WireGuard) now probe correctly. Report only host:port (never the full URL) in failure messages so any userinfo can't leak into logs. Add unit tests for unbracket_host + probe_relay (reachable / unreachable / IPv6). - contracts/local/deploy.sh: default RPC_URL to http://$WG_BIND_IP:$RPC_PORT (Docker publishes anvil's port only on WG_BIND_IP, so 127.0.0.1 won't answer when WG_BIND_IP is a non-loopback VPN IP). - contracts/local/.env.example: comment out the hardcoded RPC_URL so the derive applies, and correct the misleading "localhost on the VPS" note.
alpergundogdu
left a comment
There was a problem hiding this comment.
Review — anvil internal-testnet rig
The Docker/WireGuard rig itself is well thought through: defaulting WG_BIND_IP to 127.0.0.1, calling out the Docker-bypasses-ufw footgun, reusing the production DeployProtocol.s.sol recipe so the surface matches Sepolia/mainnet, gitignoring the manifest via the 3133769x chain-id range, and the bash -n/docker compose config test plan are all solid. Nothing under src//script/, so the CI gates are genuinely untouched. 👍
One thing needs attention before merge:
IMPORTANT — the PR description contradicts its own diff (scope)
The description has a section titled "iroh relay (follow-up, not in this PR)" stating:
The node ... does not consume
network.relay_urltoday (build_endpointincrates/node/src/runtime/mod.rs...). So a self-hosted relay isn't usable without a small endpoint-builder change. ... A commentedrelayservice is stubbed in the compose for when that change lands; tracking it separately.
But the diff does modify build_endpoint in crates/node/src/runtime/mod.rs to consume cfg.network.relay_url (RelayMode::Custom), adds probe_relay/unbracket_host + tests, and the relay compose service is active under a relay profile, not commented out. So the relay support that the description says is a separate follow-up is actually shipped here.
This matters for two reasons:
- A reviewer reading the description would not expect a production node-runtime behavior change (the endpoint now fails bring-up on a relay probe failure). The PR title is
chore(contracts): ..., which further hides that acrates/noderuntime change is included. - If the runtime change was intentional, please update the description/title; if it was meant to be split out, it should move to its own PR so it gets reviewed on its own merits.
Consideration — fail-fast-at-boot couples node availability to relay availability
probe_relay is sound (single TCP connect, 5s timeout, host:port-only error messages to avoid leaking userinfo, IPv6 unbracketing with tests). But making node bring-up fail when the configured relay isn't reachable means a transiently-down relay at startup prevents the node from starting at all. That's defensible for a misconfiguration guard (and you document the intent), but for a relay that exists for resilience it's worth a deliberate decision vs. a warn-and-continue / retry. Not blocking — just flagging the tradeoff.
Minor: the relay compose service has no healthcheck (anvil does); and port_or_known_default() will resolve https://relay.example (no explicit port) to 443 rather than the iroh-relay default 3340 — fine since your examples use explicit ports, just noting.
I confirmed network.relay_url exists in the config schema and is still correctly warn_ignored on SIGHUP reload (reload.rs:1162), so the reload note remains accurate.
Generated by Claude Code
Per PR review: an unreachable relay at startup should not block node bring-up (the relay exists for resilience, and iroh keeps retrying it in the background). probe_relay now does a few short TCP connects with backoff and, on exhaustion, logs a warning and returns — the caller proceeds. Split host/port resolution (relay_host_port) and the single attempt (relay_connect_once) out to keep clippy cognitive-complexity in bounds. Update tests to the bool return; README to warn-not-fail; note why the relay compose service has no healthcheck (operator-supplied image).
thiras
left a comment
There was a problem hiding this comment.
we don't need wg for local. that stuff belongs to the test RPC under devops repo
Per review (thiras): the anvil rig doesn't need WireGuard — exposing a shared/team test RPC (and hardening it) belongs to the devops test-RPC setup, not here. Keep the rig but bind anvil (and the optional relay) to 127.0.0.1 only and remove the wg-specific knobs/guidance. - docker-compose.yml: publish ports on 127.0.0.1 (drop WG_BIND_IP); update security comment to point remote exposure at the devops test-RPC setup. - deploy.sh / .env.example: drop WG_BIND_IP; RPC_URL defaults to http://127.0.0.1:$RPC_PORT. - README: retitle (anvil + Docker), replace the WireGuard security section with a local-only safety note + devops pointer, fix examples to 127.0.0.1. No node/runtime changes; the iroh relay wiring is untouched.
Closes #793.
This PR does two things, intentionally landed together (the relay wiring is exercised by the rig). The earlier description framed the relay as a separate follow-up — that was stale; the relay runtime change is included here, hence the
feat(node)title.1. Disposable internal-testnet rig (
contracts/local/)anvil in Docker (persistent state, WireGuard-bound port, defaults to
127.0.0.1), with adeploy.shthat deploys the test-onlyMintableUSDCthen runs the productionDeployProtocol.s.solagainst it — same recipe ascrates/node/tests/anvil_settlement_e2e.rs, so the surface matches Sepolia/mainnet. Plus.env.example,.gitignore, and a fullREADME.mdrunbook.src/orscript/, soforge build/aderyn/slither/gas-snapshot and theTestnetFaucetboundary gate are untouched.3133769xchain id.docker compose down -v+ deletecontracts/local/.2. Self-hosted iroh relay support (
crates/node) — node runtime changebuild_endpointnow honors[network] relay_url(DECDN_RELAY_URL): when set, it swaps the n0 default relay map for a single self-hosted relay (RelayMode::Custom), keepingpresets::N0DNS address-lookup for NodeId→address discovery.probe_relayis a startup diagnostic, not a gate: a few short TCP connects with backoff. On an unreachable relay it logs a warning and continues — iroh keeps retrying the relay in the background, so a slow-starting or transiently-down relay can't block node bring-up. (Changed from fail-fast per review.) IPv6 hosts are un-bracketed before dialing; failure logs show onlyhost:port, never the URL (no userinfo leak). Unit-tested: reachable / unreachable / IPv6 /unbracket_host.relayDocker service is opt-in (docker compose --profile relay up -d, operator-suppliedIROH_RELAY_IMAGE).Follow-up (out of scope here): #795 — multiple relays + self-hosted discovery for full n0 independence.
Reviewer notes addressed
chore(contracts)→feat(node)).deploy.shRPC derivation fromWG_BIND_IP,.env.examplelocalhost note, placeholder/redirection hazards,seq→bash arithmetic, sed whitespace.Validation
cargo build,cargo clippy --all-targets(anti-panic + cognitive-complexity) clean, relay unit tests pass.