From 42106286acee661a4f6776d1251ffe68cdfe8856 Mon Sep 17 00:00:00 2001 From: Gjermund Garaba Date: Sat, 7 Dec 2024 22:07:40 +0100 Subject: [PATCH] move timestamp checks in SendPacket earlier --- modules/core/04-channel/v2/keeper/msg_server.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/core/04-channel/v2/keeper/msg_server.go b/modules/core/04-channel/v2/keeper/msg_server.go index f4c2dc446a1..e7e5e7cda58 100644 --- a/modules/core/04-channel/v2/keeper/msg_server.go +++ b/modules/core/04-channel/v2/keeper/msg_server.go @@ -64,11 +64,6 @@ func (k *Keeper) RegisterCounterparty(goCtx context.Context, msg *types.MsgRegis // SendPacket implements the PacketMsgServer SendPacket method. func (k *Keeper) SendPacket(ctx context.Context, msg *types.MsgSendPacket) (*types.MsgSendPacketResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - sequence, destChannel, err := k.sendPacket(ctx, msg.SourceChannel, msg.TimeoutTimestamp, msg.Payloads) - if err != nil { - sdkCtx.Logger().Error("send packet failed", "source-channel", msg.SourceChannel, "error", errorsmod.Wrap(err, "send packet failed")) - return nil, errorsmod.Wrapf(err, "send packet failed for source id: %s", msg.SourceChannel) - } // Note, the validate basic function in sendPacket does the timeoutTimestamp != 0 check and other stateless checks on the packet. // timeoutTimestamp must be greater than current block time @@ -88,6 +83,12 @@ func (k *Keeper) SendPacket(ctx context.Context, msg *types.MsgSendPacket) (*typ return nil, errorsmod.Wrap(err, "invalid address for msg Signer") } + sequence, destChannel, err := k.sendPacket(ctx, msg.SourceChannel, msg.TimeoutTimestamp, msg.Payloads) + if err != nil { + sdkCtx.Logger().Error("send packet failed", "source-channel", msg.SourceChannel, "error", errorsmod.Wrap(err, "send packet failed")) + return nil, errorsmod.Wrapf(err, "send packet failed for source id: %s", msg.SourceChannel) + } + for _, pd := range msg.Payloads { cbs := k.Router.Route(pd.SourcePort) err := cbs.OnSendPacket(ctx, msg.SourceChannel, destChannel, sequence, pd, signer)