operations, operations_accounts: Remove txHash from operations table and build tx TOID using operation ID#479
Open
aditya1702 wants to merge 20 commits intotxhash-remove-txnsfrom
Open
operations, operations_accounts: Remove txHash from operations table and build tx TOID using operation ID#479aditya1702 wants to merge 20 commits intotxhash-remove-txnsfrom
operations, operations_accounts: Remove txHash from operations table and build tx TOID using operation ID#479aditya1702 wants to merge 20 commits intotxhash-remove-txnsfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the tx_hash column and foreign key constraint from the operations table, replacing the direct transaction hash reference with a TOID (Transaction/Operation ID) encoding scheme. Operations are now associated with transactions by deriving the transaction's ToID from the operation ID using bit masking (id &^ 0xFFF in Go, id & ~x'FFF'::bigint in SQL).
Changes:
- Removed
tx_hashcolumn and foreign key fromoperationstable schema - Updated all queries to use TOID range-based lookups (
id > to_id AND id < to_id + 4096) instead oftx_hashequality - Removed
TxHashfield fromtypes.Operationstruct and updated all processors, tests, and GraphQL resolvers - Changed dataloader from
OperationsByTxHashLoadertoOperationsByToIDLoaderusing TOID bit masking
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/db/migrations/2025-06-10.3-create_indexer_table_operations.sql | Removes tx_hash column, foreign key constraint, and associated indexes from operations table |
| internal/indexer/types/types.go | Removes TxHash field from Operation struct |
| internal/indexer/processors/utils.go | Removes TxHash assignment in ConvertOperation function |
| internal/indexer/processors/utils_test.go | Updates test assertions to remove TxHash field |
| internal/data/operations.go | Replaces BatchGetByTxHash(es) methods with BatchGetByToID(s) using TOID range queries |
| internal/data/operations_test.go | Updates all tests to use ToID-based lookups with proper TOID ranges (multiples of 4096) |
| internal/data/transactions.go | Updates BatchGetByOperationIDs to join using TOID bit masking instead of tx_hash |
| internal/data/transactions_test.go | Updates tests with proper TOID values for transaction-operation relationships |
| internal/data/accounts_test.go | Updates test data setup to use proper TOID ranges |
| internal/serve/graphql/dataloaders/operation_loaders.go | Replaces hash-based dataloader with ToID-based dataloader using bit masking |
| internal/serve/graphql/dataloaders/loaders.go | Renames loader from OperationsByTxHashLoader to OperationsByToIDLoader |
| internal/serve/graphql/resolvers/transaction.resolvers.go | Updates resolver to use ToID instead of Hash for loading operations |
| internal/serve/graphql/resolvers/test_utils.go | Updates test setup to derive tx_hash from operation IDs using toid.Parse |
| internal/serve/graphql/resolvers/*.go (tests) | Updates all GraphQL resolver tests to work with ToID-based operations |
| internal/services/ingest_test.go | Updates test helpers and cleanup logic for operations without tx_hash |
| internal/indexer/indexer_buffer_test.go | Removes TxHash from test operation creation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
This PR removes the
tx_hashcolumn and foreign key constraint from theoperationstable, replacing the direct transaction hash reference with a TOID (Transaction/Operation ID) encoding scheme. Operations are now associated with transactions by deriving the transaction's ToID from the operation ID using bit masking (id &^ 0xFFFin Go,id & ~x'FFF'::bigintin SQL).tx_hashcolumn and foreign key fromoperationstable schemaid > to_id AND id < to_id + 4096) instead oftx_hashequalityTxHashfield fromtypes.Operationstruct and updated all processors, tests, and GraphQL resolversOperationsByTxHashLoadertoOperationsByToIDLoaderusing TOID bit maskingKnown limitations
[TODO or N/A]
Issue that this PR addresses
Closes #482