Skip to content

Commit

Permalink
Force state transitions to Idle before doing work in new epoch (#82)
Browse files Browse the repository at this point in the history
Currently a single lingering ComputeInstantUnstake or Rebalance step can
be executed if the Steward was left in this state after rolling over to
a new epoch. This can affect stake based on outdated information which
we don't want. Force the transition to Idle so everything is handled
normally.
  • Loading branch information
ebatsell authored Sep 11, 2024
1 parent 68900c1 commit 9585307
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions programs/steward/src/instructions/compute_instant_unstake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ pub fn handler(ctx: Context<ComputeInstantUnstake>, validator_list_index: usize)
let clock = Clock::get()?;
let epoch_schedule = EpochSchedule::get()?;

// Transitions to Idle before doing compute_instant_unstake if RESET_TO_IDLE is set
if let Some(event) = maybe_transition(
&mut state_account.state,
&clock,
&config.parameters,
&epoch_schedule,
)? {
emit!(event);
return Ok(());
}

state_checks(
&clock,
&config,
Expand Down
11 changes: 11 additions & 0 deletions programs/steward/src/instructions/rebalance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ pub fn handler(ctx: Context<Rebalance>, validator_list_index: usize) -> Result<(
{
let mut state_account = ctx.accounts.state_account.load_mut()?;

// Transitions to Idle before doing rebalance if RESET_TO_IDLE is set
if let Some(event) = maybe_transition(
&mut state_account.state,
&clock,
&config.parameters,
&epoch_schedule,
)? {
emit!(event);
return Ok(());
}

state_checks(
&clock,
&config,
Expand Down

0 comments on commit 9585307

Please sign in to comment.