Skip to content

program: use Rent over rent_exempt_reserve#615

Merged
2501babe merged 6 commits intosolana-program:mainfrom
2501babe:20260311_rent
Mar 11, 2026
Merged

program: use Rent over rent_exempt_reserve#615
2501babe merged 6 commits intosolana-program:mainfrom
2501babe:20260311_rent

Conversation

@2501babe
Copy link
Member

downstream changes to support solana-program/stake#303

@2501babe 2501babe self-assigned this Mar 11, 2026
Comment on lines -987 to -992
let reserve_stake = try_from_slice_unchecked::<stake::state::StakeStateV2>(
&reserve_stake_info.data.borrow(),
)?;
let reserve_meta = reserve_stake
.meta()
.ok_or(StakePoolError::WrongStakeStake)?;
Copy link
Member Author

Choose a reason for hiding this comment

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

i dont believe this parse is necessary to validate the reserve, since the function checks the address, and unlike some of the other areas there is no assertion the state must be StakeStateV2::Initialized, but im not fully confident about this

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks correct -- we only did the parse because we wanted to get meta.rent_exempt_reserve

Comment on lines 2930 to +2931
// check that reserve has enough
let minimum_reserve_lamports = minimum_reserve_lamports(&meta);
let minimum_reserve_lamports = minimum_reserve_lamports(split_from_rent);
Copy link
Member Author

Choose a reason for hiding this comment

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

this looks surprising at first glance, but this instruction has no reserve_stake_info, and this is inside a branch if *stake_split_from.key == stake_pool.reserve_stake

@2501babe 2501babe marked this pull request as ready for review March 11, 2026 09:59
@2501babe 2501babe requested a review from joncinque March 11, 2026 09:59
joncinque
joncinque previously approved these changes Mar 11, 2026
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks great! Just a few additional parses that we can remove, but that can be done in a future PR if you prefer

Comment on lines -987 to -992
let reserve_stake = try_from_slice_unchecked::<stake::state::StakeStateV2>(
&reserve_stake_info.data.borrow(),
)?;
let reserve_meta = reserve_stake
.meta()
.ok_or(StakePoolError::WrongStakeStake)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks correct -- we only did the parse because we wanted to get meta.rent_exempt_reserve

Comment on lines 2220 to 2222
let reserve_stake = try_from_slice_unchecked::<stake::state::StakeStateV2>(
&reserve_stake_info.data.borrow(),
)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably don't need this parse either anymore -- same with the other case, the account address is checked earlier

Copy link
Member Author

@2501babe 2501babe Mar 11, 2026

Choose a reason for hiding this comment

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

ok i think youre right actually. i was wary of messing with the implicit assertion these are Initialized but process_initialize() ensures it is Initialized, it should not be possible to delegate to Stake, and all the rent checks surrounding the reserve are meant to ensure it can never change state to Uninitialized or closed. and in any event it couldnt be reopened anyway so the withdraw would just fail. ill remove them

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah exactly, that's what I was thinking

Comment on lines 3241 to 3243
let stake_state = try_from_slice_unchecked::<stake::state::StakeStateV2>(
&reserve_stake_info.data.borrow(),
)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably remove this parse too, since it's only used to get the rent_exempt_reserve field

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks great!

@2501babe 2501babe merged commit 2dd2a54 into solana-program:main Mar 11, 2026
20 checks passed
@2501babe 2501babe deleted the 20260311_rent branch March 11, 2026 20:05
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.

2 participants