From f4d721175334c32f9ae02f1bb7120e3e1eee2483 Mon Sep 17 00:00:00 2001 From: Stephen Akridge Date: Thu, 21 Oct 2021 13:45:14 +0000 Subject: [PATCH] Don't commit failed out-dated votes --- core/src/banking_stage.rs | 6 +++- rpc/src/transaction_status_service.rs | 2 +- runtime/src/bank.rs | 40 +++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 5134ded31dd719..08a58269bbc1e8 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -788,13 +788,14 @@ impl BankingStage { results: &[TransactionExecutionResult], recorder: &TransactionRecorder, ) -> (Result, Vec) { + let mut dropped_vote_count = 0; let mut processed_generation = Measure::start("record::process_generation"); let (processed_transactions, processed_transactions_indexes): (Vec<_>, Vec<_>) = results .iter() .zip(txs) .enumerate() .filter_map(|(i, ((r, _n), tx))| { - if Bank::can_commit(r) { + if Bank::can_commit(tx.message(), r, true, &mut dropped_vote_count) { Some((tx.to_versioned_transaction(), i)) } else { None @@ -802,6 +803,9 @@ impl BankingStage { }) .unzip(); + if dropped_vote_count > 0 { + inc_new_counter_info!("leader-dropped_vote", dropped_vote_count); + } processed_generation.stop(); let num_to_commit = processed_transactions.len(); debug!("num_to_commit: {} ", num_to_commit); diff --git a/rpc/src/transaction_status_service.rs b/rpc/src/transaction_status_service.rs index 9a12690237a722..cecff836567ebd 100644 --- a/rpc/src/transaction_status_service.rs +++ b/rpc/src/transaction_status_service.rs @@ -102,7 +102,7 @@ impl TransactionStatusService { transaction_logs_iter, rent_debits, ) { - if Bank::can_commit(&status) { + if Bank::can_commit(transaction.message(), &status, false, &mut 0usize) { let lamports_per_signature = nonce_rollback .map(|nonce_rollback| nonce_rollback.lamports_per_signature()) .unwrap_or_else(|| { diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 7115a61b8fd2f3..6f7431e684b38c 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -3177,10 +3177,37 @@ impl Bank { .clear_slot_entries(slot); } - pub fn can_commit(result: &Result<()>) -> bool { + pub fn can_commit( + message: &solana_sdk::message::SanitizedMessage, + result: &Result<()>, + from_block_producer: bool, + dropped_vote_count: &mut usize, + ) -> bool { match result { Ok(_) => true, - Err(TransactionError::InstructionError(_, _)) => true, + Err(TransactionError::InstructionError(error_index, error)) => { + if from_block_producer + && solana_vote_program::check_id( + message.get_account_key(*error_index as usize).unwrap(), + ) + { + match error { + InstructionError::Custom(error_code) => { + let vote_too_old_err: u32 = + solana_vote_program::vote_instruction::VoteError::VoteTooOld as u32; + if vote_too_old_err != *error_code { + *dropped_vote_count += 1; + true + } else { + false + } + } + _ => true, + } + } else { + true + } + } Err(_) => false, } } @@ -3193,7 +3220,7 @@ impl Bank { let mut status_cache = self.src.status_cache.write().unwrap(); assert_eq!(sanitized_txs.len(), res.len()); for (tx, (res, _nonce_rollback)) in sanitized_txs.iter().zip(res) { - if Self::can_commit(res) { + if Self::can_commit(tx.message(), res, false, &mut 0usize) { // Add the message hash to the status cache to ensure that this message // won't be processed again with a different signature. status_cache.insert( @@ -3932,7 +3959,7 @@ impl Bank { } } - if Self::can_commit(r) // Skip log collection for unprocessed transactions + if Self::can_commit(tx.message(), r, false, &mut 0usize) // Skip log collection for unprocessed transactions && transaction_log_collector_config.filter != TransactionLogCollectorFilter::None { let mut transaction_log_collector = self.transaction_log_collector.write().unwrap(); @@ -4106,7 +4133,10 @@ impl Bank { if executed .iter() - .any(|(res, _nonce_rollback)| Self::can_commit(res)) + .zip(sanitized_txs.iter()) + .any(|((res, _nonce_rollback), tx)| { + Self::can_commit(tx.message(), res, false, &mut 0usize) + }) { self.is_delta.store(true, Relaxed); }