You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/architecture/adr-065-store-v2.md
+7-65
Original file line number
Diff line number
Diff line change
@@ -79,13 +79,11 @@ We propose to build upon some of the great ideas introduced in [ADR-040](./adr-0
79
79
while being a bit more flexible with the underlying implementations and overall
80
80
less intrusive. Specifically, we propose to:
81
81
82
-
* Separate the concerns of state commitment (**SC**), needed for consensus, and
83
-
state storage (**SS**), needed for state machine and clients.
84
82
* Reduce layers of abstractions necessary between the RMS and underlying stores.
85
83
* Remove unnecessary store types and implementations such as `CacheKVStore`.
86
-
*Simplify the branching logic.
84
+
*Remove the branching logic from the store package.
87
85
* 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.
89
87
90
88
Furthermore, we will keep IAVL as the default [SC](https://cryptography.fandom.com/wiki/Commitment_scheme)
91
89
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
95
93
warrant a better alternative. However there is promising work being done to IAVL
96
94
that should result in significant performance improvement <sup>[1,2]</sup>.
97
95
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
99
97
either SC backend, with the latter showing extremely promising performance improvements
100
98
over IAVL v0 and v1, at the cost of a state migration.
101
99
102
-
### Separating SS and SC
103
100
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)
110
102
111
103
A foremost design goal is that SC backends should be easily swappable, i.e. not
112
104
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
121
113
proofs there should be at least one configuration of a given SC backend which
122
114
supports this.
123
115
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.
163
116
164
117
#### State Sync
165
118
@@ -179,7 +132,7 @@ the primary interface for the application to interact with. The `RootStore` will
179
132
be responsible for housing SS and SC backends. Specifically, a `RootStore` will
180
133
provide the following functionality:
181
134
182
-
* Manage commitment of state (both SS and SC)
135
+
* Manage commitment of state
183
136
* Provide modules access to state
184
137
* Query delegation (i.e. get a value for a <key, height> tuple)
185
138
* Providing commitment proofs
@@ -197,12 +150,7 @@ solely provide key prefixing/namespacing functionality for modules.
197
150
198
151
#### Proofs
199
152
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.
206
154
207
155
#### Commitment
208
156
@@ -231,9 +179,6 @@ and storage backends for further performance, in addition to a reduced amount of
231
179
abstraction around KVStores making operations such as caching and state branching
232
180
more intuitive.
233
181
234
-
However, due to the proposed design, there are drawbacks around providing state
235
-
proofs for historical queries.
236
-
237
182
### Backwards Compatibility
238
183
239
184
This ADR proposes changes to the storage implementation in the Cosmos SDK through
@@ -243,17 +188,14 @@ be broken or modified.
243
188
244
189
### Positive
245
190
246
-
* Improved performance of independent SS and SC layers
191
+
* Improved performance of SC layers
247
192
* Reduced layers of abstraction making storage primitives easier to understand
248
-
* Atomic commitments for SC
249
193
* Redesign of storage types and interfaces will allow for greater experimentation
250
194
such as different physical storage backends and different commitment schemes
251
195
for different application modules
252
196
253
197
### Negative
254
198
255
-
* Providing proofs for historical state is challenging
256
-
257
199
### Neutral
258
200
259
201
* Removal of OCAP-based store keys in favor of simple strings for state retrieval
Copy file name to clipboardExpand all lines: docs/build/building-apps/00-runtime.md
+18
Original file line number
Diff line number
Diff line change
@@ -5,5 +5,23 @@ sidebar_position: 1
5
5
# What is `runtime`?
6
6
7
7
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.
8
9
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.
9
17
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.
Copy file name to clipboardExpand all lines: docs/build/building-modules/00-intro.md
+7
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,13 @@ While there are no definitive guidelines for writing modules, here are some impo
58
58
***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.
59
59
***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`.
60
60
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
+
61
68
## Main Components of Cosmos SDK Modules
62
69
63
70
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:
Copy file name to clipboardExpand all lines: docs/build/building-modules/01-module-manager.md
+3-5
Original file line number
Diff line number
Diff line change
@@ -217,11 +217,9 @@ The module manager is used throughout the application whenever an action on a co
217
217
*`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.
218
218
*`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.
219
219
*`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).
225
223
* (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).
226
224
*`RegisterInterfaces(registry codectypes.InterfaceRegistry)`: Registers interface types and implementations of each of the application's `AppModule`.
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.
86
86
87
87
:::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.
89
89
:::
90
90
91
91
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