feat(tokens): materialize tokens_gnosis_suicide_events staging table - #9879
Conversation
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).
PR SummaryMedium Risk Overview The staging model replaces Schema documentation and uniqueness / not-null tests are added for the new model; downstream suicide transfer logic is unchanged aside from sourcing events from Reviewed by Cursor Bugbot for commit bfaa889. Configure here. |
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
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 directtrace_addressin both window ORDER BY clauses so ordering uses numeric element-wise array comparison.
- Replaced
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.
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
…ansfers-materialize
jeff-dude
left a comment
There was a problem hiding this comment.
Does this require a one-time backfill of tokens_gnosis_suicide_transfers so the historical ordering fix reaches existing output rows?


Materializes the SELFDESTRUCT window computation from
tokens_gnosis_suicide_transfersinto a shared staging model, droppinggnosis.tracesscans 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 originalROW_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)makesevent_sequencestable 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.