|
|
|
@ -195,7 +195,6 @@ impl Stakes {
|
|
|
|
|
&mut self,
|
|
|
|
|
pubkey: &Pubkey,
|
|
|
|
|
account: &AccountSharedData,
|
|
|
|
|
check_vote_init: bool,
|
|
|
|
|
remove_delegation_on_inactive: bool,
|
|
|
|
|
) -> Option<VoteAccount> {
|
|
|
|
|
if solana_vote_program::check_id(account.owner()) {
|
|
|
|
@ -205,9 +204,7 @@ impl Stakes {
|
|
|
|
|
let old = self.vote_accounts.remove(pubkey);
|
|
|
|
|
// when account is removed (lamports == 0 or data uninitialized), don't read so that
|
|
|
|
|
// given `pubkey` can be used for any owner in the future, while not affecting Stakes.
|
|
|
|
|
if account.lamports() != 0
|
|
|
|
|
&& !(check_vote_init && VoteState::is_uninitialized_no_deser(account.data()))
|
|
|
|
|
{
|
|
|
|
|
if account.lamports() != 0 && !VoteState::is_uninitialized_no_deser(account.data()) {
|
|
|
|
|
let stake = old.as_ref().map_or_else(
|
|
|
|
|
|| self.calculate_stake(pubkey, self.epoch, Some(&self.stake_history)),
|
|
|
|
|
|v| v.0,
|
|
|
|
@ -378,8 +375,8 @@ pub mod tests {
|
|
|
|
|
let ((vote_pubkey, vote_account), (stake_pubkey, mut stake_account)) =
|
|
|
|
|
create_staked_node_accounts(10);
|
|
|
|
|
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
let stake = stake_state::stake_from(&stake_account).unwrap();
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -391,7 +388,7 @@ pub mod tests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stake_account.set_lamports(42);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
|
assert!(vote_accounts.get(&vote_pubkey).is_some());
|
|
|
|
@ -403,7 +400,7 @@ pub mod tests {
|
|
|
|
|
|
|
|
|
|
// activate more
|
|
|
|
|
let (_stake_pubkey, mut stake_account) = create_stake_account(42, &vote_pubkey);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
let stake = stake_state::stake_from(&stake_account).unwrap();
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -415,7 +412,7 @@ pub mod tests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stake_account.set_lamports(0);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
|
assert!(vote_accounts.get(&vote_pubkey).is_some());
|
|
|
|
@ -433,14 +430,14 @@ pub mod tests {
|
|
|
|
|
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
|
|
|
|
|
create_staked_node_accounts(10);
|
|
|
|
|
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
|
|
|
|
|
let ((vote11_pubkey, vote11_account), (stake11_pubkey, stake11_account)) =
|
|
|
|
|
create_staked_node_accounts(20);
|
|
|
|
|
|
|
|
|
|
stakes.store(&vote11_pubkey, &vote11_account, true, true);
|
|
|
|
|
stakes.store(&stake11_pubkey, &stake11_account, true, true);
|
|
|
|
|
stakes.store(&vote11_pubkey, &vote11_account, true);
|
|
|
|
|
stakes.store(&stake11_pubkey, &stake11_account, true);
|
|
|
|
|
|
|
|
|
|
let vote11_node_pubkey = VoteState::from(&vote11_account).unwrap().node_pubkey;
|
|
|
|
|
|
|
|
|
@ -457,8 +454,8 @@ pub mod tests {
|
|
|
|
|
let ((vote_pubkey, mut vote_account), (stake_pubkey, stake_account)) =
|
|
|
|
|
create_staked_node_accounts(10);
|
|
|
|
|
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -467,7 +464,7 @@ pub mod tests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vote_account.set_lamports(0);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -475,7 +472,7 @@ pub mod tests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vote_account.set_lamports(1);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -488,7 +485,7 @@ pub mod tests {
|
|
|
|
|
let mut pushed = vote_account.data().to_vec();
|
|
|
|
|
pushed.push(0);
|
|
|
|
|
vote_account.set_data(pushed);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -499,7 +496,7 @@ pub mod tests {
|
|
|
|
|
let default_vote_state = VoteState::default();
|
|
|
|
|
let versioned = VoteStateVersions::new_current(default_vote_state);
|
|
|
|
|
VoteState::to(&versioned, &mut vote_account).unwrap();
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -507,7 +504,7 @@ pub mod tests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vote_account.set_data(cache_data);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -529,11 +526,11 @@ pub mod tests {
|
|
|
|
|
let ((vote_pubkey2, vote_account2), (_stake_pubkey2, stake_account2)) =
|
|
|
|
|
create_staked_node_accounts(10);
|
|
|
|
|
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey2, &vote_account2, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
stakes.store(&vote_pubkey2, &vote_account2, true);
|
|
|
|
|
|
|
|
|
|
// delegates to vote_pubkey
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
|
|
|
|
|
let stake = stake_state::stake_from(&stake_account).unwrap();
|
|
|
|
|
|
|
|
|
@ -549,7 +546,7 @@ pub mod tests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delegates to vote_pubkey2
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account2, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account2, true);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -574,11 +571,11 @@ pub mod tests {
|
|
|
|
|
|
|
|
|
|
let (stake_pubkey2, stake_account2) = create_stake_account(10, &vote_pubkey);
|
|
|
|
|
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
|
|
|
|
|
// delegates to vote_pubkey
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey2, &stake_account2, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
stakes.store(&stake_pubkey2, &stake_account2, true);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -594,8 +591,8 @@ pub mod tests {
|
|
|
|
|
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
|
|
|
|
|
create_staked_node_accounts(10);
|
|
|
|
|
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
let stake = stake_state::stake_from(&stake_account).unwrap();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
@ -623,8 +620,8 @@ pub mod tests {
|
|
|
|
|
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
|
|
|
|
|
create_staked_node_accounts(10);
|
|
|
|
|
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
let stake = stake_state::stake_from(&stake_account).unwrap();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
@ -655,8 +652,8 @@ pub mod tests {
|
|
|
|
|
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
|
|
|
|
|
create_staked_node_accounts(10);
|
|
|
|
|
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -669,7 +666,6 @@ pub mod tests {
|
|
|
|
|
&stake_pubkey,
|
|
|
|
|
&AccountSharedData::new(1, 0, &stake::program::id()),
|
|
|
|
|
true,
|
|
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -699,8 +695,8 @@ pub mod tests {
|
|
|
|
|
let genesis_epoch = 0;
|
|
|
|
|
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
|
|
|
|
|
create_warming_staked_node_accounts(10, genesis_epoch);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true, true);
|
|
|
|
|
stakes.store(&vote_pubkey, &vote_account, true);
|
|
|
|
|
stakes.store(&stake_pubkey, &stake_account, true);
|
|
|
|
|
|
|
|
|
|
assert_eq!(stakes.vote_balance_and_staked(), 11);
|
|
|
|
|
assert_eq!(stakes.vote_balance_and_warmed_staked(), 1);
|
|
|
|
|