-
Notifications
You must be signed in to change notification settings - Fork 43
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
Changes from all commits
e49d7b1
5e9091c
b6e3cd3
5c32cbc
84865d7
c8a8059
8a27636
9e3d8de
20b2205
6222d5f
30cbde4
9fd31f2
167629c
fcd3cd0
d11e9c2
bb07d07
d491b52
e6cb4dc
a449d68
29007f4
8fdaab2
409f0f8
2d504d5
48010b1
712ed08
e01ce18
fc595aa
021adc0
951ad75
81e86bf
f70d2d7
53597b9
f3076fe
e46a1b2
fb8ee89
05c2ca0
224d8cf
01ecb89
e0905fe
d64c018
c398e19
c0af83b
b0eef2f
21fccff
e73b843
a3fcfe0
4373c00
9c070ad
6768a68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -839,3 +839,111 @@ func TestMin(t *testing.T) { | |||||||||||||||||||
}) | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// TestComputeNsRange tests the ComputeRange function. | ||||||||||||||||||||
func TestComputeNsRange(t *testing.T) { | ||||||||||||||||||||
nIDSize := 1 | ||||||||||||||||||||
precomputedMaxNs := bytes.Repeat([]byte{0xFF}, nIDSize) | ||||||||||||||||||||
|
||||||||||||||||||||
testCases := []struct { | ||||||||||||||||||||
leftMinNs, leftMaxNs, rightMinNs, rightMaxNs, expectedMinNs, expectedMaxNs []byte | ||||||||||||||||||||
ignoreMaxNs bool | ||||||||||||||||||||
}{ | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: true, | ||||||||||||||||||||
leftMinNs: precomputedMaxNs, | ||||||||||||||||||||
leftMaxNs: precomputedMaxNs, | ||||||||||||||||||||
rightMinNs: precomputedMaxNs, | ||||||||||||||||||||
rightMaxNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMinNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMaxNs: precomputedMaxNs, | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: true, | ||||||||||||||||||||
leftMinNs: []byte{0x00}, | ||||||||||||||||||||
leftMaxNs: precomputedMaxNs, | ||||||||||||||||||||
rightMinNs: precomputedMaxNs, | ||||||||||||||||||||
rightMaxNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMinNs: []byte{0x00}, | ||||||||||||||||||||
expectedMaxNs: precomputedMaxNs, | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: true, | ||||||||||||||||||||
leftMinNs: []byte{0x00}, | ||||||||||||||||||||
leftMaxNs: []byte{0x01}, | ||||||||||||||||||||
rightMinNs: precomputedMaxNs, | ||||||||||||||||||||
rightMaxNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMinNs: []byte{0x00}, | ||||||||||||||||||||
expectedMaxNs: []byte{0x01}, | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: true, | ||||||||||||||||||||
leftMinNs: []byte{0x00}, | ||||||||||||||||||||
leftMaxNs: []byte{0x01}, | ||||||||||||||||||||
rightMinNs: []byte{0x02}, | ||||||||||||||||||||
rightMaxNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMinNs: []byte{0x00}, | ||||||||||||||||||||
expectedMaxNs: precomputedMaxNs, | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question, the Lines 280 to 288 in fd00c52
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agree with this, created the tracking issue as well #195 |
||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: true, | ||||||||||||||||||||
leftMinNs: []byte{0x00}, | ||||||||||||||||||||
leftMaxNs: []byte{0x01}, | ||||||||||||||||||||
rightMinNs: []byte{0x02}, | ||||||||||||||||||||
rightMaxNs: []byte{0x03}, | ||||||||||||||||||||
expectedMinNs: []byte{0x00}, | ||||||||||||||||||||
expectedMaxNs: []byte{0x03}, | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: false, | ||||||||||||||||||||
leftMinNs: precomputedMaxNs, | ||||||||||||||||||||
leftMaxNs: precomputedMaxNs, | ||||||||||||||||||||
rightMinNs: precomputedMaxNs, | ||||||||||||||||||||
rightMaxNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMinNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMaxNs: precomputedMaxNs, | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: false, | ||||||||||||||||||||
leftMinNs: []byte{0x00}, | ||||||||||||||||||||
leftMaxNs: precomputedMaxNs, | ||||||||||||||||||||
rightMinNs: precomputedMaxNs, | ||||||||||||||||||||
rightMaxNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMinNs: []byte{0x00}, | ||||||||||||||||||||
expectedMaxNs: precomputedMaxNs, | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: false, | ||||||||||||||||||||
leftMinNs: []byte{0x00}, | ||||||||||||||||||||
leftMaxNs: []byte{0x01}, | ||||||||||||||||||||
rightMinNs: precomputedMaxNs, | ||||||||||||||||||||
rightMaxNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMinNs: []byte{0x00}, | ||||||||||||||||||||
expectedMaxNs: precomputedMaxNs, | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: false, | ||||||||||||||||||||
leftMinNs: []byte{0x00}, | ||||||||||||||||||||
leftMaxNs: []byte{0x01}, | ||||||||||||||||||||
rightMinNs: []byte{0x02}, | ||||||||||||||||||||
rightMaxNs: precomputedMaxNs, | ||||||||||||||||||||
expectedMinNs: []byte{0x00}, | ||||||||||||||||||||
expectedMaxNs: precomputedMaxNs, | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
ignoreMaxNs: false, | ||||||||||||||||||||
leftMinNs: []byte{0x00}, | ||||||||||||||||||||
leftMaxNs: []byte{0x01}, | ||||||||||||||||||||
rightMinNs: []byte{0x02}, | ||||||||||||||||||||
rightMaxNs: []byte{0x03}, | ||||||||||||||||||||
expectedMinNs: []byte{0x00}, | ||||||||||||||||||||
expectedMaxNs: []byte{0x03}, | ||||||||||||||||||||
}, | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
for _, tc := range testCases { | ||||||||||||||||||||
minNs, maxNs := computeNsRange(tc.leftMinNs, tc.leftMaxNs, tc.rightMinNs, tc.rightMaxNs, tc.ignoreMaxNs, precomputedMaxNs) | ||||||||||||||||||||
assert.True(t, bytes.Equal(tc.expectedMinNs, minNs)) | ||||||||||||||||||||
assert.True(t, bytes.Equal(tc.expectedMaxNs, maxNs)) | ||||||||||||||||||||
} | ||||||||||||||||||||
} |
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.
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.