-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fault_proving(compression): include block_id in da compressed block h…
…eaders (#2551) ## Linked Issues/PRs <!-- List of related issues/PRs --> - closes #2567 ## Description <!-- List of detailed changes --> Defines a new version of the `CompressedBlockPayload` which has a header that contains the block_id, relevant for fault proving. Also refactored the proptest strategy generation and moved the macro internally so that tests can be ran from IDEs easily. ## Checklist - [x] Breaking changes are clearly marked as such in the PR description and changelog - [x] New behavior is reflected in tests - [x] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [x] I have reviewed the code myself - [x] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else?
- Loading branch information
Showing
11 changed files
with
442 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -82,3 +82,4 @@ production = [ | |
"parquet", | ||
"aws-kms", | ||
] | ||
fault-proving = ["fuel-core-compression/fault-proving"] |
This file contains 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 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 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,3 @@ | ||
pub mod v0; | ||
|
||
pub mod v1; |
This file contains 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,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, | ||
} | ||
} | ||
} |
This file contains 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,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, | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.