Skip to content

Commit

Permalink
apply
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Apr 9, 2024
1 parent e5d9788 commit 87cd300
Show file tree
Hide file tree
Showing 5 changed files with 501 additions and 474 deletions.
24 changes: 14 additions & 10 deletions examples/abort_test/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{env, process::Stdio};
use std::env;
use std::process::Stdio;

use color_eyre::Result;
use semaphore::{
cascading_merkle_tree::{CascadingMerkleTree, MmapTreeStorageConfig, MmapVec},
merkle_tree::Hasher,
};
use semaphore::cascading_merkle_tree::CascadingMerkleTree;
use semaphore::generic_storage::MmapVec;
use semaphore::merkle_tree::Hasher;

#[derive(Debug, Clone, PartialEq, Eq)]
struct TestHasher;
Expand All @@ -19,15 +19,15 @@ impl Hasher for TestHasher {
fn main() -> Result<()> {
let args: Vec<String> = env::args().collect();

let config = unsafe { MmapTreeStorageConfig::new("target/tmp/abort.mmap".into()) };
let tempfile = tempfile::tempfile()?;
let mmap_vec: MmapVec<<TestHasher as Hasher>::Hash> =
unsafe { MmapVec::new(tempfile.try_clone()?)? };

// initialize
if args.len() == 1 {
println!("initializing\n");
let leaves = vec![1; 1_000_000];
let _ = CascadingMerkleTree::<TestHasher, MmapVec<TestHasher>>::new_with_leaves(
config, 30, &1, &leaves,
);
let _ = CascadingMerkleTree::<TestHasher, _>::with_leaves(mmap_vec, 30, &1, &leaves);
for i in 0..100 {
println!("running interation {}", i);
let output = std::process::Command::new("target/debug/examples/abort_test")
Expand All @@ -42,8 +42,12 @@ fn main() -> Result<()> {
return Ok(());
}

drop(mmap_vec);

let mmap_vec: MmapVec<<TestHasher as Hasher>::Hash> = unsafe { MmapVec::new(tempfile)? };

println!("restoring");
let mut tree = CascadingMerkleTree::<TestHasher, MmapVec<TestHasher>>::restore(config, 30, &1)?;
let mut tree = CascadingMerkleTree::<TestHasher, _>::new(mmap_vec, 30, &1);
tree.push(2).unwrap();

println!("tree length: {}", tree.num_leaves());
Expand Down
Loading

0 comments on commit 87cd300

Please sign in to comment.