Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOTFIX: Adding in an admin tool for manually marking/unmarking validators #68

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions programs/steward/src/instructions/admin_mark_for_removal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use anchor_lang::prelude::*;

use crate::{utils::get_config_admin, Config, StewardStateAccount};

#[derive(Accounts)]
pub struct AdminMarkForRemoval<'info> {
#[account(mut)]
pub config: AccountLoader<'info, Config>,

#[account(
mut,
seeds = [StewardStateAccount::SEED, config.key().as_ref()],
bump
)]
pub state_account: AccountLoader<'info, StewardStateAccount>,

#[account(mut, address = get_config_admin(&config)?)]
pub authority: Signer<'info>,
}

/*
Used by the admin to unstick the machine
*/
pub fn handler(
ctx: Context<AdminMarkForRemoval>,
validator_list_index: usize,
mark_for_removal: bool,
immediate: bool,
) -> Result<()> {
let mut state = ctx.accounts.state_account.load_mut()?;

if immediate {
state
.state
.validators_for_immediate_removal
.set(validator_list_index, mark_for_removal)?;
coachchucksol marked this conversation as resolved.
Show resolved Hide resolved
} else {
state
.state
.validators_to_remove
.set(validator_list_index, mark_for_removal)?;
}

Ok(())
}
2 changes: 2 additions & 0 deletions programs/steward/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(ambiguous_glob_reexports)]
pub mod add_validator_to_blacklist;
pub mod admin_mark_for_removal;
pub mod auto_add_validator_to_pool;
pub mod auto_remove_validator_from_pool;
pub mod close_steward_accounts;
Expand All @@ -21,6 +22,7 @@ pub mod spl_passthrough;
pub mod update_parameters;

