SVM: Move `RentCollector` to sdk (#35122)

This commit is contained in:
Pankaj Garg 2024-02-07 16:38:42 -08:00 committed by GitHub
parent b9ee3b475b
commit 28a320d815
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 36 additions and 24 deletions

View File

@ -14,11 +14,11 @@ use {
},
accounts_index::AccountSecondaryIndexes,
ancestors::Ancestors,
rent_collector::RentCollector,
},
solana_measure::measure::Measure,
solana_sdk::{
genesis_config::ClusterType, pubkey::Pubkey, sysvar::epoch_schedule::EpochSchedule,
genesis_config::ClusterType, pubkey::Pubkey, rent_collector::RentCollector,
sysvar::epoch_schedule::EpochSchedule,
},
std::{env, fs, path::PathBuf, sync::Arc},
};

View File

@ -67,7 +67,6 @@ use {
partitioned_rewards::{PartitionedEpochRewardsConfig, TestPartitionedEpochRewards},
pubkey_bins::PubkeyBinCalculator24,
read_only_accounts_cache::ReadOnlyAccountsCache,
rent_collector::RentCollector,
sorted_storages::SortedStorages,
storable_accounts::StorableAccounts,
u64_align, utils,
@ -92,6 +91,7 @@ use {
genesis_config::{ClusterType, GenesisConfig},
hash::Hash,
pubkey::Pubkey,
rent_collector::RentCollector,
saturating_add_assign,
timing::AtomicInterval,
transaction::SanitizedTransaction,

View File

@ -4,7 +4,6 @@ use {
active_stats::{ActiveStatItem, ActiveStats},
ancestors::Ancestors,
pubkey_bins::PubkeyBinCalculator24,
rent_collector::RentCollector,
},
bytemuck::{Pod, Zeroable},
log::*,
@ -14,6 +13,7 @@ use {
solana_sdk::{
hash::{Hash, Hasher},
pubkey::Pubkey,
rent_collector::RentCollector,
slot_history::Slot,
sysvar::epoch_schedule::EpochSchedule,
},

View File

@ -34,7 +34,6 @@ pub mod nonce_info;
pub mod partitioned_rewards;
mod pubkey_bins;
mod read_only_accounts_cache;
pub mod rent_collector;
mod rolling_bit_field;
pub mod secondary_index;
pub mod shared_buffer_reader;

View File

@ -165,12 +165,12 @@ mod tests {
hot::HOT_FORMAT,
index::IndexOffset,
owners::OWNER_NO_OWNER,
solana_accounts_db::rent_collector::RENT_EXEMPT_RENT_EPOCH,
solana_sdk::{
account::{Account, AccountSharedData},
clock::Slot,
hash::Hash,
pubkey::Pubkey,
rent_collector::RENT_EXEMPT_RENT_EPOCH,
system_instruction::MAX_PERMITTED_DATA_LENGTH,
},
std::{

View File

@ -5,7 +5,6 @@ use {
account_storage::meta::{StoredAccountInfo, StoredAccountMeta},
accounts_file::MatchAccountOwnerError,
accounts_hash::AccountHash,
rent_collector::RENT_EXEMPT_RENT_EPOCH,
tiered_storage::{
byte_block,
file::TieredStorageFile,
@ -22,7 +21,10 @@ use {
bytemuck::{Pod, Zeroable},
memmap2::{Mmap, MmapOptions},
modular_bitfield::prelude::*,
solana_sdk::{account::ReadableAccount, pubkey::Pubkey, stake_history::Epoch},
solana_sdk::{
account::ReadableAccount, pubkey::Pubkey, rent_collector::RENT_EXEMPT_RENT_EPOCH,
stake_history::Epoch,
},
std::{borrow::Borrow, fs::OpenOptions, option::Option, path::Path},
};

View File

@ -16,7 +16,6 @@ use {
accounts_index::{AccountSecondaryIndexes, ScanConfig},
ancestors::Ancestors,
epoch_accounts_hash::EpochAccountsHash,
rent_collector::RentCollector,
},
solana_runtime::bank::*,
solana_sdk::{
@ -25,6 +24,7 @@ use {
hash::Hash,
lamports::LamportsError,
pubkey::Pubkey,
rent_collector::RentCollector,
sysvar::epoch_schedule::EpochSchedule,
},
std::{

View File

@ -88,7 +88,6 @@ use {
epoch_accounts_hash::EpochAccountsHash,
nonce_info::{NonceInfo, NoncePartial},
partitioned_rewards::PartitionedEpochRewardsConfig,
rent_collector::{CollectedInfo, RentCollector, RENT_EXEMPT_RENT_EPOCH},
sorted_storages::SortedStorages,
stake_rewards::StakeReward,
storable_accounts::StorableAccounts,
@ -142,6 +141,7 @@ use {
precompiles::get_precompiles,
pubkey::Pubkey,
rent::RentDue,
rent_collector::{CollectedInfo, RentCollector, RENT_EXEMPT_RENT_EPOCH},
rent_debits::RentDebits,
reward_info::RewardInfo,
saturating_add_assign,

View File

@ -605,7 +605,7 @@ mod tests {
// This some what long test harness is required to freeze the ABI of
// Bank's serialization due to versioned nature
#[frozen_abi(digest = "77zuTwvAGH5Rf28XHUNkRWsrcJ8uMyARMCZZMg9BBu5S")]
#[frozen_abi(digest = "7BH2s2Y1yKy396c3ixC4TTyvvpkyenAvWDSiZvY5yb7P")]
#[derive(Serialize, AbiExample)]
pub struct BankAbiTestWrapperNewer {
#[serde(serialize_with = "wrapper_newer")]

View File

@ -36,7 +36,6 @@ use {
inline_spl_token,
nonce_info::NonceFull,
partitioned_rewards::TestPartitionedEpochRewards,
rent_collector::RENT_EXEMPT_RENT_EPOCH,
transaction_results::DurableNonceFee,
},
solana_logger,
@ -88,6 +87,7 @@ use {
program::MAX_RETURN_DATA,
pubkey::Pubkey,
rent::Rent,
rent_collector::RENT_EXEMPT_RENT_EPOCH,
reward_type::RewardType,
secp256k1_program,
signature::{keypair_from_seed, Keypair, Signature, Signer},

View File

@ -25,7 +25,6 @@ use {
accounts_update_notifier_interface::AccountsUpdateNotifier,
blockhash_queue::BlockhashQueue,
epoch_accounts_hash::EpochAccountsHash,
rent_collector::RentCollector,
},
solana_measure::measure::Measure,
solana_sdk::{
@ -38,6 +37,7 @@ use {
hash::Hash,
inflation::Inflation,
pubkey::Pubkey,
rent_collector::RentCollector,
},
solana_svm::runtime_config::RuntimeConfig,
std::{

View File

@ -23,7 +23,6 @@ mod serde_snapshot_tests {
accounts_hash::AccountsHash,
accounts_index::AccountSecondaryIndexes,
ancestors::Ancestors,
rent_collector::RentCollector,
},
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
@ -32,6 +31,7 @@ mod serde_snapshot_tests {
genesis_config::{ClusterType, GenesisConfig},
hash::Hash,
pubkey::Pubkey,
rent_collector::RentCollector,
},
std::{
io::{BufReader, Cursor, Read, Write},

View File

@ -11,9 +11,11 @@ use {
accounts_db::{AccountStorageEntry, AccountsDb},
accounts_hash::{AccountsHash, AccountsHashKind},
epoch_accounts_hash::EpochAccountsHash,
rent_collector::RentCollector,
},
solana_sdk::{clock::Slot, feature_set, sysvar::epoch_schedule::EpochSchedule},
solana_sdk::{
clock::Slot, feature_set, rent_collector::RentCollector,
sysvar::epoch_schedule::EpochSchedule,
},
std::{
path::{Path, PathBuf},
sync::Arc,

View File

@ -92,6 +92,7 @@ pub mod program_utils;
pub mod pubkey;
pub mod quic;
pub mod recent_blockhashes_account;
pub mod rent_collector;
pub mod rent_debits;
pub mod reward_info;
pub mod reward_type;

View File

@ -1,3 +1,5 @@
#![cfg(feature = "full")]
//! calculate and collect rent from Accounts
use solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount},
@ -87,7 +89,10 @@ impl RentCollector {
} else {
let account_rent_epoch = account.rent_epoch();
let slots_elapsed: u64 = (account_rent_epoch..=self.epoch)
.map(|epoch| self.epoch_schedule.get_slots_in_epoch(epoch + 1))
.map(|epoch| {
self.epoch_schedule
.get_slots_in_epoch(epoch.saturating_add(1))
})
.sum();
// avoid infinite rent in rust 1.45
@ -165,7 +170,7 @@ impl RentCollector {
RentDue::Paying(0) => RentResult::NoRentCollectionNow,
// Rent is collected for next epoch.
RentDue::Paying(rent_due) => RentResult::CollectRent {
new_rent_epoch: self.epoch + 1,
new_rent_epoch: self.epoch.saturating_add(1),
rent_due,
},
}
@ -185,14 +190,16 @@ impl std::ops::Add for CollectedInfo {
type Output = Self;
fn add(self, other: Self) -> Self {
Self {
rent_amount: self.rent_amount + other.rent_amount,
account_data_len_reclaimed: self.account_data_len_reclaimed
+ other.account_data_len_reclaimed,
rent_amount: self.rent_amount.saturating_add(other.rent_amount),
account_data_len_reclaimed: self
.account_data_len_reclaimed
.saturating_add(other.account_data_len_reclaimed),
}
}
}
impl std::ops::AddAssign for CollectedInfo {
#![allow(clippy::arithmetic_side_effects)]
fn add_assign(&mut self, other: Self) {
*self = *self + other;
}

View File

@ -9,7 +9,6 @@ use {
solana_accounts_db::{
accounts::{LoadedTransaction, TransactionLoadResult, TransactionRent},
nonce_info::NonceFull,
rent_collector::{RentCollector, RENT_EXEMPT_RENT_EPOCH},
transaction_results::TransactionCheckResult,
},
solana_program_runtime::{
@ -28,6 +27,7 @@ use {
nonce::State as NonceState,
pubkey::Pubkey,
rent::RentDue,
rent_collector::{RentCollector, RENT_EXEMPT_RENT_EPOCH},
rent_debits::RentDebits,
saturating_add_assign,
sysvar::{self, instructions::construct_instructions_data},
@ -453,7 +453,7 @@ mod tests {
nonce::state::Versions as NonceVersions,
solana_accounts_db::{
accounts::Accounts, accounts_db::AccountsDb, accounts_file::MatchAccountOwnerError,
ancestors::Ancestors, rent_collector::RentCollector,
ancestors::Ancestors,
},
solana_program_runtime::{
compute_budget_processor,
@ -470,6 +470,7 @@ mod tests {
message::{Message, SanitizedMessage},
nonce,
rent::Rent,
rent_collector::RentCollector,
signature::{Keypair, Signer},
system_program, sysvar,
transaction::{Result, Transaction, TransactionError},

View File

@ -9,7 +9,6 @@ use {
solana_accounts_db::{
accounts::{LoadedTransaction, TransactionLoadResult},
accounts_file::MatchAccountOwnerError,
rent_collector::RentCollector,
transaction_results::{
DurableNonceFee, TransactionCheckResult, TransactionExecutionDetails,
TransactionExecutionResult,
@ -43,6 +42,7 @@ use {
message::SanitizedMessage,
native_loader,
pubkey::Pubkey,
rent_collector::RentCollector,
saturating_add_assign,
transaction::{self, SanitizedTransaction, TransactionError},
transaction_context::{ExecutionRecord, TransactionContext},