-
Notifications
You must be signed in to change notification settings - Fork 42
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
chore: improves documentation #96
Conversation
…nd some scattered clarification on the godocs
Codecov Report
@@ Coverage Diff @@
## master #96 +/- ##
==========================================
+ Coverage 96.21% 96.27% +0.05%
==========================================
Files 6 6
Lines 423 429 +6
==========================================
+ Hits 407 413 +6
Misses 10 10
Partials 6 6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all your effort in improving the documentation in this repo!
hasher.go
Outdated
NodePrefix), | ||
l...), | ||
r...) | ||
data := append(append(append(make([]byte, 0, 1+len(left)+len(right)), NodePrefix), left...), right...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional] I find this a lot more readable but it's subjective
data := make([]byte, 0, 1+len(left)+len(right))
data = append(data, NodePrefix)
data = append(data, left...)
data = append(data, right...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree! please see 26b1ea6
hasher.go
Outdated
// which is "res = min(left.minNID, right.minNID) || max(left.maxNID, | ||
// right.maxNID) || H(NodePrefix, left, | ||
// right)". "res" refers to the return value of the HashNode. | ||
// However, if the "ignoreMaxNs" property of the Hasher is set to true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[not blocking] for my learning, what is the purpose of the ignoreMaxNs
field? Do you think it would help readers to add docs to:
type Hasher struct {
baseHasher hash.Hash
NamespaceLen namespace.IDSize
// ignoreMaxNs is an optimization that does ...
ignoreMaxNs bool
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disregard, I learned from below. Maybe a variation of this comment would be helpful here:
// The "IgnoreMaxNamespace" flag influences the calculation of the
// namespace ID range for intermediate nodes in the tree.
// This flag signals that, when determining the upper limit of the
// namespace ID range for a tree node, the maximum possible namespace ID
// (equivalent to "NamespaceIDSize" bytes of 0xFF, or 2^NamespaceIDSize-1)
// should be omitted if feasible. For a more in-depth understanding of
// this field, refer to the "HashNode" method in the "Hasher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done 26b1ea6
namespace/id.go
Outdated
@@ -4,22 +4,27 @@ import "bytes" | |||
|
|||
type ID []byte | |||
|
|||
// Less returns true if nid < ID, otherwise, false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional] since both types that are being compared are of type ID
I think the variable name helps disambiguate
// Less returns true if nid < ID, otherwise, false. | |
// Less returns true if nid < other, otherwise, false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed 26b1ea6
namespace/id.go
Outdated
func (nid ID) Less(other ID) bool { | ||
return bytes.Compare(nid, other) < 0 | ||
} | ||
|
||
// Equal returns true if nid == ID, otherwise, false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Equal returns true if nid == ID, otherwise, false. | |
// Equal returns true if nid == other, otherwise, false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see 26b1ea6
namespace/id.go
Outdated
func (nid ID) Equal(other ID) bool { | ||
return bytes.Equal(nid, other) | ||
} | ||
|
||
// LessOrEqual returns true if nid <= ID, otherwise, false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// LessOrEqual returns true if nid <= ID, otherwise, false. | |
// LessOrEqual returns true if nid <= other, otherwise, false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 26b1ea6
nmt.go
Outdated
newIncludeNode := includeNode | ||
// check whether the subtree representing the [start, end) range of leaves has overlap with the | ||
// queried proof range i.e., [proofStart, proofEnd) | ||
// if not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was the rest of this comment lost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it was not lost, if not
refers to the following if
statement which is entered when the said condition is not met. I tried to clarify it in this commit 26b1ea6.
nmt.go
Outdated
if (end <= proofStart || start >= proofEnd) && includeNode { | ||
// setting newIncludeNode to false indicates that non of the subtrees (left and right) of the current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// setting newIncludeNode to false indicates that non of the subtrees (left and right) of the current | |
// setting newIncludeNode to false indicates that none of the subtrees (left and right) of the current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 26b1ea6
nmt.go
Outdated
// If no leaves are found, foundInRange returns (false, 0, 0). | ||
// | ||
// The endIndex is non-inclusive, | ||
// meaning it does not include the leaf at that index in the range. | ||
func (n *NamespacedMerkleTree) foundInRange(nID namespace.ID) (bool, int, int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[no change needed][optional] we can remove some of the godoc comment by using named return values https://go.dev/tour/basics/7 but that's a debated topic on our team so it may not make sense to adopt for this isolated use-case.
func (n *NamespacedMerkleTree) foundInRange(nID namespace.ID) (bool, int, int) { | |
func (n *NamespacedMerkleTree) foundInRange(nID namespace.ID) (found bool, startIndex int, endIndex int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, incorporated your suggestion 26b1ea6
proof.go
Outdated
func NewInclusionProof( | ||
proofStart, proofEnd int, proofNodes [][]byte, ignoreMaxNamespace bool) Proof { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity, why split this across two lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't meant to be broken down, fixed it now 26b1ea6
proof.go
Outdated
// `data` items MUST be ordered according to their index in the tree, with `data[0]` corresponding to the namespaced data at index `start`, | ||
// | ||
// and the last element in `data` corresponding to the data item at index | ||
// `end-1` of the tree. | ||
// | ||
// `root` is the root of the NMT against which the `proof` is verified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line wrapping got messed up here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected 26b1ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, this is really great!!
[minor nit]
as Rootul mentioned, there are few lines where it appears that we could wrap more consistently, and by doing so we would also be more consistent with other the other celestia repos. I can also see a few spots where not wrapping makes it more readable, and since we don't have a CI linter in this repo, I'll defer to the author on when exactly to do so.
other than that I couldn't even find spelling errors, and reviewing was a good forcing function to think about nmt again! 👍 👍 easy ✔️
Woohoo! Thanks for addressing my pedantic feedback. |
Thank for your comments and feedback! @rootulp @evan-forbes |
A PR inline with EPIC celestiaorg/celestia-app#1296
Aiming at improving the documentation of the NMT library.
As part of this PR, some variables have been renamed to more accurately reflect their values.