|
|
|
@ -193,7 +193,6 @@ impl Stakes {
|
|
|
|
|
&mut self,
|
|
|
|
|
pubkey: &Pubkey,
|
|
|
|
|
account: &AccountSharedData,
|
|
|
|
|
check_vote_init: bool,
|
|
|
|
|
remove_delegation_on_inactive: bool,
|
|
|
|
|
) {
|
|
|
|
|
if solana_vote_program::check_id(account.owner()) {
|
|
|
|
@ -203,10 +202,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.
|
|
|
|
|
let vote_init_check_disabled = !check_vote_init;
|
|
|
|
|
if account.lamports() != 0
|
|
|
|
|
&& (vote_init_check_disabled
|
|
|
|
|
|| VoteState::is_correct_size_and_initialized(account.data()))
|
|
|
|
|
if account.lamports() != 0 && VoteState::is_correct_size_and_initialized(account.data())
|
|
|
|
|
{
|
|
|
|
|
let stake = old.as_ref().map_or_else(
|
|
|
|
|
|| self.calculate_stake(pubkey, self.epoch, Some(&self.stake_history)),
|
|
|
|
@ -375,8 +371,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();
|
|
|
|
@ -388,7 +384,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());
|
|
|
|
@ -400,7 +396,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();
|
|
|
|
@ -412,7 +408,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());
|
|
|
|
@ -430,14 +426,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;
|
|
|
|
|
|
|
|
|
@ -454,8 +450,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();
|
|
|
|
@ -464,7 +460,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();
|
|
|
|
@ -472,7 +468,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();
|
|
|
|
@ -485,7 +481,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();
|
|
|
|
@ -496,7 +492,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();
|
|
|
|
@ -504,7 +500,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();
|
|
|
|
@ -526,11 +522,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();
|
|
|
|
|
|
|
|
|
@ -546,7 +542,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();
|
|
|
|
@ -571,11 +567,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();
|
|
|
|
@ -591,8 +587,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();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
@ -620,8 +616,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();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
@ -652,8 +648,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();
|
|
|
|
@ -666,7 +662,6 @@ pub mod tests {
|
|
|
|
|
&stake_pubkey,
|
|
|
|
|
&AccountSharedData::new(1, 0, &stake::program::id()),
|
|
|
|
|
true,
|
|
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
{
|
|
|
|
|
let vote_accounts = stakes.vote_accounts();
|
|
|
|
@ -696,8 +691,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);
|
|
|
|
|