Skip to content

Commit 5d1a5f2

Browse files
authored
Merge pull request #48 from initia-labs/feat/emit-error-event-at-hook-failed
feat: emit error event at hook failed
2 parents 7fd0b5e + 372200f commit 5d1a5f2

File tree

4 files changed

+104
-15
lines changed

4 files changed

+104
-15
lines changed

app/ibc-hooks/ack.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
1111

1212
ibchooks "github.com/initia-labs/initia/x/ibc-hooks"
13+
"github.com/initia-labs/initia/x/ibc-hooks/types"
1314
nfttransfertypes "github.com/initia-labs/initia/x/ibc/nft-transfer/types"
1415
)
1516

@@ -30,6 +31,12 @@ func (h WasmHooks) onAckIcs20Packet(
3031
return nil
3132
} else if err != nil {
3233
h.wasmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
34+
ctx.EventManager().EmitEvent(sdk.NewEvent(
35+
types.EventTypeHookFailed,
36+
sdk.NewAttribute(types.AttributeKeyReason, "failed to parse memo"),
37+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
38+
))
39+
3340
return nil
3441
}
3542

@@ -40,9 +47,21 @@ func (h WasmHooks) onAckIcs20Packet(
4047
callback := hookData.AsyncCallback
4148
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
4249
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
50+
ctx.EventManager().EmitEvent(sdk.NewEvent(
51+
types.EventTypeHookFailed,
52+
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
53+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
54+
))
55+
4356
return nil
4457
} else if !allowed {
4558
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
59+
ctx.EventManager().EmitEvent(sdk.NewEvent(
60+
types.EventTypeHookFailed,
61+
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
62+
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
63+
))
64+
4665
return nil
4766
}
4867

@@ -69,6 +88,12 @@ func (h WasmHooks) onAckIcs20Packet(
6988
packet.SourceChannel, packet.Sequence, ackAsJson, success))
7089
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
7190
if err != nil {
91+
ctx.EventManager().EmitEvent(sdk.NewEvent(
92+
types.EventTypeHookFailed,
93+
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
94+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
95+
))
96+
7297
return errorsmod.Wrap(err, "Ack callback error")
7398
}
7499

@@ -94,6 +119,12 @@ func (h WasmHooks) onAckIcs721Packet(
94119
if !isWasmRouted || hookData.AsyncCallback == "" {
95120
return nil
96121
} else if err != nil {
122+
ctx.EventManager().EmitEvent(sdk.NewEvent(
123+
types.EventTypeHookFailed,
124+
sdk.NewAttribute(types.AttributeKeyReason, "failed to parse memo"),
125+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
126+
))
127+
97128
h.wasmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
98129
return nil
99130
}
@@ -105,9 +136,21 @@ func (h WasmHooks) onAckIcs721Packet(
105136
callback := hookData.AsyncCallback
106137
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
107138
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
139+
ctx.EventManager().EmitEvent(sdk.NewEvent(
140+
types.EventTypeHookFailed,
141+
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
142+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
143+
))
144+
108145
return nil
109146
} else if !allowed {
110147
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
148+
ctx.EventManager().EmitEvent(sdk.NewEvent(
149+
types.EventTypeHookFailed,
150+
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
151+
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
152+
))
153+
111154
return nil
112155
}
113156

@@ -134,6 +177,12 @@ func (h WasmHooks) onAckIcs721Packet(
134177
packet.SourceChannel, packet.Sequence, ackAsJson, success))
135178
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
136179
if err != nil {
180+
ctx.EventManager().EmitEvent(sdk.NewEvent(
181+
types.EventTypeHookFailed,
182+
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
183+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
184+
))
185+
137186
h.wasmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
138187
return nil
139188
}

app/ibc-hooks/timeout.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
99

1010
ibchooks "github.com/initia-labs/initia/x/ibc-hooks"
11+
"github.com/initia-labs/initia/x/ibc-hooks/types"
1112
nfttransfertypes "github.com/initia-labs/initia/x/ibc/nft-transfer/types"
1213
)
1314

@@ -37,9 +38,21 @@ func (h WasmHooks) onTimeoutIcs20Packet(
3738
callback := hookData.AsyncCallback
3839
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
3940
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
41+
ctx.EventManager().EmitEvent(sdk.NewEvent(
42+
types.EventTypeHookFailed,
43+
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
44+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
45+
))
46+
4047
return nil
4148
} else if !allowed {
4249
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
50+
ctx.EventManager().EmitEvent(sdk.NewEvent(
51+
types.EventTypeHookFailed,
52+
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
53+
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
54+
))
55+
4356
return nil
4457
}
4558

