Skip to content

transactions, transactions_accounts: Use TOID instead of hash as reference and avoid storing txn hash multiple times#478

Open
aditya1702 wants to merge 13 commits intostatechanges-remove-jsonbfrom
txhash-remove-txns
Open

transactions, transactions_accounts: Use TOID instead of hash as reference and avoid storing txn hash multiple times#478
aditya1702 wants to merge 13 commits intostatechanges-remove-jsonbfrom
txhash-remove-txns

Conversation

@aditya1702
Copy link
Contributor

@aditya1702 aditya1702 commented Feb 1, 2026

This pull request refactors the database schema to use transaction order ID (TOID) as the primary key for transactions instead of hash, reducing redundant storage of transaction hashes in the transactions_accounts junction table. The PR changes the primary identifier for tracking transaction-account relationships from hash-based to ToID-based references throughout the codebase.

  • Modified database schema to make to_id the primary key and hash a unique column in the transactions table
  • Updated transactions_accounts table to reference tx_to_id instead of tx_hash
  • Refactored all in-memory data structures from hash-based maps to ToID-based maps throughout the indexer, services, and GraphQL layers

Known limitations

N/A

Issue that this PR addresses

Closes #481

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the database schema to use transaction order ID (TOID) as the primary key for transactions instead of hash, reducing redundant storage of transaction hashes in the transactions_accounts junction table. The PR changes the primary identifier for tracking transaction-account relationships from hash-based to ToID-based references throughout the codebase.

Changes:

  • Modified database schema to make to_id the primary key and hash a unique column in the transactions table
  • Updated transactions_accounts table to reference tx_to_id instead of tx_hash
  • Refactored all in-memory data structures from hash-based maps to ToID-based maps throughout the indexer, services, and GraphQL layers

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/db/migrations/2025-06-10.2-create_indexer_table_transactions.sql Changed primary key from hash to to_id; updated transactions_accounts to reference tx_to_id
internal/db/migrations/2025-06-10.3-create_indexer_table_operations.sql Added CHECK constraints for operation types; added ON DELETE CASCADE
internal/db/migrations/2025-06-10.4-create_indexer_table_state_changes.sql Added CHECK constraints for state change categories and reasons; added ON DELETE CASCADE
internal/data/transactions.go Updated BatchInsert and BatchCopy to use stellarAddressesByToID map; changed SQL to use tx_to_id
internal/data/transactions_test.go Updated test helper to generate ToIDs using toid.New; changed all test assertions to use ToID
internal/data/accounts.go Renamed BatchGetByTxHashes to BatchGetByToIDs; updated query to use tx_to_id
internal/data/accounts_test.go Updated test to verify BatchGetByToIDs functionality with ToID references
internal/data/operations_test.go Updated test data inserts to use uppercase operation types per new CHECK constraint
internal/data/statechanges_test.go Updated test data inserts to use uppercase categories per new CHECK constraint
internal/indexer/indexer_buffer.go Changed participantsByTxHash field to participantsByToID with int64 keys
internal/indexer/indexer_buffer_test.go Updated all tests to set ToID field and verify ToID-based participant tracking
internal/indexer/indexer.go Updated interface to return map[int64]set.Set[string] for transaction participants
internal/indexer/indexer_test.go Updated to use ToID for participant verification
internal/indexer/types/types.go Renamed AccountWithTxHash to AccountWithToID; changed field from TxHash to ToID
internal/services/ingest.go Changed transaction participant maps from string keys to int64 (ToID) keys
internal/services/ingest_test.go Updated test to access participants by ToID instead of hash
internal/serve/graphql/resolvers/transaction.resolvers.go Updated to use ToID in dataloader key instead of TxHash
internal/serve/graphql/dataloaders/loaders.go Renamed AccountsByTxHashLoader to AccountsByToIDLoader
internal/serve/graphql/dataloaders/account_loaders.go Updated loader to use ToID; renamed function and updated implementation
internal/integrationtests/infrastructure/backfill_helpers.go Updated JOIN conditions to use t.to_id = ta.tx_to_id

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aditya1702 aditya1702 marked this pull request as ready for review February 1, 2026 23:45
@aditya1702 aditya1702 self-assigned this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant