From acbe07fa9945e2bca0af3ab4af93a9de48aa7521 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Fri, 18 Oct 2024 17:53:34 +0900 Subject: [PATCH] fix to use cache context at ibc hook --- x/ibc-hooks/move-hooks/receive.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/x/ibc-hooks/move-hooks/receive.go b/x/ibc-hooks/move-hooks/receive.go index 87bf4e1a..335314ce 100644 --- a/x/ibc-hooks/move-hooks/receive.go +++ b/x/ibc-hooks/move-hooks/receive.go @@ -124,5 +124,16 @@ func (h MoveHooks) execMsg(ctx sdk.Context, msg *movetypes.MsgExecute) (*movetyp } moveMsgServer := movekeeper.NewMsgServerImpl(h.moveKeeper) - return moveMsgServer.Execute(ctx, msg) + + // use cache context to prevent state changes if the message execution fails + cacheCtx, write := ctx.CacheContext() + res, err := moveMsgServer.Execute(cacheCtx, msg) + if err != nil { + return nil, err + } + + // write the cache context only if the message execution was successful + write() + + return res, nil }