From 5f091fe2fbc902a0ef70e494a1c13a55717b0176 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Mon, 13 Jan 2025 18:05:27 +0530 Subject: [PATCH 01/16] fault_proving(compression): include block_id in da compressed block headers --- CHANGELOG.md | 1 + bin/fuel-core/Cargo.toml | 1 + crates/compression/Cargo.toml | 1 + crates/compression/src/compress.rs | 19 +++- crates/compression/src/decompress.rs | 14 ++- crates/compression/src/lib.rs | 124 ++++++++++++++++++++++++++- crates/fuel-core/Cargo.toml | 1 + 7 files changed, 150 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec2cb49a3a9..17380aed245 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [2472](https://github.com/FuelLabs/fuel-core/pull/2472): Added the `amountU128` field to the `Balance` GraphQL schema, providing the total balance as a `U128`. The existing `amount` field clamps any balance exceeding `U64` to `u64::MAX`. - [2526](https://github.com/FuelLabs/fuel-core/pull/2526): Add possibility to not have any cache set for RocksDB. Add an option to either load the RocksDB columns families on creation of the database or when the column is used. - [2532](https://github.com/FuelLabs/fuel-core/pull/2532): Getters for inner rocksdb database handles. +- [2551](https://github.com/FuelLabs/fuel-core/pull/2551): Enhanced the DA compressed block header to include block id. ### Fixed - [2365](https://github.com/FuelLabs/fuel-core/pull/2365): Fixed the error during dry run in the case of race condition. diff --git a/bin/fuel-core/Cargo.toml b/bin/fuel-core/Cargo.toml index 880a69f9296..1899a6cfaba 100644 --- a/bin/fuel-core/Cargo.toml +++ b/bin/fuel-core/Cargo.toml @@ -82,3 +82,4 @@ production = [ "parquet", "aws-kms", ] +fault-proving = ["fuel-core-compression/fault-proving"] diff --git a/crates/compression/Cargo.toml b/crates/compression/Cargo.toml index 40e092d1e00..967af7ef930 100644 --- a/crates/compression/Cargo.toml +++ b/crates/compression/Cargo.toml @@ -42,3 +42,4 @@ test-helpers = [ "fuel-core-types/random", "fuel-core-types/std", ] +fault-proving = [] diff --git a/crates/compression/src/compress.rs b/crates/compression/src/compress.rs index 0ad14e39f55..d5ced9230ff 100644 --- a/crates/compression/src/compress.rs +++ b/crates/compression/src/compress.rs @@ -12,7 +12,6 @@ use crate::{ RegistrationsPerTable, TemporalRegistryAll, }, - CompressedBlockPayloadV0, VersionedCompressedBlock, }; use anyhow::Context; @@ -42,6 +41,15 @@ use std::collections::{ HashSet, }; +#[cfg(feature = "fault-proving")] +use crate::{ + CompressedBlockHeader, + CompressedBlockPayloadV1, +}; + +#[cfg(not(feature = "fault-proving"))] +use crate::CompressedBlockPayloadV0; + pub trait CompressDb: TemporalRegistryAll + EvictorDbAll + UtxoIdToPointer {} impl CompressDb for T where T: TemporalRegistryAll + EvictorDbAll + UtxoIdToPointer {} @@ -70,10 +78,17 @@ where let transactions = target.compress_with(&mut ctx).await?; let registrations: RegistrationsPerTable = ctx.finalize()?; - Ok(VersionedCompressedBlock::V0(CompressedBlockPayloadV0 { + #[cfg(not(feature = "fault-proving"))] + return Ok(VersionedCompressedBlock::V0(CompressedBlockPayloadV0 { registrations, header: block.header().into(), transactions, + })); + #[cfg(feature = "fault-proving")] + Ok(VersionedCompressedBlock::V1(CompressedBlockPayloadV1 { + registrations, + header: CompressedBlockHeader::from(block.header()), + transactions, })) } diff --git a/crates/compression/src/decompress.rs b/crates/compression/src/decompress.rs index 15565ce8433..080812a439d 100644 --- a/crates/compression/src/decompress.rs +++ b/crates/compression/src/decompress.rs @@ -55,28 +55,26 @@ pub async fn decompress( where D: DecompressDb, { - let VersionedCompressedBlock::V0(compressed) = block; - // TODO: merkle root verification: https://github.com/FuelLabs/fuel-core/issues/2232 - compressed - .registrations - .write_to_registry(&mut db, compressed.header.consensus.time)?; + block + .registrations() + .write_to_registry(&mut db, block.consensus_header().time)?; let ctx = DecompressCtx { config, - timestamp: compressed.header.consensus.time, + timestamp: block.consensus_header().time, db, }; let transactions = as DecompressibleBy<_>>::decompress_with( - compressed.transactions, + block.transactions(), &ctx, ) .await?; Ok(PartialFuelBlock { - header: compressed.header, + header: block.partial_block_header(), transactions, }) } diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index d41deccefa1..838dcb8c06a 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -13,8 +13,21 @@ mod registry; pub use config::Config; pub use registry::RegistryKeyspace; +#[cfg(feature = "fault-proving")] +use fuel_core_types::blockchain::header::{ + ApplicationHeader, + BlockHeader, +}; +#[cfg(feature = "fault-proving")] +use fuel_core_types::blockchain::primitives::BlockId; use fuel_core_types::{ - blockchain::header::PartialBlockHeader, + blockchain::{ + header::{ + ConsensusHeader, + PartialBlockHeader, + }, + primitives::Empty, + }, fuel_tx::CompressedTransaction, fuel_types::BlockHeight, }; @@ -31,10 +44,79 @@ pub struct CompressedBlockPayloadV0 { pub transactions: Vec, } +#[cfg(feature = "fault-proving")] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[cfg_attr( + feature = "fault-proving", + derive(serde::Serialize, serde::Deserialize) +)] +#[derive(Default)] +/// A partially complete fuel block header that does not +/// have any generated fields because it has not been executed yet. +pub struct CompressedBlockHeader { + /// The application header. + pub application: ApplicationHeader, + /// The consensus header. + pub consensus: ConsensusHeader, + // The block id. + pub block_id: BlockId, +} + +#[cfg(feature = "fault-proving")] +impl From<&BlockHeader> for CompressedBlockHeader { + fn from(header: &BlockHeader) -> Self { + let ConsensusHeader { + prev_root, + height, + time, + .. + } = *header.consensus(); + CompressedBlockHeader { + application: ApplicationHeader { + da_height: header.da_height, + consensus_parameters_version: header.consensus_parameters_version, + state_transition_bytecode_version: header + .state_transition_bytecode_version, + generated: Empty {}, + }, + consensus: ConsensusHeader { + prev_root, + height, + time, + generated: Empty {}, + }, + block_id: header.id(), + } + } +} + +#[cfg(feature = "fault-proving")] +impl From<&CompressedBlockHeader> for PartialBlockHeader { + fn from(value: &CompressedBlockHeader) -> Self { + PartialBlockHeader { + application: value.application.clone(), + consensus: value.consensus.clone(), + } + } +} + +#[cfg(feature = "fault-proving")] +#[derive(Debug, Default, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct CompressedBlockPayloadV1 { + /// Temporal registry insertions + pub registrations: RegistrationsPerTable, + /// Compressed block header + pub header: CompressedBlockHeader, + /// Compressed transactions + pub transactions: Vec, +} + /// Versioned compressed block. #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub enum VersionedCompressedBlock { V0(CompressedBlockPayloadV0), + #[cfg(feature = "fault-proving")] + V1(CompressedBlockPayloadV1), } impl Default for VersionedCompressedBlock { @@ -48,6 +130,46 @@ impl VersionedCompressedBlock { pub fn height(&self) -> &BlockHeight { match self { VersionedCompressedBlock::V0(block) => block.header.height(), + #[cfg(feature = "fault-proving")] + VersionedCompressedBlock::V1(block) => &block.header.consensus.height, + } + } + + /// Returns the consensus header + pub fn consensus_header(&self) -> &ConsensusHeader { + match self { + VersionedCompressedBlock::V0(block) => &block.header.consensus, + #[cfg(feature = "fault-proving")] + VersionedCompressedBlock::V1(block) => &block.header.consensus, + } + } + + /// Returns the registrations table + pub fn registrations(&self) -> &RegistrationsPerTable { + match self { + VersionedCompressedBlock::V0(block) => &block.registrations, + #[cfg(feature = "fault-proving")] + VersionedCompressedBlock::V1(block) => &block.registrations, + } + } + + /// Returns the transactions + pub fn transactions(&self) -> Vec { + match self { + VersionedCompressedBlock::V0(block) => block.transactions.clone(), + #[cfg(feature = "fault-proving")] + VersionedCompressedBlock::V1(block) => block.transactions.clone(), + } + } + + /// Returns the partial block header + pub fn partial_block_header(&self) -> PartialBlockHeader { + match self { + VersionedCompressedBlock::V0(block) => block.header.clone(), + #[cfg(feature = "fault-proving")] + VersionedCompressedBlock::V1(block) => { + PartialBlockHeader::from(&block.header) + } } } } diff --git a/crates/fuel-core/Cargo.toml b/crates/fuel-core/Cargo.toml index 79c05ec33e6..9f3a6d31d34 100644 --- a/crates/fuel-core/Cargo.toml +++ b/crates/fuel-core/Cargo.toml @@ -115,3 +115,4 @@ test-helpers = [ # features to enable in production, but increase build times rocksdb-production = ["rocksdb", "rocksdb/jemalloc"] wasm-executor = ["fuel-core-upgradable-executor/wasm-executor"] +fault-proving = ["fuel-core-compression/fault-proving"] From e56f8242793b9c029fc2ef5fbf2e2658d9911784 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Mon, 13 Jan 2025 18:39:20 +0530 Subject: [PATCH 02/16] fix: clippy --- crates/compression/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index 838dcb8c06a..eb8d4a54443 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -94,8 +94,8 @@ impl From<&BlockHeader> for CompressedBlockHeader { impl From<&CompressedBlockHeader> for PartialBlockHeader { fn from(value: &CompressedBlockHeader) -> Self { PartialBlockHeader { - application: value.application.clone(), - consensus: value.consensus.clone(), + application: value.application, + consensus: value.consensus, } } } @@ -165,7 +165,7 @@ impl VersionedCompressedBlock { /// Returns the partial block header pub fn partial_block_header(&self) -> PartialBlockHeader { match self { - VersionedCompressedBlock::V0(block) => block.header.clone(), + VersionedCompressedBlock::V0(block) => block.header, #[cfg(feature = "fault-proving")] VersionedCompressedBlock::V1(block) => { PartialBlockHeader::from(&block.header) From d595e4469f2383115498343f0df5b50ce32db84b Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Mon, 13 Jan 2025 19:13:19 +0530 Subject: [PATCH 03/16] chore: update test --- crates/compression/src/lib.rs | 63 ++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index eb8d4a54443..ae99171e8f4 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -144,6 +144,15 @@ impl VersionedCompressedBlock { } } + /// Returns the application header + pub fn application_header(&self) -> &ApplicationHeader { + match self { + VersionedCompressedBlock::V0(block) => &block.header.application, + #[cfg(feature = "fault-proving")] + VersionedCompressedBlock::V1(block) => &block.header.application, + } + } + /// Returns the registrations table pub fn registrations(&self) -> &RegistrationsPerTable { match self { @@ -189,7 +198,8 @@ mod tests { tai64::Tai64, }; use proptest::prelude::*; - + #[cfg(feature = "fault-proving")] + use std::str::FromStr; use super::*; fn keyspace() -> impl Strategy { @@ -243,6 +253,7 @@ mod tests { } } + #[cfg(not(feature = "fault-proving"))] let header = PartialBlockHeader { application: ApplicationHeader { da_height: da_height.into(), @@ -257,31 +268,51 @@ mod tests { generated: Empty } }; - let original = CompressedBlockPayloadV0 { + #[cfg(feature = "fault-proving")] + let header = CompressedBlockHeader { + application: ApplicationHeader { + da_height: da_height.into(), + consensus_parameters_version, + state_transition_bytecode_version, + generated: Empty, + }, + consensus: ConsensusHeader { + prev_root: prev_root.into(), + height: height.into(), + time: Tai64::UNIX_EPOCH, + generated: Empty, + }, + block_id: BlockId::from_str("0xecea85c17070bc2e65f911310dbd01198f4436052ebba96cded9ddf30c58dd1a").unwrap(), + }; + + #[cfg(not(feature = "fault-proving"))] + let original = VersionedCompressedBlock::V0(CompressedBlockPayloadV0 { registrations, header, transactions: vec![], - }; + }); + let original = VersionedCompressedBlock::V1(CompressedBlockPayloadV1 { + registrations, + header, + transactions: vec![] + }); let compressed = postcard::to_allocvec(&original).unwrap(); - let decompressed: CompressedBlockPayloadV0 = + let decompressed: VersionedCompressedBlock = postcard::from_bytes(&compressed).unwrap(); - let CompressedBlockPayloadV0 { - registrations, - header, - transactions, - } = decompressed; + let consensus_header = decompressed.consensus_header(); + let application_header = decompressed.application_header(); - assert_eq!(registrations, original.registrations); + assert_eq!(decompressed.registrations(), original.registrations()); - assert_eq!(header.da_height, da_height.into()); - assert_eq!(*header.prev_root(), prev_root.into()); - assert_eq!(*header.height(), height.into()); - assert_eq!(header.consensus_parameters_version, consensus_parameters_version); - assert_eq!(header.state_transition_bytecode_version, state_transition_bytecode_version); + assert_eq!(application_header.da_height, da_height.into()); + assert_eq!(consensus_header.prev_root, prev_root.into()); + assert_eq!(consensus_header.height, height.into()); + assert_eq!(application_header.consensus_parameters_version, consensus_parameters_version); + assert_eq!(application_header.state_transition_bytecode_version, state_transition_bytecode_version); - assert!(transactions.is_empty()); + assert!(decompressed.transactions().is_empty()); } } } From a6cd46f63c2e7d47d996bfbdaa5458143f328c2b Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Mon, 13 Jan 2025 19:14:58 +0530 Subject: [PATCH 04/16] chore: update test --- crates/compression/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index ae99171e8f4..be0c4e263ae 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -185,6 +185,7 @@ impl VersionedCompressedBlock { #[cfg(test)] mod tests { + use super::*; use fuel_core_compression as _; use fuel_core_types::{ blockchain::{ @@ -200,7 +201,6 @@ mod tests { use proptest::prelude::*; #[cfg(feature = "fault-proving")] use std::str::FromStr; - use super::*; fn keyspace() -> impl Strategy { prop_oneof![ @@ -313,6 +313,10 @@ mod tests { assert_eq!(application_header.state_transition_bytecode_version, state_transition_bytecode_version); assert!(decompressed.transactions().is_empty()); + + if let VersionedCompressedBlock::V1(block) = decompressed { + assert_eq!(block.header.block_id, header.block_id); + } } } } From a9dc266eaf679cf9eddc9c36b05f6d40d0e90ebf Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:22:59 +0530 Subject: [PATCH 05/16] fix: import --- crates/compression/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index be0c4e263ae..5c3204df008 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -14,15 +14,13 @@ pub use config::Config; pub use registry::RegistryKeyspace; #[cfg(feature = "fault-proving")] -use fuel_core_types::blockchain::header::{ - ApplicationHeader, - BlockHeader, -}; +use fuel_core_types::blockchain::header::BlockHeader; #[cfg(feature = "fault-proving")] use fuel_core_types::blockchain::primitives::BlockId; use fuel_core_types::{ blockchain::{ header::{ + ApplicationHeader, ConsensusHeader, PartialBlockHeader, }, From daca1fe198d3b56cdf42f70bb084ea917b00ab67 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:46:25 +0530 Subject: [PATCH 06/16] feature flags --- crates/compression/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index 5c3204df008..3f50ad86cfb 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -289,6 +289,7 @@ mod tests { header, transactions: vec![], }); + #[cfg(feature = "fault-proving")] let original = VersionedCompressedBlock::V1(CompressedBlockPayloadV1 { registrations, header, @@ -312,6 +313,7 @@ mod tests { assert!(decompressed.transactions().is_empty()); + #[cfg(feature = "fault-proving")] if let VersionedCompressedBlock::V1(block) = decompressed { assert_eq!(block.header.block_id, header.block_id); } From d906b44762128e09bd059c0221c894e2b7387143 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Tue, 14 Jan 2025 21:30:28 +0530 Subject: [PATCH 07/16] fix: split payloads into different files --- Cargo.lock | 13 ++ crates/compression/Cargo.toml | 1 + .../src/compressed_block_payload/mod.rs | 3 + .../src/compressed_block_payload/v0.rs | 53 ++++++ .../src/compressed_block_payload/v1.rs | 106 ++++++++++++ crates/compression/src/decompress.rs | 1 + crates/compression/src/lib.rs | 153 ++---------------- 7 files changed, 193 insertions(+), 137 deletions(-) create mode 100644 crates/compression/src/compressed_block_payload/mod.rs create mode 100644 crates/compression/src/compressed_block_payload/v0.rs create mode 100644 crates/compression/src/compressed_block_payload/v1.rs diff --git a/Cargo.lock b/Cargo.lock index a797d35f850..e34c13d176a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2772,6 +2772,18 @@ dependencies = [ "syn 2.0.95", ] +[[package]] +name = "enum_dispatch" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd" +dependencies = [ + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.95", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -3545,6 +3557,7 @@ name = "fuel-core-compression" version = "0.40.2" dependencies = [ "anyhow", + "enum_dispatch", "fuel-core-compression", "fuel-core-types 0.40.2", "paste", diff --git a/crates/compression/Cargo.toml b/crates/compression/Cargo.toml index 967af7ef930..7636684b82e 100644 --- a/crates/compression/Cargo.toml +++ b/crates/compression/Cargo.toml @@ -28,6 +28,7 @@ rand = { workspace = true, optional = true } serde = { version = "1.0", features = ["derive"] } strum = { workspace = true } strum_macros = { workspace = true } +enum_dispatch = "0.3.13" [dev-dependencies] fuel-core-compression = { path = ".", features = ["test-helpers"] } diff --git a/crates/compression/src/compressed_block_payload/mod.rs b/crates/compression/src/compressed_block_payload/mod.rs new file mode 100644 index 00000000000..420eb16447d --- /dev/null +++ b/crates/compression/src/compressed_block_payload/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod v0; + +pub(crate) mod v1; diff --git a/crates/compression/src/compressed_block_payload/v0.rs b/crates/compression/src/compressed_block_payload/v0.rs new file mode 100644 index 00000000000..deef0d9c1f2 --- /dev/null +++ b/crates/compression/src/compressed_block_payload/v0.rs @@ -0,0 +1,53 @@ +use crate::{ + registry::RegistrationsPerTable, + VersionedBlockPayload, +}; +use fuel_core_types::{ + blockchain::{ + header::{ + ApplicationHeader, + ConsensusHeader, + PartialBlockHeader, + }, + primitives::Empty, + }, + fuel_tx::CompressedTransaction, + fuel_types::BlockHeight, +}; + +/// Compressed block, without the preceding version byte. +#[derive(Debug, Default, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct CompressedBlockPayloadV0 { + /// Temporal registry insertions + pub registrations: RegistrationsPerTable, + /// Compressed block header + pub header: PartialBlockHeader, + /// Compressed transactions + pub transactions: Vec, +} + +impl VersionedBlockPayload for CompressedBlockPayloadV0 { + fn height(&self) -> &BlockHeight { + &self.header.height() + } + + fn consensus_header(&self) -> &ConsensusHeader { + &self.header.consensus + } + + fn application_header(&self) -> &ApplicationHeader { + &self.header.application + } + + fn registrations(&self) -> &RegistrationsPerTable { + &self.registrations + } + + fn transactions(&self) -> Vec { + self.transactions.clone() + } + + fn partial_block_header(&self) -> PartialBlockHeader { + self.header + } +} diff --git a/crates/compression/src/compressed_block_payload/v1.rs b/crates/compression/src/compressed_block_payload/v1.rs new file mode 100644 index 00000000000..da72bb396fd --- /dev/null +++ b/crates/compression/src/compressed_block_payload/v1.rs @@ -0,0 +1,106 @@ +use crate::{ + registry::RegistrationsPerTable, + VersionedBlockPayload, +}; +use fuel_core_types::{ + blockchain::{ + header::{ + ApplicationHeader, + BlockHeader, + ConsensusHeader, + PartialBlockHeader, + }, + primitives::{ + BlockId, + Empty, + }, + }, + fuel_tx::CompressedTransaction, + fuel_types::BlockHeight, +}; + +/// A partially complete fuel block header that does not +/// have any generated fields because it has not been executed yet. +#[derive( + Copy, Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, +)] +pub struct CompressedBlockHeader { + /// The application header. + pub application: ApplicationHeader, + /// The consensus header. + pub consensus: ConsensusHeader, + // The block id. + pub block_id: BlockId, +} + +impl From<&BlockHeader> for CompressedBlockHeader { + fn from(header: &BlockHeader) -> Self { + let ConsensusHeader { + prev_root, + height, + time, + .. + } = *header.consensus(); + CompressedBlockHeader { + application: ApplicationHeader { + da_height: header.da_height, + consensus_parameters_version: header.consensus_parameters_version, + state_transition_bytecode_version: header + .state_transition_bytecode_version, + generated: Empty {}, + }, + consensus: ConsensusHeader { + prev_root, + height, + time, + generated: Empty {}, + }, + block_id: header.id(), + } + } +} + +impl From<&CompressedBlockHeader> for PartialBlockHeader { + fn from(value: &CompressedBlockHeader) -> Self { + PartialBlockHeader { + application: value.application, + consensus: value.consensus, + } + } +} + +#[derive(Debug, Default, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct CompressedBlockPayloadV1 { + /// Temporal registry insertions + pub registrations: RegistrationsPerTable, + /// Compressed block header + pub header: CompressedBlockHeader, + /// Compressed transactions + pub transactions: Vec, +} + +impl VersionedBlockPayload for CompressedBlockPayloadV1 { + fn height(&self) -> &BlockHeight { + &self.header.consensus.height + } + + fn consensus_header(&self) -> &ConsensusHeader { + &self.header.consensus + } + + fn application_header(&self) -> &ApplicationHeader { + &self.header.application + } + + fn registrations(&self) -> &RegistrationsPerTable { + &self.registrations + } + + fn transactions(&self) -> Vec { + self.transactions.clone() + } + + fn partial_block_header(&self) -> PartialBlockHeader { + PartialBlockHeader::from(&self.header) + } +} diff --git a/crates/compression/src/decompress.rs b/crates/compression/src/decompress.rs index 080812a439d..082124e9161 100644 --- a/crates/compression/src/decompress.rs +++ b/crates/compression/src/decompress.rs @@ -5,6 +5,7 @@ use crate::{ TemporalRegistry, }, registry::TemporalRegistryAll, + VersionedBlockPayload, VersionedCompressedBlock, }; use fuel_core_types::{ diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index 3f50ad86cfb..96c1ec81d86 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -4,6 +4,7 @@ #![deny(warnings)] pub mod compress; +mod compressed_block_payload; pub mod config; pub mod decompress; mod eviction_policy; @@ -11,12 +12,12 @@ pub mod ports; mod registry; pub use config::Config; +use enum_dispatch::enum_dispatch; pub use registry::RegistryKeyspace; +use crate::compressed_block_payload::v0::CompressedBlockPayloadV0; #[cfg(feature = "fault-proving")] -use fuel_core_types::blockchain::header::BlockHeader; -#[cfg(feature = "fault-proving")] -use fuel_core_types::blockchain::primitives::BlockId; +use crate::compressed_block_payload::v1::CompressedBlockPayloadV1; use fuel_core_types::{ blockchain::{ header::{ @@ -31,86 +32,22 @@ use fuel_core_types::{ }; use registry::RegistrationsPerTable; -/// Compressed block, without the preceding version byte. -#[derive(Debug, Default, Clone, PartialEq, serde::Serialize, serde::Deserialize)] -pub struct CompressedBlockPayloadV0 { - /// Temporal registry insertions - pub registrations: RegistrationsPerTable, - /// Compressed block header - pub header: PartialBlockHeader, - /// Compressed transactions - pub transactions: Vec, -} - -#[cfg(feature = "fault-proving")] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -#[cfg_attr( - feature = "fault-proving", - derive(serde::Serialize, serde::Deserialize) -)] -#[derive(Default)] -/// A partially complete fuel block header that does not -/// have any generated fields because it has not been executed yet. -pub struct CompressedBlockHeader { - /// The application header. - pub application: ApplicationHeader, - /// The consensus header. - pub consensus: ConsensusHeader, - // The block id. - pub block_id: BlockId, -} - -#[cfg(feature = "fault-proving")] -impl From<&BlockHeader> for CompressedBlockHeader { - fn from(header: &BlockHeader) -> Self { - let ConsensusHeader { - prev_root, - height, - time, - .. - } = *header.consensus(); - CompressedBlockHeader { - application: ApplicationHeader { - da_height: header.da_height, - consensus_parameters_version: header.consensus_parameters_version, - state_transition_bytecode_version: header - .state_transition_bytecode_version, - generated: Empty {}, - }, - consensus: ConsensusHeader { - prev_root, - height, - time, - generated: Empty {}, - }, - block_id: header.id(), - } - } -} - -#[cfg(feature = "fault-proving")] -impl From<&CompressedBlockHeader> for PartialBlockHeader { - fn from(value: &CompressedBlockHeader) -> Self { - PartialBlockHeader { - application: value.application, - consensus: value.consensus, - } - } -} - -#[cfg(feature = "fault-proving")] -#[derive(Debug, Default, Clone, PartialEq, serde::Serialize, serde::Deserialize)] -pub struct CompressedBlockPayloadV1 { - /// Temporal registry insertions - pub registrations: RegistrationsPerTable, - /// Compressed block header - pub header: CompressedBlockHeader, - /// Compressed transactions - pub transactions: Vec, +/// A compressed block payload MUST implement this trait +/// It is used to provide a convenient interface for usage within +/// compression +#[enum_dispatch] +pub trait VersionedBlockPayload { + fn height(&self) -> &BlockHeight; + fn consensus_header(&self) -> &ConsensusHeader; + fn application_header(&self) -> &ApplicationHeader; + fn registrations(&self) -> &RegistrationsPerTable; + fn transactions(&self) -> Vec; + fn partial_block_header(&self) -> PartialBlockHeader; } /// Versioned compressed block. #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +#[enum_dispatch(VersionedBlockPayload)] pub enum VersionedCompressedBlock { V0(CompressedBlockPayloadV0), #[cfg(feature = "fault-proving")] @@ -123,64 +60,6 @@ impl Default for VersionedCompressedBlock { } } -impl VersionedCompressedBlock { - /// Returns the height of the compressed block. - pub fn height(&self) -> &BlockHeight { - match self { - VersionedCompressedBlock::V0(block) => block.header.height(), - #[cfg(feature = "fault-proving")] - VersionedCompressedBlock::V1(block) => &block.header.consensus.height, - } - } - - /// Returns the consensus header - pub fn consensus_header(&self) -> &ConsensusHeader { - match self { - VersionedCompressedBlock::V0(block) => &block.header.consensus, - #[cfg(feature = "fault-proving")] - VersionedCompressedBlock::V1(block) => &block.header.consensus, - } - } - - /// Returns the application header - pub fn application_header(&self) -> &ApplicationHeader { - match self { - VersionedCompressedBlock::V0(block) => &block.header.application, - #[cfg(feature = "fault-proving")] - VersionedCompressedBlock::V1(block) => &block.header.application, - } - } - - /// Returns the registrations table - pub fn registrations(&self) -> &RegistrationsPerTable { - match self { - VersionedCompressedBlock::V0(block) => &block.registrations, - #[cfg(feature = "fault-proving")] - VersionedCompressedBlock::V1(block) => &block.registrations, - } - } - - /// Returns the transactions - pub fn transactions(&self) -> Vec { - match self { - VersionedCompressedBlock::V0(block) => block.transactions.clone(), - #[cfg(feature = "fault-proving")] - VersionedCompressedBlock::V1(block) => block.transactions.clone(), - } - } - - /// Returns the partial block header - pub fn partial_block_header(&self) -> PartialBlockHeader { - match self { - VersionedCompressedBlock::V0(block) => block.header, - #[cfg(feature = "fault-proving")] - VersionedCompressedBlock::V1(block) => { - PartialBlockHeader::from(&block.header) - } - } - } -} - #[cfg(test)] mod tests { use super::*; From 68e948a52a528795b52fc0b2d005a0bca768ab9b Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Tue, 14 Jan 2025 21:45:23 +0530 Subject: [PATCH 08/16] fix: refactor more --- crates/compression/src/compress.rs | 22 +++---------------- .../src/compressed_block_payload/mod.rs | 1 + .../src/compressed_block_payload/v0.rs | 15 +++++++++++++ .../src/compressed_block_payload/v1.rs | 14 ++++++++++++ crates/compression/src/lib.rs | 22 +++++++++++++++++++ 5 files changed, 55 insertions(+), 19 deletions(-) diff --git a/crates/compression/src/compress.rs b/crates/compression/src/compress.rs index d5ced9230ff..0330121daa4 100644 --- a/crates/compression/src/compress.rs +++ b/crates/compression/src/compress.rs @@ -41,15 +41,6 @@ use std::collections::{ HashSet, }; -#[cfg(feature = "fault-proving")] -use crate::{ - CompressedBlockHeader, - CompressedBlockPayloadV1, -}; - -#[cfg(not(feature = "fault-proving"))] -use crate::CompressedBlockPayloadV0; - pub trait CompressDb: TemporalRegistryAll + EvictorDbAll + UtxoIdToPointer {} impl CompressDb for T where T: TemporalRegistryAll + EvictorDbAll + UtxoIdToPointer {} @@ -78,18 +69,11 @@ where let transactions = target.compress_with(&mut ctx).await?; let registrations: RegistrationsPerTable = ctx.finalize()?; - #[cfg(not(feature = "fault-proving"))] - return Ok(VersionedCompressedBlock::V0(CompressedBlockPayloadV0 { - registrations, - header: block.header().into(), - transactions, - })); - #[cfg(feature = "fault-proving")] - Ok(VersionedCompressedBlock::V1(CompressedBlockPayloadV1 { + Ok(VersionedCompressedBlock::new( + block.header(), registrations, - header: CompressedBlockHeader::from(block.header()), transactions, - })) + )) } /// Preparation pass through the block to collect all keys accessed during compression. diff --git a/crates/compression/src/compressed_block_payload/mod.rs b/crates/compression/src/compressed_block_payload/mod.rs index 420eb16447d..966457f1bd3 100644 --- a/crates/compression/src/compressed_block_payload/mod.rs +++ b/crates/compression/src/compressed_block_payload/mod.rs @@ -1,3 +1,4 @@ pub(crate) mod v0; +#[cfg(feature = "fault-proving")] pub(crate) mod v1; diff --git a/crates/compression/src/compressed_block_payload/v0.rs b/crates/compression/src/compressed_block_payload/v0.rs index deef0d9c1f2..0ebe01b64cb 100644 --- a/crates/compression/src/compressed_block_payload/v0.rs +++ b/crates/compression/src/compressed_block_payload/v0.rs @@ -6,6 +6,7 @@ use fuel_core_types::{ blockchain::{ header::{ ApplicationHeader, + BlockHeader, ConsensusHeader, PartialBlockHeader, }, @@ -51,3 +52,17 @@ impl VersionedBlockPayload for CompressedBlockPayloadV0 { self.header } } + +impl CompressedBlockPayloadV0 { + pub(crate) fn new( + header: &BlockHeader, + registrations: RegistrationsPerTable, + transactions: Vec, + ) -> Self { + Self { + header: PartialBlockHeader::from(header), + registrations, + transactions, + } + } +} diff --git a/crates/compression/src/compressed_block_payload/v1.rs b/crates/compression/src/compressed_block_payload/v1.rs index da72bb396fd..50de08d8b6f 100644 --- a/crates/compression/src/compressed_block_payload/v1.rs +++ b/crates/compression/src/compressed_block_payload/v1.rs @@ -104,3 +104,17 @@ impl VersionedBlockPayload for CompressedBlockPayloadV1 { PartialBlockHeader::from(&self.header) } } + +impl CompressedBlockPayloadV1 { + pub(crate) fn new( + header: &BlockHeader, + registrations: RegistrationsPerTable, + transactions: Vec, + ) -> Self { + Self { + header: CompressedBlockHeader::from(header), + registrations, + transactions, + } + } +} diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index 96c1ec81d86..8bc58f69c70 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -22,6 +22,7 @@ use fuel_core_types::{ blockchain::{ header::{ ApplicationHeader, + BlockHeader, ConsensusHeader, PartialBlockHeader, }, @@ -54,6 +55,27 @@ pub enum VersionedCompressedBlock { V1(CompressedBlockPayloadV1), } +impl VersionedCompressedBlock { + fn new( + header: &BlockHeader, + registrations: RegistrationsPerTable, + transactions: Vec, + ) -> Self { + #[cfg(not(feature = "fault-proving"))] + return Self::V0(CompressedBlockPayloadV0::new( + header, + registrations, + transactions, + )); + #[cfg(feature = "fault-proving")] + Self::V1(CompressedBlockPayloadV1::new( + header, + registrations, + transactions, + )) + } +} + impl Default for VersionedCompressedBlock { fn default() -> Self { Self::V0(Default::default()) From dc9e1ed8fdf004cedeb468c945438df059817de7 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Tue, 14 Jan 2025 21:50:45 +0530 Subject: [PATCH 09/16] fix: toml lint --- crates/compression/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/compression/Cargo.toml b/crates/compression/Cargo.toml index 7636684b82e..c47b24e941e 100644 --- a/crates/compression/Cargo.toml +++ b/crates/compression/Cargo.toml @@ -18,6 +18,7 @@ description = "Compression and decompression of Fuel blocks for DA storage." [dependencies] anyhow = { workspace = true } +enum_dispatch = "0.3.13" fuel-core-types = { workspace = true, features = [ "alloc", "serde", @@ -28,7 +29,6 @@ rand = { workspace = true, optional = true } serde = { version = "1.0", features = ["derive"] } strum = { workspace = true } strum_macros = { workspace = true } -enum_dispatch = "0.3.13" [dev-dependencies] fuel-core-compression = { path = ".", features = ["test-helpers"] } From d92e4ef4a05e1572c903779659571a8c657a8338 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 15 Jan 2025 09:30:47 +0530 Subject: [PATCH 10/16] fix: clippy --- crates/compression/src/compressed_block_payload/v0.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/compression/src/compressed_block_payload/v0.rs b/crates/compression/src/compressed_block_payload/v0.rs index 0ebe01b64cb..fc001a7e16c 100644 --- a/crates/compression/src/compressed_block_payload/v0.rs +++ b/crates/compression/src/compressed_block_payload/v0.rs @@ -29,7 +29,7 @@ pub struct CompressedBlockPayloadV0 { impl VersionedBlockPayload for CompressedBlockPayloadV0 { fn height(&self) -> &BlockHeight { - &self.header.height() + self.header.height() } fn consensus_header(&self) -> &ConsensusHeader { From 7dbb0c15daf32c0416a6113979173ead80d91077 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 15 Jan 2025 09:31:25 +0530 Subject: [PATCH 11/16] fix: doc --- crates/compression/src/compressed_block_payload/v0.rs | 1 + crates/compression/src/compressed_block_payload/v1.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/compression/src/compressed_block_payload/v0.rs b/crates/compression/src/compressed_block_payload/v0.rs index fc001a7e16c..9e22d00010f 100644 --- a/crates/compression/src/compressed_block_payload/v0.rs +++ b/crates/compression/src/compressed_block_payload/v0.rs @@ -54,6 +54,7 @@ impl VersionedBlockPayload for CompressedBlockPayloadV0 { } impl CompressedBlockPayloadV0 { + /// Create a new compressed block payload V0. pub(crate) fn new( header: &BlockHeader, registrations: RegistrationsPerTable, diff --git a/crates/compression/src/compressed_block_payload/v1.rs b/crates/compression/src/compressed_block_payload/v1.rs index 50de08d8b6f..5463ffd4ecb 100644 --- a/crates/compression/src/compressed_block_payload/v1.rs +++ b/crates/compression/src/compressed_block_payload/v1.rs @@ -106,6 +106,7 @@ impl VersionedBlockPayload for CompressedBlockPayloadV1 { } impl CompressedBlockPayloadV1 { + /// Create a new compressed block payload V1. pub(crate) fn new( header: &BlockHeader, registrations: RegistrationsPerTable, From 4060f5d1b1fcff36ed9d85f3ea5410f4ad0ae464 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 15 Jan 2025 09:32:10 +0530 Subject: [PATCH 12/16] fix: allow unused --- crates/compression/src/compressed_block_payload/v0.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/compression/src/compressed_block_payload/v0.rs b/crates/compression/src/compressed_block_payload/v0.rs index 9e22d00010f..ea1555e8e24 100644 --- a/crates/compression/src/compressed_block_payload/v0.rs +++ b/crates/compression/src/compressed_block_payload/v0.rs @@ -55,6 +55,7 @@ impl VersionedBlockPayload for CompressedBlockPayloadV0 { impl CompressedBlockPayloadV0 { /// Create a new compressed block payload V0. + #[allow(unused)] pub(crate) fn new( header: &BlockHeader, registrations: RegistrationsPerTable, From 6331a31a39c284ec7120b523b90429b2099c61a9 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:31:20 +0530 Subject: [PATCH 13/16] fix: clean up postcard roundtrip tests --- Cargo.lock | 2 +- crates/compression/src/lib.rs | 172 +++++++++++++++++++++++++++------- 2 files changed, 140 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d00215d3c01..9dd90e6a94b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2802,7 +2802,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.95", + "syn 2.0.96", ] [[package]] diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index 8bc58f69c70..b3cbb2db64b 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -98,8 +98,6 @@ mod tests { tai64::Tai64, }; use proptest::prelude::*; - #[cfg(feature = "fault-proving")] - use std::str::FromStr; fn keyspace() -> impl Strategy { prop_oneof![ @@ -111,27 +109,74 @@ mod tests { ] } - proptest! { - /// Serialization for compressed transactions is already tested in fuel-vm, - /// but the rest of the block de/serialization is tested here. - #[test] - fn postcard_roundtrip( - da_height in 0..=u64::MAX, - prev_root in prop::array::uniform32(0..=u8::MAX), - height in 0..=u32::MAX, - consensus_parameters_version in 0..=u32::MAX, - state_transition_bytecode_version in 0..=u32::MAX, - registration_inputs in prop::collection::vec( - (keyspace(), prop::num::u16::ANY, prop::array::uniform32(0..=u8::MAX)).prop_map(|(ks, rk, arr)| { - let k = RegistryKey::try_from(rk as u32).unwrap(); - (ks, k, arr) - }), - 0..123 + #[derive(Debug)] + struct PostcardRoundtripStrategy { + da_height: u64, + prev_root: [u8; 32], + height: u32, + consensus_parameters_version: u32, + state_transition_bytecode_version: u32, + registration_inputs: Vec<(RegistryKeyspace, RegistryKey, [u8; 32])>, + } + + fn postcard_roundtrip_strategy() -> impl Strategy { + ( + 0..=u64::MAX, + prop::array::uniform32(0..=u8::MAX), + 0..=u32::MAX, + 0..=u32::MAX, + 0..=u32::MAX, + prop::collection::vec( + ( + keyspace(), + prop::num::u16::ANY, + prop::array::uniform32(0..=u8::MAX), + ) + .prop_map(|(ks, rk, arr)| { + let k = RegistryKey::try_from(rk as u32).unwrap(); + (ks, k, arr) + }), + 0..123, ), - ) { - let mut registrations: RegistrationsPerTable = Default::default(); + ) + .prop_map( + |( + da_height, + prev_root, + height, + consensus_parameters_version, + state_transition_bytecode_version, + registration_inputs, + )| { + PostcardRoundtripStrategy { + da_height, + prev_root, + height, + consensus_parameters_version, + state_transition_bytecode_version, + registration_inputs, + } + }, + ) + } - for (ks, key, arr) in registration_inputs { + /// Serialization for compressed transactions is already tested in fuel-vm, + /// but the rest of the block de/serialization is tested here. + #[test] + fn postcard_roundtrip_v0() { + proptest!(|(strat in postcard_roundtrip_strategy())| { + let PostcardRoundtripStrategy { + da_height, + prev_root, + height, + consensus_parameters_version, + state_transition_bytecode_version, + registration_inputs, + } = strat; + + + let mut registrations: RegistrationsPerTable = Default::default(); + for (ks, key, arr) in registration_inputs { let value_len_limit = (key.as_u32() % 32) as usize; match ks { RegistryKeyspace::Address => { @@ -152,7 +197,6 @@ mod tests { } } - #[cfg(not(feature = "fault-proving"))] let header = PartialBlockHeader { application: ApplicationHeader { da_height: da_height.into(), @@ -167,7 +211,74 @@ mod tests { generated: Empty } }; - #[cfg(feature = "fault-proving")] + + let original = VersionedCompressedBlock::V0(CompressedBlockPayloadV0 { + registrations, + header, + transactions: vec![], + }); + + let compressed = postcard::to_allocvec(&original).unwrap(); + let decompressed: VersionedCompressedBlock = + postcard::from_bytes(&compressed).unwrap(); + + let consensus_header = decompressed.consensus_header(); + let application_header = decompressed.application_header(); + + assert_eq!(decompressed.registrations(), original.registrations()); + + assert_eq!(application_header.da_height, da_height.into()); + assert_eq!(consensus_header.prev_root, prev_root.into()); + assert_eq!(consensus_header.height, height.into()); + assert_eq!(application_header.consensus_parameters_version, consensus_parameters_version); + assert_eq!(application_header.state_transition_bytecode_version, state_transition_bytecode_version); + + assert!(decompressed.transactions().is_empty()); + }); + } + + #[cfg(feature = "fault-proving")] + #[test] + fn postcard_roundtrip_v1() { + use compressed_block_payload::v1::{ + CompressedBlockHeader, + CompressedBlockPayloadV1, + }; + use fuel_core_types::blockchain::primitives::BlockId; + use std::str::FromStr; + + proptest!(|(strat in postcard_roundtrip_strategy())| { + let PostcardRoundtripStrategy { + da_height, + prev_root, + height, + consensus_parameters_version, + state_transition_bytecode_version, + registration_inputs, + } = strat; + + let mut registrations: RegistrationsPerTable = Default::default(); + for (ks, key, arr) in registration_inputs { + let value_len_limit = (key.as_u32() % 32) as usize; + match ks { + RegistryKeyspace::Address => { + registrations.address.push((key, arr.into())); + } + RegistryKeyspace::AssetId => { + registrations.asset_id.push((key, arr.into())); + } + RegistryKeyspace::ContractId => { + registrations.contract_id.push((key, arr.into())); + } + RegistryKeyspace::ScriptCode => { + registrations.script_code.push((key, arr[..value_len_limit].to_vec().into())); + } + RegistryKeyspace::PredicateCode => { + registrations.predicate_code.push((key, arr[..value_len_limit].to_vec().into())); + } + } + } + let header = CompressedBlockHeader { application: ApplicationHeader { da_height: da_height.into(), @@ -184,16 +295,10 @@ mod tests { block_id: BlockId::from_str("0xecea85c17070bc2e65f911310dbd01198f4436052ebba96cded9ddf30c58dd1a").unwrap(), }; - #[cfg(not(feature = "fault-proving"))] - let original = VersionedCompressedBlock::V0(CompressedBlockPayloadV0 { - registrations, - header, - transactions: vec![], - }); - #[cfg(feature = "fault-proving")] + let original = VersionedCompressedBlock::V1(CompressedBlockPayloadV1 { - registrations, header, + registrations, transactions: vec![] }); @@ -214,10 +319,11 @@ mod tests { assert!(decompressed.transactions().is_empty()); - #[cfg(feature = "fault-proving")] if let VersionedCompressedBlock::V1(block) = decompressed { assert_eq!(block.header.block_id, header.block_id); + } else { + panic!("Expected V1 block, got {:?}", decompressed); } - } + }); } } From 69ab92ab71aa0107eebfd50d24a789bddcd0b3a0 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:34:00 +0530 Subject: [PATCH 14/16] fix: spelling --- crates/compression/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index b3cbb2db64b..ae1258dd6a3 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -164,7 +164,7 @@ mod tests { /// but the rest of the block de/serialization is tested here. #[test] fn postcard_roundtrip_v0() { - proptest!(|(strat in postcard_roundtrip_strategy())| { + proptest!(|(strategy in postcard_roundtrip_strategy())| { let PostcardRoundtripStrategy { da_height, prev_root, @@ -172,7 +172,7 @@ mod tests { consensus_parameters_version, state_transition_bytecode_version, registration_inputs, - } = strat; + } = strategy; let mut registrations: RegistrationsPerTable = Default::default(); @@ -247,7 +247,7 @@ mod tests { use fuel_core_types::blockchain::primitives::BlockId; use std::str::FromStr; - proptest!(|(strat in postcard_roundtrip_strategy())| { + proptest!(|(strategy in postcard_roundtrip_strategy())| { let PostcardRoundtripStrategy { da_height, prev_root, @@ -255,7 +255,7 @@ mod tests { consensus_parameters_version, state_transition_bytecode_version, registration_inputs, - } = strat; + } = strategy; let mut registrations: RegistrationsPerTable = Default::default(); for (ks, key, arr) in registration_inputs { From 0549a1ad19af9c0a7205ebae00dcad92eb7c1a8b Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:36:01 +0530 Subject: [PATCH 15/16] fix: redundant reg table --- crates/compression/src/lib.rs | 79 +++++++++++++---------------------- 1 file changed, 30 insertions(+), 49 deletions(-) diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index ae1258dd6a3..681a466e121 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -116,7 +116,7 @@ mod tests { height: u32, consensus_parameters_version: u32, state_transition_bytecode_version: u32, - registration_inputs: Vec<(RegistryKeyspace, RegistryKey, [u8; 32])>, + registrations: RegistrationsPerTable, } fn postcard_roundtrip_strategy() -> impl Strategy { @@ -148,13 +148,39 @@ mod tests { state_transition_bytecode_version, registration_inputs, )| { + let mut registrations: RegistrationsPerTable = Default::default(); + for (ks, key, arr) in registration_inputs { + let value_len_limit = (key.as_u32() % 32) as usize; + match ks { + RegistryKeyspace::Address => { + registrations.address.push((key, arr.into())); + } + RegistryKeyspace::AssetId => { + registrations.asset_id.push((key, arr.into())); + } + RegistryKeyspace::ContractId => { + registrations.contract_id.push((key, arr.into())); + } + RegistryKeyspace::ScriptCode => { + registrations + .script_code + .push((key, arr[..value_len_limit].to_vec().into())); + } + RegistryKeyspace::PredicateCode => { + registrations + .predicate_code + .push((key, arr[..value_len_limit].to_vec().into())); + } + } + } + PostcardRoundtripStrategy { da_height, prev_root, height, consensus_parameters_version, state_transition_bytecode_version, - registration_inputs, + registrations, } }, ) @@ -171,32 +197,9 @@ mod tests { height, consensus_parameters_version, state_transition_bytecode_version, - registration_inputs, + registrations, } = strategy; - - let mut registrations: RegistrationsPerTable = Default::default(); - for (ks, key, arr) in registration_inputs { - let value_len_limit = (key.as_u32() % 32) as usize; - match ks { - RegistryKeyspace::Address => { - registrations.address.push((key, arr.into())); - } - RegistryKeyspace::AssetId => { - registrations.asset_id.push((key, arr.into())); - } - RegistryKeyspace::ContractId => { - registrations.contract_id.push((key, arr.into())); - } - RegistryKeyspace::ScriptCode => { - registrations.script_code.push((key, arr[..value_len_limit].to_vec().into())); - } - RegistryKeyspace::PredicateCode => { - registrations.predicate_code.push((key, arr[..value_len_limit].to_vec().into())); - } - } - } - let header = PartialBlockHeader { application: ApplicationHeader { da_height: da_height.into(), @@ -254,31 +257,9 @@ mod tests { height, consensus_parameters_version, state_transition_bytecode_version, - registration_inputs, + registrations, } = strategy; - let mut registrations: RegistrationsPerTable = Default::default(); - for (ks, key, arr) in registration_inputs { - let value_len_limit = (key.as_u32() % 32) as usize; - match ks { - RegistryKeyspace::Address => { - registrations.address.push((key, arr.into())); - } - RegistryKeyspace::AssetId => { - registrations.asset_id.push((key, arr.into())); - } - RegistryKeyspace::ContractId => { - registrations.contract_id.push((key, arr.into())); - } - RegistryKeyspace::ScriptCode => { - registrations.script_code.push((key, arr[..value_len_limit].to_vec().into())); - } - RegistryKeyspace::PredicateCode => { - registrations.predicate_code.push((key, arr[..value_len_limit].to_vec().into())); - } - } - } - let header = CompressedBlockHeader { application: ApplicationHeader { da_height: da_height.into(), From 22e2afc14f7015d0cef9e83b8e5957f81df3d40a Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:23:52 +0530 Subject: [PATCH 16/16] fix: make v0/v1 public and remove feature flag --- crates/compression/src/compressed_block_payload/mod.rs | 5 ++--- crates/compression/src/compressed_block_payload/v1.rs | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/compression/src/compressed_block_payload/mod.rs b/crates/compression/src/compressed_block_payload/mod.rs index 966457f1bd3..eeebe11bfb5 100644 --- a/crates/compression/src/compressed_block_payload/mod.rs +++ b/crates/compression/src/compressed_block_payload/mod.rs @@ -1,4 +1,3 @@ -pub(crate) mod v0; +pub mod v0; -#[cfg(feature = "fault-proving")] -pub(crate) mod v1; +pub mod v1; diff --git a/crates/compression/src/compressed_block_payload/v1.rs b/crates/compression/src/compressed_block_payload/v1.rs index 5463ffd4ecb..51e0012a615 100644 --- a/crates/compression/src/compressed_block_payload/v1.rs +++ b/crates/compression/src/compressed_block_payload/v1.rs @@ -107,6 +107,7 @@ impl VersionedBlockPayload for CompressedBlockPayloadV1 { impl CompressedBlockPayloadV1 { /// Create a new compressed block payload V1. + #[allow(unused)] pub(crate) fn new( header: &BlockHeader, registrations: RegistrationsPerTable,