From 8e91bbc3aae7efe5238d11c7c99dfe9a73d09868 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 29 Nov 2021 09:23:32 +0100 Subject: [PATCH 1/5] use local clock time as reference time if it is later than the consensus state timestamp from the counter party chain --- modules/apps/transfer/client/cli/tx.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/apps/transfer/client/cli/tx.go b/modules/apps/transfer/client/cli/tx.go index 1e201bddb37..139a96f8959 100644 --- a/modules/apps/transfer/client/cli/tx.go +++ b/modules/apps/transfer/client/cli/tx.go @@ -3,6 +3,7 @@ package cli import ( "fmt" "strings" + "time" "github.com/spf13/cobra" @@ -89,7 +90,21 @@ to the counterparty channel. Any timeout set to 0 is disabled.`), } if timeoutTimestamp != 0 { - timeoutTimestamp = consensusState.GetTimestamp() + timeoutTimestamp + // use local clock time as reference time if it is later than the + // consensus state timestamp of the counter party chain, otherwise + // still use consensus state timestamp as reference + now := time.Now().UnixNano() + consensusStateTimestamp := consensusState.GetTimestamp() + if now > 0 { + now := uint64(now) + if now > consensusStateTimestamp { + timeoutTimestamp = now + timeoutTimestamp + } else { + timeoutTimestamp = consensusStateTimestamp + timeoutTimestamp + } + } else { + timeoutTimestamp = consensusStateTimestamp + timeoutTimestamp + } } } From af9f1ebb25aabfb312dd8d57d9c5d0c66b023272 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 30 Nov 2021 20:39:20 +0100 Subject: [PATCH 2/5] add comment --- modules/apps/transfer/client/cli/tx.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/transfer/client/cli/tx.go b/modules/apps/transfer/client/cli/tx.go index 139a96f8959..ec2699cea45 100644 --- a/modules/apps/transfer/client/cli/tx.go +++ b/modules/apps/transfer/client/cli/tx.go @@ -103,6 +103,7 @@ to the counterparty channel. Any timeout set to 0 is disabled.`), timeoutTimestamp = consensusStateTimestamp + timeoutTimestamp } } else { + // rare case: if local clock time is equal to or earlier than Jan 1st, 1970 12:00 AM timeoutTimestamp = consensusStateTimestamp + timeoutTimestamp } } From b6ab2dcda7d86941a0f2fe52a8a11a88decdc033 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 30 Nov 2021 20:48:32 +0100 Subject: [PATCH 3/5] update command description --- modules/apps/transfer/client/cli/tx.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/apps/transfer/client/cli/tx.go b/modules/apps/transfer/client/cli/tx.go index ec2699cea45..abaa154cb55 100644 --- a/modules/apps/transfer/client/cli/tx.go +++ b/modules/apps/transfer/client/cli/tx.go @@ -30,9 +30,10 @@ func NewTransferTxCmd() *cobra.Command { Short: "Transfer a fungible token through IBC", Long: strings.TrimSpace(`Transfer a fungible token through IBC. Timeouts can be specified as absolute or relative using the "absolute-timeouts" flag. Timeout height can be set by passing in the height string -in the form {revision}-{height} using the "packet-timeout-height" flag. Relative timeouts are added to -the block height and block timestamp queried from the latest consensus state corresponding -to the counterparty channel. Any timeout set to 0 is disabled.`), +in the form {revision}-{height} using the "packet-timeout-height" flag. Relative timeout height is added to the block +height queried from the latest consensus state corresponding to the counterparty channel. Relative timeout timestamp +is added to the greater value of the local clock time and the block timestamp queried from the latest consensus state +corresponding to the counterparty channel. Any timeout set to 0 is disabled.`), Example: fmt.Sprintf("%s tx ibc-transfer transfer [src-port] [src-channel] [receiver] [amount]", version.AppName), Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { From 083d9f1a531a04b3f0b76ef27eb6978c8df5edf4 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 1 Dec 2021 07:18:11 +0100 Subject: [PATCH 4/5] add entry to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 054abb5db9c..a66a9463138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#383](https://github.com/cosmos/ibc-go/pull/383) Adds helper functions for merging and splitting middleware versions from the underlying app version. * (modules/core/05-port) [\#288](https://github.com/cosmos/ibc-go/issues/288) Making the 05-port keeper function IsBound public. The IsBound function checks if the provided portID is already binded to a module. +* (02-client) [\#568](https://github.com/cosmos/ibc-go/pull/568) In IBC `transfer` cli command use local clock time as reference for relative timestamp timeout if greater than the block timestamp queried from the latest consensus state corresponding to the counterparty channel. ### Features From b734f8d94d0302c787f32a4795130a9031f29870 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 1 Dec 2021 22:42:11 +0100 Subject: [PATCH 5/5] return error is clock time is less or equal than Jan 1st 1970 12:00 AM --- modules/apps/transfer/client/cli/tx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/transfer/client/cli/tx.go b/modules/apps/transfer/client/cli/tx.go index abaa154cb55..74ff6ae802b 100644 --- a/modules/apps/transfer/client/cli/tx.go +++ b/modules/apps/transfer/client/cli/tx.go @@ -1,6 +1,7 @@ package cli import ( + "errors" "fmt" "strings" "time" @@ -104,8 +105,7 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`), timeoutTimestamp = consensusStateTimestamp + timeoutTimestamp } } else { - // rare case: if local clock time is equal to or earlier than Jan 1st, 1970 12:00 AM - timeoutTimestamp = consensusStateTimestamp + timeoutTimestamp + return errors.New("local clock time is not greater than Jan 1st, 1970 12:00 AM") } } }