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: ibc ante handlers and upgrade cleanup #1441

Merged
merged 2 commits into from
Sep 21, 2022
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
4 changes: 4 additions & 0 deletions ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
cosmosante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/types"
ibcante "github.com/cosmos/ibc-go/v5/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper"
)

type HandlerOptions struct {
AccountKeeper cosmosante.AccountKeeper
BankKeeper types.BankKeeper
FeegrantKeeper cosmosante.FeegrantKeeper
OracleKeeper OracleKeeper
IBCKeeper *ibckeeper.Keeper
SignModeHandler signing.SignModeHandler
SigGasConsumer cosmosante.SignatureVerificationGasConsumer
}
Expand Down Expand Up @@ -49,5 +52,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
cosmosante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
cosmosante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
cosmosante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
), nil
}
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,11 @@ func (app *UmeeApp) setAnteHandler(txConfig client.TxConfig) {
customante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
OracleKeeper: app.OracleKeeper,
IBCKeeper: app.IBCKeeper,
SignModeHandler: txConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
OracleKeeper: app.OracleKeeper,
},
)
if err != nil {
Expand Down
33 changes: 14 additions & 19 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/group"
"github.com/cosmos/cosmos-sdk/x/nft"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

bech32ibckeeper "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/keeper"
bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types"
v3upgrades "github.com/umee-network/umee/v3/app/upgrades/v3"

"github.com/umee-network/umee/v3/app/upgradev3"
leveragetypes "github.com/umee-network/umee/v3/x/leverage/types"
oracletypes "github.com/umee-network/umee/v3/x/oracle/types"
)
Expand All @@ -24,33 +23,33 @@ func (app UmeeApp) RegisterUpgradeHandlers() {
UpgradeV3_0Plan,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", UpgradeV3_0Plan)
err := setupBech32ibcKeeper(&app.bech32IbcKeeper, ctx)
ctx.Logger().Info("Running setupBech32ibcKeeper")
err := upgradev3.SetupBech32ibcKeeper(&app.bech32IbcKeeper, ctx)
if err != nil {
return nil, sdkerrors.Wrapf(
err, "Calypso %q Upgrade: Unable to upgrade, bech32ibc module not initialized", UpgradeV3_0Plan)
err, "%q Upgrade: Unable to upgrade, bech32ibc module not initialized", UpgradeV3_0Plan)
}

ctx.Logger().Info("Upgrade handler execution finished, running migrations", "name", UpgradeV3_0Plan)
ctx.Logger().Info("Running module migrations")
vm, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
if err != nil {
return vm, err
}

ctx.Logger().Info("Upgrade handler execution finished, updating minimum commission rate param of staking module",
"name", UpgradeV3_0Plan)
minCommissionRate, err := v3upgrades.UpdateMinimumCommissionRateParam(ctx, app.StakingKeeper)
ctx.Logger().Info("Updating validator minimum commission rate param of staking module")
minCommissionRate, err := upgradev3.UpdateMinimumCommissionRateParam(ctx, app.StakingKeeper)
if err != nil {
return vm, sdkerrors.Wrapf(
err, "Calypso %q Upgrade: Unable to upgrade, failed to update minimum commission rate param of staking module",
err, "%q Upgrade: failed to update minimum commission rate param of staking module",
UpgradeV3_0Plan)
}

ctx.Logger().Info("Upgrade handler execution finished, updating minimum commission rate of all validators",
"name", UpgradeV3_0Plan)
err = v3upgrades.SetMinimumCommissionRateToValidators(ctx, app.StakingKeeper, minCommissionRate)
err = upgradev3.SetMinimumCommissionRateToValidators(ctx, app.StakingKeeper, minCommissionRate)
if err != nil {
return vm, sdkerrors.Wrapf(
err, "Calypso %q Upgrade: Unable to upgrade, failed to update minimum commission rate for validators",
err, "%q Upgrade: failed to update minimum commission rate for validators",
UpgradeV3_0Plan)
}

Expand All @@ -68,6 +67,9 @@ func (app UmeeApp) RegisterUpgradeHandlers() {
group.ModuleName,
nft.ModuleName,
bech32ibctypes.ModuleName,
// icacontrollertypes.StoreKey,
// icahosttypes.StoreKey,

oracletypes.ModuleName,
leveragetypes.ModuleName,
},
Expand All @@ -77,10 +79,3 @@ func (app UmeeApp) RegisterUpgradeHandlers() {
upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

// Sets up bech32ibc module by setting the native account prefix to "umee".
// Failing to set the native prefix will cause a chain halt on init genesis or
// in the firstBeginBlocker assertions.
func setupBech32ibcKeeper(bech32IbcKeeper *bech32ibckeeper.Keeper, ctx sdk.Context) error {
return bech32IbcKeeper.SetNativeHrp(ctx, sdk.GetConfig().GetBech32AccountAddrPrefix())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v3
package upgradev3

import (
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package v3
package upgradev3

import (
sdk "github.com/cosmos/cosmos-sdk/types"
bech32ibckeeper "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/keeper"
)

var minCommissionRate = sdk.MustNewDecFromStr("0.05")
Expand Down Expand Up @@ -37,3 +38,10 @@ func SetMinimumCommissionRateToValidators(ctx sdk.Context, keeper StakingKeeper,

return nil
}

// SetupBech32ibcKeeper updates keeper by setting the native account prefix to "umee".
// Failing to set the native prefix will cause a chain halt on init genesis or
// in the firstBeginBlocker assertions.
func SetupBech32ibcKeeper(bech32IbcKeeper *bech32ibckeeper.Keeper, ctx sdk.Context) error {
return bech32IbcKeeper.SetNativeHrp(ctx, sdk.GetConfig().GetBech32AccountAddrPrefix())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v3
package upgradev3

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v3
package upgradev3

import (
"crypto/rand"
Expand Down