Add versioning (#8348)

automerge
This commit is contained in:
carllin
2020-02-25 17:12:01 -08:00
committed by GitHub
parent 6b99ab3a57
commit d821fd29d6
11 changed files with 318 additions and 102 deletions

View File

@ -14,7 +14,7 @@ use solana_sdk::{
rent::Rent,
stake_history::{StakeHistory, StakeHistoryEntry},
};
use solana_vote_program::vote_state::VoteState;
use solana_vote_program::vote_state::{VoteState, VoteStateVersions};
use std::collections::HashSet;
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
@ -595,7 +595,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
let stake = Stake::new(
self.lamports()?.saturating_sub(meta.rent_exempt_reserve), // can't stake the rent ;)
vote_account.unsigned_key(),
&vote_account.state()?,
&State::<VoteStateVersions>::state(vote_account)?.convert_to_current(),
clock.epoch,
config,
);
@ -605,7 +605,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
meta.authorized.check(signers, StakeAuthorize::Staker)?;
stake.redelegate(
vote_account.unsigned_key(),
&vote_account.state()?,
&State::<VoteStateVersions>::state(vote_account)?.convert_to_current(),
clock,
stake_history,
config,
@ -778,7 +778,8 @@ pub fn redeem_rewards(
stake_history: Option<&StakeHistory>,
) -> Result<(u64, u64), InstructionError> {
if let StakeState::Stake(meta, mut stake) = stake_account.state()? {
let vote_state = vote_account.state()?;
let vote_state: VoteState =
StateMut::<VoteStateVersions>::state(vote_account)?.convert_to_current();
if let Some((voters_reward, stakers_reward)) =
stake.redeem_rewards(point_value, &vote_state, stake_history)
@ -999,7 +1000,10 @@ mod tests {
100,
));
let vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &vote_account);
vote_keyed_account.set_state(&vote_state).unwrap();
let vote_state_credits = vote_state.credits();
vote_keyed_account
.set_state(&VoteStateVersions::Current(Box::new(vote_state)))
.unwrap();
let stake_pubkey = Pubkey::new_rand();
let stake_lamports = 42;
@ -1057,7 +1061,7 @@ mod tests {
deactivation_epoch: std::u64::MAX,
..Delegation::default()
},
credits_observed: vote_state.credits(),
credits_observed: vote_state_credits,
..Stake::default()
}
);
@ -1105,7 +1109,7 @@ mod tests {
deactivation_epoch: std::u64::MAX,
..Delegation::default()
},
credits_observed: vote_state.credits(),
credits_observed: vote_state_credits,
..Stake::default()
}
);
@ -1535,7 +1539,9 @@ mod tests {
100,
));
let vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &vote_account);
vote_keyed_account.set_state(&VoteState::default()).unwrap();
vote_keyed_account
.set_state(&VoteStateVersions::Current(Box::new(VoteState::default())))
.unwrap();
assert_eq!(
stake_keyed_account.delegate(
&vote_keyed_account,
@ -1624,7 +1630,9 @@ mod tests {
100,
));
let vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &vote_account);
vote_keyed_account.set_state(&VoteState::default()).unwrap();
vote_keyed_account
.set_state(&VoteStateVersions::Current(Box::new(VoteState::default())))
.unwrap();
stake_keyed_account
.delegate(
@ -1748,7 +1756,9 @@ mod tests {
100,
));
let vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &vote_account);
vote_keyed_account.set_state(&VoteState::default()).unwrap();
vote_keyed_account
.set_state(&VoteStateVersions::Current(Box::new(VoteState::default())))
.unwrap();
assert_eq!(
stake_keyed_account.delegate(
&vote_keyed_account,
@ -1857,7 +1867,9 @@ mod tests {
100,
));
let vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &vote_account);
vote_keyed_account.set_state(&VoteState::default()).unwrap();
vote_keyed_account
.set_state(&VoteStateVersions::Current(Box::new(VoteState::default())))
.unwrap();
let signers = vec![stake_pubkey].into_iter().collect();
assert_eq!(
stake_keyed_account.delegate(