-
Notifications
You must be signed in to change notification settings - Fork 4.5k
cost model could double count builtin instruction cost #32422
cost model could double count builtin instruction cost #32422
Conversation
2. fix the issue
if let Ok(ComputeBudgetInstruction::SetComputeUnitLimit(_)) = | ||
try_from_slice_unchecked(&instruction.data) | ||
{ | ||
compute_unit_limit_is_set = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have to explicitly check if SetComputeUnitLimit
is included in the TX, only then can safely override default with compute_budget.compute_unit_limit
.
|
Codecov Report
@@ Coverage Diff @@
## master #32422 +/- ##
=======================================
Coverage 82.1% 82.1%
=======================================
Files 778 778
Lines 210107 210152 +45
=======================================
+ Hits 172556 172642 +86
+ Misses 37551 37510 -41 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine as quick fix. As implied by the comments, I think the right approach is refactoring this so we don't have a confusing setup of looping over the ixs twice. That will also help with performance.
bpf_costs = bpf_costs.saturating_add(DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT.into()); | ||
bpf_costs = bpf_costs | ||
.saturating_add(u64::from(DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT)) | ||
.min(u64::from(MAX_COMPUTE_UNIT_LIMIT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably don't need to do this every time, right? just do it after the loop
if let Ok(ComputeBudgetInstruction::SetComputeUnitLimit(_)) = | ||
try_from_slice_unchecked(&instruction.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels dirty, but is a quick fix.
1. add tests to demo builtin cost could be double counted; 2. quick fix for now (cherry picked from commit c69bc00) # Conflicts: # cost-model/src/cost_model.rs # program-runtime/src/compute_budget.rs
1. add tests to demo builtin cost could be double counted; 2. quick fix for now (cherry picked from commit c69bc00) # Conflicts: # runtime/src/cost_model.rs
1. add tests to demo builtin cost could be double counted; 2. quick fix for now (cherry picked from commit c69bc00) # Conflicts: # runtime/src/cost_model.rs
…rt of #32422) (#32516) * cost model could double count builtin instruction cost (#32422) 1. add tests to demo builtin cost could be double counted; 2. quick fix for now (cherry picked from commit c69bc00) # Conflicts: # runtime/src/cost_model.rs * fix backport merge conflict * fix a logic error --------- Co-authored-by: Tao Zhu <82401714+taozhu-chicago@users.noreply.github.com> Co-authored-by: Tao Zhu <tao@solana.com>
Problem
Philip @ FD pointed out "when there are no ComputeBudgetProgram instructions but at least 1 non-builtin instruction, bpf_execution_cost is initially set to 200k*(number of non-built-in instructions) but then overwritten to 200k*(number of non-ComputeBudgetProgram instructions) by the result of compute_budget.process_instructions . This means that if you have a mix of built-in and non-built-in instructions, the built-in ones get double counted (included in builtins_execution_cost and bpf_execution_cost )."
Summary of Changes
test_transaction_cost_with_mix_instruction_without_compute_budget
to cost_model.rs, confirms builtin ix add cost tobpf_execution_cost
test_process_mixed_instructions_without_compute_budget
to compute_budget.rs, to explicitly demo default compute unit limit behaviorset_compute_unit_limit
instruction inCostModel::get_transaction_cost()
to fix the issue.Fixes #