Skip to content
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

Merged
merged 56 commits into from
Feb 14, 2023
Merged

chore: improves documentation #96

merged 56 commits into from
Feb 14, 2023

Conversation

staheri14
Copy link
Contributor

@staheri14 staheri14 commented Feb 10, 2023

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.

@staheri14 staheri14 marked this pull request as ready for review February 10, 2023 20:19
@staheri14 staheri14 self-assigned this Feb 10, 2023
@codecov
Copy link

codecov bot commented Feb 10, 2023

Codecov Report

Merging #96 (04dd6f9) into master (b04eea5) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            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              
Impacted Files Coverage Δ
namespace/data.go 100.00% <ø> (ø)
namespace/id.go 100.00% <ø> (ø)
hasher.go 96.05% <100.00%> (+0.05%) ⬆️
nmt.go 98.80% <100.00%> (ø)
proof.go 96.77% <100.00%> (+0.18%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@staheri14 staheri14 added the documentation Improvements or additions to documentation label Feb 10, 2023
Copy link
Collaborator

@rootulp rootulp left a 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...)
Copy link
Collaborator

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...)

Copy link
Contributor Author

@staheri14 staheri14 Feb 14, 2023

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,
Copy link
Collaborator

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
}

Copy link
Collaborator

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.

Copy link
Contributor Author

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.
Copy link
Collaborator

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

Suggested change
// Less returns true if nid < ID, otherwise, false.
// Less returns true if nid < other, otherwise, false.

Copy link
Contributor Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Equal returns true if nid == ID, otherwise, false.
// Equal returns true if nid == other, otherwise, false.

Copy link
Contributor Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// LessOrEqual returns true if nid <= ID, otherwise, false.
// LessOrEqual returns true if nid <= other, otherwise, false.

Copy link
Contributor Author

@staheri14 staheri14 Feb 14, 2023

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
Copy link
Collaborator

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?

Copy link
Contributor Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

Copy link
Contributor Author

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) {
Copy link
Collaborator

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.

Suggested change
func (n *NamespacedMerkleTree) foundInRange(nID namespace.ID) (bool, int, int) {
func (n *NamespacedMerkleTree) foundInRange(nID namespace.ID) (found bool, startIndex int, endIndex int) {

Copy link
Contributor Author

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
Comment on lines 96 to 97
func NewInclusionProof(
proofStart, proofEnd int, proofNodes [][]byte, ignoreMaxNamespace bool) Proof {
Copy link
Collaborator

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?

Copy link
Contributor Author

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
Comment on lines 118 to 123
// `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.
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected 26b1ea6

Copy link
Member

@evan-forbes evan-forbes left a 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 ✔️

nmt.go Outdated Show resolved Hide resolved
@rootulp
Copy link
Collaborator

rootulp commented Feb 14, 2023

Woohoo! Thanks for addressing my pedantic feedback. :shipit:

@staheri14
Copy link
Contributor Author

Thank for your comments and feedback! @rootulp @evan-forbes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants