Skip to content

Commit ac0297b

Browse files
consistent behaviour across go and solidity for timeout behaviour (#8130) (#8133)
Co-authored-by: Gjermund Garaba <[email protected]> (cherry picked from commit 1dbaaa1) Co-authored-by: Aditya <[email protected]>
1 parent 887f2b0 commit ac0297b

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

modules/apps/callbacks/v2/ibc_middleware_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v2_test
22

33
import (
44
"fmt"
5+
"time"
56

67
errorsmod "cosmossdk.io/errors"
78
storetypes "cosmossdk.io/store/types"
@@ -474,7 +475,7 @@ func (s *CallbacksTestSuite) TestOnTimeoutPacket() {
474475
// NOTE: we call send packet so transfer is setup with the correct logic to
475476
// succeed on timeout
476477
userGasLimit := 600_000
477-
timeoutTimestamp := uint64(s.chainB.GetContext().BlockTime().Unix())
478+
timeoutTimestamp := uint64(s.chainB.GetContext().BlockTime().Add(time.Second).Unix())
478479
packetData = transfertypes.NewFungibleTokenPacketData(
479480
ibctesting.TestCoin.Denom,
480481
ibctesting.TestCoin.Amount.String(),

modules/core/04-channel/v2/keeper/msg_server_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,9 @@ func (suite *KeeperTestSuite) TestMsgTimeout() {
461461
path.SetupV2()
462462

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

467469
var err error

modules/core/04-channel/v2/keeper/packet.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func (k *Keeper) sendPacket(
3333
// Note, the validate basic function in sendPacket does the timeoutTimestamp != 0 check and other stateless checks on the packet.
3434
// timeoutTimestamp must be greater than current block time
3535
timeout := time.Unix(int64(timeoutTimestamp), 0)
36-
if timeout.Before(ctx.BlockTime()) {
37-
return 0, "", errorsmod.Wrap(types.ErrTimeoutElapsed, "timeout is less than the current block timestamp")
36+
if !timeout.After(ctx.BlockTime()) {
37+
return 0, "", errorsmod.Wrapf(types.ErrTimeoutElapsed, "timeout is less than or equal the current block timestamp, %d <= %d", timeoutTimestamp, ctx.BlockTime().Unix())
3838
}
3939

4040
// timeoutTimestamp must be less than current block time + MaxTimeoutDelta

modules/core/04-channel/v2/keeper/packet_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ func (suite *KeeperTestSuite) TestSendPacket() {
8080
},
8181
clienttypes.ErrInvalidHeight,
8282
},
83+
{
84+
"timeout equal to sending chain blocktime", func() {
85+
packet.TimeoutTimestamp = uint64(suite.chainA.GetContext().BlockTime().Unix())
86+
},
87+
types.ErrTimeoutElapsed,
88+
},
8389
{
8490
"timeout elapsed", func() {
8591
packet.TimeoutTimestamp = 1
@@ -563,7 +569,9 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
563569
// create default packet with a timed out timestamp
564570
payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)
565571

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

568576
// test cases may mutate timeout values
569577
packet = types.NewPacket(1, path.EndpointA.ClientID, path.EndpointB.ClientID,

modules/core/ante/ante_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (suite *AnteTestSuite) createTimeoutMessage(isRedundant bool) sdk.Msg {
170170

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

0 commit comments

Comments
 (0)