@@ -55,6 +68,12 @@ func (h WasmHooks) onTimeoutIcs20Packet(
5568
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
5669
if err != nil {
5770
h.wasmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
71+
ctx.EventManager().EmitEvent(sdk.NewEvent(
72+
types.EventTypeHookFailed,
73+
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
74+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
75+
))
76+
5877
return nil
5978
}
6079

@@ -90,9 +109,21 @@ func (h WasmHooks) onTimeoutIcs721Packet(
90109
callback := hookData.AsyncCallback
91110
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
92111
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
112+
ctx.EventManager().EmitEvent(sdk.NewEvent(
113+
types.EventTypeHookFailed,
114+
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
115+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
116+
))
117+
93118
return nil
94119
} else if !allowed {
95120
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
121+
ctx.EventManager().EmitEvent(sdk.NewEvent(
122+
types.EventTypeHookFailed,
123+
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
124+
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
125+
))
126+
96127
return nil
97128
}
98129

@@ -108,6 +139,12 @@ func (h WasmHooks) onTimeoutIcs721Packet(
108139
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
109140
if err != nil {
110141
h.wasmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
142+
ctx.EventManager().EmitEvent(sdk.NewEvent(
143+
types.EventTypeHookFailed,
144+
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
145+
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
146+
))
147+
111148
return nil
112149
}
113150

go.mod

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22
55
toolchain go1.22.2
66

77
require (
8-
cosmossdk.io/api v0.7.4
8+
cosmossdk.io/api v0.7.5
99
cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79
1010
cosmossdk.io/collections v0.4.0
1111
cosmossdk.io/core v0.11.0
@@ -23,7 +23,7 @@ require (
2323
github.com/cometbft/cometbft v0.38.7
2424
github.com/cosmos/cosmos-db v1.0.2
2525
github.com/cosmos/cosmos-proto v1.0.0-beta.5
26-
github.com/cosmos/cosmos-sdk v0.50.6
26+
github.com/cosmos/cosmos-sdk v0.50.7-0.20240517114248-b99ca2c1fded
2727
github.com/cosmos/go-bip39 v1.0.0
2828
github.com/cosmos/gogoproto v1.4.12
2929
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2
@@ -34,8 +34,8 @@ require (
3434
github.com/gorilla/mux v1.8.1
3535
github.com/grpc-ecosystem/grpc-gateway v1.16.0
3636
github.com/hashicorp/go-metrics v0.5.3
37-
github.com/initia-labs/OPinit v0.3.1
38-
github.com/initia-labs/initia v0.3.2
37+
github.com/initia-labs/OPinit v0.3.2
38+
github.com/initia-labs/initia v0.3.3
3939
github.com/initia-labs/kvindexer v0.1.3
4040
github.com/initia-labs/kvindexer/submodules/block v0.1.0
4141
github.com/initia-labs/kvindexer/submodules/tx v0.1.0
@@ -249,6 +249,10 @@ replace (
249249
// use cosmos fork of keyring
250250
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
251251

252+
// Use latest iavl version to fix following issue:
253+
// https://github.com/cosmos/iavl/pull/943
254+
github.com/cosmos/iavl => github.com/cosmos/iavl v1.1.4
255+
252256
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
253257
// TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
254258
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
@@ -266,6 +270,5 @@ replace (
266270
replace (
267271
github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240621094738-408dc5262680
268272
github.com/cosmos/cosmos-sdk => github.com/initia-labs/cosmos-sdk v0.0.0-20240502043911-a4bdb8e06769
269-
github.com/cosmos/iavl => github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e
270273
github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c
271274
)

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX
184184
cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg=
185185
cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
186186
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
187-
cosmossdk.io/api v0.7.4 h1:sPo8wKwCty1lht8kgL3J7YL1voJywP3YWuA5JKkBz30=
188-
cosmossdk.io/api v0.7.4/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
187+
cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ=
188+
cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
189189
cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79 h1:Hr1t0fCq1nbFC7hLs0Xvy9WAiH7Iti5iVLXMM5C37F0=
190190
cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79/go.mod h1:8pN6LSVReNnIxrC2QGcvuIJ/m1pJN6FNYn2kAYtYftI=
191191
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
@@ -406,6 +406,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ
406406
github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU=
407407
github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8JpFE=
408408
github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY=
409+
github.com/cosmos/iavl v1.1.4 h1:Z0cVVjeQqOUp78/nWt/uhQy83vYluWlAMGQ4zbH9G34=
410+
github.com/cosmos/iavl v1.1.4/go.mod h1:vCYmRQUJU1wwj0oRD3wMEtOM9sJNDP+GFMaXmIxZ/rU=
409411
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2 h1:dyLNlDElY6+5zW/BT/dO/3Ad9FpQblfh+9dQpYQodbA=
410412
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2/go.mod h1:82hPO/tRawbuFad2gPwChvpZ0JEIoNi91LwVneAYCeM=
411413
github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo8ci1mVZNO9+V0xsLE=
@@ -792,20 +794,18 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
792794
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
793795
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
794796
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
795-
github.com/initia-labs/OPinit v0.3.1 h1:uffngNx8a7hQl3ENhVbdSAJ8j5MYksiaiCLVI6xunjA=
796-
github.com/initia-labs/OPinit v0.3.1/go.mod h1:pHU2472uQZpiKXBOa/D7/aDYn0gtTiddKvhloyliOQU=
797+
github.com/initia-labs/OPinit v0.3.2 h1:TeELD5GeSJJ9meY5b5YIXDdmCZt9kZOA2Chz+IwxUHc=
798+
github.com/initia-labs/OPinit v0.3.2/go.mod h1:XlYsBFAKOFS6/wRIHB1vVbfonqX8QrC8cWK2GJvmX20=
797799
github.com/initia-labs/OPinit/api v0.3.0 h1:OY8ijwmgZLoYwtw9LI1mSY3VC8PY+gtxJFitB6ZNFl4=
798800
github.com/initia-labs/OPinit/api v0.3.0/go.mod h1:Xy/Nt3ubXLQ4zKn0m7RuQOM1sj8TVdlNNyek21TGYR0=
799801
github.com/initia-labs/cometbft v0.0.0-20240621094738-408dc5262680 h1:4tcP5F26DdqiV1Y/XOllL4LUhyUV6HITfjVJnzR/Krs=
800802
github.com/initia-labs/cometbft v0.0.0-20240621094738-408dc5262680/go.mod h1:qGaJePRWAc2OL3OGNd//8fqgypCaFjmwZcy/cNner84=
801803
github.com/initia-labs/cosmos-sdk v0.0.0-20240502043911-a4bdb8e06769 h1:R+cOwxp14K9+UAJ7MI4YyqXSL+Fm8W+wTBbXL315EMA=
802804
github.com/initia-labs/cosmos-sdk v0.0.0-20240502043911-a4bdb8e06769/go.mod h1:lVkRY6cdMJ0fG3gp8y4hFrsKZqF4z7y0M2UXFb9Yt40=
803-
github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e h1:1gkMWkAgVhYFhEv7K4tX+8uJJLdiTKlQhl5+wGaxdMg=
804-
github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM=
805805
github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c h1:FDwh5zZbm9v7C37ni4FytQQ9Os5XxYp1px5U7Nqdu2Y=
806806
github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
807-
github.com/initia-labs/initia v0.3.2 h1:nvVCgUiiDxDcFdC+ordooSlqUHXR8mFGDvCgwptTaAg=
808-
github.com/initia-labs/initia v0.3.2/go.mod h1:CXKYIajY7mj7EogHO1VcgaXnKZFpeRfSc0KxbqbxWjY=
807+
github.com/initia-labs/initia v0.3.3 h1:82ZkXki6CG+F+rPDBVpTzzSQY8NalXIZ0LnYSWNd+3U=
808+
github.com/initia-labs/initia v0.3.3/go.mod h1:1yWifo9GnhIvwDtCTTN6kb2mfq2On+oel6ha/rBXaQQ=
809809
github.com/initia-labs/kvindexer v0.1.3 h1:TLkgJjp5TiPnH+OzYfk7ZKQTKqGOfSte59Y3gasob+o=
810810
github.com/initia-labs/kvindexer v0.1.3/go.mod h1:rvAmgCAmEs4KM8sRRPcyTqNNwi8s2JiHybiFkYfp4KE=
811811
github.com/initia-labs/kvindexer/submodules/block v0.1.0 h1:y+EXnksd/I2F96mzIoQA64nZUZON2P+99YrSzeLCLoY=
@@ -816,8 +816,8 @@ github.com/initia-labs/kvindexer/submodules/wasm-nft v0.1.3 h1:diSQs+zWNj0U5tdDS
816816
github.com/initia-labs/kvindexer/submodules/wasm-nft v0.1.3/go.mod h1:1HD0/oH6kErv8F0J5ayGfLqerWSCPveGHSCbcfiBELw=
817817
github.com/initia-labs/kvindexer/submodules/wasm-pair v0.1.0 h1:Ns7bxZkwdby67aIq3VXFAzlpoLdGONJbDaMiqu6k408=
818818
github.com/initia-labs/kvindexer/submodules/wasm-pair v0.1.0/go.mod h1:SEotHE6mJ3VKr9g4j0AoXHgEYz6qhL3i1bX1QRnVT6g=
819-
github.com/initia-labs/movevm v0.3.1 h1:vydw0mdqsLyPN9W2DVq1/gDXDR3snbr6c4Wy/sTYVxY=
820-
github.com/initia-labs/movevm v0.3.1/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30=
819+
github.com/initia-labs/movevm v0.3.3 h1:xUH5VvjBSfJP4jg3axefmBlcdZ/7qfVYnUU09R4oN4g=
820+
github.com/initia-labs/movevm v0.3.3/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30=
821821
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
822822
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
823823
github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls=

0 commit comments

Comments
 (0)