tx count per fork

This commit is contained in:
Stephen Akridge 2019-02-20 16:14:58 -08:00 committed by sakridge
parent 180d297df8
commit 2158ba5863
3 changed files with 21 additions and 13 deletions

View File

@ -143,7 +143,7 @@ pub struct AccountsDB {
/// The number of transactions the bank has processed without error since the /// The number of transactions the bank has processed without error since the
/// start of the ledger. /// start of the ledger.
transaction_count: RwLock<u64>, transaction_count: RwLock<HashMap<u64, u64>>,
} }
impl Default for AccountsDB { impl Default for AccountsDB {
@ -156,7 +156,7 @@ impl Default for AccountsDB {
index_info, index_info,
storage: RwLock::new(vec![]), storage: RwLock::new(vec![]),
next_id: AtomicUsize::new(0), next_id: AtomicUsize::new(0),
transaction_count: RwLock::new(0), transaction_count: RwLock::new(HashMap::new()),
} }
} }
} }
@ -566,14 +566,19 @@ impl AccountsDB {
.collect() .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(); 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(); let tx = self.transaction_count.read().unwrap();
*tx if let Some(entry) = tx.get(&fork) {
*entry
} else {
0
}
} }
/// become the root accountsDB /// become the root accountsDB
@ -736,12 +741,12 @@ impl Accounts {
.store_accounts(fork, purge, txs, res, loaded) .store_accounts(fork, purge, txs, res, loaded)
} }
pub fn increment_transaction_count(&self, tx_count: usize) { pub fn increment_transaction_count(&self, fork: Fork, tx_count: usize) {
self.accounts_db.increment_transaction_count(tx_count) self.accounts_db.increment_transaction_count(fork, tx_count)
} }
pub fn transaction_count(&self) -> u64 { pub fn transaction_count(&self, fork: Fork) -> u64 {
self.accounts_db.transaction_count() self.accounts_db.transaction_count(fork)
} }
/// accounts starts with an empty data structure for every child/fork /// accounts starts with an empty data structure for every child/fork

View File

@ -466,7 +466,7 @@ impl Bank {
inc_new_counter_info!("bank-process_transactions-error_count", err_count); 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); inc_new_counter_info!("bank-process_transactions-txs", tx_count);
if 0 != error_counters.last_id_not_found { if 0 != error_counters.last_id_not_found {
@ -657,7 +657,7 @@ impl Bank {
} }
pub fn transaction_count(&self) -> u64 { 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<Result<()>> { pub fn get_signature_status(&self, signature: &Signature) -> Option<Result<()>> {

View File

@ -48,6 +48,8 @@ impl BankForks {
mod tests { mod tests {
use super::*; use super::*;
use solana_sdk::hash::Hash; use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::genesis_block::GenesisBlock;
#[test] #[test]
fn test_bank_forks_root() { fn test_bank_forks_root() {
@ -58,7 +60,8 @@ mod tests {
#[test] #[test]
fn test_bank_forks_parent() { 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 mut bank_forks = BankForks::new(0, bank);
let child_bank = Bank::new_from_parent(&bank_forks.working_bank()); let child_bank = Bank::new_from_parent(&bank_forks.working_bank());
child_bank.register_tick(&Hash::default()); child_bank.register_tick(&Hash::default());