Skip to content

Commit

Permalink
Fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell committed Jun 24, 2024
1 parent 2124bbe commit 235c003
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 49 deletions.
187 changes: 182 additions & 5 deletions programs/steward/idl/steward.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"address": "Stewardf95sJbmtcZsyagb2dg4Mo8eVQho8gpECvLx8",
"address": "sssh4zkKhX8jXTNQz1xDHyGpygzgu2UhcRcUvZihBjP",
"metadata": {
"name": "steward",
"version": "0.1.0",
Expand Down Expand Up @@ -56,6 +56,10 @@
{
"name": "config"
},
{
"name": "steward_state",
"writable": true
},
{
"name": "stake_pool_program"
},
Expand Down Expand Up @@ -134,10 +138,14 @@
],
"accounts": [
{
"name": "validator_history_account"
"name": "config"
},
{
"name": "config"
"name": "steward_state",
"writable": true
},
{
"name": "validator_history_account"
},
{
"name": "stake_pool_program"
Expand Down Expand Up @@ -285,6 +293,43 @@
}
]
},
{
"name": "close_steward_accounts",
"docs": [
"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"
],
"discriminator": [
172,
171,
212,
186,
90,
10,
181,
24
],
"accounts": [
{
"name": "config"
},
{
"name": "staker",
"writable": true
},
{
"name": "state_account",
"writable": true
},
{
"name": "authority",
"writable": true,
"signer": true
}
],
"args": []
},
{
"name": "compute_delegations",
"docs": [
Expand Down Expand Up @@ -587,6 +632,45 @@
}
]
},
{
"name": "epoch_maintenance",
"docs": [
"Housekeeping, run at the start of any new epoch before any other instructions"
],
"discriminator": [
208,
225,
211,
82,
219,
242,
58,
200
],
"accounts": [
{
"name": "config"
},
{
"name": "state_account",
"writable": true
},
{
"name": "validator_list"
},
{
"name": "stake_pool"
}
],
"args": [
{
"name": "validator_index_to_remove",
"type": {
"option": "u64"
}
}
]
},
{
"name": "idle",
"docs": [
Expand Down Expand Up @@ -1145,6 +1229,43 @@
}
]
},
{
"name": "reset_steward_state",
"docs": [
"Resets steward state account to its initial state."
],
"discriminator": [
84,
248,
158,
46,
200,
205,
234,
86
],
"accounts": [
{
"name": "state_account",
"writable": true
},
{
"name": "config"
},
{
"name": "stake_pool"
},
{
"name": "validator_list"
},
{
"name": "authority",
"writable": true,
"signer": true
}
],
"args": []
},
{
"name": "resume_steward",
"discriminator": [
Expand Down Expand Up @@ -1560,6 +1681,31 @@
"code": 6022,
"name": "ValidatorHistoryMismatch",
"msg": "Validator history account does not match vote account"
},
{
"code": 6023,
"name": "EpochMaintenanceNotComplete",
"msg": "Epoch Maintenance must be called before continuing"
},
{
"code": 6024,
"name": "StakePoolNotUpdated",
"msg": "The stake pool must be updated before continuing"
},
{
"code": 6025,
"name": "ValidatorNotMarkedForRemoval",
"msg": "Validator not marked for removal"
},
{
"code": 6026,
"name": "ValidatorsHaveNotBeenRemoved",
"msg": "Validators have not been removed"
},
{
"code": 6027,
"name": "ListStateMismatch",
"msg": "Validator List count does not match state machine"
}
],
"types": [
Expand Down Expand Up @@ -2250,7 +2396,8 @@
"name": "StewardState",
"docs": [
"Tracks state of the stake pool.",
"Follow state transitions here: [TODO add link to github diagram]"
"Follow state transitions here:",
"https://github.com/jito-foundation/stakenet/blob/master/programs/steward/state-machine-diagram.png"
],
"serialization": "bytemuck",
"repr": {
Expand Down Expand Up @@ -2369,6 +2516,18 @@
}
}
},
{
"name": "validators_to_remove",
"docs": [
"Marks a validator for removal after `remove_validator_from_pool` has been called on the stake pool",
"This is cleaned up in the next epoch"
],
"type": {
"defined": {
"name": "BitMask"
}
}
},
{
"name": "start_computing_scores_slot",
"docs": [
Expand Down Expand Up @@ -2419,6 +2578,13 @@
],
"type": "u64"
},
{
"name": "validators_added",
"docs": [
"Number of validators added to the pool in the current cycle"
],
"type": "u16"
},
{
"name": "compute_delegations_completed",
"docs": [
Expand All @@ -2441,6 +2607,17 @@
}
}
},
{
"name": "checked_validators_removed_from_list",
"docs": [
"So we only have to check the validator list once for `ReadyToRemove`"
],
"type": {
"defined": {
"name": "U8Bool"
}
}
},
{
"name": "_padding0",
"docs": [
Expand All @@ -2449,7 +2626,7 @@
"type": {
"array": [
"u8",
40006
40003
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion programs/steward/src/instructions/compute_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn handler(ctx: Context<ComputeScore>, validator_list_index: usize) -> Resul
validator_list_index,
&cluster_history,
&config,
num_pool_validators,
num_pool_validators as u64,
)?;

maybe_transition_and_emit(
Expand Down
16 changes: 10 additions & 6 deletions programs/steward/src/instructions/epoch_maintenance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
errors::StewardError,
utils::{
check_validator_list_has_stake_status, get_stake_pool, get_validator_list_length, StakePool,
check_validator_list_has_stake_status, deserialize_stake_pool, get_stake_pool_address,
get_validator_list_length,
},
Config, StewardStateAccount,
};
Expand All @@ -19,13 +20,15 @@ pub struct EpochMaintenance<'info> {
)]
pub state_account: AccountLoader<'info, StewardStateAccount>,

#[account(mut, address = stake_pool.validator_list)]
/// CHECK: Correct account guaranteed if address is correct
#[account(address = deserialize_stake_pool(&stake_pool)?.validator_list)]
pub validator_list: AccountInfo<'info>,

/// CHECK: Correct account guaranteed if address is correct
#[account(
address = get_stake_pool(&config)?
address = get_stake_pool_address(&config)?
)]
pub stake_pool: Account<'info, StakePool>,
pub stake_pool: AccountInfo<'info>,
}

