Skip to content

Commit

Permalink
fix to use cache context at ibc hook (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored Oct 21, 2024
1 parent 85a29a9 commit 2c304ca
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion x/ibc-hooks/move-hooks/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 2c304ca

Please sign in to comment.