Skip to content

Commit

Permalink
Gather arguments in a single struct
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Mar 7, 2024
1 parent b6f6fdb commit c645b50
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 58 deletions.
5 changes: 2 additions & 3 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use {
solana_svm::{
account_loader::{validate_fee_payer, TransactionCheckResult},
transaction_error_metrics::TransactionErrorMetrics,
transaction_processor::ExecutionRecordingConfig,
},
std::{
sync::{atomic::Ordering, Arc},
Expand Down Expand Up @@ -593,9 +594,7 @@ impl Consumer {
.load_and_execute_transactions(
batch,
MAX_PROCESSING_AGE,
transaction_status_sender_enabled,
transaction_status_sender_enabled,
transaction_status_sender_enabled,
ExecutionRecordingConfig::new_single_setting(transaction_status_sender_enabled),
&mut execute_and_commit_timings.execute_timings,
None, // account_overrides
self.log_messages_bytes_limit,
Expand Down
10 changes: 4 additions & 6 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use {
},
solana_svm::{
runtime_config::RuntimeConfig,
transaction_processor::ExecutionRecordingConfig,
transaction_results::{
TransactionExecutionDetails, TransactionExecutionResult, TransactionResults,
},
Expand Down Expand Up @@ -163,9 +164,7 @@ pub fn execute_batch(
batch,
MAX_PROCESSING_AGE,
transaction_status_sender.is_some(),
transaction_status_sender.is_some(),
transaction_status_sender.is_some(),
transaction_status_sender.is_some(),
ExecutionRecordingConfig::new_single_setting(transaction_status_sender.is_some()),
timings,
log_messages_bytes_limit,
);
Expand Down Expand Up @@ -1972,6 +1971,7 @@ pub mod tests {
system_transaction,
transaction::{Transaction, TransactionError},
},
solana_svm::transaction_processor::ExecutionRecordingConfig,
solana_vote::vote_account::VoteAccount,
solana_vote_program::{
self,
Expand Down Expand Up @@ -3962,9 +3962,7 @@ pub mod tests {
&batch,
MAX_PROCESSING_AGE,
false,
false,
false,
false,
ExecutionRecordingConfig::new_single_setting(false),
&mut ExecuteTimings::default(),
None,
);
Expand Down
37 changes: 16 additions & 21 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ pub struct BankRc {

#[cfg(RUSTC_WITH_SPECIALIZATION)]
use solana_frozen_abi::abi_example::AbiExample;
use solana_svm::transaction_processor::ExecutionRecordingConfig;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl AbiExample for BankRc {
Expand Down Expand Up @@ -4294,9 +4295,11 @@ impl Bank {
// for processing. During forwarding, the transaction could expire if the
// delay is not accounted for.
MAX_PROCESSING_AGE - MAX_TRANSACTION_FORWARDING_DELAY,
enable_cpi_recording,
true,
true,
ExecutionRecordingConfig {
enable_cpi_recording,
enable_log_recording: true,
enable_return_data_recording: true,
},
&mut timings,
Some(&account_overrides),
None,
Expand Down Expand Up @@ -4547,9 +4550,7 @@ impl Bank {
&self,
batch: &TransactionBatch,
max_age: usize,
enable_cpi_recording: bool,
enable_log_recording: bool,
enable_return_data_recording: bool,
recording_config: ExecutionRecordingConfig,
timings: &mut ExecuteTimings,
account_overrides: Option<&AccountOverrides>,
log_messages_bytes_limit: Option<usize>,
Expand Down Expand Up @@ -4613,9 +4614,7 @@ impl Bank {
sanitized_txs,
&mut check_results,
&mut error_counters,
enable_cpi_recording,
enable_log_recording,
enable_return_data_recording,
recording_config,
timings,
account_overrides,
self.builtin_programs.iter(),
Expand Down Expand Up @@ -5641,9 +5640,7 @@ impl Bank {
batch: &TransactionBatch,
max_age: usize,
collect_balances: bool,
enable_cpi_recording: bool,
enable_log_recording: bool,
enable_return_data_recording: bool,
recording_config: ExecutionRecordingConfig,
timings: &mut ExecuteTimings,
log_messages_bytes_limit: Option<usize>,
) -> (TransactionResults, TransactionBalancesSet) {
Expand All @@ -5664,9 +5661,7 @@ impl Bank {
} = self.load_and_execute_transactions(
batch,
max_age,
enable_cpi_recording,
enable_log_recording,
enable_return_data_recording,
recording_config,
timings,
None,
log_messages_bytes_limit,
Expand Down Expand Up @@ -5734,9 +5729,11 @@ impl Bank {
&batch,
MAX_PROCESSING_AGE,
false, // collect_balances
false, // enable_cpi_recording
true, // enable_log_recording
true, // enable_return_data_recording
ExecutionRecordingConfig {
enable_cpi_recording: false,
enable_log_recording: true,
enable_return_data_recording: true,
},
&mut ExecuteTimings::default(),
Some(1000 * 1000),
);
Expand Down Expand Up @@ -5772,9 +5769,7 @@ impl Bank {
batch,
MAX_PROCESSING_AGE,
false,
false,
false,
false,
ExecutionRecordingConfig::new_single_setting(false),
&mut ExecuteTimings::default(),
None,
)
Expand Down
24 changes: 12 additions & 12 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3122,9 +3122,7 @@ fn test_interleaving_locks() {
&lock_result,
MAX_PROCESSING_AGE,
false,
false,
false,
false,
ExecutionRecordingConfig::new_single_setting(false),
&mut ExecuteTimings::default(),
None,
)
Expand Down Expand Up @@ -5948,9 +5946,7 @@ fn test_pre_post_transaction_balances() {
&lock_result,
MAX_PROCESSING_AGE,
true,
false,
false,
false,
ExecutionRecordingConfig::new_single_setting(false),
&mut ExecuteTimings::default(),
None,
);
Expand Down Expand Up @@ -9230,9 +9226,11 @@ fn test_tx_log_order() {
&batch,
MAX_PROCESSING_AGE,
false,
false,
true,
false,
ExecutionRecordingConfig {
enable_cpi_recording: false,
enable_log_recording: true,
enable_return_data_recording: false,
},
&mut ExecuteTimings::default(),
None,
)
Expand Down Expand Up @@ -9338,9 +9336,11 @@ fn test_tx_return_data() {
&batch,
MAX_PROCESSING_AGE,
false,
false,
false,
true,
ExecutionRecordingConfig {
enable_cpi_recording: false,
enable_log_recording: false,
enable_return_data_recording: true,
},
&mut ExecuteTimings::default(),
None,
)
Expand Down
45 changes: 29 additions & 16 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ pub struct LoadAndExecuteSanitizedTransactionsOutput {
pub execution_results: Vec<TransactionExecutionResult>,
}

/// Configuration of the recording capabilities for transaction execution
#[derive(Copy, Clone)]
pub struct ExecutionRecordingConfig {
pub enable_cpi_recording: bool,
pub enable_log_recording: bool,
pub enable_return_data_recording: bool,
}

impl ExecutionRecordingConfig {
pub fn new_single_setting(option: bool) -> Self {
ExecutionRecordingConfig {
enable_return_data_recording: option,
enable_log_recording: option,
enable_cpi_recording: option,
}
}
}

pub trait TransactionProcessingCallback {
fn account_matches_owners(&self, account: &Pubkey, owners: &[Pubkey]) -> Option<usize>;

Expand Down Expand Up @@ -183,9 +201,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
sanitized_txs: &[SanitizedTransaction],
check_results: &mut [TransactionCheckResult],
error_counters: &mut TransactionErrorMetrics,
enable_cpi_recording: bool,
enable_log_recording: bool,
enable_return_data_recording: bool,
recording_config: ExecutionRecordingConfig,
timings: &mut ExecuteTimings,
account_overrides: Option<&AccountOverrides>,
builtin_programs: impl Iterator<Item = &'a Pubkey>,
Expand Down Expand Up @@ -265,9 +281,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
loaded_transaction,
compute_budget,
nonce.as_ref().map(DurableNonceFee::from),
enable_cpi_recording,
enable_log_recording,
enable_return_data_recording,
recording_config,
timings,
error_counters,
log_messages_bytes_limit,
Expand Down Expand Up @@ -465,9 +479,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
loaded_transaction: &mut LoadedTransaction,
compute_budget: ComputeBudget,
durable_nonce_fee: Option<DurableNonceFee>,
enable_cpi_recording: bool,
enable_log_recording: bool,
enable_return_data_recording: bool,
recording_config: ExecutionRecordingConfig,
timings: &mut ExecuteTimings,
error_counters: &mut TransactionErrorMetrics,
log_messages_bytes_limit: Option<usize>,
Expand Down Expand Up @@ -505,7 +517,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
tx.message(),
);

let log_collector = if enable_log_recording {
let log_collector = if recording_config.enable_log_recording {
match log_messages_bytes_limit {
None => Some(LogCollector::new_ref()),
Some(log_messages_bytes_limit) => Some(LogCollector::new_ref_with_limit(Some(
Expand Down Expand Up @@ -584,7 +596,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
.ok()
});

let inner_instructions = if enable_cpi_recording {
let inner_instructions = if recording_config.enable_cpi_recording {
Some(Self::inner_instructions_list_from_instruction_trace(
&transaction_context,
))
Expand Down Expand Up @@ -615,11 +627,12 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
);
saturating_add_assign!(timings.details.changed_account_count, touched_account_count);

let return_data = if enable_return_data_recording && !return_data.data.is_empty() {
Some(return_data)
} else {
None
};
let return_data =
if recording_config.enable_return_data_recording && !return_data.data.is_empty() {
Some(return_data)
} else {
None
};

TransactionExecutionResult::Executed {
details: TransactionExecutionDetails {
Expand Down

0 comments on commit c645b50

Please sign in to comment.