Replace Prove
trait with more generic Visitable
trait, implement for all types, and rewrite prove in terms of it
#174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This crate has a forking issue. Many useful additions are scattered across over 40 forks and to me this suggests that the underlying API is not flexible enough to allow consumers to do what they want to do.
This PR aims to fix that once and for all so that a single version of
ssz_rs
can stabilize while new features can continue to be added in their own separate crates that work together with this one.Motivation
Features missing from this crate but implemented in forks include:
One operation that is common to all these algorithms is the idea of visiting the different containers that make up a composite SSZ container.
Implementation
This PR introduces a generic
Visitable
traitthat is implemented by all primitives and containers via the derive macros.
The above algorithms and more can be implemented by writing a custom type that implements the
Visitor
traitIt also adds a new trait
Chunkable
also implemented for all primitives and containers that allows Visitor developers to access the underlying leaves of the subtree for each subcontainer.For example in this PR the
Prover
implementation is rewritten as a visitor that consumes chunks.https://github.com/willemolding/ssz-rs/blob/c1b956fe9d4dafc4309bcda118a6c6489a6c9064/ssz-rs/src/merkleization/proofs.rs#L75
This new API should make it easy for developers who want to implement new algorithms (or variations) that operate over the SSZ data structures in their own crates
Changes
Visitable
,Visitor
, andChunkable
traitsVisitable
andChunkable
for all primitive typesVisitable
andChunkable
via derive macrosProver
in terms of the above traits