feat: Provide sequential Merkle tree builder#247
Conversation
Previously, the only way to construct a Merkle tree was to use `CpuParallel`. However, in some cases, using parallelism does not make sense or even adversely effects the program. Add the Merkle tree maker `CpuSequential`, which constructs the entire tree sequentially.
Sword-Smith
left a comment
There was a problem hiding this comment.
Looks good. One comment: Maybe also verify that the roots agree in the tests, where you Merkle trees built in parallel and serial? To me, it's not obvious what equality for two Merkle trees mean. If the tests compared the roots, that doubt would be removed from my mind.
I don't have an opinion on the prelude question.
Footnotes
|
Why not? I would treat it the same as Incidentally, this addition provides an opportunity to get rid of the unnecessary and annoying trait |
|
I'm happy to extend the scope thusly. Following a rather established naming convention, |
|
👍 |
|
Can we make it explicit that the sequential constructor is sequential, please? E.g. sequential_new |
|
That would be |
Previously, constructing a Merkle tree required selecting an implementor of the trait `MerkleTreeMaker`. Now, the `MerkleTree` struct provides two different but equivalent methods for constructing a Merkle tree, `sequential_new` and `par_new`. To migrate, replace - `MerkleTree::new::<CpuParallel>` with `MerkleTree::par_new`, and - `MerkleTree::new::<CpuSequential>` with `MerkleTree::sequential_new`.
|
Do you want to (re-)review the changes? |
Previously, the only way to construct a Merkle tree was to use
CpuParallel. However, in some cases, using parallelism does not make sense or even adversely effects the program.Add the Merkle tree maker
CpuSequential, which constructs the entire tree sequentially.Please note that at first glance, it might seem as if this PR increases the
DEFAULT_PARALLELIZATION_CUTOFF. However, this change is merely to offset the changes around it's only use I introduce in this PR.I'm not fully convinced that the new struct
CpuSequentialshould go into the crate's prelude. Opinions welcome.