🐛 Fixing extra accounts lifetime #201
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 incrates/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:
Confidence score: 4/5
crates/bolt-lang/attribute/system/src/lib.rs
as lifetime modifications can have subtle effects on compilation