perf(address): recent-first MetaTxs fast path via Dune (mirror of Calls) - #85
Merged
Conversation
The cold MetaTxs tab scanned the 5k-block tip then walked ExtendDown backward one pf-query window at a time. On accounts whose meta-tx activity sits deep in history that is slow and surfaces the *oldest* meta-txs first. A meta-tx where ADDR is the intender is an execute_from_outside* CALL to ADDR, so Dune's trace-indexed starknet.calls (selector-filtered, ORDER BY block DESC) jumps straight to the most-recent ones. Add a Dune fast-paint mirroring the Calls progressive window ladder: - dune: QueryShape::ContractMetaTxCallsWindowed = ContractCallsWindowed narrowed to the three execute_from_outside selectors; shared row parser extracted to avoid duplication. Selector literals pinned by a test. - address: emit_recent_meta_txs_via_dune runs a 90d + hedged-365d window concurrently (cancel-on-fill), bulk-fetches the outer txs via pf, runs the shared classifier, and streams survivors via the cursor-neutral AddressMetaTxsStreamed so the pf scan still owns lifetime backfill and the private-pool / component-selector cases Dune can't see. Tail-latency hedge generalised and shared with Calls. Verified the windowed SQL against production Dune (recent-first rows) and both new dune guard tests pass; release build clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a recent-first “fast paint” path for the MetaTxs tab by querying Dune’s trace-indexed starknet.calls table for execute_from_outside* calls to the viewed address (where that address is the meta-tx intender). It mirrors the existing Calls tab’s progressive Dune window ladder to quickly render the newest public meta-transactions while keeping the existing pf-query scan as the authoritative backfill path.
Changes:
- Add a new Dune query shape to fetch meta-tx candidate calls (filtered to the three
execute_from_outside*selectors) and refactor shared row parsing forstarknet.calls. - Add an address-level recent-first meta-tx fast paint that runs concurrent Dune windows (90d + hedged 365d), bulk-fetches outer txs via pf-query, classifies, persists, and streams results cursor-neutrally.
- Generalize the tail-latency hedge helper used by the Calls ladder and reuse it for the MetaTxs Dune queries.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/network/mod.rs | Wires the optional Dune client through to the MetaTxs fetch path. |
| src/network/dune.rs | Adds ContractMetaTxCallsWindowed query shape, shared starknet.calls row parser, and selector guard test. |
| src/network/address.rs | Implements Dune-based recent-first MetaTxs fast paint and introduces a generic hedged-query helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+3750
to
+3757
| let dune_fut = async { | ||
| if continuation_token.is_none() { | ||
| if let Some(d) = dune { | ||
| emit_recent_meta_txs_via_dune(address, d, pf, abi_reg, &ds_dyn, action_tx).await; | ||
| } | ||
| } | ||
| }; | ||
| let (outcome_res, private_outcome, _) = tokio::join!(account_fut, private_fut, dune_fut); |
Comment on lines
+4565
to
+4569
| hedged_query( | ||
| || dune_client.query_contract_calls_windowed(address, 0, u64::MAX, limit, Some(min_date)), | ||
| hedge_delay, | ||
| ) | ||
| .await |
Comment on lines
+1017
to
+1036
| // Mirror of the persisted `ContractMetaTxCallsWindowed` SQL (the literal | ||
| // selector list must stay identical — `meta_tx_sql_has_correct_selectors` | ||
| // guards the persisted copy). | ||
| let sql = format!( | ||
| "SELECT transaction_hash, caller_address, entry_point_selector, \ | ||
| block_number, block_time, revert_reason \ | ||
| FROM starknet.calls \ | ||
| WHERE contract_address = {} \ | ||
| AND block_date >= date '{}' \ | ||
| AND block_number BETWEEN {} AND {} \ | ||
| AND call_type = 'CALL' \ | ||
| AND entry_point_selector IN ( \ | ||
| 0x007ec457cd7ed1630225a8328f826a29a327b19486f6b2882b4176545ebdbe3d, \ | ||
| 0x034cc13b274446654ca3233ed2c1620d4c5d1d32fd20b47146a3371064bdc57d, \ | ||
| 0x03dbc508ba4afd040c8dc4ff8a61113a7bcaf5eae88a6ba27b3c50578b3587e3 \ | ||
| ) \ | ||
| ORDER BY block_number DESC \ | ||
| LIMIT {}", | ||
| contract_hex, min_date_str, from_capped, to_capped, limit | ||
| ); |
…, log/SQL guards Acts on the Copilot review threads on the MetaTxs Dune fast-path PR: - Dune fast-paint no longer gates the terminal AddressMetaTxsLoaded. It now runs as a detached, cancel-token-guarded task concurrent with the pf scans; the join waits only on pf, so the loading state / next_token / auto-fill clear on pf timing instead of waiting on a tailing Dune window. The spawn is tied to the session CancellationToken so foreground navigation still cancels it (threaded `cancel` through fetch_address_meta_txs + its caller). - Restore address-scoped logging lost when hedged_query was generalised: both call sites now run under a tracing span carrying addr/min_date. - Extract the meta-tx fallback SQL into meta_tx_calls_windowed_sql and extend meta_tx_sql_has_correct_selectors to pin BOTH the persisted and fallback selector copies, so the two SQL paths can't drift. - Add fresh_meta_tx_hashes pure helper + unit test for the cross-rung dedup. cargo fmt clean; new + existing dune/address unit tests pass; release build clean. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Problem
The cold MetaTxs tab scanned the 5k-block tip then walked
ExtendDownbackward onepf-query window at a time. On accounts whose meta-tx activity sits deep in history that
is slow and surfaces the oldest meta-txs first.
Change
A meta-tx where the address is the intender is an
execute_from_outside*call to theaddress, so Dune's trace-indexed
starknet.calls(selector-filtered,ORDER BY block DESC)jumps straight to the most-recent ones. Adds a Dune fast-paint mirroring the Calls
progressive window ladder:
QueryShape::ContractMetaTxCallsWindowed=ContractCallsWindowednarrowed tothe three
execute_from_outsideselectors; shared row parser extracted to avoidduplication. Selector literals pinned by a test.
emit_recent_meta_txs_via_duneruns a 90d + hedged-365d window concurrently(cancel-on-fill), bulk-fetches the outer txs via pf, runs the shared classifier, and
streams survivors via the cursor-neutral
AddressMetaTxsStreamedso the pf scan stillowns lifetime backfill and the private-pool / component-selector cases Dune can't see.
Tail-latency hedge generalised and shared with Calls.
Verification
🤖 Generated with Claude Code