Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 6fc6411

Browse files
authored
stake-pool-cli: Add support for priority fees (#6499)
* stake-pool-cli: Add function to simulate tx for CUs used * Add compute unit price and limit args * Refactor to always use `checked_transaction_*` * Add compute budget instructions * Fix creation to create second transaction *after* sending first one * Address feedback * Specify "SIMULATED" explicitly
1 parent f80b00b commit 6fc6411

File tree

2 files changed

+236
-142
lines changed

2 files changed

+236
-142
lines changed

stake-pool/cli/src/client.rs

+38-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ use {
77
rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig},
88
rpc_filter::{Memcmp, RpcFilterType},
99
},
10-
solana_program::{borsh1::try_from_slice_unchecked, program_pack::Pack, pubkey::Pubkey, stake},
10+
solana_program::{
11+
borsh1::try_from_slice_unchecked, hash::Hash, instruction::Instruction, message::Message,
12+
program_pack::Pack, pubkey::Pubkey, stake,
13+
},
14+
solana_sdk::{compute_budget::ComputeBudgetInstruction, transaction::Transaction},
1115
spl_stake_pool::{
1216
find_withdraw_authority_program_address,
1317
state::{StakePool, ValidatorList},
1418
},
1519
std::collections::HashSet,
1620
};
1721

18-
type Error = Box<dyn std::error::Error>;
22+
pub(crate) type Error = Box<dyn std::error::Error>;
1923

2024
pub fn get_stake_pool(
2125
rpc_client: &RpcClient,
@@ -146,3 +150,35 @@ pub(crate) fn get_all_stake(
146150
.map(|(address, _)| address)
147151
.collect())
148152
}
153+
154+
/// Helper function to add a compute unit limit instruction to a given set
155+
/// of instructions
156+
pub(crate) fn add_compute_unit_limit_from_simulation(
157+
rpc_client: &RpcClient,
158+
instructions: &mut Vec<Instruction>,
159+
payer: &Pubkey,
160+
blockhash: &Hash,
161+
) -> Result<(), Error> {
162+
// add a max compute unit limit instruction for the simulation
163+
const MAX_COMPUTE_UNIT_LIMIT: u32 = 1_400_000;
164+
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(
165+
MAX_COMPUTE_UNIT_LIMIT,
166+
));
167+
168+
let transaction = Transaction::new_unsigned(Message::new_with_blockhash(
169+
instructions,
170+
Some(payer),
171+
blockhash,
172+
));
173+
let simulation_result = rpc_client.simulate_transaction(&transaction)?.value;
174+
let units_consumed = simulation_result
175+
.units_consumed
176+
.ok_or("No units consumed on simulation")?;
177+
// Overwrite the compute unit limit instruction with the actual units consumed
178+
let compute_unit_limit = u32::try_from(units_consumed)?;
179+
instructions
180+
.last_mut()
181+
.expect("Compute budget instruction was added earlier")
182+
.data = ComputeBudgetInstruction::set_compute_unit_limit(compute_unit_limit).data;
183+
Ok(())
184+
}

0 commit comments

Comments
 (0)