diff --git a/crates/papyrus_storage/src/lib.rs b/crates/papyrus_storage/src/lib.rs index b362930ab2..6ec9622436 100644 --- a/crates/papyrus_storage/src/lib.rs +++ b/crates/papyrus_storage/src/lib.rs @@ -125,7 +125,7 @@ use crate::version::{VersionStorageReader, VersionStorageWriter}; /// The current version of the storage code. /// Whenever a breaking change is introduced, the version is incremented and a storage /// migration is required for existing storages. -pub const STORAGE_VERSION: Version = Version(6); +pub const STORAGE_VERSION: Version = Version(7); /// Opens a storage and returns a [`StorageReader`] and a [`StorageWriter`]. pub fn open_storage( diff --git a/crates/papyrus_storage/src/serializers.rs b/crates/papyrus_storage/src/serializers.rs index 61c49bef56..c8c01b7e93 100644 --- a/crates/papyrus_storage/src/serializers.rs +++ b/crates/papyrus_storage/src/serializers.rs @@ -416,14 +416,6 @@ auto_storage_serde! { pub events_contract_addresses: Vec, pub execution_status: TransactionExecutionStatus, } - pub struct ThinStateDiff { - pub deployed_contracts: IndexMap, - pub storage_diffs: IndexMap>, - pub declared_classes: IndexMap, - pub deprecated_declared_classes: Vec, - pub nonces: IndexMap, - pub replaced_classes: IndexMap, - } pub enum ThinTransactionOutput { Declare(ThinDeclareTransactionOutput) = 0, Deploy(ThinDeployTransactionOutput) = 1, @@ -980,3 +972,35 @@ impl StorageSerde for CasmContractClass { #[cfg(test)] create_storage_serde_test!(CasmContractClass); + +impl StorageSerde for ThinStateDiff { + fn serialize_into(&self, res: &mut impl std::io::Write) -> Result<(), StorageSerdeError> { + let mut to_compress: Vec = Vec::new(); + self.deployed_contracts.serialize_into(&mut to_compress)?; + self.storage_diffs.serialize_into(&mut to_compress)?; + self.declared_classes.serialize_into(&mut to_compress)?; + self.deprecated_declared_classes.serialize_into(&mut to_compress)?; + self.nonces.serialize_into(&mut to_compress)?; + self.replaced_classes.serialize_into(&mut to_compress)?; + let compressed = compress(to_compress.as_slice())?; + compressed.serialize_into(res)?; + Ok(()) + } + + fn deserialize_from(bytes: &mut impl std::io::Read) -> Option { + let compressed_data = Vec::::deserialize_from(bytes)?; + let data = decompress(compressed_data.as_slice()).ok()?; + let data = &mut data.as_slice(); + Some(Self { + deployed_contracts: IndexMap::deserialize_from(data)?, + storage_diffs: IndexMap::deserialize_from(data)?, + declared_classes: IndexMap::deserialize_from(data)?, + deprecated_declared_classes: Vec::deserialize_from(data)?, + nonces: IndexMap::deserialize_from(data)?, + replaced_classes: IndexMap::deserialize_from(data)?, + }) + } +} + +#[cfg(test)] +create_storage_serde_test!(ThinStateDiff);