Skip to content

perf: eliminate redundant RPC calls in deposit and withdrawal flows#71

Open
aioverlord92 wants to merge 6 commits intomatter-labs:mainfrom
aioverlord92:perf/reduce-rpc-calls
Open

perf: eliminate redundant RPC calls in deposit and withdrawal flows#71
aioverlord92 wants to merge 6 commits intomatter-labs:mainfrom
aioverlord92:perf/reduce-rpc-calls

Conversation

@aioverlord92
Copy link
Copy Markdown

Summary

  • Duplicate receipt fetch eliminated in finalization services: fetchFinalizeDepositParams() was calling getReceiptWithL2ToL1() 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: quoteL2BaseCost and quoteL1Gas each independently called fetchFees() (i.e. eth_feeHistory or eth_gasPrice) on the L1 provider. These two calls always fetch the same data within a single deposit quote. Fixed by:

    • Exporting fetchFees and MarketFees from core/resources/deposits/gas
    • Adding an optional precomputedMarket field to QuoteL2BaseCostInput and QuoteL1GasInput so callers can supply pre-fetched fees
    • Adding fetchL1MarketFees() helpers in both ethers and viem adapter service layers
    • Pre-fetching L1 market fees once at the start of each deposit route's build() and passing it to both quoteL2BaseCost and quoteL1Gas

Net 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

  • Run bun run typecheck — passes with no errors (verified locally)
  • Run bun run test to ensure unit tests still pass
  • Run e2e tests against a testnet node to confirm deposit quote latency is reduced
  • Verify withdrawal finalization still works end-to-end

🤖 Generated with Claude Code

aioverlord92 and others added 6 commits March 11, 2026 16:56
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>
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.

2 participants