fix: bound receipt enrichment updates to repaired blocks - #289
Draft
kuyziss wants to merge 1 commit into
Draft
Conversation
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.
Summary
min..maxspanblock_timestamp, matching the partition keyIssue
In production, the Moderato receipt backfill repeatedly times out while running:
The repair worker can select sparse missing blocks. Collapsing those blocks into a single lowest/highest range makes PostgreSQL examine every transaction and receipt between them, potentially across a large portion of the chain. Both tables are partitioned by
block_timestamp, but the join omitted that key. Production showed sustained PostgreSQL temporary-file throughput up to roughly 140 MB/s, approximately 1 GB temporary files, and the statement being cancelled by the 60-second timeout before the worker retried it.The currently deployed production image also predates #277, which added the durable bounded receipt-repair queue and stopped treating legitimate empty blocks as missing receipts. Rolling out a build containing both changes addresses selection/retry behavior and keeps genuine repair enrichment bounded.
Fix
The enrichment query now receives the deduplicated exact block list, limited by the existing 100-block receipt-repair batch. It applies
block_num = ANY($1)to both tables and joins onblock_timestampin addition to block number and transaction index. This allows PostgreSQL to use the per-partition indexes and prevents sparse repair work from becoming a broad range scan.No database migration or new production index is required.
Impact
Receipt repair remains functionally identical, but transaction enrichment is proportional to the blocks actually repaired. This should eliminate the recurring statement timeouts and high temporary-file I/O caused by the broad range join.
Validation
cargo fmt --checkcargo test --lib(409 passed)cargo clippy --lib -- -D warnings