Skip to content

Commit 93d0d25

Browse files
authored
Move rent debit out of bank (solana-labs#31204)
* Move rent debit out of bank * Clean up imports and visibility * Fix imports * rename public mod rent_debits
1 parent 0332f5f commit 93d0d25

File tree

8 files changed

+73
-59
lines changed

8 files changed

+73
-59
lines changed

ledger/src/blockstore_processor.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ use {
2424
accounts_index::AccountSecondaryIndexes,
2525
accounts_update_notifier_interface::AccountsUpdateNotifier,
2626
bank::{
27-
Bank, RentDebits, TransactionBalancesSet, TransactionExecutionDetails,
28-
TransactionExecutionResult, TransactionResults, VerifyAccountsHashConfig,
27+
Bank, TransactionBalancesSet, TransactionExecutionDetails, TransactionExecutionResult,
28+
TransactionResults, VerifyAccountsHashConfig,
2929
},
3030
bank_forks::BankForks,
3131
bank_utils,
3232
commitment::VOTE_THRESHOLD_SIZE,
3333
cost_model::CostModel,
3434
epoch_accounts_hash::EpochAccountsHash,
3535
prioritization_fee_cache::PrioritizationFeeCache,
36+
rent_debits::RentDebits,
3637
runtime_config::RuntimeConfig,
3738
transaction_batch::TransactionBatch,
3839
vote_account::VoteAccountsHashMap,

rpc/src/transaction_status_service.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ pub(crate) mod tests {
227227
dashmap::DashMap,
228228
solana_account_decoder::parse_token::token_amount_to_ui_amount,
229229
solana_ledger::{genesis_utils::create_genesis_config, get_tmp_ledger_path},
230-
solana_runtime::bank::{Bank, NonceFull, NoncePartial, RentDebits, TransactionBalancesSet},
230+
solana_runtime::{
231+
bank::{Bank, NonceFull, NoncePartial, TransactionBalancesSet},
232+
rent_debits::RentDebits,
233+
},
231234
solana_sdk::{
232235
account_utils::StateMut,
233236
clock::Slot,

runtime/src/accounts.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ use {
1313
},
1414
accounts_update_notifier_interface::AccountsUpdateNotifier,
1515
ancestors::Ancestors,
16-
bank::{
17-
Bank, NonceFull, NonceInfo, RentDebits, TransactionCheckResult,
18-
TransactionExecutionResult,
19-
},
16+
bank::{Bank, NonceFull, NonceInfo, TransactionCheckResult, TransactionExecutionResult},
2017
blockhash_queue::BlockhashQueue,
2118
rent_collector::RentCollector,
19+
rent_debits::RentDebits,
2220
storable_accounts::StorableAccounts,
2321
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
2422
transaction_error_metrics::TransactionErrorMetrics,

runtime/src/bank.rs

+1-49
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use {
6262
inline_spl_associated_token_account, inline_spl_token,
6363
message_processor::MessageProcessor,
6464
rent_collector::{CollectedInfo, RentCollector},
65+
rent_debits::RentDebits,
6566
runtime_config::RuntimeConfig,
6667
serde_snapshot::{SerdeAccountsHash, SerdeIncrementalAccountsHash},
6768
snapshot_hash::SnapshotHash,
@@ -216,26 +217,6 @@ struct RentMetrics {
216217
count: AtomicUsize,
217218
}
218219

219-
#[derive(Clone, Debug, PartialEq, Eq)]
220-
pub struct RentDebit {
221-
rent_collected: u64,
222-
post_balance: u64,
223-
}
224-
225-
impl RentDebit {
226-
fn try_into_reward_info(self) -> Option<RewardInfo> {
227-
let rent_debit = i64::try_from(self.rent_collected)
228-
.ok()
229-
.and_then(|r| r.checked_neg());
230-
rent_debit.map(|rent_debit| RewardInfo {
231-
reward_type: RewardType::Rent,
232-
lamports: rent_debit,
233-
post_balance: self.post_balance,
234-
commission: None, // Not applicable
235-
})
236-
}
237-
}
238-
239220
/// Incremental snapshots only calculate their accounts hash based on the account changes WITHIN the incremental slot range.
240221
/// So, we need to keep track of the full snapshot expected accounts hash results.
241222
/// 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 {
255236
pub incremental_capitalization: u64,
256237
}
257238

258-
#[derive(Clone, Debug, Default, PartialEq, Eq)]
259-
pub struct RentDebits(HashMap<Pubkey, RentDebit>);
260-
impl RentDebits {
261-
fn get_account_rent_debit(&self, address: &Pubkey) -> u64 {
262-
self.0
263-
.get(address)
264-
.map(|r| r.rent_collected)
265-
.unwrap_or_default()
266-
}
267-
268-
pub fn insert(&mut self, address: &Pubkey, rent_collected: u64, post_balance: u64) {
269-
if rent_collected != 0 {
270-
self.0.insert(
271-
*address,
272-
RentDebit {
273-
rent_collected,
274-
post_balance,
275-
},
276-
);
277-
}
278-
}
279-
280-
pub fn into_unordered_rewards_iter(self) -> impl Iterator<Item = (Pubkey, RewardInfo)> {
281-
self.0
282-
.into_iter()
283-
.filter_map(|(address, rent_debit)| Some((address, rent_debit.try_into_reward_info()?)))
284-
}
285-
}
286-
287239
pub type BankStatusCache = StatusCache<Result<()>>;
288240
#[frozen_abi(digest = "GBTLfFjModD9ykS9LV4pGi4S8eCrUj2JjWSDQLf8tMwV")]
289241
pub type BankSlotDelta = SlotDelta<Result<()>>;

runtime/src/bank/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10318,13 +10318,13 @@ fn test_rent_debits() {
1031810318

1031910319
// No entry for 0 rewards
1032010320
rent_debits.insert(&Pubkey::new_unique(), 0, 0);
10321-
assert_eq!(rent_debits.0.len(), 0);
10321+
assert_eq!(rent_debits.len(), 0);
1032210322

1032310323
// Some that actually work
1032410324
rent_debits.insert(&Pubkey::new_unique(), 1, 0);
10325-
assert_eq!(rent_debits.0.len(), 1);
10325+
assert_eq!(rent_debits.len(), 1);
1032610326
rent_debits.insert(&Pubkey::new_unique(), i64::MAX as u64, 0);
10327-
assert_eq!(rent_debits.0.len(), 2);
10327+
assert_eq!(rent_debits.len(), 2);
1032810328
}
1032910329

1033010330
#[test]

runtime/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub mod prioritization_fee_cache;
5454
mod pubkey_bins;
5555
mod read_only_accounts_cache;
5656
pub mod rent_collector;
57+
pub mod rent_debits;
5758
mod rent_paying_accounts_by_partition;
5859
mod rolling_bit_field;
5960
pub mod root_bank_cache;

runtime/src/rent_debit.rs

Whitespace-only changes.

runtime/src/rent_debits.rs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use {
2+
crate::bank::RewardInfo,
3+
solana_sdk::{pubkey::Pubkey, reward_type::RewardType},
4+
std::collections::HashMap,
5+
};
6+
7+
#[derive(Clone, Debug, PartialEq, Eq)]
8+
pub(crate) struct RentDebit {
9+
rent_collected: u64,
10+
post_balance: u64,
11+
}
12+
13+
impl RentDebit {
14+
fn try_into_reward_info(self) -> Option<RewardInfo> {
15+
let rent_debit = i64::try_from(self.rent_collected)
16+
.ok()
17+
.and_then(|r| r.checked_neg());
18+
rent_debit.map(|rent_debit| RewardInfo {
19+
reward_type: RewardType::Rent,
20+
lamports: rent_debit,
21+
post_balance: self.post_balance,
22+
commission: None, // Not applicable
23+
})
24+
}
25+
}
26+
27+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
28+
pub struct RentDebits(HashMap<Pubkey, RentDebit>);
29+
impl RentDebits {
30+
pub(crate) fn get_account_rent_debit(&self, address: &Pubkey) -> u64 {
31+
self.0
32+
.get(address)
33+
.map(|r| r.rent_collected)
34+
.unwrap_or_default()
35+
}
36+
37+
#[cfg(test)]
38+
pub(crate) fn len(&self) -> usize {
39+
self.0.len()
40+
}
41+
42+
pub fn insert(&mut self, address: &Pubkey, rent_collected: u64, post_balance: u64) {
43+
if rent_collected != 0 {
44+
self.0.insert(
45+
*address,
46+
RentDebit {
47+
rent_collected,
48+
post_balance,
49+
},
50+
);
51+
}
52+
}
53+
54+
pub fn into_unordered_rewards_iter(self) -> impl Iterator<Item = (Pubkey, RewardInfo)> {
55+
self.0
56+
.into_iter()
57+
.filter_map(|(address, rent_debit)| Some((address, rent_debit.try_into_reward_info()?)))
58+
}
59+
}

0 commit comments

Comments
 (0)