Skip to content

Commit

Permalink
feat: update gravity bridge to v1.5.0 + upgrade handler for Calypso (…
Browse files Browse the repository at this point in the history
…v2.0.0) (#729)

## Description

- Upgrade to Gravity Bridge v1.5.0
- Add upgrade handlers to do the Calypso update (Leverage and oracle modules)
- While I was at it I added the option to run tests with Ganache instead of geth, pretty helpful when running on Mac M1

----

### 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 appropriate labels to the PR
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] 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 `!` in the type prefix if API or client breaking change
- [ ] 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
facundomedica authored Apr 4, 2022
1 parent 14011e9 commit 3b596e0
Show file tree
Hide file tree
Showing 19 changed files with 409 additions and 1,238 deletions.
139 changes: 101 additions & 38 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"os"
"path/filepath"

gravity "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity"
gravitykeeper "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/keeper"
gravitytypes "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand All @@ -15,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -88,12 +92,14 @@ import (
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"
gravity "github.com/umee-network/Gravity-Bridge/module/x/gravity"
gravitykeeper "github.com/umee-network/Gravity-Bridge/module/x/gravity/keeper"
gravitytypes "github.com/umee-network/Gravity-Bridge/module/x/gravity/types"

"github.com/osmosis-labs/bech32-ibc/x/bech32ibc"
bech32ibckeeper "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/keeper"
bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types"
customante "github.com/umee-network/umee/ante"
appparams "github.com/umee-network/umee/app/params"
"github.com/umee-network/umee/app/upgrades"
"github.com/umee-network/umee/app/upgrades/calypso"
uibctransfer "github.com/umee-network/umee/x/ibctransfer"
uibctransferkeeper "github.com/umee-network/umee/x/ibctransfer/keeper"
"github.com/umee-network/umee/x/leverage"
Expand Down Expand Up @@ -154,6 +160,7 @@ var (
gravity.AppModuleBasic{},
leverage.AppModuleBasic{},
oracle.AppModuleBasic{},
bech32ibc.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -222,6 +229,7 @@ type UmeeApp struct {
GravityKeeper gravitykeeper.Keeper
LeverageKeeper leveragekeeper.Keeper
OracleKeeper oraclekeeper.Keeper
bech32IbcKeeper bech32ibckeeper.Keeper

// make scoped keepers public for testing purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand All @@ -232,6 +240,9 @@ type UmeeApp struct {

// simulation manager
sm *module.SimulationManager

// configurator
configurator *module.Configurator
}

func New(
Expand All @@ -246,7 +257,6 @@ func New(
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *UmeeApp {

appCodec := encodingConfig.Marshaler
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand All @@ -261,7 +271,7 @@ func New(
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, gravitytypes.StoreKey,
leveragetypes.StoreKey, oracletypes.StoreKey,
leveragetypes.StoreKey, oracletypes.StoreKey, bech32ibctypes.StoreKey,
)
transientKeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -329,18 +339,19 @@ func New(
app.GetSubspace(banktypes.ModuleName),
app.ModuleAccountAddrs(),
)
stakingKeeper := stakingkeeper.NewKeeper(
app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
)

app.MintKeeper = mintkeeper.NewKeeper(
appCodec,
keys[minttypes.StoreKey],
app.GetSubspace(minttypes.ModuleName),
&stakingKeeper,
&app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
Expand All @@ -351,14 +362,14 @@ func New(
app.GetSubspace(distrtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
&stakingKeeper,
&app.StakingKeeper,
authtypes.FeeCollectorName,
app.ModuleAccountAddrs(),
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
keys[slashingtypes.StoreKey],
&stakingKeeper,
&app.StakingKeeper,
app.GetSubspace(slashingtypes.ModuleName),
)
app.CrisisKeeper = crisiskeeper.NewKeeper(
Expand All @@ -381,7 +392,7 @@ func New(
app.AccountKeeper,
app.BankKeeper,
app.DistrKeeper,
&stakingKeeper,
&app.StakingKeeper,
distrtypes.ModuleName,
)
app.LeverageKeeper = leveragekeeper.NewKeeper(
Expand All @@ -397,30 +408,6 @@ func New(
),
)

baseBankKeeper := app.BankKeeper.(bankkeeper.BaseKeeper)
app.GravityKeeper = gravitykeeper.NewKeeper(
keys[gravitytypes.StoreKey],
app.GetSubspace(gravitytypes.ModuleName),
appCodec,
&baseBankKeeper,
&stakingKeeper,
&app.SlashingKeeper,
&app.DistrKeeper,
&app.AccountKeeper,
)

// register the staking hooks
//
// NOTE: The stakingKeeper above is passed by reference, so that it will contain
// these hooks.
app.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.GravityKeeper.Hooks(),
),
)

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibchost.StoreKey],
Expand All @@ -445,6 +432,38 @@ func New(
app.TransferKeeper = uibctransferkeeper.New(ibcTransferKeeper, app.BankKeeper)
transferModule := uibctransfer.NewAppModule(ibctransfer.NewAppModule(ibcTransferKeeper), app.TransferKeeper)

baseBankKeeper := app.BankKeeper.(bankkeeper.BaseKeeper)

app.bech32IbcKeeper = *bech32ibckeeper.NewKeeper(
app.IBCKeeper.ChannelKeeper, appCodec, keys[bech32ibctypes.StoreKey],
app.TransferKeeper,
)

app.GravityKeeper = gravitykeeper.NewKeeper(
keys[gravitytypes.StoreKey],
app.GetSubspace(gravitytypes.ModuleName),
appCodec,
&baseBankKeeper,
&app.StakingKeeper,
&app.SlashingKeeper,
&app.DistrKeeper,
&app.AccountKeeper,
&app.TransferKeeper.Keeper,
&app.bech32IbcKeeper,
)

// register the staking hooks
//
// NOTE: The stakingKeeper above is passed by reference, so that it will contain
// these hooks.
app.StakingKeeper = *app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.GravityKeeper.Hooks(),
),
)

// create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
Expand All @@ -459,7 +478,8 @@ func New(
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(leveragetypes.RouterKey, leverage.NewUpdateRegistryProposalHandler(app.LeverageKeeper)).
AddRoute(gravitytypes.RouterKey, gravitykeeper.NewGravityProposalHandler(app.GravityKeeper))
AddRoute(gravitytypes.RouterKey, gravitykeeper.NewGravityProposalHandler(app.GravityKeeper)).
AddRoute(bech32ibctypes.RouterKey, bech32ibc.NewBech32IBCProposalHandler(app.bech32IbcKeeper))

// Create evidence Keeper so we can register the IBC light client misbehavior
// evidence route.
Expand All @@ -477,12 +497,14 @@ func New(
app.GetSubspace(govtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
&stakingKeeper,
&app.StakingKeeper,
govRouter,
)

skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))

app.registerStoreLoaders()

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.mm = module.NewManager(
Expand Down Expand Up @@ -512,6 +534,7 @@ func New(
gravity.NewAppModule(app.GravityKeeper, app.BankKeeper),
leverage.NewAppModule(appCodec, app.LeverageKeeper, app.AccountKeeper, app.BankKeeper),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
bech32ibc.NewAppModule(appCodec, app.bech32IbcKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that there
Expand Down Expand Up @@ -541,6 +564,7 @@ func New(
leveragetypes.ModuleName,
oracletypes.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand All @@ -565,6 +589,7 @@ func New(
authz.ModuleName,
stakingtypes.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -595,11 +620,14 @@ func New(
oracletypes.ModuleName,
leveragetypes.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.mm.RegisterServices(module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()))
configurator := module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.configurator = &configurator
app.mm.RegisterServices(*app.configurator)

// Create the simulation manager and define the order of the modules for
// deterministic simulations.
Expand Down Expand Up @@ -649,6 +677,11 @@ func New(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

upgrades.RegisterUpgradeHandlers(
app.mm, app.configurator, &app.AccountKeeper, &baseBankKeeper, &app.bech32IbcKeeper, &app.DistrKeeper,
&app.MintKeeper, &app.StakingKeeper, &app.UpgradeKeeper, &app.LeverageKeeper, &app.OracleKeeper,
)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(fmt.Sprintf("failed to load latest version: %s", err))
Expand All @@ -658,6 +691,37 @@ func New(
return app
}

// Sets up the StoreLoader for new, deleted, or renamed modules
func (app *UmeeApp) registerStoreLoaders() {
// Read the upgrade height and name from previous execution
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

// v1->Calypso STORE LOADER SETUP
// Register the new Calypso modules and the special StoreLoader to add them
if upgradeInfo.Name == calypso.PlanName {
if !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { // Recognized the plan, need to skip this one though
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
bech32ibctypes.ModuleName,
oracletypes.ModuleName,
leveragetypes.ModuleName,
}, // We are adding these modules
Renamed: nil,
Deleted: nil,
}

// configure store loader that checks if version == upgradeHeight and applies
// store upgrades
app.SetStoreLoader(
upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades),
)
}
}
}

// Name returns the name of the Umee network.
func (app *UmeeApp) Name() string {
return app.BaseApp.Name()
Expand Down Expand Up @@ -828,7 +892,6 @@ func initParamsKeeper(
legacyAmino *codec.LegacyAmino,
key, tkey sdk.StoreKey,
) paramskeeper.Keeper {

paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
Expand Down
2 changes: 1 addition & 1 deletion app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

gravitytypes "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -22,7 +23,6 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
gravitytypes "github.com/umee-network/Gravity-Bridge/module/x/gravity/types"
)

// BankModule defines a custom wrapper around the x/bank module's AppModuleBasic
Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/calypso/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package calypso

var PlanName = "calypso"
Loading

0 comments on commit 3b596e0

Please sign in to comment.