From 616a9760757fd13566dd597c7f51e90700d2dcdb Mon Sep 17 00:00:00 2001 From: yoshidan Date: Sun, 17 Dec 2023 18:28:22 +0900 Subject: [PATCH 1/4] add --src-seqs and --dst-seqs Signed-off-by: yoshidan --- cmd/tx.go | 50 +++++++++++++++++++++++++++++++ tests/cases/tm2tm/scripts/test-tx | 4 +-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/cmd/tx.go b/cmd/tx.go index b1b61f99..5f5eb554 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -196,6 +196,8 @@ func createChannelCmd(ctx *config.Context) *cobra.Command { func relayMsgsCmd(ctx *config.Context) *cobra.Command { const ( flagDoRefresh = "do-refresh" + flagSrcSeqs = "src-seqs" + flagDstSeqs = "dst-seqs" ) const ( defaultDoRefresh = false @@ -205,6 +207,7 @@ func relayMsgsCmd(ctx *config.Context) *cobra.Command { Short: "relay any packets that remain to be relayed on a given path, in both directions", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + c, src, dst, err := ctx.Config.ChainsFromPath(args[0]) if err != nil { return err @@ -230,6 +233,11 @@ func relayMsgsCmd(ctx *config.Context) *cobra.Command { if err != nil { return err } + srcSeq := getInt64Slice(flagSrcSeqs) + dstSeq := getInt64Slice(flagDstSeqs) + if err = tryFilterRelayPackets(sp, srcSeq, dstSeq); err != nil { + return err + } msgs := core.NewRelayMsgs() @@ -251,6 +259,8 @@ func relayMsgsCmd(ctx *config.Context) *cobra.Command { }, } cmd.Flags().Bool(flagDoRefresh, defaultDoRefresh, "execute light client refresh (updateClient) if required") + cmd.Flags().IntSlice(flagSrcSeqs, nil, "packet filter for src chain") + cmd.Flags().IntSlice(flagDstSeqs, nil, "packet filter for dst chain") // TODO add option support for strategy return cmd } @@ -258,6 +268,8 @@ func relayMsgsCmd(ctx *config.Context) *cobra.Command { func relayAcksCmd(ctx *config.Context) *cobra.Command { const ( flagDoRefresh = "do-refresh" + flagSrcSeqs = "src-seqs" + flagDstSeqs = "dst-seqs" ) const ( defaultDoRefresh = false @@ -291,6 +303,11 @@ func relayAcksCmd(ctx *config.Context) *cobra.Command { if err != nil { return err } + srcSeq := getInt64Slice(flagSrcSeqs) + dstSeq := getInt64Slice(flagDstSeqs) + if err = tryFilterRelayPackets(sp, srcSeq, dstSeq); err != nil { + return err + } msgs := core.NewRelayMsgs() @@ -312,5 +329,38 @@ func relayAcksCmd(ctx *config.Context) *cobra.Command { }, } cmd.Flags().Bool(flagDoRefresh, defaultDoRefresh, "execute light client refresh (updateClient) if required") + cmd.Flags().IntSlice(flagSrcSeqs, nil, "packet filter for src chain") + cmd.Flags().IntSlice(flagDstSeqs, nil, "packet filter for dst chain") return cmd } + +func tryFilterRelayPackets(sp *core.RelayPackets, srcSeq []uint64, dstSeq []uint64) error { + checkSequence := func(p core.PacketInfoList, selected []uint64) error { + if len(p) != len(selected) { + return fmt.Errorf("packet not found packetLength=%d selectedLength=%d", len(p), len(selected)) + } + return nil + } + if len(srcSeq) > 0 { + sp.Src = sp.Src.Filter(srcSeq) + if err := checkSequence(sp.Src, srcSeq); err != nil { + return err + } + } + if len(dstSeq) > 0 { + sp.Dst = sp.Dst.Filter(dstSeq) + if err := checkSequence(sp.Dst, dstSeq); err != nil { + return err + } + } + return nil +} + +func getInt64Slice(key string) []uint64 { + org := viper.GetIntSlice(key) + ret := make([]uint64, len(org)) + for i, e := range org { + ret[i] = uint64(e) + } + return ret +} diff --git a/tests/cases/tm2tm/scripts/test-tx b/tests/cases/tm2tm/scripts/test-tx index e1f9c9e6..49c5e65f 100755 --- a/tests/cases/tm2tm/scripts/test-tx +++ b/tests/cases/tm2tm/scripts/test-tx @@ -19,9 +19,9 @@ echo "Before ibc1 balance: $(${RLY} query balance ibc1 ${TM_ADDRESS1})" ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep ${TX_INTERNAL} -${RLY} tx relay --do-refresh ibc01 +${RLY} tx relay --do-refresh ibc01 --src-seqs 1 sleep ${TX_INTERNAL} -${RLY} tx acks --do-refresh ibc01 +${RLY} tx acks --do-refresh ibc01 --dst-seqs 1 sleep ${TX_INTERNAL} echo "After ibc0 balance: $(${RLY} query balance ibc0 ${TM_ADDRESS0})" From 3394be6362a3b03befbb54e1b25a22636065df9c Mon Sep 17 00:00:00 2001 From: yoshidan Date: Sun, 17 Dec 2023 19:23:06 +0900 Subject: [PATCH 2/4] add opts for mock test Signed-off-by: yoshidan --- tests/cases/tmmock2tmmock/scripts/test-tx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cases/tmmock2tmmock/scripts/test-tx b/tests/cases/tmmock2tmmock/scripts/test-tx index cf73c68d..4e51b18f 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-tx +++ b/tests/cases/tmmock2tmmock/scripts/test-tx @@ -33,7 +33,7 @@ do done # relay the packet (recvPacket) -${RLY} tx relay --do-refresh ibc01 +${RLY} tx relay --do-refresh ibc01 --src-seqs 1 # wait for the finalization of the recvPacket execution for i in `seq $RETRY_COUNT` @@ -48,7 +48,7 @@ do done # relay the ack for the packet (acknowledgePacket) -${RLY} tx acks --do-refresh ibc01 +${RLY} tx acks --do-refresh ibc01 --dst-seqs 1 # wait for the finalization of the recvPacket execution for i in `seq $RETRY_COUNT` From 6acb84bf759e6179627d9d2c4889ed8e9734094e Mon Sep 17 00:00:00 2001 From: yoshidan Date: Tue, 19 Dec 2023 10:38:27 +0900 Subject: [PATCH 3/4] change func name Signed-off-by: yoshidan --- cmd/tx.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/tx.go b/cmd/tx.go index 5f5eb554..958d955e 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -233,8 +233,8 @@ func relayMsgsCmd(ctx *config.Context) *cobra.Command { if err != nil { return err } - srcSeq := getInt64Slice(flagSrcSeqs) - dstSeq := getInt64Slice(flagDstSeqs) + srcSeq := getUint64Slice(flagSrcSeqs) + dstSeq := getUint64Slice(flagDstSeqs) if err = tryFilterRelayPackets(sp, srcSeq, dstSeq); err != nil { return err } @@ -303,8 +303,8 @@ func relayAcksCmd(ctx *config.Context) *cobra.Command { if err != nil { return err } - srcSeq := getInt64Slice(flagSrcSeqs) - dstSeq := getInt64Slice(flagDstSeqs) + srcSeq := getUint64Slice(flagSrcSeqs) + dstSeq := getUint64Slice(flagDstSeqs) if err = tryFilterRelayPackets(sp, srcSeq, dstSeq); err != nil { return err } @@ -356,7 +356,7 @@ func tryFilterRelayPackets(sp *core.RelayPackets, srcSeq []uint64, dstSeq []uint return nil } -func getInt64Slice(key string) []uint64 { +func getUint64Slice(key string) []uint64 { org := viper.GetIntSlice(key) ret := make([]uint64, len(org)) for i, e := range org { From a042abd824459666dd6dfdccecdd58be8632ec9b Mon Sep 17 00:00:00 2001 From: yoshidan Date: Tue, 19 Dec 2023 21:18:13 +0900 Subject: [PATCH 4/4] change func name Signed-off-by: yoshidan --- cmd/tx.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/cmd/tx.go b/cmd/tx.go index 958d955e..a4164979 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -335,22 +335,16 @@ func relayAcksCmd(ctx *config.Context) *cobra.Command { } func tryFilterRelayPackets(sp *core.RelayPackets, srcSeq []uint64, dstSeq []uint64) error { - checkSequence := func(p core.PacketInfoList, selected []uint64) error { - if len(p) != len(selected) { - return fmt.Errorf("packet not found packetLength=%d selectedLength=%d", len(p), len(selected)) - } - return nil - } if len(srcSeq) > 0 { sp.Src = sp.Src.Filter(srcSeq) - if err := checkSequence(sp.Src, srcSeq); err != nil { - return err + if len(sp.Src) != len(srcSeq) { + return fmt.Errorf("src packet not found packetLength=%d selectedLength=%d", len(sp.Src), len(srcSeq)) } } if len(dstSeq) > 0 { sp.Dst = sp.Dst.Filter(dstSeq) - if err := checkSequence(sp.Dst, dstSeq); err != nil { - return err + if len(sp.Dst) != len(dstSeq) { + return fmt.Errorf("dst packet not found packetLength=%d selectedLength=%d", len(sp.Dst), len(dstSeq)) } } return nil