updates to address review feedback
This commit is contained in:
@ -312,57 +312,50 @@ fn execute_batches(
|
|||||||
|
|
||||||
let cost_model = CostModel::new();
|
let cost_model = CostModel::new();
|
||||||
let mut minimal_tx_cost = u64::MAX;
|
let mut minimal_tx_cost = u64::MAX;
|
||||||
let total_cost: u64 = sanitized_txs
|
let mut total_cost: u64 = 0;
|
||||||
|
let tx_costs = sanitized_txs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|tx| {
|
.map(|tx| {
|
||||||
let cost = cost_model.calculate_cost(tx).sum();
|
let cost = cost_model.calculate_cost(tx).sum();
|
||||||
minimal_tx_cost = std::cmp::min(minimal_tx_cost, cost);
|
minimal_tx_cost = std::cmp::min(minimal_tx_cost, cost);
|
||||||
|
total_cost = total_cost.saturating_add(cost);
|
||||||
cost
|
cost
|
||||||
})
|
})
|
||||||
.sum();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let target_batch_count = get_thread_count() as u64;
|
let target_batch_count = get_thread_count() as u64;
|
||||||
|
|
||||||
if total_cost > target_batch_count.saturating_mul(minimal_tx_cost) {
|
let mut tx_batches: Vec<TransactionBatch> = vec![];
|
||||||
|
let rebatched_txs = if total_cost > target_batch_count.saturating_mul(minimal_tx_cost) {
|
||||||
let target_batch_cost = total_cost / target_batch_count;
|
let target_batch_cost = total_cost / target_batch_count;
|
||||||
let mut batch_cost = 0;
|
let mut batch_cost: u64 = 0;
|
||||||
let mut index = 0;
|
let mut slice_start = 0;
|
||||||
let mut tx_batches: Vec<TransactionBatch> = vec![];
|
tx_costs.into_iter().enumerate().for_each(|(index, cost)| {
|
||||||
let mut slice_range = 0..0;
|
let next_index = index + 1;
|
||||||
while index < sanitized_txs.len() {
|
batch_cost = batch_cost.saturating_add(cost);
|
||||||
batch_cost += cost_model.calculate_cost(&sanitized_txs[index]).sum();
|
if batch_cost >= target_batch_cost || next_index == sanitized_txs.len() {
|
||||||
index += 1;
|
let txs = &sanitized_txs[slice_start..=index];
|
||||||
if batch_cost >= target_batch_cost || sanitized_txs.len() == index {
|
let results = &lock_results[slice_start..=index];
|
||||||
slice_range.end = index;
|
|
||||||
let txs = &sanitized_txs[slice_range.clone()];
|
|
||||||
let results = &lock_results[slice_range.clone()];
|
|
||||||
let tx_batch = TransactionBatch::new(results.to_vec(), bank, Cow::from(txs));
|
let tx_batch = TransactionBatch::new(results.to_vec(), bank, Cow::from(txs));
|
||||||
slice_range.start = index;
|
slice_start = next_index;
|
||||||
tx_batches.push(tx_batch);
|
tx_batches.push(tx_batch);
|
||||||
batch_cost = 0;
|
batch_cost = 0;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
&tx_batches[..]
|
||||||
execute_batches_internal(
|
|
||||||
bank,
|
|
||||||
&tx_batches,
|
|
||||||
entry_callback,
|
|
||||||
transaction_status_sender,
|
|
||||||
replay_vote_sender,
|
|
||||||
timings,
|
|
||||||
cost_capacity_meter,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
execute_batches_internal(
|
batches
|
||||||
bank,
|
};
|
||||||
batches,
|
|
||||||
entry_callback,
|
execute_batches_internal(
|
||||||
transaction_status_sender,
|
bank,
|
||||||
replay_vote_sender,
|
rebatched_txs,
|
||||||
timings,
|
entry_callback,
|
||||||
cost_capacity_meter,
|
transaction_status_sender,
|
||||||
)
|
replay_vote_sender,
|
||||||
}
|
timings,
|
||||||
|
cost_capacity_meter,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process an ordered list of entries in parallel
|
/// Process an ordered list of entries in parallel
|
||||||
|
Reference in New Issue
Block a user