Skip to content

Commit

Permalink
Bot: Add argument for ignoring errors when distributing stake in stak…
Browse files Browse the repository at this point in the history
…e-pool v0
  • Loading branch information
alex-at-planetariummusic committed Jun 5, 2023
1 parent 6bf4ff8 commit 158375f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
11 changes: 11 additions & 0 deletions bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,13 @@ fn get_config() -> BoxResult<GetConfigResult> {
.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")
Expand Down Expand Up @@ -955,6 +962,9 @@ fn get_config() -> BoxResult<GetConfigResult> {
("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) {
Expand All @@ -973,6 +983,7 @@ fn get_config() -> BoxResult<GetConfigResult> {
baseline_stake_amount,
reserve_stake_address,
min_reserve_stake_balance,
ignore_stake_distribution_errors,
)?)
}
("stake-pool", Some(matches)) => {
Expand Down
21 changes: 17 additions & 4 deletions bot/src/stake_pool_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<StakePool, Box<dyn error::Error>> {
if baseline_stake_amount < MIN_STAKE_CHANGE_AMOUNT {
return Err(format!(
Expand All @@ -70,6 +72,7 @@ pub fn new(
baseline_stake_amount,
reserve_stake_address,
min_reserve_stake_balance,
ignore_stake_distribution_errors,
})
}

Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -629,6 +633,7 @@ fn distribute_validator_stake<V>(
bonus_stake_amount: u64,
validator_stake_actions: &mut ValidatorStakeActions,
unfunded_validators: &mut HashSet<Pubkey>,
ignore_stake_distribution_errors: bool,
) -> Result<(u64, u64), Box<dyn error::Error>>
where
V: IntoIterator<Item = ValidatorStake>,
Expand Down Expand Up @@ -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());
}
}
}
};
Expand All @@ -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))
}
Expand Down Expand Up @@ -1006,6 +1018,7 @@ mod test {
baseline_stake_amount,
reserve_stake_address,
min_reserve_stake_balance,
false,
)
.unwrap();

Expand Down
5 changes: 5 additions & 0 deletions stake-o-matic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:?}
Expand Down

0 comments on commit 158375f

Please sign in to comment.