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

chore: Add x/capability docs #11922

Merged
merged 4 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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