perf: eliminate redundant RPC calls in deposit and withdrawal flows#71
Open
aioverlord92 wants to merge 6 commits intomatter-labs:mainfrom
Open
perf: eliminate redundant RPC calls in deposit and withdrawal flows#71aioverlord92 wants to merge 6 commits intomatter-labs:mainfrom
aioverlord92 wants to merge 6 commits intomatter-labs:mainfrom
Conversation
Two classes of unnecessary RPC round-trips removed:
1. Duplicate receipt fetch in finalization services
fetchFinalizeDepositParams() called getReceiptWithL2ToL1() twice for
the same tx hash - once to find the L1MessageSent log and again to
derive the messenger log index. The second fetch is eliminated by
reusing the already-fetched receipt. Applies to both ethers and viem
adapters, saving one L2 RPC call per withdrawal finalization.
2. Repeated L1 fee fetches across quoteL2BaseCost + quoteL1Gas
Each deposit route called fetchFees() (eth_feeHistory / eth_gasPrice)
independently in quoteL2BaseCost and then again in quoteL1Gas,
resulting in 2 redundant L1 fee queries per deposit quote. Fix:
- Export fetchFees as a public function from core deposits/gas
- Add optional precomputedMarket to QuoteL2BaseCostInput and
QuoteL1GasInput so callers can supply pre-fetched fees
- Add fetchL1MarketFees() helpers in ethers/viem adapter service
layers
- Pre-fetch L1 market fees once at the start of each deposit route's
build() and pass it to both callers, saving one L1 RPC call per
deposit quote across all 4 routes × 2 adapters = 8 route files
Net savings per deposit quote: -1 L1 fee RPC call (~100-500 ms)
Net savings per withdrawal finalization: -1 L2 receipt RPC call (~50-200 ms)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…alization services Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
Duplicate receipt fetch eliminated in finalization services:
fetchFinalizeDepositParams()was callinggetReceiptWithL2ToL1()twice for the same tx hash — once to locate the L1MessageSent log and once to derive the messenger log index. The second fetch is removed by reusing the already-fetched receipt. Applies to both ethers and viem adapters.Redundant L1 fee fetches eliminated across all deposit routes:
quoteL2BaseCostandquoteL1Gaseach independently calledfetchFees()(i.e.eth_feeHistoryoreth_gasPrice) on the L1 provider. These two calls always fetch the same data within a single deposit quote. Fixed by:fetchFeesandMarketFeesfromcore/resources/deposits/gasprecomputedMarketfield toQuoteL2BaseCostInputandQuoteL1GasInputso callers can supply pre-fetched feesfetchL1MarketFees()helpers in both ethers and viem adapter service layersbuild()and passing it to bothquoteL2BaseCostandquoteL1GasNet savings per deposit quote: −1 L1 fee RPC call (~100–500 ms latency reduction)
Net savings per withdrawal finalization: −1 L2 receipt RPC call (~50–200 ms latency reduction)
Files affected: 15 (4 ethers routes, 4 viem routes, 2 adapter service layers × 2 adapters, 1 core gas module, 2 finalization services)
Test plan
bun run typecheck— passes with no errors (verified locally)bun run testto ensure unit tests still pass🤖 Generated with Claude Code