Inherit transaction count from parent (#3134)
This commit is contained in:
parent
0f1d6c6271
commit
9349f90a59
|
@ -220,6 +220,7 @@ 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);
|
||||||
|
@ -720,10 +721,6 @@ impl AccountsDB {
|
||||||
/// make fork a root, i.e. forget its heritage
|
/// make fork a root, i.e. forget its heritage
|
||||||
fn squash(&self, fork: Fork) {
|
fn squash(&self, fork: Fork) {
|
||||||
let parents = self.remove_parents(fork);
|
let parents = self.remove_parents(fork);
|
||||||
let tx_count = parents
|
|
||||||
.iter()
|
|
||||||
.fold(0, |sum, parent| sum + self.transaction_count(*parent));
|
|
||||||
self.increment_transaction_count(fork, tx_count as usize);
|
|
||||||
|
|
||||||
// for every account in all the parents, load latest and update self if
|
// for every account in all the parents, load latest and update self if
|
||||||
// absent
|
// absent
|
||||||
|
@ -1783,4 +1780,24 @@ 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);
|
||||||
|
cleanup_paths(&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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1417,11 +1417,12 @@ mod tests {
|
||||||
assert_eq!(parent.transaction_count(), 1);
|
assert_eq!(parent.transaction_count(), 1);
|
||||||
|
|
||||||
let bank = new_from_parent(&parent);
|
let bank = new_from_parent(&parent);
|
||||||
assert_eq!(bank.transaction_count(), 0);
|
assert_eq!(bank.transaction_count(), parent.transaction_count());
|
||||||
let tx_move_1_to_2 =
|
let tx_move_1_to_2 =
|
||||||
SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.hash(), 0);
|
SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx_move_1_to_2), Ok(()));
|
assert_eq!(bank.process_transaction(&tx_move_1_to_2), Ok(()));
|
||||||
assert_eq!(bank.transaction_count(), 1);
|
assert_eq!(bank.transaction_count(), 2);
|
||||||
|
assert_eq!(parent.transaction_count(), 1);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parent.get_signature_status(&tx_move_1_to_2.signatures[0]),
|
parent.get_signature_status(&tx_move_1_to_2.signatures[0]),
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in New Issue