-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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: pre,begin,end block #22127
docs: pre,begin,end block #22127
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,10 +2,11 @@ | |||||||||
sidebar_position: 1 | ||||||||||
--- | ||||||||||
|
||||||||||
# BeginBlocker and EndBlocker | ||||||||||
# PreBlocker, BeginBlocker and EndBlocker | ||||||||||
|
||||||||||
:::note 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, when the [`BeginBlock`](../../learn/advanced/00-baseapp.md#beginblock) and [`EndBlock`](../../learn/advanced/00-baseapp.md#endblock) ABCI messages are received from the underlying consensus engine. | ||||||||||
`PreBlocker`, `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, when the [`BeginBlock`](../../learn/advanced/00-baseapp.md#beginblock) and [`EndBlock`](../../learn/advanced/00-baseapp.md#endblock) inside within ABCI `FinalizeBlock` | ||||||||||
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Approve addition of The inclusion of Please apply the following change to fix the grammatical issue: -They will be triggered at the beginning and at the end of each block respectively, when the [`BeginBlock`](../../learn/advanced/00-baseapp.md#beginblock) and [`EndBlock`](../../learn/advanced/00-baseapp.md#endblock) inside within ABCI `FinalizeBlock`
+They will be triggered at the beginning and at the end of each block respectively, when the [`BeginBlock`](../../learn/advanced/00-baseapp.md#beginblock) and [`EndBlock`](../../learn/advanced/00-baseapp.md#endblock) are called within ABCI `FinalizeBlock` 📝 Committable suggestion
Suggested change
|
||||||||||
::: | ||||||||||
|
||||||||||
:::note Pre-requisite Readings | ||||||||||
|
@@ -14,11 +15,22 @@ sidebar_position: 1 | |||||||||
|
||||||||||
::: | ||||||||||
|
||||||||||
## PreBlocker | ||||||||||
|
||||||||||
There are two semantics around the new lifecycle method: | ||||||||||
|
||||||||||
* It runs before the `BeginBlocker` of all modules | ||||||||||
* It can modify consensus parameters in storage, and signal the caller through the return value. | ||||||||||
|
||||||||||
:::warning | ||||||||||
Modules are required to get the consensus params from the consensus module. Consensus params located in `sdk.Context` were deprecated and should be treated as unsafe. `sdk.Context` is deprecated due to it being a global state within the entire state machine, it has been replaced with `appmodule.Environment`. | ||||||||||
::: | ||||||||||
|
||||||||||
## BeginBlocker and EndBlocker | ||||||||||
|
||||||||||
`BeginBlocker` and `EndBlocker` are a way for module developers to add automatic execution of logic to their module. This is a powerful tool that should be used carefully, as complex automatic functions can slow down or even halt the chain. | ||||||||||
|
||||||||||
In 0.47.0, Prepare and Process Proposal were added that allow app developers to do arbitrary work at those phases, but they do not influence the work that will be done in BeginBlock. If an application required `BeginBlock` to execute prior to any sort of work is done then this is not possible today (0.50.0). | ||||||||||
In 0.47.0, `PrepareProposal` and `ProcessProposal` were added that allow app developers to do arbitrary work at those phases, but they do not influence the work that will be done in `BeginBlock`, nor are they accessible from modules. | ||||||||||
|
||||||||||
When needed, `BeginBlocker` and `EndBlocker` are implemented as part of the [`HasBeginBlocker`, `HasABCIEndBlocker` and `EndBlocker` interfaces](./01-module-manager.md#appmodule). This means either can be left-out if not required. 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 `abci.go`. | ||||||||||
|
||||||||||
|
@@ -28,10 +40,18 @@ The actual implementation of `BeginBlocker` and `EndBlocker` in `abci.go` are ve | |||||||||
* If needed, they use the `keeper` and `ctx` to trigger state-transitions. | ||||||||||
* If needed, they can emit [`events`](../../learn/advanced/08-events.md) via the `environments`'s `EventManager`. | ||||||||||
|
||||||||||
A specific method (`UpdateValidators`) is available to return validator updates to the underlying consensus engine in the form of an [`[]appmodule.ValidatorUpdates`](https://github.com/cosmos/cosmos-sdk/blob/07151304e2ec6a185243d083f59a2d543253cb15/core/appmodule/v2/module.go#L87-L101). This is the preferred way to implement custom validator changes. | ||||||||||
A specific method (`UpdateValidators`) is available to return validator updates to the underlying consensus engine in the form of an [`[]appmodule.ValidatorUpdates`](https://github.com/cosmos/cosmos-sdk/blob/07151304e2ec6a185243d083f59a2d543253cb15/core/appmodule/v2/module.go#L87-L101). This is the preferred way to implement custom validator changes (in v1). | ||||||||||
|
||||||||||
It is possible for developers to define the order of execution between the `BeginBlocker`/`EndBlocker` functions of each of their application's modules via the module's manager `SetOrderBeginBlocker`/`SetOrderEndBlocker` methods. For more on the module manager, click [here](./01-module-manager.md#manager). | ||||||||||
|
||||||||||
### Implementation | ||||||||||
|
||||||||||
A module must implement those core interface to make use of the `PreBlocker`, `BeginBlocker` or `EndBlocker` capabilities: | ||||||||||
|
||||||||||
```go reference | ||||||||||
https://github.com/cosmos/cosmos-sdk/blob/core/v1.0.0-alpha.4/core/appmodule/v2/module.go#L22-L48 | ||||||||||
``` | ||||||||||
|
||||||||||
See an example implementation of `BeginBlocker` from the `distribution` module: | ||||||||||
|
||||||||||
```go reference | ||||||||||
|
@@ -49,6 +69,3 @@ and an example implementation of `EndBlocker` with validator updates from the `s | |||||||||
```go reference | ||||||||||
https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/staking/keeper/abci.go#L12-L17 | ||||||||||
``` | ||||||||||
|
||||||||||
|
||||||||||
<!-- TODO: leaving this here to update docs with core api changes --> |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consolidate
EndBlock
descriptions and correct grammatical error.This line appears to be redundant with the previous
EndBlock
description (line 247). Consider merging these two descriptions to avoid confusion. If there are important differences between the twoEndBlock
functions, please clarify them in a single, comprehensive description.Additionally, there is a minor grammatical issue:
By consolidating the
EndBlock
descriptions and fixing the grammatical error, the documentation will be more concise and clear.🧰 Tools
🪛 LanguageTool