Skip to content

Commit

Permalink
abs: Refactor determining the accounts package type (solana-labs#27944)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Sep 21, 2022
1 parent 6e24edb commit ceac6a1
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions runtime/src/accounts_background_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ impl SnapshotRequestHandler {
.last()
.map(|snapshot_request| {
let mut total_time = Measure::start("snapshot_request_receiver_total_time");
let accounts_package_type = new_accounts_package_type(&snapshot_request, &self.snapshot_config, *last_full_snapshot_slot);
let SnapshotRequest {
snapshot_root_bank,
status_cache_slot_deltas,
request_type,
request_type: _request_type,
} = snapshot_request;

// we should not rely on the state of this validator until startup verification is complete
Expand Down Expand Up @@ -228,21 +229,9 @@ impl SnapshotRequestHandler {
shrink_time.stop();
}

let block_height = snapshot_root_bank.block_height();
let accounts_package_type = match request_type {
SnapshotRequestType::EpochAccountsHash => AccountsPackageType::EpochAccountsHash,
_ => {
if snapshot_utils::should_take_full_snapshot(block_height, self.snapshot_config.full_snapshot_archive_interval_slots) {
*last_full_snapshot_slot = Some(snapshot_root_bank.slot());
AccountsPackageType::Snapshot(SnapshotType::FullSnapshot)
} else if snapshot_utils::should_take_incremental_snapshot(block_height, self.snapshot_config .incremental_snapshot_archive_interval_slots, *last_full_snapshot_slot) {
AccountsPackageType::Snapshot(SnapshotType::IncrementalSnapshot( last_full_snapshot_slot.unwrap()))
} else {
AccountsPackageType::AccountsHashVerifier
}
},

};
if accounts_package_type == AccountsPackageType::Snapshot(SnapshotType::FullSnapshot) {
*last_full_snapshot_slot = Some(snapshot_root_bank.slot());
}

// Snapshot the bank and send over an accounts package
let mut snapshot_time = Measure::start("snapshot_time");
Expand Down Expand Up @@ -595,6 +584,37 @@ impl AccountsBackgroundService {
}
}

/// Get the AccountsPackageType from a given SnapshotRequest
#[must_use]
fn new_accounts_package_type(
snapshot_request: &SnapshotRequest,
snapshot_config: &SnapshotConfig,
last_full_snapshot_slot: Option<Slot>,
) -> AccountsPackageType {
let block_height = snapshot_request.snapshot_root_bank.block_height();
match snapshot_request.request_type {
SnapshotRequestType::EpochAccountsHash => AccountsPackageType::EpochAccountsHash,
_ => {
if snapshot_utils::should_take_full_snapshot(
block_height,
snapshot_config.full_snapshot_archive_interval_slots,
) {
AccountsPackageType::Snapshot(SnapshotType::FullSnapshot)
} else if snapshot_utils::should_take_incremental_snapshot(
block_height,
snapshot_config.incremental_snapshot_archive_interval_slots,
last_full_snapshot_slot,
) {
AccountsPackageType::Snapshot(SnapshotType::IncrementalSnapshot(
last_full_snapshot_slot.unwrap(),
))
} else {
AccountsPackageType::AccountsHashVerifier
}
}
}
}

#[cfg(test)]
mod test {
use {
Expand Down

0 comments on commit ceac6a1

Please sign in to comment.