-
Notifications
You must be signed in to change notification settings - Fork 12
Refactor indexer data model to not store tx_hash multiple times in different tables
#437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aditya1702
wants to merge
31
commits into
backfilling-metrics
Choose a base branch
from
statechanges-data-model
base: backfilling-metrics
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
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
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
…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 <[email protected]>
- 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 <[email protected]>
- 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 <[email protected]>
- 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 <[email protected]>
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 <[email protected]>
- 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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
- 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 <[email protected]>
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 <[email protected]>
…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 <[email protected]>
tx_hash multiple times in different tables
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