-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
ADR-003: Dynamic Capabilities #5828
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.
👍 Core logic LGTM
@@ -326,6 +327,25 @@ func (key *TransientStoreKey) String() string { | |||
return fmt.Sprintf("TransientStoreKey{%p, %s}", key, key.name) | |||
} | |||
|
|||
// MemoryStoreKey defines a typed key to be used with an in-memory KVStore. | |||
type MemoryStoreKey struct { |
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'd add a Type() sdk.StoreKeyType
method to the sdk.StoreKey
interface
return Keeper{ | ||
cdc: cdc, | ||
storeKey: storeKey, | ||
memKey: memKey, |
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'd panic
here if the memKey.Type()
doesn't match sdk. MemoryStoreKey
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 could, but the app has to call InitializeAndSeal
which does the check without us having to change the interface of StoreKey
.
|
||
// Set attempts to add a given owner to the CapabilityOwners. If the owner already | ||
// exists, an error will be returned. | ||
func (co *CapabilityOwners) Set(owner Owner) error { |
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.
Just a note, this is O(n)
, it could be O(1)
if we use a map (should be safe since iteration order won't change behaviour), or O(log n)
if we do a binary search to check for duplicates & then insert.
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.
Yes, I've already thought about this. But since the CapabilityOwners
type is encoded and persisted to state, you cannot use a map. Even if you did use a map at runtime and use a slice when you persist, you'd still have O(n)
conversion. I've thought of various ways to do this like keeping an ephemeral map/cache, but it doesn't seem clean.
However, binary search would work and we can cut down Set
to O(log n)
. I'll address that.
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.
Updated. Note, worst case can still be O(n)
. Maybe this is overkill, idk. We could also define an initial capacity in the owner slice.
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 it's fine for the time being.
Co-Authored-By: Aditya <[email protected]>
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 job @alexanderbez, looks almost entirely correct to me, a few changes to documentation needed (probably copied from a slightly out-of-date spec) and a few minor comments, but overall nearly there. 🎉
Think the ADR still has the outdated behavior in e77496f#diff-b232b32a8f540d33f5040df6477179b1R175
|
Yes - we should delete the last sentence. |
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.
utACK 🎈 - thanks for the ADR updates.
|
||
// Set attempts to add a given owner to the CapabilityOwners. If the owner already | ||
// exists, an error will be returned. | ||
func (co *CapabilityOwners) Set(owner Owner) error { |
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 it's fine for the time being.
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.
utACK, good work @alexanderbez! looking forward to integrating this 👍
Description
Implementation of ADR 003 - Dynamic Capabilities.
ref: #5542
/cc @jackzampolin @cwgoes @AdityaSripal @fedekunze
For contributor use:
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerFor admin use:
WIP
,R4R
,docs
, etc)