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.

aditya1702 and others added 21 commits December 21, 2025 17:07
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]>
@aditya1702 aditya1702 changed the title Statechanges data model Refactor indexer data model to not store tx_hash multiple times in different tables Dec 22, 2025
@aditya1702 aditya1702 marked this pull request as draft December 22, 2025 20:53
@aditya1702 aditya1702 marked this pull request as ready for review December 22, 2025 22:41
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