Adjustments to cost_tracker updates

- don't store pending tx signatures and costs in CostTracker
- apply tx costs to global state immediately again
- go from commit_or_cancel to update_or_remove, where the cost tracker
  is either updated with the true costs for successful tx, or the costs
  of a retryable tx is removed
- move the function into qos_service and hold the cost tracker lock for
  the whole loop

(cherry picked from commit 924b8ea1eb)

# Conflicts:
#	core/src/qos_service.rs
#	runtime/src/cost_tracker.rs
This commit is contained in:
Christian Kamm
2022-04-08 14:22:31 +02:00
committed by Tao Zhu
parent 6cb6b9206f
commit 9ae13f26e5
3 changed files with 116 additions and 83 deletions

View File

@ -1330,31 +1330,34 @@ impl BankingStage {
gossip_vote_sender: &ReplayVoteSender,
qos_service: &Arc<QosService>,
) -> ProcessTransactionBatchOutput {
let ((transactions_qos_results, cost_model_throttled_transactions_count), cost_model_time) =
Measure::this(
|_| {
let tx_costs = qos_service.compute_transaction_costs(txs.iter());
let (
(transactions_qos_results, cost_model_throttled_transactions_count, transaction_costs),
cost_model_time,
) = Measure::this(
|_| {
let tx_costs = qos_service.compute_transaction_costs(txs.iter());
let (transactions_qos_results, num_included) =
qos_service.select_transactions_per_cost(txs.iter(), tx_costs.iter(), bank);
let (transactions_qos_results, num_included) =
qos_service.select_transactions_per_cost(txs.iter(), tx_costs.iter(), bank);
let cost_model_throttled_transactions_count =
txs.len().saturating_sub(num_included);
let cost_model_throttled_transactions_count =
txs.len().saturating_sub(num_included);
qos_service.accumulate_estimated_transaction_costs(
&Self::accumulate_batched_transaction_costs(
tx_costs.iter(),
transactions_qos_results.iter(),
),
);
(
transactions_qos_results,
cost_model_throttled_transactions_count,
)
},
(),
"cost_model",
);
qos_service.accumulate_estimated_transaction_costs(
&Self::accumulate_batched_transaction_costs(
tx_costs.iter(),
transactions_qos_results.iter(),
),
);
(
transactions_qos_results,
cost_model_throttled_transactions_count,
tx_costs,
)
},
(),
"cost_model",
);
// Only lock accounts for those transactions are selected for the block;
// Once accounts are locked, other threads cannot encode transactions that will modify the
@ -1386,11 +1389,10 @@ impl BankingStage {
..
} = execute_and_commit_transactions_output;
Self::commit_or_cancel_transaction_cost(
txs.iter(),
QosService::update_or_remove_transaction_costs(
transaction_costs.iter(),
transactions_qos_results.iter(),
retryable_transaction_indexes,
qos_service,
bank,
);
@ -1418,30 +1420,6 @@ impl BankingStage {
}
}
/// To commit transaction cost to cost_tracker if it was executed successfully;
/// Otherwise cancel it from being committed, therefore prevents cost_tracker
/// being inflated with unsuccessfully executed transactions.
fn commit_or_cancel_transaction_cost<'a>(
transactions: impl Iterator<Item = &'a SanitizedTransaction>,
transaction_results: impl Iterator<Item = &'a transaction::Result<()>>,
retryable_transaction_indexes: &[usize],
qos_service: &QosService,
bank: &Arc<Bank>,
) {
transactions
.zip(transaction_results)
.enumerate()
.for_each(|(index, (tx, result))| {
if result.is_ok() && retryable_transaction_indexes.contains(&index) {
qos_service.cancel_transaction_cost(bank, tx);
} else {
// TODO the 3rd param is for transaction's actual units. Will have
// to plumb it in next; For now, it simply commit estimated units.
qos_service.commit_transaction_cost(bank, tx, None);
}
});
}
// rollup transaction cost details, eg signature_cost, write_lock_cost, data_bytes_cost and
// execution_cost from the batch of transactions selected for block.
fn accumulate_batched_transaction_costs<'a>(

View File

@ -151,23 +151,38 @@ impl QosService {
(select_results, num_included)
}
<<<<<<< HEAD
<<<<<<< HEAD
=======
pub fn commit_transaction_cost(
&self,
=======
/// Update the transaction cost in the cost_tracker with the real cost for
/// transactions that were executed successfully;
/// Otherwise remove the cost from the cost tracker, therefore preventing cost_tracker
/// being inflated with unsuccessfully executed transactions.
pub fn update_or_remove_transaction_costs<'a>(
transaction_costs: impl Iterator<Item = &'a TransactionCost>,
transaction_qos_results: impl Iterator<Item = &'a transaction::Result<()>>,
retryable_transaction_indexes: &[usize],
>>>>>>> 924b8ea1e (Adjustments to cost_tracker updates)
bank: &Arc<Bank>,
transaction: &SanitizedTransaction,
actual_units: Option<u64>,
) {
bank.write_cost_tracker()
.unwrap()
.commit_transaction(transaction, actual_units);
}
pub fn cancel_transaction_cost(&self, bank: &Arc<Bank>, transaction: &SanitizedTransaction) {
bank.write_cost_tracker()
.unwrap()
.cancel_transaction(transaction);
let mut cost_tracker = bank.write_cost_tracker().unwrap();
transaction_costs
.zip(transaction_qos_results)
.enumerate()
.for_each(|(index, (tx_cost, qos_result))| {
if qos_result.is_ok() && retryable_transaction_indexes.contains(&index) {
cost_tracker.remove(tx_cost);
} else {
// TODO: Update the cost tracker with the actual execution compute units.
// Will have to plumb it in next; For now, keep estimated costs.
//
// let actual_execution_cost = 0;
// cost_tracker.update_execution_cost(tx_cost, actual_execution_cost);
}
});
}
// metrics are reported by bank slot