From 158375f1ac4e635ee287387ad610b637917e2eae Mon Sep 17 00:00:00 2001 From: Alex Bundy Date: Fri, 26 May 2023 14:21:39 -0700 Subject: [PATCH] Bot: Add argument for ignoring errors when distributing stake in stake-pool v0 --- bot/src/main.rs | 11 +++++++++++ bot/src/stake_pool_v0.rs | 21 +++++++++++++++++---- stake-o-matic.sh | 5 +++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/bot/src/main.rs b/bot/src/main.rs index 972314d3..70534c30 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -717,6 +717,13 @@ fn get_config() -> BoxResult { .takes_value(true) .help("The baseline SOL amount to stake to validators with adequate performance") ) + .arg( + Arg::with_name("ignore_stake_distribution_errors") + .required(false) + .takes_value(false) + .help("If set, do not ") + + ) ) .subcommand( SubCommand::with_name("stake-pool").about("Use a stake pool") @@ -955,6 +962,9 @@ fn get_config() -> BoxResult { ("stake-pool-v0", Some(matches)) => { let authorized_staker = keypair_of(matches, "authorized_staker").unwrap(); let reserve_stake_address = pubkey_of(matches, "reserve_stake_address").unwrap(); + + let ignore_stake_distribution_errors = + matches.is_present("ignore_stake_distribution_errors"); let min_reserve_stake_balance = sol_to_lamports(value_t_or_exit!(matches, "min_reserve_stake_balance", f64)); let baseline_stake_amount = match value_t!(matches, "baseline_stake_amount", f64) { @@ -973,6 +983,7 @@ fn get_config() -> BoxResult { baseline_stake_amount, reserve_stake_address, min_reserve_stake_balance, + ignore_stake_distribution_errors, )?) } ("stake-pool", Some(matches)) => { diff --git a/bot/src/stake_pool_v0.rs b/bot/src/stake_pool_v0.rs index a46ae413..798180f4 100644 --- a/bot/src/stake_pool_v0.rs +++ b/bot/src/stake_pool_v0.rs @@ -40,6 +40,7 @@ pub struct StakePool { baseline_stake_amount: u64, reserve_stake_address: Pubkey, min_reserve_stake_balance: u64, + ignore_stake_distribution_errors: bool, } pub fn new( @@ -48,6 +49,7 @@ pub fn new( baseline_stake_amount: u64, reserve_stake_address: Pubkey, min_reserve_stake_balance: u64, + ignore_stake_distribution_errors: bool, ) -> Result> { if baseline_stake_amount < MIN_STAKE_CHANGE_AMOUNT { return Err(format!( @@ -70,6 +72,7 @@ pub fn new( baseline_stake_amount, reserve_stake_address, min_reserve_stake_balance, + ignore_stake_distribution_errors, }) } @@ -275,6 +278,7 @@ impl GenericStakePool for StakePool { bonus_stake_amount, &mut validator_stake_actions, &mut unfunded_validators, + self.ignore_stake_distribution_errors, )?; notes.push(format!( @@ -629,6 +633,7 @@ fn distribute_validator_stake( bonus_stake_amount: u64, validator_stake_actions: &mut ValidatorStakeActions, unfunded_validators: &mut HashSet, + ignore_stake_distribution_errors: bool, ) -> Result<(u64, u64), Box> where V: IntoIterator, @@ -820,7 +825,11 @@ where Ok(errors) => errors.iter().filter(|err| err.is_some()).count(), Err(e) => { error!("Sending transactions failed: {:?}", e); - return Ok((activating_total, deactivating_total)); + if ignore_stake_distribution_errors { + return Ok((activating_total, deactivating_total)); + } else { + return Err("Some transactions failed to land".into()); + } } } }; @@ -830,9 +839,12 @@ where "{:?} transactions failed to execute due to errors.", num_transaction_errors ); - // Err("One or more transactions failed to execute".into()) - // for now, ignore errors while distributing stake. The next time the bot runs it should retry all failed transactions. - Ok((activating_total, deactivating_total)) + if ignore_stake_distribution_errors { + error!("Ignoring stake distribution errors"); + Ok((activating_total, deactivating_total)) + } else { + Err("One or more transactions failed to execute".into()) + } } else { Ok((activating_total, deactivating_total)) } @@ -1006,6 +1018,7 @@ mod test { baseline_stake_amount, reserve_stake_address, min_reserve_stake_balance, + false, ) .unwrap(); diff --git a/stake-o-matic.sh b/stake-o-matic.sh index 6ce64b40..52362879 100755 --- a/stake-o-matic.sh +++ b/stake-o-matic.sh @@ -75,6 +75,10 @@ if [[ -n $USE_RPC_TX_SUBMISSION ]]; then USE_RPC_TX_SUBMISSION="--use-rpc-tx-submission $USE_RPC_TX_SUBMISSION" fi +if [[ -n $IGNORE_STAKE_DISTRIBUTION_ERRORS ]]; then + IGNORE_STAKE_DISTRIBUTION_ERRORS="--ignore-stake-distribution-errors" +fi + # shellcheck disable=SC2206 TESTNET_ARGS=( --cluster testnet @@ -109,6 +113,7 @@ MAINNET_BETA_ARGS=( # shellcheck disable=SC2206 NOT_A_STAKE_POOL_ARGS=( stake-pool-v0 + $IGNORE_STAKE_DISTRIBUTION_ERRORS --min-reserve-stake-balance ${MIN_RESERVE_STAKE_BALANCE:?} ${RESERVE_ACCOUNT_ADDRESS:?} ${STAKE_AUTHORITY_KEYPAIR:?}