Skip to content

Commit d248c6b

Browse files
committed
Special-case old exemption-threshold, update digest
1 parent 5a2e29e commit d248c6b

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

genesis-config/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub const UNUSED_DEFAULT: u64 = 1024;
4949
#[cfg_attr(
5050
feature = "frozen-abi",
5151
derive(AbiExample),
52-
frozen_abi(digest = "3tUUJkZiUUGfuNCXbDuDR6KCQYPsh3m3cPw5vVUSt113")
52+
frozen_abi(digest = "8z56w59NRUjj4SVu6RxXGfUsdyUZn835ok9LTupU6jTy")
5353
)]
5454
#[cfg_attr(
5555
feature = "serde",

rent/src/lib.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ pub const DEFAULT_LAMPORTS_PER_BYTE: u64 = 6_960;
4646
// 1 as a 64-bit little-endian float, f64::to_le_bytes() is not stable in a
4747
// const context for older rust versions
4848
const DEFAULT_EXEMPTION_THRESHOLD: [u8; 8] = [0, 0, 0, 0, 0, 0, 240, 63];
49+
// 2 as a 64-bit little-endian float, f64::to_le_bytes() is not stable in a
50+
// const context for older rust versions. Remove this const and the match arm
51+
// using it in `minimum_balance()` once SIMD-0194 is released.
52+
const PREVIOUS_EXEMPTION_THRESHOLD: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 64];
4953
const DEFAULT_BURN_PERCENT: u8 = 50;
5054

5155
/// Account storage overhead for calculation of base rent.
@@ -68,11 +72,17 @@ impl Rent {
6872
/// Minimum balance due for rent-exemption of a given account data size.
6973
pub fn minimum_balance(&self, data_len: usize) -> u64 {
7074
let bytes = data_len as u64;
71-
if self.unused_exemption_threshold == DEFAULT_EXEMPTION_THRESHOLD {
72-
(ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte
73-
} else {
74-
(((ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte) as f64
75-
* f64::from_le_bytes(self.unused_exemption_threshold)) as u64
75+
match self.unused_exemption_threshold {
76+
DEFAULT_EXEMPTION_THRESHOLD => {
77+
(ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte
78+
}
79+
PREVIOUS_EXEMPTION_THRESHOLD => {
80+
2 * (ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte
81+
}
82+
_ => {
83+
(((ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte) as f64
84+
* f64::from_le_bytes(self.unused_exemption_threshold)) as u64
85+
}
7686
}
7787
}
7888

@@ -117,8 +127,9 @@ mod tests {
117127
}
118128

119129
#[test]
120-
fn test_default_exemption_threshold() {
130+
fn test_exemption_threshold() {
121131
assert_eq!(1f64.to_le_bytes(), DEFAULT_EXEMPTION_THRESHOLD);
132+
assert_eq!(2f64.to_le_bytes(), PREVIOUS_EXEMPTION_THRESHOLD);
122133
}
123134

124135
proptest! {
@@ -130,7 +141,13 @@ mod tests {
130141
unused_exemption_threshold: 2.0f64.to_le_bytes(),
131142
..Default::default()
132143
};
133-
assert_eq!(default_rent.minimum_balance(bytes), previous_rent.minimum_balance(bytes));
144+
let default_calc = default_rent.minimum_balance(bytes);
145+
assert_eq!(default_calc, previous_rent.minimum_balance(bytes));
146+
147+
// check that the calculation gives the same result using floats
148+
let float_calc = (((ACCOUNT_STORAGE_OVERHEAD + bytes as u64) * previous_rent.lamports_per_byte) as f64
149+
* f64::from_le_bytes(previous_rent.unused_exemption_threshold)) as u64;
150+
assert_eq!(default_calc, float_calc);
134151
}
135152
}
136153
}

0 commit comments

Comments
 (0)