Skip to content

Commit

Permalink
fix: do not load corresponding stores if wasm or wasm hooks are disab…
Browse files Browse the repository at this point in the history
…led (#2097)

(cherry picked from commit 657bc5a)
  • Loading branch information
cgorenflo committed Feb 3, 2024
1 parent 179cf50 commit 0a75f20
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
38 changes: 24 additions & 14 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ func NewAxelarApp(
// BaseApp handles interactions with Tendermint through the ABCI protocol
bApp := initBaseApp(db, traceStore, encodingConfig, keepers, baseAppOptions, logger)

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig := mustReadWasmConfig(appOpts)
appCodec := encodingConfig.Codec
moduleAccountPermissions := initModuleAccountPermissions()

Expand Down Expand Up @@ -255,12 +253,15 @@ func NewAxelarApp(
setKeeper(keepers, initIBCTransferKeeper(appCodec, keys, keepers, ics4Wrapper))

setKeeper(keepers, initAxelarIBCKeeper(keepers))
setKeeper(keepers, initWasmKeeper(encodingConfig, keys, keepers, bApp, wasmDir, wasmConfig, wasmOpts))
setKeeper(keepers, initWasmContractKeeper(keepers))

// set the contract keeper for the Ics20WasmHooks
if wasmHooks != nil {
wasmHooks.ContractKeeper = getKeeper[wasmkeeper.PermissionedKeeper](keepers)
if IsWasmEnabled() {
setKeeper(keepers, initWasmKeeper(encodingConfig, keys, keepers, bApp, appOpts, wasmOpts, homePath))
setKeeper(keepers, initWasmContractKeeper(keepers))

// set the contract keeper for the Ics20WasmHooks
if wasmHooks != nil {
wasmHooks.ContractKeeper = getKeeper[wasmkeeper.PermissionedKeeper](keepers)
}
}

// set up governance keeper last when it has access to all other keepers to set up governance routes
Expand Down Expand Up @@ -335,7 +336,7 @@ func NewAxelarApp(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

app.SetAnteHandler(initAnteHandlers(encodingConfig, keys, keepers, wasmConfig))
app.SetAnteHandler(initAnteHandlers(encodingConfig, keys, keepers, appOpts))

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand Down Expand Up @@ -397,7 +398,7 @@ func initWasmHooks(keys map[string]*sdk.KVStoreKey) *ibchooks.WasmHooks {
ibcHooksKeeper := ibchookskeeper.NewKeeper(keys[ibchookstypes.StoreKey])

// The contract keeper needs to be set later
var wasmHooks ibchooks.WasmHooks = ibchooks.NewWasmHooks(&ibcHooksKeeper, nil, sdk.GetConfig().GetBech32AccountAddrPrefix())
var wasmHooks = ibchooks.NewWasmHooks(&ibcHooksKeeper, nil, sdk.GetConfig().GetBech32AccountAddrPrefix())
return &wasmHooks
}

Expand Down Expand Up @@ -592,7 +593,7 @@ func mustReadWasmConfig(appOpts servertypes.AppOptions) wasmtypes.WasmConfig {
return wasmConfig
}

func initAnteHandlers(encodingConfig axelarParams.EncodingConfig, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, wasmConfig wasmtypes.WasmConfig) sdk.AnteHandler {
func initAnteHandlers(encodingConfig axelarParams.EncodingConfig, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, appOpts servertypes.AppOptions) sdk.AnteHandler {
// The baseAnteHandler handles signature verification and transaction pre-processing
baseAnteHandler, err := authAnte.NewAnteHandler(
authAnte.HandlerOptions{
Expand All @@ -613,6 +614,7 @@ func initAnteHandlers(encodingConfig axelarParams.EncodingConfig, keys map[strin

// enforce wasm limits earlier in the ante handler chain
if IsWasmEnabled() {
wasmConfig := mustReadWasmConfig(appOpts)
wasmAnteDecorators := []sdk.AnteDecorator{
wasmkeeper.NewLimitSimulationGasDecorator(wasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(keys[wasm.StoreKey]),
Expand Down Expand Up @@ -859,7 +861,7 @@ func orderModulesForGenesis() []string {
}

func createStoreKeys() map[string]*sdk.KVStoreKey {
return sdk.NewKVStoreKeys(authtypes.StoreKey,
keys := []string{authtypes.StoreKey,
banktypes.StoreKey,
stakingtypes.StoreKey,
minttypes.StoreKey,
Expand All @@ -873,8 +875,6 @@ func createStoreKeys() map[string]*sdk.KVStoreKey {
ibctransfertypes.StoreKey,
capabilitytypes.StoreKey,
feegrant.StoreKey,
wasm.StoreKey,
ibchookstypes.StoreKey,
voteTypes.StoreKey,
evmTypes.StoreKey,
snapTypes.StoreKey,
Expand All @@ -883,7 +883,17 @@ func createStoreKeys() map[string]*sdk.KVStoreKey {
nexusTypes.StoreKey,
axelarnetTypes.StoreKey,
rewardTypes.StoreKey,
permissionTypes.StoreKey)
permissionTypes.StoreKey}

if IsWasmEnabled() {
keys = append(keys, wasm.StoreKey)
}

if IsIBCWasmHooksEnabled() {
keys = append(keys, ibchookstypes.StoreKey)
}

return sdk.NewKVStoreKeys(keys...)
}

// GenesisState represents chain state at the start of the chain. Any initial state (account balances) are stored here.
Expand Down
8 changes: 6 additions & 2 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package app

import (
"fmt"
"path/filepath"
"reflect"
"strings"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -161,7 +162,10 @@ func initStakingKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, ke
return &stakingK
}

func initWasmKeeper(encodingConfig axelarParams.EncodingConfig, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, bApp *bam.BaseApp, wasmDir string, wasmConfig wasmtypes.WasmConfig, wasmOpts []wasm.Option) *wasm.Keeper {
func initWasmKeeper(encodingConfig axelarParams.EncodingConfig, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, bApp *bam.BaseApp, appOpts types.AppOptions, wasmOpts []wasm.Option, homePath string) *wasm.Keeper {
wasmDir := filepath.Join(homePath, "wasm")
wasmConfig := mustReadWasmConfig(appOpts)

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
wasmOpts = append(wasmOpts, wasmkeeper.WithMessageHandlerDecorator(
Expand Down

0 comments on commit 0a75f20

Please sign in to comment.