Skip to content

Commit

Permalink
Added storeLoader while upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Sep 21, 2021
1 parent f6192d2 commit 358081e
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 6 deletions.
20 changes: 14 additions & 6 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import (

hubparams "github.com/sentinel-official/hub/params"
upgrade1 "github.com/sentinel-official/hub/upgrades/upgrade-1"
upgrade2 "github.com/sentinel-official/hub/upgrades/upgrade-2"
deposittypes "github.com/sentinel-official/hub/x/deposit/types"
custommint "github.com/sentinel-official/hub/x/mint"
custommintkeeper "github.com/sentinel-official/hub/x/mint/keeper"
Expand Down Expand Up @@ -161,7 +162,7 @@ type App struct {
slashingKeeper slashingkeeper.Keeper
stakingKeeper stakingkeeper.Keeper
upgradeKeeper upgradekeeper.Keeper
custommintKeeper custommintkeeper.Keeper
customMintKeeper custommintkeeper.Keeper
swapKeeper swapkeeper.Keeper
vpnKeeper vpnkeeper.Keeper

Expand Down Expand Up @@ -365,9 +366,7 @@ func NewApp(
)
app.evidenceKeeper.SetRouter(evidenceRouter)

app.upgradeKeeper.SetUpgradeHandler(upgrade1.Name, upgrade1.Handler(app.accountKeeper))

app.custommintKeeper = custommintkeeper.NewKeeper(
app.customMintKeeper = custommintkeeper.NewKeeper(
app.cdc,
app.keys[customminttypes.StoreKey],
app.mintKeeper,
Expand Down Expand Up @@ -413,7 +412,7 @@ func NewApp(
staking.NewAppModule(app.cdc, app.stakingKeeper, app.accountKeeper, app.bankKeeper),
upgrade.NewAppModule(app.upgradeKeeper),
transferModule,
custommint.NewAppModule(cdc, app.custommintKeeper),
custommint.NewAppModule(cdc, app.customMintKeeper),
swap.NewAppModule(app.cdc, app.swapKeeper),
vpn.NewAppModule(app.cdc, app.accountKeeper, app.bankKeeper, app.vpnKeeper),
)
Expand Down Expand Up @@ -453,7 +452,7 @@ func NewApp(
slashing.NewAppModule(app.cdc, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper),
staking.NewAppModule(app.cdc, app.stakingKeeper, app.accountKeeper, app.bankKeeper),
transferModule,
custommint.NewAppModule(cdc, app.custommintKeeper),
custommint.NewAppModule(cdc, app.customMintKeeper),
swap.NewAppModule(app.cdc, app.swapKeeper),
vpn.NewAppModule(app.cdc, app.accountKeeper, app.bankKeeper, app.vpnKeeper),
)
Expand All @@ -475,6 +474,15 @@ func NewApp(
)
app.SetEndBlocker(app.EndBlocker)

app.upgradeKeeper.SetUpgradeHandler(
upgrade1.Name,
upgrade1.Handler(app.accountKeeper),
)
app.upgradeKeeper.SetUpgradeHandler(
upgrade2.Name,
upgrade2.Handler(app.SetStoreLoader, app.upgradeKeeper, app.customMintKeeper),
)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down
99 changes: 99 additions & 0 deletions upgrades/upgrade-2/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package upgrade2

import (
"time"

"github.com/cosmos/cosmos-sdk/baseapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

custommintkeeper "github.com/sentinel-official/hub/x/mint/keeper"
customminttypes "github.com/sentinel-official/hub/x/mint/types"
)

func Handler(
setStoreLoader func(baseapp.StoreLoader),
upgradeKeeper upgradekeeper.Keeper,
customMintKeeper custommintkeeper.Keeper,
) upgradetypes.UpgradeHandler {
info, err := upgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if info.Name == Name && !upgradeKeeper.IsSkipHeight(info.Height) {
upgrades := &storetypes.StoreUpgrades{
Added: []string{customminttypes.ModuleName},
}

setStoreLoader(
upgradetypes.UpgradeStoreLoader(
info.Height,
upgrades,
),
)
}

return func(ctx sdk.Context, _ upgradetypes.Plan) {
if err := updateInflations(ctx, customMintKeeper); err != nil {
panic(err)
}
}
}

func updateInflations(ctx sdk.Context, k custommintkeeper.Keeper) error {
var (
inflations = []customminttypes.Inflation{
{
Max: sdk.NewDecWithPrec(49, 2),
Min: sdk.NewDecWithPrec(43, 2),
RateChange: sdk.NewDecWithPrec(6, 2),
Timestamp: time.Date(2021, 9, 27, 0, 0, 0, 0, time.UTC),
},
{
Max: sdk.NewDecWithPrec(43, 2),
Min: sdk.NewDecWithPrec(37, 2),
RateChange: sdk.NewDecWithPrec(6, 2),
Timestamp: time.Date(2022, 3, 27, 0, 0, 0, 0, time.UTC),
},
{
Max: sdk.NewDecWithPrec(37, 2),
Min: sdk.NewDecWithPrec(31, 2),
RateChange: sdk.NewDecWithPrec(6, 2),
Timestamp: time.Date(2022, 9, 27, 0, 0, 0, 0, time.UTC),
},
{
Max: sdk.NewDecWithPrec(31, 2),
Min: sdk.NewDecWithPrec(25, 2),
RateChange: sdk.NewDecWithPrec(6, 2),
Timestamp: time.Date(2023, 3, 27, 0, 0, 0, 0, time.UTC),
},
{
Max: sdk.NewDecWithPrec(25, 2),
Min: sdk.NewDecWithPrec(19, 2),
RateChange: sdk.NewDecWithPrec(6, 2),
Timestamp: time.Date(2023, 9, 27, 0, 0, 0, 0, time.UTC),
},
{
Max: sdk.NewDecWithPrec(19, 2),
Min: sdk.NewDecWithPrec(13, 2),
RateChange: sdk.NewDecWithPrec(6, 2),
Timestamp: time.Date(2024, 3, 27, 0, 0, 0, 0, time.UTC),
},
}
)

for _, inflation := range inflations {
if err := inflation.Validate(); err != nil {
return err
}
}

for _, inflation := range inflations {
k.SetInflation(ctx, inflation)
}

return nil
}
5 changes: 5 additions & 0 deletions upgrades/upgrade-2/keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package upgrade2

const (
Name = "upgrade-2"
)

0 comments on commit 358081e

Please sign in to comment.