parent
46e6911ec1
commit
9f046a023e
|
@ -183,9 +183,6 @@ type AccountStorage = Vec<AccountStorageEntry>;
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
struct ForkInfo {
|
struct ForkInfo {
|
||||||
/// The number of transactions processed without error
|
|
||||||
transaction_count: u64,
|
|
||||||
|
|
||||||
/// List of all parents of this fork
|
/// List of all parents of this fork
|
||||||
parents: Vec<Fork>,
|
parents: Vec<Fork>,
|
||||||
|
|
||||||
|
@ -284,7 +281,6 @@ impl AccountsDB {
|
||||||
if let Some(parent) = parent {
|
if let Some(parent) = parent {
|
||||||
fork_info.parents.push(parent);
|
fork_info.parents.push(parent);
|
||||||
if let Some(parent_fork_info) = fork_infos.get(&parent) {
|
if let Some(parent_fork_info) = fork_infos.get(&parent) {
|
||||||
fork_info.transaction_count = parent_fork_info.transaction_count;
|
|
||||||
fork_info
|
fork_info
|
||||||
.parents
|
.parents
|
||||||
.extend_from_slice(&parent_fork_info.parents);
|
.extend_from_slice(&parent_fork_info.parents);
|
||||||
|
@ -739,20 +735,6 @@ impl AccountsDB {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn increment_transaction_count(&self, fork: Fork, tx_count: usize) {
|
|
||||||
let mut fork_infos = self.fork_infos.write().unwrap();
|
|
||||||
let fork_info = fork_infos.entry(fork).or_insert(ForkInfo::default());
|
|
||||||
fork_info.transaction_count += tx_count as u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn transaction_count(&self, fork: Fork) -> u64 {
|
|
||||||
self.fork_infos
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get(&fork)
|
|
||||||
.map_or(0, |fork_info| fork_info.transaction_count)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_parents(&self, fork: Fork) -> Vec<Fork> {
|
fn remove_parents(&self, fork: Fork) -> Vec<Fork> {
|
||||||
let mut squashed_vote_accounts = self.get_vote_accounts(fork);
|
let mut squashed_vote_accounts = self.get_vote_accounts(fork);
|
||||||
squashed_vote_accounts.retain(|_, account| account.lamports != 0);
|
squashed_vote_accounts.retain(|_, account| account.lamports != 0);
|
||||||
|
@ -995,14 +977,6 @@ impl Accounts {
|
||||||
self.accounts_db.store_accounts(fork, txs, res, loaded)
|
self.accounts_db.store_accounts(fork, txs, res, loaded)
|
||||||
}
|
}
|
||||||
|
|
||||||
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, fork: Fork) -> u64 {
|
|
||||||
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
|
||||||
/// this function squashes all the parents into this instance
|
/// this function squashes all the parents into this instance
|
||||||
pub fn squash(&self, fork: Fork) {
|
pub fn squash(&self, fork: Fork) {
|
||||||
|
@ -1915,25 +1889,6 @@ mod tests {
|
||||||
assert_eq!(error_counters.account_not_found, 1);
|
assert_eq!(error_counters.account_not_found, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_accountsdb_inherit_tx_count() {
|
|
||||||
let paths = get_tmp_accounts_path!();
|
|
||||||
let accounts = AccountsDB::new(0, &paths.paths);
|
|
||||||
assert_eq!(accounts.transaction_count(0), 0);
|
|
||||||
accounts.increment_transaction_count(0, 1);
|
|
||||||
assert_eq!(accounts.transaction_count(0), 1);
|
|
||||||
// fork and check that tx count is inherited
|
|
||||||
accounts.add_fork(1, Some(0));
|
|
||||||
assert_eq!(accounts.transaction_count(1), 1);
|
|
||||||
// Parent fork shouldn't change
|
|
||||||
accounts.increment_transaction_count(1, 1);
|
|
||||||
assert_eq!(accounts.transaction_count(1), 2);
|
|
||||||
assert_eq!(accounts.transaction_count(0), 1);
|
|
||||||
// Squash shouldn't effect tx count
|
|
||||||
accounts.squash(1);
|
|
||||||
assert_eq!(accounts.transaction_count(1), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_by_program() {
|
fn test_load_by_program() {
|
||||||
let paths = get_tmp_accounts_path!();
|
let paths = get_tmp_accounts_path!();
|
||||||
|
|
|
@ -131,6 +131,9 @@ pub struct Bank {
|
||||||
/// Hash of this Bank's parent's state
|
/// Hash of this Bank's parent's state
|
||||||
parent_hash: Hash,
|
parent_hash: Hash,
|
||||||
|
|
||||||
|
/// The number of transactions processed without error
|
||||||
|
transaction_count: AtomicUsize, // TODO: Use AtomicU64 if/when available
|
||||||
|
|
||||||
/// Bank tick height
|
/// Bank tick height
|
||||||
tick_height: AtomicUsize, // TODO: Use AtomicU64 if/when available
|
tick_height: AtomicUsize, // TODO: Use AtomicU64 if/when available
|
||||||
|
|
||||||
|
@ -194,6 +197,9 @@ impl Bank {
|
||||||
bank.blockhash_queue = RwLock::new(parent.blockhash_queue.read().unwrap().clone());
|
bank.blockhash_queue = RwLock::new(parent.blockhash_queue.read().unwrap().clone());
|
||||||
bank.status_cache = parent.status_cache.clone();
|
bank.status_cache = parent.status_cache.clone();
|
||||||
|
|
||||||
|
bank.transaction_count
|
||||||
|
.store(parent.transaction_count() as usize, Ordering::Relaxed);
|
||||||
|
|
||||||
bank.tick_height
|
bank.tick_height
|
||||||
.store(parent.tick_height.load(Ordering::SeqCst), Ordering::SeqCst);
|
.store(parent.tick_height.load(Ordering::SeqCst), Ordering::SeqCst);
|
||||||
bank.ticks_per_slot = parent.ticks_per_slot;
|
bank.ticks_per_slot = parent.ticks_per_slot;
|
||||||
|
@ -647,8 +653,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
|
self.increment_transaction_count(tx_count);
|
||||||
.increment_transaction_count(self.accounts_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.blockhash_not_found {
|
if 0 != error_counters.blockhash_not_found {
|
||||||
|
@ -839,7 +844,11 @@ impl Bank {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transaction_count(&self) -> u64 {
|
pub fn transaction_count(&self) -> u64 {
|
||||||
self.accounts.transaction_count(self.accounts_id)
|
self.transaction_count.load(Ordering::Relaxed) as u64
|
||||||
|
}
|
||||||
|
fn increment_transaction_count(&self, tx_count: usize) {
|
||||||
|
self.transaction_count
|
||||||
|
.fetch_add(tx_count, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_signature_confirmation_status(
|
pub fn get_signature_confirmation_status(
|
||||||
|
@ -1758,4 +1767,45 @@ mod tests {
|
||||||
assert!(!bank5.is_in_subtree_of(2));
|
assert!(!bank5.is_in_subtree_of(2));
|
||||||
assert!(!bank5.is_in_subtree_of(4));
|
assert!(!bank5.is_in_subtree_of(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bank_inherit_tx_count() {
|
||||||
|
let (genesis_block, mint_keypair) = GenesisBlock::new(500);
|
||||||
|
let bank0 = Arc::new(Bank::new(&genesis_block));
|
||||||
|
|
||||||
|
// Bank 1
|
||||||
|
let bank1 = Arc::new(new_from_parent(&bank0));
|
||||||
|
// Bank 2
|
||||||
|
let bank2 = new_from_parent(&bank0);
|
||||||
|
|
||||||
|
// transfer a token
|
||||||
|
assert_eq!(
|
||||||
|
bank1.process_transaction(&system_transaction::transfer(
|
||||||
|
&mint_keypair,
|
||||||
|
&Keypair::new().pubkey(),
|
||||||
|
1,
|
||||||
|
genesis_block.hash(),
|
||||||
|
0
|
||||||
|
)),
|
||||||
|
Ok(())
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(bank0.transaction_count(), 0);
|
||||||
|
assert_eq!(bank2.transaction_count(), 0);
|
||||||
|
assert_eq!(bank1.transaction_count(), 1);
|
||||||
|
|
||||||
|
bank1.squash();
|
||||||
|
|
||||||
|
assert_eq!(bank0.transaction_count(), 0);
|
||||||
|
assert_eq!(bank2.transaction_count(), 0);
|
||||||
|
assert_eq!(bank1.transaction_count(), 1);
|
||||||
|
|
||||||
|
let bank6 = new_from_parent(&bank1);
|
||||||
|
assert_eq!(bank1.transaction_count(), 1);
|
||||||
|
assert_eq!(bank6.transaction_count(), 1);
|
||||||
|
|
||||||
|
bank6.squash();
|
||||||
|
assert_eq!(bank6.transaction_count(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue