Refactor indexer data model to not store tx_hash multiple times in different tables#437
Closed
aditya1702 wants to merge 31 commits intobackfilling-metricsfrom
Closed
Refactor indexer data model to not store tx_hash multiple times in different tables#437aditya1702 wants to merge 31 commits intobackfilling-metricsfrom
tx_hash multiple times in different tables#437aditya1702 wants to merge 31 commits intobackfilling-metricsfrom
Conversation
Add constants and methods to derive ledger_number, operation_id, and tx_id from TOID (Total Order ID) values stored in to_id fields. This enables removing redundant columns from the database schema. Methods added: - Transaction.GetLedgerNumber() - Operation.GetLedgerNumber(), GetTxID() - StateChange.GetLedgerNumber(), GetOperationID(), HasOperation(), GetTxID() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add bidirectional mappings between string enum types and SMALLINT values for efficient database storage: - StateChangeCategory (10 values) - StateChangeReason (18 values) - OperationType (27 values) Each type has ToInt16() method and FromInt16() function for conversion. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Migration changes: - transactions: PK changed from hash to to_id, removed ledger_number and ingested_at - transactions_accounts: tx_hash (TEXT) -> tx_id (BIGINT) - operations: removed tx_hash, ledger_number, ingested_at; operation_type TEXT -> SMALLINT - operations_accounts: removed created_at - state_changes: removed tx_hash, operation_id, ledger_number, ingested_at; category and reason TEXT -> SMALLINT All removed fields can be derived from TOID (to_id) using bit operations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…structs Fields removed (can be derived from TOID): - Transaction: LedgerNumber, IngestedAt - Operation: LedgerNumber, TxHash, IngestedAt - StateChange: LedgerNumber, OperationID, TxHash, IngestedAt Use GetLedgerNumber(), GetOperationID(), GetTxID() methods to derive values. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Simplify StateChangeBuilder: set ToID directly in constructor (txID) and WithOperationID() now directly overrides ToID - Remove redundant parameters from NewStateChangeBuilder (ledgerNumber, txHash) - Update ConvertTransaction/ConvertOperation to not populate removed fields - Remove stale GetIngestedAt() and duplicate GetLedgerNumber() methods from types.go - Update all processor callers to use new signature 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove tx_hash and ledger_number columns from BatchInsert and BatchCopy - Change operation_type from TEXT to SMALLINT using ToInt16() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove ledger_number, operation_id, tx_hash columns from BatchInsert and BatchCopy - Change state_change_category and state_change_reason from TEXT to SMALLINT - Update helper function pgtypeTextFromReasonPtr -> pgtypeInt2FromReasonPtr 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Since ledgerNumber is no longer passed to NewStateChangeBuilder, remove the unused variable declarations from effects.go and sac.go. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove IngestedAt comparison in assertStateChangeEqual - Use HasOperation(), GetOperationID(), GetTxID() methods instead of deleted fields in assertStateChangeBase and assertFeeEvent 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
These fields are populated via JOINs with the transactions table, not stored in the database. Required for dataloaders to group results by transaction hash. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Since tx_hash column was removed from operations table, these queries now JOIN with transactions table using TOID derivation: (o.id & ~4095) = t.to_id 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Since operation_id column was removed from state_changes table, the join now uses to_id directly (for operation-related state changes, to_id equals operation_id when to_id & 4095 != 0). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- txHash filter now JOINs with transactions table via TOID derivation - operationID filter now uses to_id directly (to_id = operation_id for operation-related state changes) - Added table alias 'sc' for proper column qualification 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Since tx_hash column was removed from state_changes table, these queries now JOIN with transactions table via TOID derivation: (sc.to_id & ~4095) = t.to_id 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…o use to_id Since operation_id column was removed from state_changes table, these queries now use to_id directly. For operation-related state changes, to_id equals the operation ID (when to_id & 4095 != 0). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tx_hash multiple times in different tables
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.
What
[TODO: Short statement about what is changing.]
Why
[TODO: Why this change is being made. Include any context required to understand the why.]
Known limitations
[TODO or N/A]
Issue that this PR addresses
[TODO: Attach the link to the GitHub issue or task. Include the priority of the task here in addition to the link.]
Checklist
PR Structure
allif the changes are broad or impact many packages.Thoroughness
Release