Merge PR #196: Upgrade module

This commit is contained in:
Federico Kunze 2019-11-30 18:45:08 +01:00 committed by Alexander Bezobchuk
parent 37333837dc
commit 982376964f
5 changed files with 97 additions and 16 deletions

View File

@ -43,11 +43,12 @@ flag and configuration.
* (gaiacli) [\#132](https://github.com/cosmos/gaia/pull/132) Add `tx decode` command to decode
Base64 encoded transactions.
* (modules) [\#190](https://github.com/cosmos/gaia/pull/190) Introduce use of the `x/evidence` module.
* (gaiad) [\#191](https://github.com/cosmos/gaia/pull/191) Add debug commands to gaiad:
- `pubkey`: decode pubkey from base64, hex or bech32
- `addr`: convert a address between hex and bech32
- `raw-bytes` convert raw-bytes to hex
* (gaiad) [\#191](https://github.com/cosmos/gaia/pull/191) Add debug commands to gaiad:
* `pubkey`: decode pubkey from base64, hex or bech32
* `addr`: convert a address between hex and bech32
* `raw-bytes` convert raw-bytes to hex
* (gaiacli) [\#191](https://github.com/cosmos/gaia/pull/191) Add cmd `decode-tx`, decodes a tx from hex or base64
* (modules) [\#196](https://github.com/cosmos/gaia/pull/196) Integrate the `x/upgrade` module.
## [v2.0.3] - 2019-11-04

View File

@ -29,6 +29,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
)
const appName = "GaiaApp"
@ -50,11 +52,12 @@ var (
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(paramsclient.ProposalHandler, distr.ProposalHandler),
gov.NewAppModuleBasic(paramsclient.ProposalHandler, distr.ProposalHandler, upgradeclient.ProposalHandler),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
supply.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
)
@ -105,6 +108,7 @@ type GaiaApp struct {
govKeeper gov.Keeper
crisisKeeper crisis.Keeper
paramsKeeper params.Keeper
upgradeKeeper upgrade.Keeper
evidenceKeeper *evidence.Keeper
// the module manager
@ -125,11 +129,10 @@ func NewGaiaApp(
bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetAppVersion(version.Version)
keys := sdk.NewKVStoreKeys(
bam.MainStoreKey, auth.StoreKey, staking.StoreKey, supply.StoreKey,
mint.StoreKey, distr.StoreKey, slashing.StoreKey, gov.StoreKey,
params.StoreKey, evidence.StoreKey,
bam.MainStoreKey, auth.StoreKey, staking.StoreKey,
supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey,
gov.StoreKey, params.StoreKey, evidence.StoreKey, upgrade.StoreKey,
)
tKeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey)
@ -167,6 +170,7 @@ func NewGaiaApp(
app.cdc, keys[slashing.StoreKey], &stakingKeeper, slashingSubspace, slashing.DefaultCodespace,
)
app.crisisKeeper = crisis.NewKeeper(crisisSubspace, invCheckPeriod, app.supplyKeeper, auth.FeeCollectorName)
app.upgradeKeeper = upgrade.NewKeeper(keys[upgrade.StoreKey], app.cdc)
// create evidence keeper with evidence router
app.evidenceKeeper = evidence.NewKeeper(
@ -180,7 +184,8 @@ func NewGaiaApp(
govRouter := gov.NewRouter()
govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler).
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)).
AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.distrKeeper))
AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.distrKeeper)).
AddRoute(upgrade.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.upgradeKeeper))
app.govKeeper = gov.NewKeeper(
app.cdc, keys[gov.StoreKey], govSubspace,
app.supplyKeeper, &stakingKeeper, gov.DefaultCodespace, govRouter,
@ -205,14 +210,15 @@ func NewGaiaApp(
mint.NewAppModule(app.mintKeeper),
slashing.NewAppModule(app.slashingKeeper, app.stakingKeeper),
staking.NewAppModule(app.stakingKeeper, app.accountKeeper, app.supplyKeeper),
upgrade.NewAppModule(app.upgradeKeeper),
evidence.NewAppModule(*app.evidenceKeeper),
)
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
app.mm.SetOrderBeginBlockers(mint.ModuleName, distr.ModuleName, slashing.ModuleName)
app.mm.SetOrderBeginBlockers(upgrade.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName)
app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName)
// NOTE: The genutils module must occur after staking so that pools are

