Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Move counter and logging code back to load_and_execute_transactions() (
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 authored Jan 25, 2024
1 parent 22500c2 commit 1e68ba5
Showing 1 changed file with 120 additions and 131 deletions.
251 changes: 120 additions & 131 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,6 @@ pub struct LoadAndExecuteSanitizedTransactionsOutput {
// Vector of results indicating whether a transaction was executed or could not
// be executed. Note executed transactions can still have failed!
pub execution_results: Vec<TransactionExecutionResult>,
// 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,
pub signature_count: u64,
}

pub struct TransactionSimulationResult {
Expand Down Expand Up @@ -5187,16 +5179,130 @@ impl Bank {
account_overrides,
log_messages_bytes_limit,
);

let mut signature_count = 0;

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 =
self.transaction_log_collector_config.read().unwrap();

let mut collect_logs_time = Measure::start("collect_logs_time");
for (execution_result, tx) in sanitized_output.execution_results.iter().zip(sanitized_txs) {
if let Some(debug_keys) = &self.transaction_debug_keys {
for key in tx.message().account_keys().iter() {
if debug_keys.contains(key) {
let result = execution_result.flattened_result();
info!("slot: {} result: {:?} tx: {:?}", self.slot, result, tx);
break;
}
}
}

let is_vote = tx.is_simple_vote_transaction();

if execution_result.was_executed() // Skip log collection for unprocessed transactions
&& transaction_log_collector_config.filter != TransactionLogCollectorFilter::None
{
let mut filtered_mentioned_addresses = Vec::new();
if !transaction_log_collector_config
.mentioned_addresses
.is_empty()
{
for key in tx.message().account_keys().iter() {
if transaction_log_collector_config
.mentioned_addresses
.contains(key)
{
filtered_mentioned_addresses.push(*key);
}
}
}

let store = match transaction_log_collector_config.filter {
TransactionLogCollectorFilter::All => {
!is_vote || !filtered_mentioned_addresses.is_empty()
}
TransactionLogCollectorFilter::AllWithVotes => true,
TransactionLogCollectorFilter::None => false,
TransactionLogCollectorFilter::OnlyMentionedAddresses => {
!filtered_mentioned_addresses.is_empty()
}
};

if store {
if let Some(TransactionExecutionDetails {
status,
log_messages: Some(log_messages),
..
}) = execution_result.details()
{
let mut transaction_log_collector =
self.transaction_log_collector.write().unwrap();
let transaction_log_index = transaction_log_collector.logs.len();

transaction_log_collector.logs.push(TransactionLogInfo {
signature: *tx.signature(),
result: status.clone(),
is_vote,
log_messages: log_messages.clone(),
});
for key in filtered_mentioned_addresses.into_iter() {
transaction_log_collector
.mentioned_address_map
.entry(key)
.or_default()
.push(transaction_log_index);
}
}
}
}

if execution_result.was_executed() {
// Signature count must be accumulated only if the transaction
// is executed, otherwise a mismatched count between banking and
// replay could occur
signature_count += u64::from(tx.message().header().num_required_signatures);
executed_transactions_count += 1;
}

match execution_result.flattened_result() {
Ok(()) => {
if !is_vote {
executed_non_vote_transactions_count += 1;
}
executed_with_successful_result_count += 1;
}
Err(err) => {
if *err_count == 0 {
debug!("tx error: {:?} {:?}", err, tx);
}
*err_count += 1;
}
}
}
collect_logs_time.stop();
timings
.saturating_add_in_place(ExecuteTimingType::CollectLogsUs, collect_logs_time.as_us());

if *err_count > 0 {
debug!(
"{} errors of {} txs",
*err_count,
*err_count + executed_with_successful_result_count
);
}

LoadAndExecuteTransactionsOutput {
loaded_transactions: sanitized_output.loaded_transactions,
execution_results: sanitized_output.execution_results,
retryable_transaction_indexes,
executed_transactions_count: sanitized_output.executed_transactions_count,
executed_non_vote_transactions_count: sanitized_output
.executed_non_vote_transactions_count,
executed_with_successful_result_count: sanitized_output
.executed_with_successful_result_count,
signature_count: sanitized_output.signature_count,
executed_transactions_count,
executed_non_vote_transactions_count,
executed_with_successful_result_count,
signature_count,
error_counters,
}
}
Expand Down Expand Up @@ -5250,7 +5356,6 @@ impl Bank {
load_time.stop();

let mut execution_time = Measure::start("execution_time");
let mut signature_count: u64 = 0;

let execution_results: Vec<TransactionExecutionResult> = loaded_transactions
.iter_mut()
Expand Down Expand Up @@ -5334,125 +5439,9 @@ impl Bank {
timings.saturating_add_in_place(ExecuteTimingType::LoadUs, load_time.as_us());
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 =
self.transaction_log_collector_config.read().unwrap();

let mut collect_logs_time = Measure::start("collect_logs_time");
for (execution_result, tx) in execution_results.iter().zip(sanitized_txs) {
if let Some(debug_keys) = &self.transaction_debug_keys {
for key in tx.message().account_keys().iter() {
if debug_keys.contains(key) {
let result = execution_result.flattened_result();
info!("slot: {} result: {:?} tx: {:?}", self.slot, result, tx);
break;
}
}
}

let is_vote = tx.is_simple_vote_transaction();

if execution_result.was_executed() // Skip log collection for unprocessed transactions
&& transaction_log_collector_config.filter != TransactionLogCollectorFilter::None
{
let mut filtered_mentioned_addresses = Vec::new();
if !transaction_log_collector_config
.mentioned_addresses
.is_empty()
{
for key in tx.message().account_keys().iter() {
if transaction_log_collector_config
.mentioned_addresses
.contains(key)
{
filtered_mentioned_addresses.push(*key);
}
}
}

let store = match transaction_log_collector_config.filter {
TransactionLogCollectorFilter::All => {
!is_vote || !filtered_mentioned_addresses.is_empty()
}
TransactionLogCollectorFilter::AllWithVotes => true,
TransactionLogCollectorFilter::None => false,
TransactionLogCollectorFilter::OnlyMentionedAddresses => {
!filtered_mentioned_addresses.is_empty()
}
};

if store {
if let Some(TransactionExecutionDetails {
status,
log_messages: Some(log_messages),
..
}) = execution_result.details()
{
let mut transaction_log_collector =
self.transaction_log_collector.write().unwrap();
let transaction_log_index = transaction_log_collector.logs.len();

transaction_log_collector.logs.push(TransactionLogInfo {
signature: *tx.signature(),
result: status.clone(),
is_vote,
log_messages: log_messages.clone(),
});
for key in filtered_mentioned_addresses.into_iter() {
transaction_log_collector
.mentioned_address_map
.entry(key)
.or_default()
.push(transaction_log_index);
}
}
}
}

if execution_result.was_executed() {
// Signature count must be accumulated only if the transaction
// is executed, otherwise a mismatched count between banking and
// replay could occur
signature_count += u64::from(tx.message().header().num_required_signatures);
executed_transactions_count += 1;
}

match execution_result.flattened_result() {
Ok(()) => {
if !is_vote {
executed_non_vote_transactions_count += 1;
}
executed_with_successful_result_count += 1;
}
Err(err) => {
if *err_count == 0 {
debug!("tx error: {:?} {:?}", err, tx);
}
*err_count += 1;
}
}
}
collect_logs_time.stop();
timings
.saturating_add_in_place(ExecuteTimingType::CollectLogsUs, collect_logs_time.as_us());

if *err_count > 0 {
debug!(
"{} errors of {} txs",
*err_count,
*err_count + executed_with_successful_result_count
);
}
LoadAndExecuteSanitizedTransactionsOutput {
loaded_transactions,
execution_results,
executed_transactions_count,
executed_non_vote_transactions_count,
executed_with_successful_result_count,
signature_count,
}
}

Expand Down

0 comments on commit 1e68ba5

Please sign in to comment.