-
Notifications
You must be signed in to change notification settings - Fork 1
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 decoupled state commitments and storage #11
Conversation
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.
Looking good. In addition to the comments, as you know we need to replace tm-db with tm-dbv2 and remove IAVL usage. In addition to that the next step is to flesh out how the decoupling will be handled at the multistore level. I think what we want to do is have the multistore map StoreKeys to a Store tuple (SCKVStore, SSKVStore).
if err != nil { | ||
panic(err.Error()) | ||
} | ||
s.sc.Set(key, kvHash[:]) // TODO: key or hash(key)? |
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.
Need an err :=
here. But actually I don't think we need this Set
, the key, value
and hash(key, value), key
will be sufficient
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 is where the state commitment mapping is set; Set()
has no return value
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.
Got it, we don't need the err
check below then.
store/decoupled/store.go
Outdated
// Direct KV mapping (SS) | ||
data dbm.DB | ||
// Inverted index of SC values to SS keys | ||
inv dbm.DB |
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.
Does the second bucket need to move through a separate tm-db interface?
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 using PrefixDB
s to separate the two into different namespaces. Collisions are unlikely since the inverted index uses a hash as key, but I think it's still desired.
if err != nil { | ||
panic(err.Error()) | ||
} | ||
s.sc.Set(key, kvHash[:]) // TODO: key or hash(key)? |
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.
Got it, we don't need the err
check below then.
store/decoupled/store.go
Outdated
if err != nil { | ||
panic(err.Error()) | ||
} | ||
err = s.inv.Set(kvHash[:], key) |
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.
We're deviating pretty hard from the simple behavior expected from a KVStore. A KVStore Set
is expected to Set
that key-value, it isn't expected to generate and Set
two other kv pairs. I think this logic makes more sense at a higher level.
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.
Per standup discussion, let's run this by Cosmos to see if this is the intended semantics, or where it's more appropriate to put this logic.
store/decoupled/store.go
Outdated
} | ||
|
||
func (s *Store) Iterator(start, end []byte) types.Iterator { | ||
iter, err := s.data.Iterator(start, end) |
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 think methods such as this one also highlight the issue with wrapping 3 distinct KVStores with a single KVStore- when we ask for an Iterator on this wrapping KVStore we are only getting the iterator for one of the underlying KVStores.
store/decoupled/store.go
Outdated
if err != nil { | ||
panic(err.Error()) | ||
} | ||
kvHash := sha256.Sum256(append(key, value...)) |
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 looking up the value and hashing it and the key to reconstruct hash(key, value)
we could lookup the hash(key, value)
from the SC before deleting it. This appears preferable since both approaches require a DB lookup but this approach doesn't require a hashing step. What do you think?
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.
That does indeed make more sense
* Initial SMT store type SMT (Sparse Merkle Tree) is intended to replace IAVL. New type implements same interfaces as iavl.Store. * Add iteration support to SMT 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. * Migrate to smt v0.1.1 * Extra test for SMT iterator * CommitStore implementation for SMT store * Use interface instead of concrete type * Add telemetry to SMT store * SMT: version->root mapping, cleanup * SMT proofs - initial code * Tests for SMT store ProofOp implementation * Fix linter errors * Use simple 1 byte KV-store prefixes * Improve assertions in tests * Use mutex properly * Store data in ADR-040-compatible way SMT stores: * key -> hash(key, value) KV store stores: * key->value in "bucket 1", * hash(key, value) -> key in "bucket 2".
Outline of new store following ADR-040 pattern of decoupled commitment/data concerns Largely adapted from store/ll-smt branch
This should be a MVP state store for #1. |
- Move tm-db code in from external repo - Refactor store/ and types/ packages - leaves out IAVL and multistore code pending confirmed deprecation - some hacks to glue existing tmdb usage and get compile/tests working
- Update to new db interface - Use smt as SC structure - Refactor smt to BasicKVStore
Moving this work to a PR on the main repo: cosmos#9485 |
Introduces a new
CommitKVStore
to implement ADR-040 proposal of decoupled commitment/data concerns.Adapted from
store/ll-smt
branch (see cosmos#8507).Description
Introduces the
decoupled.Store
type composed of:key → value
)hash(key) → hash(key, value)
)iavl.Store
held as aCommitKVStore
reference, which will later be refactored to use an SMT storehash(key, value) → key
)closes: #1
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.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes