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

Initial SMT store type #12

Closed
wants to merge 14 commits into from
Closed

Initial SMT store type #12

wants to merge 14 commits into from

Conversation

tzdybal
Copy link
Member

@tzdybal tzdybal commented Jan 13, 2021

Description

This PR introduces SMT store layer. We need to wait for conclusion of ADR-040 before moving forward.

Current state implements most interfaces (except Queryable), and provides compatibility layer for Tendermint ProofOp's.

SMT (Sparse Merkle Tree) is intended to replace IAVL. New type
implements same interfaces as iavl.Store.
Sparse Merkle Tree does not support iteration over keys in order.
To provide drop-in replacement for IAVL, Iterator and ReverseIterator
has to be implemented.
SMT Store implementation use the underlying KV store to:
 - maintain a list of keys (under a prefix)
 - iterate over a keys
Values are stored only in SMT.
@codecov-io
Copy link

codecov-io commented Jan 14, 2021

Codecov Report

Merging #12 (19e07ee) into master (85b5fa9) will increase coverage by 0.01%.
The diff coverage is 65.82%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #12      +/-   ##
==========================================
+ Coverage   61.91%   61.92%   +0.01%     
==========================================
  Files         609      611       +2     
  Lines       35102    35178      +76     
==========================================
+ Hits        21732    21784      +52     
- Misses      11086    11105      +19     
- Partials     2284     2289       +5     
Impacted Files Coverage Δ
store/types/store.go 57.14% <0.00%> (-2.86%) ⬇️
store/smt/store.go 45.23% <45.23%> (ø)
store/smt/iterator.go 94.28% <94.28%> (ø)
x/ibc/core/02-client/module.go 25.00% <0.00%> (-8.34%) ⬇️
.../light-clients/07-tendermint/types/misbehaviour.go 73.01% <0.00%> (ø)
...light-clients/06-solomachine/types/misbehaviour.go 96.15% <0.00%> (ø)
simapp/app.go 84.79% <0.00%> (+0.77%) ⬆️
...ght-clients/07-tendermint/types/consensus_state.go 100.00% <0.00%> (+11.76%) ⬆️

)

func TestIteration(t *testing.T) {
pairs := []struct{ key, val []byte }{
Copy link
Member Author

Choose a reason for hiding this comment

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

Table driven tests

val, err := s.tree.Get(key)
// TODO(tzdybal): how to handle this err?
if err != nil {
return nil
Copy link
Member Author

Choose a reason for hiding this comment

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

SMT propagates errors from underlying storage, so we should panic (and probably log before)

@tzdybal tzdybal marked this pull request as ready for review January 28, 2021 09:37
@tzdybal tzdybal force-pushed the tzdybal/add_smt branch 2 times, most recently from 3291c1f to bab3f84 Compare January 28, 2021 09:48
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.

Great start to get the SMT to adhere to the required interfaces 👍🏼

Comment on lines +14 to +17
var (
indexPrefix = []byte("smt-ordering-idx-")
afterIndex = []byte("smt-ordering-idx.") // '.' is next after '-' in ASCII
)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't really self-explanatory. Add a brief explanation (even if it is unexported).

Nit: I'd prefer using string constants instead and wrap them with []byte() where they are used.

store/smt/proof.go Show resolved Hide resolved
@liamsi
Copy link
Member

liamsi commented Jan 28, 2021

We need to wait for conclusion of ADR-040 before moving forward.

Does that mean we should hold off from merging as well?

@tzdybal
Copy link
Member Author

tzdybal commented Jan 28, 2021

Does that mean we should hold off from merging as well?

Current state of implementation is a complete, usable store, with support for proofs. We can merge it, and then continue work, or we can just leave it as is, to be a starting point for further work.

r, err := storeProofOp.Run([][]byte{value})
assert.NoError(t, err)
assert.NotEmpty(t, r)
assert.Equal(t, root, r[0])

Choose a reason for hiding this comment

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

instead of adding t to every assert or require I usually shadow the package names:

assert := assert.New(t)
require := require.New(t)
// and then:
assert.Equal(root, r[0])  // no need to pass `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.

Nice one!

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.

I'm OK with merging this in its current form into our fork.

I would certainly hold-off from replacing iavl with the smt untill we have a MVP without fraud-proofs. Maybe, we should even implement fraud proofs using iavl first.

@robert-zaremba
Copy link

I think the plan was to make a new PR and target it to cosmos-sdk/store/ll-smt and then review.

@liamsi
Copy link
Member

liamsi commented Feb 3, 2021

That's right! I actually forgot. But we could do both. I'll leave it up to @tzdybal to decide.

@robert-zaremba
Copy link

That's right! I actually forgot. But we could do both. I'll leave it up to @tzdybal to decide.

What's the advantage of doing both? Wouldn't it complicate?

@liamsi
Copy link
Member

liamsi commented Feb 3, 2021

It would only complicate things if we'd have to versions that we try to keep in sync, one in that branch and one in our fork.

@tzdybal
Copy link
Member Author

tzdybal commented Feb 3, 2021

Drafted cosmos#8507.

@github-actions

This comment has been minimized.

@github-actions github-actions bot added the Stale label Mar 21, 2021
@liamsi liamsi removed the Stale label Mar 23, 2021
@adlerjohn
Copy link
Member

What's the status on implementing the SMT here @tzdybal?

@adlerjohn adlerjohn marked this pull request as draft April 12, 2022 14:23
@adlerjohn
Copy link
Member

Converting to draft but keeping around since we may need this branch soon

@adlerjohn
Copy link
Member

cc @Manav-Aggarwal @jbowen93

tzdybal added a commit that referenced this pull request Sep 16, 2022
This code is copied from #12
with following changes:
 * updated smt to v0.2.0
 * added CacheWrapWithListeners to fully implement KVStore interface
@evan-forbes
Copy link
Member

can we close this?

@evan-forbes
Copy link
Member

closing as I think this is outdated

pls reopen or move if not slightly_smiling_face

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants