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

Implement wrapper for rsmt2d.Tree #25

Closed
wants to merge 2 commits into from
Closed

Conversation

evan-forbes
Copy link
Member

This PR creates a wrapper for NamespacedMerkleTree that conforms to the rsmt2d.Tree interface, which will enable RetrieveBlockData to properly repair the extended data square. It will also help close #172.

ref #15

closes: #24

@codecov
Copy link

codecov bot commented Mar 19, 2021

Codecov Report

Merging #25 (d7af062) into master (e0a317a) will decrease coverage by 2.42%.
The diff coverage is 55.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #25      +/-   ##
==========================================
- Coverage   94.82%   92.40%   -2.43%     
==========================================
  Files           7        8       +1     
  Lines         309      329      +20     
==========================================
+ Hits          293      304      +11     
- Misses         11       19       +8     
- Partials        5        6       +1     
Impacted Files Coverage Δ
wrapper.go 55.00% <55.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0a317a...d7af062. Read the comment docs.

@evan-forbes evan-forbes requested review from liamsi and adlerjohn March 19, 2021 05:26
adjustedMessageSize = shareSize - DefaultNamespaceIDLen
)

func TestPushErasuredNamespacedMerkleTree(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure what else I could test, so any suggestions are greatly appreciated.

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 there is not much to test as the wrapper is really simple. And that is good. Well done!

The only thing I'd suggest is to also cover the non-happy paths in unit tests (e.g. the few edge cases where this can panic/error).

Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

IMO, the same can be achieved without any changes to the NMT. Namely by adding the wrapper to ll-core. Otherwise, the PR looks good to me. I want to think further about the implications of introducing rsmt2d as a dependency here before approving.

@@ -5,4 +5,5 @@ go 1.14
require (
github.com/google/gofuzz v1.2.0
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f
github.com/lazyledger/rsmt2d v0.0.0-20210121155026-23bf69f65287
Copy link
Member

Choose a reason for hiding this comment

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

IMO, the NMT should not need to know about rsmt2d. That is why I think the wrapper should live in ll-core. There all the dependencies need to come together anyways. And introducing the dependency here might cause some headaches in the future.

Copy link
Member

Choose a reason for hiding this comment

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

So what's the plan here, is the logic in this PR going to be moved instead of lazyledger-core?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, that makes a lot of sense!

"github.com/lazyledger/rsmt2d"
)

var paritySharesNamespaceID = namespace.ID{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +58 to +61
// if the data is erasure data use the parity ns
default:
copy(nsID, paritySharesNamespaceID)
}
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't the caller do this instead? They already know which shares are parity shares. Then they could simply prefix the parity shares with namespace.ID{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}. It would simplify the wrapper a bit.

On another note, I think we should change the method signature for Push from Push(nid, data []byte) (currently) to Push(data []byte) for the underlying nmt anyways. I think I've mentioned this in some convos but I never got around opening a small issue explaining the rationale for that 😬 Will do in a sec.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 for changing the signature

We will need the wrapper to be aware of the parity share, as it will have to be passed to rsmt2d.RepairExtendedDataSquare

adjustedMessageSize = shareSize - DefaultNamespaceIDLen
)

func TestPushErasuredNamespacedMerkleTree(t *testing.T) {
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 there is not much to test as the wrapper is really simple. And that is good. Well done!

The only thing I'd suggest is to also cover the non-happy paths in unit tests (e.g. the few edge cases where this can panic/error).

@evan-forbes
Copy link
Member Author

I'm going to close this PR for now. As mentioned in the comments, it makes sense to keep any new logic in lazyledger-core. I think we will still need a wrapper, because we need to pass a rsmt2d.Tree to rsmt.RepairExtendedDataSquare when recovering the data. That tree also needs to be aware of our hard coded parity namespace for the second half of the tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants