Skip to content

Commit

Permalink
Merge pull request #130 from yoshidan/add_seq_opt
Browse files Browse the repository at this point in the history
Add `src-seqs` and `dst-seqs` option to `tx acks` and `tx relay`
  • Loading branch information
siburu authored Dec 20, 2023
2 parents ae204cd + a042abd commit c226f1b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
44 changes: 44 additions & 0 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -230,6 +233,11 @@ func relayMsgsCmd(ctx *config.Context) *cobra.Command {
if err != nil {
return err
}
srcSeq := getUint64Slice(flagSrcSeqs)
dstSeq := getUint64Slice(flagDstSeqs)
if err = tryFilterRelayPackets(sp, srcSeq, dstSeq); err != nil {
return err
}

msgs := core.NewRelayMsgs()

Expand All @@ -251,13 +259,17 @@ 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
}

func relayAcksCmd(ctx *config.Context) *cobra.Command {
const (
flagDoRefresh = "do-refresh"
flagSrcSeqs = "src-seqs"
flagDstSeqs = "dst-seqs"
)
const (
defaultDoRefresh = false
Expand Down Expand Up @@ -291,6 +303,11 @@ func relayAcksCmd(ctx *config.Context) *cobra.Command {
if err != nil {
return err
}
srcSeq := getUint64Slice(flagSrcSeqs)
dstSeq := getUint64Slice(flagDstSeqs)
if err = tryFilterRelayPackets(sp, srcSeq, dstSeq); err != nil {
return err
}

msgs := core.NewRelayMsgs()

Expand All @@ -312,5 +329,32 @@ 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 {
if len(srcSeq) > 0 {
sp.Src = sp.Src.Filter(srcSeq)
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 len(sp.Dst) != len(dstSeq) {
return fmt.Errorf("dst packet not found packetLength=%d selectedLength=%d", len(sp.Dst), len(dstSeq))
}
}
return nil
}

func getUint64Slice(key string) []uint64 {
org := viper.GetIntSlice(key)
ret := make([]uint64, len(org))
for i, e := range org {
ret[i] = uint64(e)
}
return ret
}
4 changes: 2 additions & 2 deletions tests/cases/tm2tm/scripts/test-tx
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/tmmock2tmmock/scripts/test-tx
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand Down

0 comments on commit c226f1b

Please sign in to comment.