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

[docs]: update building modules section to reflect ADR31 #7702

Merged
merged 64 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b4cce15
Revert "Revert "Update old ref of RegisterQueryService""
blushi Oct 28, 2020
fde2e77
Update intro, module-manager and messages-and-queries
blushi Oct 28, 2020
5d09284
Update messages-and-queries
blushi Oct 28, 2020
65c73a5
Update handler
blushi Oct 28, 2020
f0c058e
Update structure
blushi Oct 28, 2020
ada3680
Add doc related to RegisterMsgServiceDesc
blushi Oct 28, 2020
f229566
Merge branch 'master' into marie/7660-building-modules
blushi Oct 28, 2020
d18b09f
Merge branch 'master' into marie/7660-building-modules
blushi Oct 28, 2020
f0fb8a7
Update docs/building-modules/handler.md
blushi Oct 29, 2020
24d173f
Update docs/building-modules/handler.md
blushi Oct 29, 2020
62309ee
Update docs/building-modules/handler.md
blushi Oct 29, 2020
c818fcd
Update docs/building-modules/messages-and-queries.md
blushi Oct 29, 2020
707f7c0
Merge branch 'master' into marie/7660-building-modules
blushi Oct 29, 2020
ce68469
Update handler.md
blushi Oct 29, 2020
c904f91
Rename handler.md to msg-services.md
blushi Oct 29, 2020
96f475e
Merge branch 'master' into marie/7660-building-modules
blushi Oct 29, 2020
3f1e0b9
Update legacy msgs wording
blushi Oct 29, 2020
59876d6
Update messages-and-queries.md
blushi Nov 2, 2020
2ef7045
Merge branch 'master' into marie/7660-building-modules
blushi Nov 2, 2020
f0503a1
Update docs/building-modules/msg-services.md
blushi Nov 4, 2020
2e49f17
Update docs/building-modules/intro.md
blushi Nov 4, 2020
a4deb7a
Remove handler mention from intro.md
blushi Nov 4, 2020
d032298
Update docs/building-modules/messages-and-queries.md
blushi Nov 4, 2020
de02dba
Update docs/building-modules/messages-and-queries.md
blushi Nov 4, 2020
c44842d
Update docs/building-modules/msg-services.md
blushi Nov 4, 2020
04b60c2
Update docs/building-modules/keeper.md
blushi Nov 4, 2020
fe83359
Merge branch 'master' into marie/7660-building-modules
blushi Nov 4, 2020
0da8557
Update docs/building-modules/msg-services.md
blushi Nov 4, 2020
14ee531
Address review comments
blushi Nov 4, 2020
efcc34e
Use tag
blushi Nov 4, 2020
820bd08
Merge branch 'master' into marie/7660-building-modules
blushi Nov 4, 2020
ced7d04
Merge branch 'master' into marie/7660-building-modules
blushi Nov 9, 2020
b6d9e64
Merge branch 'master' into marie/7660-building-modules
aaronc Nov 10, 2020
7708646
Update docs/building-modules/intro.md
blushi Nov 13, 2020
f2f593f
Update docs/building-modules/intro.md
blushi Nov 13, 2020
e728cf2
Update docs/building-modules/messages-and-queries.md
blushi Nov 13, 2020
d269fdf
Update docs/building-modules/messages-and-queries.md
blushi Nov 13, 2020
fbb724d
Update docs/building-modules/messages-and-queries.md
blushi Nov 13, 2020
7994850
Update docs/core/transactions.md
blushi Nov 13, 2020
4f53c17
Update docs/building-modules/messages-and-queries.md
blushi Nov 13, 2020
ffdc24f
Update docs/building-modules/messages-and-queries.md
blushi Nov 13, 2020
29abd96
Update docs/building-modules/messages-and-queries.md
blushi Nov 13, 2020
7c04784
Update docs/building-modules/messages-and-queries.md
blushi Nov 13, 2020
d8d1f21
Remove framework related explanation from docs
blushi Nov 13, 2020
3297ee7
Update docs/building-modules/messages-and-queries.md
blushi Nov 13, 2020
ee30a4d
Update docs/building-modules/module-manager.md
blushi Nov 13, 2020
6797e76
Update docs/building-modules/module-manager.md
blushi Nov 13, 2020
7c8ef33
Update docs/building-modules/msg-services.md
blushi Nov 13, 2020
e5f8731
Update docs/building-modules/msg-services.md
blushi Nov 13, 2020
c23d91e
Update docs/building-modules/msg-services.md
blushi Nov 13, 2020
8ae65d9
Update docs/building-modules/msg-services.md
blushi Nov 13, 2020
da10ab1
Update docs/building-modules/msg-services.md
blushi Nov 13, 2020
b38b0be
Update docs/building-modules/msg-services.md
blushi Nov 13, 2020
d3fb3a1
Update docs/building-modules/msg-services.md
blushi Nov 13, 2020
372d54f
Update docs/core/baseapp.md
blushi Nov 13, 2020
3843a36
Update docs/core/baseapp.md
blushi Nov 13, 2020
f05e072
Update beginblock-endblock.md
blushi Nov 13, 2020
71cb122
Update docs/core/baseapp.md
blushi Nov 13, 2020
49a86d3
Update docs/core/transactions.md
blushi Nov 13, 2020
e874cf4
Add deprecated notice
blushi Nov 13, 2020
96939f8
Merge branch 'master' into marie/7660-building-modules
blushi Nov 13, 2020
6c5c7e6
Update tx-lifecycle.md
blushi Nov 13, 2020
c136ccb
Merge branch 'master' into marie/7660-building-modules
clevinson Nov 17, 2020
fdc22e7
Merge branch 'master' into marie/7660-building-modules
mergify[bot] Nov 17, 2020
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
2 changes: 1 addition & 1 deletion docs/basics/app-anatomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Each module should also implement the `RegisterServices` method as part of the [

#### Handlers

The [handler](../building-modules/handler.md) refers to the part of the module responsible for processing the `Msg` after it is routed by `baseapp`. Handler functions of modules are only executed if the transaction is relayed from Tendermint by the `DeliverTx` ABCI message. If the transaction is relayed by `CheckTx`, only stateless checks and fee-related stateful checks are performed. To better understand the difference between `DeliverTx`and `CheckTx`, as well as the difference between stateful and stateless checks, click [here](./tx-lifecycle.md).
The [handler](../building-modules/msg-services.md#handler-type) refers to the part of the module responsible for processing the `Msg` after it is routed by `baseapp`. Handler functions of modules are only executed if the transaction is relayed from Tendermint by the `DeliverTx` ABCI message. If the transaction is relayed by `CheckTx`, only stateless checks and fee-related stateful checks are performed. To better understand the difference between `DeliverTx`and `CheckTx`, as well as the difference between stateful and stateless checks, click [here](./tx-lifecycle.md).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still want to use the word handler?

Copy link
Contributor Author

@blushi blushi Nov 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had agreed to remove any mention to handler in the docs, except in the "building modules" section, which @amaurymartiny did as part of this PR #7782 which isn't merged yet.


The `handler` of a module is generally defined in a file called `handler.go` and consists of:

Expand Down
2 changes: 1 addition & 1 deletion docs/basics/gas-fees.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ By default, the Cosmos SDK makes use of two different gas meters, the [main gas

`ctx.GasMeter()` is the main gas meter of the application. The main gas meter is initialized in `BeginBlock` via `setDeliverState`, and then tracks gas consumption during execution sequences that lead to state-transitions, i.e. those originally triggered by [`BeginBlock`](../core/baseapp.md#beginblock), [`DeliverTx`](../core/baseapp.md#delivertx) and [`EndBlock`](../core/baseapp.md#endblock). At the beginning of each `DeliverTx`, the main gas meter **must be set to 0** in the [`AnteHandler`](#antehandler), so that it can track gas consumption per-transaction.

Gas consumption can be done manually, generally by the module developer in the [`BeginBlocker`, `EndBlocker`](../building-modules/beginblock-endblock.md) or [`handler`](../building-modules/handler.md), but most of the time it is done automatically whenever there is a read or write to the store. This automatic gas consumption logic is implemented in a special store called [`GasKv`](../core/store.md#gaskv-store).
Gas consumption can be done manually, generally by the module developer in the [`BeginBlocker`, `EndBlocker`](../building-modules/beginblock-endblock.md) or [`Msg` service](../building-modules/msg-services.md), but most of the time it is done automatically whenever there is a read or write to the store. This automatic gas consumption logic is implemented in a special store called [`GasKv`](../core/store.md#gaskv-store).

### Block Gas Meter

Expand Down
14 changes: 7 additions & 7 deletions docs/basics/tx-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ explicitly ordered in the block proposal.

### DeliverTx

The `DeliverTx` ABCI function defined in [`baseapp`](../core/baseapp.md) does the bulk of the
The `DeliverTx` ABCI function defined in [`BaseApp`](../core/baseapp.md) does the bulk of the
state transitions: it is run for each transaction in the block in sequential order as committed
to during consensus. Under the hood, `DeliverTx` is almost identical to `CheckTx` but calls the
[`runTx`](../core/baseapp.md#runtx) function in deliver mode instead of check mode.
Expand All @@ -194,15 +194,15 @@ Instead of using their `checkState`, full-nodes use `deliverState`:
`AnteHandler` will not compare `gas-prices` to the node's `min-gas-prices` since that value is local
to each node - differing values across nodes would yield nondeterministic results.

- **Route and Handler:** While `CheckTx` would have exited, `DeliverTx` continues to run
- **`MsgServiceRouter`:** While `CheckTx` would have exited, `DeliverTx` continues to run
[`runMsgs`](../core/baseapp.md#runtx-and-runmsgs) to fully execute each `Msg` within the transaction.
Since the transaction may have messages from different modules, `baseapp` needs to know which module
to find the appropriate Handler. Thus, the `route` function is called via the [module manager](../building-modules/module-manager.md) to
retrieve the route name and find the [`Handler`](../building-modules/handler.md) within the module.
Since the transaction may have messages from different modules, `BaseApp` needs to know which module
to find the appropriate handler. This is achieved using `BaseApp`'s `MsgServiceRouter` so that it can be processed by the module's [`Msg` service](../building-modules/msg-services.md).
For legacy `Msg` routing, the `Route` function is called via the [module manager](../building-modules/module-manager.md) to retrieve the route name and find the legacy [`Handler`](../building-modules/msg-services.md#handler-type) within the module.

- **Handler:** The `handler`, a step up from `AnteHandler`, is responsible for executing each
- **`Msg` service:** The `Msg` service, a step up from `AnteHandler`, is responsible for executing each
message in the `Tx` and causes state transitions to persist in `deliverTxState`. It is defined
within a `Msg`'s module and writes to the appropriate stores within the module.
within a module `Msg` protobuf service and writes to the appropriate stores within the module.

- **Gas:** While a `Tx` is being delivered, a `GasMeter` is used to keep track of how much
gas is being used; if execution completes, `GasUsed` is set and returned in the
Expand Down
2 changes: 1 addition & 1 deletion docs/building-modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This repository contains documentation on concepts developers need to know in or
1. [Introduction to Cosmos SDK Modules](./intro.md)
2. [`AppModule` Interface and Module Manager](./module-manager.md)
3. [Messages and Queries](./messages-and-queries.md)
4. [`Handler`s - Processing Messages](./handler.md)
4. [`Msg` services - Processing Messages](./msg-services.md)
5. [Query Services - Processing Queries](./query-services.md)
6. [BeginBlocker and EndBlocker](./beginblock-endblock.md)
7. [`Keeper`s](./keeper.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/building-modules/beginblock-endblock.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ order: 6

When needed, `BeginBlocker` and `EndBlocker` are implemented as part of the [`AppModule` interface](./module-manager.md#appmodule). The `BeginBlock` and `EndBlock` methods of the interface implemented in `module.go` generally defer to `BeginBlocker` and `EndBlocker` methods respectively, which are usually implemented in a **`abci.go`** file.

The actual implementation of `BeginBlocker` and `EndBlocker` in `./abci.go` are very similar to that of a [`handler`](./handler.md):
The actual implementation of `BeginBlocker` and `EndBlocker` in `./abci.go` are very similar to that of a [`Msg` service](./msg-services.md):

- They generally use the [`keeper`](./keeper.md) and [`ctx`](../core/context.md) to retrieve information about the latest state.
- If needed, they use the `keeper` and `ctx` to trigger state-transitions.
Expand Down
96 changes: 0 additions & 96 deletions docs/building-modules/handler.md

This file was deleted.

11 changes: 5 additions & 6 deletions docs/building-modules/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Cosmos SDK can be thought as the Ruby-on-Rails of blockchain development. It

On top of this core, the Cosmos SDK enables developers to build modules that implement the business logic of their application. In other words, SDK modules implement the bulk of the logic of applications, while the core does the wiring and enables modules to be composed together. The end goal is to build a robust ecosystem of open-source SDK modules, making it increasingly easier to build complex blockchain applications.

SDK Modules can be seen as little state-machines within the state-machine. They generally define a subset of the state using one ore multiple `KVStore` in the [main multistore](../core/store.md), as well as a subset of [`message` types](./messages-and-queries.md#messages). These `message`s are routed by one of the main component of SDK core, [`baseapp`](../core/baseapp.md), to the [`handler`](./handler.md) of the module that define them.
SDK Modules can be seen as little state-machines within the state-machine. They generally define a subset of the state using one or more `KVStore`s in the [main multistore](../core/store.md), as well as a subset of [message types](./messages-and-queries.md#messages). These messages are routed by one of the main component of SDK core, [`BaseApp`](../core/baseapp.md), to the [`Msg` service](./msg-services.md) of the module that define them.

```
+
Expand Down Expand Up @@ -76,12 +76,11 @@ While there is no definitive guidelines for writing modules, here are some impor

## Main Components of SDK Modules

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:
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:

- Custom [`message` types](./messages-and-queries.md#messages) to trigger state-transitions.
- A [`handler`](./handler.md) used to process messages when they are routed to the module by [`baseapp`](../core/baseapp.md#message-routing).
- A [`keeper`](./keeper.md), used to access the module's store(s) and update the state.
- A [query service](./query-services.md), used to process user queries when they are routed to the module by [`baseapp`](../core/baseapp.md#query-routing).
- A [`keeper`](./keeper.md), used to access the module's store(s) and update the state.
- A [`Msg` service](./messages-and-queries.md#messages) used to process messages when they are routed to the module by [`BaseApp`](../core/baseapp.md#message-routing) and trigger state-transitions.
- A [query service](./query-services.md), used to process user queries when they are routed to the module by [`BaseApp`](../core/baseapp.md#query-routing).
- Interfaces, for end users to query the subset of the state defined by the module and create `message`s of the custom types defined in the module.

In addition to these components, modules implement the `AppModule` interface in order to be managed by the [`module manager`](./module-manager.md).
Expand Down
2 changes: 1 addition & 1 deletion docs/building-modules/keeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Of course, it is possible to define different types of internal `keeper`s for th

## Implementing Methods

`Keeper`s primarily expose getter and setter methods for the store(s) managed by their module. These methods should remain as simple as possible and strictly be limited to getting or setting the requested value, as validity checks should have already been performed via the `ValidateBasic()` method of the [`message`](./messages-and-queries.md#messages) and the [`handler`](./handler.md) when `keeper`s' methods are called.
`Keeper`s primarily expose getter and setter methods for the store(s) managed by their module. These methods should remain as simple as possible and strictly be limited to getting or setting the requested value, as validity checks should have already been performed via the `ValidateBasic()` method of the [`message`](./messages-and-queries.md#messages) and the [`Msg` server](./msg-services.md) when `keeper`s' methods are called.

Typically, a *getter* method will present with the following signature

Expand Down
Loading