Skip to content
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 30 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
af10e05
Implement in-memory KVStore
alexanderbez Mar 18, 2020
29d68cf
Start keeper and types
alexanderbez Mar 18, 2020
191df59
Add codec
alexanderbez Mar 19, 2020
cb6fc18
Add keys logic
alexanderbez Mar 19, 2020
447221b
Update types
alexanderbez Mar 19, 2020
970e786
Update keeper
alexanderbez Mar 19, 2020
0f950e1
Implement NewCapability
alexanderbez Mar 19, 2020
2a3dde9
Implement InitializeAndSeal
alexanderbez Mar 20, 2020
4d40d4d
Update simapp
alexanderbez Mar 20, 2020
4c3e8ef
Implement GetCapability
alexanderbez Mar 20, 2020
772d0f6
Add logging for new and claimed caps
alexanderbez Mar 20, 2020
d8f0ee2
Call InitializeAndSeal in SimApp
alexanderbez Mar 20, 2020
e989574
Update keeper semantics + unit tests
alexanderbez Mar 20, 2020
e929832
Use big endian
alexanderbez Mar 20, 2020
3a95ff8
More unit tests
alexanderbez Mar 20, 2020
9e46368
Increase keeper test coverage
alexanderbez Mar 20, 2020
abc15d8
Remove TODO
alexanderbez Mar 20, 2020
74d09b9
Add module doc
alexanderbez Mar 20, 2020
083494c
Update doc
alexanderbez Mar 20, 2020
d6b5f5b
Apply suggestions from code review
cwgoes Mar 23, 2020
c5e9c60
Update NewCapability godoc
alexanderbez Mar 23, 2020
0fa3522
Clarify owner
alexanderbez Mar 23, 2020
f3a514a
Add forgery test case to TestAuthenticateCapability
alexanderbez Mar 23, 2020
1db27ad
Format doc
alexanderbez Mar 23, 2020
290344c
Update ADR
alexanderbez Mar 23, 2020
76a5c3e
Explicitly take pointer in FwdCapabilityKey
alexanderbez Mar 23, 2020
82afa7d
Update set to be logn
alexanderbez Mar 23, 2020
84707a8
Merge branch 'ibc-alpha' into bez/adr-003-dynamic-cap
alexanderbez Mar 23, 2020
a8efe0f
Update app module
alexanderbez Mar 23, 2020
9b4f448
Lint
alexanderbez Mar 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-Authored-By: Aditya <adityasripal@gmail.com>
  • Loading branch information
cwgoes and AdityaSripal committed Mar 23, 2020
commit d6b5f5b92ea21098f8ed40d0c276b804af4dbb16
4 changes: 2 additions & 2 deletions store/mem/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var (
_ types.Committer = (*Store)(nil)
)

// Store implements an in-memory only KVStore. Entries are peresistent between
// commits and thus between blocks.
// 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
}
Expand Down
9 changes: 4 additions & 5 deletions x/capability/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ The keeper maintains two states: persistent and ephemeral in-memory. The persist
store maintains a globally unique auto-incrementing index and a mapping from
capability index to a set of capability owners that are defined as a module and
capability name tuple. The in-memory ephemeral state keeps track of the actual
capabilities with both forward and reverse indexes. The forward index maps
capabilities, represented as addresses in local memory, with both forward and reverse indexes. The forward index maps
module name and capability tuples to the capability name. The reverse index maps
between the module and capability name and the capability itself.

The keeper allows the creation of "scoped" sub-keepers which are tied to a particular
module by name. Scoped keepers must be created at application initialization and
passed to modules, which can then use them to claim capabilities they receive and
retrieve capabilities which they own by name, in addition to creating new capabilities
& authenticating capabilities passed by other modules.
& authenticating capabilities passed by other modules. A scoped keeper cannot escape its scope, so a module cannot interfere with or inspect capabilities owned by other modules.

The keeper provides no other core functionality that can be found in other modules
like queriers, REST and CLI handlers, and genesis state.
Expand Down Expand Up @@ -75,13 +75,12 @@ allows a module to claim a capability key which it has received from another
module so that future `GetCapability` calls will succeed. `ClaimCapability` MUST
be called if a module which receives a capability wishes to access it by name in
the future. Again, capabilities are multi-owner, so if multiple modules have a
single Capability reference, they will all own it.
single Capability reference, they will all own it. If a module receives a capability from another module but does not call `ClaimCapability`, it may use it in the executing transaction but will not be able to access it afterwards.

`AuthenticateCapability` can be called by any module to check that a capability
does in fact correspond to a particular name (the name can be un-trusted user input)
with which the calling module previously associated it.

`GetCapability` allows a module to fetch a capability which it has previously
claimed by name. The module is not allowed to retrieve capabilities which it does
not own. If another module claims a capability, the previously owning module will
no longer be able to claim it.
not own.
5 changes: 2 additions & 3 deletions x/capability/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (types.Capabi
// true upon success and false upon failure.
//
// Note, the capability's forward mapping is indexed by a string which should
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 on helpful note

// contain it's unique memory reference.
// contain its unique memory reference.
func (sk ScopedKeeper) AuthenticateCapability(ctx sdk.Context, cap types.Capability, name string) bool {
memStore := ctx.KVStore(sk.memKey)

Expand Down Expand Up @@ -201,8 +201,7 @@ func (sk ScopedKeeper) ClaimCapability(ctx sdk.Context, cap types.Capability, na

// GetCapability allows a module to fetch a capability which it previously claimed
// by name. The module is not allowed to retrieve capabilities which it does not
// own. If another module claims a capability, the previously owning module will
// no longer be able to claim it.
// own.
func (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (types.Capability, bool) {
memStore := ctx.KVStore(sk.memKey)

Expand Down