Skip to content

Commit

Permalink
feat: ibc ante handlers and upgrade cleanup (#1441)
Browse files Browse the repository at this point in the history
## Description

streamming down #1425 changes.

---

### Author Checklist

_All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] added appropriate labels to the PR
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

_All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items._

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
robert-zaremba authored Sep 21, 2022
1 parent 421da96 commit c54d166
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
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

0 comments on commit c54d166

Please sign in to comment.