From 373c07dc681b7d5c48bf6cffcb1e33c260c300a5 Mon Sep 17 00:00:00 2001 From: Jon C Date: Fri, 26 Apr 2024 00:58:22 +0200 Subject: [PATCH 1/2] stake-pool-cli: Default to simulated compute units --- stake-pool/cli/src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/stake-pool/cli/src/main.rs b/stake-pool/cli/src/main.rs index c695f351120..956134777c1 100644 --- a/stake-pool/cli/src/main.rs +++ b/stake-pool/cli/src/main.rs @@ -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(string: T) -> Result<(), String> where T: AsRef + std::fmt::Display, { - if string.as_ref().parse::().is_ok() || string.as_ref() == "SIMULATED" { + if string.as_ref().parse::().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}" )) } } @@ -136,7 +138,7 @@ where { match string.as_ref().parse::() { 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}" )), @@ -2834,7 +2836,7 @@ 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(ComputeUnitLimit::Simulated); Config { rpc_client: RpcClient::new_with_commitment(json_rpc_url, CommitmentConfig::confirmed()), From 775b41c3f32b5fb8c52df8d9de8edd1c21a3d92f Mon Sep 17 00:00:00 2001 From: hanako mumei <81144685+2501babe@users.noreply.github.com> Date: Sat, 27 Apr 2024 04:02:48 -0700 Subject: [PATCH 2/2] stake-pool-cli: Fix compute limit logic --- stake-pool/cli/src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stake-pool/cli/src/main.rs b/stake-pool/cli/src/main.rs index 956134777c1..a7bd4cfa5cb 100644 --- a/stake-pool/cli/src/main.rs +++ b/stake-pool/cli/src/main.rs @@ -2042,7 +2042,7 @@ fn main() { .global(true) .help("Transaction fee payer account [default: cli config keypair]"), ) - .arg(compute_unit_price_arg().validator(is_parsable::).requires(COMPUTE_UNIT_LIMIT_ARG.name).global(true)) + .arg(compute_unit_price_arg().validator(is_parsable::).global(true)) .arg( Arg::with_name(COMPUTE_UNIT_LIMIT_ARG.name) .long(COMPUTE_UNIT_LIMIT_ARG.long) @@ -2836,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::Simulated); + .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()),