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

Refactors startup verify with accounts lt hash #3318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brooksprumo
Copy link

Problem

While working on a branch to feature-gate accounts lt hash changes, I ran into issues in tests around startup accounts verification.

When the feature was enabled, I would get startup account verification mismatches. This is because the code to compute the accounts lt hash at startup from storages relies on generate_index() finding the duplicates lt hash. Since generate_index() runs before there is a Bank instance, that function cannot check if the feature is enabled or not. Instead it relies on the accounts lt hash cli arg. So if the feature is enabled and the cli arg is not, then generate_index() would not compute the duplicates lt hash, yet verify_accounts_hash() would need it.

Summary of Changes

  • Until we have snapshot support for the accounts lt hash, verify_accounts_hash() should only use the lattice verification when the cli arg is set.
  • generate_index() returns an Option of the duplicates lt hash, based on the cli arg. This makes it explicit when this paramter is valid or not.
  • Add test permutations to the snapshot integration tests to verify with lattice (and merkle) accounts hashing.

@brooksprumo brooksprumo self-assigned this Oct 25, 2024
Comment on lines +5626 to +5635
let verify_kind = if self
.rc
.accounts
.accounts_db
.is_experimental_accumulator_hash_enabled()
{
VerifyKind::Lattice
} else {
VerifyKind::Merkle
};
Copy link
Author

Choose a reason for hiding this comment

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

Here's the main change: we only look at the CLI arg to determine which hash kind to verify with.

Note that Bank::is_accounts_lt_hash_enabled() is the same as AccountsDb::is_experimental_accumulator_hash_enabled() today, but not when we add feature gate logic. This PR future proofs the feature gate changes, thus reducing future complexity.

Comment on lines +8794 to +8797
if self.is_experimental_accumulator_hash_enabled() {
let old_val = outer_duplicates_lt_hash.replace(duplicates_lt_hash);
assert!(old_val.is_none());
}
Copy link
Author

Choose a reason for hiding this comment

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

We now also wrap the duplicates lt hash, that generate_index() computes, in an Option. If the CLI arg is not set, we did not compute the duplicates. This Option makes that explicit.

In the future, we'll be able to check the snapshot if the accounts lt hash is enabled.

Comment on lines +638 to +643
/// Spin up the background services fully then test taking & verifying snapshots
#[test_matrix(
V1_2_0,
[Development, Devnet, Testnet, MainnetBeta],
[VerifyAccountsKind::Merkle, VerifyAccountsKind::Lattice]
)]
Copy link
Author

Choose a reason for hiding this comment

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

These changes add permutations on this snapshot test for verifying the accounts with both merkle and lattice based accounts hashing.

Comment on lines +5700 to +5701
match verify_kind {
VerifyKind::Lattice => {
Copy link
Author

Choose a reason for hiding this comment

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

I know the rest of the changes here look like a lot, but they are just moving from if {} else {} to a match with the VerifyKind arms. Ignoring whitespace in the diff will help. No logic was changed.

@brooksprumo brooksprumo marked this pull request as ready for review October 25, 2024 18:44
Copy link

@HaoranYi HaoranYi left a comment

Choose a reason for hiding this comment

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

By Introducing the enum VerifyKind variant and using it for hash verify instead of checking the feature enable makes the code clearer, a good improvment.

lgtm.

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.

2 participants