perf: compute gas stats from stored transactions - #59
Merged
Merged
Conversation
This was referenced Aug 9, 2026
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.
Closes #51.
/api/gastook 4.3s to return 6.5 KB, because it downloaded every transaction on the chain from the indexer and aggregated them in Go — the same unbounded pattern fixed in #45 and #48.It could not be fixed the same way. The page presents all-time totals ("total txs", "gas used", "total fees", success/failed), so bounding the query to a recent window would silently understate every number. Slow and correct beats fast and wrong.
Computing it locally
The
transactionstable already storesgas_used,gas_wanted,gas_feeandsuccessper network, so the totals are one aggregate. Per-realm gas comes from joining transactions to whichever table recorded the message; top transactions resolve their type and target the same way./api/gas?network=topaz: 4.3s → 0.13s, same shape of response.The part that made this non-trivial
Switching naively would have shipped a correctness regression. The
transactionstable was added after the event tables, and incremental sync only writes it going forward — so on the live instance it held 37 rows for a network with 2738 transactions. Local aggregation would have reported gas totals ~70x too low while looking perfectly plausible.Gas figures exist only on the transaction row, so they cannot be reconstructed from what is already stored.
backfillTransactionsfetches the missing rows back from the indexer: newest first, 100 blocks per sync pass, 10 requests in flight. Measured on real data, 129 → 423 rows in three passes; a full gap of ~2700 closes in about twelve minutes and then costs one cheap query per cycle.Operators should know: for the first few minutes after upgrading, gas totals for networks with pre-existing history will read low and climb as the backfill runs. Networks synced entirely by a recent build are unaffected.
Sits on top of #55, which repaired
block_timethe same way.Tests
GetGasStatstotals, success/fail split, per-realm attribution and top-transaction ordering, plus an assertion that another networks gas does not leak into the totals.HeightsMissingTransactionsfinds events with no transaction row, ignores properly paired ones and other networks, and reports nothing once the gap is filled.