pub use add_validator_to_blacklist::*;
pub use admin_mark_for_removal::*;
pub use auto_add_validator_to_pool::*;
pub use auto_remove_validator_from_pool::*;
pub use close_steward_accounts::*;
Expand Down
16 changes: 16 additions & 0 deletions programs/steward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ If manual intervention is required, the following spl-stake-pool instructions ar
*/
#[program]
pub mod steward {

use super::*;

/* Initialization instructions */
Expand Down Expand Up @@ -191,6 +192,21 @@ pub mod steward {
instructions::reset_steward_state::handler(ctx)
}

/// Admin to mark or unmark validator for removal and unstuck the machine
pub fn admin_mark_for_removal(
ctx: Context<AdminMarkForRemoval>,
validator_list_index: u64,
mark_for_removal: u8,
immediate: u8,
) -> Result<()> {
instructions::admin_mark_for_removal::handler(
ctx,
validator_list_index as usize,
mark_for_removal != 0,
immediate != 0,
)
}

/// Closes Steward PDA accounts associated with a given Config (StewardStateAccount, and Staker).
/// Config is not closed as it is a Keypair, so lamports can simply be withdrawn.
/// Reclaims lamports to authority
Expand Down
22 changes: 19 additions & 3 deletions utils/steward-cli/initial_notes.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

# Accounts

**Authority**
**Authority**
`aaaDerwdMyzNkoX1aSoTi3UtFe2W45vh5wCgQNhsjF8`

**Steward Config**
**Steward Config**
`6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5`

**Stake Pool**
Expand All @@ -19,6 +19,7 @@
# Initial Commands

## Create Config

```bash
cargo run init-config \
--authority-keypair-path ../../credentials/stakenet_test.json \
Expand All @@ -45,6 +46,7 @@ cargo run init-config \
```

## Update Config

```bash
cargo run update-config \
--authority-keypair-path ../../credentials/stakenet_test.json \
Expand All @@ -54,71 +56,85 @@ cargo run update-config \
```

## Create State

```bash
cargo run init-state --authority-keypair-path ../../credentials/stakenet_test.json --stake-pool 3DuPtyTAKrxKfHkSPZ5fqCayMcGru1BarAKKTfGDeo2j --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5
```

## View Config

```bash
cargo run view-config --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5
```

## View State

```bash
cargo run view-state --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5
```

## View State Per Validator

```bash
cargo run view-state-per-validator --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5
```

## View Next Index To Remove

```bash
cargo run view-next-index-to-remove --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5
```

## Auto Remove Validator

```bash
cargo run auto-remove-validator-from-pool --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5 --payer-keypair-path ../../credentials/stakenet_test.json --validator-index-to-remove 1397
```

## Auto Add Validator

```bash
cargo run auto-add-validator-from-pool --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5 --payer-keypair-path ../../credentials/stakenet_test.json --vote-account 4m64H5TbwAGtZVnxaGAVoTSwjZGV8BCLKRPr8agKQv4Z
```

## Remove Bad Validators

```bash
cargo run remove-bad-validators --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5 --payer-keypair-path ../../credentials/stakenet_test.json
```

## Crank Epoch Maintenance

```bash
cargo run crank-epoch-maintenance --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5 --payer-keypair-path ../../credentials/stakenet_test.json
```

## Crank Compute Score

```bash
cargo run crank-compute-score --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5 --payer-keypair-path ../../credentials/stakenet_test.json
```

## Crank Compute Delegations

```bash
cargo run crank-compute-delegations --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5 --payer-keypair-path ../../credentials/stakenet_test.json
```

## Crank Idle

```bash
cargo run crank-idle --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5 --payer-keypair-path ../../credentials/stakenet_test.json
```

## Crank Compute Instant Unstake

```bash
cargo run crank-compute-instant-unstake --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5 --payer-keypair-path ../../credentials/stakenet_test.json
```

## Crank Rebalance

```bash
cargo run crank-rebalance --steward-config 6auT7Q91SSgAoYLAnu449DK1MK9skDmtiLmtkCECP1b5 --payer-keypair-path ../../credentials/stakenet_test.json
```
Expand Down Expand Up @@ -157,4 +173,4 @@ INSTANT_UNSTAKE_INPUTS_EPOCH_PROGRESS=0.50
NUM_EPOCHS_BETWEEN_SCORING=3
MINIMUM_STAKE_LAMPORTS=100000000000
MINIMUM_VOTING_EPOCHS=5
```
```
1 change: 1 addition & 0 deletions utils/steward-cli/src/commands/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub mod auto_add_validator_from_pool;
pub mod auto_remove_validator_from_pool;
pub mod remove_bad_validators;
pub mod reset_state;
pub mod surgery;
pub mod update_config;
116 changes: 116 additions & 0 deletions utils/steward-cli/src/commands/actions/surgery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
use std::sync::Arc;

use anchor_lang::{InstructionData, ToAccountMetas};
use anyhow::Result;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_program::instruction::Instruction;

use solana_sdk::{
pubkey::Pubkey, signature::read_keypair_file, signer::Signer, transaction::Transaction,
};

use crate::{
commands::command_args::Surgery,
utils::{
accounts::{
get_steward_config_account, get_steward_state_address, get_validator_list_account,
},
transactions::configure_instruction,
},
};

pub async fn command_surgery(
args: Surgery,
client: &Arc<RpcClient>,
program_id: Pubkey,
) -> Result<()> {
let validator_list_index: u64 = args.validator_list_index as u64;
let mark_for_removal: u8 = {
if args.mark_for_removal {
0xFF // TRUE
} else {
0x00 // FALSE
}
};
let immediate: u8 = {
if args.immediate {
0xFF // TRUE
} else {
0x00 // FALSE
}
};

let authority = read_keypair_file(args.permissioned_parameters.authority_keypair_path)
.expect("Failed reading keypair file ( Authority )");

let steward_config_address = args.permissioned_parameters.steward_config;
let steward_state_address = get_steward_state_address(&program_id, &steward_config_address);

let steward_config_account =
get_steward_config_account(client, &steward_config_address).await?;
let validator_list_account =
get_validator_list_account(client, &steward_config_account.validator_list).await?;

{
println!("Submit: {}", args.submit_ix);

println!("Validator list index: {}", validator_list_index);
println!("Mark for removal: {}", mark_for_removal);
println!("Immediate: {}", immediate);

let validator_to_mark = validator_list_account
.validators
.get(validator_list_index as usize)
.unwrap();

println!("Validator to mark: {:?}", validator_to_mark);
}

if args.submit_ix {
let ix = Instruction {
program_id,
accounts: jito_steward::accounts::AdminMarkForRemoval {
state_account: steward_state_address,
config: steward_config_address,
authority: authority.pubkey(),
}
.to_account_metas(None),
data: jito_steward::instruction::AdminMarkForRemoval {
validator_list_index,
mark_for_removal,
immediate,
}
.data(),
};

let blockhash = client.get_latest_blockhash().await?;

let configured_ix = configure_instruction(
&[ix],
args.permissioned_parameters
.transaction_parameters
.priority_fee,
args.permissioned_parameters
.transaction_parameters
.compute_limit,
args.permissioned_parameters
.transaction_parameters
.heap_size,
);

let transaction = Transaction::new_signed_with_payer(
&configured_ix,
Some(&authority.pubkey()),
&[&authority],
blockhash,
);

let signature = client
.send_and_confirm_transaction_with_spinner(&transaction)
.await?;

println!("Signature: {}", signature);
}

Ok(())
}
20 changes: 20 additions & 0 deletions utils/steward-cli/src/commands/command_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ pub enum Commands {

InitState(InitState),
ResetState(ResetState),
Surgery(Surgery),

RemoveBadValidators(RemoveBadValidators),
AutoRemoveValidatorFromPool(AutoRemoveValidatorFromPool),
Expand Down Expand Up @@ -289,6 +290,25 @@ pub struct ResetState {
pub permissioned_parameters: PermissionedParameters,
}

#[derive(Parser)]
#[command(about = "Mark the correct validator for removal")]
pub struct Surgery {
#[command(flatten)]
pub permissioned_parameters: PermissionedParameters,

#[arg(long)]
pub mark_for_removal: bool,

#[arg(long)]
pub immediate: bool,

#[arg(long)]
pub validator_list_index: usize,

#[arg(long, default_value = "false")]
pub submit_ix: bool,
}

#[derive(Parser)]
#[command(about = "Removes bad validators from the pool")]
pub struct RemoveBadValidators {
Expand Down
3 changes: 2 additions & 1 deletion utils/steward-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use commands::{
auto_add_validator_from_pool::command_auto_add_validator_from_pool,
auto_remove_validator_from_pool::command_auto_remove_validator_from_pool,
remove_bad_validators::command_remove_bad_validators, reset_state::command_reset_state,
update_config::command_update_config,
surgery::command_surgery, update_config::command_update_config,
},
command_args::{Args, Commands},
cranks::{
Expand Down Expand Up @@ -51,6 +51,7 @@ async fn main() -> Result<()> {
Commands::UpdateConfig(args) => command_update_config(args, &client, program_id).await,
Commands::InitState(args) => command_init_state(args, &client, program_id).await,
Commands::ResetState(args) => command_reset_state(args, &client, program_id).await,
coachchucksol marked this conversation as resolved.
Show resolved Hide resolved
Commands::Surgery(args) => command_surgery(args, &client, program_id).await,
Commands::AutoRemoveValidatorFromPool(args) => {
command_auto_remove_validator_from_pool(args, &client, program_id).await
}
Expand Down
Loading