Conversation
📝 WalkthroughWalkthroughAdds mint-only codegen support to the light_pdas macros (placeholder enums, trait stubs, and branching for mint-only flows) and gates two test files behind a Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@sdk-libs/macros/src/light_pdas/account/utils.rs`:
- Around line 151-156: The impl of IntoCTokenVariant for TokenAccountVariant
uses unreachable!() in into_ctoken_variant which can panic; change it to return
the safe fallback LightAccountVariant::Empty instead. Locate the method
TokenAccountVariant::into_ctoken_variant (impl
light_sdk::interface::IntoCTokenVariant<LightAccountVariant,
light_token::compat::TokenData> for TokenAccountVariant) and replace the
unreachable!() call with a deterministic return of LightAccountVariant::Empty so
it matches the defensive behavior of Pack/Unpack/TokenSeedProvider.
In `@sdk-libs/macros/src/light_pdas/program/decompress.rs`:
- Around line 158-165: The current generate_seed_provider_impls function
silently returns Ok(Vec::new()) when self.pda_seeds is None or empty, which can
hide a mismatch if self.pda_ctx_seeds contains variants; update the guard to
detect this mismatch and fail fast: if pda_seeds is None/empty but pda_ctx_seeds
is non-empty, return an Err with a clear message referencing the program and the
missing PDA seed specs; otherwise, when pda_seeds exists and is non-empty,
proceed as before. Ensure the error message mentions
generate_seed_provider_impls, pda_seeds, and pda_ctx_seeds so it's easy to
locate and debug.
| impl light_sdk::interface::IntoCTokenVariant<LightAccountVariant, light_token::compat::TokenData> for TokenAccountVariant { | ||
| fn into_ctoken_variant(self, _token_data: light_token::compat::TokenData) -> LightAccountVariant { | ||
| // This function should never be called for programs without token accounts. | ||
| // The Empty variant only exists in mint-only programs (no PDAs). | ||
| // For programs with PDAs but no tokens, this impl exists only to satisfy trait bounds. | ||
| unreachable!("into_ctoken_variant called on program without token accounts") |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's explore the file structure and find the file in question
cd /repo && find . -name "utils.rs" | grep -E "macros/.*light_pdas.*account"Repository: Lightprotocol/light-protocol
Length of output: 127
🏁 Script executed:
# Read the specific file to see the context around lines 151-156
wc -l sdk-libs/macros/src/light_pdas/account/utils.rsRepository: Lightprotocol/light-protocol
Length of output: 123
🏁 Script executed:
# Read the file with context
cat -n sdk-libs/macros/src/light_pdas/account/utils.rs | head -200 | tail -80Repository: Lightprotocol/light-protocol
Length of output: 4068
🏁 Script executed:
# Search for the IntoCTokenVariant trait definition
rg "trait IntoCTokenVariant" --type rs -A 10Repository: Lightprotocol/light-protocol
Length of output: 98
🏁 Script executed:
# Search for usages of TokenAccountVariant and into_ctoken_variant
rg "TokenAccountVariant" --type rs -B 2 -A 2Repository: Lightprotocol/light-protocol
Length of output: 98
🏁 Script executed:
# Search for other unreachable! patterns in similar macros code
rg "unreachable!" sdk-libs/macros --type rs -B 2 -A 2Repository: Lightprotocol/light-protocol
Length of output: 98
🏁 Script executed:
# Check for LightAccountVariant::Empty definition and usage
rg "LightAccountVariant::Empty" --type rs -B 2 -A 2Repository: Lightprotocol/light-protocol
Length of output: 98
🏁 Script executed:
rg "trait IntoCTokenVariant" --type-listRepository: Lightprotocol/light-protocol
Length of output: 461
🏁 Script executed:
rg "trait IntoCTokenVariant" -A 10Repository: Lightprotocol/light-protocol
Length of output: 805
🏁 Script executed:
rg "into_ctoken_variant" -B 3 -A 3Repository: Lightprotocol/light-protocol
Length of output: 4496
🏁 Script executed:
rg "TokenAccountVariant" -B 2 -A 2 | head -100Repository: Lightprotocol/light-protocol
Length of output: 8886
🏁 Script executed:
# Look at how other generated Empty enums handle trait implementations
rg "generate_empty_ctoken_enum" -B 5 -A 20Repository: Lightprotocol/light-protocol
Length of output: 5140
🏁 Script executed:
# Check if there are other unreachable! macros in the generated code sections
rg "unreachable!" sdk-libs/macros -B 3 -A 1Repository: Lightprotocol/light-protocol
Length of output: 1516
🏁 Script executed:
rg "enum LightAccountVariant" -A 15Repository: Lightprotocol/light-protocol
Length of output: 3172
🏁 Script executed:
# Check how this Empty TokenAccountVariant is used/called
rg "into_ctoken_variant" --context 5Repository: Lightprotocol/light-protocol
Length of output: 5900
🏁 Script executed:
# See if there are defensive patterns (returning a default/empty variant) elsewhere
rg "LightAccountVariant::" sdk-libs/sdk -A 1 | head -50Repository: Lightprotocol/light-protocol
Length of output: 54
🏁 Script executed:
# Check the trait documentation more carefully
cat -n sdk-libs/sdk/src/interface/traits.rs | grep -A 20 "trait IntoCTokenVariant"Repository: Lightprotocol/light-protocol
Length of output: 505
🏁 Script executed:
# Search for where into_ctoken_variant is invoked
rg "\.into_ctoken_variant\(" -B 5 -A 3Repository: Lightprotocol/light-protocol
Length of output: 54
🏁 Script executed:
# Search for calls that might guard against the empty case
rg "into_ctoken_variant" -B 10 | head -80Repository: Lightprotocol/light-protocol
Length of output: 6725
🏁 Script executed:
# Check if there's any match/guard logic before calling
rg "match.*TokenAccountVariant" -A 5 | head -60Repository: Lightprotocol/light-protocol
Length of output: 54
Replace unreachable!() with safe fallback to LightAccountVariant::Empty.
The into_ctoken_variant implementation for the empty token variant currently uses unreachable!(), which will panic on-chain if ever invoked. While the intent is that this path should never execute, the other trait impls on TokenAccountVariant::Empty (Pack, Unpack, TokenSeedProvider) all use defensive returns. For consistency and safety, return LightAccountVariant::Empty:
Suggested fix
- unreachable!("into_ctoken_variant called on program without token accounts")
+ LightAccountVariant::Empty🤖 Prompt for AI Agents
In `@sdk-libs/macros/src/light_pdas/account/utils.rs` around lines 151 - 156, The
impl of IntoCTokenVariant for TokenAccountVariant uses unreachable!() in
into_ctoken_variant which can panic; change it to return the safe fallback
LightAccountVariant::Empty instead. Locate the method
TokenAccountVariant::into_ctoken_variant (impl
light_sdk::interface::IntoCTokenVariant<LightAccountVariant,
light_token::compat::TokenData> for TokenAccountVariant) and replace the
unreachable!() call with a deterministic return of LightAccountVariant::Empty so
it matches the defensive behavior of Pack/Unpack/TokenSeedProvider.
Summary by CodeRabbit
New Features
Bug Fixes
Chores / Refactor
✏️ Tip: You can customize this high-level summary in your review settings.