-
Notifications
You must be signed in to change notification settings - Fork 34
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
Conversation
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 Report
@@ 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
|
) | ||
|
||
func TestIteration(t *testing.T) { | ||
pairs := []struct{ key, val []byte }{ |
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.
Table driven tests
store/smt/store.go
Outdated
val, err := s.tree.Get(key) | ||
// TODO(tzdybal): how to handle this err? | ||
if err != nil { | ||
return nil |
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.
SMT propagates errors from underlying storage, so we should panic (and probably log before)
3291c1f
to
bab3f84
Compare
bab3f84
to
9eb31c8
Compare
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.
Great start to get the SMT to adhere to the required interfaces 👍🏼
var ( | ||
indexPrefix = []byte("smt-ordering-idx-") | ||
afterIndex = []byte("smt-ordering-idx.") // '.' is next after '-' in ASCII | ||
) |
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.
This isn't really self-explanatory. Add a brief explanation (even if it is unexported).
Nit: I'd prefer using string
const
ants instead and wrap them with []byte()
where they are used.
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. |
e79dc4a
to
6171e35
Compare
r, err := storeProofOp.Run([][]byte{value}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, r) | ||
assert.Equal(t, root, r[0]) |
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.
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`
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.
Nice one!
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.
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.
I think the plan was to make a new PR and target it to |
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? |
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. |
Drafted cosmos#8507. |
This comment has been minimized.
This comment has been minimized.
What's the status on implementing the SMT here @tzdybal? |
Converting to draft but keeping around since we may need this branch soon |
This code is copied from #12 with following changes: * updated smt to v0.2.0 * added CacheWrapWithListeners to fully implement KVStore interface
can we close this? |
closing as I think this is outdated pls reopen or move if not slightly_smiling_face |
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.