Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fault_proving(compression): include block_id in da compressed block headers #2551

Merged
merged 18 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- [2551](https://github.com/FuelLabs/fuel-core/pull/2551): Enhanced the DA compressed block header to include block id.

## [Version 0.41.0]

### Added
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ production = [
"parquet",
"aws-kms",
]
fault-proving = ["fuel-core-compression/fault-proving"]
2 changes: 2 additions & 0 deletions crates/compression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -42,3 +43,4 @@ test-helpers = [
"fuel-core-types/random",
"fuel-core-types/std",
]
fault-proving = []
7 changes: 3 additions & 4 deletions crates/compression/src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
RegistrationsPerTable,
TemporalRegistryAll,
},
CompressedBlockPayloadV0,
VersionedCompressedBlock,
};
use anyhow::Context;
Expand Down Expand Up @@ -70,11 +69,11 @@ where
let transactions = target.compress_with(&mut ctx).await?;
let registrations: RegistrationsPerTable = ctx.finalize()?;

Ok(VersionedCompressedBlock::V0(CompressedBlockPayloadV0 {
Ok(VersionedCompressedBlock::new(
block.header(),
registrations,
header: block.header().into(),
transactions,
}))
))
}

/// Preparation pass through the block to collect all keys accessed during compression.
Expand Down
3 changes: 3 additions & 0 deletions crates/compression/src/compressed_block_payload/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod v0;

pub mod v1;
70 changes: 70 additions & 0 deletions crates/compression/src/compressed_block_payload/v0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use crate::{
registry::RegistrationsPerTable,
VersionedBlockPayload,
};
use fuel_core_types::{
blockchain::{
header::{
ApplicationHeader,
BlockHeader,
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<CompressedTransaction>,
}

impl VersionedBlockPayload for CompressedBlockPayloadV0 {
fn height(&self) -> &BlockHeight {
self.header.height()
}

fn consensus_header(&self) -> &ConsensusHeader<Empty> {
&self.header.consensus
}

fn application_header(&self) -> &ApplicationHeader<Empty> {
&self.header.application
}

fn registrations(&self) -> &RegistrationsPerTable {
&self.registrations
}

fn transactions(&self) -> Vec<CompressedTransaction> {
self.transactions.clone()
}

fn partial_block_header(&self) -> PartialBlockHeader {
self.header
}
}

impl CompressedBlockPayloadV0 {
/// Create a new compressed block payload V0.
#[allow(unused)]
pub(crate) fn new(
header: &BlockHeader,
registrations: RegistrationsPerTable,
transactions: Vec<CompressedTransaction>,
) -> Self {
Self {
header: PartialBlockHeader::from(header),
registrations,
transactions,
}
}
}
122 changes: 122 additions & 0 deletions crates/compression/src/compressed_block_payload/v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
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<Empty>,
/// The consensus header.
pub consensus: ConsensusHeader<Empty>,
// 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<CompressedTransaction>,
}

impl VersionedBlockPayload for CompressedBlockPayloadV1 {
fn height(&self) -> &BlockHeight {
&self.header.consensus.height
}

fn consensus_header(&self) -> &ConsensusHeader<Empty> {
&self.header.consensus
}

fn application_header(&self) -> &ApplicationHeader<Empty> {
&self.header.application
}

fn registrations(&self) -> &RegistrationsPerTable {
&self.registrations
}

fn transactions(&self) -> Vec<CompressedTransaction> {
self.transactions.clone()
}

fn partial_block_header(&self) -> PartialBlockHeader {
PartialBlockHeader::from(&self.header)
}
}

impl CompressedBlockPayloadV1 {
/// Create a new compressed block payload V1.
#[allow(unused)]
pub(crate) fn new(
header: &BlockHeader,
registrations: RegistrationsPerTable,
transactions: Vec<CompressedTransaction>,
) -> Self {
Self {
header: CompressedBlockHeader::from(header),
registrations,
transactions,
}
}
}
15 changes: 7 additions & 8 deletions crates/compression/src/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
TemporalRegistry,
},
registry::TemporalRegistryAll,
VersionedBlockPayload,
VersionedCompressedBlock,
};
use fuel_core_types::{
Expand Down Expand Up @@ -55,28 +56,26 @@ pub async fn decompress<D>(
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 = <Vec<Transaction> as DecompressibleBy<_>>::decompress_with(
compressed.transactions,
block.transactions(),
&ctx,
)
.await?;

Ok(PartialFuelBlock {
header: compressed.header,
header: block.partial_block_header(),
transactions,
})
}
Expand Down
Loading
Loading