Skip to content

Commit

Permalink
Update the logic for expand to include upper layers.
Browse files Browse the repository at this point in the history
There was a bug where expanding the lowest layer and calling set on
all of the new elements was not sufficient to grow the upper layers.

This commit also fixes a warning about the package-level profile
override being ineffective.
  • Loading branch information
eljobe committed Apr 29, 2024
1 parent fc16ec3 commit 1a52847
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 0 additions & 3 deletions arbitrator/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,3 @@ gperftools = { version = "0.2.0", optional = true }
counters = []
cpuprof = ["gperftools"]
heapprof = ["gperftools", "gperftools/heap"]

[profile.release]
debug = true
4 changes: 2 additions & 2 deletions arbitrator/bench/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Args {

fn main() -> eyre::Result<()> {
let args = Args::parse();
let step_sizes = [1, 1 << 10, 1 << 15, 1 << 20];
let step_sizes = [1, 1 << 10, 1 << 15, 1 << 20, 1 << 24];
if args.always_merkleize {
println!("Running benchmark with always merkleize feature on");
} else {
Expand Down Expand Up @@ -94,7 +94,7 @@ fn main() -> eyre::Result<()> {

let total_end_time = total.elapsed();
println!(
"avg hash time {:?}, avg step time {:?}, step size {}, num_iters {}, total time {:?}",
"avg hash time {:>12?}, avg step time {:>12?}, step size {:>8}, num_iters {}, total time {:>12?}",
average(&hash_times),
average(&step_times),
step_size,
Expand Down
8 changes: 6 additions & 2 deletions arbitrator/prover/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl Merkle {
} else if idx == layer.len() {
layer.push(next_hash);
} else {
panic!("Index {} out of bounds {}", idx, layer.len());
panic!("Index {} out of bounds {} in layer {}", idx, layer.len(), layer_i);
}
if layer_i == layers_len - 1 {
// next_hash isn't needed
Expand Down Expand Up @@ -334,7 +334,11 @@ impl Merkle {
return Err("Cannot extend with more leaves than the capicity of the tree.".to_owned());
}
let mut idx = self.layers[0].len();
self.layers[0].resize(idx + hashes.len(), self.empty_layers[0]);
let mut new_size = idx + hashes.len();
for (layer_i, layer) in self.layers.iter_mut().enumerate() {
layer.resize(new_size, self.empty_layers[layer_i]);
new_size >>= 1;
}
for hash in hashes {
self.set(idx, hash);
idx += 1;
Expand Down

0 comments on commit 1a52847

Please sign in to comment.