View File

@ -0,0 +1,74 @@
# Live Upgrade Tutorial
This document demonstrates how a live upgrade can be performed on-chain through a
governance process.
1. Start the network and trigger upgrade
```bash
# start a gaia application full-node
$ gaiad start
# set up the cli config
$ gaiacli config trust-node true
$ gaiacli config chain-id testing
# create an upgrade governance proposal
$ gaiacli tx gov submit-proposal software-upgrade <plan-name> \
--title <proposal-title> --description <proposal-description> \
--from <name-or-key> --upgrade-height <desired-upgrade-height> --deposit 10000000stake
# once the proposal passes you can query the pending plan
$ gaiacli query upgrade plan
```
2. Performing an upgrade
Assuming the proposal passes the chain will stop at given upgrade height.
You can stop and start the original binary all you want, but **it will refuse to
run after the upgrade height**.
We need a new binary with the upgrade handler installed. The logs should look
something like:
```shell
E[2019-11-05|12:44:18.913] UPGRADE "<plan-name>" NEEDED at height: <desired-upgrade-height>: module=main
E[2019-11-05|12:44:18.914] CONSENSUS FAILURE!!!
...
```
Note that the process will hang indefinitely (doesn't exit to avoid restart loops). So, you must
manually kill the process and replace it with a new binary. Do so now with `Ctrl+C` or `killall gaiad`.
In `gaia/app/app.go`, after `upgrade.Keeper` is initialized and set in the app, set the the
corresponding upgrade `Handler` with the correct `<plan-name>`:
```go
app.upgradeKeeper.SetUpgradeHandler("<plan-name>", func(ctx sdk.Context, plan upgrade.Plan) {
// custom logic after the network upgrade has been executed
})
```
Note that we panic on any error - this would cause the upgrade to fail if the
migration could not be run, and no node would advance - allowing a manual recovery.
If we ignored the errors, then we would proceed with an incomplete upgrade and
have a very difficult time every recovering the proper state.
Now, compile the new binary and run the upgraded code to complete the upgrade:
```bash
# create a new binary of gaia with the added upgrade handler
$ make install
# Restart the chain using the new binary. You should see the chain resume from
# the upgrade height:
# `I[2019-11-05|12:48:15.184] applying upgrade <plan-name> at height: <desired-upgrade-height> module=main`
$ gaiad start
# verify there is no pending plan
$ gaiacli query upgrade plan
# verify you can query the block header of the completed upgrade
$ gaiacli query upgrade applied <plan-name>
```

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.13
require (
github.com/btcsuite/btcd v0.0.0-20190807005414-4063feeff79a // indirect
github.com/cosmos/cosmos-sdk v0.34.4-0.20191114141721-d4c831e63ad3
github.com/cosmos/cosmos-sdk v0.34.4-0.20191130143208-b9cb3e105dba
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
github.com/golang/mock v1.3.1 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect

8
go.sum
View File

@ -40,8 +40,8 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cosmos/cosmos-sdk v0.34.4-0.20191114141721-d4c831e63ad3 h1:vjzTX8arh3cEAHSbxazdRRLS67Gl4JoNY6tcNyjqmms=
github.com/cosmos/cosmos-sdk v0.34.4-0.20191114141721-d4c831e63ad3/go.mod h1:0sLtjU+qex1OfpGQHjWhJByx74IoH78R742PEAdoQJk=
github.com/cosmos/cosmos-sdk v0.34.4-0.20191130143208-b9cb3e105dba h1:S9ojH+R2yp+m2yDpUz+6fmP1vUknYWNM9eOge1IAYL4=
github.com/cosmos/cosmos-sdk v0.34.4-0.20191130143208-b9cb3e105dba/go.mod h1:tA4b40PRtoZdit2w1o29YYdrCfuAVEpD7bRz9JDo43M=
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
@ -375,7 +375,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=