Skip to content

Commit

Permalink
Merge pull request #7994 from Agoric/7992-enact-upgrade-plan
Browse files Browse the repository at this point in the history
feat: Cosmos upgrade handler calls swingset
  • Loading branch information
JimLarson authored Jul 12, 2023
2 parents 5382a55 + 8d8580a commit bcca849
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 39 deletions.
56 changes: 20 additions & 36 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ type GaiaApp struct { // nolint: golint
vibcPort int
vstoragePort int

upgradePlan *upgradetypes.Plan

invCheckPeriod uint

// keys to access the substores
Expand Down Expand Up @@ -744,11 +746,11 @@ func NewAgoricApp(

app.UpgradeKeeper.SetUpgradeHandler(
upgradeName,
upgrade10Handler(app, upgradeName),
upgrade11Handler(app, upgradeName),
)
app.UpgradeKeeper.SetUpgradeHandler(
upgradeNameTest,
upgrade10Handler(app, upgradeNameTest),
upgrade11Handler(app, upgradeNameTest),
)

if loadLatest {
Expand All @@ -771,39 +773,19 @@ func NewAgoricApp(
return app
}

func upgrade10Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
// upgrade11Handler performs standard upgrade actions plus custom actions for upgrade-11.
func upgrade11Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
// change bootrap gov parameter to correct vaults parameter

prevParams := app.SwingSetKeeper.GetParams(ctx)

ctx.Logger().Info("Pre-upgrade swingset params", "BeansPerUnit", fmt.Sprintf("%v", prevParams.BeansPerUnit), "BootstrapVatConfig", prevParams.BootstrapVatConfig)

switch targetUpgrade {
case upgradeName:
prevParams.BootstrapVatConfig = "@agoric/vats/decentral-main-vaults-config.json"
case upgradeNameTest:
prevParams.BootstrapVatConfig = "@agoric/vats/decentral-test-vaults-config.json"
default:
return fromVm, fmt.Errorf("invalid upgrade name")
}

app.SwingSetKeeper.SetParams(ctx, prevParams)
ctx.Logger().Info("Post-upgrade swingset params", "BeansPerUnit", fmt.Sprintf("%v", prevParams.BeansPerUnit), "BootstrapVatConfig", prevParams.BootstrapVatConfig)

app.VstorageKeeper.MigrateNoDataPlaceholders(ctx) // upgrade-10 only
normalizeModuleAccount(ctx, app.AccountKeeper, vbanktypes.ProvisionPoolName)
normalizeModuleAccount(ctx, app.AccountKeeper, vbanktypes.ReservePoolName)
// Record the plan to send to SwingSet
app.upgradePlan = &plan

// Always run module migrations
mvm, err := app.mm.RunMigrations(ctx, app.configurator, fromVm)
if err != nil {
return mvm, err
}

// Just run the SwingSet kernel to finish bootstrap and get ready to open for
// business.
stdlog.Println("Rebooting SwingSet")
return mvm, swingset.BootSwingset(ctx, app.SwingSetKeeper)
return mvm, nil
}
}

Expand All @@ -825,14 +807,15 @@ func normalizeModuleAccount(ctx sdk.Context, ak authkeeper.AccountKeeper, name s
}

type cosmosInitAction struct {
Type string `json:"type"`
ChainID string `json:"chainID"`
Params swingset.Params `json:"params"`
StoragePort int `json:"storagePort"`
SupplyCoins sdk.Coins `json:"supplyCoins"`
VibcPort int `json:"vibcPort"`
VbankPort int `json:"vbankPort"`
LienPort int `json:"lienPort"`
Type string `json:"type"`
ChainID string `json:"chainID"`
Params swingset.Params `json:"params"`
StoragePort int `json:"storagePort"`
SupplyCoins sdk.Coins `json:"supplyCoins"`
VibcPort int `json:"vibcPort"`
VbankPort int `json:"vbankPort"`
LienPort int `json:"lienPort"`
UpgradePlan *upgradetypes.Plan `json:"upgradePlan,omitempty"`
}

// Name returns the name of the App
Expand All @@ -853,6 +836,7 @@ func (app *GaiaApp) MustInitController(ctx sdk.Context) {
VibcPort: app.vibcPort,
VbankPort: app.vbankPort,
LienPort: app.lienPort,
UpgradePlan: app.upgradePlan,
}
out, err := app.SwingSetKeeper.BlockingSend(ctx, action)

Expand Down
4 changes: 2 additions & 2 deletions golang/cosmos/app/const.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gaia

const (
upgradeName = "agoric-upgrade-10"
upgradeNameTest = "agorictest-upgrade-10"
upgradeName = "agoric-upgrade-11"
upgradeNameTest = "agorictest-upgrade-11"
)
2 changes: 1 addition & 1 deletion packages/deployment/upgrade-test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ARG DEST_IMAGE
#this is agoric-upgrade-10 / vaults
FROM ghcr.io/agoric/agoric-sdk:34 as agoric-upgrade-10
ARG BOOTSTRAP_MODE
ENV THIS_NAME=agoric-upgrade-10 BOOTSTRAP_MODE=${BOOTSTRAP_MODE}
ENV THIS_NAME=agoric-upgrade-10 UPGRADE_TO=agoric-upgrade-11 BOOTSTRAP_MODE=${BOOTSTRAP_MODE}

WORKDIR /usr/src/agoric-sdk/
COPY ./bash_entrypoint.sh ./env_setup.sh ./start_to_to.sh ./upgrade-test-scripts/
Expand Down

0 comments on commit bcca849

Please sign in to comment.