edb-rpc-proxy

Crates.ioedb-rpc-proxy
lib.rsedb-rpc-proxy
version0.0.1
created_at2025-09-19 14:24:57.713554+00
updated_at2025-09-19 14:24:57.713554+00
descriptionCaching RPC proxy server for EDB
homepagehttps://medga.org/
repositoryhttps://github.com/edb-rs/EDB
max_upload_size
id1846552
size549,258
Zhuo Zhang (ZhangZhuoSJTU)

documentation

README

EDB RPC Proxy

A high-performance, intelligent caching RPC proxy for Ethereum that can reduce RPC requests by 70-90% and dramatically accelerate blockchain debugging and development workflows.

This document is created by Claude with ❀️.

πŸš€ Quick Start

Install and run in 30 seconds:

# Clone and build
git clone https://github.com/MedGa-eth/EDB
cd EDB
cargo build --release -p edb-rpc-proxy

# Start proxy server with sensible defaults
./target/release/edb-rpc-proxy server

# Or monitor a running proxy with TUI
./target/release/edb-rpc-proxy monitor http://localhost:8546

Use immediately:

# Point your RPC client to the proxy
curl -X POST http://localhost:8546 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Common Issues

If you are using Foundry (e.g., cast) and ebd-rpc-proxy together, where ebd-rpc-proxy is running on a loopback address (e.g., 127.0.0.1), you may encounter connection issues. This is because Foundry's HTTP client (reqwest/hyper) honors *_PROXY environment variables and may route http://127.0.0.1:... through your local proxy, which often drops loopback-to-loopback forwarding. On macOS, localhost may resolve to ::1 (IPv6) first; if your RPC server isn't bound to IPv6, localhost won’t work even though 127.0.0.1 does.

To bypass these issues, run the CLI with proxy bypasses for both IPv4 and IPv6 loopback, and use an explicit loopback that your server actually binds to:

# Ensure loopback addresses bypass any proxy and clear proxy vars
NO_PROXY=localhost,127.0.0.1,::1 \
no_proxy=localhost,127.0.0.1,::1 \
HTTP_PROXY= HTTPS_PROXY= ALL_PROXY= \
http_proxy= https_proxy= all_proxy= \
cast tx 0xda0df2b215534a6cea2304f55ffa307bcb0f4e4b55e3a1158fc9bcde1fd76ae0 \
  --rpc-url http://127.0.0.1:54321

❓ Why Use EDB RPC Proxy?

If you've ever faced these problems:

  • 🚫 "Rate limit exceeded" errors from free RPC providers
  • πŸ’Έ Expensive monthly bills from Infura/Alchemy
  • 🐌 Slow test suites making thousands of identical RPC calls
  • πŸ˜” Your local node crashed and your MEV bot missed opportunities
  • πŸ”„ Manually switching between RPC endpoints when one fails
  • ⏳ Waiting for the same debug_traceTransaction over and over

Then EDB RPC Proxy is your solution!

🎯 Key Benefits

  • πŸ”₯ Massive Performance Gains: 70-90% reduction in RPC requests through intelligent caching
  • πŸ’° Cost Savings: Significantly reduce paid RPC service costs for teams
  • ⚑ Instant Debug Traces: Cache expensive debug/trace calls for instant subsequent access
  • πŸ›‘οΈ High Availability: Automatic failover across 13+ RPC providers with weighted selection
  • 🀝 Team Collaboration: Shared cache benefits entire team's debugging sessions
  • πŸ“Š Real-time Monitoring: TUI interface with live metrics and provider health
  • πŸ”§ Zero Configuration: Works out-of-the-box with sensible defaults
  • 🌐 Universal Compatibility: Works with any Ethereum RPC client (MetaMask, Foundry, Hardhat, etc.)

πŸ“‹ Table of Contents

πŸ“– Overview

