1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/// Rent Calculation
// pub const DEFAULT_LAMPORTS_PER_BYTE_YEAR: u64 = 1_000_000_000 / 100 * 365 / (1024 * 1024);
// TODO: Temp value as the rent is becoming greater than MIN_LAMPORTS_REQUIRED,
// fix that to a good value then comback to this
pub const DEFAULT_LAMPORTS_PER_BYTE_YEAR: u64 = 2;
/// Default amount of time (in years) the balance has to include rent for the
/// account to be rent exempt.
pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 2.0;
/// Account storage overhead for calculation of base rent.
///
/// This is the number of bytes required to store an account with no data. It is
/// added to an accounts data length when calculating [`Rent::minimum_balance`].
pub const ACCOUNT_STORAGE_OVERHEAD: u64 = 128;
/// Minimum balance due for rent-exemption of a given account data size.
pub fn minimum_rent(data_len: usize) -> u64 {
let bytes = data_len as u64;
(ACCOUNT_STORAGE_OVERHEAD + bytes) * DEFAULT_LAMPORTS_PER_BYTE_YEAR
}
/// Checks if the account is exempt from rent.
pub fn is_exempt(lamports: u64, data_len: usize) -> bool {
let rent = minimum_rent(data_len);
lamports >= rent
}
#[cfg(test)]
mod tests {
use super::*;
/// Consensus and clients size accounts with these exact values; any change
/// is a protocol change.
#[test]
fn minimum_rent_is_pinned() {
assert_eq!(minimum_rent(0), 256);
assert_eq!(minimum_rent(10), 276);
}
#[test]
fn exemption_starts_at_minimum_rent() {
assert!(!is_exempt(255, 0));
assert!(is_exempt(256, 0));
}
}