Skip to content

Commit 154f54f

Browse files
committed
add --src-height and --dst-height options to tx clients subcommand
Signed-off-by: Masanori Yoshida <masanori.yoshida@datachain.jp>
1 parent 374258c commit 154f54f

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

cmd/tx.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"context"
5+
"math"
56
"strings"
67

78
"github.com/cosmos/cosmos-sdk/client/flags"
@@ -38,6 +39,10 @@ func transactionCmd(ctx *config.Context) *cobra.Command {
3839
}
3940

4041
func createClientsCmd(ctx *config.Context) *cobra.Command {
42+
const (
43+
flagSrcHeight = "src-height"
44+
flagDstHeight = "dst-height"
45+
)
4146
cmd := &cobra.Command{
4247
Use: "clients [path-name]",
4348
Short: "create a clients between two configured chains with a configured path",
@@ -58,9 +63,29 @@ func createClientsCmd(ctx *config.Context) *cobra.Command {
5863
return err
5964
}
6065

61-
return core.CreateClients(c[src], c[dst])
66+
var srcHeight *uint64
67+
if h, err := cmd.Flags().GetUint64(flagSrcHeight); err != nil {
68+
return err
69+
} else if h == math.MaxUint64 {
70+
srcHeight = nil
71+
} else {
72+
srcHeight = &h
73+
}
74+
75+
var dstHeight *uint64
76+
if h, err := cmd.Flags().GetUint64(flagDstHeight); err != nil {
77+
return err
78+
} else if h == math.MaxUint64 {
79+
dstHeight = nil
80+
} else {
81+
dstHeight = &h
82+
}
83+
84+
return core.CreateClients(c[src], c[dst], srcHeight, dstHeight)
6285
},
6386
}
87+
cmd.Flags().Uint64(flagSrcHeight, math.MaxUint64, "src header at this height is submitted to dst chain")
88+
cmd.Flags().Uint64(flagDstHeight, math.MaxUint64, "dst header at this height is submitted to src chain")
6489
return cmd
6590
}
6691

core/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
"golang.org/x/sync/errgroup"
99
)
1010

11-
func CreateClients(src, dst *ProvableChain) error {
11+
func CreateClients(src, dst *ProvableChain, srcHeight, dstHeight *uint64) error {
1212
logger := GetChainPairLogger(src, dst)
1313
defer logger.TimeTrack(time.Now(), "CreateClients")
1414
var (
1515
clients = &RelayMsgs{Src: []sdk.Msg{}, Dst: []sdk.Msg{}}
1616
)
1717

18-
srcH, dstH, err := getHeadersForCreateClient(src, dst)
18+
srcH, dstH, err := getHeadersForCreateClient(src, dst, srcHeight, dstHeight)
1919
if err != nil {
2020
logger.Error(
2121
"failed to get headers for create client",
@@ -118,14 +118,14 @@ func UpdateClients(src, dst *ProvableChain) error {
118118
}
119119

120120
// getHeadersForCreateClient calls UpdateLightWithHeader on the passed chains concurrently
121-
func getHeadersForCreateClient(src, dst LightClient) (srch, dsth Header, err error) {
121+
func getHeadersForCreateClient(src, dst LightClient, srcHeight, dstHeight *uint64) (srch, dsth Header, err error) {
122122
var eg = new(errgroup.Group)
123123
eg.Go(func() error {
124-
srch, err = src.GetFinalizedHeader(nil)
124+
srch, err = src.GetFinalizedHeader(srcHeight)
125125
return err
126126
})
127127
eg.Go(func() error {
128-
dsth, err = dst.GetFinalizedHeader(nil)
128+
dsth, err = dst.GetFinalizedHeader(dstHeight)
129129
return err
130130
})
131131
if err := eg.Wait(); err != nil {

tests/cases/tm2tm/scripts/handshake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ retry 5 $RLY tendermint light init $CHAINID_TWO -f
2727
# add a path between chain0 and chain1
2828
$RLY paths add $CHAINID_ONE $CHAINID_TWO $PATH_NAME --file=./configs/path.json
2929

30-
retry 5 $RLY tx clients $PATH_NAME
30+
retry 5 $RLY tx clients --src-height 2 $PATH_NAME
3131
retry 5 $RLY tx connection $PATH_NAME
3232
retry 5 $RLY tx channel $PATH_NAME

tests/cases/tmmock2tmmock/scripts/handshake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ $RLY tendermint keys show $CHAINID_TWO $RLYKEY
1919
# add a path between chain0 and chain1
2020
$RLY paths add $CHAINID_ONE $CHAINID_TWO $PATH_NAME --file=./configs/path.json
2121

22-
retry 5 $RLY tx clients $PATH_NAME
22+
retry 5 $RLY tx clients --dst-height 2 $PATH_NAME
2323
retry 5 $RLY tx connection $PATH_NAME
2424
retry 5 $RLY tx channel $PATH_NAME

0 commit comments

Comments
 (0)