Skip to content

Commit

Permalink
add upgrade handler migration
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Apr 16, 2024
1 parent 1c71ba6 commit 3123253
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
attributetypes "github.com/provenance-io/provenance/x/attribute/types"
markertypes "github.com/provenance-io/provenance/x/marker/types"
metadatatypes "github.com/provenance-io/provenance/x/metadata/types"
msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types"
)

// appUpgrade is an internal structure for defining all things for an upgrade.
Expand Down Expand Up @@ -61,6 +62,7 @@ var upgrades = map[string]appUpgrade{
migrateAttributeParams(ctx, app)
migrateMarkerParams(ctx, app)
migrateMetadataOSLocatorParams(ctx, app)
migrateMsgFeesParams(ctx, app)

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
Expand Down Expand Up @@ -95,6 +97,7 @@ var upgrades = map[string]appUpgrade{
migrateAttributeParams(ctx, app)
migrateMarkerParams(ctx, app)
migrateMetadataOSLocatorParams(ctx, app)
migrateMsgFeesParams(ctx, app)

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
Expand Down Expand Up @@ -363,3 +366,33 @@ func migrateMetadataOSLocatorParams(ctx sdk.Context, app *App) {
ctx.Logger().Info("Done migrating metadata os locator params.")

}

// migrateMsgFeesParams migrates to new MsgFees Params store
func migrateMsgFeesParams(ctx sdk.Context, app *App) {
ctx.Logger().Info("Migrating msgfees params.")
msgFeesParamSpace := app.ParamsKeeper.Subspace(msgfeestypes.ModuleName).WithKeyTable(msgfeestypes.ParamKeyTable())

var floorGasPrice sdk.Coin
if msgFeesParamSpace.Has(ctx, msgfeestypes.ParamStoreKeyFloorGasPrice) {
msgFeesParamSpace.Get(ctx, msgfeestypes.ParamStoreKeyFloorGasPrice, &floorGasPrice)
}

var nhashPerUsdMil uint64
if msgFeesParamSpace.Has(ctx, msgfeestypes.ParamStoreKeyNhashPerUsdMil) {
msgFeesParamSpace.Get(ctx, msgfeestypes.ParamStoreKeyNhashPerUsdMil, &nhashPerUsdMil)
}

var conversionFeeDenom string
if msgFeesParamSpace.Has(ctx, msgfeestypes.ParamStoreKeyConversionFeeDenom) {
msgFeesParamSpace.Get(ctx, msgfeestypes.ParamStoreKeyConversionFeeDenom, &conversionFeeDenom)
}

migratedParams := msgfeestypes.Params{
FloorGasPrice: floorGasPrice,
NhashPerUsdMil: nhashPerUsdMil,
ConversionFeeDenom: conversionFeeDenom,
}
app.MsgFeesKeeper.SetParams(ctx, migratedParams)

ctx.Logger().Info("Done migrating msgfees params.")
}
4 changes: 4 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ func (s *UpgradeTestSuite) TestUmberRC1() {
"INF Done migrating marker params.",
"INF Migrating metadata os locator params.",
"INF Done migrating metadata os locator params.",
"INF Migrating msgfees params.",
"INF Done migrating msgfees params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
Expand All @@ -408,6 +410,8 @@ func (s *UpgradeTestSuite) TestUmber() {
"INF Done migrating marker params.",
"INF Migrating metadata os locator params.",
"INF Done migrating metadata os locator params.",
"INF Migrating msgfees params.",
"INF Done migrating msgfees params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
Expand Down

0 comments on commit 3123253

Please sign in to comment.