Skip to content

Commit

Permalink
Bot: Show stake deactivated from orphaned accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-at-planetariummusic committed Jan 26, 2023
1 parent 870e4f4 commit 79f7648
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2455,10 +2455,10 @@ fn main() -> BoxResult<()> {
_ => {}
}

if first_time && post_notifications {
for notification in notifications {
info!("notification: {}", notification);
// Only notify the user if this is the first run for this epoch
for notification in notifications {
info!("notification: {}", notification);
if first_time && post_notifications {
notifier.send(&notification);
}
}
Expand Down
18 changes: 13 additions & 5 deletions bot/src/stake_pool_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl GenericStakePool for StakePool {
get_all_stake(&rpc_client, self.authorized_staker.pubkey())?;

info!("Merge orphaned stake into the reserve");
merge_orphaned_stake_accounts(
let deactivated_merged_stake = merge_orphaned_stake_accounts(
rpc_client.clone(),
websocket_url,
&self.authorized_staker,
Expand Down Expand Up @@ -253,6 +253,10 @@ impl GenericStakePool for StakePool {
"Validators by stake level: None={}, Baseline={}, Bonus={}",
min_stake_node_count, baseline_stake_node_count, bonus_stake_node_count
),
format!(
"Deactiving stake from orphaned stake accounts: ◎{}",
(lamports_to_sol(deactivated_merged_stake) as u64).to_formatted_string(&Locale::en)
),
];

let busy_validators = validator_stake_actions
Expand All @@ -278,11 +282,11 @@ impl GenericStakePool for StakePool {
)?;

notes.push(format!(
"Activating stake: ◎{}",
"Activating stake: ◎{}",
(lamports_to_sol(activating_stake) as u64).to_formatted_string(&Locale::en)
));
notes.push(format!(
"Deactivating stake: ◎{}",
"Deactivating stake: ◎{}",
(lamports_to_sol(deactivating_stake) as u64).to_formatted_string(&Locale::en)
));

Expand Down Expand Up @@ -328,8 +332,11 @@ fn merge_orphaned_stake_accounts(
source_stake_addresses: HashSet<Pubkey>,
reserve_stake_address: Pubkey,
dry_run: bool,
) -> Result<(), Box<dyn error::Error>> {
) -> Result<u64, Box<dyn error::Error>> {
let mut transactions = vec![];

let mut deactivating_stake_lamports = 0;

for stake_address in source_stake_addresses {
let stake_activation = rpc_client
.get_stake_activation(stake_address, None)
Expand All @@ -343,6 +350,7 @@ fn merge_orphaned_stake_accounts(
match stake_activation.state {
StakeActivationState::Activating | StakeActivationState::Deactivating => {}
StakeActivationState::Active => {
deactivating_stake_lamports += stake_activation.active;
transactions.push(Transaction::new_with_payer(
&[stake_instruction::deactivate_stake(
&stake_address,
Expand Down Expand Up @@ -382,7 +390,7 @@ fn merge_orphaned_stake_accounts(
{
Err("Failed to merge orphaned stake accounts".into())
} else {
Ok(())
Ok(deactivating_stake_lamports)
}
}

Expand Down

0 comments on commit 79f7648

Please sign in to comment.