Skip to content

Commit

Permalink
SVM: Move RentCollector to sdk (#35122)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 authored Feb 8, 2024
1 parent b9ee3b4 commit 28a320d
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 24 deletions.
4 changes: 2 additions & 2 deletions accounts-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down
2 changes: 1 addition & 1 deletion accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -92,6 +91,7 @@ use {
genesis_config::{ClusterType, GenesisConfig},
hash::Hash,
pubkey::Pubkey,
rent_collector::RentCollector,
saturating_add_assign,
timing::AtomicInterval,
transaction::SanitizedTransaction,
Expand Down
2 changes: 1 addition & 1 deletion accounts-db/src/accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use {
active_stats::{ActiveStatItem, ActiveStats},
ancestors::Ancestors,
pubkey_bins::PubkeyBinCalculator24,
rent_collector::RentCollector,
},
bytemuck::{Pod, Zeroable},
log::*,
Expand All @@ -14,6 +13,7 @@ use {
solana_sdk::{
hash::{Hash, Hasher},
pubkey::Pubkey,
rent_collector::RentCollector,
slot_history::Slot,
sysvar::epoch_schedule::EpochSchedule,
},
Expand Down
1 change: 0 additions & 1 deletion accounts-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion accounts-db/src/tiered_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
6 changes: 4 additions & 2 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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},
};

Expand Down
2 changes: 1 addition & 1 deletion runtime/benches/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use {
accounts_index::{AccountSecondaryIndexes, ScanConfig},
ancestors::Ancestors,
epoch_accounts_hash::EpochAccountsHash,
rent_collector::RentCollector,
},
solana_runtime::bank::*,
solana_sdk::{
Expand All @@ -25,6 +24,7 @@ use {
hash::Hash,
lamports::LamportsError,
pubkey::Pubkey,
rent_collector::RentCollector,
sysvar::epoch_schedule::EpochSchedule,
},
std::{
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -38,6 +37,7 @@ use {
hash::Hash,
inflation::Inflation,
pubkey::Pubkey,
rent_collector::RentCollector,
},
solana_svm::runtime_config::RuntimeConfig,
std::{
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ mod serde_snapshot_tests {
accounts_hash::AccountsHash,
accounts_index::AccountSecondaryIndexes,
ancestors::Ancestors,
rent_collector::RentCollector,
},
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
Expand All @@ -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},
Expand Down
6 changes: 4 additions & 2 deletions runtime/src/snapshot_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 12 additions & 5 deletions accounts-db/src/rent_collector.rs → sdk/src/rent_collector.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "full")]

//! calculate and collect rent from Accounts
use solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
}
Expand All @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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},
Expand Down Expand Up @@ -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,
Expand All @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use {
solana_accounts_db::{
accounts::{LoadedTransaction, TransactionLoadResult},
accounts_file::MatchAccountOwnerError,
rent_collector::RentCollector,
transaction_results::{
DurableNonceFee, TransactionCheckResult, TransactionExecutionDetails,
TransactionExecutionResult,
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 28a320d

Please sign in to comment.