-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add possibility to traverse inner nodes #16
Conversation
- to print the tree nodes - collect nodes (incl. inner) to write storage
Codecov Report
@@ Coverage Diff @@
## master #16 +/- ##
==========================================
+ Coverage 95.13% 95.30% +0.16%
==========================================
Files 7 7
Lines 288 298 +10
==========================================
+ Hits 274 284 +10
Misses 10 10
Partials 4 4
Continue to review full report at Codecov.
|
This is super neat! The implementation as an |
Looks like this is all we need for the IPLD plugin. |
As |
Good point. Currently, this is not relevant - at least for the first LL ipld plugin it isn't and I tried to keep the diff as small as possible. That said, there probably are use-cases where this will become relevant (e.g. when doing #15 this might need to change) 🤔 Did you have something specific in mind when you wondered about this? Maybe I'm missing something? For now, I don't see any urgent need: nodes who generate proofs are expected to have all the data to generate these, and, they can always recompute the (inner) proof-nodes from scratch. The |
I assume this is used in the IPLD plugin in order to publish the intermediate nodes? If so this seems like a non-generalisable feature but I guess it's OK if it's implemented as an option rather than a mandatory constructor argument. |
Yes, that is exactly what it is used for. What kind of generalization do you have in mind though? For reading the nodes from storage? If there is sth. obvious which do need soon, we can add this here too. Otherwise, let's track this in a separate issue. |
I suppose actually storing the tree itself (in memory) within NMT itself and letting people read from it. |
The tree exists in memory but proofs are currently recomputed on demand. That's isn't "reading from it" but should be quite efficient already, especially for a first version / mvp (the leaf-data and the leaf-hashes are also stored in memory and the former can be retrieved via the API). If we want to avoid recomputing the inner proof nodes every time they are needed, we can actually store the inner nodes too. Not sure this would need to be exposed as an exported API or sth like this. Of course, if we want to store and then read the inner nodes from somewhere else, we'd need to change the API. We could also pass in an optional |
Hashing is pretty fast and involves no disk I/O. Storing inner nodes would mean multiple on-disk accesses along with more storage overhead. So it might not actually be so bad to just fetch the leaves all at once then recompute proofs as needed. |
Adds an optional "NodeVisitor" function to the tree that will be called on each node of the tree.
This can be used to tackle #9, and can also be used in the IPLD-plugin. It might also be useful to inspect/debug the tree, or, to print-out the tree in different ways.