Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
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
16 changes: 16 additions & 0 deletions runtime/src/stakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ impl Stakes {
fix_stake_deactivate: bool,
) -> Option<ArcVoteAccount> {
if solana_vote_program::check_id(&account.owner) {
// unconditionally remove existing at first; there is no dependent calculated state for
// votes, not like stakes (stake codepath maintains calculated stake value grouped by
// delegated vote pubkey)
let old = self.vote_accounts.remove(pubkey);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here.

// when account is removed (lamports == 0), don't readd so that given
// `pubkey` can be used for any owner in the future, while not
// affecting Stakes.
if account.lamports != 0 {
let stake = old.as_ref().map_or_else(
|| {
Expand Down Expand Up @@ -162,6 +168,9 @@ impl Stakes {
fix_stake_deactivate,
)
} else {
// when account is removed (lamports == 0), this special `else` clause ensures
// resetting cached stake value below, even if the account happens to be
// still staked for some (odd) reason
0
},
)
Expand All @@ -182,12 +191,19 @@ impl Stakes {
}

if account.lamports == 0 {
// when account is removed (lamports == 0), remove it from Stakes as well
// so that given `pubkey` can be used for any owner in the future, while not
// affecting Stakes.
self.stake_delegations.remove(pubkey);
} else if let Some(delegation) = delegation {
self.stake_delegations.insert(*pubkey, delegation);
}
None
} else {
// there is no need to remove possibly existing Stakes cache entries with given
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CriesofCarrots Account::default() was hitting here in #14062.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

// `pubkey` because this isn't possible, first of all.
// Runtime always enforces an intermediary write of account.lamports == 0,
// when not-System111-owned account.owner is swapped.
None
}
}
Expand Down