Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.
Merged
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
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