Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMenko committed Jun 27, 2023
1 parent a405f4c commit c1c88b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/lazy_merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
sync::{Arc, Mutex},
};

use bincode::serialize;
use bincode::{serialize, Options};

Check warning on line 12 in src/lazy_merkle_tree.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `serialize`
use mmap_rs::{MmapMut, MmapOptions};
use thiserror::Error;

Expand Down Expand Up @@ -1119,12 +1119,18 @@ impl<H: Hasher> MmapMutWrapper<H> {
initial_value: &H::Hash,
storage_size: usize,
) -> Result<Self, DenseMMapError> {
let empty_hash_bytes = serialize(initial_value).expect("cannot serialize initial value");
let initial_value_size = std::mem::size_of_val(initial_value);

let bincode_opts = bincode::DefaultOptions::new()
.with_fixint_encoding()
.reject_trailing_bytes()
.with_little_endian()
.with_no_limit();

let empty_hash_bytes = bincode_opts.serialize(initial_value).expect("cannot serialize initial value");

let bytes: Vec<u8> =
empty_hash_bytes.repeat(storage_size * initial_value_size / empty_hash_bytes.len());
let file_size: u64 = storage_size as u64 * initial_value_size as u64;
empty_hash_bytes.repeat(storage_size);
let file_size: u64 = storage_size as u64 * empty_hash_bytes.len() as u64;

let mut file = match OpenOptions::new()
.read(true)
Expand Down
2 changes: 1 addition & 1 deletion src/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
/// Hash types, values and algorithms for a Merkle tree
pub trait Hasher {
/// Type of the leaf and node hashes
type Hash: Clone + Eq + Serialize + DeserializeOwned + Debug;
type Hash: Clone + Eq + Serialize + Debug;

/// Compute the hash of an intermediate node
fn hash_node(left: &Self::Hash, right: &Self::Hash) -> Self::Hash;
Expand Down

0 comments on commit c1c88b5

Please sign in to comment.