Skip to content

Commit

Permalink
Set default ibc params, prevent panic in ExportGenesis
Browse files Browse the repository at this point in the history
  • Loading branch information
iverc committed Nov 21, 2024
1 parent 4fa4d53 commit 2bae9aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
18 changes: 5 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,10 @@ func New(
// must be set manually as follow. The upgrade module will de-duplicate the module version map.
//
initChainer := func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {

// TODO: Is there a cleaner way to update the denom without having to unmarshal and marshal the genesis state?
// At the time of validator being created, the denom is still the old one if we just set the params here:
//
// stakingParams := app.StakingKeeper.GetParams(ctx)
// stakingParams.BondDenom = BondDenom
// app.StakingKeeper.SetParams(ctx, stakingParams)
//
// The above approach doesn't work because the params need to be set before InitGenesis runs.
// Hence, we need to update the genesis state directly.
// Temp workaround to set default IBC params until app wiring is fully supported.
if req.InitialHeight == 1 {
app.setDefaultIBCParams(ctx)
}

var genesisState GenesisState
err := json.Unmarshal(req.AppStateBytes, &genesisState)
Expand All @@ -376,8 +370,8 @@ func New(
}

return app.App.InitChainer(ctx, req)

}

app.SetInitChainer(initChainer)

if err := app.Load(loadLatest); err != nil {
Expand Down Expand Up @@ -418,7 +412,6 @@ func (app *App) GetMemKey(storeKey string) *storetypes.MemoryStoreKey {
if !ok {
return nil
}

return key
}

Expand All @@ -430,7 +423,6 @@ func (app *App) kvStoreKeys() map[string]*storetypes.KVStoreKey {
keys[kv.Name()] = kv
}
}

return keys
}

Expand Down
15 changes: 15 additions & 0 deletions app/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"cosmossdk.io/core/appmodule"
storetypes "cosmossdk.io/store/types"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
Expand All @@ -28,6 +29,7 @@ import (
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
Expand Down Expand Up @@ -179,6 +181,19 @@ func (app *App) registerIBCModules() {
}
}

// setDefaultIBCParams is used to set default IBC params until app wiring is fully supported.
func (app *App) setDefaultIBCParams(ctx sdk.Context) {
app.IBCKeeper.ClientKeeper.SetNextClientSequence(ctx, 0)
app.IBCKeeper.ConnectionKeeper.SetNextConnectionSequence(ctx, 0)
app.IBCKeeper.ChannelKeeper.SetNextChannelSequence(ctx, 0)
app.IBCKeeper.ClientKeeper.SetParams(ctx, ibcclienttypes.DefaultParams())
app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())
app.IBCKeeper.ChannelKeeper.SetParams(ctx, ibcchanneltypes.DefaultParams())
app.ICAControllerKeeper.SetParams(ctx, icacontrollertypes.DefaultParams())
app.ICAHostKeeper.SetParams(ctx, icahosttypes.DefaultParams())
app.TransferKeeper.SetParams(ctx, ibctransfertypes.DefaultParams())
}

// Since the IBC modules don't support dependency injection, we need to
// manually register the modules on the client side.
// This needs to be removed after IBC supports App Wiring.
Expand Down

0 comments on commit 2bae9aa

Please sign in to comment.