Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit error event at hook failed #48

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions app/ibc-hooks/ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

ibchooks "github.com/initia-labs/initia/x/ibc-hooks"
"github.com/initia-labs/initia/x/ibc-hooks/types"
nfttransfertypes "github.com/initia-labs/initia/x/ibc/nft-transfer/types"
)

Expand All @@ -30,6 +31,12 @@ func (h WasmHooks) onAckIcs20Packet(
return nil
} else if err != nil {
h.wasmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to parse memo"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
}

Expand All @@ -40,9 +47,21 @@ func (h WasmHooks) onAckIcs20Packet(
callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
} else if !allowed {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
))

return nil
}

Expand All @@ -69,6 +88,12 @@ func (h WasmHooks) onAckIcs20Packet(
packet.SourceChannel, packet.Sequence, ackAsJson, success))
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
if err != nil {
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return errorsmod.Wrap(err, "Ack callback error")
}

Expand All @@ -94,6 +119,12 @@ func (h WasmHooks) onAckIcs721Packet(
if !isWasmRouted || hookData.AsyncCallback == "" {
return nil
} else if err != nil {
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to parse memo"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

h.wasmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
return nil
}
Expand All @@ -105,9 +136,21 @@ func (h WasmHooks) onAckIcs721Packet(
callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
} else if !allowed {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
))

return nil
}

Expand All @@ -134,6 +177,12 @@ func (h WasmHooks) onAckIcs721Packet(
packet.SourceChannel, packet.Sequence, ackAsJson, success))
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
if err != nil {
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

h.wasmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
return nil
}
Expand Down
37 changes: 37 additions & 0 deletions app/ibc-hooks/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

ibchooks "github.com/initia-labs/initia/x/ibc-hooks"
"github.com/initia-labs/initia/x/ibc-hooks/types"
nfttransfertypes "github.com/initia-labs/initia/x/ibc/nft-transfer/types"
)

Expand Down Expand Up @@ -37,9 +38,21 @@ func (h WasmHooks) onTimeoutIcs20Packet(
callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
} else if !allowed {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
))

return nil
}

Expand All @@ -55,6 +68,12 @@ func (h WasmHooks) onTimeoutIcs20Packet(
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
if err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
}

Expand Down Expand Up @@ -90,9 +109,21 @@ func (h WasmHooks) onTimeoutIcs721Packet(
callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
} else if !allowed {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
))

return nil
}

Expand All @@ -108,6 +139,12 @@ func (h WasmHooks) onTimeoutIcs721Packet(
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
if err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
}

Expand Down
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
toolchain go1.22.2

require (
cosmossdk.io/api v0.7.4
cosmossdk.io/api v0.7.5
cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79
cosmossdk.io/collections v0.4.0
cosmossdk.io/core v0.11.0
Expand All @@ -23,7 +23,7 @@ require (
github.com/cometbft/cometbft v0.38.7
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.6
github.com/cosmos/cosmos-sdk v0.50.7-0.20240517114248-b99ca2c1fded
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.12
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2
Expand All @@ -34,8 +34,8 @@ require (
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hashicorp/go-metrics v0.5.3
github.com/initia-labs/OPinit v0.3.1
github.com/initia-labs/initia v0.3.2
github.com/initia-labs/OPinit v0.3.2
github.com/initia-labs/initia v0.3.3
github.com/initia-labs/kvindexer v0.1.3
github.com/initia-labs/kvindexer/submodules/block v0.1.0
github.com/initia-labs/kvindexer/submodules/tx v0.1.0
Expand Down Expand Up @@ -249,6 +249,10 @@ replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0

// Use latest iavl version to fix following issue:
// https://github.com/cosmos/iavl/pull/943
github.com/cosmos/iavl => github.com/cosmos/iavl v1.1.4

// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
Expand All @@ -266,6 +270,5 @@ replace (
replace (
github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240621094738-408dc5262680
github.com/cosmos/cosmos-sdk => github.com/initia-labs/cosmos-sdk v0.0.0-20240502043911-a4bdb8e06769
github.com/cosmos/iavl => github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e
github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX
cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg=
cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
cosmossdk.io/api v0.7.4 h1:sPo8wKwCty1lht8kgL3J7YL1voJywP3YWuA5JKkBz30=
cosmossdk.io/api v0.7.4/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ=
cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79 h1:Hr1t0fCq1nbFC7hLs0Xvy9WAiH7Iti5iVLXMM5C37F0=
cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79/go.mod h1:8pN6LSVReNnIxrC2QGcvuIJ/m1pJN6FNYn2kAYtYftI=
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
Expand Down Expand Up @@ -406,6 +406,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ
github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU=
github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8JpFE=
github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY=
github.com/cosmos/iavl v1.1.4 h1:Z0cVVjeQqOUp78/nWt/uhQy83vYluWlAMGQ4zbH9G34=
github.com/cosmos/iavl v1.1.4/go.mod h1:vCYmRQUJU1wwj0oRD3wMEtOM9sJNDP+GFMaXmIxZ/rU=
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2 h1:dyLNlDElY6+5zW/BT/dO/3Ad9FpQblfh+9dQpYQodbA=
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2/go.mod h1:82hPO/tRawbuFad2gPwChvpZ0JEIoNi91LwVneAYCeM=
github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo8ci1mVZNO9+V0xsLE=
Expand Down Expand Up @@ -792,20 +794,18 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/initia-labs/OPinit v0.3.1 h1:uffngNx8a7hQl3ENhVbdSAJ8j5MYksiaiCLVI6xunjA=
github.com/initia-labs/OPinit v0.3.1/go.mod h1:pHU2472uQZpiKXBOa/D7/aDYn0gtTiddKvhloyliOQU=
github.com/initia-labs/OPinit v0.3.2 h1:TeELD5GeSJJ9meY5b5YIXDdmCZt9kZOA2Chz+IwxUHc=
github.com/initia-labs/OPinit v0.3.2/go.mod h1:XlYsBFAKOFS6/wRIHB1vVbfonqX8QrC8cWK2GJvmX20=
github.com/initia-labs/OPinit/api v0.3.0 h1:OY8ijwmgZLoYwtw9LI1mSY3VC8PY+gtxJFitB6ZNFl4=
github.com/initia-labs/OPinit/api v0.3.0/go.mod h1:Xy/Nt3ubXLQ4zKn0m7RuQOM1sj8TVdlNNyek21TGYR0=
github.com/initia-labs/cometbft v0.0.0-20240621094738-408dc5262680 h1:4tcP5F26DdqiV1Y/XOllL4LUhyUV6HITfjVJnzR/Krs=
github.com/initia-labs/cometbft v0.0.0-20240621094738-408dc5262680/go.mod h1:qGaJePRWAc2OL3OGNd//8fqgypCaFjmwZcy/cNner84=
github.com/initia-labs/cosmos-sdk v0.0.0-20240502043911-a4bdb8e06769 h1:R+cOwxp14K9+UAJ7MI4YyqXSL+Fm8W+wTBbXL315EMA=
github.com/initia-labs/cosmos-sdk v0.0.0-20240502043911-a4bdb8e06769/go.mod h1:lVkRY6cdMJ0fG3gp8y4hFrsKZqF4z7y0M2UXFb9Yt40=
github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e h1:1gkMWkAgVhYFhEv7K4tX+8uJJLdiTKlQhl5+wGaxdMg=
github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM=
github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c h1:FDwh5zZbm9v7C37ni4FytQQ9Os5XxYp1px5U7Nqdu2Y=
github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/initia-labs/initia v0.3.2 h1:nvVCgUiiDxDcFdC+ordooSlqUHXR8mFGDvCgwptTaAg=
github.com/initia-labs/initia v0.3.2/go.mod h1:CXKYIajY7mj7EogHO1VcgaXnKZFpeRfSc0KxbqbxWjY=
github.com/initia-labs/initia v0.3.3 h1:82ZkXki6CG+F+rPDBVpTzzSQY8NalXIZ0LnYSWNd+3U=
github.com/initia-labs/initia v0.3.3/go.mod h1:1yWifo9GnhIvwDtCTTN6kb2mfq2On+oel6ha/rBXaQQ=
github.com/initia-labs/kvindexer v0.1.3 h1:TLkgJjp5TiPnH+OzYfk7ZKQTKqGOfSte59Y3gasob+o=
github.com/initia-labs/kvindexer v0.1.3/go.mod h1:rvAmgCAmEs4KM8sRRPcyTqNNwi8s2JiHybiFkYfp4KE=
github.com/initia-labs/kvindexer/submodules/block v0.1.0 h1:y+EXnksd/I2F96mzIoQA64nZUZON2P+99YrSzeLCLoY=
Expand All @@ -816,8 +816,8 @@ github.com/initia-labs/kvindexer/submodules/wasm-nft v0.1.3 h1:diSQs+zWNj0U5tdDS
github.com/initia-labs/kvindexer/submodules/wasm-nft v0.1.3/go.mod h1:1HD0/oH6kErv8F0J5ayGfLqerWSCPveGHSCbcfiBELw=
github.com/initia-labs/kvindexer/submodules/wasm-pair v0.1.0 h1:Ns7bxZkwdby67aIq3VXFAzlpoLdGONJbDaMiqu6k408=
github.com/initia-labs/kvindexer/submodules/wasm-pair v0.1.0/go.mod h1:SEotHE6mJ3VKr9g4j0AoXHgEYz6qhL3i1bX1QRnVT6g=
github.com/initia-labs/movevm v0.3.1 h1:vydw0mdqsLyPN9W2DVq1/gDXDR3snbr6c4Wy/sTYVxY=
github.com/initia-labs/movevm v0.3.1/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30=
github.com/initia-labs/movevm v0.3.3 h1:xUH5VvjBSfJP4jg3axefmBlcdZ/7qfVYnUU09R4oN4g=
github.com/initia-labs/movevm v0.3.3/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls=
Expand Down
Loading