perf(gas_solana_tx_fees): merge compute_limit + compute_unit_price into single compute_budget table#9880
Conversation
…olana_compute_budget Introduce gas_solana_compute_budget: one incremental delta table keyed (block_date, block_slot, tx_id) with both compute_limit (opcode 0x02) and compute_unit_price (opcode 0x03) columns, populated from a single filtered scan of solana.instruction_calls. Rewrite gas_solana_compute_limit and gas_solana_compute_unit_price as views over the merged table so external consumers of dune.gas_solana.compute_limit and dune.gas_solana.compute_unit_price keep the same column contract. Update solana_tx_fees_macro (used by gas_solana_tx_fees_current and the 17 quarterly backfills) to LEFT JOIN once against gas_solana_compute_budget instead of joining compute_limit and compute_unit_price separately. Baseline (2026-06-13): 86.66M limit + 74.65M price rows across two ~200M-key hash joins. Merged: 89.35M rows in one table, one hash join. Live-engine EXCEPT ALL both ways = 0 (n=89,353,063 on both sides). Ref CUR2-2801.
PR SummaryMedium Risk Overview
Reviewed by Cursor Bugbot for commit a2171a3. Configure here. |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a2171a3. Configure here.
Adds `{% if target.name == 'ci' %} AND <partition> >= current_date - interval '3' day` to source scans in the two files modified by this PR so the solana CI job (state:modified.macros fan-out to all 18 tx_fees models) prunes instead of full-scanning and completes within the 90-minute CI cap.
- gas_solana_compute_budget.sql: bound instruction_calls block_date in CI.
- solana_tx_fees_macro.sql: bound transactions t.block_date, compute_budget cb.block_date, block_leaders b.date, prices.usd_forward_fill p.minute in CI.
Prod SQL unrendered: target.name != 'ci' so the guards render to nothing.
Partition columns confirmed pruning on delta_prod: instruction_calls/block_date (~53s for 3-day slice), transactions/block_date (~5s), prices.usd_forward_fill/minute (~2s).
Verified with `dbt parse --profile spellbook-trino --project-dir dbt_subprojects/solana/` (exit 0). Ref CUR2-2801.
…nt-restructure-dual
jeff-dude
left a comment
There was a problem hiding this comment.
approved with minor addition
Summary
gas_solana_tx_fees_current(and its 17 quarterly backfills) joins two upstream ComputeBudget decodings —gas_solana_compute_limitandgas_solana_compute_unit_price— once each, keyed on(tx_id, block_date). Both models decode the same source (solana.instruction_calls,ComputeBudget111...) with identical filters except a single opcode byte (0x02vs0x03). This PR merges them into one upstream table,gas_solana_compute_budget, keyed on(block_date, block_slot, tx_id), with one row per tx and two columns (compute_limit,compute_unit_price, either nullable). The macro then joins once. The old model names remain as backward-compat views over the new table, so external Dune users ofdune.gas_solana.compute_limit/dune.gas_solana.compute_unit_pricesee no contract change.Ref: CUR2-2801
Why (baseline from CUR2-2801, 24h @ 2026-06-13)
20260612_191937_01377_p49px: 7,265 CPU-s, 41.2 GB IO, 1,248 s wall, peak memory 155 GB total / 55.4 GB per task (memory-pressure warning), MERGE writes ~168 rows.solana.transactionsLEFT JOINcompute_limitLEFT JOINcompute_unit_price). LookupJoin stage ≈ 45% CPU.Design
New model —
dbt_subprojects/solana/models/_sector/gas/gas_solana_compute_budget.sqlschema='gas_solana',alias='compute_budget',partition_by=['block_date','block_hour'],materialized='incremental',file_format='delta',incremental_strategy='delete+insert',unique_key=['block_date','block_slot','tx_id'].solana.instruction_callsonce withbytearray_substring(data,1,1) IN (0x02, 0x03)and pivots:MAX(CASE WHEN op = 0x02 THEN val END) AS compute_limit,MAX(CASE WHEN op = 0x03 THEN val END) AS compute_unit_price,GROUP BY tx_id, block_date, block_hour, block_time, block_slot, tx_index.Backward-compat views (contract-preserving)
gas_solana_compute_limit→materialized='view',SELECT tx_id, block_date, block_hour, block_time, block_slot, tx_index, compute_limit FROM ref('gas_solana_compute_budget') WHERE compute_limit IS NOT NULL.gas_solana_compute_unit_price→ symmetric,WHERE compute_unit_price IS NOT NULL.Macro edit —
dbt_subprojects/solana/macros/_sector/gas/solana_tx_fees_macro.sqlLEFT JOIN gas_solana_compute_limit cl+LEFT JOIN gas_solana_compute_unit_price upwith a singleLEFT JOIN gas_solana_compute_budget cb.cb.compute_limitandcb.compute_unit_pricefeed the existingCOALESCE(..., 200000)/COALESCE(.../1e6, 0)expressions unchanged. Base fee, breakdown maps, block-leaders join, prices join, andtx_fee_currencyare untouched.gas_solana_tx_fees_currentand all 17 quarterly backfills.Not in this PR (deliberate):
prices.usd_forward_fillscan / minute predicate not pushed) is left alone — different failure mode, worth a separate change.#todoplaceholders on the view stubs are left as-is.Evidence (live delta_prod, 2026-06-13)
Sizing (single production day):
delta_prod.gas_solana.compute_limit(op0x02)delta_prod.gas_solana.compute_unit_price(op0x03)(block_date, tx_id)in merged tableCost math (unit day):
instruction_callsscans in the compute buildAligned with the -30-40% CPU / halved-join-memory estimate in the issue.
Bit-identical equivalence (delta_prod, 2026-06-13):
Result:
The merged model reproduces the exact
(tx_id, block_date, compute_limit, compute_unit_price)cross-product of the two existing tables — bit-identical in both directions.Compile check
Exit 0. Compiled
gas_solana_tx_fees_currentshows the singleLEFT JOIN ... gas_solana_compute_budget cbin place of the previous two joins.dbt buildintentionally not run — CI handles it.Files changed
dbt_subprojects/solana/models/_sector/gas/gas_solana_compute_budget.sqldbt_subprojects/solana/models/_sector/gas/gas_solana_compute_limit.sql— now a view overgas_solana_compute_budgetdbt_subprojects/solana/models/_sector/gas/gas_solana_compute_unit_price.sql— now a view overgas_solana_compute_budgetdbt_subprojects/solana/macros/_sector/gas/solana_tx_fees_macro.sql— dual → single JOINdbt_subprojects/solana/models/_sector/gas/_schema.yml— full metadata + tests forgas_solana_compute_budget