Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
docs: adr-40: reduce multistore and make it atomic #9355
docs: adr-40: reduce multistore and make it atomic #9355
Changes from 4 commits
201c73e
c432f5e
7c4e308
bbc692f
0612088
c12c5ec
60af1b0
28bda90
aa1ded8
d14572d
096526c
4351424
ac7cde7
4ee227e
1781fb5
eaa80de
3f841fd
2a7b1aa
50cf72a
fbe4676
5dad4ef
f9c77ae
1fec94c
74193a9
2390332
aa9fd58
6206ce1
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 this need to be on the root
KVStore
interface itself? Can't this just be a functionality ofRootStore
?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 agree, mentioned this above #9355 (comment)
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.
It makes sense for this API to exist on the
RootStore
as that is how I imagine module's will request access to a prefixed store. That abstraction makes sense to me.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.
If this
WithPrefix
method just takes a string and compresses it, it shouldn't be used by modules for prefix storesThere 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.
Then again maybe that's something we do want modules to have to manage key prefixes 🤔
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.
Could you elaborate a bit on that? I still don't see the advantage of this over a prefix store which externally wraps a KV store. What optimizations would be useful?
I don't think it makes sense to try to do prefix compression within substores, especially not dynamically. That needs to be done on the SS bucket, so each substore would have to refer back to the root store to register the prefix. Also, if this exists on the
KVStore
interface, it could be used recursively on any derived store.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.
In SDK, modules usually have key families - objects with a common prefix. For example, in
x/bank
we have: supply, DenomMetadata, DenomAddress, Balances. In one of the architecture updates to the module we want that the module will receive it's own store. In x/bank, today we have:This doesn't follow OCAPS, because in x/bank I coud do
ctx.KVStore("gov")
. Instead we want:Then I can write:
and us it in some DAL responsible for balance management.
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.
If
WithPrefix
is confusing then we can rename it toSubstore
orSubnamespace
.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.
But what advantage does this have over:
balanceStore := PrefixStore(bankStore, "BalancesPrefix")
What kind of optimization would warrant adding this to the KVStore 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.
@roysc , you are right,
PrefixStore
function is better than extending the 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.
@aaronc originally suggested to map a module "verbose" key to a 2 byte sequence prefix for key prefix compression, eg:
In both mechanisms we will need to assure that the created map will be stable (we will always construct the same mapping pairs).
NOTE: Both Huffman Codes and module key map compress the keys only for the
SS
. It's not needed forSC
because inSC
we always operate on a hash of a 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.
I think the Aaron idea is easier to manage. The limitation is that we bound the number of modules to 65536 (2^16) - which is big enough to not worry about it now.
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.
To make this prefix model work effectively, I think there should be some stateful prefix map - possibly stored under some special restricted schema prefix (probably
0
) on theRootStore
. We can use varint encoding and not require a restriction to 2 bytes, but also 2 bytes is probably fine.In this restricted schema key-space, we would have a mapping from
key name
->compressed prefix
, which is itself prefixed to allow for other schema use cases.How does that sound?
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.
How important is it to have this optimization at all?
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.
String prefixes could potentially be rather long (maybe full proto msg names eventually as discussed in #9156). I think it's relatively important.
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.
If we want to enable variable prefix length, then huffman coding is better, because it takes frequency into account and it is also protects against common prefixes.
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.
NOTE: we decided to use
varint
.