@@ -393,13 +393,11 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke
393
393
cacheCtx , writeFn := ctx .CacheContext ()
394
394
err = k .ChannelKeeper .RecvPacket (cacheCtx , cap , msg .Packet , msg .ProofCommitment , msg .ProofHeight )
395
395
396
- // NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context.
397
- ctx .EventManager ().EmitEvents (cacheCtx .EventManager ().Events ())
398
-
399
396
switch err {
400
397
case nil :
401
398
writeFn ()
402
399
case channeltypes .ErrNoOpMsg :
400
+ // no-ops do not need event emission as they will be ignored
403
401
return & channeltypes.MsgRecvPacketResponse {Result : channeltypes .NOOP }, nil
404
402
default :
405
403
return nil , sdkerrors .Wrap (err , "receive packet verification failed" )
@@ -410,12 +408,13 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke
410
408
// Cache context so that we may discard state changes from callback if the acknowledgement is unsuccessful.
411
409
cacheCtx , writeFn = ctx .CacheContext ()
412
410
ack := cbs .OnRecvPacket (cacheCtx , msg .Packet , relayer )
413
- // NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context.
414
- // Events from callback are emitted regardless of acknowledgement success
415
- ctx .EventManager ().EmitEvents (cacheCtx .EventManager ().Events ())
416
411
if ack == nil || ack .Success () {
417
412
// write application state changes for asynchronous and successful acknowledgements
418
413
writeFn ()
414
+ } else {
415
+ // NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context.
416
+ // Events should still be emitted from failed acks and asynchronous acks
417
+ ctx .EventManager ().EmitEvents (cacheCtx .EventManager ().Events ())
419
418
}
420
419
421
420
// Set packet acknowledgement only if the acknowledgement is not nil.
@@ -471,13 +470,11 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c
471
470
cacheCtx , writeFn := ctx .CacheContext ()
472
471
err = k .ChannelKeeper .TimeoutPacket (cacheCtx , msg .Packet , msg .ProofUnreceived , msg .ProofHeight , msg .NextSequenceRecv )
473
472
474
- // NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context.
475
- ctx .EventManager ().EmitEvents (cacheCtx .EventManager ().Events ())
476
-
477
473
switch err {
478
474
case nil :
479
475
writeFn ()
480
476
case channeltypes .ErrNoOpMsg :
477
+ // no-ops do not need event emission as they will be ignored
481
478
return & channeltypes.MsgTimeoutResponse {Result : channeltypes .NOOP }, nil
482
479
default :
483
480
return nil , sdkerrors .Wrap (err , "timeout packet verification failed" )
@@ -539,13 +536,11 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo
539
536
cacheCtx , writeFn := ctx .CacheContext ()
540
537
err = k .ChannelKeeper .TimeoutOnClose (cacheCtx , cap , msg .Packet , msg .ProofUnreceived , msg .ProofClose , msg .ProofHeight , msg .NextSequenceRecv )
541
538
542
- // NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context.
543
- ctx .EventManager ().EmitEvents (cacheCtx .EventManager ().Events ())
544
-
545
539
switch err {
546
540
case nil :
547
541
writeFn ()
548
542
case channeltypes .ErrNoOpMsg :
543
+ // no-ops do not need event emission as they will be ignored
549
544
return & channeltypes.MsgTimeoutOnCloseResponse {Result : channeltypes .NOOP }, nil
550
545
default :
551
546
return nil , sdkerrors .Wrap (err , "timeout on close packet verification failed" )
@@ -610,13 +605,11 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn
610
605
cacheCtx , writeFn := ctx .CacheContext ()
611
606
err = k .ChannelKeeper .AcknowledgePacket (cacheCtx , cap , msg .Packet , msg .Acknowledgement , msg .ProofAcked , msg .ProofHeight )
612
607
613
- // NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context.
614
- ctx .EventManager ().EmitEvents (cacheCtx .EventManager ().Events ())
615
-
616
608
switch err {
617
609
case nil :
618
610
writeFn ()
619
611
case channeltypes .ErrNoOpMsg :
612
+ // no-ops do not need event emission as they will be ignored
620
613
return & channeltypes.MsgAcknowledgementResponse {Result : channeltypes .NOOP }, nil
621
614
default :
622
615
return nil , sdkerrors .Wrap (err , "acknowledge packet verification failed" )
0 commit comments