Skip to content

feat: network-aware EVM defaults and bootstrap-peer fallback#27

Merged
Nic-dorman merged 5 commits intomainfrom
fix/evm-defaults-and-peer-fallback
Apr 21, 2026
Merged

feat: network-aware EVM defaults and bootstrap-peer fallback#27
Nic-dorman merged 5 commits intomainfrom
fix/evm-defaults-and-peer-fallback

Conversation

@Nic-dorman
Copy link
Copy Markdown
Collaborator

Summary

Two quality-of-life fixes for running antd against a real network without a devnet manifest. Discovered while testing indelible against Arbitrum One mainnet on 2026-04-21 — both issues surfaced as confusing, late-failing errors that cost real time to debug.

1. Network-aware EVM defaults

Before this PR, EVM_RPC_URL silently defaulted to `http://127.0.0.1:8545\` for every `--network default` deployment. External clients consumed that URL from `PrepareUpload` responses and failed with `dial tcp 127.0.0.1:8545: connection refused` — but only after paying the full ~7 min antd encryption + quote round-trip on mainnet.

New `antd/src/evm_defaults.rs` resolves `(rpc_url, token, vault)` from `--network` + optional `EVM_NETWORK` preset + individual env overrides:

`--network` default `EVM_NETWORK` default RPC token vault
`default` `arbitrum-one` `https://arb1.arbitrum.io/rpc\` `evmlib::Network::ArbitrumOne` `evmlib::Network::ArbitrumOne`
`local` `local` `http://127.0.0.1:8545\` (empty) (empty)
  • `EVM_NETWORK=arbitrum-sepolia` switches to the Sepolia testnet preset.
  • Any of `EVM_RPC_URL` / `EVM_PAYMENT_TOKEN_ADDRESS` / `EVM_PAYMENT_VAULT_ADDRESS` / legacy `EVM_DATA_PAYMENTS_ADDRESS` still override.
  • `--network local` keeps its existing behaviour for devnet tooling.
  • The `Network::new_custom` call is guarded against empty addresses to match prior local-with-no-env behaviour (no panic).

2. Bootstrap-peer fallback

New `antd/src/peers.rs` reads ant-client's shared `bootstrap_peers.toml` via `ant_core::config::load_bootstrap_peers` as a fallback when `--peers` / `ANTD_PEERS` is empty and we're not on the local devnet. `SocketAddr` entries are converted to `/ip4//udp//quic` multiaddrs that saorsa-core accepts.

Explicit `--peers` / env still wins; `--network local` never falls back. Previously antd required operators to know the MultiAddr format and set `ANTD_PEERS` separately from every other ant-* tool, even though ant-node installs already populate the shared toml.

Test plan

  • `cargo check` passes locally (skipped here — CI)
  • Unit tests added for `evm_defaults` (preset selection, overrides, legacy vault var, local mode) — use injected env lookup to avoid cross-test races on real env
  • Unit tests added for `peers` (IPv4 + IPv6 socket → multiaddr round-trip)
  • CI `cargo test` green on all crates
  • Manual smoke: start antd with `--network default` and no env → log shows `rpc_url=https://arb1.arbitrum.io/rpc\`, `preset=arbitrum-one`
  • Manual smoke: start antd with `--network local` and no env → log shows `rpc_url=http://127.0.0.1:8545\` and empty-address warning
  • Manual smoke: populate `%APPDATA%/ant/bootstrap_peers.toml` with mainnet peers and start antd with no `--peers` → log shows "loaded bootstrap peers from ant-client"
  • Mainnet integration: a full upload/download round-trip with zero EVM env vars set

Out of scope

Doesn't change the existing `AUTONOMI_WALLET_KEY` / internal-signer wallet loading path semantics — it just routes both branches through the same resolver.

Separately filed: antd HTTP handlers appear to be starved by saorsa-core NAT-traversal churn during initial bootstrap (20–30 min window). That's upstream in saorsa-core and has in-flight PRs.

🤖 Generated with Claude Code

Two quality-of-life fixes for running antd against a real network
without a devnet manifest.

EVM defaults
- New `antd/src/evm_defaults.rs` resolves `(rpc_url, token, vault)` from
  `--network` + optional `EVM_NETWORK` preset + individual env overrides.
- When `--network default`, the preset defaults to `arbitrum-one`,
  picking addresses from `evmlib::Network::ArbitrumOne` so mainnet is the
  opt-out path rather than opt-in.
- `EVM_NETWORK=arbitrum-sepolia` selects the Sepolia testnet preset; any
  individual `EVM_RPC_URL` / `EVM_PAYMENT_TOKEN_ADDRESS` /
  `EVM_PAYMENT_VAULT_ADDRESS` (or legacy `EVM_DATA_PAYMENTS_ADDRESS`) env
  var still overrides.
- `--network local` keeps its existing `http://127.0.0.1:8545` + empty
  addresses default — devnet tooling still provides addresses via env.
- The EVM `new_custom` call is now guarded against empty token/vault to
  avoid a panic in local-with-no-env scenarios, matching prior behaviour.
- Both internal-signer (`AUTONOMI_WALLET_KEY` set) and external-signer
  branches now use the same resolver.

Previously, `EVM_RPC_URL` silently defaulted to `http://127.0.0.1:8545`
for every `--network default` deployment. External clients like indelible
consumed that URL from `PrepareUpload` responses and failed with a
confusing "dial tcp 127.0.0.1:8545" error — but only AFTER paying the
full ~7 min antd encryption + quote round-trip on mainnet.

Bootstrap-peer fallback
- New `antd/src/peers.rs` reads ant-client's shared
  `bootstrap_peers.toml` (via `ant_core::config::load_bootstrap_peers`)
  as a fallback when `--peers` / `ANTD_PEERS` is empty and `--network`
  is not `local`. `SocketAddr` entries are converted to
  `/ip4/<ip>/udp/<port>/quic` multiaddrs.
- Explicit `--peers` / env still wins. `--network local` never falls back.

Previously antd required operators to know the MultiAddr format and set
`ANTD_PEERS` separately from every other ant-* tool. The shared toml is
already populated by ant-node installs; having antd read it matches
ant-cli's behaviour and removes a setup step.

Tests
- `evm_defaults`: unit tests with an injected env lookup closure covering
  default/local/sepolia presets, individual overrides, legacy
  `EVM_DATA_PAYMENTS_ADDRESS`, and the precedence of
  `EVM_PAYMENT_VAULT_ADDRESS` over it.
- `peers`: unit tests covering IPv4 and IPv6 socket → multiaddr
  conversion.

Discovered while validating indelible PR #8 (network timeouts + DataCost
probe) against Arbitrum One mainnet on 2026-04-21.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Nic-dorman Nic-dorman marked this pull request as draft April 21, 2026 09:56
Nic-dorman and others added 4 commits April 21, 2026 10:57
The helper's closure captures an owned HashMap via `move`, so it
doesn't borrow from `pairs` and shouldn't claim to. CI's rustc
rejected `+ '_` because `&[(&str, &str)]` has three possible input
lifetimes and none were named.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Nic-dorman Nic-dorman marked this pull request as ready for review April 21, 2026 20:36
@Nic-dorman Nic-dorman merged commit 6b74518 into main Apr 21, 2026
3 checks passed
@Nic-dorman Nic-dorman deleted the fix/evm-defaults-and-peer-fallback branch April 22, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant