Skip to content
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

feat: Cosmos upgrade handler calls swingset #7994

Merged
merged 4 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, placing the upgradePlan in the init message actually makes sense. I have plans to refactor the toSwingSet in chain-main.js which would make this a lot easier and straightforward to handle too!

}
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