Skip to content

fix(anvil): fix multi-fork-url bootstrap race, stale docs, and RoundRobinService guard#14393

Merged
zerosnacks merged 1 commit intozerosnacks/multi-fork-urlfrom
zerosnacks/multi-fork-url-followup
Apr 21, 2026
Merged

fix(anvil): fix multi-fork-url bootstrap race, stale docs, and RoundRobinService guard#14393
zerosnacks merged 1 commit intozerosnacks/multi-fork-urlfrom
zerosnacks/multi-fork-url-followup

Conversation

@zerosnacks
Copy link
Copy Markdown
Member

Summary

Follow-up to #14280. Fixes medium and minor issues identified during review.

Changes

Bootstrap race condition fix

setup_fork_db_config() now uses the primary URL only for bootstrap/discovery calls (get_chain_id, find_latest_fork_block, get_block, get_gas_price). The round-robin provider is built after the fork block is pinned, preventing intermittent startup failures when endpoints are at slightly different chain tips.

is_local detection fix

build_fallback() now uses normalized/parsed URLs for guess_local_url(), consistent with how build() computes is_local. Previously it ran guess_local_url on raw input strings, which could misclassify localhost:8545, bare socket addresses, or IPC paths.

RoundRobinService::new() guard

Added a panic guard for empty transport lists to prevent a % 0 panic in call().

Stale docs/comments

Fixed all references to Alloy FallbackService and health-scored routing:

  • build_fallback() docstring → now describes round-robin + retry
  • CLI --fork-url help text → removed "best-performing endpoint" claim
  • NodeConfig.fork_urls comment → "round-robin load balancing with retry-based failover"
  • ClientForkConfig.fork_urls comment → same
  • setup_fork_db_config debug log → "round-robin" instead of "fallback"

Testing

cargo test -p foundry-config -- endpoints
cargo test -p anvil --lib cmd::tests
cargo test -p anvil --test it -- test_anvil_set_rpc_url_syncs_fork_config test_anvil_reset_with_url_updates_fork_urls

…rvice guard

- Fix bootstrap race condition: use primary URL only for discovery calls
  (get_chain_id, find_latest_fork_block, get_block), then rebuild with
  round-robin provider after the fork block is pinned.

- Fix is_local detection in build_fallback() to use normalized/parsed URLs,
  consistent with build().

- Add panic guard for RoundRobinService::new() with empty transports.

- Fix stale docs/comments that incorrectly referenced Alloy FallbackService
  and health-scored routing in CLI help, NodeConfig, ClientForkConfig, and
  build_fallback() docstring.

Amp-Thread-ID: https://ampcode.com/threads/T-019db0c0-6038-7428-8483-365402ff31a3
Co-authored-by: Amp <amp@ampcode.com>
@zerosnacks zerosnacks marked this pull request as ready for review April 21, 2026 16:40
@zerosnacks zerosnacks merged commit 0c7a967 into zerosnacks/multi-fork-url Apr 21, 2026
16 of 18 checks passed
@zerosnacks zerosnacks deleted the zerosnacks/multi-fork-url-followup branch April 21, 2026 16:57
@github-project-automation github-project-automation Bot moved this to Done in Foundry Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant