Revert "Count compute units even when transaction errors (#22059)" (#22174)

This reverts commit eaa8c67bde.
This commit is contained in:
carllin
2021-12-30 02:42:32 -05:00
committed by GitHub
parent 135af08b8b
commit 33d0b5e011
13 changed files with 97 additions and 295 deletions

View File

@ -25,7 +25,7 @@ use {
TransactionExecutionResult,
},
bank_utils,
cost_model::{CostModel, ExecutionCost},
cost_model::CostModel,
transaction_batch::TransactionBatch,
vote_sender_types::ReplayVoteSender,
},
@ -974,20 +974,14 @@ impl BankingStage {
let tx_costs = qos_service.compute_transaction_costs(txs.iter());
let transactions_qos_results =
qos_service.select_transactions_per_cost(txs.iter(), tx_costs.into_iter(), bank);
qos_service.select_transactions_per_cost(txs.iter(), tx_costs.iter(), bank);
// Only lock accounts for those transactions are selected for the block;
// Once accounts are locked, other threads cannot encode transactions that will modify the
// same account state
let mut lock_time = Measure::start("lock_time");
let batch = bank.prepare_sanitized_batch_with_results(
txs,
transactions_qos_results
.into_iter()
.map(|transaction_cost_result| {
transaction_cost_result.map(|transaction_cost| transaction_cost.execution_cost)
}),
);
let batch =
bank.prepare_sanitized_batch_with_results(txs, transactions_qos_results.into_iter());
lock_time.stop();
// retryable_txs includes AccountInUse, WouldExceedMaxBlockCostLimit
@ -1087,9 +1081,9 @@ impl BankingStage {
fn prepare_filter_for_pending_transactions(
transactions_len: usize,
pending_tx_indexes: &[usize],
) -> Vec<transaction::Result<ExecutionCost>> {
) -> Vec<transaction::Result<()>> {
let mut mask = vec![Err(TransactionError::BlockhashNotFound); transactions_len];
pending_tx_indexes.iter().for_each(|x| mask[*x] = Ok(0));
pending_tx_indexes.iter().for_each(|x| mask[*x] = Ok(()));
mask
}
@ -1180,7 +1174,7 @@ impl BankingStage {
let results = bank.check_transactions(
transactions,
filter.into_iter(),
&filter,
(MAX_PROCESSING_AGE)
.saturating_sub(max_tx_fwd_delay)
.saturating_sub(FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET as usize),
@ -1985,20 +1979,20 @@ mod tests {
vec![
Err(TransactionError::BlockhashNotFound),
Err(TransactionError::BlockhashNotFound),
Ok(0),
Ok(()),
Err(TransactionError::BlockhashNotFound),
Ok(0),
Ok(0)
Ok(()),
Ok(())
]
);
assert_eq!(
BankingStage::prepare_filter_for_pending_transactions(6, &[0, 2, 3]),
vec![
Ok(0),
Ok(()),
Err(TransactionError::BlockhashNotFound),
Ok(0),
Ok(0),
Ok(()),
Ok(()),
Err(TransactionError::BlockhashNotFound),
Err(TransactionError::BlockhashNotFound),
]
@ -2012,10 +2006,10 @@ mod tests {
&[
(Err(TransactionError::BlockhashNotFound), None),
(Err(TransactionError::BlockhashNotFound), None),
(Ok(0), None),
(Ok(()), None),
(Err(TransactionError::BlockhashNotFound), None),
(Ok(0), None),
(Ok(0), None),
(Ok(()), None),
(Ok(()), None),
],
&[2, 4, 5, 9, 11, 13]
),
@ -2025,12 +2019,12 @@ mod tests {
assert_eq!(
BankingStage::filter_valid_transaction_indexes(
&[
(Ok(0), None),
(Ok(()), None),
(Err(TransactionError::BlockhashNotFound), None),
(Err(TransactionError::BlockhashNotFound), None),
(Ok(0), None),
(Ok(0), None),
(Ok(0), None),
(Ok(()), None),
(Ok(()), None),
(Ok(()), None),
],
&[1, 6, 7, 9, 31, 43]
),

View File

@ -246,7 +246,6 @@ mod tests {
ProgramTiming {
accumulated_us,
accumulated_units,
current_cost_model_estimated_units: 0,
count,
},
);
@ -282,7 +281,6 @@ mod tests {
ProgramTiming {
accumulated_us,
accumulated_units,
current_cost_model_estimated_units: 0,
count,
},
);

View File

@ -117,18 +117,18 @@ impl QosService {
pub fn select_transactions_per_cost<'a>(
&self,
transactions: impl Iterator<Item = &'a SanitizedTransaction>,
transactions_costs: impl Iterator<Item = TransactionCost>,
transactions_costs: impl Iterator<Item = &'a TransactionCost>,
bank: &Arc<Bank>,
) -> Vec<transaction::Result<TransactionCost>> {
) -> Vec<transaction::Result<()>> {
let mut cost_tracking_time = Measure::start("cost_tracking_time");
let mut cost_tracker = bank.write_cost_tracker().unwrap();
let select_results = transactions
.zip(transactions_costs)
.map(|(tx, cost)| match cost_tracker.try_add(tx, &cost) {
.map(|(tx, cost)| match cost_tracker.try_add(tx, cost) {
Ok(current_block_cost) => {
debug!("slot {:?}, transaction {:?}, cost {:?}, fit into current block, current block cost {}", bank.slot(), tx, cost, current_block_cost);
self.metrics.selected_txs_count.fetch_add(1, Ordering::Relaxed);
Ok(cost)
Ok(())
},
Err(e) => {
debug!("slot {:?}, transaction {:?}, cost {:?}, not fit into current block, '{:?}'", bank.slot(), tx, cost, e);
@ -441,8 +441,7 @@ mod tests {
bank.write_cost_tracker()
.unwrap()
.set_limits(cost_limit, cost_limit);
let results =
qos_service.select_transactions_per_cost(txs.iter(), txs_costs.into_iter(), &bank);
let results = qos_service.select_transactions_per_cost(txs.iter(), txs_costs.iter(), &bank);
// verify that first transfer tx and all votes are allowed
assert_eq!(results.len(), txs.len());