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

Ensure nodes that are not part of the compact merkle tree state #180

Merged
merged 3 commits into from Oct 4, 2016

Conversation

phad
Copy link
Contributor

@phad phad commented Oct 3, 2016

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.

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 {
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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=")},
Copy link
Member

Choose a reason for hiding this comment

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

Nicely nicelington.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ACK

@phad phad force-pushed the ph_compact_merkle_tree_nil_nodes branch 2 times, most recently from 86b7d92 to 42240d8 Compare October 4, 2016 10:43
@phad phad merged commit d1ee609 into google:master Oct 4, 2016
@phad phad deleted the ph_compact_merkle_tree_nil_nodes branch October 4, 2016 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants