Skip to content

Commit

Permalink
get docs from main
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Sep 19, 2023
1 parent 0a64664 commit 6f3ab49
Show file tree
Hide file tree
Showing 43 changed files with 1,325 additions and 774 deletions.
3 changes: 1 addition & 2 deletions docs/build/building-apps/00-app-go.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
sidebar_position: 1

---

# Overview of `app.go`
Expand All @@ -11,5 +10,5 @@ For now please instead read the [tutorials](https://tutorials.cosmos.network) fo
## Complete `app.go`

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app.go#L107-L738
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app.go
```
54 changes: 38 additions & 16 deletions docs/build/building-apps/01-app-go-v2.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
---
sidebar_position: 1

---

# Overview of `app_v2.go`

:::note Synopsis

The Cosmos SDK allows much easier wiring of an `app.go` thanks to App Wiring and [`depinject`](../libraries/01-depinject.md).
The Cosmos SDK allows much easier wiring of an `app.go` thanks to App Wiring and [`depinject`](../packages/01-depinject.md).
Learn more about the rationale of App Wiring in [ADR-057](../architecture/adr-057-app-wiring.md).

:::

:::note

### Pre-requisite Readings
:::note Pre-requisite Readings

* [ADR 057: App Wiring](../architecture/adr-057-app-wiring.md)
* [Depinject Documentation](../libraries/01-depinject.md)
* [Depinject Documentation](../packages/01-depinject.md)
* [Modules depinject-ready](../building-modules/15-depinject.md)

:::
Expand All @@ -31,29 +28,29 @@ The `app_config.go` file is the single place to configure all modules parameters
1. Create the `AppConfig` variable:

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app_config.go#L91-L93
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_config.go#L103
```

2. Configure the `runtime` module:

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app_config.go#L94-L158
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_config.go#L103-L167
```

3. Configure the modules defined in the `BeginBlocker` and `EndBlocker` and the `tx` module:
3. Configure the modules defined in the `PreBlocker`, `BeginBlocker` and `EndBlocker` and the `tx` module:

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app_config.go#L159-L177
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_config.go#L112-L129
```

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app_config.go#L192-L194
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_config.go#L200-L203
```

### Complete `app_config.go`

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app_config.go#L52-L254
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_config.go
```

### Alternative formats
Expand Down Expand Up @@ -93,7 +90,7 @@ modules:
"@type": cosmos.staking.module.v1.Module
- name: tx
config:
"@type": cosmos.tx.module.v1.Module
"@type": cosmos.tx.config.v1.Config
```

A more complete example of `app.yaml` can be found [here](https://github.com/cosmos/cosmos-sdk/blob/91b1d83f1339e235a1dfa929ecc00084101a19e3/simapp/app.yaml).
Expand All @@ -104,7 +101,7 @@ A more complete example of `app.yaml` can be found [here](https://github.com/cos
In short `depinject` and the [`runtime` package](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/runtime) abstract the wiring of the app, and the `AppBuilder` is the place where the app is constructed. [`runtime`](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/runtime) takes care of registering the codecs, KV store, subspaces and instantiating `baseapp`.

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app_v2.go#L158-L291
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_v2.go#L101-L245
```

:::warning
Expand All @@ -118,15 +115,40 @@ In this case, use `depinject.Configs` for combining the extra configuration and
More information on how work `depinject.Configs` and `depinject.Supply` can be found in the [`depinject` documentation](https://pkg.go.dev/cosmossdk.io/depinject).

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app_v2.go#L186-L216
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_v2.go#L114-L146
```

### Registering non app wiring modules

It is possible to combine app wiring / depinject enabled modules with non app wiring modules.
To do so, use the `app.RegisterModules` method to register the modules on your app, as well as `app.RegisterStores` for registering the extra stores needed.

```go
// ....
app.App = appBuilder.Build(db, traceStore, baseAppOptions...)
// register module manually
app.RegisterStores(storetypes.NewKVStoreKey(example.ModuleName))
app.ExampleKeeper = examplekeeper.NewKeeper(app.appCodec, app.AccountKeeper.AddressCodec(), runtime.NewKVStoreService(app.GetKey(example.ModuleName)), authtypes.NewModuleAddress(govtypes.ModuleName).String())
exampleAppModule := examplemodule.NewAppModule(app.ExampleKeeper)
if err := app.RegisterModules(&exampleAppModule); err != nil {
panic(err)
}
// ....
```

:::warning
When using AutoCLI and combining app wiring and non app wiring modules. The AutoCLI options should be manually constructed instead of injected.
Otherwise it will miss the non depinject modules and not register their CLI.
:::

### Complete `app_v2.go`

:::tip
Note that in the complete `SimApp` `app_v2.go` file, testing utilities are also defined, but they could as well be defined in a separate file.
:::

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app_v2.go#L75-L395
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_v2.go
```
29 changes: 18 additions & 11 deletions docs/build/building-apps/02-app-mempool.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
sidebar_position: 1

---

# Application mempool
# Application Mempool

:::note Synopsis
This sections describes how the app-side mempool can be used and replaced.
Expand All @@ -14,9 +13,7 @@ block building than previous versions. This change was enabled by
[ABCI 1.0](https://github.com/cometbft/cometbft/blob/v0.37.0/spec/abci).
Notably it introduces the `PrepareProposal` and `ProcessProposal` steps of ABCI++.

:::note

### Pre-requisite Readings
:::note Pre-requisite Readings

* [BaseApp](../../develop/advanced/00-baseapp.md)

Expand Down Expand Up @@ -44,14 +41,18 @@ all transactions, it can provide greater control over transaction ordering.
Allowing the application to handle ordering enables the application to define how
it would like the block constructed.

Currently, there is a default `PrepareProposal` implementation provided by the application.
The Cosmos SDK defines the `DefaultProposalHandler` type, which provides applications with
`PrepareProposal` and `ProcessProposal` handlers. If you decide to implement your
own `PrepareProposal` handler, you must be sure to ensure that the transactions
selected DO NOT exceed the maximum block gas (if set) and the maximum bytes provided
by `req.MaxBytes`.

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/baseapp/baseapp.go#L868-L916
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/abci_utils.go
```

This default implementation can be overridden by the application developer in
favor of a custom implementation in [`app.go`](01-app-go-v2.md):
favor of a custom implementation in [`app.go`](./01-app-go-v2.md):

```go
prepareOpt := func(app *baseapp.BaseApp) {
Expand All @@ -78,10 +79,13 @@ proposal is proposed.
Here is the implementation of the default implementation:

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/baseapp/baseapp.go#L927-L942
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/abci_utils.go#L153-L159
```

Like `PrepareProposal` this implementation is the default and can be modified by the application developer in [`app.go`](01-app-go-v2.md):
Like `PrepareProposal` this implementation is the default and can be modified by
the application developer in [`app.go`](./01-app-go-v2.md). If you decide to implement
your own `ProcessProposal` handler, you must be sure to ensure that the transactions
provided in the proposal DO NOT exceed the maximum block gas (if set).

```go
processOpt := func(app *baseapp.BaseApp) {
Expand All @@ -103,7 +107,7 @@ Namely, the SDK provides the following mempools:
* [Sender Nonce Mempool](#sender-nonce-mempool)
* [Priority Nonce Mempool](#priority-nonce-mempool)

The default SDK is a [No-op Mempool](#no-op-mempool), but it can be replaced by the application developer in [`app.go`](01-app-go-v2.md):
The default SDK is a [No-op Mempool](#no-op-mempool), but it can be replaced by the application developer in [`app.go`](./01-app-go-v2.md):

```go
nonceMempool := mempool.NewSenderNonceMempool()
Expand All @@ -117,6 +121,9 @@ A no-op mempool is a mempool where transactions are completely discarded and ign
When this mempool is used, it assumed that an application will rely on CometBFT's transaction ordering defined in `RequestPrepareProposal`,
which is FIFO-ordered by default.

> Note: If a NoOp mempool is used, PrepareProposal and ProcessProposal both should be aware of this as
> PrepareProposal could include transactions that could fail verification in ProcessProposal.
### Sender Nonce Mempool

The nonce mempool is a mempool that keeps transactions from an sorted by nonce in order to avoid the issues with nonces.
Expand Down
Loading

0 comments on commit 6f3ab49

Please sign in to comment.