/// Runs maintenance tasks at the start of each epoch, needs to be run multiple times
Expand All @@ -35,7 +38,7 @@ pub fn handler(
ctx: Context<EpochMaintenance>,
validator_index_to_remove: Option<usize>,
) -> Result<()> {
let stake_pool = &ctx.accounts.stake_pool;
let stake_pool = deserialize_stake_pool(&ctx.accounts.stake_pool)?;
let mut state_account = ctx.accounts.state_account.load_mut()?;

let clock = Clock::get()?;
Expand Down Expand Up @@ -65,7 +68,8 @@ pub fn handler(

// Ensure we have a 1-1 mapping between the number of validators in the list and the number of validators in the state
require!(
state_account.state.num_pool_validators + state_account.state.validators_added as usize
state_account.state.num_pool_validators as usize
+ state_account.state.validators_added as usize
- validators_to_remove
== validators_in_list,
StewardError::ListStateMismatch
Expand Down
12 changes: 7 additions & 5 deletions programs/steward/src/instructions/reset_steward_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
constants::{MAX_VALIDATORS, SORTED_INDEX_DEFAULT},
errors::StewardError,
state::{Config, StewardStateAccount},
utils::{get_config_authority, get_stake_pool, StakePool},
utils::{deserialize_stake_pool, get_config_authority, get_stake_pool_address},
BitMask, Delegation, StewardStateEnum, STATE_PADDING_0_SIZE,
};
use anchor_lang::prelude::*;
Expand All @@ -19,10 +19,12 @@ pub struct ResetStewardState<'info> {

pub config: AccountLoader<'info, Config>,

#[account(address = get_stake_pool(&config)?)]
pub stake_pool: Account<'info, StakePool>,
/// CHECK: Correct account guaranteed if address is correct
#[account(address = get_stake_pool_address(&config)?)]
pub stake_pool: AccountInfo<'info>,

#[account(address = stake_pool.validator_list)]
/// CHECK: Correct account guaranteed if address is correct
#[account(address = deserialize_stake_pool(&stake_pool)?.validator_list)]
pub validator_list: AccountInfo<'info>,

#[account(mut, address = get_config_authority(&config)?)]
Expand All @@ -44,7 +46,7 @@ pub fn handler(ctx: Context<ResetStewardState>) -> Result<()> {
let (_, validator_list) = ValidatorListHeader::deserialize_vec(validator_list_data)?;

state_account.state.state_tag = StewardStateEnum::ComputeScores;
state_account.state.num_pool_validators = validator_list.len() as usize;
state_account.state.num_pool_validators = validator_list.len() as u64;
state_account.state.scores = [0; MAX_VALIDATORS];
state_account.state.sorted_score_indices = [SORTED_INDEX_DEFAULT; MAX_VALIDATORS];
state_account.state.yield_scores = [0; MAX_VALIDATORS];
Expand Down
6 changes: 3 additions & 3 deletions programs/steward/src/instructions/spl_passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub struct RemoveValidatorFromPool<'info> {
/// CHECK: passing through, checks are done by spl-stake-pool
pub withdraw_authority: AccountInfo<'info>,
/// CHECK: passing through, checks are done by spl-stake-pool
#[account(mut)]
#[account(mut, address = deserialize_stake_pool(&stake_pool)?.validator_list)]
pub validator_list: AccountInfo<'info>,
/// CHECK: passing through, checks are done by spl-stake-pool
#[account(mut)]
Expand Down Expand Up @@ -335,7 +335,7 @@ pub struct IncreaseValidatorStake<'info> {
/// CHECK: passing through, checks are done by spl-stake-pool
pub withdraw_authority: AccountInfo<'info>,
/// CHECK: passing through, checks are done by spl-stake-pool
#[account(mut, address = stake_pool.validator_list)]
#[account(mut, address = deserialize_stake_pool(&stake_pool)?.validator_list)]
pub validator_list: AccountInfo<'info>,
/// CHECK: passing through, checks are done by spl-stake-pool
#[account(
Expand Down Expand Up @@ -464,7 +464,7 @@ pub struct DecreaseValidatorStake<'info> {
/// CHECK: passing through, checks are done by spl-stake-pool
pub withdraw_authority: AccountInfo<'info>,
/// CHECK: passing through, checks are done by spl-stake-pool
#[account(mut, address = stake_pool.validator_list)]
#[account(mut, address = deserialize_stake_pool(&stake_pool)?.validator_list)]
pub validator_list: AccountInfo<'info>,
/// CHECK: passing through, checks are done by spl-stake-pool
#[account(
Expand Down
Loading

0 comments on commit 235c003

Please sign in to comment.