From 1f7ac22b60ab1644777bc95e795e546ee6deaf9d Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2020 17:25:15 -0700 Subject: [PATCH] Don't subject authorizing a new stake authority to lockup (#9434) (#9441) automerge --- programs/stake/src/stake_state.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/programs/stake/src/stake_state.rs b/programs/stake/src/stake_state.rs index d62841c2a9f7b1..3bb3dc35ae5d7e 100644 --- a/programs/stake/src/stake_state.rs +++ b/programs/stake/src/stake_state.rs @@ -151,7 +151,8 @@ impl Meta { ) -> Result<(), InstructionError> { // verify that lockup has expired or that the authorization // is *also* signed by the custodian - if self.lockup.is_in_force(clock, signers) { + if stake_authorize == StakeAuthorize::Withdrawer && self.lockup.is_in_force(clock, signers) + { return Err(StakeError::LockupInForce.into()); } self.authorized @@ -948,23 +949,28 @@ mod tests { meta.authorize(&staker, StakeAuthorize::Staker, &signers, &clock), Ok(()) ); - // verify lockup check + // verify staker not subject to lockup, but withdrawer is meta.lockup.epoch = 1; assert_eq!( meta.authorize(&staker, StakeAuthorize::Staker, &signers, &clock), + Ok(()) + ); + // verify lockup check + assert_eq!( + meta.authorize(&staker, StakeAuthorize::Withdrawer, &signers, &clock), Err(StakeError::LockupInForce.into()) ); // verify lockup check defeated by custodian signers.insert(custodian); assert_eq!( - meta.authorize(&staker, StakeAuthorize::Staker, &signers, &clock), + meta.authorize(&staker, StakeAuthorize::Withdrawer, &signers, &clock), Ok(()) ); // verify lock expiry signers.remove(&custodian); clock.epoch = 1; assert_eq!( - meta.authorize(&staker, StakeAuthorize::Staker, &signers, &clock), + meta.authorize(&staker, StakeAuthorize::Withdrawer, &signers, &clock), Ok(()) ); }