Skip to content

Commit 41e5ed2

Browse files
julienrbrtmergify[bot]
authored andcommitted
docs: improve upgrade docs on preblocker (#17734)
(cherry picked from commit 62838eb)
1 parent 5a347a4 commit 41e5ed2

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

UPGRADING.md

+25-4
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,41 @@ for more info.
6969

7070
#### Set PreBlocker
7171

72-
**Users using `depinject` / app v2 do not need any changes, this is abstracted for them.**
72+
A `SetPreBlocker` method has been added to BaseApp. This is essential for BaseApp to run `PreBlock` which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics.
73+
Read more about other use cases [here](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-068-preblock.md).
74+
75+
`depinject` / app v2 users need to add `x/upgrade` in their `app_config.go` / `app.yml`:
7376

7477
```diff
75-
+ app.SetPreBlocker(app.PreBlocker)
78+
+ PreBlockers: []string{
79+
+ upgradetypes.ModuleName,
80+
+ },
81+
BeginBlockers: []string{
82+
- upgradetypes.ModuleName,
83+
minttypes.ModuleName,
84+
}
7685
```
7786

87+
When using (legacy) application wiring, the following must be added to `app.go`:
88+
7889
```diff
90+
+app.ModuleManager.SetOrderPreBlockers(
91+
+ upgradetypes.ModuleName,
92+
+)
93+
94+
app.ModuleManager.SetOrderBeginBlockers(
95+
- upgradetypes.ModuleName,
96+
)
97+
98+
+ app.SetPreBlocker(app.PreBlocker)
99+
100+
// ... //
101+
79102
+func (app *SimApp) PreBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (sdk.ResponsePreBlock, error) {
80103
+ return app.ModuleManager.PreBlock(ctx, req)
81104
+}
82105
```
83106

84-
BaseApp added `SetPreBlocker` for apps. This is essential for BaseApp to run `PreBlock` which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics.
85-
86107
#### Events
87108

88109
The log section of `abci.TxResult` is not populated in the case of successful

docs/docs/build/building-apps/03-app-upgrade.md

+11-23
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,24 @@ the rest of the block as normal. Once 2/3 of the voting power has upgraded, the
5050
resume the consensus mechanism. If the majority of operators add a custom `do-upgrade` script, this should
5151
be a matter of minutes and not even require them to be awake at that time.
5252

53-
## Set PreBlocker
54-
55-
:::tip
56-
Users using `depinject` / app v2 do not need any changes, this is abstracted for them.
57-
:::
53+
## Integrating With An App
5854

59-
Call `SetPreBlocker` to run `PreBlock`:
55+
::tip
56+
The following is not required for users using `depinject` / app v2, this is abstracted for them.
57+
::
6058

61-
```go
62-
app.SetPreBlocker(app.PreBlocker)
63-
```
59+
In addition to basic module wiring, setup the upgrade Keeper for the app and then define a `PreBlocker` that calls the upgrade
60+
keeper's PreBlocker method:
6461

6562
```go
66-
func (app *SimApp) PreBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (sdk.ResponsePreBlock, error) {
67-
return app.ModuleManager.PreBlock(ctx, req)
63+
func (app *myApp) PreBlocker(ctx sdk.Context, req req.RequestFinalizeBlock) (sdk.ResponsePreBlock, error) {
64+
// For demonstration sake, the app PreBlocker only returns the upgrade module pre-blocker.
65+
// In a real app, the module manager should call all pre-blockers
66+
// return return app.ModuleManager.PreBlock(ctx, req)
67+
return app.upgradeKeeper.PreBlocker(ctx, req)
6868
}
6969
```
7070

71-
## Integrating With An App
72-
73-
Setup an upgrade Keeper for the app and then define a `BeginBlocker` that calls the upgrade
74-
keeper's BeginBlocker method:
75-
76-
```go
77-
func (app *myApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (abci.ResponseBeginBlock, error) {
78-
app.upgradeKeeper.BeginBlocker(ctx, req)
79-
return abci.ResponseBeginBlock{}, nil
80-
}
81-
```
82-
8371
The app must then integrate the upgrade keeper with its governance module as appropriate. The governance module
8472
should call ScheduleUpgrade to schedule an upgrade and ClearUpgradePlan to cancel a pending upgrade.
8573

x/upgrade/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar_position: 1
88

99
`x/upgrade` is an implementation of a Cosmos SDK module that facilitates smoothly
1010
upgrading a live Cosmos chain to a new (breaking) software version. It accomplishes this by
11-
providing a `BeginBlocker` hook that prevents the blockchain state machine from
11+
providing a `PreBlocker` hook that prevents the blockchain state machine from
1212
proceeding once a pre-defined upgrade block height has been reached.
1313

1414
The module does not prescribe anything regarding how governance decides to do an

0 commit comments

Comments
 (0)