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

R4R: Docs: Building-modules section 2nd part #5037

Merged
merged 17 commits into from
Oct 11, 2019

Conversation

gamarin2
Copy link
Contributor

@gamarin2 gamarin2 commented Sep 12, 2019

Finishing building-modules section of the new docs.

  • Targeted PR against correct branch (see CONTRIBUTING.md)

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.

  • Wrote tests

  • Updated relevant documentation (docs/)

  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md

  • Re-reviewed Files changed in the github PR explorer


For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@gamarin2 gamarin2 changed the title Docs: Building-modules section Docs: Building-modules section 2nd part Sep 12, 2019
@codecov
Copy link

codecov bot commented Sep 12, 2019

Codecov Report

Merging #5037 into master-docs will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff              @@
##           master-docs    #5037   +/-   ##
============================================
  Coverage        54.85%   54.85%           
============================================
  Files              305      305           
  Lines            18494    18494           
============================================
  Hits             10144    10144           
  Misses            7595     7595           
  Partials           755      755

@gamarin2 gamarin2 marked this pull request as ready for review September 13, 2019 15:42
@gamarin2 gamarin2 changed the title Docs: Building-modules section 2nd part R4R: Docs: Building-modules section 2nd part Sep 13, 2019
docs/building-modules/beginblock-endblock.md Outdated Show resolved Hide resolved
docs/building-modules/invariants.md Show resolved Hide resolved
docs/building-modules/invariants.md Outdated Show resolved Hide resolved
docs/building-modules/invariants.md Outdated Show resolved Hide resolved
docs/building-modules/invariants.md Outdated Show resolved Hide resolved
docs/building-modules/messages-and-queries.md Outdated Show resolved Hide resolved
docs/building-modules/module-manager.md Outdated Show resolved Hide resolved
docs/building-modules/module-manager.md Outdated Show resolved Hide resolved
docs/core/baseapp.md Outdated Show resolved Hide resolved
docs/core/baseapp.md Outdated Show resolved Hide resolved
@alexanderbez
Copy link
Contributor

Is this ready to merge @gamarin2? I also recommend merging the latest master into master-docs prior to merging this if possible.

@gamarin2
Copy link
Contributor Author

@alexanderbez well I'd like 1 more review if possible, but otherwise yes

@fedekunze fedekunze added T:Docs Changes and features related to documentation. R4R labels Oct 1, 2019
docs/building-modules/handler.md Outdated Show resolved Hide resolved
docs/building-modules/handler.md Outdated Show resolved Hide resolved
docs/building-modules/querier.md Outdated Show resolved Hide resolved
@fedekunze
Copy link
Collaborator

@gamarin2 please merge master into master-docs to fix CI

@gamarin2 gamarin2 merged commit d3a168a into master-docs Oct 11, 2019
@gamarin2 gamarin2 deleted the gamarin/building-modules branch October 11, 2019 14:52
Copy link
Contributor

@hschoenburg hschoenburg left a comment

Choose a reason for hiding this comment

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

