Skip to content

Commit

Permalink
Refactors purging old accounts hashes in AccountsHashVerifier (solana…
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored May 17, 2024
1 parent 8f9fc2a commit a7dd8d6
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions core/src/accounts_hash_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ impl AccountsHashVerifier {

Self::save_epoch_accounts_hash(&accounts_package, accounts_hash);

Self::purge_old_accounts_hashes(&accounts_package, snapshot_config);

Self::submit_for_packaging(
accounts_package,
snapshot_package_sender,
Expand Down Expand Up @@ -324,15 +326,6 @@ impl AccountsHashVerifier {
})?;
}

if accounts_package.package_kind
== AccountsPackageKind::Snapshot(SnapshotKind::FullSnapshot)
{
accounts_package
.accounts
.accounts_db
.purge_old_accounts_hashes(accounts_package.slot);
}

// After an accounts package has had its accounts hash calculated and
// has been reserialized to become a BankSnapshotPost, it is now safe
// to clean up some older bank snapshots.
Expand Down Expand Up @@ -499,6 +492,37 @@ impl AccountsHashVerifier {
}
}

fn purge_old_accounts_hashes(
accounts_package: &AccountsPackage,
snapshot_config: &SnapshotConfig,
) {
let should_purge = match (
snapshot_config.should_generate_snapshots(),
accounts_package.package_kind,
) {
(false, _) => {
// If we are *not* generating snapshots, then it is safe to purge every time.
true
}
(true, AccountsPackageKind::Snapshot(SnapshotKind::FullSnapshot)) => {
// If we *are* generating snapshots, then only purge old accounts hashes after
// handling full snapshot packages. This is because handling incremental snapshot
// packages requires the accounts hash from the latest full snapshot, and if we
// purged after every package, we'd remove the accounts hash needed by the next
// incremental snapshot.
true
}
(true, _) => false,
};

if should_purge {
accounts_package
.accounts
.accounts_db
.purge_old_accounts_hashes(accounts_package.slot);
}
}

fn submit_for_packaging(
accounts_package: AccountsPackage,
snapshot_package_sender: Option<&Sender<SnapshotPackage>>,
Expand Down

0 comments on commit a7dd8d6

Please sign in to comment.