From 2164a50d007a3b9fb5621f03bbe8037f3d30e480 Mon Sep 17 00:00:00 2001 From: Brennan Date: Tue, 18 Apr 2023 11:18:17 -0700 Subject: [PATCH] Move BankIncrementalSnapshotPersistence (#31236) * Move BankIncrementalSnapshotPersistence * Update bank serialize ABI digest --- core/src/accounts_hash_verifier.rs | 2 +- runtime/src/bank.rs | 21 +-------------------- runtime/src/serde_snapshot.rs | 24 +++++++++++++++++++++++- runtime/src/serde_snapshot/tests.rs | 2 +- runtime/src/snapshot_utils.rs | 5 +++-- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/core/src/accounts_hash_verifier.rs b/core/src/accounts_hash_verifier.rs index ccb644a29..2f4a5a102 100644 --- a/core/src/accounts_hash_verifier.rs +++ b/core/src/accounts_hash_verifier.rs @@ -14,7 +14,7 @@ use { AccountsHash, AccountsHashEnum, CalcAccountsHashConfig, HashStats, IncrementalAccountsHash, }, - bank::BankIncrementalSnapshotPersistence, + serde_snapshot::BankIncrementalSnapshotPersistence, snapshot_config::SnapshotConfig, snapshot_package::{ self, retain_max_n_elements, AccountsPackage, AccountsPackageType, SnapshotPackage, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 1b00b619d..459ba6ab3 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -64,7 +64,7 @@ use { rent_collector::{CollectedInfo, RentCollector}, rent_debits::RentDebits, runtime_config::RuntimeConfig, - serde_snapshot::{SerdeAccountsHash, SerdeIncrementalAccountsHash}, + serde_snapshot::BankIncrementalSnapshotPersistence, snapshot_hash::SnapshotHash, sorted_storages::SortedStorages, stake_account::{self, StakeAccount}, @@ -217,25 +217,6 @@ struct RentMetrics { count: AtomicUsize, } -/// Incremental snapshots only calculate their accounts hash based on the account changes WITHIN the incremental slot range. -/// So, we need to keep track of the full snapshot expected accounts hash results. -/// We also need to keep track of the hash and capitalization specific to the incremental snapshot slot range. -/// The capitalization we calculate for the incremental slot will NOT be consistent with the bank's capitalization. -/// It is not feasible to calculate a capitalization delta that is correct given just incremental slots account data and the full snapshot's capitalization. -#[derive(Serialize, Deserialize, AbiExample, Clone, Debug, Default, PartialEq, Eq)] -pub struct BankIncrementalSnapshotPersistence { - /// slot of full snapshot - pub full_slot: Slot, - /// accounts hash from the full snapshot - pub full_hash: SerdeAccountsHash, - /// capitalization from the full snapshot - pub full_capitalization: u64, - /// hash of the accounts in the incremental snapshot slot range, including zero-lamport accounts - pub incremental_hash: SerdeIncrementalAccountsHash, - /// capitalization of the accounts in the incremental snapshot slot range - pub incremental_capitalization: u64, -} - pub type BankStatusCache = StatusCache>; #[frozen_abi(digest = "GBTLfFjModD9ykS9LV4pGi4S8eCrUj2JjWSDQLf8tMwV")] pub type BankSlotDelta = SlotDelta>; diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index 95b8a526d..4a352fc12 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -10,7 +10,7 @@ use { accounts_hash::AccountsHash, accounts_index::AccountSecondaryIndexes, accounts_update_notifier_interface::AccountsUpdateNotifier, - bank::{Bank, BankFieldsToDeserialize, BankIncrementalSnapshotPersistence, BankRc}, + bank::{Bank, BankFieldsToDeserialize, BankRc}, blockhash_queue::BlockhashQueue, builtins::Builtins, epoch_accounts_hash::EpochAccountsHash, @@ -85,6 +85,28 @@ pub struct AccountsDbFields( Vec<(Slot, Hash)>, ); +/// Incremental snapshots only calculate their accounts hash based on the +/// account changes WITHIN the incremental slot range. So, we need to keep track +/// of the full snapshot expected accounts hash results. We also need to keep +/// track of the hash and capitalization specific to the incremental snapshot +/// slot range. The capitalization we calculate for the incremental slot will +/// NOT be consistent with the bank's capitalization. It is not feasible to +/// calculate a capitalization delta that is correct given just incremental +/// slots account data and the full snapshot's capitalization. +#[derive(Serialize, Deserialize, AbiExample, Clone, Debug, Default, PartialEq, Eq)] +pub struct BankIncrementalSnapshotPersistence { + /// slot of full snapshot + pub full_slot: Slot, + /// accounts hash from the full snapshot + pub full_hash: SerdeAccountsHash, + /// capitalization from the full snapshot + pub full_capitalization: u64, + /// hash of the accounts in the incremental snapshot slot range, including zero-lamport accounts + pub incremental_hash: SerdeIncrementalAccountsHash, + /// capitalization of the accounts in the incremental snapshot slot range + pub incremental_capitalization: u64, +} + #[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)] struct BankHashInfo { accounts_delta_hash: SerdeAccountsDeltaHash, diff --git a/runtime/src/serde_snapshot/tests.rs b/runtime/src/serde_snapshot/tests.rs index d3c2c1558..cf93baab1 100644 --- a/runtime/src/serde_snapshot/tests.rs +++ b/runtime/src/serde_snapshot/tests.rs @@ -721,7 +721,7 @@ mod test_bank_serialize { // This some what long test harness is required to freeze the ABI of // Bank's serialization due to versioned nature - #[frozen_abi(digest = "6JEjZCVdbC7CgpEexb9BKEtyMBL6aTHNZrjEWmhzmgp3")] + #[frozen_abi(digest = "GbEcrk8sgqbQ5kJ8mAaHTh2REmHyESQ6GXnGWxkGbxDe")] #[derive(Serialize, AbiExample)] pub struct BankAbiTestWrapperNewer { #[serde(serialize_with = "wrapper_newer")] diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 78350bff3..66212245c 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -9,7 +9,7 @@ use { accounts_index::AccountSecondaryIndexes, accounts_update_notifier_interface::AccountsUpdateNotifier, append_vec::AppendVec, - bank::{Bank, BankFieldsToDeserialize, BankIncrementalSnapshotPersistence, BankSlotDelta}, + bank::{Bank, BankFieldsToDeserialize, BankSlotDelta}, builtins::Builtins, hardened_unpack::{ streaming_unpack_snapshot, unpack_snapshot, ParallelSelector, UnpackError, @@ -17,7 +17,8 @@ use { }, runtime_config::RuntimeConfig, serde_snapshot::{ - bank_from_streams, bank_to_stream, fields_from_streams, SerdeStyle, SnapshotStreams, + bank_from_streams, bank_to_stream, fields_from_streams, + BankIncrementalSnapshotPersistence, SerdeStyle, SnapshotStreams, }, shared_buffer_reader::{SharedBuffer, SharedBufferReader}, snapshot_archive_info::{