Skip to content

Commit 1d823f9

Browse files
committed
Fix review comments
1 parent efaad10 commit 1d823f9

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

scripts/setup/solana.dic

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ pinocchio
6969
mainnet
7070
getters
7171
PRNG
72-
middleware
72+
middleware

sdk/src/sysvars/rent.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,17 @@ pub const DEFAULT_LAMPORTS_PER_BYTE: u64 = 6960;
5151
)]
5252
pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 2.0;
5353

54-
/// Default amount of time (in years) the balance has to include rent for the
55-
/// account to be rent exempt as a `u64`.
56-
const DEFAULT_EXEMPTION_THRESHOLD_AS_U64: u64 = 2;
57-
5854
/// The `u64` representation of the default exemption threshold.
5955
///
6056
/// This is used to check whether the `f64` value can be safely cast to a `u64`.
61-
const F64_EXEMPTION_THRESHOLD_AS_U64: u64 = 4611686018427387904;
57+
const CURRENT_EXEMPTION_THRESHOLD: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 64];
6258

63-
/// The `u64` representation of the deprecated exemption threshold.
59+
/// The `f64::to_le_bytes` representation of the SIMD-0194 exemption threshold.
6460
///
6561
/// This value is equivalent to `1f64`. It is only used to check whether
6662
/// the exemption threshold is the deprecated value to avoid performing
6763
/// floating-point operations on-chain.
68-
const F64_SIMD0194_EXEMPTION_THRESHOLD_AS_U64: u64 = 4607182418800017408;
64+
const SIMD0194_EXEMPTION_THRESHOLD: [u8; 8] = [0, 0, 0, 0, 0, 0, 240, 63];
6965

7066
/// Default percentage of collected rent that is burned.
7167
///
@@ -178,18 +174,16 @@ impl Rent {
178174
#[inline]
179175
pub fn minimum_balance(&self, data_len: usize) -> u64 {
180176
let bytes = data_len as u64;
181-
let exemption_threshold_as_u64 = u64::from_le_bytes(self.exemption_threshold);
182177

183-
match exemption_threshold_as_u64 {
184-
F64_SIMD0194_EXEMPTION_THRESHOLD_AS_U64 => {
178+
match self.exemption_threshold {
179+
SIMD0194_EXEMPTION_THRESHOLD => {
185180
(ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte
186181
}
187-
F64_EXEMPTION_THRESHOLD_AS_U64 => {
188-
((ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte)
189-
* DEFAULT_EXEMPTION_THRESHOLD_AS_U64
182+
CURRENT_EXEMPTION_THRESHOLD => {
183+
2 * (ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte
190184
}
191185
_ => {
192-
#[cfg(any(target_os = "solana", not(target_arch = "bpf")))]
186+
#[cfg(not(target_arch = "bpf"))]
193187
{
194188
(((ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte) as f64
195189
* f64::from_le_bytes(self.exemption_threshold)) as u64
@@ -224,15 +218,15 @@ impl Sysvar for Rent {
224218
#[allow(deprecated)]
225219
mod tests {
226220
use crate::sysvars::rent::{
227-
ACCOUNT_STORAGE_OVERHEAD, DEFAULT_BURN_PERCENT, DEFAULT_EXEMPTION_THRESHOLD,
228-
DEFAULT_LAMPORTS_PER_BYTE, DEFAULT_LAMPORTS_PER_BYTE_YEAR,
221+
ACCOUNT_STORAGE_OVERHEAD, CURRENT_EXEMPTION_THRESHOLD, DEFAULT_BURN_PERCENT,
222+
DEFAULT_LAMPORTS_PER_BYTE, DEFAULT_LAMPORTS_PER_BYTE_YEAR, SIMD0194_EXEMPTION_THRESHOLD,
229223
};
230224

231225
#[test]
232226
pub fn test_minimum_balance() {
233227
let mut rent = super::Rent {
234228
lamports_per_byte: DEFAULT_LAMPORTS_PER_BYTE_YEAR,
235-
exemption_threshold: DEFAULT_EXEMPTION_THRESHOLD.to_le_bytes(),
229+
exemption_threshold: CURRENT_EXEMPTION_THRESHOLD,
236230
burn_percent: DEFAULT_BURN_PERCENT,
237231
};
238232

@@ -260,7 +254,7 @@ mod tests {
260254
pub fn test_minimum_balance_simd0194() {
261255
let mut rent = super::Rent {
262256
lamports_per_byte: DEFAULT_LAMPORTS_PER_BYTE,
263-
exemption_threshold: 1.0f64.to_le_bytes(), // SIMD-0194 default
257+
exemption_threshold: SIMD0194_EXEMPTION_THRESHOLD,
264258
burn_percent: DEFAULT_BURN_PERCENT,
265259
};
266260

0 commit comments

Comments
 (0)