Skip to content

Commit

Permalink
switching
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Krueger authored and Christian Krueger committed Jul 22, 2024
1 parent 0f4ff38 commit 8440c1b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 22 deletions.
24 changes: 16 additions & 8 deletions programs/steward/src/instructions/auto_add_validator_to_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::constants::{MAX_VALIDATORS, STAKE_POOL_WITHDRAW_SEED};
use crate::errors::StewardError;
use crate::events::AutoAddValidatorEvent;
use crate::state::{Config, StewardStateAccount};
use crate::utils::{deserialize_stake_pool, get_stake_pool_address};
use crate::utils::{deserialize_stake_pool, get_stake_pool_address, get_validator_list_length};
use anchor_lang::prelude::*;
use anchor_lang::solana_program::{program::invoke_signed, stake, sysvar, vote};
use spl_stake_pool::find_stake_program_address;
Expand Down Expand Up @@ -106,13 +106,21 @@ pub fn handler(ctx: Context<AutoAddValidator>) -> Result<()> {
let validator_history = ctx.accounts.validator_history_account.load()?;
let epoch = Clock::get()?.epoch;

//TODO Cannot add if validator mismatch

// Should not be able to add a validator if update is not complete
require!(
epoch == state_account.state.current_epoch,
StewardError::EpochMaintenanceNotComplete
);
{
// CHECKS
require!(
epoch == state_account.state.current_epoch,
StewardError::EpochMaintenanceNotComplete
);

let validators_in_list = get_validator_list_length(&ctx.accounts.validator_list)?;
require!(
state_account.state.num_pool_validators as usize
+ state_account.state.validators_added as usize
== validators_in_list,
StewardError::ListStateMismatch
);
}

let validator_list_len = {
let validator_list_data = &mut ctx.accounts.validator_list.try_borrow_mut_data()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::errors::StewardError;
use crate::events::AutoRemoveValidatorEvent;
use crate::state::Config;
use crate::utils::{
deserialize_stake_pool, get_stake_pool_address, get_validator_stake_info_at_index,
deserialize_stake_pool, get_stake_pool_address, get_validator_list_length,
get_validator_stake_info_at_index,
};
use crate::StewardStateAccount;
use anchor_lang::solana_program::{program::invoke_signed, stake, sysvar, vote};
Expand Down Expand Up @@ -124,13 +125,27 @@ pub struct AutoRemoveValidator<'info> {
*/
pub fn handler(ctx: Context<AutoRemoveValidator>, validator_list_index: usize) -> Result<()> {
//TODO Cannot remove if mismatch

{
let mut state_account = ctx.accounts.state_account.load_mut()?;
let validator_list = &ctx.accounts.validator_list;
let epoch = Clock::get()?.epoch;

{
// CHECKS
require!(
epoch == state_account.state.current_epoch,
StewardError::EpochMaintenanceNotComplete
);

let validators_in_list = get_validator_list_length(&ctx.accounts.validator_list)?;
require!(
state_account.state.num_pool_validators as usize
+ state_account.state.validators_added as usize
== validators_in_list,
StewardError::ListStateMismatch
);
}

let validator_stake_info =
get_validator_stake_info_at_index(validator_list, validator_list_index)?;
require!(
Expand Down
56 changes: 45 additions & 11 deletions programs/steward/src/instructions/index_mismatch_interrupt.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::{
errors::StewardError,

Check failure on line 2 in programs/steward/src/instructions/index_mismatch_interrupt.rs

View workflow job for this annotation

GitHub Actions / verified_build

unused import: `errors::StewardError`

Check failure on line 2 in programs/steward/src/instructions/index_mismatch_interrupt.rs

View workflow job for this annotation

GitHub Actions / udeps

unused import: `errors::StewardError`

Check failure on line 2 in programs/steward/src/instructions/index_mismatch_interrupt.rs

View workflow job for this annotation

GitHub Actions / lint

unused import: `errors::StewardError`
events::IndexMismatchInterruptEvent,
utils::{deserialize_stake_pool, get_stake_pool_address, get_validator_list_length},
utils::{
deserialize_stake_pool, deserialize_validator_list, get_stake_pool_address,
get_validator_list_length,
},
Config, StewardStateAccount,
};
use anchor_lang::prelude::*;
use spl_stake_pool::state::ValidatorListHeader;
use spl_stake_pool::state::StakeStatus;

Check failure on line 11 in programs/steward/src/instructions/index_mismatch_interrupt.rs

View workflow job for this annotation

GitHub Actions / verified_build

unused import: `spl_stake_pool::state::StakeStatus`

Check failure on line 11 in programs/steward/src/instructions/index_mismatch_interrupt.rs

View workflow job for this annotation

GitHub Actions / udeps

unused import: `spl_stake_pool::state::StakeStatus`

Check failure on line 11 in programs/steward/src/instructions/index_mismatch_interrupt.rs

View workflow job for this annotation

GitHub Actions / lint

unused import: `spl_stake_pool::state::StakeStatus`

#[derive(Accounts)]
pub struct IndexMismatchInterrupt<'info> {
Expand Down Expand Up @@ -34,6 +37,22 @@ pub struct IndexMismatchInterrupt<'info> {
/// - Remove delinquent validators
pub fn handler(ctx: Context<IndexMismatchInterrupt>) -> Result<()> {
let mut state_account = ctx.accounts.state_account.load_mut()?;
let validator_list = deserialize_validator_list(&ctx.accounts.validator_list)?;

// {
// // Need there to be a mismatch
// require!(
// state_account.state.num_pool_validators as usize
// + state_account.state.validators_added as usize
// != validator_list.validators.len(),
// StewardError::ListStateMismatch
// );

// require!(
// state_account.state.validators_to_remove.count() > 0,
// StewardError::NoValidatorsToRemove
// )
// }

// How do we know if a validator has been removed?

Expand All @@ -42,15 +61,30 @@ pub fn handler(ctx: Context<IndexMismatchInterrupt>) -> Result<()> {
// Use diff amount to find correct index to remove
//TODO take out validator index to remove - we always remove the lowest index

{
require!(
state_account
.state
.validators_to_remove
.get(validator_index_to_remove)?,
StewardError::ValidatorNotMarkedForRemoval
);
}
let mut validator_index_to_remove = validator_list.validators.len();

// for i in smallest_index..validator_list.validators.len() {
// let validator = &validator_list.validators[i];
// let stake_status = StakeStatus::try_from(validator.status).unwrap();

// match stake_status {
// StakeStatus::Active => {
// // If what's coming up is active this means the validator has been removed and
// // shifted
// validator_index_to_remove = i;
// }
// StakeStatus::DeactivatingTransient
// | StakeStatus::ReadyForRemoval
// | StakeStatus::DeactivatingValidator
// | StakeStatus::DeactivatingAll => {
// // Index has not yet been removed
// }
// }

// if validator_index_to_remove != validator_list.validators.len() {
// break;
// }
// }

state_account
.state
Expand Down

0 comments on commit 8440c1b

Please sign in to comment.