-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
af10e05
Implement in-memory KVStore
alexanderbez 29d68cf
Start keeper and types
alexanderbez 191df59
Add codec
alexanderbez cb6fc18
Add keys logic
alexanderbez 447221b
Update types
alexanderbez 970e786
Update keeper
alexanderbez 0f950e1
Implement NewCapability
alexanderbez 2a3dde9
Implement InitializeAndSeal
alexanderbez 4d40d4d
Update simapp
alexanderbez 4c3e8ef
Implement GetCapability
alexanderbez 772d0f6
Add logging for new and claimed caps
alexanderbez d8f0ee2
Call InitializeAndSeal in SimApp
alexanderbez e989574
Update keeper semantics + unit tests
alexanderbez e929832
Use big endian
alexanderbez 3a95ff8
More unit tests
alexanderbez 9e46368
Increase keeper test coverage
alexanderbez abc15d8
Remove TODO
alexanderbez 74d09b9
Add module doc
alexanderbez 083494c
Update doc
alexanderbez d6b5f5b
Apply suggestions from code review
cwgoes c5e9c60
Update NewCapability godoc
alexanderbez 0fa3522
Clarify owner
alexanderbez f3a514a
Add forgery test case to TestAuthenticateCapability
alexanderbez 1db27ad
Format doc
alexanderbez 290344c
Update ADR
alexanderbez 76a5c3e
Explicitly take pointer in FwdCapabilityKey
alexanderbez 82afa7d
Update set to be logn
alexanderbez 84707a8
Merge branch 'ibc-alpha' into bez/adr-003-dynamic-cap
alexanderbez a8efe0f
Update app module
alexanderbez 9b4f448
Lint
alexanderbez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package mem_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/mem" | ||
"github.com/cosmos/cosmos-sdk/store/types" | ||
) | ||
|
||
func TestStore(t *testing.T) { | ||
db := mem.NewStore() | ||
key, value := []byte("key"), []byte("value") | ||
|
||
require.Equal(t, types.StoreTypeMemory, db.GetStoreType()) | ||
|
||
require.Nil(t, db.Get(key)) | ||
db.Set(key, value) | ||
require.Equal(t, value, db.Get(key)) | ||
|
||
newValue := []byte("newValue") | ||
db.Set(key, newValue) | ||
require.Equal(t, newValue, db.Get(key)) | ||
|
||
db.Delete(key) | ||
require.Nil(t, db.Get(key)) | ||
} | ||
|
||
func TestCommit(t *testing.T) { | ||
db := mem.NewStore() | ||
key, value := []byte("key"), []byte("value") | ||
|
||
db.Set(key, value) | ||
id := db.Commit() | ||
require.True(t, id.IsZero()) | ||
require.True(t, db.LastCommitID().IsZero()) | ||
require.Equal(t, value, db.Get(key)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package mem | ||
|
||
import ( | ||
"io" | ||
|
||
dbm "github.com/tendermint/tm-db" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/cachekv" | ||
"github.com/cosmos/cosmos-sdk/store/dbadapter" | ||
"github.com/cosmos/cosmos-sdk/store/tracekv" | ||
"github.com/cosmos/cosmos-sdk/store/types" | ||
) | ||
|
||
var ( | ||
_ types.KVStore = (*Store)(nil) | ||
_ types.Committer = (*Store)(nil) | ||
) | ||
|
||
// Store implements an in-memory only KVStore. Entries are persisted between | ||
// commits and thus between blocks. State in Memory store is not committed as part of app state but maintained privately by each node | ||
type Store struct { | ||
dbadapter.Store | ||
} | ||
|
||
func NewStore() *Store { | ||
return NewStoreWithDB(dbm.NewMemDB()) | ||
} | ||
|
||
func NewStoreWithDB(db *dbm.MemDB) *Store { // nolint: interfacer | ||
return &Store{Store: dbadapter.Store{DB: db}} | ||
} | ||
|
||
// GetStoreType returns the Store's type. | ||
func (s Store) GetStoreType() types.StoreType { | ||
return types.StoreTypeMemory | ||
} | ||
|
||
// CacheWrap cache wraps the underlying store. | ||
func (s Store) CacheWrap() types.CacheWrap { | ||
return cachekv.NewStore(s) | ||
} | ||
|
||
// CacheWrapWithTrace implements KVStore. | ||
func (s Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap { | ||
return cachekv.NewStore(tracekv.NewStore(s, w, tc)) | ||
} | ||
|
||
// Commit performs a no-op as entries are persistent between commitments. | ||
func (s *Store) Commit() (id types.CommitID) { return } | ||
|
||
// nolint | ||
func (s *Store) SetPruning(pruning types.PruningOptions) {} | ||
func (s Store) LastCommitID() (id types.CommitID) { return } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,8 +273,30 @@ const ( | |
StoreTypeDB | ||
StoreTypeIAVL | ||
StoreTypeTransient | ||
StoreTypeMemory | ||
) | ||
|
||
func (st StoreType) String() string { | ||
switch st { | ||
case StoreTypeMulti: | ||
return "StoreTypeMulti" | ||
|
||
case StoreTypeDB: | ||
return "StoreTypeDB" | ||
|
||
case StoreTypeIAVL: | ||
return "StoreTypeIAVL" | ||
|
||
case StoreTypeTransient: | ||
return "StoreTypeTransient" | ||
|
||
case StoreTypeMemory: | ||
return "StoreTypeMemory" | ||
} | ||
|
||
return "unknown store type" | ||
} | ||
|
||
//---------------------------------------- | ||
// Keys for accessing substores | ||
|
||
|
@@ -333,6 +355,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 commentThe reason will be displayed to describe this comment to others. Learn more. I'd add a |
||
name string | ||
} | ||
|
||
func NewMemoryStoreKey(name string) *MemoryStoreKey { | ||
return &MemoryStoreKey{name: name} | ||
} | ||
|
||
// Name returns the name of the MemoryStoreKey. | ||
func (key *MemoryStoreKey) Name() string { | ||
return key.name | ||
} | ||
|
||
// String returns a stringified representation of the MemoryStoreKey. | ||
func (key *MemoryStoreKey) String() string { | ||
return fmt.Sprintf("MemoryStoreKey{%p, %s}", key, key.name) | ||
} | ||
|
||
//---------------------------------------- | ||
|
||
// key-value result for iterator queries | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Whats the difference between "memStoreKey" and "transientStoreKey"?
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.
The memory store is in-memory only but persists across blocks, whereas the transient store is reset after each
Commit
, I believe.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.
What @cwgoes stated is correct. Think of the in-memory store as a simple cache/map. Since both are really in-memory and the only semantic difference is on commit, perhaps it makes sense to rename in-memory store (future PR).