Skip to content

Commit 18c9168

Browse files
authored
Merge branch 'main' into julien/export
2 parents 127d45c + f995d0a commit 18c9168

File tree

15 files changed

+119
-167
lines changed

15 files changed

+119
-167
lines changed

docs/architecture/adr-065-store-v2.md

+7-65
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ We propose to build upon some of the great ideas introduced in [ADR-040](./adr-0
7979
while being a bit more flexible with the underlying implementations and overall
8080
less intrusive. Specifically, we propose to:
8181

82-
* Separate the concerns of state commitment (**SC**), needed for consensus, and
83-
state storage (**SS**), needed for state machine and clients.
8482
* Reduce layers of abstractions necessary between the RMS and underlying stores.
8583
* Remove unnecessary store types and implementations such as `CacheKVStore`.
86-
* Simplify the branching logic.
84+
* Remove the branching logic from the store package.
8785
* Ensure the `RootStore` interface remains as lightweight as possible.
88-
* Allow application developers to easily swap out SS and SC backends.
86+
* Allow application developers to easily swap out SC backends.
8987

9088
Furthermore, we will keep IAVL as the default [SC](https://cryptography.fandom.com/wiki/Commitment_scheme)
9189
backend for the time being. While we might not fully settle on the use of IAVL in
@@ -95,18 +93,12 @@ to change the backing commitment store in the future should evidence arise to
9593
warrant a better alternative. However there is promising work being done to IAVL
9694
that should result in significant performance improvement <sup>[1,2]</sup>.
9795

98-
Note, we will provide applications with the ability to use IAVL v1 and IAVL v2 as
96+
Note, we will provide applications with the ability to use IAVL v1, IAVL v2 and MemIAVL as
9997
either SC backend, with the latter showing extremely promising performance improvements
10098
over IAVL v0 and v1, at the cost of a state migration.
10199

102-
### Separating SS and SC
103100

104-
By separating SS and SC, it will allow for us to optimize against primary use cases
105-
and access patterns to state. Specifically, The SS layer will be responsible for
106-
direct access to data in the form of (key, value) pairs, whereas the SC layer (e.g. IAVL)
107-
will be responsible for committing to data and providing Merkle proofs.
108-
109-
#### State Commitment (SC)
101+
### State Commitment (SC)
110102

111103
A foremost design goal is that SC backends should be easily swappable, i.e. not
112104
necessarily IAVL. To this end, the scope of SC has been reduced, it must only:
@@ -121,45 +113,6 @@ due to the time and space constraints, but since store v2 defines an API for his
121113
proofs there should be at least one configuration of a given SC backend which
122114
supports this.
123115

124-
#### State Storage (SS)
125-
126-
The goal of SS is to provide a modular storage backend, i.e. multiple implementations,
127-
to facilitate storing versioned raw key/value pairs in a fast embedded database.
128-
The responsibility and functions of SS include the following:
129-
130-
* Provided fast and efficient queries for versioned raw key/value pairs
131-
* Provide versioned CRUD operations
132-
* Provide versioned batching functionality
133-
* Provide versioned iteration (forward and reverse) functionality
134-
* Provide pruning functionality
135-
136-
All of the functionality provided by an SS backend should work under a versioned
137-
scheme, i.e. a user should be able to get, store, and iterate over keys for the latest
138-
and historical versions efficiently and a store key, which is used for name-spacing
139-
purposes.
140-
141-
We propose to have three defaulting SS backends for applications to choose from:
142-
143-
* RocksDB
144-
* CGO based
145-
* Usage of User-Defined Timestamps as a built-in versioning mechanism
146-
* PebbleDB
147-
* Native
148-
* Manual implementation of MVCC keys for versioning
149-
* SQLite
150-
* CGO based
151-
* Single table for all state
152-
153-
Since operators might want pruning strategies to differ in SS compared to SC,
154-
e.g. having a very tight pruning strategy in SC while having a looser pruning
155-
strategy for SS, we propose to introduce an additional pruning configuration,
156-
with parameters that are identical to what exists in the SDK today, and allow
157-
operators to control the pruning strategy of the SS layer independently of the
158-
SC layer.
159-
160-
Note, the SC pruning strategy must be congruent with the operator's state sync
161-
configuration. This is so as to allow state sync snapshots to execute successfully,
162-
otherwise, a snapshot could be triggered on a height that is not available in SC.
163116

164117
#### State Sync
165118

@@ -179,7 +132,7 @@ the primary interface for the application to interact with. The `RootStore` will
179132
be responsible for housing SS and SC backends. Specifically, a `RootStore` will
180133
provide the following functionality:
181134

182-
* Manage commitment of state (both SS and SC)
135+
* Manage commitment of state
183136
* Provide modules access to state
184137
* Query delegation (i.e. get a value for a <key, height> tuple)
185138
* Providing commitment proofs
@@ -197,12 +150,7 @@ solely provide key prefixing/namespacing functionality for modules.
197150

198151
#### Proofs
199152

200-
Since the SS layer is naturally a storage layer only, without any commitments
201-
to (key, value) pairs, it cannot provide Merkle proofs to clients during queries.
202-
203-
So providing inclusion and exclusion proofs, via a `CommitmentOp` type, will be
204-
the responsibility of the SC backend. Retrieving proofs will be done through the
205-
a `RootStore`, which will internally route the request to the SC backend.
153+
Providing a `CommitmentOp` type, will be the responsibility of the SC backend. Retrieving proofs will be done through the a `RootStore`, which will internally route the request to the SC backend.
206154

207155
#### Commitment
208156

@@ -231,9 +179,6 @@ and storage backends for further performance, in addition to a reduced amount of
231179
abstraction around KVStores making operations such as caching and state branching
232180
more intuitive.
233181

234-
However, due to the proposed design, there are drawbacks around providing state
235-
proofs for historical queries.
236-
237182
### Backwards Compatibility
238183

239184
This ADR proposes changes to the storage implementation in the Cosmos SDK through
@@ -243,17 +188,14 @@ be broken or modified.
243188

244189
### Positive
245190

246-
* Improved performance of independent SS and SC layers
191+
* Improved performance of SC layers
247192
* Reduced layers of abstraction making storage primitives easier to understand
248-
* Atomic commitments for SC
249193
* Redesign of storage types and interfaces will allow for greater experimentation
250194
such as different physical storage backends and different commitment schemes
251195
for different application modules
252196

253197
### Negative
254198

255-
* Providing proofs for historical state is challenging
256-
257199
### Neutral
258200

259201
* Removal of OCAP-based store keys in favor of simple strings for state retrieval

docs/build/building-apps/00-runtime.md

+18
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,23 @@ sidebar_position: 1
55
# What is `runtime`?
66

77
The `runtime` package is the Cosmos SDK package that combines the building blocks of your blockchain together. It wires together the modules, the applications, the codecs, and the stores.
8+
It is a layer of abstraction between `baseapp` and the application modules that simplifies the process of building a Cosmos SDK application.
89

10+
## Modules wiring
11+
12+
Runtime is responsible for wiring the modules together. It uses `depinject` to inject the dependencies of the modules.
13+
14+
## App wiring
15+
16+
Runtime is the base boilerplate of a Cosmos SDK application.
917
A user only needs to import `runtime` in their `app.go` and instantiate a `runtime.App`.
18+
19+
## Services
20+
21+
Modules have access to a multitude of services that are provided by the runtime.
22+
These services include the `store`, the `event manager`, the `context`, and the `logger`.
23+
As runtime is doing the wiring of modules, it can ensure that the services are scoped to their respective modules.
24+
25+
```go reference
26+
https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.2/runtime/module.go#L250-L279
27+
```

docs/build/building-modules/00-intro.md

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ While there are no definitive guidelines for writing modules, here are some impo
5858
* **Specialization**: A direct consequence of the **composability** feature is that modules should be **specialized**. Developers should carefully establish the scope of their module and not batch multiple functionalities into the same module. This separation of concerns enables modules to be re-used in other projects and improves the upgradability of the application. **Specialization** also plays an important role in the [object-capabilities model](https://docs.cosmos.network/main/learn/advanced/ocap#ocaps-in-practice) of the Cosmos SDK.
5959
* **Capabilities**: Most modules need to read and/or write to the store(s) of other modules. However, in an open-source environment, it is possible for some modules to be malicious. That is why module developers need to carefully think not only about how their module interacts with other modules, but also about how to give access to the module's store(s). The Cosmos SDK takes a capabilities-oriented approach to inter-module security. This means that each store defined by a module is accessed by a `key`, which is held by the module's [`keeper`](./06-keeper.md). This `keeper` defines how to access the store(s) and under what conditions. Access to the module's store(s) is done by passing a reference to the module's `keeper`.
6060

61+
## Core APIs for Modules
62+
63+
The SDK provides a set of APIs that a module can implement, and a set of services that a module can use.
64+
Those APIs are defined in the `cosmossdk.io/core/appmodule` package, and are used to defined the module capabilities, which is used by `runtime` during the wiring of the application.
65+
66+
Learn more about the core APIs for modules [here](../../learn/advanced/02-core.md).
67+
6168
## Main Components of Cosmos SDK Modules
6269

6370
Modules are by convention defined in the `./x/` subfolder (e.g. the `bank` module will be defined in the `./x/bank` folder). They generally share the same core components:

docs/build/building-modules/01-module-manager.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,9 @@ The module manager is used throughout the application whenever an action on a co
217217
* `InitGenesis(ctx context.Context, genesisData map[string]json.RawMessage)`: Calls the [`InitGenesis`](./08-genesis.md#initgenesis) function of each module when the application is first started, in the order defined in `OrderInitGenesis`. Returns an `abci.InitChainResponse` to the underlying consensus engine, which can contain validator updates.
218218
* `ExportGenesis(ctx context.Context)`: Calls the [`ExportGenesis`](./08-genesis.md#exportgenesis) function of each module, in the order defined in `OrderExportGenesis`. The export constructs a genesis file from a previously existing state, and is mainly used when a hard-fork upgrade of the chain is required.
219219
* `ExportGenesisForModules(ctx context.Context, modulesToExport []string)`: Behaves the same as `ExportGenesis`, except takes a list of modules to export.
220-
* `BeginBlock(ctx context.Context) error`: At the beginning of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./06-preblock-beginblock-endblock.md) function of each modules implementing the `appmodule.HasBeginBlocker` interface, in the order defined in `OrderBeginBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from each modules.
221-
* `EndBlock(ctx context.Context) error`: At the end of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./06-preblock-beginblock-endblock.md) function of each modules implementing the `appmodule.HasEndBlocker` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any).
222-
* `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./06-preblock-beginblock-endblock.md) function of each modules implementing the `module.HasABCIEndBlock` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any).
223-
* `Precommit(ctx context.Context)`: During [`Commit`](../../learn/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately before the [`deliverState`](../../learn/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../learn/advanced/04-store.md#commitmultistore) and, in turn calls the `Precommit` function of each modules implementing the `HasPrecommit` interface, in the order defined in `OrderPrecommiters`. It creates a child [context](../../learn/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the newly committed block's [`finalizeblockstate`](../../learn/advanced/00-baseapp.md#state-updates).
224-
* `PrepareCheckState(ctx context.Context)`: During [`Commit`](../../learn/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately after the [`deliverState`](../../learn/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../learn/advanced/04-store.md#commitmultistore) and, in turn calls the `PrepareCheckState` function of each module implementing the `HasPrepareCheckState` interface, in the order defined in `OrderPrepareCheckStaters`. It creates a child [context](../../learn/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the next block's [`checkState`](../../learn/advanced/00-baseapp.md#state-updates). Writes to this state will be present in the [`checkState`](../../learn/advanced/00-baseapp.md#state-updates) of the next block, and therefore this method can be used to prepare the `checkState` for the next block.
220+
* `BeginBlock(ctx context.Context) error`: At the beginning of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./06-preblock-beginblock-endblock.md) function of each modules implementing the `appmodule.HasBeginBlocker` interface, in the order defined in `OrderBeginBlockers`.
221+
* `EndBlock(ctx context.Context) error`: At the end of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./06-preblock-beginblock-endblock.md) function of each modules implementing the `appmodule.HasEndBlocker` interface, in the order defined in `OrderEndBlockers`.
222+
* `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./06-preblock-beginblock-endblock.md) function of each modules implementing the `appmodule.HasABCIEndBlock` interface, in the order defined in `OrderEndBlockers`. Extended implementation for modules that need to update the validator set (typically used by the staking module).
225223
* (Optional) `RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)`: Registers the [`codec.LegacyAmino`s](../../learn/advanced/05-encoding.md#amino) of each of the application module. This function is usually called early on in the [application's construction](../../learn/beginner/00-app-anatomy.md#constructor).
226224
* `RegisterInterfaces(registry codectypes.InterfaceRegistry)`: Registers interface types and implementations of each of the application's `AppModule`.
227225
* (Optional) `RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux)`: Registers gRPC routes for modules.

docs/build/building-modules/05-protobuf-annotations.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
sidebar_position: 1
33
---
44

5-
# ProtocolBuffer Annotations
5+
# Protocol buffer Annotations
66

7-
This document explains the various protobuf scalars that have been added to make working with protobuf easier for Cosmos SDK application developers
7+
This document explains the various protobuf scalars that have been added to make working with protobuf easier for Cosmos SDK application developers.
88

99
## Signer
1010

@@ -85,7 +85,7 @@ option (cosmos_proto.method_added_in) = "simapp v24.0.0";
8585
The amino codec was removed in `v0.50+`, this means there is not a need register `legacyAminoCodec`. To replace the amino codec, Amino protobuf annotations are used to provide information to the amino codec on how to encode and decode protobuf messages.
8686

8787
:::note
88-
Amino annotations are only used for backwards compatibility with amino. New modules are not required use amino annotations.
88+
Amino annotations are only used for backwards compatibility with amino.
8989
:::
9090

9191
The below annotations are used to provide information to the amino codec on how to encode and decode protobuf messages in a backwards compatible manner.

0 commit comments

Comments
 (0)