EDB RPC Proxy was originally developed as part of the EDB (Ethereum Debugger) project but provides universal benefits for any Ethereum development workflow. While it includes EDB-specific features like instance registration and lifecycle management, the core caching and multi-provider functionality benefits any RPC client.

What Makes It Special?

  • Intelligent Caching: Understands which RPC methods are cacheable and avoids caching non-deterministic requests
  • Weighted Provider Selection: Performance-based provider selection with unique provider per request
  • Advanced Error Handling: Rate limit detection, user error classification, and genuine error consensus
  • Production Ready: Atomic disk persistence, graceful shutdown, comprehensive error handling
  • Highly Observable: Real-time TUI monitoring with metrics, charts, and provider health

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                              EDB RPC PROXY                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
β”‚  β”‚   EDB Client    β”‚    β”‚   Any RPC       β”‚    β”‚   Hardhat/      β”‚             β”‚
β”‚  β”‚   Instance      β”‚    β”‚   Client        β”‚    β”‚   Foundry       β”‚             β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
β”‚            β”‚                      β”‚                      β”‚                     β”‚
β”‚            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β”‚                                   β”‚                                            β”‚
β”‚                            β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”                                     β”‚
β”‚                            β”‚   HTTP API  β”‚                                     β”‚
β”‚                            β”‚  (Port 8546) β”‚                                    β”‚
β”‚                            β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                                     β”‚
β”‚                                   β”‚                                            β”‚
β”‚            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚            β”‚                      β–Ό                      β”‚                     β”‚
β”‚            β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚                     β”‚
β”‚            β”‚         β”‚    RPC HANDLER      β”‚             β”‚                     β”‚
β”‚            β”‚         β”‚                     β”‚             β”‚                     β”‚
β”‚            β”‚         β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚             β”‚                     β”‚
β”‚            β”‚         β”‚ β”‚ Smart Cache     β”‚ β”‚             β”‚                     β”‚
β”‚            β”‚         β”‚ β”‚ β€’ 55+ Methods   β”‚ β”‚             β”‚                     β”‚
β”‚            β”‚         β”‚ β”‚ β€’ Deterministic β”‚ β”‚             β”‚                     β”‚
β”‚            β”‚         β”‚ β”‚ β€’ Block Params  β”‚ β”‚             β”‚                     β”‚
β”‚            β”‚         β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚             β”‚                     β”‚
β”‚            β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚                     β”‚
β”‚            β”‚                    β”‚                        β”‚                     β”‚
β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”                β”‚
β”‚    β”‚  CACHE MANAGER β”‚           β”‚          β”‚ PROVIDER MANAGER β”‚                β”‚
β”‚    β”‚                β”‚           β”‚          β”‚                  β”‚                β”‚
β”‚    β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚           β”‚          β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚                β”‚
β”‚    β”‚ β”‚ In-Memory  β”‚ β”‚           β”‚          β”‚ β”‚ Weighted     β”‚ β”‚                β”‚
β”‚    β”‚ β”‚ LRU Cache  β”‚ β”‚           β”‚          β”‚ β”‚ Selection    β”‚ β”‚                β”‚
β”‚    β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚           β”‚          β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚                β”‚
β”‚    β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚           β”‚          β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚                β”‚
β”‚    β”‚ β”‚ Disk Cache β”‚ β”‚           β”‚          β”‚ β”‚Health Monitorβ”‚ β”‚                β”‚
β”‚    β”‚ β”‚ Atomic I/O β”‚ β”‚           β”‚          β”‚ β”‚& Error Track β”‚ β”‚                β”‚
β”‚    β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚           β”‚          β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚                β”‚
β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β”‚
β”‚                                 β”‚                    β”‚                         β”‚
β”‚                          β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”             β”‚                         β”‚
β”‚                          β”‚   CACHE     β”‚             β”‚                         β”‚
β”‚                          β”‚    HIT      β”‚             β”‚                         β”‚
β”‚                          β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜             β”‚                         β”‚
β”‚                                 β”‚                    β”‚                         β”‚
β”‚                          β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚                          β”‚   Return    β”‚    β”‚  Forward to    β”‚                 β”‚
β”‚                          β”‚   Cached    β”‚    β”‚   Best         β”‚                 β”‚
β”‚                          β”‚  Response   β”‚    β”‚   Provider     β”‚                 β”‚
β”‚                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β”‚                                                      β”‚                         β”‚
└────────────────────────────────────────────-β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                       β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β”‚       WEIGHTED PROVIDER SELECTION (13 Endpoints)          β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                       β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚              β”‚              β”‚                     β”‚              β”‚
         β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€-─▼───┐   β”Œβ”€β”€-───▼───┐
         β”‚Gateway β”‚    β”‚PublicNodeβ”‚   β”‚Tenderly  β”‚   ...   β”‚  Ankr    β”‚   β”‚ LlamaRPC β”‚
         β”‚ Tier 1 β”‚    β”‚ Tier 2   β”‚   β”‚ Tier 1   β”‚         β”‚ Tier 3   β”‚   β”‚ Tier 2   β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

  1. Smart RPC Handler: Analyzes requests for cacheability and tracks tried providers per request
  2. Cache Manager: In-memory LRU cache with atomic disk persistence and merge logic
  3. Provider Manager: Weighted selection based on response time performance tiers
  4. EDB Registry: Lifecycle management for EDB instances (optional, benefits any client)
  5. TUI Monitor: Real-time monitoring interface with metrics and charts

πŸ”§ Installation

Prerequisites

Build from Source

# Clone the EDB repository
git clone https://github.com/MedGa-eth/EDB
cd EDB

# Build the RPC proxy
cargo build --release -p edb-rpc-proxy

# The binary will be at: ./target/release/edb-rpc-proxy

Verify Installation

./target/release/edb-rpc-proxy --help

πŸ’» CLI Commands

The proxy has two main operation modes:

Server Mode (Background Service)

# Start proxy server with defaults
edb-rpc-proxy server

# Start with custom configuration
edb-rpc-proxy server --port 8547 --max-cache-items 500000

Monitor Mode (Interactive TUI)

# Monitor a local proxy
edb-rpc-proxy monitor http://localhost:8546

# Monitor a remote proxy
edb-rpc-proxy monitor https://your-proxy.example.com:8546

Global Options

Option Default Description
--help - Show help information
--version - Show version information

βš™οΈ Configuration

Server Configuration

Argument Default Description
--port 8546 HTTP server listening port
--rpc-urls 13 public RPCs Comma-separated upstream RPC endpoints

Cache Configuration

Argument Default Description
--max-cache-items 1024000 Maximum cached responses (~1GB for 1M items)
--cache-dir ~/.edb/cache/rpc/<chain_id>/ Cache storage directory
--cache-save-interval 5 Minutes between disk saves (0 = shutdown only)

Provider Health

Argument Default Description
--max-failures 3 Failures before marking provider unhealthy
--health-check-interval 60 Seconds between provider health checks

EDB Integration (Optional)

Argument Default Description
--grace-period 0 Seconds before auto-shutdown when no EDB instances (0 = never)
--heartbeat-interval 10 Seconds between EDB instance health checks

Configuration Examples

Development Mode (auto-shutdown when idle):

edb-rpc-proxy server --grace-period 300 --cache-save-interval 1
# Saves cache every minute, shuts down after 5 minutes of no activity

Production Mode (long-running service):

edb-rpc-proxy server --port 8546 --max-cache-items 500000 --grace-period 0
# Large cache, never auto-shutdown, standard port

High-Performance Setup:

edb-rpc-proxy server \
  --max-cache-items 1000000 \
  --cache-save-interval 10 \
  --health-check-interval 30 \
  --max-failures 2
# 1M item cache, frequent health checks, fast failover

Resource Usage Estimates

  • Memory: 50MB + (max_cache_items Γ— 1KB)
  • Disk: Cache size varies by response complexity
  • Network: Reduced by 70-90% due to caching

πŸ“Š TUI Monitoring

The TUI provides real-time monitoring of a running proxy instance:

edb-rpc-proxy monitor http://localhost:8546

Features

  • Provider Health Dashboard: Real-time status, response times, success rates
  • Cache Performance: Hit rates, utilization, method-level statistics
  • EDB Instance Registry: Connected instances and their status
  • Historical Charts: Request rates, cache performance over time
  • Interactive Navigation: Tab between sections, refresh, clear cache

Keyboard Shortcuts

Key Action
Tab Navigate between tabs
← β†’ Switch tabs
r Refresh data
c Clear cache (with confirmation)
q / Ctrl+C Quit

πŸ”Œ EDB Integration

While the proxy works with any RPC client, it includes special features for EDB instances:

Instance Registration

EDB instances can register themselves for lifecycle management:

# EDB instances automatically call:
curl -X POST http://localhost:8546 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"edb_register","params":[12345, 1703123456],"id":1}'

Heartbeat Monitoring

Registered instances send periodic heartbeats:

curl -X POST http://localhost:8546 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"edb_heartbeat","params":[12345],"id":1}'

Auto-Shutdown

When --grace-period > 0, the proxy automatically shuts down when no EDB instances are active, preventing resource waste.

This functionality can be adopted by any project - simply implement the registration and heartbeat calls in your application.

πŸ“‘ API Endpoints

Standard JSON-RPC

All standard Ethereum RPC methods are supported and automatically cached when appropriate:

curl -X POST http://localhost:8546 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x1000000",false],"id":1}'

Management Endpoints

Method Description Example Response
edb_ping Service health check {"status": "healthy", "timestamp": 1703123456}
edb_info Detailed service info Version, uptime, PID, cache info
edb_cache_stats Cache utilization Hit rate, size, utilization
edb_cache_metrics Method-level cache stats Per-method hit rates and performance
edb_active_instances List registered EDB instances PIDs and last heartbeat times
edb_providers Provider health status Health, response times, failure counts
edb_shutdown Graceful shutdown Saves cache and stops service

Example Management Calls

# Check service health
curl -X POST http://localhost:8546 \
  -d '{"jsonrpc":"2.0","method":"edb_ping","id":1}'

# Get detailed cache statistics
curl -X POST http://localhost:8546 \
  -d '{"jsonrpc":"2.0","method":"edb_cache_metrics","id":1}'

# Check provider health and performance
curl -X POST http://localhost:8546 \
  -d '{"jsonrpc":"2.0","method":"edb_providers","id":1}'

🎯 Real-World Use Cases

1. Breaking Through Rate Limits on Free RPCs

Problem: You're hitting rate limits on free public RPC providers and constantly switching between them manually.

Solution: The proxy automatically rotates through 13+ providers with intelligent failover.

# Start proxy with default free providers
edb-rpc-proxy server

# The proxy handles:
# - Automatic rotation when rate limited
# - Weighted selection based on performance
# - Seamless failover without manual intervention
# - Each provider tried only once per request

# Your app just uses one endpoint:
curl http://localhost:8546  # Never worry about rate limits again!

Real Example: A developer scanning NFT metadata hits Ankr's rate limit. The proxy automatically switches to LlamaRPC, then Tenderly, keeping the scan running without any code changes.

2. Reducing Costs on Paid RPC Services

Problem: You have Infura/Alchemy but want to reduce costs by using free RPCs when possible and caching repeated requests.

Solution: Mix paid and free providers with intelligent caching.

# Combine paid and free RPCs (paid as fallback)
edb-rpc-proxy server --rpc-urls \
  "https://eth.llamarpc.com,\
   https://rpc.ankr.com/eth,\
   https://mainnet.infura.io/v3/YOUR_KEY"

# Benefits:
# - Free RPCs used first (weighted by performance)
# - Paid RPC as reliable fallback
# - 70-90% reduction through caching
# - One request cached = savings for entire team

Real Example: A DeFi protocol saves $3,000/month by caching eth_getLogs queries that their 50-person team repeatedly makes while debugging the same smart contract events.

3. High-Reliability Failover for Critical Services

Problem: Your MEV bot or critical service uses a local node that might silently fail, causing missed opportunities.

Solution: Use proxy as an automatic failover layer with health monitoring.

# Local node as primary, public RPCs as emergency backup
edb-rpc-proxy server --rpc-urls \
  "http://localhost:8545,\
   https://rpc.flashbots.net/fast,\
   https://eth.llamarpc.com" \
  --health-check-interval 10 \
  --max-failures 1

# Your MEV bot configuration:
const provider = new ethers.JsonRpcProvider('http://localhost:8546');
// If local node fails, proxy instantly switches to Flashbots RPC
// Your bot never misses a block!

Real Example: An MEV searcher's local node crashed at 3 AM. The proxy automatically failed over to Flashbots RPC, allowing the bot to continue operating and capture a $50K arbitrage opportunity.

4. Blockchain Debugging Teams

Problem: Debug traces cost 10-100x more compute than regular calls. Teams repeatedly debug the same transactions.

Solution: Cache expensive debug calls for instant team-wide access.

# First developer triggers expensive computation
cast run 0xabc... --rpc-url http://localhost:8546  # Takes 3 seconds

# Rest of the team gets instant access
cast run 0xabc... --rpc-url http://localhost:8546  # Takes 5ms (cached!)

# Massive time savings:
# - 10 developers debugging same tx = 30 seconds β†’ 3 seconds total
# - Complex traces cached permanently
# - Share cache across team via network mount

Real Example: Uniswap team debugging a complex MEV sandwich attack. First developer waits 5 seconds for trace computation. Next 20 team members analyzing the same attack get instant responses.

5. Fork Testing & Development

Problem: Hardhat/Foundry fork tests make thousands of identical RPC calls, slowing down test suites.

Solution: Cache fork state queries across test runs.

# First test run populates cache
npx hardhat test --network mainnet  # 2 minutes

# Subsequent runs use cache
npx hardhat test --network mainnet  # 30 seconds

# CI/CD benefits:
# - Faster test execution
# - Reduced RPC costs
# - Deterministic test data

Real Example: Compound's test suite reduced from 5 minutes to 45 seconds by caching eth_getStorageAt calls used in fork tests.

6. Multi-Region Redundancy

Problem: Your global dApp needs reliable RPC access across different regions with automatic geo-failover.

Solution: Deploy proxy instances in multiple regions with shared cache.

# US Instance
edb-rpc-proxy server --cache-dir /shared/cache --port 8546

# EU Instance  
edb-rpc-proxy server --cache-dir /shared/cache --port 8547

# Asia Instance
edb-rpc-proxy server --cache-dir /shared/cache --port 8548

# Benefits:
# - Shared cache across regions
# - Automatic regional failover
# - Reduced latency for global users

Real Example: A DEX aggregator runs proxy instances in 3 AWS regions, reducing average RPC latency from 200ms to 50ms for global users.

7. Smart Contract Verification & Analysis

Problem: Tools like Etherscan verification or Slither analysis repeatedly fetch the same bytecode and state.

Solution: Cache contract data for faster repeated analysis.

# Run Slither analysis with proxy
export WEB3_PROVIDER_URI=http://localhost:8546
slither MyContract.sol

# Benefits:
# - Contract bytecode cached
# - State queries cached
# - 10x faster repeated analysis

Real Example: Security firm reduces contract audit time by 40% by caching all contract interactions during initial analysis phase.

πŸš€ Performance Tuning

Cache Optimization

# For high-volume usage, increase cache size
edb-rpc-proxy server --max-cache-items 1000000

# For memory-constrained environments
edb-rpc-proxy server --max-cache-items 50000

Provider Optimization

# Faster failover for critical applications
edb-rpc-proxy server --max-failures 1 --health-check-interval 15

# More tolerance for unstable providers
edb-rpc-proxy server --max-failures 5 --health-check-interval 120

Persistence Tuning

# Frequent saves for critical data
edb-rpc-proxy server --cache-save-interval 1

# Reduce I/O for high-performance setups
edb-rpc-proxy server --cache-save-interval 30

πŸ” Cached Methods

The proxy intelligently caches 55+ RPC methods when they use deterministic parameters:

Always Cached

  • Chain constants: eth_chainId, net_version
  • Transaction data: eth_getTransactionByHash, eth_getTransactionReceipt
  • Block data: eth_getBlockByHash, eth_getBlockByNumber (with specific block numbers)

Conditionally Cached

  • State queries: eth_call, eth_getBalance, eth_getCode (only with specific block numbers, not "latest")
  • Debug traces: debug_traceTransaction, trace_transaction (immutable once computed)
  • Logs: eth_getLogs (only with specific block ranges)

Never Cached

  • Dynamic data: eth_blockNumber, eth_gasPrice, eth_estimateGas
  • Account state: Methods using "latest", "pending", "safe", "finalized" block parameters
  • Network state: net_peerCount, eth_syncing

🎯 Provider Selection Algorithm

The proxy uses a sophisticated weighted selection system:

Performance Tiers

  • Tier 1 (0-199ms): 100% weight - highest priority
  • Tier 2 (200-399ms): 60% weight
  • Tier 3 (400-599ms): 30% weight
  • Tier 4 (600ms+): 10% weight - lowest priority

Selection Strategy

  1. Weighted Random: Faster providers selected more often
  2. Unique Per Request: Each provider tried only once per request
  3. Error Consensus: Returns error only when multiple unique providers agree
  4. Automatic Recovery: Failed providers restored when healthy

Default Provider Pool (13 endpoints)

  • rpc.eth.gateway.fm
  • ethereum-rpc.publicnode.com
  • mainnet.gateway.tenderly.co
  • rpc.flashbots.net/fast
  • rpc.flashbots.net
  • gateway.tenderly.co/public/mainnet
  • eth-mainnet.public.blastapi.io
  • ethereum-mainnet.gateway.tatum.io
  • eth.api.onfinality.io/public
  • eth.llamarpc.com
  • api.zan.top/eth-mainnet
  • eth.drpc.org
  • ethereum.rpc.subquery.network/public

πŸ› οΈ Development

Running from Source

# Development mode with debug logging
RUST_LOG=debug cargo run --bin edb-rpc-proxy -- server --grace-period 300

# Run with TUI monitoring
cargo run --bin edb-rpc-proxy -- monitor http://localhost:8546

# Run tests
cargo test -p edb-rpc-proxy

# Run with custom configuration
cargo run --bin edb-rpc-proxy -- server \
  --port 8547 \
  --max-cache-items 10000 \
  --cache-save-interval 1

Testing

# Run all tests
cargo test -p edb-rpc-proxy

# Run specific test
cargo test -p edb-rpc-proxy test_provider_tried_once_per_request

# Run with output
cargo test -p edb-rpc-proxy -- --nocapture

# Run integration tests
cargo test -p edb-rpc-proxy --test integration_tests

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make changes and add tests
  4. Run tests: cargo test -p edb-rpc-proxy
  5. Submit a pull request

πŸ“ License

This project is licensed under the MIT OR Apache-2.0 license.

🀝 Community

πŸ™ Acknowledgments

  • Built as part of the EDB (Ethereum Debugger) project
  • Uses public RPC endpoints from various providers
  • Inspired by the need for efficient blockchain development workflows

Get started in 30 seconds β†’ Just run edb-rpc-proxy server and point your RPC client to http://localhost:8546!

Commit count: 237

cargo fmt