Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct comment stating lockup gates stake authorize ixs #10063

Merged
merged 2 commits into from
May 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 2 additions & 53 deletions programs/stake/src/stake_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,11 @@ pub enum StakeAuthorize {

#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
pub struct Lockup {
/// UnixTimestamp at which this stake will allow withdrawal, or
/// changes to authorized staker or withdrawer, unless the
/// UnixTimestamp at which this stake will allow withdrawal, unless the
/// transaction is signed by the custodian
pub unix_timestamp: UnixTimestamp,
/// epoch height at which this stake will allow withdrawal, or
/// changes to authorized staker or withdrawer, unless the
/// epoch height at which this stake will allow withdrawal, unless the
/// transaction is signed by the custodian
/// to the custodian
pub epoch: Epoch,
/// custodian signature on a transaction exempts the operation from
/// lockup constraints
Expand Down Expand Up @@ -153,21 +150,6 @@ impl Meta {
}
Ok(())
}

pub fn authorize_withdraw(
&mut self,
authority: &Pubkey,
signers: &HashSet<Pubkey>,
clock: &Clock,
) -> 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) {
return Err(StakeError::LockupInForce.into());
}
self.authorized
.authorize(signers, authority, StakeAuthorize::Withdrawer)
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -949,39 +931,6 @@ mod tests {
);
}

#[test]
fn test_meta_authorize_withdraw() {
let staker = Pubkey::new_rand();
let custodian = Pubkey::new_rand();
let mut meta = Meta {
authorized: Authorized::auto(&staker),
lockup: Lockup {
epoch: 0,
unix_timestamp: 0,
custodian,
},
..Meta::default()
};
// verify sig check
let mut signers = HashSet::new();
signers.insert(staker);
let mut clock = Clock::default();

// verify lockup check
meta.lockup.epoch = 1;
assert_eq!(
meta.authorize_withdraw(&staker, &signers, &clock),
Err(StakeError::LockupInForce.into())
);
// verify lockup check defeated by custodian
signers.insert(custodian);
assert_eq!(meta.authorize_withdraw(&staker, &signers, &clock), Ok(()));
// verify lock expiry
signers.remove(&custodian);
clock.epoch = 1;
assert_eq!(meta.authorize_withdraw(&staker, &signers, &clock), Ok(()));
}

#[test]
fn test_stake_state_stake_from_fail() {
let mut stake_account = Account::new(0, std::mem::size_of::<StakeState>(), &id());
Expand Down