Skip to content

Commit

Permalink
Gate debug_asserts with compile feature
Browse files Browse the repository at this point in the history
  • Loading branch information
aborg-dev committed Apr 3, 2023
1 parent 97e4147 commit 2b79110
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions core/primitives/src/runtime/parameter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ impl TryFrom<&ParameterValue> for ParameterCost {
fn try_from(value: &ParameterValue) -> Result<Self, Self::Error> {
match value {
ParameterValue::ParameterCost { gas, compute } => {
if !cfg!(feature = "protocol_feature_compute_costs") {
debug_assert_eq!(compute, gas, "Compute cost must match gas cost");
}

Ok(ParameterCost { gas: *gas, compute: *compute })
}
// If not specified, compute costs default to gas costs.
Expand Down
20 changes: 12 additions & 8 deletions runtime/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,10 +1283,12 @@ impl Runtime {
safe_add_compute(total_compute_usage, outcome_with_id.outcome.compute_usage)?;

// TODO(#8032): Remove when compute costs are stabilized.
debug_assert_eq!(
total_compute_usage, total_gas_burnt,
"Compute usage must match burnt gas"
);
if !cfg!(feature = "protocol_feature_compute_costs") {
debug_assert_eq!(
total_compute_usage, total_gas_burnt,
"Compute usage must match burnt gas"
);
}

outcomes.push(outcome_with_id);
}
Expand Down Expand Up @@ -1326,10 +1328,12 @@ impl Runtime {
*total_compute_usage =
safe_add_compute(*total_compute_usage, outcome_with_id.outcome.compute_usage)?;
// TODO(#8032): Remove when compute costs are stabilized.
debug_assert_eq!(
total_compute_usage, total_gas_burnt,
"Compute usage must match burnt gas"
);
if !cfg!(feature = "protocol_feature_compute_costs") {
debug_assert_eq!(
total_compute_usage, total_gas_burnt,
"Compute usage must match burnt gas"
);
}
outcomes.push(outcome_with_id);
}
Ok(())
Expand Down

0 comments on commit 2b79110

Please sign in to comment.