Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic cost_model #3036

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,14 @@ mod tests {
}
};

let mut cost = CostModel::calculate_cost(&transactions[0], &bank.feature_set);
let is_simple_vote_transaction = transactions[0].is_simple_vote_transaction();
let signature_count_detail = transactions[0].message().get_signature_details();
let mut cost = CostModel::calculate_cost(
&transactions[0],
is_simple_vote_transaction,
&signature_count_detail,
&bank.feature_set,
);
if let TransactionCost::Transaction(ref mut usage_cost) = cost {
usage_cost.programs_execution_cost = actual_programs_execution_cost;
usage_cost.loaded_accounts_data_size_cost =
Expand Down
18 changes: 16 additions & 2 deletions core/src/banking_stage/forward_packet_batches_by_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ impl ForwardPacketBatchesByAccounts {
immutable_packet: Arc<ImmutableDeserializedPacket>,
feature_set: &FeatureSet,
) -> bool {
let tx_cost = CostModel::calculate_cost(sanitized_transaction, feature_set);
let is_simple_vote_tx = sanitized_transaction.is_simple_vote_transaction();
let signature_count_detail = sanitized_transaction.message().get_signature_details();
let tx_cost = CostModel::calculate_cost(
sanitized_transaction,
is_simple_vote_tx,
&signature_count_detail,
feature_set,
);

if let Ok(updated_costs) = self.cost_tracker.try_add(&tx_cost) {
let batch_index = self.get_batch_index_by_updated_costs(&tx_cost, &updated_costs);
Expand Down Expand Up @@ -195,7 +202,14 @@ mod tests {
));
let sanitized_transaction =
SanitizedTransaction::from_transaction_for_tests(transaction.clone());
let tx_cost = CostModel::calculate_cost(&sanitized_transaction, &FeatureSet::all_enabled());
let is_simple_vote_transaction = sanitized_transaction.is_simple_vote_transaction();
let signature_count_detail = sanitized_transaction.message().get_signature_details();
let tx_cost = CostModel::calculate_cost(
&sanitized_transaction,
is_simple_vote_transaction,
&signature_count_detail,
&FeatureSet::all_enabled(),
);
let cost = tx_cost.sum();
let deserialized_packet =
DeserializedPacket::new(Packet::from_data(None, transaction).unwrap()).unwrap();
Expand Down
50 changes: 45 additions & 5 deletions core/src/banking_stage/qos_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,18 @@ impl QosService {
let mut compute_cost_time = Measure::start("compute_cost_time");
let txs_costs: Vec<_> = transactions
.zip(pre_results)
.map(|(tx, pre_result)| pre_result.map(|()| CostModel::calculate_cost(tx, feature_set)))
.map(|(tx, pre_result)| {
pre_result.map(|()| {
let is_simple_vote_tx = tx.is_simple_vote_transaction();
let signature_count_details = tx.message().get_signature_details();
CostModel::calculate_cost(
tx,
is_simple_vote_tx,
&signature_count_details,
feature_set,
)
})
})
.collect();
compute_cost_time.stop();
self.metrics
Expand Down Expand Up @@ -654,9 +665,17 @@ mod tests {
.iter()
.enumerate()
.map(|(index, cost)| {
let is_simple_vote_transaction = txs[index].is_simple_vote_transaction();
let signature_count_details = txs[index].message().get_signature_details();
assert_eq!(
cost.as_ref().unwrap().sum(),
CostModel::calculate_cost(&txs[index], &FeatureSet::all_enabled()).sum()
CostModel::calculate_cost(
&txs[index],
is_simple_vote_transaction,
&signature_count_details,
&FeatureSet::all_enabled()
)
.sum()
);
})
.collect_vec();
Expand All @@ -682,9 +701,30 @@ mod tests {
None,
),
);
let transfer_tx_cost =
CostModel::calculate_cost(&transfer_tx, &FeatureSet::all_enabled()).sum();
let vote_tx_cost = CostModel::calculate_cost(&vote_tx, &FeatureSet::all_enabled()).sum();

let transfer_tx_cost = {
let is_simple_vote_transaction = transfer_tx.is_simple_vote_transaction();
let signature_count_detail = transfer_tx.message().get_signature_details();
CostModel::calculate_cost(
&transfer_tx,
is_simple_vote_transaction,
&signature_count_detail,
&FeatureSet::all_enabled(),
)
.sum()
};
let vote_tx_cost = {
let is_simple_vote_transaction = vote_tx.is_simple_vote_transaction();
let signature_count_detail = vote_tx.message().get_signature_details();

CostModel::calculate_cost(
&vote_tx,
is_simple_vote_transaction,
&signature_count_detail,
&FeatureSet::all_enabled(),
)
.sum()
};

// make a vec of txs
let txs = vec![transfer_tx.clone(), vote_tx.clone(), transfer_tx, vote_tx];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,16 @@ impl<T: LikeClusterInfo> SchedulerController<T> {
fee_budget_limits: &FeeBudgetLimits,
bank: &Bank,
) -> (u64, u64) {
let cost = CostModel::calculate_cost(transaction, &bank.feature_set).sum();
let is_simple_vote_tx = transaction.is_simple_vote_transaction();
let signature_count_detail = transaction.message().get_signature_details();

let cost = CostModel::calculate_cost(
transaction,
is_simple_vote_tx,
&signature_count_detail,
&bank.feature_set,
)
.sum();
let reward = bank.calculate_reward_for_transaction(transaction, fee_budget_limits);

// We need a multiplier here to avoid rounding down too aggressively.
Expand Down
20 changes: 18 additions & 2 deletions cost-model/benches/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ fn bench_cost_model(bencher: &mut Bencher) {

bencher.iter(|| {
for transaction in &transactions {
let _ = CostModel::calculate_cost(test::black_box(transaction), &feature_set);
let transaction = test::black_box(transaction);
let is_simple_vote_transaction = transaction.is_simple_vote_transaction();
let signature_count_detail = transaction.message().get_signature_details();
let _ = CostModel::calculate_cost(
transaction,
is_simple_vote_transaction,
&signature_count_detail,
&feature_set,
);
}
});
}
Expand All @@ -71,7 +79,15 @@ fn bench_cost_model_requested_write_locks(bencher: &mut Bencher) {

bencher.iter(|| {
for transaction in &transactions {
let _ = CostModel::calculate_cost(test::black_box(transaction), &feature_set);
let transaction = test::black_box(transaction);
let is_simple_vote_transaction = transaction.is_simple_vote_transaction();
let signature_count_detail = transaction.message().get_signature_details();
let _ = CostModel::calculate_cost(
transaction,
is_simple_vote_transaction,
&signature_count_detail,
&feature_set,
);
}
});
}
Loading
Loading