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

feat: ensures consistent use of the assumption that NMT nodes are ordered ascendingly #188

Merged
merged 49 commits into from
May 12, 2023

Conversation

staheri14
Copy link
Contributor

@staheri14 staheri14 commented May 1, 2023

Overview

Closes #121 and closes #148.
Please refer to this PR to compare the new and old version of namsespacre range calculation for a parent node in the HashNode().

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

@staheri14 staheri14 self-assigned this May 1, 2023
minNs := min(leftMinNs, rightMinNs)
var maxNs []byte
if n.ignoreMaxNs && n.precomputedMaxNs.Equal(leftMinNs) {
maxNs = n.precomputedMaxNs
Copy link
Contributor Author

@staheri14 staheri14 May 1, 2023

Choose a reason for hiding this comment

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

If leftMinNs represents the maximum possible namespace ID, then by definition, rightMax must also be the maximum possible namespace ID (left and right nodes are already checked to be ordered based on their namespaces). Therefore, this check can be removed.

@codecov
Copy link

codecov bot commented May 1, 2023

Codecov Report

Merging #188 (6768a68) into master (c41093d) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #188      +/-   ##
==========================================
- Coverage   95.41%   95.39%   -0.03%     
==========================================
  Files           5        5              
  Lines         567      564       -3     
==========================================
- Hits          541      538       -3     
  Misses         15       15              
  Partials       11       11              
Impacted Files Coverage Δ
hasher.go 97.54% <100.00%> (-0.06%) ⬇️

@staheri14 staheri14 added the enhancement New feature or request label May 4, 2023
@mergify mergify bot mentioned this pull request May 8, 2023
5 tasks
@staheri14 staheri14 marked this pull request as ready for review May 8, 2023 21:24
rightMinNs: []byte{0x02},
rightMaxNs: precomputedMaxNs,
expectedMinNs: []byte{0x00},
expectedMaxNs: precomputedMaxNs,
Copy link
Collaborator

Choose a reason for hiding this comment

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

[non-blocking][question] this test case has me puzzled. Based on the feature ignoreMaxNs I would expect max ns to be []byte{0x02}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, the IgnoreMaxNamespace ignores the MaxNs from the namespace range of the parent node when the right subtree (the right child) of the parent is filled with the leaves all with MaxNs. In this testcase, the right subtree is not populated only by MaxNs leaves, so, the condition is not met hence the normal range calculation takes place. This is how it is done in the original code as well, please see

nmt/hasher.go

Lines 280 to 288 in fd00c52

minNs := min(leftMinNs, rightMinNs)
var maxNs []byte
if n.ignoreMaxNs && n.precomputedMaxNs.Equal(leftMinNs) {
maxNs = n.precomputedMaxNs
} else if n.ignoreMaxNs && n.precomputedMaxNs.Equal(rightMinNs) {
maxNs = leftMaxNs
} else {
maxNs = max(leftMaxNs, rightMaxNs)
}
.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for explaining. I think we can def merge this PR.

No concrete feedback but I think the ignoreMaxNs feature is confusing b/c it only applies under certain circumstances.

Copy link
Contributor Author

@staheri14 staheri14 May 10, 2023

Choose a reason for hiding this comment

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

I agree with the confusion part. It takes time for one's mental model to be shaped around the semantics of IgnoreMaxNamespace, especially without any context regarding its use case in Celestia. Without such context, it may never make sense.

it only applies under certain circumstances.

To provide further clarity, this condition applies only under two circumstances. Firstly, when the tree has more than one leaf, and secondly, when the right half of a (parent) node is fully occupied by values that all have the Maximum namespace. In essence, the first condition can be deduced from the second one, so there is effectively only one condition.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should (eventually) move the ignoreNS logic to celestia somehow as it is really difficult to grasp in the context of the NMT only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should (eventually) move the ignoreNS logic to celestia somehow as it is really difficult to grasp in the context of the NMT only.

Agree with this, created the tracking issue as well #195

@staheri14 staheri14 added this to the Mainnet milestone May 12, 2023
@staheri14 staheri14 merged commit eabb595 into master May 12, 2023
@staheri14 staheri14 deleted the use-namespace-ordering-assumption-consistently branch May 12, 2023 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IgnoreMaxNS leads to false computing maxNs Assumption that leaves are ordered is not used consistently
4 participants