Skip to content

Commit

Permalink
chore: Add x/capability docs (#11922)
Browse files Browse the repository at this point in the history
* chore: Add x/capability docs

* bad ident
  • Loading branch information
facundomedica authored May 11, 2022
1 parent 90272e3 commit 137c758
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions x/capability/spec/01_concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ not own.
## Stores

* MemStore
* KeyStore
21 changes: 18 additions & 3 deletions x/capability/spec/02_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@ order: 2
-->

# State
## In persisted KV store

## Index
1. Global unique capability index
2. Capability owners

## CapabilityOwners
Indexes:

## Capability
* Unique index: `[]byte("index") -> []byte(currentGlobalIndex)`
* Capability Index: `[]byte("capability_index") | []byte(index) -> ProtocolBuffer(CapabilityOwners)`

## In-memory KV store

1. Initialized flag
2. Mapping between the module and capability tuple and the capability name
3. Mapping between the module and capability name and its index

Indexes:

* Initialized flag: `[]byte("mem_initialized")`
* RevCapabilityKey: `[]byte(moduleName + "/rev/" + capabilityName) -> []byte(index)`
* FwdCapabilityKey: `[]byte(moduleName + "/fwd/" + capabilityPointerAddress) -> []byte(capabilityName)`
13 changes: 7 additions & 6 deletions x/capability/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ func NewApp(...) *App {
After the keeper is created, it can be used to create scoped sub-keepers which
are passed to other modules that can create, authenticate, and claim capabilities.
After all the necessary scoped keepers are created and the state is loaded, the
main capability keeper must be initialized and sealed to populate the in-memory
state and to prevent further scoped keepers from being created.
main capability keeper must be sealed to prevent further scoped keepers from
being created.

```go
func NewApp(...) *App {
// ...

// Initialize and seal the capability keeper so all persistent capabilities
// are loaded in-memory and prevent any further modules from creating scoped
// Creating a scoped keeper
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)

// Seal the capability keeper to prevent any further modules from creating scoped
// sub-keepers.
ctx := app.BaseApp.NewContext(true, tmproto.Header{})
app.capabilityKeeper.InitializeAndSeal(ctx)
app.capabilityKeeper.Seal()

return app
}
Expand Down
2 changes: 1 addition & 1 deletion x/capability/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
KeyIndex = []byte("index")

// KeyPrefixIndexCapability defines a key prefix that stores index to capability
// name mappings.
// owners mappings.
KeyPrefixIndexCapability = []byte("capability_index")

// KeyMemInitialized defines the key that stores the initialized flag in the memory store
Expand Down

0 comments on commit 137c758

Please sign in to comment.