diff --git a/x/compute/internal/keeper/handler_plugin.go b/x/compute/internal/keeper/handler_plugin.go index 4508f7b29..f3268b896 100644 --- a/x/compute/internal/keeper/handler_plugin.go +++ b/x/compute/internal/keeper/handler_plugin.go @@ -610,21 +610,6 @@ func (h SDKMessageHandler) handleSdkMessage(ctx sdk.Context, contractAddr sdk.Ad return nil, sdkerrors.ErrUnknownRequest.Wrapf("can't route message %+v", msg) } -// callDepthMessageHandler is a wrapper around a Messenger that checks the call depth before dispatching a message. -type callDepthMessageHandler struct { - Messenger - MaxCallDepth uint32 -} - -func (h callDepthMessageHandler) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg v1wasmTypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error) { - ctx, err = checkAndIncreaseCallDepth(ctx, h.MaxCallDepth) - if err != nil { - return nil, nil, err - } - - return h.Messenger.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg) -} - // convertWasmIBCTimeoutHeightToCosmosHeight converts a wasm type ibc timeout height to ibc module type height func convertWasmIBCTimeoutHeightToCosmosHeight(ibcTimeoutBlock *v1wasmTypes.IBCTimeoutBlock) ibcclienttypes.Height { if ibcTimeoutBlock == nil { diff --git a/x/compute/internal/keeper/keeper.go b/x/compute/internal/keeper/keeper.go index 2df0d1f6e..7c2cf5e02 100644 --- a/x/compute/internal/keeper/keeper.go +++ b/x/compute/internal/keeper/keeper.go @@ -165,8 +165,6 @@ func NewKeeper( LastMsgManager: lastMsgManager, authority: authority, } - // always wrap the messenger, even if it was replaced by an option - keeper.messenger = callDepthMessageHandler{keeper.messenger, keeper.maxCallDepth} keeper.queryPlugins = DefaultQueryPlugins(govKeeper, distKeeper, mintKeeper, bankKeeper, stakingKeeper, queryRouter, &keeper, channelKeeper).Merge(customPlugins) return keeper @@ -1476,6 +1474,11 @@ func (k *Keeper) handleContractResponse( } responseHandler := NewContractResponseHandler(NewMessageDispatcher(k.messenger, k)) + // keep track of call depth + ctx, err := checkAndIncreaseCallDepth(ctx, k.maxCallDepth) + if err != nil { + return nil, err + } return responseHandler.Handle(ctx, contractAddr, ibcPort, msgs, data, ogTx, ogSigInfo) } diff --git a/x/compute/internal/types/types.go b/x/compute/internal/types/types.go index 0d5ca9276..2a6f0478a 100644 --- a/x/compute/internal/types/types.go +++ b/x/compute/internal/types/types.go @@ -17,7 +17,7 @@ import ( ) const ( - DefaultMaxCallDepth = uint32(500) + DefaultMaxCallDepth = uint32(100) defaultLRUCacheSize = uint64(0) defaultEnclaveLRUCacheSize = uint16(100) defaultQueryGasLimit = uint64(10_000_000)