diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 6512ca9763..3b45fc1ac3 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -143,7 +143,7 @@ pub struct AccountsDB { /// The number of transactions the bank has processed without error since the /// start of the ledger. - transaction_count: RwLock, + transaction_count: RwLock>, } impl Default for AccountsDB { @@ -156,7 +156,7 @@ impl Default for AccountsDB { index_info, storage: RwLock::new(vec![]), next_id: AtomicUsize::new(0), - transaction_count: RwLock::new(0), + transaction_count: RwLock::new(HashMap::new()), } } } @@ -566,14 +566,19 @@ impl AccountsDB { .collect() } - pub fn increment_transaction_count(&self, tx_count: usize) { + pub fn increment_transaction_count(&self, fork: Fork, tx_count: usize) { let mut tx = self.transaction_count.write().unwrap(); - *tx += tx_count as u64; + let entry = tx.entry(fork).or_insert(0); + *entry += tx_count as u64; } - pub fn transaction_count(&self) -> u64 { + pub fn transaction_count(&self, fork: Fork) -> u64 { let tx = self.transaction_count.read().unwrap(); - *tx + if let Some(entry) = tx.get(&fork) { + *entry + } else { + 0 + } } /// become the root accountsDB @@ -736,12 +741,12 @@ impl Accounts { .store_accounts(fork, purge, txs, res, loaded) } - pub fn increment_transaction_count(&self, tx_count: usize) { - self.accounts_db.increment_transaction_count(tx_count) + pub fn increment_transaction_count(&self, fork: Fork, tx_count: usize) { + self.accounts_db.increment_transaction_count(fork, tx_count) } - pub fn transaction_count(&self) -> u64 { - self.accounts_db.transaction_count() + pub fn transaction_count(&self, fork: Fork) -> u64 { + self.accounts_db.transaction_count(fork) } /// accounts starts with an empty data structure for every child/fork diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 2d97e204b7..c36e34924a 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -466,7 +466,7 @@ impl Bank { inc_new_counter_info!("bank-process_transactions-error_count", err_count); } - self.accounts().increment_transaction_count(tx_count); + self.accounts().increment_transaction_count(self.id, tx_count); inc_new_counter_info!("bank-process_transactions-txs", tx_count); if 0 != error_counters.last_id_not_found { @@ -657,7 +657,7 @@ impl Bank { } pub fn transaction_count(&self) -> u64 { - self.accounts().transaction_count() + self.accounts().transaction_count(self.id) } pub fn get_signature_status(&self, signature: &Signature) -> Option> { diff --git a/src/bank_forks.rs b/src/bank_forks.rs index e71451acc5..ccf8d637b4 100644 --- a/src/bank_forks.rs +++ b/src/bank_forks.rs @@ -48,6 +48,8 @@ impl BankForks { mod tests { use super::*; use solana_sdk::hash::Hash; + use solana_sdk::pubkey::Pubkey; + use solana_sdk::genesis_block::GenesisBlock; #[test] fn test_bank_forks_root() { @@ -58,7 +60,8 @@ mod tests { #[test] fn test_bank_forks_parent() { - let bank = Bank::default(); + let (genesis_block, _) = GenesisBlock::new(10_000); + let bank = Bank::new(&genesis_block); let mut bank_forks = BankForks::new(0, bank); let child_bank = Bank::new_from_parent(&bank_forks.working_bank()); child_bank.register_tick(&Hash::default());