-
Notifications
You must be signed in to change notification settings - Fork 256
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
Add --with-compute-unit-price
to cli program deploy commands
#364
Conversation
cli/src/program.rs
Outdated
let mut compute_unit_limit: u32 = 300; // 2 * 150 for compute budget ixs | ||
for ix in ixs.iter() { | ||
if ix.program_id == bpf_loader_upgradeable::id() { | ||
compute_unit_limit += 2370; | ||
match ix.data.first() { | ||
Some(2) // DeployWithMaxDataLen | ||
| Some(6) // ExtendProgram | ||
=> { | ||
// add compute for native system program invocation | ||
compute_unit_limit += 150; | ||
} | ||
_ => {} | ||
} | ||
} else if ix.program_id == system_program::id() { | ||
compute_unit_limit += 150; | ||
} else { | ||
panic!( | ||
"Couldn't estimate compute unit limit for unexpected program {}", | ||
ix.program_id | ||
); | ||
} | ||
} |
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.
I'm not really in favor of having compute unit limit logic here in the cli client. I'd prefer to get the units consumed from the simulate transaction call.
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.
Yeah that would be great, I've been trying to figure out a nice API to do it. No need to change what you've done though
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.
I would feel better knowing that deploys won't get broken in the future if we increase the compute unit limit for certain instructions. Let me know what you think of the simulation code!
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #364 +/- ##
=========================================
- Coverage 81.9% 81.9% -0.1%
=========================================
Files 838 838
Lines 227368 227412 +44
=========================================
+ Hits 186238 186266 +28
- Misses 41130 41146 +16 |
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.
Looks great! Just a nit on the test, but nothing stopping this from going in
cli/src/program.rs
Outdated
let mut compute_unit_limit: u32 = 300; // 2 * 150 for compute budget ixs | ||
for ix in ixs.iter() { | ||
if ix.program_id == bpf_loader_upgradeable::id() { | ||
compute_unit_limit += 2370; | ||
match ix.data.first() { | ||
Some(2) // DeployWithMaxDataLen | ||
| Some(6) // ExtendProgram | ||
=> { | ||
// add compute for native system program invocation | ||
compute_unit_limit += 150; | ||
} | ||
_ => {} | ||
} | ||
} else if ix.program_id == system_program::id() { | ||
compute_unit_limit += 150; | ||
} else { | ||
panic!( | ||
"Couldn't estimate compute unit limit for unexpected program {}", | ||
ix.program_id | ||
); | ||
} | ||
} |
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.
Yeah that would be great, I've been trying to figure out a nice API to do it. No need to change what you've done though
cli/src/program.rs
Outdated
compute_unit_limit += 2370; | ||
match ix.data.first() { | ||
Some(2) // DeployWithMaxDataLen | ||
| Some(6) // ExtendProgram |
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.
Thanks for thinking about the future by including this even though it isn't used in this PR ❤️
cli/src/program.rs
Outdated
// add compute for native system program invocation | ||
compute_unit_limit += 150; |
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.
Confirming this is correct
let (initial_message, write_messages, balance_needed) = if let Some(buffer_signer) = | ||
buffer_signer |
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.
thanks rustfmt 🙃
cli/tests/program.rs
Outdated
match try_from_slice_unchecked(&tx.message.instructions[0].data) { | ||
Ok(ComputeBudgetInstruction::SetComputeUnitPrice(price)) | ||
if price == compute_unit_price => {} | ||
ix => assert!(false, "unexpected ix {ix:?}"), | ||
} |
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.
nit: I believe all of these checks could use matches!
to be simpler, ie:
match try_from_slice_unchecked(&tx.message.instructions[0].data) { | |
Ok(ComputeBudgetInstruction::SetComputeUnitPrice(price)) | |
if price == compute_unit_price => {} | |
ix => assert!(false, "unexpected ix {ix:?}"), | |
} | |
assert!( | |
matches!( | |
try_from_slice_unchecked(&tx.message.instructions[0].data), | |
Ok(ComputeBudgetInstruction::SetComputeUnitPrice(price)) if price == compute_unit_price | |
), | |
"unexpected ix {ix:?}" | |
); |
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.
Still looks great! Just a couple of nits, but nothing to stop this from going in
Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis. |
* add set compute units arg for program deploy * update master changes * remove duplicates * fixes and tests * remove extra lines * feedback * Use simulation to determine compute units consumed * feedback --------- Co-authored-by: NagaprasadVr <nagaprasadvr246@gmail.com> (cherry picked from commit 2ee606d)
… (backport of #364) (#392) Add `--with-compute-unit-price` to cli program deploy commands (#364) * add set compute units arg for program deploy * update master changes * remove duplicates * fixes and tests * remove extra lines * feedback * Use simulation to determine compute units consumed * feedback --------- Co-authored-by: NagaprasadVr <nagaprasadvr246@gmail.com> (cherry picked from commit 2ee606d) Co-authored-by: Justin Starry <justin@anza.xyz>
Hi @joncinque, after adding |
@tarunjais28 it still can be difficult to get transactions to the leader due to stake-weighted quality of service setups, but you're doing the right thing. You can also try adding the |
Problem
It's not possible to set a compute unit price or limit on deploy transactions. This causes deploys to be very slow when transaction priority fees increase on the cluster.
Summary of Changes
--with-compute-unit-price
flag is passed forsolana program deploy
andsolana program write-buffer
Fixes #21