Address review comments

(cherry picked from commit a058f348a2)

# Conflicts:
#	runtime/src/cost_tracker.rs
This commit is contained in:
Christian Kamm
2022-04-08 19:34:11 +02:00
committed by Tao Zhu
parent 55e64910f7
commit 671e9cbac1
5 changed files with 77 additions and 68 deletions

View File

@ -1330,34 +1330,22 @@ impl BankingStage {
gossip_vote_sender: &ReplayVoteSender,
qos_service: &Arc<QosService>,
) -> ProcessTransactionBatchOutput {
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 mut cost_model_time = Measure::start("cost_model");
let (transactions_qos_results, num_included) =
qos_service.select_transactions_per_cost(txs.iter(), tx_costs.iter(), bank);
let transaction_costs = qos_service.compute_transaction_costs(txs.iter());
let cost_model_throttled_transactions_count =
txs.len().saturating_sub(num_included);
let (transactions_qos_results, num_included) =
qos_service.select_transactions_per_cost(txs.iter(), transaction_costs.iter(), bank);
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",
let cost_model_throttled_transactions_count = txs.len().saturating_sub(num_included);
qos_service.accumulate_estimated_transaction_costs(
&Self::accumulate_batched_transaction_costs(
transaction_costs.iter(),
transactions_qos_results.iter(),
),
);
cost_model_time.stop();
// Only lock accounts for those transactions are selected for the block;
// Once accounts are locked, other threads cannot encode transactions that will modify the
@ -1389,6 +1377,9 @@ impl BankingStage {
..
} = execute_and_commit_transactions_output;
// TODO: This does not revert the cost tracker changes from all unexecuted transactions
// yet: For example tx that are too old will not be included in the block, but are not
// retryable.
QosService::update_or_remove_transaction_costs(
transaction_costs.iter(),
transactions_qos_results.iter(),

View File

@ -118,7 +118,7 @@ impl QosService {
let mut num_included = 0;
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(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);
@ -172,8 +172,10 @@ impl QosService {
transaction_costs
.zip(transaction_qos_results)
.enumerate()
.for_each(|(index, (tx_cost, qos_result))| {
if qos_result.is_ok() && retryable_transaction_indexes.contains(&index) {
.for_each(|(index, (tx_cost, qos_inclusion_result))| {
// Only transactions that the qos service incuded have been added to the
// cost tracker.
if qos_inclusion_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.