3

I'm writing a Solana program with Anchor 0.29.0 and Solana 1.18.9. I want to invoke through CPI another program. It all worked well until I realised that, the called program needs the remaining accounts as well. And when I tried to pass them through the CpiContext I blocked into argument requires that '1 must outlive '2. Here is my instruction file:

#[derive(Accounts)]
pub struct MyVaultExecuteTransaction<'info> {
    
    #[account(mut)]
    pub executor: Signer<'info>,

    pub my_config: Account<'info, MyConfig>,

    pub multisig: Account<'info, Multisig>,

    #[account(mut)]
    /// CHECK: Managed by Squads
    pub proposal: AccountInfo<'info>,

    /// CHECK: Managed by Squads
    pub transaction: AccountInfo<'info>,

    pub squads_multisig_program: Program<'info, SquadsMultisigProgram>,
}

impl MyVaultExecuteTransaction<'_> {
    fn validate(&self) -> Result<()> {
        let Self {
            my_config, executor, ..
        } = self;

        // creator
        require!(
            my_config.is_executor(executor.key()).is_some(),
            Errors::NotAnExecutorError
        );
        
        Ok(())
    }
 
    
    #[access_control(ctx.accounts.validate())]
    pub fn handle(ctx: Context<MyVaultExecuteTransaction>) -> Result<()> {
    
        let vault_transaction_execute_cpi_accounts = VaultTransactionExecute {
            multisig: ctx.accounts.multisig.to_account_info(),
            proposal: ctx.accounts.proposal.to_account_info(),
            transaction: ctx.accounts.transaction.to_account_info(),
            member: ctx.accounts.executor.to_account_info(),
        };

        squads_multisig_program::cpi::vault_transaction_execute(
            CpiContext::new(
                ctx.accounts.squads_multisig_program.to_account_info(),
                vault_transaction_execute_cpi_accounts
            ).with_remaining_accounts(ctx.remaining_accounts.to_vec())
        )?;
    
        Ok(())
    }

}

and here is the error I get:

error: lifetime may not live long enough
  --> programs/my-sol/src/instructions/multisig_vault_execute_tx.rs:62:13
   |
46 |       pub fn handle(ctx: Context<MyVaultExecuteTransaction>) -> Result<()> {
   |                     ---
   |                     |
   |                     has type `anchor_lang::context::Context<'_, '_, '_, '1, multisig_vault_execute_tx::MyVaultExecuteTransaction<'_>>`
   |                     has type `anchor_lang::context::Context<'_, '_, '_, '_, multisig_vault_execute_tx::MyVaultExecuteTransaction<'2>>`
...
62 | /             CpiContext::new(
63 | |                 ctx.accounts.squads_multisig_program.to_account_info(),
64 | |                 vault_transaction_execute_cpi_accounts
65 | |             ).with_remaining_accounts(ctx.remaining_accounts.to_vec())
   | |_____________^ argument requires that `'1` must outlive `'2`

Appreciate your feedback!

1 Answer 1

1

I'm no rust expert but have been struggling with a similar issue. Seems it's not happy with one lifetime outliving the other.

You can probably fix this by setting the lifetimes to be equal on your context.

pub fn handle<'info>(ctx: Context<'_, '_, '_, 'info, MyVaultExecuteTransaction<'info>>) -> Result<()> {
   ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.