Skip to content

refactor: AccountInterface: use photon v2 types and simplify ColdContext#2274

Merged
SwenSchaeferjohann merged 3 commits intomainfrom
sergey/use-photon-submodule-version
Feb 11, 2026
Merged

refactor: AccountInterface: use photon v2 types and simplify ColdContext#2274
SwenSchaeferjohann merged 3 commits intomainfrom
sergey/use-photon-submodule-version

Conversation

@sergeytimoshin
Copy link
Contributor

@sergeytimoshin sergeytimoshin commented Feb 11, 2026

  • integrate photon submodule versioning into the build process (CLI and devenv scripts)
  • migrate indexer ColdContext from enum (Account/Token variants) to a flat struct
  • add data_hash, address, and prove_by_index fields to indexer cold types, eliminating placeholder [0u8; 32] values and enabling correct round-tripping
  • replace client-level ColdContext enum with typed fields (Option / Option) on AccountInterface and TokenAccountInterface
  • extract shared cold_context_to_compressed_account helper to deduplicate conversion logic across convert_account_interface, convert_token_account_interface, and get_mint_interface
  • eliminate the second indexer round-trip in get_mint_interface by constructing CompressedAccount directly from the first call's ColdContext
  • regenarate photon API codegen

Summary by CodeRabbit

  • API Changes

    • Removed get_token_account_interface_post endpoint
    • Removed get_ata_interface_post endpoint
  • Refactor

    • Optimized internal account context data structures for improved efficiency

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

This pull request refactors the cold (compressed) account representation by consolidating an enumerated ColdContext type into a unified struct, simplifies accessor patterns by removing variant branching, and adjusts public API surfaces across the indexer and interface modules.

Changes

Cohort / File(s) Summary
ColdContext Structural Migration
sdk-libs/client/src/indexer/types/interface.rs, sdk-libs/client/src/interface/account_interface.rs, sdk-libs/client/src/interface/decompress_mint.rs, sdk-libs/client/src/interface/light_program_interface.rs, sdk-libs/client/src/interface/mod.rs
Replaces enum-based ColdContext with a unified struct; updates AccountInterface and TokenAccountInterface to store CompressedAccount/CompressedTokenAccount directly instead of wrapped variants; removes per-variant branching and simplifies accessors throughout cold-data handling.
Indexer Conversion Logic Simplification
sdk-libs/client/src/indexer/photon_indexer.rs, sdk-libs/client/src/indexer/types/interface.rs
Introduces decode_tree_info_v2, decode_account_data, and convert_account_v2 helpers to standardize AccountV2 conversion; removes legacy convert_cold_context, convert_flattened_account_interface, and variant-specific TryFrom implementations; consolidates token data parsing into parse_token_data_from_indexer_account.
RPC Client Account/Token Mounting
sdk-libs/client/src/rpc/client.rs, sdk-libs/client/src/interface/load_accounts.rs
Introduces cold_context_to_compressed_account helper to centralize cold-context conversion; refactors get_account_interface and get_token_account_interface to use the new helper; adjusts ATA spec boxed-reference handling in cold-account collection.
Public API Surface Reduction
sdk-libs/photon-api/src/lib.rs
Removes four public functions: make_get_token_account_interface_body, make_get_ata_interface_body, get_token_account_interface_post, and get_ata_interface_post from the default_api module.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

The changes involve heterogeneous structural modifications across multiple interconnected modules. Type signature changes in core public APIs (AccountInterface.cold, TokenAccountInterface.cold), removal of an entire enum pattern with cascading effects on accessor logic, introduction of new helper functions with non-trivial deserialization paths, and elimination of legacy conversion paths require careful validation that the new unified data flow maintains correctness without losing logic or introducing subtle bugs.

