solana_svm_rent_collector::svm_rent_collector

Trait SVMRentCollector

Source
pub trait SVMRentCollector {
    // Required methods
    fn collect_rent(
        &self,
        address: &Pubkey,
        account: &mut AccountSharedData,
    ) -> CollectedInfo;
    fn get_rent(&self) -> &Rent;
    fn get_rent_due(
        &self,
        lamports: u64,
        data_len: usize,
        account_rent_epoch: Epoch,
    ) -> RentDue;

    // Provided methods
    fn check_rent_state(
        &self,
        pre_rent_state: Option<&RentState>,
        post_rent_state: Option<&RentState>,
        transaction_context: &TransactionContext,
        index: IndexOfAccount,
    ) -> Result<()> { ... }
    fn check_rent_state_with_account(
        &self,
        pre_rent_state: &RentState,
        post_rent_state: &RentState,
        address: &Pubkey,
        _account_state: &AccountSharedData,
        account_index: IndexOfAccount,
    ) -> Result<()> { ... }
    fn get_account_rent_state(&self, account: &AccountSharedData) -> RentState { ... }
    fn transition_allowed(
        &self,
        pre_rent_state: &RentState,
        post_rent_state: &RentState,
    ) -> bool { ... }
}
Expand description

Rent collector trait. Represents an entity that can evaluate the rent state of an account, determine rent due, and collect rent.

Implementors are responsible for evaluating rent due and collecting rent from accounts, if required. Methods for evaluating account rent state have default implementations, which can be overridden for customized rent management.

Required Methods§

Source

fn collect_rent( &self, address: &Pubkey, account: &mut AccountSharedData, ) -> CollectedInfo

Collect rent from an account.

Source

fn get_rent(&self) -> &Rent

Get the rent collector’s rent instance.

Source

fn get_rent_due( &self, lamports: u64, data_len: usize, account_rent_epoch: Epoch, ) -> RentDue

Get the rent due for an account.

Provided Methods§

Source

fn check_rent_state( &self, pre_rent_state: Option<&RentState>, post_rent_state: Option<&RentState>, transaction_context: &TransactionContext, index: IndexOfAccount, ) -> Result<()>

Check rent state transition for an account in a transaction.

This method has a default implementation that calls into check_rent_state_with_account.

Source

fn check_rent_state_with_account( &self, pre_rent_state: &RentState, post_rent_state: &RentState, address: &Pubkey, _account_state: &AccountSharedData, account_index: IndexOfAccount, ) -> Result<()>

Check rent state transition for an account directly.

This method has a default implementation that checks whether the transition is allowed and returns an error if it is not. It also verifies that the account is not the incinerator.

Source

fn get_account_rent_state(&self, account: &AccountSharedData) -> RentState

Determine the rent state of an account.

This method has a default implementation that treats accounts with zero lamports as uninitialized and uses the implemented get_rent to determine whether an account is rent-exempt.

Source

fn transition_allowed( &self, pre_rent_state: &RentState, post_rent_state: &RentState, ) -> bool

Check whether a transition from the pre_rent_state to the post_rent_state is valid.

This method has a default implementation that allows transitions from any state to RentState::Uninitialized or RentState::RentExempt. Pre-state RentState::RentPaying can only transition to RentState::RentPaying if the data size remains the same and the account is not credited.

Implementations on Foreign Types§

Source§

impl SVMRentCollector for RentCollector

Source§

fn collect_rent( &self, address: &Pubkey, account: &mut AccountSharedData, ) -> CollectedInfo

Source§

fn get_rent(&self) -> &Rent

Source§

fn get_rent_due( &self, lamports: u64, data_len: usize, account_rent_epoch: Epoch, ) -> RentDue

Implementors§