some small comments.


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` are very similar to that of a [`handler`](./handler.md):
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to add a line describing app.ModuleManager.SetOrderBeginBlockers and SetOrderEndBlockers


## Synopsis

`BeginBlocker` and `EndBlocker` are optional methods module developers can implement in their module. They will be triggered at the beginning and at the end of each block respectively.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add something along the lines of "They will be triggered at the beginning and at the end of each block by the BeginBlock and EndBlock ABCI messages sent from Tendermint."

### `InitGenesis`

The `InitGenesis` method is executed during [`InitChain`](../core/baseapp.md#initchain) when the application is first started. Given a `GenesisState`, it initializes the subset of the state managed by the module by using the module's [`keeper`](./keeper.md) setter function on each parameter within the `GenesisState`.
Copy link
Contributor

Choose a reason for hiding this comment

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

probably want to mention ModuleManager.SetOrderInitGenesis here too
https://github.com/cosmos/gaia/blob/master/app/app.go#L203

The `InvariantRegistry` is a registry where the `Invariant`s of all the modules of an application are registered. There is only one `InvariantRegistry` per **application**, meaning module developers need not implement their own `InvariantRegistry` when building a module. All module developers need to do is to register their modules' invariants in the `InvariantRegistry`, as explained in the section above.

Typically, the `InvariantRegistry` is implemented as a specific module (the most used implementation is that of the [`crisis` module](https://github.com/cosmos/cosmos-sdk/blob/master/x/crisis/)). This module must implement an object that follow the [`sdk.InvariantRegistry` interface](https://github.com/cosmos/cosmos-sdk/blob/master/types/invariant.go#L14-L17).
Copy link
Contributor

Choose a reason for hiding this comment

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

this paragraph is confusing. -- does the SDK contain the only instance of the InvariantRegistry ? Does the crisis module contain another instance?

- `storeKey`s grant access to the store(s) of the [multistore](../core/store.md) managed by the module. They should always remain unexposed to external modules.
- A [codec `cdc`](../core/encoding.md), used to marshall and unmarshall struct to/from `[]byte`.

Of course, it is possible to define different types of internal `keeper`s for the same module (e.g. a read-only `keeper`). Each type of `keeper` comes with its own constructor function, which is called from the [application's constructor function](../basics/app-anatomy.md). This is where `keeper`s are instanciated, and where developers make sure to pass correct instances of modules' `keeper`s to other modules that require it.
Copy link
Contributor

Choose a reason for hiding this comment

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

instantiated


## Synopsis

`Keeper`s refer to a Cosmos SDK abstraction whose role is to manage access to the subset of the state defined by various modules. `Keeper`s are module-specific, i.e. the subset of state defined by a module can only be accessed by a `keeper` defined in said module. If a module needs to access the subset of state defined by another module, a reference to the second module's internal `keeper` needs to be passed to the first one. This is done in `app.go` during the instantiation of module keepers.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps add a line describing what the underlying KVStore is? https://github.com/tendermint/iavl

```

The `Msg` is typically accompagnied by a standard constructor function, that is called from one of the [module's interface](./module-interface). `message`s also need to implement the [`Msg`](https://github.com/cosmos/cosmos-sdk/blob/master/types/tx_msg.go#L7-L29) interface, which contains the following methods:
Copy link
Contributor

Choose a reason for hiding this comment

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

accompanied

## Queries

A `query` is a request for information made by end-users of applications through an interface and processed by a full-node. A `query` is received by a full-node through its consensus engine and relayed to the application via the ABCI. It is then routed to the appropriate module via `baseapp`'s `queryrouter` so that it can be processed by the module's [`querier`](./querier.md). For a deeper look at the lifecycle of a `query`, click [here](../interfaces/query-lifecycle.md).
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe mention that these queries should not be confused with the REST server and its endpoints?

The module manager is used throughout the application whenever an action on a collection of modules is required. It implements the following methods:

- `NewManager(modules ...AppModule)`: Constructor function. It takes a list of the application's `AppModule`s and builds a new `Manager`. It is generally called from the application's main [constructor function](../basics/app-anatomy.md#constructor-function).
- `SetOrderInitGenesis(moduleNames ...string)`: Sets the order in which the [`InitGenesis`](./genesis.md#initgenesis) function of each module will be called when the application is first started. This function is generally called from the application's main [constructor function](../basics/app-anatomy.md#constructor-function).
Copy link
Contributor

Choose a reason for hiding this comment

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

ah great maybe just provide a link to this section above when discussing InitGenesis and BeginBlock

@hschoenburg
Copy link
Contributor

oops submitted my review too late sorrry. Nothing major, could probably be ignored

@gamarin2
Copy link
Contributor Author

No worries @hschoenburg. I will integrate your comments in the final docs-cleanup PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T:Docs Changes and features related to documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants