-
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
feat: compute leaf hashes in the Push method #172
Conversation
Codecov Report
@@ Coverage Diff @@
## master #172 +/- ##
==========================================
- Coverage 96.19% 95.76% -0.43%
==========================================
Files 5 5
Lines 525 519 -6
==========================================
- Hits 505 497 -8
- Misses 12 13 +1
- Partials 8 9 +1
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.
only two questions, otherwise LGTM this makes sense.
iirc, we have some benchmarks in this repo, have we compared this change against the old yet?
nmt.go
Outdated
// compute the leaf hash | ||
res := n.treeHasher.MustHashLeaf(namespacedData) |
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.
why not bubble the error here if there ever is one?
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.
There are two reasons why the error is not being bubbled up:
-
In line 410, the data validity is checked through the
validateAndExtractNamespace
function call. As a result, theHashLeaf
function call cannot produce an error. To handle this scenario, theMustHashLeaf
function is introduced, which assumes that the data passed to it has already been validated. This approach is similar to the current situation and avoids any unnecessary error handling. -
If we were to use
HashLeaf
and bubble up the error, we would need to introduce an if block in our code i.e., thePush
method. However, this if block would not be covered in our tests, leading to a reduction in test coverage percentage. Therefore, I have opted not to bubble up the error in this situation.
Please let me know if this addresses your question.
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.
that makes sense, but documenting it in the code for posterity would be a good addition imo. we could also just ignore the error if its impossible (and we have comments), but in general I think its always best to bubble even if we don't strictly need to. Its one less thing the reader or future contributors have to think about.
I'm not blocking on it though! will defer to the author 🙂
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.
Fair point, replaced MustHashLeaf with HashLeaf and bubbled up the error, please see d60367b
With this change, the code coverage percentage decreases below the set threshold, and there is no way to develop a test to cover the line that captures the returned error. In such situations, what should we do? Should we still merge the PR?
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.
Yeah, 100% merge imo
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.
LGTM
cc: @evan-forbes
|
@rootulp Can you please review the recent changes 🙏🏼 |
Overview
Closes #108 and #143
Checklist