Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

More conservative purge_zero_lamport_accounts purge logic #7157

Merged
merged 1 commit into from
Dec 2, 2019

Conversation

sakridge
Copy link
Contributor

@sakridge sakridge commented Nov 27, 2019

Problem

Purging zero lamport accounts where the parent account's appendvec is not removed is not compatible with snapshots. Since the index is not serialized in the snapshot, the old view of the account could be revived.

Summary of Changes

Don't purge zero lamport accounts unless all AppendVecs containing parent accounts can be also removed.

Fixes #7117

@sakridge sakridge requested a review from ryoqun November 27, 2019 00:46
@sakridge sakridge force-pushed the conservative-purge branch 3 times, most recently from 72b0b31 to d9bfa39 Compare November 27, 2019 04:10
@codecov
Copy link

codecov bot commented Nov 27, 2019

Codecov Report

Merging #7157 into master will decrease coverage by 6.4%.
The diff coverage is 84.6%.

@@           Coverage Diff            @@
##           master   #7157     +/-   ##
========================================
- Coverage    79.3%   72.8%   -6.5%     
========================================
  Files         230     230             
  Lines       45117   49329   +4212     
========================================
+ Hits        35781   35919    +138     
- Misses       9336   13410   +4074

runtime/src/accounts_db.rs Outdated Show resolved Hide resolved
runtime/src/accounts_db.rs Outdated Show resolved Hide resolved
if let Some(slot_storage) = storage.0.get(&slot_id) {
if let Some(store) = slot_storage.get(&account_info.id) {
if let Some(store_count) = store_counts.get_mut(&account_info.id) {
*store_count -= 1;
Copy link
Contributor

@ryoqun ryoqun Nov 27, 2019

Choose a reason for hiding this comment

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

nits: it might be pedantic to avoid overflows? Or it never happens? Hmm, hard situation, but I might be able to write a test case for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it should be able to happen, but if you can think of any more tests that would be great.

runtime/src/accounts_db.rs Outdated Show resolved Hide resolved
runtime/src/accounts_db.rs Outdated Show resolved Hide resolved
runtime/src/accounts_db.rs Outdated Show resolved Hide resolved
@@ -1446,20 +1446,6 @@ impl Bank {
self.rc
.accounts
.verify_hash_internal_state(self.slot(), &self.ancestors)
&& !self.has_accounts_with_zero_lamports()
Copy link
Contributor

Choose a reason for hiding this comment

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

(note to myself: lifting this restriction is needed because we're purging 0-lamport accounts conservatively, however is this really OK so as not to cause shielding attacks? Maybe I'm still not sure about it completely or missing something.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, the requirement is not necessarily that there are no 0-lamport accounts, just that they do not alter the accounts view such that it would give incorrect results when the accounts db has operations performed on it. Removing all 0-lamport accounts was just an easy way to verify that there are no incorrect shielding accounts, but it wasn't correct.

We do some checks when we do verify_hash_internal_state that looks at all account paths from the root, I think we have to convince ourselves that this is enough or that we maybe need to make extra checks.

I have an idea to add another path which is like an aggressive purge_zero_lamport_accounts path which removes them from the index and then rewrites the AppendVec stores to not contain those accounts at all so that the accounts store is consistent, but I think that can be in a follow-up PR if required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see! Then, purging zero lamports account isn't set in stone as a hard requirement. That makes sense!

ryoqun
ryoqun previously requested changes Nov 27, 2019
Copy link
Contributor

@ryoqun ryoqun left a comment

Choose a reason for hiding this comment

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

Great work so far! So we've taken the conservative (or might be leaky) approach! I hope this generally works this time really. Finally my original concern over #7013 is vanishing.

This impl looks promising. However, still needs more rigorous thought for me to approve this. At the moment, first round of reviews are done! I need to cool down my head a bit...

@mergify mergify bot dismissed ryoqun’s stale review November 27, 2019 21:20

Pull request has been modified.

@sakridge sakridge force-pushed the conservative-purge branch 3 times, most recently from f4540a3 to 0baedac Compare December 1, 2019 00:56
pub fn purge_zero_lamport_accounts(&self, ancestors: &HashMap<u64, usize>) {
self.report_store_stats();
let mut purges = HashMap::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is exactly what I thought would have liked to see! But not bothered to write a comment. :p This way, we can reduce redundant call of would_purge around here. :)

@ryoqun
Copy link
Contributor

ryoqun commented Dec 2, 2019

@sakridge Thanks for addressing all review comments! This looks almost complete! Only remaining is at my part: Come up with a creative testcase (#7157 (comment)) and run this locally.

Also, I think the quality of this PR is well beyond being mere a draft PR. :)

@ryoqun ryoqun marked this pull request as ready for review December 2, 2019 05:05
Copy link
Contributor

@ryoqun ryoqun left a comment

Choose a reason for hiding this comment

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

I've tested this locally and it seems this works as intended!

LGTM!

@sakridge sakridge merged commit 887bff5 into solana-labs:master Dec 2, 2019
@sakridge sakridge deleted the conservative-purge branch December 2, 2019 17:51
@mvines mvines added the v0.21 label Dec 2, 2019
mergify bot pushed a commit that referenced this pull request Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

thread 'main' panicked at 'Snapshot bank failed to verify'
3 participants