Skip to content

feat(tokens): materialize tokens_gnosis_suicide_events staging table - #9879

Merged
jeff-dude merged 3 commits into
mainfrom
robin/cur2-2813-perftokens_gnosis_suicide_transfers-materialize
Jul 23, 2026
Merged

feat(tokens): materialize tokens_gnosis_suicide_events staging table#9879
jeff-dude merged 3 commits into
mainfrom
robin/cur2-2813-perftokens_gnosis_suicide_transfers-materialize

Conversation

@0xRobin

@0xRobin 0xRobin commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Materializes the SELFDESTRUCT window computation from tokens_gnosis_suicide_transfers into a shared staging model, dropping gnosis.traces scans from 3x to 1x per hourly run (~0.95 CPU-hrs and ~384 GB IO saved daily on the CUR2-2813 baseline). Bundled correctness fix: the original ROW_NUMBER/LAG OVER (PARTITION BY address ORDER BY block_time) was nondeterministic on 82 of 143,517 rows (4 addresses that self-destructed multiple times in the same block) — new total order (block_time, block_number, tx_index, trace_address) makes event_sequence stable across runs.

Live-engine validation (full-history delta_prod.gnosis.traces): row count and unique-key preserved (143,517 = source suicide count); disagreement with the old window strictly bounded to the 82 tie-affected rows (53 seq-shifts, 12 prev-shifts). Design pass by Andre Monteiro (2026-06-30). Linear: CUR2-2813.

Extracts the SELFDESTRUCT window computation from tokens_gnosis_suicide_transfers into a shared staging model, dropping gnosis.traces scans from 3x to 1x per hourly run (~0.95 CPU-hrs and ~384 GB IO saved daily on baseline).

Also fixes a latent nondeterminism: the ROW_NUMBER/LAG window used ORDER BY block_time alone, which had ties on 82 of 143,517 rows over full history. Total order (block_time, block_number, tx_index, trace_address) makes event_sequence stable across runs. Design pass by Andre Monteiro (2026-06-30).
@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes how suicide transfer windows are sequenced (small row-level corrections on same-block ties) and adds a new dependency in the hourly Gnosis tokens pipeline, though scope is limited to suicide staging and downstream refs.

Overview
Introduces a materialized tokens_gnosis_suicide_events staging model so SELFDESTRUCT ordering and window fields are computed once from gnosis.traces, and tokens_gnosis_suicide_transfers reads that table instead of inlining the same trace scan three times per hourly build.

The staging model replaces ORDER BY block_time only with a deterministic total order (block_time, block_number, tx_index, trace_address) for event_sequence and previous_block_time, fixing unstable sequencing when the same address self-destructs multiple times in one block.

Schema documentation and uniqueness / not-null tests are added for the new model; downstream suicide transfer logic is unchanged aside from sourcing events from ref('tokens_gnosis_suicide_events').

Reviewed by Cursor Bugbot for commit bfaa889. Configure here.

@github-actions github-actions Bot added WIP work in progress dbt: tokens covers the Tokens dbt subproject labels Jul 8, 2026
@0xRobin

0xRobin commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: String-based trace_address ordering gives incorrect sequence for multi-digit indices
    • Replaced array_join(trace_address, ',') with direct trace_address in both window ORDER BY clauses so ordering uses numeric element-wise array comparison.

Create PR

Or push these changes by commenting:

@cursor push 238250544f
Preview (238250544f)
diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/gnosis/tokens_gnosis_suicide_events.sql b/dbt_subprojects/tokens/models/transfers_and_balances/gnosis/tokens_gnosis_suicide_events.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/gnosis/tokens_gnosis_suicide_events.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/gnosis/tokens_gnosis_suicide_events.sql
@@ -29,11 +29,11 @@
     , refund_address
     , ROW_NUMBER() OVER (
           PARTITION BY address
-          ORDER BY block_time, block_number, tx_index, array_join(trace_address, ',')
+          ORDER BY block_time, block_number, tx_index, trace_address
       ) AS event_sequence
     , LAG(block_time) OVER (
           PARTITION BY address
-          ORDER BY block_time, block_number, tx_index, array_join(trace_address, ',')
+          ORDER BY block_time, block_number, tx_index, trace_address
       ) AS previous_block_time
 FROM
     {{ source('gnosis', 'traces') }}

You can send follow-ups to the cloud agent here.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit bfaa889. Configure here.

@0xRobin

0xRobin commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@cursor push 2382505

Replace array_join(trace_address, ',') with direct trace_address ordering
in window functions to use numeric element-wise array comparison instead of
lexicographic string comparison.

Applied via @cursor push command
@0xRobin
0xRobin marked this pull request as ready for review July 15, 2026 10:45
@github-actions github-actions Bot added ready-for-review this PR development is complete, please review and removed WIP work in progress labels Jul 15, 2026
@0xRobin
0xRobin requested review from a team and jeff-dude July 15, 2026 10:45

@jeff-dude jeff-dude left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this require a one-time backfill of tokens_gnosis_suicide_transfers so the historical ordering fix reaches existing output rows?

@jeff-dude jeff-dude added ready-for-merging and removed ready-for-review this PR development is complete, please review labels Jul 16, 2026
@jeff-dude
jeff-dude merged commit f8e655c into main Jul 23, 2026
11 checks passed
@jeff-dude
jeff-dude deleted the robin/cur2-2813-perftokens_gnosis_suicide_transfers-materialize branch July 23, 2026 21:10
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

dbt: tokens covers the Tokens dbt subproject ready-for-merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants