Deinit zero-lamport account data (bp #14242) (#14265)

* Deinitialize nonce data upon zero balance

(cherry picked from commit 3881ae10fb)

* vote: Add helper for creating current-versioned states

(cherry picked from commit 5b903318b2)

* Deinitialize vote data upon zero balance

(cherry picked from commit db5bd6ea1a)

* Deinitialize stake data upon zero balance

(cherry picked from commit 50710473a8)

Co-authored-by: Trent Nelson <trent@solana.com>
This commit is contained in:
mergify[bot]
2020-12-23 04:34:52 +00:00
committed by GitHub
parent 09a3b5001c
commit 6f2b37b015
15 changed files with 151 additions and 81 deletions

View File

@@ -204,6 +204,8 @@ impl Accounts {
})? {
SystemAccountKind::System => 0,
SystemAccountKind::Nonce => {
// Should we ever allow a fees charge to zero a nonce account's
// balance. The state MUST be set to uninitialized in that case
rent_collector.rent.minimum_balance(nonce::State::size())
}
};

View File

@@ -10731,7 +10731,7 @@ pub(crate) mod tests {
let mut vote_account = bank.get_account(vote_pubkey).unwrap_or_default();
let mut vote_state = VoteState::from(&vote_account).unwrap_or_default();
vote_state.last_timestamp = timestamp;
let versioned = VoteStateVersions::Current(Box::new(vote_state));
let versioned = VoteStateVersions::new_current(vote_state);
VoteState::to(&versioned, &mut vote_account).unwrap();
bank.store_account(vote_pubkey, &vote_account);
}

View File

@@ -116,7 +116,7 @@ mod tests {
let vote_state = VoteState::new(&vote_init, &clock);
let account = Account::new_data(
rng.gen(), // lamports
&VoteStateVersions::Current(Box::new(vote_state.clone())),
&VoteStateVersions::new_current(vote_state.clone()),
&Pubkey::new_unique(), // owner
)
.unwrap();