Skip to content

Commit

Permalink
Simply dense Merkle metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
bvrooman committed Jan 31, 2024
1 parent b980c7d commit 312661c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions crates/fuel-core/src/database/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use fuel_core_storage::{
structured_storage::TableWithBlueprint,
tables::{
merkle::{
DenseMerkleMetadataV1,
DenseMerkleMetadata,
FuelBlockMerkleData,
FuelBlockMerkleMetadata,
},
Expand Down Expand Up @@ -115,7 +115,7 @@ impl StorageMutate<FuelBlocks> for Database {
.next()
.transpose()?
.map(|(_, metadata)| metadata)
.unwrap_or(DenseMerkleMetadataV1::default().into());
.unwrap_or_default();

let storage = self.borrow_mut();
let mut tree: MerkleTree<FuelBlockMerkleData, _> =
Expand All @@ -124,9 +124,9 @@ impl StorageMutate<FuelBlocks> for Database {
tree.push(block_id.as_slice())?;

// Generate new metadata for the updated tree
let version = tree.leaves_count();
let root = tree.root();
let metadata = DenseMerkleMetadataV1 { version, root }.into();
let version = tree.leaves_count();
let metadata = DenseMerkleMetadata::new(root, version);
self.storage::<FuelBlockMerkleMetadata>()
.insert(height, &metadata)?;

Expand Down
8 changes: 7 additions & 1 deletion crates/storage/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,20 @@ pub mod merkle {
V1(DenseMerkleMetadataV1),
}

#[cfg(any(test, feature = "test-helpers"))]
impl Default for DenseMerkleMetadata {
fn default() -> Self {
Self::V1(Default::default())
}
}

impl DenseMerkleMetadata {
/// Create a new dense Merkle metadata object from the given Merkle
/// root and version
pub fn new(root: MerkleRoot, version: u64) -> Self {
let metadata = DenseMerkleMetadataV1 { root, version };
Self::V1(metadata)
}

/// Get the Merkle root of the dense Metadata
pub fn root(&self) -> &MerkleRoot {
match self {
Expand Down

0 comments on commit 312661c

Please sign in to comment.