Skip to content

Commit

Permalink
Update relay.go
Browse files Browse the repository at this point in the history
  • Loading branch information
timwhite2 committed Sep 26, 2022
1 parent 0238402 commit d1b4468
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,6 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
telemetry.NewLabel(coretypes.LabelSourceChannel, packet.GetSourceChannel()),
}

var commit func()
tmpCtx := ctx
if k.hooks != nil {
// Create a cache context to revert state when tx hooks fails,
// the cache context is only committed when both tx and hooks executed successfully.
// Didn't use `Snapshot` because the context stack has exponential complexity on certain operations,
// thus restricted to be used only inside `ApplyMessage`.
tmpCtx, commit = ctx.CacheContext()
}

// This is the prefix that would have been prefixed to the denomination
// on sender chain IF and only if the token originally came from the
// receiving chain.
Expand Down Expand Up @@ -282,12 +272,9 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
}()

// Only call hooks if tx executed successfully.
if err = k.AfterRecvPacket(tmpCtx, receiver, token); err != nil {
if err = k.AfterRecvPacket(ctx, receiver, token); err != nil {
// If hooks return error, only revert hooks.
k.Logger(ctx).Error("ibc transfer hooks failed", "error", err)
} else if commit != nil {
// hooks is successful, commit the tmpCtx
commit()
k.Logger(ctx).Info("ibc transfer hooks failed", "error", err)
}

return nil
Expand Down Expand Up @@ -351,12 +338,9 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
}()

// Only call hooks if tx executed successfully.
if err = k.AfterRecvPacket(tmpCtx, receiver, voucher); err != nil {
if err = k.AfterRecvPacket(ctx, receiver, voucher); err != nil {
// If hooks return error, only revert hooks.
k.Logger(ctx).Error("ibc transfer hooks failed", "error", err)
} else if commit != nil {
// hooks is successful, commit the tmpCtx
commit()
}

return nil
Expand Down

0 comments on commit d1b4468

Please sign in to comment.