Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow test feature to skip rewrites #33851

Merged
merged 13 commits into from
Oct 27, 2023
Merged

Conversation

jeffwashington
Copy link
Contributor

Problem

When the feature to disable rewrites during rent collection is enabled, rent exempt accounts will not be rewritten during rent collection. And, consensus will not expect those accounts to be rewritten.
However, prior to that feature being activated, it is now possible for a validator to avoid rewrites (and improve performance), while still creating compatible bank hashes.

Summary of Changes

With a test option, during rent collection, do not do rewrites on rent exempt accounts. But, include the hashes into the bank hash's accounts delta hash so the validator remains compatible with consensus.
This allows us to test the long term effects of eliminating rewrites.

Fixes #

@HaoranYi HaoranYi self-assigned this Oct 25, 2023
@codecov
Copy link

codecov bot commented Oct 25, 2023

Codecov Report

Merging #33851 (48c875d) into master (9ffbe2a) will decrease coverage by 0.1%.
Report is 13 commits behind head on master.
The diff coverage is 81.6%.

@@            Coverage Diff            @@
##           master   #33851     +/-   ##
=========================================
- Coverage    81.9%    81.8%   -0.1%     
=========================================
  Files         809      809             
  Lines      217717   217761     +44     
=========================================
- Hits       178345   178329     -16     
- Misses      39372    39432     +60     

@HaoranYi HaoranYi requested a review from brooksprumo October 25, 2023 15:50
@HaoranYi HaoranYi marked this pull request as ready for review October 25, 2023 15:51
@HaoranYi
Copy link
Contributor

@jeffwashington can you take a look? thanks!

@@ -764,7 +768,7 @@ mod serde_snapshot_tests {
// F: Finally, make Step A cleanable
current_slot += 1;
accounts.store_for_tests(current_slot, &[(&pubkey2, &account)]);
accounts.calculate_accounts_delta_hash(current_slot);
accounts.calculate_accounts_delta_hash(current_slot, Vec::default());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems like we should probably make a calculate_accounts_delta_hash_with_skips fn that takes the Vec and leave the signature of calculate_accounts_delta_hash the same.
I should've done that initially. That would remove all this test noise. Once all features are activated, we'll be removing this arg and all these tests would just have to go back.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah. updated.

.arg(
Arg::with_name("accounts_db_test_skip_rewrites_but_include_in_bank_hash")
.long("accounts-db-test-skip-rewrites-but-include-in-bank-hash")
.help("Debug option to skip rewrites for rent exempted accounts but still added them in bank delta hash calculation")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rent exempt. Remove ed
add them. Remove ed

Copy link
Contributor

Choose a reason for hiding this comment

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

yes updated.

@@ -1194,6 +1194,12 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.help("Debug option to scan all append vecs and verify account index refcounts prior to clean")
.hidden(hidden_unless_forced())
)
.arg(
Arg::with_name("accounts_db_test_skip_rewrites_but_include_in_bank_hash")
.long("accounts-db-test-skip-rewrites-but-include-in-bank-hash")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

my words here are so verbose. @brooksprumo or @HaoranYi do you have any better ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

How about just accounts-db-test-skip-rewrites? Since it's testing-only and hidden, it really only needs to make sense to us.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes. updated.

@@ -1243,7 +1243,7 @@ pub enum ZeroLamportAccounts {

/// Hash of an account
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Pod, Zeroable)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Pod, Zeroable, AbiExample)]
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 guess this is caused by the addition of the rewrites on Bank?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah.

ledger-tool/src/main.rs Outdated Show resolved Hide resolved
runtime/src/bank.rs Outdated Show resolved Hide resolved
accounts-db/src/accounts_db.rs Outdated Show resolved Hide resolved
runtime/src/bank.rs Outdated Show resolved Hide resolved
runtime/src/bank.rs Outdated Show resolved Hide resolved
@jeffwashington
Copy link
Contributor Author

jeffwashington commented Oct 26, 2023 via email

@brooksprumo
Copy link
Contributor

I think a read is going to run every slot, right?

There are no read locks in the current impl, only write locks.

@HaoranYi
Copy link
Contributor

HaoranYi commented Oct 26, 2023

There seems to be a bug in fn calculate_accounts_delta_hash_internal.

When calling this fn, it has the side effect of clearing skipped_rewrites. If the function is called again, i.e. rehash() by snapshot, it will yield a different hash.

A fix could be as follows - do not clear skipped_rewrites. And to be safe, we clear skipped_rewrites before rent collection.

WDYT?

diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs
index 6313a57904..bda8da0b51 100644
--- a/runtime/src/bank.rs
+++ b/runtime/src/bank.rs
@@ -5901,6 +5901,7 @@ impl Bank {
         let partitions = self.rent_collection_partitions();
         let count = partitions.len();
         let rent_metrics = RentMetrics::default();
+        self.skipped_rewrites.write().unwrap().clear();
         // partitions will usually be 1, but could be more if we skip slots
         let mut parallel = count > 1;
         if parallel {
@@ -7103,7 +7104,7 @@ impl Bank {
             .calculate_accounts_delta_hash_internal(
                 slot,
                 ignore,
-                std::mem::take(&mut self.skipped_rewrites.write().unwrap()),
+                self.skipped_rewrites.write().unwrap().clone(),
             );

         let mut signature_count_buf = [0u8; 8];

@jeffwashington
Copy link
Contributor Author

i.e. rehash() by

The two places that call rehash() have this comment:
/// This is only called from ledger-tool or tests. Warping is a special case as well.

I think we can ignore these use cases. There will only be interesting info in skipped_rewrites when this debug option is turned on.

@jeffwashington
Copy link
Contributor Author

I think a read is going to run every slot, right?

There are no read locks in the current impl, only write locks.

I was considering this a read, but you are right, it is technically a write:
std::mem::take(&mut self.skipped_rewrites.write().unwrap()),

@HaoranYi HaoranYi requested a review from brooksprumo October 26, 2023 15:16
runtime/src/bank.rs Outdated Show resolved Hide resolved
runtime/src/bank.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

lgtm!

@HaoranYi HaoranYi merged commit a18debc into solana-labs:master Oct 27, 2023
7 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants