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

Use simple merkle proof for commit info #6323

Merged

Conversation

ethanfrey
Copy link
Contributor

@ethanfrey ethanfrey commented Jun 2, 2020

Description

Pulling out one part of the logic from #6178 and simplifying the changes

One step towards #5842

Currently we serialize the entire commitInfo in the root multistore proofs. This is not even a merkle proof, just all data. Before we can move to ics23 proofs, we need to use merkle proofs that can be transformed to that format (it is just an encoding, not the logic).

As discussed a few times with @cwgoes and now @AdityaSripal we use merkle.SimpleProofsFromMap to produce the commitment of the root multi store. This can later be converted into ics23 format, but this is a valid, testable step that can be merged to master and is an improvement over current state.

closes: #XXXX

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@codecov
Copy link

codecov bot commented Jun 2, 2020

Codecov Report

Merging #6323 into master will decrease coverage by 0.02%.
The diff coverage is 70.49%.

@@            Coverage Diff             @@
##           master    #6323      +/-   ##
==========================================
- Coverage   55.71%   55.69%   -0.03%     
==========================================
  Files         448      448              
  Lines       26978    26941      -37     
==========================================
- Hits        15032    15005      -27     
+ Misses      10869    10862       -7     
+ Partials     1077     1074       -3     

Copy link
Contributor Author

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Some comments for the reviewers

"github.com/tendermint/iavl"
"github.com/tendermint/tendermint/crypto/merkle"
)

// MultiStoreProof defines a collection of store proofs in a multi-store
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to review: This was for handling the serialized StoreInfos[] as a proof, which is now removed in favor of a merkle commitment (which scales much better for dozens or more of substores)

func (si storeInfo) Hash() []byte {
// Doesn't write Name, since SimpleHashFromMap() will
// include them via the keys.
bz := si.Core.CommitID.Hash
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The storeInfo contains a name and a commitment (hash and version).
This method is not really used to "hash" it in a normal means, but rather pull out the hash that was already inside of it.

In effect, to make a chained proof op work, you would have to take the root hash from the iavlstore and then hash it before feeding it as a value to the merkle simple proof, which makes no sense. We want the simple proof to commit directly to the root hash of the sub stores (not a hash of a hash of a hash... - we are not bitcoin mining).

If anyone intends to use this as a real hashing op (which it never was used as), it must contain the name as well before feeding it to the hasher. In such a case we could rename this to eg. Commitment, which we would use to feed into commitInfo.Hash() and commitInfo.ProofOp().

Copy link
Member

Choose a reason for hiding this comment

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

Yes, believe this was why the hashing in TM had to be removed. This approach works better. Could you please put the cruz of this comment in the godoc. Namely that this does not actually hash the storeInfo, rather it returns the embedded store hash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can definitely add it to the GoDoc. I can also rename the function to make it more explicit that we are not trying to implement the Hasher interface but just access the substore hash.

Actually I can do both (rename an explain the purpose of the function). Any preferences for names?

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

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

Quick doc request, otherwise lgtm 👍

func (si storeInfo) Hash() []byte {
// Doesn't write Name, since SimpleHashFromMap() will
// include them via the keys.
bz := si.Core.CommitID.Hash
Copy link
Member

Choose a reason for hiding this comment

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

Yes, believe this was why the hashing in TM had to be removed. This approach works better. Could you please put the cruz of this comment in the godoc. Namely that this does not actually hash the storeInfo, rather it returns the embedded store hash

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

utACK

@ethanfrey
Copy link
Contributor Author

Nice.
When this is merged, I can make another cleanup PR that builds on top.

@alexanderbez alexanderbez added the A:automerge Automatically merge PR once all prerequisites pass. label Jun 3, 2020
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

ACK

@alexanderbez
Copy link
Contributor

Great work @ethanfrey -- please merge latest master and GH will automatically merge this for us.

@ethanfrey ethanfrey force-pushed the use-simple-merkle-proof-for-commit-info branch from 403d922 to e37e82b Compare June 3, 2020 17:16
@ethanfrey
Copy link
Contributor Author

Thanks for the quick reply everyone 😄

I just rebased on top of latest master, waiting for the CI to do it's magic

@ethanfrey
Copy link
Contributor Author

How does automerge work?

I rebased and passed all CI tests, but now it says: "Merging is blocked. The base branch restricts merging to authorized users". Looks like someone with write access will have to do so manually.

@alexanderbez alexanderbez merged commit cd272d5 into cosmos:master Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:Store
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants