Add HTTP request coalescing (in-flight deduplication) - #2
Merged
Conversation
Collapse identical concurrent read requests on the HTTP JSON-RPC path into a single upstream call and fan the response back to every caller, reducing redundant provider load and rate-limit exposure under bursty traffic. - chain.Chain gains Coalesceable(method): a per-chain allowlist of read-only, idempotent methods (EVM allowlist shared by eth+tron; solana and btc have their own). Default-deny: anything not listed is sent individually. - Endpoint holds a singleflight.Group; a single coalesceable request runs through it keyed by method+params (id excluded). - The failover loop is extracted into forwardWithFailover; the leader runs it under a detached context so one client disconnecting can't cancel the shared call. Each caller writes a copy of the shared response stamped with its own id. - Batches and non-allowlisted methods bypass coalescing entirely. - New haprovider_coalesced_requests_total metric; README updated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds request coalescing on the HTTP JSON-RPC path: identical concurrent read requests collapse into a single upstream call, and that one response is fanned back to every caller.
This reduces redundant load on upstream providers and lowers rate-limit (429) exposure under bursty traffic (e.g. many clients polling
eth_getTransactionReceiptfor the same hash).How
chain.ChaingainsCoalesceable(method string) bool— a per-chain allowlist of read-only, idempotent methods. The EVM allowlist is shared byethandtron;solanaandbtchave their own. Default-deny: anything not on the list is sent individually.core.Endpointholds asingleflight.Group. A single coalesceable request runs through it, keyed bymethod + params(the JSON-RPCidis excluded since it varies per client).forwardWithFailover. The coalescing leader runs it under a detached context (context.WithoutCancel) so one client disconnecting can't cancel the shared upstream call the others are waiting on. Each caller writes a value-copy of the shared response stamped with its ownid(never mutating the shared response).haprovider_coalesced_requests_total{endpoint,method}metric; README updated.Scope / non-goals
Testing
internal/coalesce_test.go, driving the real handler concurrently against a hit-counting mock upstream:eth_call→ 1 upstream hit; every client gets the result with its own id echoed.eth_sendRawTransaction→ 10 hits (never coalesced).go test -race ./...green (stable across repeated runs);go vetandgolangci-lintclean.