Skip to content

Commit

Permalink
break out of loop after 100ms
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Apr 19, 2024
1 parent 5ec0886 commit 241be0f
Showing 1 changed file with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use {
solana_program_runtime::compute_budget_processor::process_compute_budget_instructions,
solana_runtime::{bank::Bank, bank_forks::BankForks},
solana_sdk::{
clock::MAX_PROCESSING_AGE,
clock::{FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET, MAX_PROCESSING_AGE},
feature_set::{
include_loaded_accounts_data_size_in_fee_calculation,
remove_rounding_in_fee_calculation,
Expand All @@ -40,7 +40,7 @@ use {
solana_svm::transaction_error_metrics::TransactionErrorMetrics,
std::{
sync::{Arc, RwLock},
time::Duration,
time::{Duration, Instant},
},
};

Expand Down Expand Up @@ -159,7 +159,12 @@ impl SchedulerController {
let (scheduling_summary, schedule_time_us) = measure_us!(self.scheduler.schedule(
&mut self.container,
|txs, results| {
Self::pre_graph_filter(txs, results, &bank_start.working_bank)
Self::pre_graph_filter(
txs,
results,
&bank_start.working_bank,
MAX_PROCESSING_AGE,
)
},
|_| true // no pre-lock filter for now
)?);
Expand Down Expand Up @@ -205,15 +210,16 @@ impl SchedulerController {
Ok(())
}

fn pre_graph_filter(transactions: &[&SanitizedTransaction], results: &mut [bool], bank: &Bank) {
fn pre_graph_filter(
transactions: &[&SanitizedTransaction],
results: &mut [bool],
bank: &Bank,
max_age: usize,
) {
let lock_results = vec![Ok(()); transactions.len()];
let mut error_counters = TransactionErrorMetrics::default();
let check_results = bank.check_transactions(
transactions,
&lock_results,
MAX_PROCESSING_AGE,
&mut error_counters,
);
let check_results =
bank.check_transactions(transactions, &lock_results, max_age, &mut error_counters);

let fee_check_results: Vec<_> = check_results
.into_iter()
Expand All @@ -231,6 +237,8 @@ impl SchedulerController {

/// Forward packets to the next leader.
fn forward_packets(&mut self, hold: bool) {
const MAX_FORWARDING_DURATION: Duration = Duration::from_millis(100);
let start = Instant::now();
let bank = self.bank_forks.read().unwrap().working_bank();
let feature_set = &bank.feature_set;
let mut forwardable_packets =
Expand Down Expand Up @@ -260,7 +268,13 @@ impl SchedulerController {

// use same filter we use for processing transactions:
// age, already processed, fee-check.
Self::pre_graph_filter(&txs, &mut filter_array, &bank);
Self::pre_graph_filter(
&txs,
&mut filter_array,
&bank,
MAX_PROCESSING_AGE
.saturating_sub(FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET as usize),
);

for (id, filter_result) in ids.iter().zip(&filter_array[..chunk_size]) {
if !*filter_result || !hold {
Expand All @@ -284,6 +298,10 @@ impl SchedulerController {
state.mark_forwarded();
}
}

if start.elapsed() >= MAX_FORWARDING_DURATION {
break;
}
}

// Push into worker queue.
Expand Down

0 comments on commit 241be0f

Please sign in to comment.