Skip to content

perf(address): recent-first MetaTxs fast path via Dune (mirror of Calls) - #85

Merged
amanusk merged 2 commits into
masterfrom
metatx-recent-first
Jun 30, 2026
Merged

perf(address): recent-first MetaTxs fast path via Dune (mirror of Calls)#85
amanusk merged 2 commits into
masterfrom
metatx-recent-first

Conversation

@amanusk

@amanusk amanusk commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Split out of #84 — this is pre-existing work that got bundled into the WS branch when it was cut from a local master that was one commit ahead of origin/master. It is independent (touches address.rs / dune.rs / mod.rs; no overlap with the WS change).

Problem

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.

Change

A meta-tx where the address is the intender is an execute_from_outside* call to the
address, 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:

  • 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.

Verification

  • Windowed SQL verified against production Dune (recent-first rows).
  • Both new dune guard tests pass; release build clean.

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for starknet.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 thread src/network/dune.rs
Comment thread src/network/address.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread src/network/address.rs Outdated
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 thread src/network/address.rs
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 thread src/network/dune.rs Outdated
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>
@amanusk
amanusk merged commit c22fca5 into master Jun 30, 2026
2 checks passed
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