This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SoftwareUpgradeProposal is a gov Content type for initiating a software | |
// upgrade. | |
message SoftwareUpgradeProposal { | |
string title = 1; | |
string description = 2; | |
Plan plan = 3 [(gogoproto.nullable) = false]; | |
} | |
// Plan specifies information about a planned upgrade and when it should occur. | |
message Plan { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EndBlocker called every block, process inflation, update validator set. | |
func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { | |
keeper.IterateActiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal types.Proposal) bool { | |
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal) | |
... | |
if passes { | |
handler := keeper.Router().GetRoute(proposal.ProposalRoute()) | |
cacheCtx, writeCache := ctx.CacheContext() | |
err := handler(cacheCtx, proposal.GetContent()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func NewSimApp(...) *SimApp { | |
... | |
// register the proposal types | |
govRouter := govtypes.NewRouter() | |
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). | |
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) | |
govKeeper := govkeeper.NewKeeper( | |
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, | |
&stakingKeeper, govRouter, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UpgradeHandler specifies the type of function that is called when an upgrade | |
// is applied. | |
// | |
// `fromVM` is a VersionMap of moduleName to fromVersion (unit64), where | |
// fromVersion denotes the version from which we should migrate the module, the | |
// target version being the module's latest version in the return VersionMap, | |
// let's call it `toVM`. | |
// | |
// `fromVM` is retrieved from x/upgrade's store, whereas `toVM` is chosen | |
// arbitrarily by the app developer (and persisted to x/upgrade's store right |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VersionMap is a map of moduleName -> version | |
type VersionMap map[string]uint64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { | |
BeginBlocker(am.keeper, ctx, req) | |
} | |
func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { | |
plan, found := k.GetUpgradePlan(ctx) | |
... | |
if !found { | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. # application project root | |
βββ app | |
β βββ upgrades | |
β β βββ v2 | |
β β β βββ constants.go | |
β β β βββ upgrades.go | |
β β βββ ... | |
β βββ app.go | |
β βββ upgrades.go | |
βββ ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package v2 // constants.go | |
const ( | |
UpgradeName = "v2.0.0" | |
... | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package v2 // upgrades.go | |
func CreateUpgradeHandler( | |
mm *module.Manager, | |
configurator module.Configurator, | |
... | |
) upgradetypes.UpgradeHandler { | |
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | |
... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app // upgrades.go | |
func (app *App) setupUpgradeHandlers( | |
configurator module.Configurator, | |
... | |
) { | |
app.UpgradeKeeper.SetUpgradeHandler( | |
v2.UpgradeName, | |
v2.CreateUpgradeHandler(app.mm, configurator, ...), | |
) |