program: replace rent_exempt_reserve with Rent #303
program: replace rent_exempt_reserve with Rent #3032501babe merged 9 commits intosolana-program:mainfrom
rent_exempt_reserve with Rent #303Conversation
| let source_lamports = checked_add( | ||
| source_meta.rent_exempt_reserve, | ||
| source_stake.delegation.stake, | ||
| )?; |
There was a problem hiding this comment.
as a nice little side effect, we now merge all lamports from an activating source into the delegation of an activating destination instead of leaving out non-rent non-stake lamports
There was a problem hiding this comment.
Very nice! I hadn't even considered that part
bb19ad6 to
842a7ec
Compare
|
these are probably all spurious since edit: yep all nonsense. i would however recommend looking at the |
| #[deprecated( | ||
| since = "3.0.1", | ||
| note = "Stake account rent must be calculated via the `Rent` sysvar. \ | ||
| This value will cease to be correct once lamports-per-byte is adjusted." | ||
| )] |
There was a problem hiding this comment.
youll notice we use lamports_per_byte_year in interface.rs. the lamports_per_byte rename comes in solana-rent v4 which landed in agave v4 so i chose to use this term in comments. we may or may not bump solana-rent before release, but its out of scope for this pr
it not unsafe to keep using solana-rent v3 because the underlying onchain bytes just change to a lamports_per_byte_year twice the historical value and an exemption_threshold of 1
There was a problem hiding this comment.
Yeah that's totally fine, we've been adopting that language everywhere already
| let mut dest_meta = source_meta; | ||
| dest_meta.rent_exempt_reserve = destination_rent_exempt_reserve; | ||
| dest_meta.rent_exempt_reserve = PSEUDO_RENT_EXEMPT_RESERVE; |
There was a problem hiding this comment.
i kept this because we enforce split destination is 200 bytes, so if there is a larger source, we dont want to allow its potentially different rent_exempt_reserve to proliferate
There was a problem hiding this comment.
Makes sense, thanks for the explanation
|
@grod220 jon agreed to take this but i added you as a secondary reviewer in case youd like to keep abreast of these changes |
joncinque
left a comment
There was a problem hiding this comment.
Really great work!
the question becomes moot if we rewrite rent_exempt_reserve at epoch boundaries but it doesnt seem like a hard requirement that we do this
Looking at the code, I think we'll be better off not rewriting rent_exempt_reserve at the boundary. Like you say, a fixed value that's incorrect, but too high is better than a floating value that can be either too big or too small.
I looked at the stake pool program, and it should be fine with these changes, since as you mention, it'll just overshoot. I'll put in a PR over there to always use Rent too.
| #[deprecated( | ||
| since = "3.0.1", | ||
| note = "Stake account rent must be calculated via the `Rent` sysvar. \ | ||
| This value will cease to be correct once lamports-per-byte is adjusted." | ||
| )] |
There was a problem hiding this comment.
Yeah that's totally fine, we've been adopting that language everywhere already
| let source_lamports = checked_add( | ||
| source_meta.rent_exempt_reserve, | ||
| source_stake.delegation.stake, | ||
| )?; |
There was a problem hiding this comment.
Very nice! I hadn't even considered that part
| let mut dest_meta = source_meta; | ||
| dest_meta.rent_exempt_reserve = destination_rent_exempt_reserve; | ||
| dest_meta.rent_exempt_reserve = PSEUDO_RENT_EXEMPT_RESERVE; |
There was a problem hiding this comment.
Makes sense, thanks for the explanation
agave now has several feature gates to reduce rent costs. historically, stake has assumed rent does not change and stored rent-exemption in
Meta.rent_exempt_reserve. this pr changes bpf stake to rely exclusively onRentas long as rent only goes down, this pr is a sufficient solution to all our problems. if rent were to go back up, we need a mechanism to adjust delegation down so that rent lamports and stake lamports are always mutually exclusive. the expectation at present is that this will be added to agave, rewriting delegations at the epoch boundary so that stake does not need to be aware of such happenings
the question of what exactly do do with
rent_exempt_reserveis potentially a matter for debate. existing programs that use stake accounts probably treat it as canonical. thus, continuing to write something to this field is an obvious decision. whats non-obvious is what to writei decided to unconditionally set
rent_exempt_reserveto the current value used for new stake accounts. the downside is this has the potential to confuse programs when the actual rent required is lower. however i believe the most attractive property of this approach is consistencyonce rent changes for the first time, all stake account
rent_exempt_reservevalues will become wrong. the problem with settingrent_exempt_reserveto true rent on stake account initialization or delegation is that when rent changes again, the stake accounts set up in that intervening period become wrong again anyway, and wrong in a different way than older accounts. we also create novel edge cases if rent ever goes up: fixingrent_exempt_reserveat a ceiling value means it always overshoots, but letting it float means it may overshoot and undershootthe question becomes moot if we rewrite
rent_exempt_reserveat epoch boundaries but it doesnt seem like a hard requirement that we do thiswe may wish to consider setting
rent_exempt_reserveto our chosen magic number inMeta::default()andMeta::auto(), but because this does not affect the stake program, it seems unecessary to do so