Skip to content

Commit

Permalink
consistent behaviour across go and solidity for timeout behaviour (#8130
Browse files Browse the repository at this point in the history
) (#8133)

Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
(cherry picked from commit 1dbaaa1)

Co-authored-by: Aditya <14364734+AdityaSripal@users.noreply.github.com>
  • Loading branch information
mergify[bot] and AdityaSripal authored Mar 3, 2025
1 parent 887f2b0 commit ac0297b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion modules/apps/callbacks/v2/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v2_test

import (
"fmt"
"time"

errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -474,7 +475,7 @@ func (s *CallbacksTestSuite) TestOnTimeoutPacket() {
// NOTE: we call send packet so transfer is setup with the correct logic to
// succeed on timeout
userGasLimit := 600_000
timeoutTimestamp := uint64(s.chainB.GetContext().BlockTime().Unix())
timeoutTimestamp := uint64(s.chainB.GetContext().BlockTime().Add(time.Second).Unix())
packetData = transfertypes.NewFungibleTokenPacketData(
ibctesting.TestCoin.Denom,
ibctesting.TestCoin.Amount.String(),
Expand Down
4 changes: 3 additions & 1 deletion modules/core/04-channel/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ func (suite *KeeperTestSuite) TestMsgTimeout() {
path.SetupV2()

// Send packet from A to B
timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().Unix())
// make timeoutTimestamp 1 second more than sending chain time to ensure it passes SendPacket
// and times out successfully after update
timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().Add(time.Second).Unix())
mockData := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

var err error
Expand Down
4 changes: 2 additions & 2 deletions modules/core/04-channel/v2/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (k *Keeper) sendPacket(
// 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
timeout := time.Unix(int64(timeoutTimestamp), 0)
if timeout.Before(ctx.BlockTime()) {
return 0, "", errorsmod.Wrap(types.ErrTimeoutElapsed, "timeout is less than the current block timestamp")
if !timeout.After(ctx.BlockTime()) {
return 0, "", errorsmod.Wrapf(types.ErrTimeoutElapsed, "timeout is less than or equal the current block timestamp, %d <= %d", timeoutTimestamp, ctx.BlockTime().Unix())
}

// timeoutTimestamp must be less than current block time + MaxTimeoutDelta
Expand Down
10 changes: 9 additions & 1 deletion modules/core/04-channel/v2/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func (suite *KeeperTestSuite) TestSendPacket() {
},
clienttypes.ErrInvalidHeight,
},
{
"timeout equal to sending chain blocktime", func() {
packet.TimeoutTimestamp = uint64(suite.chainA.GetContext().BlockTime().Unix())
},
types.ErrTimeoutElapsed,
},
{
"timeout elapsed", func() {
packet.TimeoutTimestamp = 1
Expand Down Expand Up @@ -563,7 +569,9 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
// create default packet with a timed out timestamp
payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Unix())
// make timeoutTimestamp 1 second more than sending chain time to ensure it passes SendPacket
// and times out successfully after update
timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Second).Unix())

// test cases may mutate timeout values
packet = types.NewPacket(1, path.EndpointA.ClientID, path.EndpointB.ClientID,
Expand Down
2 changes: 1 addition & 1 deletion modules/core/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (suite *AnteTestSuite) createTimeoutMessage(isRedundant bool) sdk.Msg {

// createTimeoutMessageV2 creates a V2 Timeout message for a packet sent from chain B to chain A.
func (suite *AnteTestSuite) createTimeoutMessageV2(isRedundant bool) *channeltypesv2.MsgTimeout {
timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Unix())
timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Second).Unix())
packet, err := suite.path.EndpointB.MsgSendPacket(timeoutTimestamp, mock.NewMockPayload(mock.ModuleNameA, mock.ModuleNameB))
suite.Require().NoError(err)

Expand Down

0 comments on commit ac0297b

Please # to comment.