Skip to content

Conversation

@febo
Copy link
Collaborator

@febo febo commented Dec 5, 2025

Problem

The concept of rent no longer exists, only rent-exemption, and upstream BPF does not support f64 values but currently the Rent sysvar implementation uses them.

Solution

Refactor the sysvar implementation and remove all references to f64.

@febo febo requested a review from joncinque December 5, 2025 01:08
@febo febo force-pushed the febo/upstream-rent branch 2 times, most recently from 812d444 to 37d9cc7 Compare December 5, 2025 01:43
@febo febo force-pushed the febo/upstream-rent branch from 37d9cc7 to efaad10 Compare December 5, 2025 01:46
Copy link
Collaborator

@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.

Just one question about the target_os = solana part, the rest looks great!

@febo febo force-pushed the febo/upstream-rent branch from 9bb767d to 4146158 Compare December 6, 2025 01:19
@febo febo force-pushed the febo/upstream-rent branch from 4146158 to 1d823f9 Compare December 6, 2025 01:20
joncinque
joncinque previously approved these changes Dec 6, 2025
Copy link
Collaborator

@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 the bit about saturating math, but we can address later

F64_SIMD0194_EXEMPTION_THRESHOLD_AS_U64 => {
match self.exemption_threshold {
SIMD0194_EXEMPTION_THRESHOLD => {
(ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this code has been here for some time, but I'm just realizing that we now have an opportunity to overflow this calculation, which wasn't the case when it used floats. Should we eventually use some saturating math here to be safe?

Copy link
Collaborator Author

@febo febo Dec 7, 2025

Choose a reason for hiding this comment

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

This is a tricky one. Adding saturated math increased CUs by ~70, which is about 50%. It will probably be cheaper to validate the data_len and lamports_per_byte values so that we can determine that it won't overflow.

Copy link
Collaborator

@joncinque joncinque Dec 8, 2025

Choose a reason for hiding this comment

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

Wow, I didn't think it would be so bad! Adding checks makes sense to me, and if it's costly, we could only check data_len and add a warning specifying the range of valid values for lamports_per_byte

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding a test on both data_len and lamports_per_byte takes 6 extra CUs. The caveat is that currently minimum_exempt is not a fallible function, so either we would need to panic or change the return type.

We could probably have a minimum_exempt and an unsafe minimim_exempt_unchecked (without the validation).

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes sense to me -- performance is getting huge gains anyway from not using floats, so the extra checks are not such a big deal

Copy link
Collaborator Author

@febo febo Dec 12, 2025

Choose a reason for hiding this comment

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

Added a fallible try_minimum_balance and unsafe minimum_balance_unchecked; also deprecated the minimum_balance, which now would panic if data_len exceeds the maximum allowed.

It is a bit tricky to have a good check for lamports_per_byte, since it depends on both exempt_threshold and maximum data_len. I was thinking that we can assume that the runtime guarantees the value of lamports_per_byte is valid in relation to the maximum data_len.

/// Burn percentage
pub burn_percent: u8,
/// The concept of rent no longer exists, only rent-exemption.
exemption_threshold: [u8; 8],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we just store this as a u64 to make things simpler?

Copy link
Collaborator Author

@febo febo Dec 11, 2025

Choose a reason for hiding this comment

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

We can everything as a [u8; 8] if we use an if statements instead of a match – no difference in CUs (eb6d8da).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah interesting, good to know! Do we know if that's a problem with codegen? It seems like the two should be equivalent, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I checked this and the compiler/llvm won't be able to infer all the information to optimize when used in a match statement, so this is the expected behaviour.

@febo febo force-pushed the febo/upstream-rent branch from 0cba916 to 2dcc702 Compare December 12, 2025 06:34
@febo febo force-pushed the febo/upstream-rent branch from 2dcc702 to 2671ac7 Compare December 12, 2025 06:47
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.

3 participants