Skip to content

Conversation

notdanilo
Copy link
Contributor

@notdanilo notdanilo commented Sep 17, 2025

Status Type ⚠️ Core Change Issue
Ready Bug Yes #92

Problem

Currently, we cannot use extra acconts in combinations with normal accounts to create for example a CpiContext to perform a CPI due to lifetime conflicts.

Solution

Modify how extra accounts macro inject the helpers and set proper lifetimes: https://github.com/magicblock-labs/bolt/blob/main/crates/bolt-lang/attribute/extra-accounts/src/lib.rs#L80

Greptile Summary

Updated On: 2025-09-17 21:10:42 UTC

This PR fixes a critical lifetime conflict issue in the Bolt framework's extra_accounts macro that prevented developers from using extra accounts alongside normal component accounts when creating CpiContext for cross-program invocations (CPI).

The core fix modifies the bolt_execute function signature in crates/bolt-lang/attribute/system/src/lib.rs to include explicit lifetime parameters ('a, 'b) that align with Anchor's Context lifetime requirements. The original implementation had implicit lifetimes that caused Rust compiler errors when attempting to combine different account types in the same function scope.

Additionally, the PR improves the robustness of the Context generic argument extraction logic by iterating through all generic arguments instead of assuming the component struct is always the first argument. This change makes the code more resilient to complex Context type signatures with multiple lifetime parameters.

To demonstrate and validate the fix, a new escrow-funding example is added that showcases a system performing SOL transfers using both regular component accounts (receiver) and extra accounts (sender, system_program). The example includes proper Cargo.toml and Xargo.toml configurations for Solana BPF compilation.

The changes integrate seamlessly with the existing Bolt framework architecture, maintaining compatibility with the #[extra_accounts] procedural macro while resolving the lifetime management issues that were blocking CPI operations.

PR Description Notes:

  • Minor typo: "extra acconts" should be "extra accounts"

Confidence score: 4/5

  • This PR addresses a well-defined compilation issue with a focused lifetime fix that follows Rust and Anchor best practices
  • Score reflects good understanding of the lifetime system and appropriate solution, but complexity of lifetime interactions in procedural macros requires careful testing
  • Pay close attention to the system attribute macro changes in crates/bolt-lang/attribute/system/src/lib.rs as lifetime modifications can have subtle effects on compilation

@notdanilo notdanilo self-assigned this Sep 17, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

@notdanilo notdanilo merged commit 981cfbf into main Sep 17, 2025
5 checks passed
@notdanilo notdanilo mentioned this pull request Sep 17, 2025
@notdanilo notdanilo deleted the fix/extra-accounts-lifetime branch October 8, 2025 13:56
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