This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
More serde snapshot cleanup #22449
Merged
Merged
More serde snapshot cleanup #22449
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,86 +1,55 @@ | ||
| use { | ||
| super::{common::UnusedAccounts, *}, | ||
| super::{ | ||
| common::UnusedAccounts, | ||
| storage::SerializableAccountStorageEntry, | ||
| utils::{serialize_iter_as_map, serialize_iter_as_seq}, | ||
| *, | ||
| }, | ||
| crate::{ancestors::AncestorsForSerialization, stakes::StakesCache}, | ||
| solana_measure::measure::Measure, | ||
| std::{cell::RefCell, sync::RwLock}, | ||
| }; | ||
|
|
||
| type AccountsDbFields = super::AccountsDbFields<SerializableAccountStorageEntry>; | ||
|
|
||
| /// the serialized type is fixed as usize | ||
| pub type AppendVecIdSerialized = usize; | ||
|
|
||
| // Serializable version of AccountStorageEntry for snapshot format | ||
| #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] | ||
| pub(super) struct SerializableAccountStorageEntry { | ||
| id: AppendVecIdSerialized, | ||
| accounts_current_len: usize, | ||
| } | ||
|
|
||
| pub trait SerializableStorage { | ||
| fn id(&self) -> AppendVecIdSerialized; | ||
| fn current_len(&self) -> usize; | ||
| } | ||
|
|
||
| impl SerializableStorage for SerializableAccountStorageEntry { | ||
| fn id(&self) -> AppendVecIdSerialized { | ||
| self.id | ||
| } | ||
| fn current_len(&self) -> usize { | ||
| self.accounts_current_len | ||
| } | ||
| } | ||
|
|
||
| #[cfg(RUSTC_WITH_SPECIALIZATION)] | ||
| impl solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableAccountStorageEntry {} | ||
|
|
||
| impl From<&AccountStorageEntry> for SerializableAccountStorageEntry { | ||
| fn from(rhs: &AccountStorageEntry) -> Self { | ||
| Self { | ||
| id: rhs.append_vec_id() as AppendVecIdSerialized, | ||
| accounts_current_len: rhs.accounts.len(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Deserializable version of Bank which need not be serializable, | ||
| // because it's handled by SerializableVersionedBank. | ||
| // So, sync fields with it! | ||
| #[derive(Clone, Deserialize)] | ||
| pub(crate) struct DeserializableVersionedBank { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing in here is used outside of this module, so removing the |
||
| pub(crate) blockhash_queue: BlockhashQueue, | ||
| pub(crate) ancestors: AncestorsForSerialization, | ||
| pub(crate) hash: Hash, | ||
| pub(crate) parent_hash: Hash, | ||
| pub(crate) parent_slot: Slot, | ||
| pub(crate) hard_forks: HardForks, | ||
| pub(crate) transaction_count: u64, | ||
| pub(crate) tick_height: u64, | ||
| pub(crate) signature_count: u64, | ||
| pub(crate) capitalization: u64, | ||
| pub(crate) max_tick_height: u64, | ||
| pub(crate) hashes_per_tick: Option<u64>, | ||
| pub(crate) ticks_per_slot: u64, | ||
| pub(crate) ns_per_slot: u128, | ||
| pub(crate) genesis_creation_time: UnixTimestamp, | ||
| pub(crate) slots_per_year: f64, | ||
| pub(crate) unused: u64, | ||
| pub(crate) slot: Slot, | ||
| pub(crate) epoch: Epoch, | ||
| pub(crate) block_height: u64, | ||
| pub(crate) collector_id: Pubkey, | ||
| pub(crate) collector_fees: u64, | ||
| pub(crate) fee_calculator: FeeCalculator, | ||
| pub(crate) fee_rate_governor: FeeRateGovernor, | ||
| pub(crate) collected_rent: u64, | ||
| pub(crate) rent_collector: RentCollector, | ||
| pub(crate) epoch_schedule: EpochSchedule, | ||
| pub(crate) inflation: Inflation, | ||
| pub(crate) stakes: Stakes, | ||
| struct DeserializableVersionedBank { | ||
| blockhash_queue: BlockhashQueue, | ||
| ancestors: AncestorsForSerialization, | ||
| hash: Hash, | ||
| parent_hash: Hash, | ||
| parent_slot: Slot, | ||
| hard_forks: HardForks, | ||
| transaction_count: u64, | ||
| tick_height: u64, | ||
| signature_count: u64, | ||
| capitalization: u64, | ||
| max_tick_height: u64, | ||
| hashes_per_tick: Option<u64>, | ||
| ticks_per_slot: u64, | ||
| ns_per_slot: u128, | ||
| genesis_creation_time: UnixTimestamp, | ||
| slots_per_year: f64, | ||
| unused: u64, | ||
| slot: Slot, | ||
| epoch: Epoch, | ||
| block_height: u64, | ||
| collector_id: Pubkey, | ||
| collector_fees: u64, | ||
| fee_calculator: FeeCalculator, | ||
| fee_rate_governor: FeeRateGovernor, | ||
| collected_rent: u64, | ||
| rent_collector: RentCollector, | ||
| epoch_schedule: EpochSchedule, | ||
| inflation: Inflation, | ||
| stakes: Stakes, | ||
| #[allow(dead_code)] | ||
| pub(crate) unused_accounts: UnusedAccounts, | ||
| pub(crate) epoch_stakes: HashMap<Epoch, EpochStakes>, | ||
| pub(crate) is_delta: bool, | ||
| unused_accounts: UnusedAccounts, | ||
| epoch_stakes: HashMap<Epoch, EpochStakes>, | ||
| is_delta: bool, | ||
| } | ||
|
|
||
| impl From<DeserializableVersionedBank> for BankFieldsToDeserialize { | ||
|
|
@@ -124,39 +93,39 @@ impl From<DeserializableVersionedBank> for BankFieldsToDeserialize { | |
| // Serializable version of Bank, not Deserializable to avoid cloning by using refs. | ||
| // Sync fields with DeserializableVersionedBank! | ||
| #[derive(Serialize)] | ||
| pub(crate) struct SerializableVersionedBank<'a> { | ||
| pub(crate) blockhash_queue: &'a RwLock<BlockhashQueue>, | ||
| pub(crate) ancestors: &'a AncestorsForSerialization, | ||
| pub(crate) hash: Hash, | ||
| pub(crate) parent_hash: Hash, | ||
| pub(crate) parent_slot: Slot, | ||
| pub(crate) hard_forks: &'a RwLock<HardForks>, | ||
| pub(crate) transaction_count: u64, | ||
| pub(crate) tick_height: u64, | ||
| pub(crate) signature_count: u64, | ||
| pub(crate) capitalization: u64, | ||
| pub(crate) max_tick_height: u64, | ||
| pub(crate) hashes_per_tick: Option<u64>, | ||
| pub(crate) ticks_per_slot: u64, | ||
| pub(crate) ns_per_slot: u128, | ||
| pub(crate) genesis_creation_time: UnixTimestamp, | ||
| pub(crate) slots_per_year: f64, | ||
| pub(crate) unused: u64, | ||
| pub(crate) slot: Slot, | ||
| pub(crate) epoch: Epoch, | ||
| pub(crate) block_height: u64, | ||
| pub(crate) collector_id: Pubkey, | ||
| pub(crate) collector_fees: u64, | ||
| pub(crate) fee_calculator: FeeCalculator, | ||
| pub(crate) fee_rate_governor: FeeRateGovernor, | ||
| pub(crate) collected_rent: u64, | ||
| pub(crate) rent_collector: RentCollector, | ||
| pub(crate) epoch_schedule: EpochSchedule, | ||
| pub(crate) inflation: Inflation, | ||
| pub(crate) stakes: &'a StakesCache, | ||
| pub(crate) unused_accounts: UnusedAccounts, | ||
| pub(crate) epoch_stakes: &'a HashMap<Epoch, EpochStakes>, | ||
| pub(crate) is_delta: bool, | ||
| struct SerializableVersionedBank<'a> { | ||
| blockhash_queue: &'a RwLock<BlockhashQueue>, | ||
| ancestors: &'a AncestorsForSerialization, | ||
| hash: Hash, | ||
| parent_hash: Hash, | ||
| parent_slot: Slot, | ||
| hard_forks: &'a RwLock<HardForks>, | ||
| transaction_count: u64, | ||
| tick_height: u64, | ||
| signature_count: u64, | ||
| capitalization: u64, | ||
| max_tick_height: u64, | ||
| hashes_per_tick: Option<u64>, | ||
| ticks_per_slot: u64, | ||
| ns_per_slot: u128, | ||
| genesis_creation_time: UnixTimestamp, | ||
| slots_per_year: f64, | ||
| unused: u64, | ||
| slot: Slot, | ||
| epoch: Epoch, | ||
| block_height: u64, | ||
| collector_id: Pubkey, | ||
| collector_fees: u64, | ||
| fee_calculator: FeeCalculator, | ||
| fee_rate_governor: FeeRateGovernor, | ||
| collected_rent: u64, | ||
| rent_collector: RentCollector, | ||
| epoch_schedule: EpochSchedule, | ||
| inflation: Inflation, | ||
| stakes: &'a StakesCache, | ||
| unused_accounts: UnusedAccounts, | ||
| epoch_stakes: &'a HashMap<Epoch, EpochStakes>, | ||
| is_delta: bool, | ||
| } | ||
|
|
||
| impl<'a> From<crate::bank::BankFieldsToSerialize<'a>> for SerializableVersionedBank<'a> { | ||
|
|
@@ -205,6 +174,7 @@ impl<'a> From<crate::bank::BankFieldsToSerialize<'a>> for SerializableVersionedB | |
| impl<'a> solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableVersionedBank<'a> {} | ||
|
|
||
| pub(super) struct Context {} | ||
|
|
||
| impl<'a> TypeContext<'a> for Context { | ||
| type SerializableAccountStorageEntry = SerializableAccountStorageEntry; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| use { | ||
| crate::accounts_db::AccountStorageEntry, | ||
| serde::{Deserialize, Serialize}, | ||
| }; | ||
|
|
||
| /// The serialized AppendVecId type is fixed as usize | ||
| pub(super) type SerializedAppendVecId = usize; | ||
|
|
||
| // Serializable version of AccountStorageEntry for snapshot format | ||
| #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] | ||
| pub(super) struct SerializableAccountStorageEntry { | ||
| id: SerializedAppendVecId, | ||
| accounts_current_len: usize, | ||
| } | ||
|
|
||
| pub(super) trait SerializableStorage { | ||
| fn id(&self) -> SerializedAppendVecId; | ||
| fn current_len(&self) -> usize; | ||
| } | ||
|
|
||
| impl SerializableStorage for SerializableAccountStorageEntry { | ||
| fn id(&self) -> SerializedAppendVecId { | ||
| self.id | ||
| } | ||
| fn current_len(&self) -> usize { | ||
| self.accounts_current_len | ||
| } | ||
| } | ||
|
|
||
| impl From<&AccountStorageEntry> for SerializableAccountStorageEntry { | ||
| fn from(rhs: &AccountStorageEntry) -> Self { | ||
| Self { | ||
| id: rhs.append_vec_id() as SerializedAppendVecId, | ||
| accounts_current_len: rhs.accounts.len(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(RUSTC_WITH_SPECIALIZATION)] | ||
| impl solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableAccountStorageEntry {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -305,7 +305,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 = "4xi75P1M48JwDjxf5k8y43r2w57AjYmgjMB1BmX6hXKK")] | ||
| #[frozen_abi(digest = "7PcarCw6gpw9Yw8xypdxQP24TFjLiaHyuDkq95cgwtte")] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The diff is due to moving the storage fields into a new module. |
||
| #[derive(Serialize, AbiExample)] | ||
| pub struct BankAbiTestWrapperNewer { | ||
| #[serde(serialize_with = "wrapper_newer")] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved all this over to a new file,
storage.rs, because I'm going to add a new serde style, which would result in these types/traits being duplicated and causing build errors.