Skip to content

Commit

Permalink
chore: compare timeouts as was done in the olden days
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Oct 22, 2024
1 parent 0d10de6 commit 588810f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions modules/core/04-channel/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() {
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupV2()

timeoutTimestamp = suite.chainA.GetTimeoutTimestamp()
timeoutTimestamp = suite.chainA.GetTimeoutTimestampSecs()
payload = mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

expectedPacket = channeltypesv2.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, timeoutTimestamp, payload)
Expand Down Expand Up @@ -201,7 +201,7 @@ func (suite *KeeperTestSuite) TestMsgRecvPacket() {
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupV2()

timeoutTimestamp := suite.chainA.GetTimeoutTimestamp()
timeoutTimestamp := suite.chainA.GetTimeoutTimestampSecs()

var err error
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB))
Expand Down Expand Up @@ -393,7 +393,7 @@ func (suite *KeeperTestSuite) TestMsgAcknowledgement() {
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupV2()

timeoutTimestamp := suite.chainA.GetTimeoutTimestamp()
timeoutTimestamp := suite.chainA.GetTimeoutTimestampSecs()

var err error
// Send packet from A to B
Expand Down
18 changes: 9 additions & 9 deletions modules/core/04-channel/v2/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func (k *Keeper) sendPacket(
return 0, "", err
}

timeout := types.TimeoutTimestampToNanos(packet.TimeoutTimestamp)
if timeout < latestTimestamp {
return 0, "", errorsmod.Wrapf(channeltypes.ErrTimeoutElapsed, "latest timestamp: %d, timeout timestamp: %d", latestTimestamp, timeout)
timeoutTimestamp = types.TimeoutTimestampToNanos(packet.TimeoutTimestamp)
if latestTimestamp >= timeoutTimestamp {
return 0, "", errorsmod.Wrapf(channeltypes.ErrTimeoutElapsed, "latest timestamp: %d, timeout timestamp: %d", latestTimestamp, timeoutTimestamp)
}

commitment := types.CommitPacket(packet)
Expand Down Expand Up @@ -117,9 +117,9 @@ func (k *Keeper) recvPacket(
// check if packet timed out by comparing it with the latest height of the chain
sdkCtx := sdk.UnwrapSDKContext(ctx)
currentTimestamp := uint64(sdkCtx.BlockTime().UnixNano())
timeout := types.TimeoutTimestampToNanos(packet.TimeoutTimestamp)
if timeout <= currentTimestamp {
return errorsmod.Wrapf(channeltypes.ErrTimeoutElapsed, "current timestamp: %d, timeout timestamp: %d", currentTimestamp, timeout)
timeoutTimestamp := types.TimeoutTimestampToNanos(packet.TimeoutTimestamp)
if currentTimestamp >= timeoutTimestamp {
return errorsmod.Wrapf(channeltypes.ErrTimeoutElapsed, "current timestamp: %d, timeout timestamp: %d", currentTimestamp, timeoutTimestamp)
}

// REPLAY PROTECTION: Packet receipts will indicate that a packet has already been received
Expand Down Expand Up @@ -295,9 +295,9 @@ func (k *Keeper) timeoutPacket(
return err
}

timeout := types.TimeoutTimestampToNanos(packet.TimeoutTimestamp)
if timeout > proofTimestamp {
return errorsmod.Wrapf(channeltypes.ErrTimeoutNotReached, "proof timestamp: %d, timeout timestamp: %d", proofTimestamp, timeout)
timeoutTimestamp := types.TimeoutTimestampToNanos(packet.TimeoutTimestamp)
if proofTimestamp < timeoutTimestamp {
return errorsmod.Wrapf(channeltypes.ErrTimeoutNotReached, "proof timestamp: %d, timeout timestamp: %d", proofTimestamp, timeoutTimestamp)
}

// check that the commitment has not been cleared and that it matches the packet sent by relayer
Expand Down

0 comments on commit 588810f

Please sign in to comment.