Skip to content

Commit

Permalink
bank: Record non-vote transaction count (solana-labs#29383)
Browse files Browse the repository at this point in the history
A subsequent change to `SamplePerformanceService` introduces non-vote transaction counts, which `bank`s need to store.

Part of work on solana-labs#29159
  • Loading branch information
ilya-bobyr authored and nickfrosty committed Jan 4, 2023
1 parent 5f043d0 commit daa1bd0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,7 @@ impl BankingStage {
gossip_vote_sender: &ReplayVoteSender,
signature_count: u64,
executed_transactions_count: usize,
executed_non_vote_transactions_count: usize,
executed_with_successful_result_count: usize,
) -> (u64, Vec<CommitTransactionDetails>) {
inc_new_counter_info!(
Expand All @@ -1195,6 +1196,8 @@ impl BankingStage {
lamports_per_signature,
CommitTransactionCounts {
committed_transactions_count: executed_transactions_count as u64,
committed_non_vote_transactions_count: executed_non_vote_transactions_count
as u64,
committed_with_failure_result_count: executed_transactions_count
.saturating_sub(executed_with_successful_result_count)
as u64,
Expand Down Expand Up @@ -1330,6 +1333,7 @@ impl BankingStage {
execution_results,
mut retryable_transaction_indexes,
executed_transactions_count,
executed_non_vote_transactions_count,
executed_with_successful_result_count,
signature_count,
error_counters,
Expand Down Expand Up @@ -1407,6 +1411,7 @@ impl BankingStage {
gossip_vote_sender,
signature_count,
executed_transactions_count,
executed_non_vote_transactions_count,
executed_with_successful_result_count,
)
} else {
Expand Down
64 changes: 63 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ pub struct LoadAndExecuteTransactionsOutput {
pub retryable_transaction_indexes: Vec<usize>,
// Total number of transactions that were executed
pub executed_transactions_count: usize,
// Number of non-vote transactions that were executed
pub executed_non_vote_transactions_count: usize,
// Total number of the executed transactions that returned success/not
// an error.
pub executed_with_successful_result_count: usize,
Expand Down Expand Up @@ -816,6 +818,7 @@ impl PartialEq for Bank {
parent_slot,
hard_forks,
transaction_count,
non_vote_transaction_count_since_restart: _,
transaction_error_count: _,
transaction_entries_count: _,
transactions_per_entry_max: _,
Expand Down Expand Up @@ -979,6 +982,11 @@ pub struct Bank {
/// The number of transactions processed without error
transaction_count: AtomicU64,

/// The number of non-vote transactions processed without error since the most recent boot from
/// snapshot or genesis. This value is not shared though the network, nor retained within
/// snapshots, but is preserved in `Bank::new_from_parent`.
non_vote_transaction_count_since_restart: AtomicU64,

/// The number of transaction errors in this slot
transaction_error_count: AtomicU64,

Expand Down Expand Up @@ -1157,6 +1165,7 @@ struct PrevEpochInflationRewards {

pub struct CommitTransactionCounts {
pub committed_transactions_count: u64,
pub committed_non_vote_transactions_count: u64,
pub committed_with_failure_result_count: u64,
pub signature_count: u64,
}
Expand Down Expand Up @@ -1269,6 +1278,7 @@ impl Bank {
parent_slot: Slot::default(),
hard_forks: Arc::<RwLock<HardForks>>::default(),
transaction_count: AtomicU64::default(),
non_vote_transaction_count_since_restart: AtomicU64::default(),
transaction_error_count: AtomicU64::default(),
transaction_entries_count: AtomicU64::default(),
transactions_per_entry_max: AtomicU64::default(),
Expand Down Expand Up @@ -1582,6 +1592,9 @@ impl Bank {
vote_only_bank,
inflation: parent.inflation.clone(),
transaction_count: AtomicU64::new(parent.transaction_count()),
non_vote_transaction_count_since_restart: AtomicU64::new(
parent.non_vote_transaction_count_since_restart(),
),
transaction_error_count: AtomicU64::new(0),
transaction_entries_count: AtomicU64::new(0),
transactions_per_entry_max: AtomicU64::new(0),
Expand Down Expand Up @@ -1950,6 +1963,7 @@ impl Bank {
parent_slot: fields.parent_slot,
hard_forks: Arc::new(RwLock::new(fields.hard_forks)),
transaction_count: AtomicU64::new(fields.transaction_count),
non_vote_transaction_count_since_restart: new(),
transaction_error_count: new(),
transaction_entries_count: new(),
transactions_per_entry_max: new(),
Expand Down Expand Up @@ -4504,6 +4518,7 @@ impl Bank {
timings.saturating_add_in_place(ExecuteTimingType::ExecuteUs, execution_time.as_us());

let mut executed_transactions_count: usize = 0;
let mut executed_non_vote_transactions_count: usize = 0;
let mut executed_with_successful_result_count: usize = 0;
let err_count = &mut error_counters.total;
let transaction_log_collector_config =
Expand All @@ -4521,6 +4536,8 @@ impl Bank {
}
}

let is_vote = vote_parser::is_simple_vote_transaction(tx);

if execution_result.was_executed() // Skip log collection for unprocessed transactions
&& transaction_log_collector_config.filter != TransactionLogCollectorFilter::None
{
Expand All @@ -4539,7 +4556,6 @@ impl Bank {
}
}

let is_vote = vote_parser::is_simple_vote_transaction(tx);
let store = match transaction_log_collector_config.filter {
TransactionLogCollectorFilter::All => {
!is_vote || !filtered_mentioned_addresses.is_empty()
Expand Down Expand Up @@ -4589,6 +4605,9 @@ impl Bank {

match execution_result.flattened_result() {
Ok(()) => {
if !is_vote {
executed_non_vote_transactions_count += 1;
}
executed_with_successful_result_count += 1;
}
Err(err) => {
Expand All @@ -4615,6 +4634,7 @@ impl Bank {
execution_results,
retryable_transaction_indexes,
executed_transactions_count,
executed_non_vote_transactions_count,
executed_with_successful_result_count,
signature_count,
error_counters,
Expand Down Expand Up @@ -4879,6 +4899,7 @@ impl Bank {

let CommitTransactionCounts {
committed_transactions_count,
committed_non_vote_transactions_count,
committed_with_failure_result_count,
signature_count,
} = counts;
Expand All @@ -4890,12 +4911,19 @@ impl Bank {
};

self.increment_transaction_count(tx_count);
self.increment_non_vote_transaction_count_since_restart(
committed_non_vote_transactions_count,
);
self.increment_signature_count(signature_count);

inc_new_counter_info!(
"bank-process_transactions-txs",
committed_transactions_count as usize
);
inc_new_counter_info!(
"bank-process_non_vote_transactions-txs",
committed_non_vote_transactions_count as usize
);
inc_new_counter_info!("bank-process_transactions-sigs", signature_count as usize);

if committed_with_failure_result_count > 0 {
Expand Down Expand Up @@ -6041,6 +6069,7 @@ impl Bank {
mut loaded_transactions,
execution_results,
executed_transactions_count,
executed_non_vote_transactions_count,
executed_with_successful_result_count,
signature_count,
..
Expand All @@ -6065,6 +6094,7 @@ impl Bank {
lamports_per_signature,
CommitTransactionCounts {
committed_transactions_count: executed_transactions_count as u64,
committed_non_vote_transactions_count: executed_non_vote_transactions_count as u64,
committed_with_failure_result_count: executed_transactions_count
.saturating_sub(executed_with_successful_result_count)
as u64,
Expand Down Expand Up @@ -6589,6 +6619,10 @@ impl Bank {
self.transaction_count.load(Relaxed)
}

pub fn non_vote_transaction_count_since_restart(&self) -> u64 {
self.non_vote_transaction_count_since_restart.load(Relaxed)
}

pub fn transaction_error_count(&self) -> u64 {
self.transaction_error_count.load(Relaxed)
}
Expand All @@ -6605,6 +6639,11 @@ impl Bank {
self.transaction_count.fetch_add(tx_count, Relaxed);
}

fn increment_non_vote_transaction_count_since_restart(&self, tx_count: u64) {
self.non_vote_transaction_count_since_restart
.fetch_add(tx_count, Relaxed);
}

pub fn signature_count(&self) -> u64 {
self.signature_count.load(Relaxed)
}
Expand Down Expand Up @@ -10453,6 +10492,7 @@ pub(crate) mod tests {
bank.transfer(amount * 2, &mint_keypair, &pubkey).unwrap();
assert_eq!(bank.get_balance(&pubkey), amount * 3);
assert_eq!(bank.transaction_count(), 2);
assert_eq!(bank.non_vote_transaction_count_since_restart(), 2);
}

#[test]
Expand Down Expand Up @@ -10577,6 +10617,7 @@ pub(crate) mod tests {
Err(TransactionError::AccountNotFound)
);
assert_eq!(bank.transaction_count(), 0);
assert_eq!(bank.non_vote_transaction_count_since_restart(), 0);
}

#[test]
Expand All @@ -10588,6 +10629,7 @@ pub(crate) mod tests {
let amount = genesis_config.rent.minimum_balance(0);
bank.transfer(amount, &mint_keypair, &pubkey).unwrap();
assert_eq!(bank.transaction_count(), 1);
assert_eq!(bank.non_vote_transaction_count_since_restart(), 1);
assert_eq!(bank.get_balance(&pubkey), amount);
assert_eq!(
bank.transfer((mint_amount - amount) + 1, &mint_keypair, &pubkey),
Expand All @@ -10597,6 +10639,7 @@ pub(crate) mod tests {
))
);
assert_eq!(bank.transaction_count(), 1);
assert_eq!(bank.non_vote_transaction_count_since_restart(), 1);

let mint_pubkey = mint_keypair.pubkey();
assert_eq!(bank.get_balance(&mint_pubkey), mint_amount - amount);
Expand Down Expand Up @@ -11197,6 +11240,7 @@ pub(crate) mod tests {

// Assert bad transactions aren't counted.
assert_eq!(bank.transaction_count(), 1);
assert_eq!(bank.non_vote_transaction_count_since_restart(), 1);
}

#[test]
Expand Down Expand Up @@ -11754,6 +11798,7 @@ pub(crate) mod tests {
assert_eq!(parent.process_transaction(&tx_transfer_mint_to_1), Ok(()));
trace!("done parent process tx ");
assert_eq!(parent.transaction_count(), 1);
assert_eq!(parent.non_vote_transaction_count_since_restart(), 1);
assert_eq!(
parent.get_signature_status(&tx_transfer_mint_to_1.signatures[0]),
Some(Ok(()))
Expand All @@ -11768,11 +11813,17 @@ pub(crate) mod tests {
);

assert_eq!(bank.transaction_count(), parent.transaction_count());
assert_eq!(
bank.non_vote_transaction_count_since_restart(),
parent.non_vote_transaction_count_since_restart()
);
let tx_transfer_1_to_2 =
system_transaction::transfer(&key1, &key2.pubkey(), amount, genesis_config.hash());
assert_eq!(bank.process_transaction(&tx_transfer_1_to_2), Ok(()));
assert_eq!(bank.transaction_count(), 2);
assert_eq!(bank.non_vote_transaction_count_since_restart(), 2);
assert_eq!(parent.transaction_count(), 1);
assert_eq!(parent.non_vote_transaction_count_since_restart(), 1);
assert_eq!(
parent.get_signature_status(&tx_transfer_1_to_2.signatures[0]),
None
Expand All @@ -11798,7 +11849,9 @@ pub(crate) mod tests {
bank.squash();

assert_eq!(parent.transaction_count(), 1);
assert_eq!(parent.non_vote_transaction_count_since_restart(), 1);
assert_eq!(bank.transaction_count(), 2);
assert_eq!(bank.non_vote_transaction_count_since_restart(), 2);
}
}

Expand Down Expand Up @@ -12281,21 +12334,30 @@ pub(crate) mod tests {
);

assert_eq!(bank0.transaction_count(), 0);
assert_eq!(bank0.non_vote_transaction_count_since_restart(), 0);
assert_eq!(bank2.transaction_count(), 0);
assert_eq!(bank2.non_vote_transaction_count_since_restart(), 0);
assert_eq!(bank1.transaction_count(), 1);
assert_eq!(bank1.non_vote_transaction_count_since_restart(), 1);

bank1.squash();

assert_eq!(bank0.transaction_count(), 0);
assert_eq!(bank0.non_vote_transaction_count_since_restart(), 0);
assert_eq!(bank2.transaction_count(), 0);
assert_eq!(bank2.non_vote_transaction_count_since_restart(), 0);
assert_eq!(bank1.transaction_count(), 1);
assert_eq!(bank1.non_vote_transaction_count_since_restart(), 1);

let bank6 = Bank::new_from_parent(&bank1, &solana_sdk::pubkey::new_rand(), 3);
assert_eq!(bank1.transaction_count(), 1);
assert_eq!(bank1.non_vote_transaction_count_since_restart(), 1);
assert_eq!(bank6.transaction_count(), 1);
assert_eq!(bank6.non_vote_transaction_count_since_restart(), 1);

bank6.squash();
assert_eq!(bank6.transaction_count(), 1);
assert_eq!(bank6.non_vote_transaction_count_since_restart(), 1);
}

#[test]
Expand Down

0 comments on commit daa1bd0

Please sign in to comment.