Move rent debit out of bank (#31204)
* Move rent debit out of bank * Clean up imports and visibility * Fix imports * rename public mod rent_debits
This commit is contained in:
parent
0332f5f38d
commit
93d0d25d77
|
@ -24,8 +24,8 @@ use {
|
|||
accounts_index::AccountSecondaryIndexes,
|
||||
accounts_update_notifier_interface::AccountsUpdateNotifier,
|
||||
bank::{
|
||||
Bank, RentDebits, TransactionBalancesSet, TransactionExecutionDetails,
|
||||
TransactionExecutionResult, TransactionResults, VerifyAccountsHashConfig,
|
||||
Bank, TransactionBalancesSet, TransactionExecutionDetails, TransactionExecutionResult,
|
||||
TransactionResults, VerifyAccountsHashConfig,
|
||||
},
|
||||
bank_forks::BankForks,
|
||||
bank_utils,
|
||||
|
@ -33,6 +33,7 @@ use {
|
|||
cost_model::CostModel,
|
||||
epoch_accounts_hash::EpochAccountsHash,
|
||||
prioritization_fee_cache::PrioritizationFeeCache,
|
||||
rent_debits::RentDebits,
|
||||
runtime_config::RuntimeConfig,
|
||||
transaction_batch::TransactionBatch,
|
||||
vote_account::VoteAccountsHashMap,
|
||||
|
|
|
@ -227,7 +227,10 @@ pub(crate) mod tests {
|
|||
dashmap::DashMap,
|
||||
solana_account_decoder::parse_token::token_amount_to_ui_amount,
|
||||
solana_ledger::{genesis_utils::create_genesis_config, get_tmp_ledger_path},
|
||||
solana_runtime::bank::{Bank, NonceFull, NoncePartial, RentDebits, TransactionBalancesSet},
|
||||
solana_runtime::{
|
||||
bank::{Bank, NonceFull, NoncePartial, TransactionBalancesSet},
|
||||
rent_debits::RentDebits,
|
||||
},
|
||||
solana_sdk::{
|
||||
account_utils::StateMut,
|
||||
clock::Slot,
|
||||
|
|
|
@ -13,12 +13,10 @@ use {
|
|||
},
|
||||
accounts_update_notifier_interface::AccountsUpdateNotifier,
|
||||
ancestors::Ancestors,
|
||||
bank::{
|
||||
Bank, NonceFull, NonceInfo, RentDebits, TransactionCheckResult,
|
||||
TransactionExecutionResult,
|
||||
},
|
||||
bank::{Bank, NonceFull, NonceInfo, TransactionCheckResult, TransactionExecutionResult},
|
||||
blockhash_queue::BlockhashQueue,
|
||||
rent_collector::RentCollector,
|
||||
rent_debits::RentDebits,
|
||||
storable_accounts::StorableAccounts,
|
||||
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
|
||||
transaction_error_metrics::TransactionErrorMetrics,
|
||||
|
|
|
@ -62,6 +62,7 @@ use {
|
|||
inline_spl_associated_token_account, inline_spl_token,
|
||||
message_processor::MessageProcessor,
|
||||
rent_collector::{CollectedInfo, RentCollector},
|
||||
rent_debits::RentDebits,
|
||||
runtime_config::RuntimeConfig,
|
||||
serde_snapshot::{SerdeAccountsHash, SerdeIncrementalAccountsHash},
|
||||
snapshot_hash::SnapshotHash,
|
||||
|
@ -216,26 +217,6 @@ struct RentMetrics {
|
|||
count: AtomicUsize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct RentDebit {
|
||||
rent_collected: u64,
|
||||
post_balance: u64,
|
||||
}
|
||||
|
||||
impl RentDebit {
|
||||
fn try_into_reward_info(self) -> Option<RewardInfo> {
|
||||
let rent_debit = i64::try_from(self.rent_collected)
|
||||
.ok()
|
||||
.and_then(|r| r.checked_neg());
|
||||
rent_debit.map(|rent_debit| RewardInfo {
|
||||
reward_type: RewardType::Rent,
|
||||
lamports: rent_debit,
|
||||
post_balance: self.post_balance,
|
||||
commission: None, // Not applicable
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Incremental snapshots only calculate their accounts hash based on the account changes WITHIN the incremental slot range.
|
||||
/// So, we need to keep track of the full snapshot expected accounts hash results.
|
||||
/// We also need to keep track of the hash and capitalization specific to the incremental snapshot slot range.
|
||||
|
@ -255,35 +236,6 @@ pub struct BankIncrementalSnapshotPersistence {
|
|||
pub incremental_capitalization: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct RentDebits(HashMap<Pubkey, RentDebit>);
|
||||
impl RentDebits {
|
||||
fn get_account_rent_debit(&self, address: &Pubkey) -> u64 {
|
||||
self.0
|
||||
.get(address)
|
||||
.map(|r| r.rent_collected)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, address: &Pubkey, rent_collected: u64, post_balance: u64) {
|
||||
if rent_collected != 0 {
|
||||
self.0.insert(
|
||||
*address,
|
||||
RentDebit {
|
||||
rent_collected,
|
||||
post_balance,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_unordered_rewards_iter(self) -> impl Iterator<Item = (Pubkey, RewardInfo)> {
|
||||
self.0
|
||||
.into_iter()
|
||||
.filter_map(|(address, rent_debit)| Some((address, rent_debit.try_into_reward_info()?)))
|
||||
}
|
||||
}
|
||||
|
||||
pub type BankStatusCache = StatusCache<Result<()>>;
|
||||
#[frozen_abi(digest = "GBTLfFjModD9ykS9LV4pGi4S8eCrUj2JjWSDQLf8tMwV")]
|
||||
pub type BankSlotDelta = SlotDelta<Result<()>>;
|
||||
|
|
|
@ -10318,13 +10318,13 @@ fn test_rent_debits() {
|
|||
|
||||
// No entry for 0 rewards
|
||||
rent_debits.insert(&Pubkey::new_unique(), 0, 0);
|
||||
assert_eq!(rent_debits.0.len(), 0);
|
||||
assert_eq!(rent_debits.len(), 0);
|
||||
|
||||
// Some that actually work
|
||||
rent_debits.insert(&Pubkey::new_unique(), 1, 0);
|
||||
assert_eq!(rent_debits.0.len(), 1);
|
||||
assert_eq!(rent_debits.len(), 1);
|
||||
rent_debits.insert(&Pubkey::new_unique(), i64::MAX as u64, 0);
|
||||
assert_eq!(rent_debits.0.len(), 2);
|
||||
assert_eq!(rent_debits.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -54,6 +54,7 @@ pub mod prioritization_fee_cache;
|
|||
mod pubkey_bins;
|
||||
mod read_only_accounts_cache;
|
||||
pub mod rent_collector;
|
||||
pub mod rent_debits;
|
||||
mod rent_paying_accounts_by_partition;
|
||||
mod rolling_bit_field;
|
||||
pub mod root_bank_cache;
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
use {
|
||||
crate::bank::RewardInfo,
|
||||
solana_sdk::{pubkey::Pubkey, reward_type::RewardType},
|
||||
std::collections::HashMap,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct RentDebit {
|
||||
rent_collected: u64,
|
||||
post_balance: u64,
|
||||
}
|
||||
|
||||
impl RentDebit {
|
||||
fn try_into_reward_info(self) -> Option<RewardInfo> {
|
||||
let rent_debit = i64::try_from(self.rent_collected)
|
||||
.ok()
|
||||
.and_then(|r| r.checked_neg());
|
||||
rent_debit.map(|rent_debit| RewardInfo {
|
||||
reward_type: RewardType::Rent,
|
||||
lamports: rent_debit,
|
||||
post_balance: self.post_balance,
|
||||
commission: None, // Not applicable
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct RentDebits(HashMap<Pubkey, RentDebit>);
|
||||
impl RentDebits {
|
||||
pub(crate) fn get_account_rent_debit(&self, address: &Pubkey) -> u64 {
|
||||
self.0
|
||||
.get(address)
|
||||
.map(|r| r.rent_collected)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, address: &Pubkey, rent_collected: u64, post_balance: u64) {
|
||||
if rent_collected != 0 {
|
||||
self.0.insert(
|
||||
*address,
|
||||
RentDebit {
|
||||
rent_collected,
|
||||
post_balance,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_unordered_rewards_iter(self) -> impl Iterator<Item = (Pubkey, RewardInfo)> {
|
||||
self.0
|
||||
.into_iter()
|
||||
.filter_map(|(address, rent_debit)| Some((address, rent_debit.try_into_reward_info()?)))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue