Skip to content

chore: compressed repr. should store disc as part of data#2282

Open
SwenSchaeferjohann wants to merge 1 commit intomainfrom
swen/fix-disc-for-accountinterface
Open

chore: compressed repr. should store disc as part of data#2282
SwenSchaeferjohann wants to merge 1 commit intomainfrom
swen/fix-disc-for-accountinterface

Conversation

@SwenSchaeferjohann
Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann commented Feb 12, 2026

  • indexer has to store the Account data as it is on-chain in the Account field of AccountInterface. this includes the discriminator
  • indexer cannot stitch it together if it doesn't know the length of the discriminator
  • we should support var length discriminators for eg pinocchio programs

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency in account data serialization and hashing across the SDK to ensure proper alignment with on-chain protocol standards.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

The pull request modifies discriminator handling across account interface and compressed/decompressed account data processing. Changes shift from rebuilding account data with explicit discriminator prefixes to incorporating 8-byte discriminators as direct prefixes in hashing and data construction operations.

Changes

Cohort / File(s) Summary
Account Data Construction
sdk-libs/client/src/interface/account_interface.rs
Modified hot-to-cold transition to directly clone existing on-chain data bytes instead of rebuilding with discriminator prefix. Updated doc comment clarifies that data.data contains full on-chain account bytes as-is.
Compressed Account Hashing
sdk-libs/sdk-types/src/interface/program/compression/pda.rs, sdk-libs/sdk-types/src/interface/program/decompression/pda.rs
Both files now prepend 8-byte discriminator as a prefix to Borsh-serialized account data before hashing, changing hash input from Borsh(data) to DISCRIMINATOR || Borsh(data). Maintains protocol convention by zeroing first hash byte. Adds Vec allocation support for buffer construction.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

ai-review

Suggested reviewers

  • sergeytimoshin
  • ananas-block

Poem

🔷 Eight bytes now lead the way,
Discriminators prefix play,
Hashes mirror what's on-chain,
Data flows without refrain! 🎯

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ⚠️ Unable to check for merge conflicts: Failed to fetch base branch: From https://github.com/Lightprotocol/light-protocol
! [rejected] main -> main (non-fast-forward)
+ 2cde4dd...c7866ee main -> origin/main (forced update)
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the core change: storing the discriminator as part of the account data, which aligns with the PR objectives and all three modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 70.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch swen/fix-disc-for-accountinterface
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch swen/fix-disc-for-accountinterface
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
sdk-libs/sdk-types/src/interface/program/compression/pda.rs (1)

142-148: ⚠️ Potential issue | 🔴 Critical

Inconsistency in OutAccountInfo.data format between pda.rs and account.rs paths.

The data field format is inconsistent across code paths. In pda.rs (decompression), OutAccountInfo.data includes the 8-byte discriminator prefix (disc + borsh), with data_hash calculated over both. However, in account.rs (modification via to_account_info()), OutAccountInfo.data contains only the borsh serialization without the discriminator prefix, and data_hash is calculated on the account object directly.

Both paths populate the same OutAccountInfo structure, so this format mismatch will break downstream consumers. Additionally, the data_hash calculations differ between paths (pda.rs hashes disc+borsh, account.rs hashes account), which could cause validation failures. Update account.rs to mirror the pda.rs layout: include the discriminator prefix in the data field and recalculate data_hash consistently.

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