Add versioning (#8348) (#8524)

automerge
This commit is contained in:
mergify[bot]
2020-02-27 20:12:49 -08:00
committed by GitHub
parent 082d8fff36
commit ac545cadaf
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)]
@@ -603,7 +603,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,
);
@@ -613,7 +613,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,
@@ -786,7 +786,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)
@@ -1007,7 +1008,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;
@@ -1065,7 +1069,7 @@ mod tests {
deactivation_epoch: std::u64::MAX,
..Delegation::default()
},
credits_observed: vote_state.credits(),
credits_observed: vote_state_credits,
..Stake::default()
}
);
@@ -1113,7 +1117,7 @@ mod tests {
deactivation_epoch: std::u64::MAX,
..Delegation::default()
},
credits_observed: vote_state.credits(),
credits_observed: vote_state_credits,
..Stake::default()
}
);
@@ -1543,7 +1547,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,
@@ -1632,7 +1638,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(
@@ -1756,7 +1764,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,
@@ -1865,7 +1875,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(