Possibly related PRs

  • chore: update light sdk docs, upstream fixes #1954: Overlapping modifications to indexer/photon_indexer.rs and compression type handling (TokenAccount → CompressedTokenAccount) with related account-interface surface changes.
  • feat: compressed mint photon api  #2198: Direct code-level correlation in indexer interface and token/account interface refactoring (get_account_interface, get_token_account_interface, and token-data parsing paths).
  • chore: program trait #2178: Shared modifications to account/interface structures (ColdContext removal) and refactoring of token/mint data parsing flows.

Suggested labels

ai-review

Suggested reviewers

  • SwenSchaeferjohann
  • ananas-block

Poem

A context once fragmented by three,
Now unified—account, token, mint decree.
The enum dissolves to a struct, clean and true,
Variants begone! Accessors shine through. 🎯✨

🚥 Pre-merge checks | ✅ 3
✅ 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 accurately summarizes the main refactoring: replacing ColdContext enum with direct types and migrating to photon v2 API structures across the codebase.
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 sergey/use-photon-submodule-version

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.

- Removed `make_get_token_account_interface_body` and `make_get_ata_interface_body` functions from the photon API module.
- Updated various test files to remove references to `ColdContext` and directly use compressed accounts in `AccountInterface`.
- Adjusted `AccountSpec::Ata` instantiation to wrap `ata_interface` in `Box::new`.
- Cleaned up imports in multiple test files by removing unused `ColdContext` references.
@sergeytimoshin sergeytimoshin changed the title feat: integrate photon submodule versioning into build process refactor: AccountInterface: use photon v2 types and simplify ColdContext Feb 11, 2026
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 (2)
sdk-libs/client/src/indexer/types/interface.rs (1)

127-137: ⚠️ Potential issue | 🟠 Major

Guard against multiple cold entries instead of silently picking the first.
Line 131 currently takes entries.first(). If the API ever returns more than one cold entry, the extras are ignored silently, which can lead to incorrect hashes/proofs. Consider rejecting multiple entries explicitly.

🔧 Suggested fix
-    let cold = ai
-        .cold
-        .as_ref()
-        .and_then(|entries| entries.first())
-        .map(convert_account_v2)
-        .transpose()?;
+    let cold = match ai.cold.as_ref() {
+        Some(entries) if entries.len() > 1 => {
+            return Err(IndexerError::InvalidParameters(
+                "expected at most one cold entry".to_string(),
+            ));
+        }
+        Some(entries) => entries.first().map(convert_account_v2).transpose()?,
+        None => None,
+    };
sdk-libs/client/src/indexer/photon_indexer.rs (1)

1764-1870: ⚠️ Potential issue | 🟠 Major

Add owner validation for hot token accounts before returning TokenData.

The parse_token_data_from_indexer_account function returns a default TokenData for on-chain accounts without checking that the account is owned by light_token_interface::LIGHT_TOKEN_PROGRAM_ID. Since get_token_account_interface accepts any address and routes through get_account_interface, a non-token account could pass through with misleading default token data. The codebase already validates mint account ownership in a similar context (see client.rs mint path), establishing this as a required check.

🔧 Suggested fix
 fn parse_token_data_from_indexer_account(
     ai: &AccountInterface,
 ) -> Result<light_token::compat::TokenData, IndexerError> {
     match &ai.cold {
         Some(cold) => borsh::BorshDeserialize::deserialize(&mut cold.data.data.as_slice())
             .map_err(|e| IndexerError::decode_error("token_data", e)),
         None => {
+            let expected =
+                Pubkey::new_from_array(light_token_interface::LIGHT_TOKEN_PROGRAM_ID);
+            if ai.account.owner != expected {
+                return Err(IndexerError::InvalidParameters(format!(
+                    "expected token account owner {}, got {}",
+                    expected, ai.account.owner
+                )));
+            }
             // Hot account — downstream will re-parse from SPL account data directly
             Ok(light_token::compat::TokenData::default())
         }
     }
 }

@SwenSchaeferjohann SwenSchaeferjohann merged commit e81c9b4 into main Feb 11, 2026
25 checks passed
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