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
Ensure nodes that are not part of the compact merkle tree state #180
Conversation
for given tree size are set to nil when new leaves are added. Check using an invariant after each AddLeaf in the tests. Fix test data to have nils in the appropriate places.
sizes. Test data generated with the code to write nil in 'nodes []trillian.Hash' disabled, so that it is known to be good with the existing CompactMerkleTree. With the new 'write nil' code enabled this acts as a regression check.
@@ -17,6 +18,40 @@ func getTree() *CompactMerkleTree { | |||
return NewCompactMerkleTree(NewRFC6962TreeHasher(trillian.NewSHA256())) | |||
} | |||
|
|||
func (c *CompactMerkleTree) checkUnusedNodesInvariant() error { |
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.
Since the test is in the same package you should have access to the non-exported contents of structs, so this func could just take a *CompactMerkleTree
and reach in, rather than adding this testing method to CMT.
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.
for i, n := range c.nodes { | ||
expectNil := i != sizeBits-1 | ||
if expectNil && n != nil { | ||
return fmt.Errorf("Perfect Tree size %d has non-nil node at index %d, wanted nil", size, i) |
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 initial-caps on these errors
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.
Is that for chaining-of-errors purposes? (so you get approximately readable sentences with no jarring mid-sentence caps?)
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.
Prexactly.
{4095, testonly.MustDecodeBase64("cWRFdQhPcjn9WyBXE/r1f04ejxIm5lvg40DEpRBVS0w=")}, | ||
{4096, testonly.MustDecodeBase64("6uU/phfHg1n/GksYT6TO9aN8EauMCCJRl3dIK0HDs2M=")}, | ||
{10000, testonly.MustDecodeBase64("VZcav65F9haHVRk3wre2axFoBXRNeUh/1d9d5FQfxIg=")}, | ||
{65535, testonly.MustDecodeBase64("iPuVYJhP6SEE4gUFp8qbafd2rYv9YTCDYqAxCj8HdLM=")}, |
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.
Nicely nicelington.
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.
ACK
86b7d92
to
42240d8
Compare
for given tree size are set to nil when new leaves are added.
Check using an invariant after each AddLeaf in the tests.
Fix test data to have nils in the appropriate places.