Skip to content

Commit

Permalink
stake-pool-cli: Default to simulated compute units (#6635)
Browse files Browse the repository at this point in the history
* stake-pool-cli: Default to simulated compute units

* stake-pool-cli: Fix compute limit logic

---------

Co-authored-by: hanako mumei <[email protected]>
  • Loading branch information
joncinque and 2501babe authored Apr 30, 2024
1 parent 528a9b5 commit 4297ae6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions stake-pool/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,21 @@ const COMPUTE_UNIT_LIMIT_ARG: ArgConstant<'static> = ArgConstant {
name: "compute_unit_limit",
long: "--with-compute-unit-limit",
help: "Set compute unit limit for transaction, in compute units; also accepts \
keyword SIMULATED to use compute units from transaction simulation prior \
to sending. Note that SIMULATED may fail if accounts are modified by another \
transaction between simulation and execution.",
keyword DEFAULT to use the default compute unit limit, which is 200k per \
top-level instruction, with a maximum of 1.4 million. \
If nothing is set, transactions are simulated prior to sending, and the \
compute units consumed are set as the limit. This may may fail if accounts \
are modified by another transaction between simulation and execution.",
};
fn is_compute_unit_limit_or_simulated<T>(string: T) -> Result<(), String>
where
T: AsRef<str> + std::fmt::Display,
{
if string.as_ref().parse::<u32>().is_ok() || string.as_ref() == "SIMULATED" {
if string.as_ref().parse::<u32>().is_ok() || string.as_ref() == "DEFAULT" {
Ok(())
} else {
Err(format!(
"Unable to parse input compute unit limit as integer or SIMULATED, provided: {string}"
"Unable to parse input compute unit limit as integer or DEFAULT, provided: {string}"
))
}
}
Expand All @@ -136,7 +138,7 @@ where
{
match string.as_ref().parse::<u32>() {
Ok(compute_unit_limit) => Ok(ComputeUnitLimit::Static(compute_unit_limit)),
Err(_) if string.as_ref() == "SIMULATED" => Ok(ComputeUnitLimit::Simulated),
Err(_) if string.as_ref() == "DEFAULT" => Ok(ComputeUnitLimit::Default),
_ => Err(format!(
"Unable to parse compute unit limit, provided: {string}"
)),
Expand Down Expand Up @@ -2040,7 +2042,7 @@ fn main() {
.global(true)
.help("Transaction fee payer account [default: cli config keypair]"),
)
.arg(compute_unit_price_arg().validator(is_parsable::<u64>).requires(COMPUTE_UNIT_LIMIT_ARG.name).global(true))
.arg(compute_unit_price_arg().validator(is_parsable::<u64>).global(true))
.arg(
Arg::with_name(COMPUTE_UNIT_LIMIT_ARG.name)
.long(COMPUTE_UNIT_LIMIT_ARG.long)
Expand Down Expand Up @@ -2834,7 +2836,13 @@ fn main() {
let compute_unit_limit = matches
.value_of(COMPUTE_UNIT_LIMIT_ARG.name)
.map(|x| parse_compute_unit_limit(x).unwrap())
.unwrap_or(ComputeUnitLimit::Default);
.unwrap_or_else(|| {
if compute_unit_price.is_some() {
ComputeUnitLimit::Simulated
} else {
ComputeUnitLimit::Default
}
});

Config {
rpc_client: RpcClient::new_with_commitment(json_rpc_url, CommitmentConfig::confirmed()),
Expand Down

0 comments on commit 4297ae6

Please sign in to comment.