Skip to content

program: Add optional rent sysvar account#138

Merged
febo merged 1 commit intomainfrom
febo/rent-sysvar-account
Mar 5, 2026
Merged

program: Add optional rent sysvar account#138
febo merged 1 commit intomainfrom
febo/rent-sysvar-account

Conversation

@febo
Copy link
Copy Markdown
Contributor

@febo febo commented Mar 4, 2026

Problem

PR #132 add the requirement of using the Rent sysvar in SyncNative to update the current rent-exempt reserve, which can lead to an increase CU consumption.

Solution

Allow the Rent sysvar account to be provided.

@febo febo requested a review from joncinque March 5, 2026 00:07
@febo febo merged commit e872399 into main Mar 5, 2026
27 checks passed
@febo febo deleted the febo/rent-sysvar-account branch March 30, 2026 11:28

let rent = Rent::get()?;
let rent_exempt_reserve = rent.minimum_balance(native_account_info.data_len());
let rent_exempt_reserve = if let Ok(rent_sysvar_info) = next_account_info(account_info_iter)
Copy link
Copy Markdown

@sushant-baton sushant-baton Mar 30, 2026

Choose a reason for hiding this comment

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

Suggested change
let rent_exempt_reserve = if let Ok(rent_sysvar_info) = next_account_info(account_info_iter)
        let rent_exempt_reserve = if let Ok(rent_sysvar_info) = next_account_info(account_info_iter)  && account_info_iter.address  == expected_rent_sysvar

@febo Can we change to that?
We are passing some other account as remaining account, this change is now breaking our deployed logic on devnet.
We pass the other account because of another solana runtime bug solana-labs/solana#9711 during a CPI call, Solana Runtime only checks balances of accounts used by the CPI call.
Not adding the extra account account here would make the CPI  "sum of account balances before and after instruction do not match" error.

We have the following code:

    normalAccountWithData.sub_lamports(sol_amount)?;
    wsolAta.add_lamports(sol_amount)?;

anchor_lang::solana_program::program::invoke(
        &Instruction {
            program_id: token::spl_token::ID,
            accounts: vec![
                AccountMeta::new(wsolAta.key(), false),
                AccountMeta::new(normalAccountWithData.key(), false),
            ],
            data: TokenInstruction::SyncNative.pack(),
        },
        &[
            [wsolAta.to](http://wsolata.to/)_account_info(),
            [normalAccountWithData.to](http://normalaccountwithdata.to/)_account_info(),
        ],
    )?;

EDIT: another suggestion maybe add next_account_info to check key if it is the token_program_id then assume it is not passed, this is exactly how anchor implements optional accounts.

Whats the timeline for this on mainnet?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We understand we can add the sysvar rent before the additional account but we cannot push it to mainnet before you push this to mainnet too I presume. Can we have timelines so it can be coordinated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can start adding the rent sysvar right away -- if the current program is ok with a different random account, it should be fine with the rent sysvar either way

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.

4 participants