Skip to content

Commit

Permalink
Don't subject authorizing a new stake authority to lockup (#9434) (#9441
Browse files Browse the repository at this point in the history
)

automerge
  • Loading branch information
mergify[bot] committed Apr 11, 2020
1 parent 747deba commit 1f7ac22
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions programs/stake/src/stake_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(())
);
}
Expand Down

0 comments on commit 1f7ac22

Please sign in to comment.