Skip to content

Conversation

@aditya1702
Copy link
Contributor

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

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

- Remove tx_hash column and its FK constraint to transactions(hash)
- Add FK constraint on to_id referencing transactions(to_id)
- Remove idx_state_changes_tx_hash index
The tx_hash is redundant since to_id can be used to look up transactions.
Transaction can be looked up via to_id, so txHash is redundant.
Updated calls in:
- effects.go
- token_transfer.go
- contract_deploy.go
- contracts/sac.go
- Remove txHashes slice and loop assignment
- Update INSERT query to remove tx_hash column
- Shift parameter indices accordingly
- Update BatchCopy column list and row values
- Update BatchGetByAccountAddress to use subquery for tx_hash filter
- BatchGetByTxHash -> BatchGetByToID (uses to_id instead of tx_hash)
- BatchGetByTxHashes -> BatchGetByToIDs (uses to_ids array instead of tx_hashes)
- Update queries to use to_id for filtering and partitioning
- Change StateChangeColumnsKey.TxHash to ToID (int64)
- Rename stateChangesByTxHashLoader to stateChangesByToIDLoader
- Update dataloader to use BatchGetByToID/BatchGetByToIDs
- Update key extraction functions to use ToID
- Change loaderKey.TxHash to loaderKey.ToID (use obj.ToID instead of obj.Hash)
- Call StateChangesByToIDLoader instead of StateChangesByTxHashLoader
- Remove TxHash from test state change structs
- Update INSERT statements to remove tx_hash column
- Update filter tests to check ToID instead of TxHash
- Rename BatchGetByTxHash/TxHashes tests to BatchGetByToID/ToIDs
- Remove TxHash assertions from effects and contract_deploy tests
- Update buildStateChange helper function signature
- Update createTestStateChange helper in ingest_test.go
- Remove TxHash from state change struct in statechange_resolvers_test.go
The sc3 state change previously had to_id=3 but only transactions with
to_id=1 and to_id=2 exist. Changed to to_id=1 with state_change_order=2
to reference an existing transaction while avoiding PK conflict.
- Use valid to_id values that reference existing transactions
- Remove tx_hash from transactions_test.go INSERT
- Adjust test expectations to match updated test data
- Update PK from (to_id, state_change_order) to (to_id, operation_id, state_change_order)
- Add partial index on operation_id for non-zero values
- Enables proper FK semantics where to_id always references transaction to_id
- Add OperationID field to StateChangeCursor for 3-part cursor
- Update GetCursor() method to include OperationID
- For operation changes: derive ToID from OperationID using TOID bitmask (&^ 0xFFF)
- For fee changes: use transaction's to_id directly
- This ensures FK constraint to transactions table is always valid
- Add operation_id to cursor columns in all queries
- Update ordering to use (to_id, operation_id, state_change_order)
- Update pagination predicates to use 3-column comparison
- Update ON CONFLICT clause for 3-part PK
- Update returned ID format to include operation_id
- Add scOpIDs parameter to all BatchGetByStateChangeIDs functions
- Update tuple format from (to_id, state_change_order) to (to_id, operation_id, state_change_order)
- Update state_change_id format to include operation_id
- Change format from to_id-state_change_order to to_id-operation_id-state_change_order
- Return toIDs, opIDs, orders instead of toIDs, orders
- Update account_loaders.go to pass scOpIDs to BatchGetByStateChangeIDs
- Update operation_loaders.go to pass scOpIDs to BatchGetByStateChangeIDs
- Update transaction_loaders.go to pass scOpIDs to BatchGetByStateChangeIDs
- Update resolveStateChangeAccount/Operation/Transaction to accept operationID
- Update all statechange resolvers to pass operationID to helper functions
- Update cursor format from to_id:state_change_order to to_id:operation_id:state_change_order
- Update parseStateChangeCursor to parse 3-part format
- Update statechanges_test.go: wantIDs format, verification queries, cursor tests
- Update accounts_test.go: BatchGetByStateChangeIDs to use 3-part format
- Update operations_test.go: BatchGetByStateChangeIDs to use 3-part format
- Update transactions_test.go: BatchGetByStateChangeIDs to use 3-part format
- Update test_utils.go: ToID derived from OperationID using TOID bitmask
@aditya1702 aditya1702 changed the title statechanges: Remove txHash and use tx TOID statechanges: Remove txHash and use tx TOID to reference transactions table Feb 1, 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.

2 participants