Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions rent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,28 @@ static_assertions::const_assert_eq!(
#[derive(PartialEq, CloneZeroed, Debug)]
pub struct Rent {
/// Rental rate in lamports/byte-year.
#[deprecated(
since = "3.1.0",
note = "Field will be renamed to `lamports_per_byte` in v4, use `Rent::new_with_lamports_per_byte` to create, and `Rent::minimum_balance` or `Rent::is_exempt`"
)]
pub lamports_per_byte_year: u64,

/// Amount of time (in years) a balance must include rent for the account to
/// be rent exempt.
#[deprecated(
since = "3.1.0",
note = "Exemption threshold will be set to 1f64 with SIMD-0194 and should no longer be used"
)]
pub exemption_threshold: f64,

/// The percentage of collected rent that is burned.
///
/// Valid values are in the range [0, 100]. The remaining percentage is
/// distributed to validators.
#[deprecated(
since = "3.1.0",
note = "The concept of rent no longer exists, only rent-exemption"
)]
pub burn_percent: u8,
}

Expand Down Expand Up @@ -71,6 +83,7 @@ pub const DEFAULT_BURN_PERCENT: u8 = 50;
pub const ACCOUNT_STORAGE_OVERHEAD: u64 = 128;

impl Default for Rent {
#[allow(deprecated)]
fn default() -> Self {
Self {
lamports_per_byte_year: DEFAULT_LAMPORTS_PER_BYTE_YEAR,
Expand All @@ -85,12 +98,18 @@ impl Rent {
///
/// The first value returned is the amount burned. The second is the amount
/// to distribute to validators.
#[deprecated(
since = "3.1.0",
note = "The concept of rent no longer exists, only rent-exemption"
)]
#[allow(deprecated)]
pub fn calculate_burn(&self, rent_collected: u64) -> (u64, u64) {
let burned_portion = (rent_collected * u64::from(self.burn_percent)) / 100;
(burned_portion, rent_collected - burned_portion)
}

/// Minimum balance due for rent-exemption of a given account data size.
#[allow(deprecated)]
pub fn minimum_balance(&self, data_len: usize) -> u64 {
let bytes = data_len as u64;
(((ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte_year) as f64
Expand All @@ -103,6 +122,11 @@ impl Rent {
}

/// Rent due on account's data length with balance.
#[deprecated(
since = "3.1.0",
note = "The concept of rent no longer exists, only rent-exemption"
)]
#[allow(deprecated)]
pub fn due(&self, balance: u64, data_len: usize, years_elapsed: f64) -> RentDue {
if self.is_exempt(balance, data_len) {
RentDue::Exempt
Expand All @@ -112,6 +136,11 @@ impl Rent {
}

/// Rent due for account that is known to be not exempt.
#[deprecated(
since = "3.1.0",
note = "The concept of rent no longer exists, only rent-exemption"
)]
#[allow(deprecated)]
pub fn due_amount(&self, data_len: usize, years_elapsed: f64) -> u64 {
let actual_data_len = data_len as u64 + ACCOUNT_STORAGE_OVERHEAD;
let lamports_per_year = self.lamports_per_byte_year * actual_data_len;
Expand All @@ -121,6 +150,7 @@ impl Rent {
/// Creates a `Rent` that charges no lamports.
///
/// This is used for testing.
#[allow(deprecated)]
pub fn free() -> Self {
Self {
lamports_per_byte_year: 0,
Expand All @@ -131,6 +161,11 @@ impl Rent {
/// Creates a `Rent` that is scaled based on the number of slots in an epoch.
///
/// This is used for testing.
#[deprecated(
since = "3.1.0",
note = "The concept of rent no longer exists, only rent-exemption, use `Rent::with_lamports_per_byte`"
)]
#[allow(deprecated)]
pub fn with_slots_per_epoch(slots_per_epoch: u64) -> Self {
let ratio = slots_per_epoch as f64 / DEFAULT_SLOTS_PER_EPOCH as f64;
let exemption_threshold = DEFAULT_EXEMPTION_THRESHOLD * ratio;
Expand All @@ -141,9 +176,22 @@ impl Rent {
..Self::default()
}
}

/// Creates a `Rent` with lamports per byte
#[allow(deprecated)]
pub fn with_lamports_per_byte(lamports_per_byte: u64) -> Self {
Self {
lamports_per_byte_year: lamports_per_byte,
..Self::default()
}
}
}

/// The return value of [`Rent::due`].
#[deprecated(
since = "3.1.0",
note = "The concept of rent no longer exists, only rent-exemption"
)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum RentDue {
/// Used to indicate the account is rent exempt.
Expand All @@ -152,6 +200,7 @@ pub enum RentDue {
Paying(u64),
}

#[allow(deprecated)]
impl RentDue {
/// Return the lamports due for rent.
pub fn lamports(&self) -> u64 {
Expand All @@ -175,6 +224,7 @@ mod tests {
use super::*;

#[test]
#[allow(deprecated)]
fn test_due() {
let default_rent = Rent::default();

Expand Down Expand Up @@ -221,6 +271,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn test_rent_due_lamports() {
assert_eq!(RentDue::Exempt.lamports(), 0);

Expand All @@ -229,12 +280,14 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn test_rent_due_is_exempt() {
assert!(RentDue::Exempt.is_exempt());
assert!(!RentDue::Paying(0).is_exempt());
}

#[test]
#[allow(deprecated)]
fn test_clone() {
let rent = Rent {
lamports_per_byte_year: 1,
Expand Down