Skip to content

feat: add weighted rpc steering #6090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: feature/add-weighted-random-steering-load-balancing
Choose a base branch
from

Conversation

DaMandal0rian
Copy link
Contributor

Summary

Adds weighted random steering to Graph Node’s Ethereum RPC provider selection, enabling per-endpoint load balancing with fractional weights and optional runtime control via a new CLI/config flag.

  • add weighted random steering flag for Ethereum RPC providers
  • allow provider entries to specify connection weights
  • select RPC adapters using weighted random strategy

Key Changes

  • Decimal weight configuration: RPC providers accept weights as f64 fractions (0.0–1.0), defaulting to 1.0.
  • Weighted steering flag: --weighted-rpc-steering (and corresponding config option) toggles the new load-balancing strategy.
  • Randomized adapter selection: Providers are chosen using a weighted distribution based on their configured fractions.
  • Validation: Configuration rejects negative weights or values above 1.0.

Configuration Format

Enable weighted steering with custom fractions:

[chains.mainnet]
weighted_rpc_steering = true
provider = [
  { 
    label = "fast-node",
    details = { type = "web3", url = "https://fast.example", weight = 0.8 }
  },
  { 
    label = "backup-node",
    details = { type = "web3", url = "https://backup.example", weight = 0.2 }
  }
]

Weights omitted or set to 1.0 distribute traffic evenly.


Implementation Details

  • Configuration: Added weight field and weighted_rpc_steering flag in node/src/config.rs with serde support.
  • CLI: node/src/opt.rs exposes --weighted-rpc-steering flag.
  • Network setup: node/src/network_setup.rs forwards weights to adapter creation.
  • Ethereum adapter: chain/ethereum/src/network.rs implements weighted sampling logic in RPC selection.

Future Extensions

  • Support dynamic weight updates without restarting the node.
  • Expose metrics for per-provider utilization to tune weights automatically.
  • Extend weighted steering to other chains or transport layers.

Test Plan

  • Unit tests for configuration parsing of fractional weights.
  • CLI integration tests for --weighted-rpc-steering.
  • Manual verification against multiple RPC endpoints with uneven weights.
  • (Pending) cargo test -p graph-node -p graph-chain-ethereum once protoc and proto dependencies are available.

@DaMandal0rian DaMandal0rian requested a review from Copilot August 11, 2025 00:19
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds weighted random steering functionality to Graph Node's Ethereum RPC provider selection system, allowing operators to configure fractional weights (0.0-1.0) for load balancing across different RPC endpoints.

Key Changes

  • Added weighted random steering configuration flag and CLI option
  • Implemented weight-based provider selection using fractional values (0.0-1.0)
  • Modified adapter selection logic to support both weighted and traditional selection strategies

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
node/src/opt.rs Added CLI flag for enabling weighted RPC steering
node/src/config.rs Added weight field to Provider struct with validation and serde support
node/src/network_setup.rs Integrated weighted steering flag into network configuration
node/src/chain.rs Updated adapter creation to pass weight parameter
chain/ethereum/src/network.rs Implemented weighted selection algorithm using WeightedIndex
node/resources/tests/full_config.toml Updated test configuration with weight examples

@DaMandal0rian DaMandal0rian changed the base branch from master to feature/add-weighted-random-steering-load-balancing August 11, 2025 00:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update chain/ethereum/src/network.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update chain/ethereum/src/network.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update chain/ethereum/src/network.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update chain/ethereum/src/network.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update chain/ethereum/src/network.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update chain/ethereum/src/network.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@DaMandal0rian DaMandal0rian force-pushed the codex/add-weighted-random-steering-load-balancing branch from 50b2cca to c3d0c5b Compare August 11, 2025 00:40
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