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

fix(headers): move tx_id_commitment to application_headers #2678

Merged
merged 6 commits into from
Feb 11, 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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Breaking
- [2648](https://github.com/FuelLabs/fuel-core/pull/2648): Add feature-flagged field to block header `fault_proving_header` that contains a commitment to all transaction ids.
- [2678](https://github.com/FuelLabs/fuel-core/pull/2678): Removed public accessors for `BlockHeader` fields and replaced with methods instead, moved `tx_id_commitment` to the application header of `BlockHeaderV2`.

### Added
- [2150](https://github.com/FuelLabs/fuel-core/pull/2150): Upgraded `libp2p` to `0.54.1` and introduced `ConnectionLimiter` to limit pending incoming/outgoing connections.
- [2648](https://github.com/FuelLabs/fuel-core/pull/2648): Add feature-flagged field to block header `fault_proving_header` that contains a commitment to all transaction ids.

### Changed

Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

7 changes: 4 additions & 3 deletions bin/fuel-core/src/cli/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ mod tests {
.last_block_config()
.cloned()
.expect("Expects the last block config to be set");
block.header_mut().application_mut().da_height =
last_block_config.da_block_height;
block
.header_mut()
.set_da_height(last_block_config.da_block_height);
block
.header_mut()
.set_block_height(last_block_config.block_height);
Expand Down Expand Up @@ -557,7 +558,7 @@ mod tests {
fn given_block(&mut self) -> TableEntry<FuelBlocks> {
let mut block = CompressedBlock::default();
let height = self.rng.gen();
block.header_mut().application_mut().da_height = self.rng.gen();
block.header_mut().set_da_height(self.rng.gen());
block.header_mut().set_block_height(height);
let _ = self
.db
Expand Down
10 changes: 3 additions & 7 deletions crates/chain-config/src/config/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,9 @@ impl LastBlockConfig {
pub fn from_header(header: &BlockHeader, blocks_root: Bytes32) -> Self {
Self {
block_height: *header.height(),
da_block_height: header.application().da_height,
consensus_parameters_version: header
.application()
.consensus_parameters_version,
state_transition_version: header
.application()
.state_transition_bytecode_version,
da_block_height: header.da_height(),
consensus_parameters_version: header.consensus_parameters_version(),
state_transition_version: header.state_transition_bytecode_version(),
blocks_root,
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/compression/src/compressed_block_payload/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ impl From<&BlockHeader> for CompressedBlockHeader {
} = *header.consensus();
CompressedBlockHeader {
application: ApplicationHeader {
da_height: header.da_height,
consensus_parameters_version: header.consensus_parameters_version,
da_height: header.da_height(),
consensus_parameters_version: header.consensus_parameters_version(),
state_transition_bytecode_version: header
.state_transition_bytecode_version,
.state_transition_bytecode_version(),
generated: Empty {},
},
consensus: ConsensusHeader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ where
storage: self,
latest_state_transition_bytecode_version: block
.header()
.state_transition_bytecode_version,
.state_transition_bytecode_version(),
latest_consensus_parameters_version: block
.header()
.consensus_parameters_version,
.consensus_parameters_version(),
};

update_transaction.process_block(block)?;
Expand Down
10 changes: 5 additions & 5 deletions crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ mod tests {

assert!(skipped_transactions.is_empty());
assert_ne!(
start_block.header().transactions_root,
block.header().transactions_root
start_block.header().transactions_root(),
block.header().transactions_root()
);
assert_eq!(block.transactions().len(), 11);
assert!(block.transactions()[10].as_mint().is_some());
Expand Down Expand Up @@ -2713,7 +2713,7 @@ mod tests {
.message_id()
.to_bytes(),
);
assert_eq!(block.header().message_outbox_root.as_ref(), mt.root());
assert_eq!(block.header().message_outbox_root().as_ref(), mt.root());
}

#[test]
Expand Down Expand Up @@ -2752,7 +2752,7 @@ mod tests {

// Then
let empty_root = empty_sum_sha256();
assert_eq!(block.header().message_outbox_root.as_ref(), empty_root)
assert_eq!(block.header().message_outbox_root().as_ref(), empty_root)
}

#[test]
Expand Down Expand Up @@ -3387,7 +3387,7 @@ mod tests {

// then
let expected = root_calculator.root().into();
let actual = result.block.header().application().event_inbox_root;
let actual = result.block.header().event_inbox_root();
assert_eq!(actual, expected);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/fuel-core/src/query/message/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ async fn can_build_message_proof() {
)
.unwrap();
assert_eq!(
proof.message_block_header.message_outbox_root,
message_block.header().message_outbox_root
proof.message_block_header.message_outbox_root(),
message_block.header().message_outbox_root()
);
assert_eq!(
proof.message_block_header.height(),
Expand Down
16 changes: 8 additions & 8 deletions crates/fuel-core/src/schema/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,42 +188,42 @@ impl Header {

/// The layer 1 height of messages and events to include since the last layer 1 block number.
async fn da_height(&self) -> U64 {
self.0.da_height.0.into()
self.0.da_height().0.into()
}

/// The version of the consensus parameters used to create this block.
async fn consensus_parameters_version(&self) -> U32 {
self.0.consensus_parameters_version.into()
self.0.consensus_parameters_version().into()
}

/// The version of the state transition bytecode used to create this block.
async fn state_transition_bytecode_version(&self) -> U32 {
self.0.state_transition_bytecode_version.into()
self.0.state_transition_bytecode_version().into()
}

/// Number of transactions in this block.
async fn transactions_count(&self) -> U16 {
self.0.transactions_count.into()
self.0.transactions_count().into()
}

/// Number of message receipts in this block.
async fn message_receipt_count(&self) -> U32 {
self.0.message_receipt_count.into()
self.0.message_receipt_count().into()
}

/// Merkle root of transactions.
async fn transactions_root(&self) -> Bytes32 {
self.0.transactions_root.into()
self.0.transactions_root().into()
}

/// Merkle root of message receipts in this block.
async fn message_outbox_root(&self) -> Bytes32 {
self.0.message_outbox_root.into()
self.0.message_outbox_root().into()
}

/// Merkle root of inbox events in this block.
async fn event_inbox_root(&self) -> Bytes32 {
self.0.event_inbox_root.into()
self.0.event_inbox_root().into()
}

/// Fuel block height.
Expand Down
4 changes: 3 additions & 1 deletion crates/fuel-core/src/schema/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,12 @@ impl ConcreteStorage {
.get_current_block()?
.ok_or(not_found!("Block for VMDatabase"))?;

let application_header = block.header().as_empty_application_header();

let vm_database = VmStorage::new(
view.into_transaction(),
block.header().consensus(),
block.header().application(),
&application_header,
// TODO: Use a real coinbase address
Default::default(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl VerifierAdapter {
database: Database,
) -> Self {
let block_height = *genesis_block.header().height();
let da_block_height = genesis_block.header().da_height;
let da_block_height = genesis_block.header().da_height();
let config = VerifierConfig::new(consensus, block_height, da_block_height);
Self {
block_verifier: Arc::new(Verifier::new(config, database)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ impl RunnableTask for Task {
.sealed_block
.entity
.header()
.application()
.consensus_parameters_version;
.consensus_parameters_version();

if new_version > *self.shared_state.latest_consensus_parameters_version.lock() {
match self.shared_state.cache_consensus_parameters(new_version) {
Expand Down Expand Up @@ -296,10 +295,7 @@ mod tests {
version: ConsensusParametersVersion,
) -> SharedImportResult {
let mut block = Block::default();
block
.header_mut()
.application_mut()
.consensus_parameters_version = version;
block.header_mut().set_consensus_parameters_version(version);
let sealed_block = SealedBlock {
entity: block,
consensus: Default::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl DatabaseContracts for OnChainIterableKeyValueView {
impl DatabaseChain for OnChainIterableKeyValueView {
fn da_height(&self) -> StorageResult<DaBlockHeight> {
self.latest_compressed_block()?
.map(|block| block.header().da_height)
.map(|block| block.header().da_height())
.ok_or(not_found!("DaBlockHeight"))
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/fuel-core/src/service/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ pub async fn execute_genesis_block(
database_transaction_on_chain
.storage_as_mut::<ConsensusParametersVersions>()
.insert(
&genesis_block.header().consensus_parameters_version,
&genesis_block.header().consensus_parameters_version(),
&chain_config.consensus_parameters,
)?;

let bytecode_root = Hasher::hash(chain_config.state_transition_bytecode.as_slice());
database_transaction_on_chain
.storage_as_mut::<StateTransitionBytecodeVersions>()
.insert(
&genesis_block.header().state_transition_bytecode_version,
&genesis_block.header().state_transition_bytecode_version(),
&bytecode_root,
)?;
database_transaction_on_chain
Expand Down Expand Up @@ -723,7 +723,7 @@ mod tests {
.latest_block()
.unwrap()
.header()
.state_transition_bytecode_version;
.state_transition_bytecode_version();
last_block.blocks_root = view
.block_header_merkle_root(&last_block.block_height)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/fuel-core/src/service/genesis/importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl SnapshotImporter {
}

let block_height = *self.genesis_block.header().height();
let da_block_height = self.genesis_block.header().da_height;
let da_block_height = self.genesis_block.header().da_height();
let db = self.db.on_chain().clone();

let migration_name = migration_name::<TableBeingWritten, TableBeingWritten>();
Expand Down Expand Up @@ -233,7 +233,7 @@ impl SnapshotImporter {
}

let block_height = *self.genesis_block.header().height();
let da_block_height = self.genesis_block.header().da_height;
let da_block_height = self.genesis_block.header().da_height();

let db = self.db.off_chain().clone();

Expand Down
8 changes: 8 additions & 0 deletions crates/services/consensus_module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ fuel-core-types = { workspace = true, features = ["std"] }
[dev-dependencies]
fuel-core-types = { path = "../../types", features = ["test-helpers"] }
test-case = { workspace = true }

[features]
fault-proving = [
"fuel-core-types/fault-proving",
"fuel-core-storage/fault-proving",
"fuel-core-poa/fault-proving",
"fuel-core-chain-config/fault-proving",
]
10 changes: 8 additions & 2 deletions crates/services/consensus_module/poa/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn verify_block_fields<D: Database>(
let prev_header = database.block_header(&prev_height)?;

ensure!(
header.da_height >= prev_header.da_height,
header.da_height() >= prev_header.da_height(),
"The `da_height` of the next block can't be lower"
);

Expand All @@ -70,8 +70,14 @@ pub fn verify_block_fields<D: Database>(
"The `time` of the next block can't be lower"
);

let application_header_hash = match header {
BlockHeader::V1(header) => &header.application().hash(),
#[cfg(feature = "fault-proving")]
BlockHeader::V2(header) => &header.application().hash(),
};

ensure!(
header.application_hash() == &header.application().hash(),
header.application_hash() == application_header_hash,
"The application hash mismatch."
);

Expand Down
Loading
Loading