From 3ba1c3381e7a01cab7ea5b328b3588955dde5d48 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Wed, 27 Sep 2023 16:38:34 +0900 Subject: [PATCH 01/23] Optimize Relay Signed-off-by: Dongri Jin --- cmd/service.go | 16 ++- core/service.go | 59 +++++++-- tests/cases/tmmock2tmmock/Makefile | 4 + .../cases/tmmock2tmmock/scripts/test-service | 114 ++++++++++++++++++ 4 files changed, 175 insertions(+), 18 deletions(-) create mode 100755 tests/cases/tmmock2tmmock/scripts/test-service diff --git a/cmd/service.go b/cmd/service.go index 257582e1..ab0bb526 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -27,12 +27,16 @@ func serviceCmd(ctx *config.Context) *cobra.Command { func startCmd(ctx *config.Context) *cobra.Command { const ( - flagRelayInterval = "relay-interval" - flagPrometheusAddr = "prometheus-addr" + flagRelayInterval = "relay-interval" + flagPrometheusAddr = "prometheus-addr" + flagRelayOptimizeInterval = "relay-optimize-interval" + flagRelayOptimizeCount = "relay-optimize-count" ) const ( - defaultRelayInterval = 3 * time.Second - defaultPrometheusAddr = "localhost:2223" + defaultRelayInterval = 3 * time.Second + defaultPrometheusAddr = "localhost:2223" + defaultRelayOptimizeInterval = 10 * time.Second + defaultRelayOptimizeCount = 5 ) cmd := &cobra.Command{ @@ -60,10 +64,12 @@ func startCmd(ctx *config.Context) *cobra.Command { if err := st.SetupRelay(context.TODO(), c[src], c[dst]); err != nil { return err } - return core.StartService(context.Background(), st, c[src], c[dst], viper.GetDuration(flagRelayInterval)) + return core.StartService(context.Background(), st, c[src], c[dst], viper.GetDuration(flagRelayInterval), viper.GetDuration(flagRelayOptimizeInterval), viper.GetInt64(flagRelayOptimizeCount)) }, } cmd.Flags().Duration(flagRelayInterval, defaultRelayInterval, "time interval to perform relays") cmd.Flags().String(flagPrometheusAddr, defaultPrometheusAddr, "host address to which the prometheus exporter listens") + cmd.Flags().Duration(flagRelayOptimizeInterval, defaultRelayOptimizeInterval, "time interval to perform relays optimization") + cmd.Flags().Int64(flagRelayOptimizeCount, defaultRelayOptimizeCount, "number of packets to relays optimization") return cmd } diff --git a/core/service.go b/core/service.go index abc8162a..9be1fdcc 100644 --- a/core/service.go +++ b/core/service.go @@ -7,32 +7,48 @@ import ( retry "github.com/avast/retry-go" ) +var currentTime = time.Now() + // StartService starts a relay service -func StartService(ctx context.Context, st StrategyI, src, dst *ProvableChain, relayInterval time.Duration) error { +func StartService( + ctx context.Context, + st StrategyI, + src, dst *ProvableChain, + relayInterval, relayOptimizeInterval time.Duration, + relayOptimizeCount int64) error { sh, err := NewSyncHeaders(src, dst) if err != nil { return err } - srv := NewRelayService(st, src, dst, sh, relayInterval) + srv := NewRelayService(st, src, dst, sh, relayInterval, relayOptimizeInterval, relayOptimizeCount) return srv.Start(ctx) } type RelayService struct { - src *ProvableChain - dst *ProvableChain - st StrategyI - sh SyncHeaders - interval time.Duration + src *ProvableChain + dst *ProvableChain + st StrategyI + sh SyncHeaders + interval time.Duration + optimizeInterval time.Duration + optimizeCount int64 } // NewRelayService returns a new service -func NewRelayService(st StrategyI, src, dst *ProvableChain, sh SyncHeaders, interval time.Duration) *RelayService { +func NewRelayService( + st StrategyI, + src, dst *ProvableChain, + sh SyncHeaders, + interval, optimizeInterval time.Duration, + optimizeCount int64) *RelayService { return &RelayService{ - src: src, - dst: dst, - st: st, - sh: sh, - interval: interval, + src: src, + dst: dst, + st: st, + sh: sh, + interval: interval, + optimizeInterval: optimizeInterval, + optimizeCount: optimizeCount, } } @@ -118,3 +134,20 @@ func (srv *RelayService) Serve(ctx context.Context) error { return nil } + +func optimizeRelay(pseqs RelayPackets, optimizeInterval time.Duration, optimizeCount int64) bool { + // time interval + elapseTime := time.Since(currentTime) + if elapseTime >= optimizeInterval { + currentTime = time.Now() + return true + } + // packet count + srcPacketCount := len(pseqs.Src) + dstPacketCount := len(pseqs.Dst) + if int64(srcPacketCount) >= optimizeCount || int64(dstPacketCount) >= optimizeCount { + return true + } + + return false +} diff --git a/tests/cases/tmmock2tmmock/Makefile b/tests/cases/tmmock2tmmock/Makefile index d1c56efe..29e90605 100644 --- a/tests/cases/tmmock2tmmock/Makefile +++ b/tests/cases/tmmock2tmmock/Makefile @@ -14,6 +14,10 @@ test: ./scripts/handshake ./scripts/test-tx +.PHONY: test-service +test-service: + ./scripts/test-service + .PHONY: network-down network-down: TAG=${DOCKER_TAG} $(DOCKER_COMPOSE) \ diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service new file mode 100755 index 00000000..20d89005 --- /dev/null +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -0,0 +1,114 @@ +#!/bin/bash + +: <<'END_COMMENT' +* relay-interval = 10s +* relay-optimize-interval = 15s +* relay-optimize-count = 3 + +- relay service [query = 0, time = 0] -> skip + - transfer + - + - + - finality + - query = 1 + - + - + - + - +- relay service [query = 1, time = 10] -> skip + - transfer + - + - + - finality + - query = 2 + - + - + - + - +- relay service [query = 2, time = 20] -> exec (time) + - transfer x 3 + - + - + - finality + - query 3 + - + - + - + - +- relay service [query = 3, time = 10] -> exec (count) +END_COMMENT + +set -eux + +SCRIPT_DIR=$(cd $(dirname $0); pwd) +RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly +RLY="${RLY_BINARY} --debug" + +TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) +TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) + +RETRY_COUNT=5 +RETRY_INTERVAL=1 + +${RLY} service start ibc01 --relay-interval 10s --relay-optimize-interval 15s --relay-optimize-count 3 & +RLY_PID=$! + +# transfer a token +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +sleep 3 # finality_delay + +# query unrelayed-packets 1 +unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') +if [ $unrelayed_packets -ne 1 ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 +fi + +sleep 7 # wait for relay-interval +echo "xxxxxxx relay service -> skip xxxxxx" + +# transfer a token +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +sleep 3 # finality_delay + +# query unrelayed-packets 2 +unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') +if [ $unrelayed_packets -ne 2 ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 +fi + +sleep 7 # wait for relay-interval +echo "xxxxxxx relay service -> exec - time xxxxxx" + +# transfer a token x 3 +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +sleep 3 # finality_delay + +# query unrelayed-packets 3 +unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') +if [ $unrelayed_packets -ne 3 ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 +fi + +sleep 7 # wait for relay-interval +echo "xxxxxxx relay service -> exec - count xxxxxx" + +# wait for relay service to execute +for i in `seq $RETRY_COUNT` +do + echo "[try:$i] waiting for sendPacket finalization ..." + sleep $RETRY_INTERVAL + unrelayed=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') + if [ $unrelayed -eq 0 ]; then + break + fi +done + +kill $RLY_PID From a48bbecbd510f864a46e30a0b94f620c14306a99 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 3 Oct 2023 10:57:18 +0900 Subject: [PATCH 02/23] Fix curerntTime Signed-off-by: Dongri Jin --- core/service.go | 14 ++++++-------- tests/cases/tmmock2tmmock/scripts/test-service | 8 ++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/core/service.go b/core/service.go index 9be1fdcc..59d9801d 100644 --- a/core/service.go +++ b/core/service.go @@ -7,8 +7,6 @@ import ( retry "github.com/avast/retry-go" ) -var currentTime = time.Now() - // StartService starts a relay service func StartService( ctx context.Context, @@ -32,6 +30,7 @@ type RelayService struct { interval time.Duration optimizeInterval time.Duration optimizeCount int64 + currentTime time.Time } // NewRelayService returns a new service @@ -49,6 +48,7 @@ func NewRelayService( interval: interval, optimizeInterval: optimizeInterval, optimizeCount: optimizeCount, + currentTime: time.Now(), } } @@ -135,19 +135,17 @@ func (srv *RelayService) Serve(ctx context.Context) error { return nil } -func optimizeRelay(pseqs RelayPackets, optimizeInterval time.Duration, optimizeCount int64) bool { +func (srv *RelayService) optimizeRelay(pseqs RelayPackets) bool { // time interval - elapseTime := time.Since(currentTime) - if elapseTime >= optimizeInterval { - currentTime = time.Now() + elapseTime := time.Since(srv.currentTime) + if elapseTime >= srv.optimizeInterval { return true } // packet count srcPacketCount := len(pseqs.Src) dstPacketCount := len(pseqs.Dst) - if int64(srcPacketCount) >= optimizeCount || int64(dstPacketCount) >= optimizeCount { + if int64(srcPacketCount) >= srv.optimizeCount || int64(dstPacketCount) >= srv.optimizeCount { return true } - return false } diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 20d89005..9519e819 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -6,10 +6,10 @@ * relay-optimize-count = 3 - relay service [query = 0, time = 0] -> skip - - transfer - - - - - - finality + - transfer + - + - + - finality - query = 1 - - From 6cde7b118256e97e45a7cdc93c7cdb69f8c48a8c Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Wed, 18 Oct 2023 09:13:35 +0900 Subject: [PATCH 03/23] Add src, dst current time Signed-off-by: Dongri Jin --- core/service.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/core/service.go b/core/service.go index 59d9801d..ce575bdd 100644 --- a/core/service.go +++ b/core/service.go @@ -30,7 +30,8 @@ type RelayService struct { interval time.Duration optimizeInterval time.Duration optimizeCount int64 - currentTime time.Time + srcCurrentTime time.Time + dstCurrentTime time.Time } // NewRelayService returns a new service @@ -48,7 +49,8 @@ func NewRelayService( interval: interval, optimizeInterval: optimizeInterval, optimizeCount: optimizeCount, - currentTime: time.Now(), + srcCurrentTime: time.Now(), + dstCurrentTime: time.Now(), } } @@ -136,16 +138,22 @@ func (srv *RelayService) Serve(ctx context.Context) error { } func (srv *RelayService) optimizeRelay(pseqs RelayPackets) bool { - // time interval - elapseTime := time.Since(srv.currentTime) - if elapseTime >= srv.optimizeInterval { - return true - } // packet count srcPacketCount := len(pseqs.Src) dstPacketCount := len(pseqs.Dst) if int64(srcPacketCount) >= srv.optimizeCount || int64(dstPacketCount) >= srv.optimizeCount { return true } + // time interval + if time.Since(srv.srcCurrentTime) >= srv.optimizeInterval || time.Since(srv.dstCurrentTime) >= srv.optimizeInterval { + return true + } + // set current time + if srcPacketCount > 0 { + srv.srcCurrentTime = time.Now() + } + if dstPacketCount > 0 { + srv.dstCurrentTime = time.Now() + } return false } From 1ccd6c0f8afe53fe18343fa55b58f1dded592b04 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Wed, 8 Nov 2023 10:09:02 +0900 Subject: [PATCH 04/23] Add optimizeRelay Signed-off-by: Dongri Jin --- core/service.go | 26 +++++++++++++++----------- tests/cases/tmmock2tmmock/Makefile | 3 --- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/core/service.go b/core/service.go index ce575bdd..053ea3e4 100644 --- a/core/service.go +++ b/core/service.go @@ -116,19 +116,23 @@ func (srv *RelayService) Serve(ctx context.Context) error { } // relay packets if unrelayed seqs exist - if m, err := srv.st.RelayPackets(srv.src, srv.dst, pseqs, srv.sh); err != nil { - logger.Error("failed to relay packets", err) - return err - } else { - msgs.Merge(m) + if srv.optimizeRelay(pseqs) { + if m, err := srv.st.RelayPackets(srv.src, srv.dst, pseqs, srv.sh); err != nil { + logger.Error("failed to relay packets", err) + return err + } else { + msgs.Merge(m) + } } // relay acks if unrelayed seqs exist - if m, err := srv.st.RelayAcknowledgements(srv.src, srv.dst, aseqs, srv.sh); err != nil { - logger.Error("failed to relay acknowledgements", err) - return err - } else { - msgs.Merge(m) + if srv.optimizeRelay(aseqs) { + if m, err := srv.st.RelayAcknowledgements(srv.src, srv.dst, aseqs, srv.sh); err != nil { + logger.Error("failed to relay acknowledgements", err) + return err + } else { + msgs.Merge(m) + } } // send all msgs to src/dst chains @@ -137,7 +141,7 @@ func (srv *RelayService) Serve(ctx context.Context) error { return nil } -func (srv *RelayService) optimizeRelay(pseqs RelayPackets) bool { +func (srv *RelayService) optimizeRelay(pseqs *RelayPackets) bool { // packet count srcPacketCount := len(pseqs.Src) dstPacketCount := len(pseqs.Dst) diff --git a/tests/cases/tmmock2tmmock/Makefile b/tests/cases/tmmock2tmmock/Makefile index 29e90605..f4697b83 100644 --- a/tests/cases/tmmock2tmmock/Makefile +++ b/tests/cases/tmmock2tmmock/Makefile @@ -13,9 +13,6 @@ test: ./scripts/init-rly ./scripts/handshake ./scripts/test-tx - -.PHONY: test-service -test-service: ./scripts/test-service .PHONY: network-down From 37c0f444c2df9259b7a77f77ca8c3105927dddbb Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 14 Nov 2023 09:37:49 +0900 Subject: [PATCH 05/23] Refactoring optimize relay Signed-off-by: Dongri Jin --- core/naive-strategy.go | 45 ++++-- core/service.go | 150 +++++++++++++----- core/strategies.go | 3 + tests/cases/tm2tm/Makefile | 1 + tests/cases/tm2tm/scripts/test-service | 114 +++++++++++++ .../cases/tmmock2tmmock/scripts/test-service | 4 +- 6 files changed, 258 insertions(+), 59 deletions(-) create mode 100755 tests/cases/tm2tm/scripts/test-service diff --git a/core/naive-strategy.go b/core/naive-strategy.go index 3f401c85..0e208c03 100644 --- a/core/naive-strategy.go +++ b/core/naive-strategy.go @@ -25,6 +25,9 @@ type NaiveStrategy struct { dstNoAck bool metrics naiveStrategyMetrics + + srcSkipRelay bool + dstSkipRelay bool } type naiveStrategyMetrics struct { @@ -225,21 +228,26 @@ func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, return nil, err } - msgs.Dst, err = collectPackets(srcCtx, src, rp.Src, dstAddress) - if err != nil { - logger.Error( - "error collecting packets", - err, - ) - return nil, err + if !st.srcSkipRelay { + msgs.Dst, err = collectPackets(srcCtx, src, rp.Src, dstAddress) + if err != nil { + logger.Error( + "error collecting packets", + err, + ) + return nil, err + } } - msgs.Src, err = collectPackets(dstCtx, dst, rp.Dst, srcAddress) - if err != nil { - logger.Error( - "error collecting packets", - err, - ) - return nil, err + + if !st.dstSkipRelay { + msgs.Src, err = collectPackets(dstCtx, dst, rp.Dst, srcAddress) + if err != nil { + logger.Error( + "error collecting packets", + err, + ) + return nil, err + } } if len(msgs.Dst) == 0 && len(msgs.Src) == 0 { @@ -440,13 +448,13 @@ func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *Rela return nil, err } - if !st.dstNoAck { + if !st.dstNoAck && !st.srcSkipRelay { msgs.Dst, err = collectAcks(srcCtx, src, rp.Src, dstAddress) if err != nil { return nil, err } } - if !st.srcNoAck { + if !st.srcNoAck && !st.dstSkipRelay { msgs.Src, err = collectAcks(dstCtx, dst, rp.Dst, srcAddress) if err != nil { return nil, err @@ -568,6 +576,11 @@ func (st *NaiveStrategy) Send(src, dst Chain, msgs *RelayMsgs) { ) } +func (st *NaiveStrategy) SkipRelay(src, dst bool) { + st.srcSkipRelay = src + st.dstSkipRelay = dst +} + func (st *naiveStrategyMetrics) updateBacklogMetrics(ctx context.Context, src, dst ChainInfo, newSrcBacklog, newDstBacklog PacketInfoList) error { srcAttrs := []attribute.KeyValue{ attribute.Key("chain_id").String(src.ChainID()), diff --git a/core/service.go b/core/service.go index 053ea3e4..cb12f31b 100644 --- a/core/service.go +++ b/core/service.go @@ -23,15 +23,27 @@ func StartService( } type RelayService struct { - src *ProvableChain - dst *ProvableChain - st StrategyI - sh SyncHeaders - interval time.Duration + src *ProvableChain + dst *ProvableChain + st StrategyI + sh SyncHeaders + interval time.Duration + optimizeRelay OptimizeRelay +} + +type OptimizeRelay struct { optimizeInterval time.Duration optimizeCount int64 - srcCurrentTime time.Time - dstCurrentTime time.Time + + srcRelayPacketStartTime WatchStartTime + dstRelayPacketStartTime WatchStartTime + srcRelayAckStartTime WatchStartTime + dstRelayAckStartTime WatchStartTime +} + +type WatchStartTime struct { + Reset bool + StartTime time.Time } // NewRelayService returns a new service @@ -42,15 +54,31 @@ func NewRelayService( interval, optimizeInterval time.Duration, optimizeCount int64) *RelayService { return &RelayService{ - src: src, - dst: dst, - st: st, - sh: sh, - interval: interval, - optimizeInterval: optimizeInterval, - optimizeCount: optimizeCount, - srcCurrentTime: time.Now(), - dstCurrentTime: time.Now(), + src: src, + dst: dst, + st: st, + sh: sh, + interval: interval, + optimizeRelay: OptimizeRelay{ + optimizeInterval: optimizeInterval, + optimizeCount: optimizeCount, + srcRelayPacketStartTime: WatchStartTime{ + Reset: false, + StartTime: time.Now(), + }, + dstRelayPacketStartTime: WatchStartTime{ + Reset: false, + StartTime: time.Now(), + }, + srcRelayAckStartTime: WatchStartTime{ + Reset: false, + StartTime: time.Now(), + }, + dstRelayAckStartTime: WatchStartTime{ + Reset: false, + StartTime: time.Now(), + }, + }, } } @@ -115,24 +143,52 @@ func (srv *RelayService) Serve(ctx context.Context) error { msgs.Merge(m) } + // reset watch start time for packets + if len(pseqs.Src) > 0 { + resetWatchStartTime(&srv.optimizeRelay.srcRelayPacketStartTime) + } + if len(pseqs.Dst) > 0 { + resetWatchStartTime(&srv.optimizeRelay.dstRelayPacketStartTime) + } + // relay packets if unrelayed seqs exist - if srv.optimizeRelay(pseqs) { - if m, err := srv.st.RelayPackets(srv.src, srv.dst, pseqs, srv.sh); err != nil { - logger.Error("failed to relay packets", err) - return err - } else { - msgs.Merge(m) + srcRelayPackets, dstRelayPackets := srv.shouldExecuteRelay(pseqs, srv.optimizeRelay.srcRelayPacketStartTime, srv.optimizeRelay.dstRelayPacketStartTime) + srv.st.SkipRelay(!srcRelayPackets, !dstRelayPackets) + if m, err := srv.st.RelayPackets(srv.src, srv.dst, pseqs, srv.sh); err != nil { + logger.Error("failed to relay packets", err) + return err + } else { + if srcRelayPackets { + srv.optimizeRelay.srcRelayPacketStartTime.Reset = true } + if dstRelayPackets { + srv.optimizeRelay.dstRelayPacketStartTime.Reset = true + } + msgs.Merge(m) + } + + // reset watch start time for acks + if len(aseqs.Src) > 0 { + resetWatchStartTime(&srv.optimizeRelay.srcRelayAckStartTime) + } + if len(aseqs.Dst) > 0 { + resetWatchStartTime(&srv.optimizeRelay.dstRelayAckStartTime) } // relay acks if unrelayed seqs exist - if srv.optimizeRelay(aseqs) { - if m, err := srv.st.RelayAcknowledgements(srv.src, srv.dst, aseqs, srv.sh); err != nil { - logger.Error("failed to relay acknowledgements", err) - return err - } else { - msgs.Merge(m) + srcRelayAcks, dstRelayAcks := srv.shouldExecuteRelay(aseqs, srv.optimizeRelay.srcRelayAckStartTime, srv.optimizeRelay.dstRelayAckStartTime) + srv.st.SkipRelay(!srcRelayAcks, !dstRelayAcks) + if m, err := srv.st.RelayAcknowledgements(srv.src, srv.dst, aseqs, srv.sh); err != nil { + logger.Error("failed to relay acknowledgements", err) + return err + } else { + if srcRelayAcks { + srv.optimizeRelay.srcRelayAckStartTime.Reset = true + } + if dstRelayAcks { + srv.optimizeRelay.dstRelayAckStartTime.Reset = true } + msgs.Merge(m) } // send all msgs to src/dst chains @@ -141,23 +197,35 @@ func (srv *RelayService) Serve(ctx context.Context) error { return nil } -func (srv *RelayService) optimizeRelay(pseqs *RelayPackets) bool { +func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcRelayStartTime, dstRelayStartTime WatchStartTime) (bool, bool) { + srcRelay := false + dstRelay := false + // packet count - srcPacketCount := len(pseqs.Src) - dstPacketCount := len(pseqs.Dst) - if int64(srcPacketCount) >= srv.optimizeCount || int64(dstPacketCount) >= srv.optimizeCount { - return true + srcRelayCount := len(seqs.Src) + dstRelayCount := len(seqs.Dst) + if int64(srcRelayCount) >= srv.optimizeRelay.optimizeCount { + srcRelay = true + } + if int64(dstRelayCount) >= srv.optimizeRelay.optimizeCount { + dstRelay = true } + // time interval - if time.Since(srv.srcCurrentTime) >= srv.optimizeInterval || time.Since(srv.dstCurrentTime) >= srv.optimizeInterval { - return true + if time.Since(srcRelayStartTime.StartTime) >= srv.optimizeRelay.optimizeInterval { + srcRelay = true } - // set current time - if srcPacketCount > 0 { - srv.srcCurrentTime = time.Now() + if time.Since(dstRelayStartTime.StartTime) >= srv.optimizeRelay.optimizeInterval { + dstRelay = true } - if dstPacketCount > 0 { - srv.dstCurrentTime = time.Now() + + return srcRelay, dstRelay +} + +func resetWatchStartTime(watchStartTime *WatchStartTime) { + if !watchStartTime.Reset { + return } - return false + watchStartTime.Reset = false + watchStartTime.StartTime = time.Now() } diff --git a/core/strategies.go b/core/strategies.go index 46edae59..a8c26a15 100644 --- a/core/strategies.go +++ b/core/strategies.go @@ -32,6 +32,9 @@ type StrategyI interface { // Send executes submission of msgs to src/dst chains Send(src, dst Chain, msgs *RelayMsgs) + + // SkipRelay skips relay on `src` and `dst` + SkipRelay(src, dst bool) } // StrategyCfg defines which relaying strategy to take for a given path diff --git a/tests/cases/tm2tm/Makefile b/tests/cases/tm2tm/Makefile index ed0dd01f..1cf67bdd 100644 --- a/tests/cases/tm2tm/Makefile +++ b/tests/cases/tm2tm/Makefile @@ -13,6 +13,7 @@ test: ./scripts/init-rly ./scripts/handshake ./scripts/test-tx + ./scripts/test-service .PHONY: network-down network-down: diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service new file mode 100755 index 00000000..73f39eac --- /dev/null +++ b/tests/cases/tm2tm/scripts/test-service @@ -0,0 +1,114 @@ +#!/bin/bash + +: <<'END_COMMENT' +* relay-interval = 10s +* relay-optimize-interval = 15s +* relay-optimize-count = 3 + +- relay service [query = 0, time = 0] -> skip + - transfer + - + - + - finality + - query = 1 + - + - + - + - +- relay service [query = 1, time = 10] -> skip + - transfer + - + - + - finality + - query = 2 + - + - + - + - +- relay service [query = 2, time = 20] -> exec (time) + - transfer x 3 + - + - + - finality + - query 3 + - + - + - + - +- relay service [query = 3, time = 10] -> exec (count) +END_COMMENT + +set -eux + +SCRIPT_DIR=$(cd $(dirname $0); pwd) +RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly +RLY="${RLY_BINARY} --debug" + +TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) +TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) + +RETRY_COUNT=10 +RETRY_INTERVAL=1 + +${RLY} service start ibc01 --relay-interval 10s --relay-optimize-interval 15s --relay-optimize-count 3 & +RLY_PID=$! + +# transfer a token +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +sleep 3 # finality_delay + +# query unrelayed-packets 1 +unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') +if [ $unrelayed_packets -ne 1 ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 +fi + +sleep 7 # wait for relay-interval +echo "xxxxxxx relay service -> skip xxxxxx" + +# transfer a token +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +sleep 3 # finality_delay + +# query unrelayed-packets 2 +unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') +if [ $unrelayed_packets -ne 2 ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 +fi + +sleep 7 # wait for relay-interval +echo "xxxxxxx relay service -> exec - time xxxxxx" + +# transfer a token x 3 +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} +sleep 3 # finality_delay + +# query unrelayed-packets 3 +unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') +if [ $unrelayed_packets -ne 3 ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 +fi + +sleep 20 # wait for relay-interval +echo "xxxxxxx relay service -> exec - count xxxxxx" + +# wait for relay service to execute +for i in `seq $RETRY_COUNT` +do + echo "[try:$i] waiting for sendPacket finalization ..." + sleep $RETRY_INTERVAL + unrelayed=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') + if [ $unrelayed -eq 0 ]; then + break + fi +done + +kill $RLY_PID diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 9519e819..73f39eac 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -47,7 +47,7 @@ RLY="${RLY_BINARY} --debug" TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) -RETRY_COUNT=5 +RETRY_COUNT=10 RETRY_INTERVAL=1 ${RLY} service start ibc01 --relay-interval 10s --relay-optimize-interval 15s --relay-optimize-count 3 & @@ -97,7 +97,7 @@ if [ $unrelayed_packets -ne 3 ]; then exit 1 fi -sleep 7 # wait for relay-interval +sleep 20 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" # wait for relay service to execute From 90a61b7ace659478ec5cc766fa5b64d7a2937f33 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Fri, 17 Nov 2023 11:57:33 +0900 Subject: [PATCH 06/23] * Add src, dst parameter * Fix start time variable * Change relay parameter Signed-off-by: Dongri Jin --- cmd/service.go | 28 ++++-- cmd/tx.go | 4 +- core/naive-strategy.go | 20 ++--- core/service.go | 86 ++++++++++++------- core/strategies.go | 7 +- tests/cases/tm2tm/scripts/test-service | 2 +- .../cases/tmmock2tmmock/scripts/test-service | 2 +- 7 files changed, 86 insertions(+), 63 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index ab0bb526..6c797b5d 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -27,10 +27,12 @@ func serviceCmd(ctx *config.Context) *cobra.Command { func startCmd(ctx *config.Context) *cobra.Command { const ( - flagRelayInterval = "relay-interval" - flagPrometheusAddr = "prometheus-addr" - flagRelayOptimizeInterval = "relay-optimize-interval" - flagRelayOptimizeCount = "relay-optimize-count" + flagRelayInterval = "relay-interval" + flagPrometheusAddr = "prometheus-addr" + flagSrcRelayOptimizeInterval = "src-relay-optimize-interval" + flagSrcRelayOptimizeCount = "src-relay-optimize-count" + flagDstRelayOptimizeInterval = "dst-relay-optimize-interval" + flagDstRelayOptimizeCount = "dst-relay-optimize-count" ) const ( defaultRelayInterval = 3 * time.Second @@ -64,12 +66,24 @@ func startCmd(ctx *config.Context) *cobra.Command { if err := st.SetupRelay(context.TODO(), c[src], c[dst]); err != nil { return err } - return core.StartService(context.Background(), st, c[src], c[dst], viper.GetDuration(flagRelayInterval), viper.GetDuration(flagRelayOptimizeInterval), viper.GetInt64(flagRelayOptimizeCount)) + return core.StartService( + context.Background(), + st, + c[src], + c[dst], + viper.GetDuration(flagRelayInterval), + viper.GetDuration(flagSrcRelayOptimizeInterval), + viper.GetInt64(flagSrcRelayOptimizeCount), + viper.GetDuration(flagDstRelayOptimizeInterval), + viper.GetInt64(flagDstRelayOptimizeCount), + ) }, } cmd.Flags().Duration(flagRelayInterval, defaultRelayInterval, "time interval to perform relays") cmd.Flags().String(flagPrometheusAddr, defaultPrometheusAddr, "host address to which the prometheus exporter listens") - cmd.Flags().Duration(flagRelayOptimizeInterval, defaultRelayOptimizeInterval, "time interval to perform relays optimization") - cmd.Flags().Int64(flagRelayOptimizeCount, defaultRelayOptimizeCount, "number of packets to relays optimization") + cmd.Flags().Duration(flagSrcRelayOptimizeInterval, defaultRelayOptimizeInterval, "time interval to perform relays optimization on source chain") + cmd.Flags().Int64(flagSrcRelayOptimizeCount, defaultRelayOptimizeCount, "number of packets to relays optimization on source chain") + cmd.Flags().Duration(flagDstRelayOptimizeInterval, defaultRelayOptimizeInterval, "time interval to perform relays optimization on destination chain") + cmd.Flags().Int64(flagDstRelayOptimizeCount, defaultRelayOptimizeCount, "number of packets to relays optimization on destination chain") return cmd } diff --git a/cmd/tx.go b/cmd/tx.go index 60a6c78d..08b68ee8 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -240,7 +240,7 @@ func relayMsgsCmd(ctx *config.Context) *cobra.Command { msgs.Merge(m) } - if m, err := st.RelayPackets(c[src], c[dst], sp, sh); err != nil { + if m, err := st.RelayPackets(c[src], c[dst], sp, sh, true, true); err != nil { return err } else { msgs.Merge(m) @@ -301,7 +301,7 @@ func relayAcksCmd(ctx *config.Context) *cobra.Command { msgs.Merge(m) } - if m, err := st.RelayAcknowledgements(c[src], c[dst], sp, sh); err != nil { + if m, err := st.RelayAcknowledgements(c[src], c[dst], sp, sh, true, true); err != nil { return err } else { msgs.Merge(m) diff --git a/core/naive-strategy.go b/core/naive-strategy.go index 0e208c03..555a2ca3 100644 --- a/core/naive-strategy.go +++ b/core/naive-strategy.go @@ -25,9 +25,6 @@ type NaiveStrategy struct { dstNoAck bool metrics naiveStrategyMetrics - - srcSkipRelay bool - dstSkipRelay bool } type naiveStrategyMetrics struct { @@ -202,7 +199,7 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader }, nil } -func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders) (*RelayMsgs, error) { +func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, srcOptimizeRelay, dstOptimizeRelay bool) (*RelayMsgs, error) { logger := GetChannelPairLogger(src, dst) defer logger.TimeTrack(time.Now(), "RelayPackets", "num_src", len(rp.Src), "num_dst", len(rp.Dst)) @@ -228,7 +225,7 @@ func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, return nil, err } - if !st.srcSkipRelay { + if srcOptimizeRelay { msgs.Dst, err = collectPackets(srcCtx, src, rp.Src, dstAddress) if err != nil { logger.Error( @@ -239,7 +236,7 @@ func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, } } - if !st.dstSkipRelay { + if dstOptimizeRelay { msgs.Src, err = collectPackets(dstCtx, dst, rp.Dst, srcAddress) if err != nil { logger.Error( @@ -423,7 +420,7 @@ func logPacketsRelayed(src, dst Chain, num int, obj string, dir string) { ) } -func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders) (*RelayMsgs, error) { +func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, srcOptimizeRelay, dstOptimizeRelay bool) (*RelayMsgs, error) { logger := GetChannelPairLogger(src, dst) defer logger.TimeTrack(time.Now(), "RelayAcknowledgements", "num_src", len(rp.Src), "num_dst", len(rp.Dst)) @@ -448,13 +445,13 @@ func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *Rela return nil, err } - if !st.dstNoAck && !st.srcSkipRelay { + if !st.dstNoAck && srcOptimizeRelay { msgs.Dst, err = collectAcks(srcCtx, src, rp.Src, dstAddress) if err != nil { return nil, err } } - if !st.srcNoAck && !st.dstSkipRelay { + if !st.srcNoAck && dstOptimizeRelay { msgs.Src, err = collectAcks(dstCtx, dst, rp.Dst, srcAddress) if err != nil { return nil, err @@ -576,11 +573,6 @@ func (st *NaiveStrategy) Send(src, dst Chain, msgs *RelayMsgs) { ) } -func (st *NaiveStrategy) SkipRelay(src, dst bool) { - st.srcSkipRelay = src - st.dstSkipRelay = dst -} - func (st *naiveStrategyMetrics) updateBacklogMetrics(ctx context.Context, src, dst ChainInfo, newSrcBacklog, newDstBacklog PacketInfoList) error { srcAttrs := []attribute.KeyValue{ attribute.Key("chain_id").String(src.ChainID()), diff --git a/core/service.go b/core/service.go index cb12f31b..811b5719 100644 --- a/core/service.go +++ b/core/service.go @@ -12,13 +12,27 @@ func StartService( ctx context.Context, st StrategyI, src, dst *ProvableChain, - relayInterval, relayOptimizeInterval time.Duration, - relayOptimizeCount int64) error { + relayInterval, + srcRelayOptimizeInterval time.Duration, + srcRelayOptimizeCount int64, + dstRelayOptimizaInterval time.Duration, + dstRelayOptimizeCount int64, +) error { sh, err := NewSyncHeaders(src, dst) if err != nil { return err } - srv := NewRelayService(st, src, dst, sh, relayInterval, relayOptimizeInterval, relayOptimizeCount) + srv := NewRelayService( + st, + src, + dst, + sh, + relayInterval, + srcRelayOptimizeInterval, + srcRelayOptimizeCount, + dstRelayOptimizaInterval, + dstRelayOptimizeCount, + ) return srv.Start(ctx) } @@ -32,8 +46,10 @@ type RelayService struct { } type OptimizeRelay struct { - optimizeInterval time.Duration - optimizeCount int64 + srcOptimizeInterval time.Duration + srcOptimizeCount int64 + dstOptimizeInterval time.Duration + dstOptimizeCount int64 srcRelayPacketStartTime WatchStartTime dstRelayPacketStartTime WatchStartTime @@ -42,8 +58,8 @@ type OptimizeRelay struct { } type WatchStartTime struct { - Reset bool - StartTime time.Time + AlreadySet bool + StartTime time.Time } // NewRelayService returns a new service @@ -51,8 +67,12 @@ func NewRelayService( st StrategyI, src, dst *ProvableChain, sh SyncHeaders, - interval, optimizeInterval time.Duration, - optimizeCount int64) *RelayService { + interval, + srcOptimizeInterval time.Duration, + srcOptimizeCount int64, + dstOptimizeInterval time.Duration, + dstOptimizeCount int64, +) *RelayService { return &RelayService{ src: src, dst: dst, @@ -60,23 +80,25 @@ func NewRelayService( sh: sh, interval: interval, optimizeRelay: OptimizeRelay{ - optimizeInterval: optimizeInterval, - optimizeCount: optimizeCount, + srcOptimizeInterval: srcOptimizeInterval, + srcOptimizeCount: srcOptimizeCount, + dstOptimizeInterval: dstOptimizeInterval, + dstOptimizeCount: dstOptimizeCount, srcRelayPacketStartTime: WatchStartTime{ - Reset: false, - StartTime: time.Now(), + AlreadySet: true, + StartTime: time.Now(), }, dstRelayPacketStartTime: WatchStartTime{ - Reset: false, - StartTime: time.Now(), + AlreadySet: true, + StartTime: time.Now(), }, srcRelayAckStartTime: WatchStartTime{ - Reset: false, - StartTime: time.Now(), + AlreadySet: true, + StartTime: time.Now(), }, dstRelayAckStartTime: WatchStartTime{ - Reset: false, - StartTime: time.Now(), + AlreadySet: true, + StartTime: time.Now(), }, }, } @@ -153,16 +175,15 @@ func (srv *RelayService) Serve(ctx context.Context) error { // relay packets if unrelayed seqs exist srcRelayPackets, dstRelayPackets := srv.shouldExecuteRelay(pseqs, srv.optimizeRelay.srcRelayPacketStartTime, srv.optimizeRelay.dstRelayPacketStartTime) - srv.st.SkipRelay(!srcRelayPackets, !dstRelayPackets) - if m, err := srv.st.RelayPackets(srv.src, srv.dst, pseqs, srv.sh); err != nil { + if m, err := srv.st.RelayPackets(srv.src, srv.dst, pseqs, srv.sh, srcRelayPackets, dstRelayPackets); err != nil { logger.Error("failed to relay packets", err) return err } else { if srcRelayPackets { - srv.optimizeRelay.srcRelayPacketStartTime.Reset = true + srv.optimizeRelay.srcRelayPacketStartTime.AlreadySet = false } if dstRelayPackets { - srv.optimizeRelay.dstRelayPacketStartTime.Reset = true + srv.optimizeRelay.dstRelayPacketStartTime.AlreadySet = false } msgs.Merge(m) } @@ -177,16 +198,15 @@ func (srv *RelayService) Serve(ctx context.Context) error { // relay acks if unrelayed seqs exist srcRelayAcks, dstRelayAcks := srv.shouldExecuteRelay(aseqs, srv.optimizeRelay.srcRelayAckStartTime, srv.optimizeRelay.dstRelayAckStartTime) - srv.st.SkipRelay(!srcRelayAcks, !dstRelayAcks) - if m, err := srv.st.RelayAcknowledgements(srv.src, srv.dst, aseqs, srv.sh); err != nil { + if m, err := srv.st.RelayAcknowledgements(srv.src, srv.dst, aseqs, srv.sh, srcRelayAcks, dstRelayAcks); err != nil { logger.Error("failed to relay acknowledgements", err) return err } else { if srcRelayAcks { - srv.optimizeRelay.srcRelayAckStartTime.Reset = true + srv.optimizeRelay.srcRelayAckStartTime.AlreadySet = false } if dstRelayAcks { - srv.optimizeRelay.dstRelayAckStartTime.Reset = true + srv.optimizeRelay.dstRelayAckStartTime.AlreadySet = false } msgs.Merge(m) } @@ -204,18 +224,18 @@ func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcRelayStartTim // packet count srcRelayCount := len(seqs.Src) dstRelayCount := len(seqs.Dst) - if int64(srcRelayCount) >= srv.optimizeRelay.optimizeCount { + if int64(srcRelayCount) >= srv.optimizeRelay.srcOptimizeCount { srcRelay = true } - if int64(dstRelayCount) >= srv.optimizeRelay.optimizeCount { + if int64(dstRelayCount) >= srv.optimizeRelay.dstOptimizeCount { dstRelay = true } // time interval - if time.Since(srcRelayStartTime.StartTime) >= srv.optimizeRelay.optimizeInterval { + if time.Since(srcRelayStartTime.StartTime) >= srv.optimizeRelay.srcOptimizeInterval { srcRelay = true } - if time.Since(dstRelayStartTime.StartTime) >= srv.optimizeRelay.optimizeInterval { + if time.Since(dstRelayStartTime.StartTime) >= srv.optimizeRelay.dstOptimizeInterval { dstRelay = true } @@ -223,9 +243,9 @@ func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcRelayStartTim } func resetWatchStartTime(watchStartTime *WatchStartTime) { - if !watchStartTime.Reset { + if watchStartTime.AlreadySet { return } - watchStartTime.Reset = false + watchStartTime.AlreadySet = true watchStartTime.StartTime = time.Now() } diff --git a/core/strategies.go b/core/strategies.go index a8c26a15..5985749c 100644 --- a/core/strategies.go +++ b/core/strategies.go @@ -18,23 +18,20 @@ type StrategyI interface { UnrelayedPackets(src, dst *ProvableChain, sh SyncHeaders, includeRelayedButUnfinalized bool) (*RelayPackets, error) // RelayPackets executes RecvPacket to the packets contained in `rp` on both chains (`src` and `dst`). - RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders) (*RelayMsgs, error) + RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, srcOptimizeRelay, dstOptimizeRelay bool) (*RelayMsgs, error) // UnrelayedAcknowledgements returns packets to execute AcknowledgePacket to on `src` and `dst`. // `includeRelayedButUnfinalized` decides if the result includes packets of which acknowledgePacket has been executed but not finalized UnrelayedAcknowledgements(src, dst *ProvableChain, sh SyncHeaders, includeRelayedButUnfinalized bool) (*RelayPackets, error) // RelayAcknowledgements executes AcknowledgePacket to the packets contained in `rp` on both chains (`src` and `dst`). - RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders) (*RelayMsgs, error) + RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, srcOptimizeRelay, dstOptimizeRelay bool) (*RelayMsgs, error) // UpdateClients executes UpdateClient only if needed UpdateClients(src, dst *ProvableChain, rpForRecv, rpForAck *RelayPackets, sh SyncHeaders, doRefresh bool) (*RelayMsgs, error) // Send executes submission of msgs to src/dst chains Send(src, dst Chain, msgs *RelayMsgs) - - // SkipRelay skips relay on `src` and `dst` - SkipRelay(src, dst bool) } // StrategyCfg defines which relaying strategy to take for a given path diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 73f39eac..92b4abca 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -50,7 +50,7 @@ TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) RETRY_COUNT=10 RETRY_INTERVAL=1 -${RLY} service start ibc01 --relay-interval 10s --relay-optimize-interval 15s --relay-optimize-count 3 & +${RLY} service start ibc01 --relay-interval 10s --src-relay-optimize-interval 15s --src-relay-optimize-count 3 --dst-relay-optimize-interval 15s --dst-relay-optimize-count 3 & RLY_PID=$! # transfer a token diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 73f39eac..92b4abca 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -50,7 +50,7 @@ TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) RETRY_COUNT=10 RETRY_INTERVAL=1 -${RLY} service start ibc01 --relay-interval 10s --relay-optimize-interval 15s --relay-optimize-count 3 & +${RLY} service start ibc01 --relay-interval 10s --src-relay-optimize-interval 15s --src-relay-optimize-count 3 --dst-relay-optimize-interval 15s --dst-relay-optimize-count 3 & RLY_PID=$! # transfer a token From 07b8a79c774c7d5e68f262ebd8433d5dd74daa68 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Fri, 24 Nov 2023 10:35:14 +0900 Subject: [PATCH 07/23] Fix update clients Signed-off-by: Dongri Jin --- cmd/service.go | 8 +-- cmd/tx.go | 18 +++-- core/naive-strategy.go | 21 +++--- core/service.go | 68 ++++++++++--------- core/strategies.go | 6 +- tests/cases/tm2tm/scripts/test-service | 22 ++++-- .../cases/tmmock2tmmock/scripts/test-service | 22 ++++-- 7 files changed, 99 insertions(+), 66 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index 6c797b5d..e80278e7 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -81,9 +81,9 @@ func startCmd(ctx *config.Context) *cobra.Command { } cmd.Flags().Duration(flagRelayInterval, defaultRelayInterval, "time interval to perform relays") cmd.Flags().String(flagPrometheusAddr, defaultPrometheusAddr, "host address to which the prometheus exporter listens") - cmd.Flags().Duration(flagSrcRelayOptimizeInterval, defaultRelayOptimizeInterval, "time interval to perform relays optimization on source chain") - cmd.Flags().Int64(flagSrcRelayOptimizeCount, defaultRelayOptimizeCount, "number of packets to relays optimization on source chain") - cmd.Flags().Duration(flagDstRelayOptimizeInterval, defaultRelayOptimizeInterval, "time interval to perform relays optimization on destination chain") - cmd.Flags().Int64(flagDstRelayOptimizeCount, defaultRelayOptimizeCount, "number of packets to relays optimization on destination chain") + cmd.Flags().Duration(flagSrcRelayOptimizeInterval, defaultRelayOptimizeInterval, "maximum time interval to delay relays for optimization") + cmd.Flags().Int64(flagSrcRelayOptimizeCount, defaultRelayOptimizeCount, "maximum number of relays to delay for optimization") + cmd.Flags().Duration(flagDstRelayOptimizeInterval, defaultRelayOptimizeInterval, "maximum time interval to delay relays for optimization") + cmd.Flags().Int64(flagDstRelayOptimizeCount, defaultRelayOptimizeCount, "maximum number of relays to delay for optimization") return cmd } diff --git a/cmd/tx.go b/cmd/tx.go index 08b68ee8..fcc71245 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -234,13 +234,18 @@ func relayMsgsCmd(ctx *config.Context) *cobra.Command { msgs := core.NewRelayMsgs() - if m, err := st.UpdateClients(c[src], c[dst], sp, &core.RelayPackets{}, sh, viper.GetBool(flagDoRefresh)); err != nil { + doExecuteRelaySrc := len(sp.Src) > 0 + doExecuteRelayDst := len(sp.Dst) > 0 + doExecuteAckSrc := false + doExecuteAckDst := false + + if m, err := st.UpdateClients(c[src], c[dst], doExecuteRelaySrc, doExecuteRelayDst, doExecuteAckSrc, doExecuteAckDst, sh, viper.GetBool(flagDoRefresh)); err != nil { return err } else { msgs.Merge(m) } - if m, err := st.RelayPackets(c[src], c[dst], sp, sh, true, true); err != nil { + if m, err := st.RelayPackets(c[src], c[dst], sp, sh, doExecuteRelaySrc, doExecuteRelayDst); err != nil { return err } else { msgs.Merge(m) @@ -295,13 +300,18 @@ func relayAcksCmd(ctx *config.Context) *cobra.Command { msgs := core.NewRelayMsgs() - if m, err := st.UpdateClients(c[src], c[dst], &core.RelayPackets{}, sp, sh, viper.GetBool(flagDoRefresh)); err != nil { + doExecuteRelaySrc := false + doExecuteRelayDst := false + doExecuteAckSrc := len(sp.Src) > 0 + doExecuteAckDst := len(sp.Dst) > 0 + + if m, err := st.UpdateClients(c[src], c[dst], doExecuteRelaySrc, doExecuteRelayDst, doExecuteAckSrc, doExecuteAckDst, sh, viper.GetBool(flagDoRefresh)); err != nil { return err } else { msgs.Merge(m) } - if m, err := st.RelayAcknowledgements(c[src], c[dst], sp, sh, true, true); err != nil { + if m, err := st.RelayAcknowledgements(c[src], c[dst], sp, sh, doExecuteAckSrc, doExecuteAckDst); err != nil { return err } else { msgs.Merge(m) diff --git a/core/naive-strategy.go b/core/naive-strategy.go index 555a2ca3..3365e532 100644 --- a/core/naive-strategy.go +++ b/core/naive-strategy.go @@ -199,7 +199,7 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader }, nil } -func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, srcOptimizeRelay, dstOptimizeRelay bool) (*RelayMsgs, error) { +func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, doExecuteRelaySrc, doExecuteRelayDst bool) (*RelayMsgs, error) { logger := GetChannelPairLogger(src, dst) defer logger.TimeTrack(time.Now(), "RelayPackets", "num_src", len(rp.Src), "num_dst", len(rp.Dst)) @@ -225,7 +225,7 @@ func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, return nil, err } - if srcOptimizeRelay { + if doExecuteRelaySrc { msgs.Dst, err = collectPackets(srcCtx, src, rp.Src, dstAddress) if err != nil { logger.Error( @@ -236,7 +236,7 @@ func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, } } - if dstOptimizeRelay { + if doExecuteRelayDst { msgs.Src, err = collectPackets(dstCtx, dst, rp.Dst, srcAddress) if err != nil { logger.Error( @@ -420,7 +420,7 @@ func logPacketsRelayed(src, dst Chain, num int, obj string, dir string) { ) } -func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, srcOptimizeRelay, dstOptimizeRelay bool) (*RelayMsgs, error) { +func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, doExecuteRelaySrc, doExecuteRelayDst bool) (*RelayMsgs, error) { logger := GetChannelPairLogger(src, dst) defer logger.TimeTrack(time.Now(), "RelayAcknowledgements", "num_src", len(rp.Src), "num_dst", len(rp.Dst)) @@ -445,13 +445,13 @@ func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *Rela return nil, err } - if !st.dstNoAck && srcOptimizeRelay { + if !st.dstNoAck && doExecuteRelaySrc { msgs.Dst, err = collectAcks(srcCtx, src, rp.Src, dstAddress) if err != nil { return nil, err } } - if !st.srcNoAck && dstOptimizeRelay { + if !st.srcNoAck && doExecuteRelayDst { msgs.Src, err = collectAcks(dstCtx, dst, rp.Dst, srcAddress) if err != nil { return nil, err @@ -495,16 +495,13 @@ func collectAcks(ctx QueryContext, chain *ProvableChain, packets PacketInfoList, return msgs, nil } -func (st *NaiveStrategy) UpdateClients(src, dst *ProvableChain, rpForRecv, rpForAck *RelayPackets, sh SyncHeaders, doRefresh bool) (*RelayMsgs, error) { +func (st *NaiveStrategy) UpdateClients(src, dst *ProvableChain, doExecuteRelaySrc, doExecuteRelayDst, doExecuteAckSrc, doExecuteAckDst bool, sh SyncHeaders, doRefresh bool) (*RelayMsgs, error) { logger := GetChannelPairLogger(src, dst) msgs := NewRelayMsgs() - // check if unrelayed packets or acks exist - needsUpdateForSrc := len(rpForRecv.Dst) > 0 || - !st.srcNoAck && len(rpForAck.Dst) > 0 - needsUpdateForDst := len(rpForRecv.Src) > 0 || - !st.dstNoAck && len(rpForAck.Src) > 0 + needsUpdateForSrc := doExecuteRelaySrc || (doExecuteAckSrc && !st.srcNoAck) + needsUpdateForDst := doExecuteRelayDst || (doExecuteAckDst && !st.dstNoAck) // check if LC refresh is needed if !needsUpdateForSrc && doRefresh { diff --git a/core/service.go b/core/service.go index 811b5719..c0425927 100644 --- a/core/service.go +++ b/core/service.go @@ -85,19 +85,19 @@ func NewRelayService( dstOptimizeInterval: dstOptimizeInterval, dstOptimizeCount: dstOptimizeCount, srcRelayPacketStartTime: WatchStartTime{ - AlreadySet: true, + AlreadySet: false, StartTime: time.Now(), }, dstRelayPacketStartTime: WatchStartTime{ - AlreadySet: true, + AlreadySet: false, StartTime: time.Now(), }, srcRelayAckStartTime: WatchStartTime{ - AlreadySet: true, + AlreadySet: false, StartTime: time.Now(), }, dstRelayAckStartTime: WatchStartTime{ - AlreadySet: true, + AlreadySet: false, StartTime: time.Now(), }, }, @@ -157,14 +157,6 @@ func (srv *RelayService) Serve(ctx context.Context) error { msgs := NewRelayMsgs() - // update clients - if m, err := srv.st.UpdateClients(srv.src, srv.dst, pseqs, aseqs, srv.sh, true); err != nil { - logger.Error("failed to update clients", err) - return err - } else { - msgs.Merge(m) - } - // reset watch start time for packets if len(pseqs.Src) > 0 { resetWatchStartTime(&srv.optimizeRelay.srcRelayPacketStartTime) @@ -173,43 +165,53 @@ func (srv *RelayService) Serve(ctx context.Context) error { resetWatchStartTime(&srv.optimizeRelay.dstRelayPacketStartTime) } + // reset watch start time for acks + if len(aseqs.Src) > 0 { + resetWatchStartTime(&srv.optimizeRelay.srcRelayAckStartTime) + } + if len(aseqs.Dst) > 0 { + resetWatchStartTime(&srv.optimizeRelay.dstRelayAckStartTime) + } + + doExecuteRelaySrc, doExecuteRelayDst := srv.shouldExecuteRelay(pseqs, srv.optimizeRelay.srcRelayPacketStartTime, srv.optimizeRelay.dstRelayPacketStartTime) + doExecuteAckSrc, doExecuteAckDst := srv.shouldExecuteRelay(aseqs, srv.optimizeRelay.srcRelayAckStartTime, srv.optimizeRelay.dstRelayAckStartTime) + + // update clients + if m, err := srv.st.UpdateClients(srv.src, srv.dst, doExecuteRelaySrc, doExecuteRelayDst, doExecuteAckSrc, doExecuteAckDst, srv.sh, true); err != nil { + logger.Error("failed to update clients", err) + return err + } else { + msgs.Merge(m) + } + // relay packets if unrelayed seqs exist - srcRelayPackets, dstRelayPackets := srv.shouldExecuteRelay(pseqs, srv.optimizeRelay.srcRelayPacketStartTime, srv.optimizeRelay.dstRelayPacketStartTime) - if m, err := srv.st.RelayPackets(srv.src, srv.dst, pseqs, srv.sh, srcRelayPackets, dstRelayPackets); err != nil { + if m, err := srv.st.RelayPackets(srv.src, srv.dst, pseqs, srv.sh, doExecuteRelaySrc, doExecuteRelayDst); err != nil { logger.Error("failed to relay packets", err) return err } else { - if srcRelayPackets { - srv.optimizeRelay.srcRelayPacketStartTime.AlreadySet = false - } - if dstRelayPackets { - srv.optimizeRelay.dstRelayPacketStartTime.AlreadySet = false - } msgs.Merge(m) } - // reset watch start time for acks - if len(aseqs.Src) > 0 { - resetWatchStartTime(&srv.optimizeRelay.srcRelayAckStartTime) + if doExecuteRelaySrc { + srv.optimizeRelay.srcRelayPacketStartTime.AlreadySet = false } - if len(aseqs.Dst) > 0 { - resetWatchStartTime(&srv.optimizeRelay.dstRelayAckStartTime) + if doExecuteRelayDst { + srv.optimizeRelay.dstRelayPacketStartTime.AlreadySet = false } // relay acks if unrelayed seqs exist - srcRelayAcks, dstRelayAcks := srv.shouldExecuteRelay(aseqs, srv.optimizeRelay.srcRelayAckStartTime, srv.optimizeRelay.dstRelayAckStartTime) - if m, err := srv.st.RelayAcknowledgements(srv.src, srv.dst, aseqs, srv.sh, srcRelayAcks, dstRelayAcks); err != nil { + if m, err := srv.st.RelayAcknowledgements(srv.src, srv.dst, aseqs, srv.sh, doExecuteAckSrc, doExecuteAckDst); err != nil { logger.Error("failed to relay acknowledgements", err) return err } else { - if srcRelayAcks { - srv.optimizeRelay.srcRelayAckStartTime.AlreadySet = false - } - if dstRelayAcks { - srv.optimizeRelay.dstRelayAckStartTime.AlreadySet = false - } msgs.Merge(m) } + if doExecuteAckSrc { + srv.optimizeRelay.srcRelayAckStartTime.AlreadySet = false + } + if doExecuteAckDst { + srv.optimizeRelay.dstRelayAckStartTime.AlreadySet = false + } // send all msgs to src/dst chains srv.st.Send(srv.src, srv.dst, msgs) diff --git a/core/strategies.go b/core/strategies.go index 5985749c..f344ff2f 100644 --- a/core/strategies.go +++ b/core/strategies.go @@ -18,17 +18,17 @@ type StrategyI interface { UnrelayedPackets(src, dst *ProvableChain, sh SyncHeaders, includeRelayedButUnfinalized bool) (*RelayPackets, error) // RelayPackets executes RecvPacket to the packets contained in `rp` on both chains (`src` and `dst`). - RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, srcOptimizeRelay, dstOptimizeRelay bool) (*RelayMsgs, error) + RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, doExecuteRelaySrc, doExecuteRelayDst bool) (*RelayMsgs, error) // UnrelayedAcknowledgements returns packets to execute AcknowledgePacket to on `src` and `dst`. // `includeRelayedButUnfinalized` decides if the result includes packets of which acknowledgePacket has been executed but not finalized UnrelayedAcknowledgements(src, dst *ProvableChain, sh SyncHeaders, includeRelayedButUnfinalized bool) (*RelayPackets, error) // RelayAcknowledgements executes AcknowledgePacket to the packets contained in `rp` on both chains (`src` and `dst`). - RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, srcOptimizeRelay, dstOptimizeRelay bool) (*RelayMsgs, error) + RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, doExecuteRelaySrc, doExecuteRelayDst bool) (*RelayMsgs, error) // UpdateClients executes UpdateClient only if needed - UpdateClients(src, dst *ProvableChain, rpForRecv, rpForAck *RelayPackets, sh SyncHeaders, doRefresh bool) (*RelayMsgs, error) + UpdateClients(src, dst *ProvableChain, doExecuteRelaySrc, doExecuteRelayDst, doExecuteAckSrc, doExecuteAckDst bool, sh SyncHeaders, doRefresh bool) (*RelayMsgs, error) // Send executes submission of msgs to src/dst chains Send(src, dst Chain, msgs *RelayMsgs) diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 92b4abca..21aa3910 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -2,8 +2,10 @@ : <<'END_COMMENT' * relay-interval = 10s -* relay-optimize-interval = 15s -* relay-optimize-count = 3 +* src-relay-optimize-interval = 15s +* src-relay-optimize-count = 3 +* dst-relay-optimize-interval = 15s +* dst-relay-optimize-count = 3 - relay service [query = 0, time = 0] -> skip - transfer @@ -15,7 +17,7 @@ - - - -- relay service [query = 1, time = 10] -> skip +- relay service [query = 1, time = 0] -> skip - transfer - - @@ -25,6 +27,16 @@ - - - +- relay service [query = 2, time = 10] -> skip + - + - + - + - + - + - + - + - + - - relay service [query = 2, time = 20] -> exec (time) - transfer x 3 - @@ -34,7 +46,7 @@ - - - - - + - - relay service [query = 3, time = 10] -> exec (count) END_COMMENT @@ -80,7 +92,7 @@ if [ $unrelayed_packets -ne 2 ]; then exit 1 fi -sleep 7 # wait for relay-interval +sleep 17 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" # transfer a token x 3 diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 92b4abca..21aa3910 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -2,8 +2,10 @@ : <<'END_COMMENT' * relay-interval = 10s -* relay-optimize-interval = 15s -* relay-optimize-count = 3 +* src-relay-optimize-interval = 15s +* src-relay-optimize-count = 3 +* dst-relay-optimize-interval = 15s +* dst-relay-optimize-count = 3 - relay service [query = 0, time = 0] -> skip - transfer @@ -15,7 +17,7 @@ - - - -- relay service [query = 1, time = 10] -> skip +- relay service [query = 1, time = 0] -> skip - transfer - - @@ -25,6 +27,16 @@ - - - +- relay service [query = 2, time = 10] -> skip + - + - + - + - + - + - + - + - + - - relay service [query = 2, time = 20] -> exec (time) - transfer x 3 - @@ -34,7 +46,7 @@ - - - - - + - - relay service [query = 3, time = 10] -> exec (count) END_COMMENT @@ -80,7 +92,7 @@ if [ $unrelayed_packets -ne 2 ]; then exit 1 fi -sleep 7 # wait for relay-interval +sleep 17 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" # transfer a token x 3 From dfcad6fb2a18d75541cc899f15bd962ef84e9f6d Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 28 Nov 2023 11:55:08 +0900 Subject: [PATCH 08/23] Fix src, dst parameters Signed-off-by: Dongri Jin --- core/naive-strategy.go | 10 +++++----- core/service.go | 4 ++-- core/strategies.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/naive-strategy.go b/core/naive-strategy.go index 3365e532..0fffbf1b 100644 --- a/core/naive-strategy.go +++ b/core/naive-strategy.go @@ -225,7 +225,7 @@ func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, return nil, err } - if doExecuteRelaySrc { + if doExecuteRelayDst { msgs.Dst, err = collectPackets(srcCtx, src, rp.Src, dstAddress) if err != nil { logger.Error( @@ -236,7 +236,7 @@ func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, } } - if doExecuteRelayDst { + if doExecuteRelaySrc { msgs.Src, err = collectPackets(dstCtx, dst, rp.Dst, srcAddress) if err != nil { logger.Error( @@ -420,7 +420,7 @@ func logPacketsRelayed(src, dst Chain, num int, obj string, dir string) { ) } -func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, doExecuteRelaySrc, doExecuteRelayDst bool) (*RelayMsgs, error) { +func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, doExecuteAckSrc, doExecuteAckDst bool) (*RelayMsgs, error) { logger := GetChannelPairLogger(src, dst) defer logger.TimeTrack(time.Now(), "RelayAcknowledgements", "num_src", len(rp.Src), "num_dst", len(rp.Dst)) @@ -445,13 +445,13 @@ func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *Rela return nil, err } - if !st.dstNoAck && doExecuteRelaySrc { + if !st.dstNoAck && doExecuteAckDst { msgs.Dst, err = collectAcks(srcCtx, src, rp.Src, dstAddress) if err != nil { return nil, err } } - if !st.srcNoAck && doExecuteRelayDst { + if !st.srcNoAck && doExecuteAckSrc { msgs.Src, err = collectAcks(dstCtx, dst, rp.Dst, srcAddress) if err != nil { return nil, err diff --git a/core/service.go b/core/service.go index c0425927..93e68b9b 100644 --- a/core/service.go +++ b/core/service.go @@ -234,10 +234,10 @@ func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcRelayStartTim } // time interval - if time.Since(srcRelayStartTime.StartTime) >= srv.optimizeRelay.srcOptimizeInterval { + if srcRelayStartTime.AlreadySet && time.Since(srcRelayStartTime.StartTime) >= srv.optimizeRelay.srcOptimizeInterval { srcRelay = true } - if time.Since(dstRelayStartTime.StartTime) >= srv.optimizeRelay.dstOptimizeInterval { + if dstRelayStartTime.AlreadySet && time.Since(dstRelayStartTime.StartTime) >= srv.optimizeRelay.dstOptimizeInterval { dstRelay = true } diff --git a/core/strategies.go b/core/strategies.go index f344ff2f..c469624b 100644 --- a/core/strategies.go +++ b/core/strategies.go @@ -25,7 +25,7 @@ type StrategyI interface { UnrelayedAcknowledgements(src, dst *ProvableChain, sh SyncHeaders, includeRelayedButUnfinalized bool) (*RelayPackets, error) // RelayAcknowledgements executes AcknowledgePacket to the packets contained in `rp` on both chains (`src` and `dst`). - RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, doExecuteRelaySrc, doExecuteRelayDst bool) (*RelayMsgs, error) + RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders, doExecuteAckSrc, doExecuteAckDst bool) (*RelayMsgs, error) // UpdateClients executes UpdateClient only if needed UpdateClients(src, dst *ProvableChain, doExecuteRelaySrc, doExecuteRelayDst, doExecuteAckSrc, doExecuteAckDst bool, sh SyncHeaders, doRefresh bool) (*RelayMsgs, error) From 80660e3b725d775cfe57b4d0b2a271d8ffafa211 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Wed, 29 Nov 2023 15:44:21 +0900 Subject: [PATCH 09/23] Fix src, dst Signed-off-by: Dongri Jin --- cmd/tx.go | 8 ++++---- core/service.go | 12 ++++++------ tests/cases/tm2tm/scripts/test-service | 7 +++++-- tests/cases/tmmock2tmmock/scripts/test-service | 7 +++++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/cmd/tx.go b/cmd/tx.go index fcc71245..bb038f21 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -234,8 +234,8 @@ func relayMsgsCmd(ctx *config.Context) *cobra.Command { msgs := core.NewRelayMsgs() - doExecuteRelaySrc := len(sp.Src) > 0 - doExecuteRelayDst := len(sp.Dst) > 0 + doExecuteRelaySrc := len(sp.Dst) > 0 + doExecuteRelayDst := len(sp.Src) > 0 doExecuteAckSrc := false doExecuteAckDst := false @@ -302,8 +302,8 @@ func relayAcksCmd(ctx *config.Context) *cobra.Command { doExecuteRelaySrc := false doExecuteRelayDst := false - doExecuteAckSrc := len(sp.Src) > 0 - doExecuteAckDst := len(sp.Dst) > 0 + doExecuteAckSrc := len(sp.Dst) > 0 + doExecuteAckDst := len(sp.Src) > 0 if m, err := st.UpdateClients(c[src], c[dst], doExecuteRelaySrc, doExecuteRelayDst, doExecuteAckSrc, doExecuteAckDst, sh, viper.GetBool(flagDoRefresh)); err != nil { return err diff --git a/core/service.go b/core/service.go index 93e68b9b..a10ff07b 100644 --- a/core/service.go +++ b/core/service.go @@ -158,18 +158,18 @@ func (srv *RelayService) Serve(ctx context.Context) error { msgs := NewRelayMsgs() // reset watch start time for packets - if len(pseqs.Src) > 0 { + if len(pseqs.Dst) > 0 { resetWatchStartTime(&srv.optimizeRelay.srcRelayPacketStartTime) } - if len(pseqs.Dst) > 0 { + if len(pseqs.Src) > 0 { resetWatchStartTime(&srv.optimizeRelay.dstRelayPacketStartTime) } // reset watch start time for acks - if len(aseqs.Src) > 0 { + if len(aseqs.Dst) > 0 { resetWatchStartTime(&srv.optimizeRelay.srcRelayAckStartTime) } - if len(aseqs.Dst) > 0 { + if len(aseqs.Src) > 0 { resetWatchStartTime(&srv.optimizeRelay.dstRelayAckStartTime) } @@ -224,8 +224,8 @@ func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcRelayStartTim dstRelay := false // packet count - srcRelayCount := len(seqs.Src) - dstRelayCount := len(seqs.Dst) + srcRelayCount := len(seqs.Dst) + dstRelayCount := len(seqs.Src) if int64(srcRelayCount) >= srv.optimizeRelay.srcOptimizeCount { srcRelay = true } diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 21aa3910..8c9a5316 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -92,7 +92,10 @@ if [ $unrelayed_packets -ne 2 ]; then exit 1 fi -sleep 17 # wait for relay-interval +sleep 7 # wait for relay-interval +echo "xxxxxxx relay service -> skip xxxxxx" + +sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" # transfer a token x 3 @@ -109,7 +112,7 @@ if [ $unrelayed_packets -ne 3 ]; then exit 1 fi -sleep 20 # wait for relay-interval +sleep 7 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" # wait for relay service to execute diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 21aa3910..8c9a5316 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -92,7 +92,10 @@ if [ $unrelayed_packets -ne 2 ]; then exit 1 fi -sleep 17 # wait for relay-interval +sleep 7 # wait for relay-interval +echo "xxxxxxx relay service -> skip xxxxxx" + +sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" # transfer a token x 3 @@ -109,7 +112,7 @@ if [ $unrelayed_packets -ne 3 ]; then exit 1 fi -sleep 20 # wait for relay-interval +sleep 7 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" # wait for relay service to execute From 8e5b121c0d5011311b579124bbc13c0c08fc3e1a Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Wed, 29 Nov 2023 16:04:00 +0900 Subject: [PATCH 10/23] Fix tm2tm test Signed-off-by: Dongri Jin --- tests/cases/tm2tm/scripts/test-service | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 8c9a5316..06b22c59 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -67,7 +67,6 @@ RLY_PID=$! # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -sleep 3 # finality_delay # query unrelayed-packets 1 unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') @@ -77,12 +76,11 @@ if [ $unrelayed_packets -ne 1 ]; then exit 1 fi -sleep 7 # wait for relay-interval +sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -sleep 3 # finality_delay # query unrelayed-packets 2 unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') @@ -92,7 +90,7 @@ if [ $unrelayed_packets -ne 2 ]; then exit 1 fi -sleep 7 # wait for relay-interval +sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" sleep 10 # wait for relay-interval @@ -102,7 +100,6 @@ echo "xxxxxxx relay service -> exec - time xxxxxx" ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -sleep 3 # finality_delay # query unrelayed-packets 3 unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') @@ -112,7 +109,7 @@ if [ $unrelayed_packets -ne 3 ]; then exit 1 fi -sleep 7 # wait for relay-interval +sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" # wait for relay service to execute From b3cd4e76270d910731df60cdbdeba155b6b5a98c Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 5 Dec 2023 11:09:55 +0900 Subject: [PATCH 11/23] Refactoring shouldExecuteRelay Signed-off-by: Dongri Jin --- cmd/service.go | 4 ++-- core/service.go | 56 +++++++++++++++++++------------------------------ 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index e80278e7..f6f03c52 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -82,8 +82,8 @@ func startCmd(ctx *config.Context) *cobra.Command { cmd.Flags().Duration(flagRelayInterval, defaultRelayInterval, "time interval to perform relays") cmd.Flags().String(flagPrometheusAddr, defaultPrometheusAddr, "host address to which the prometheus exporter listens") cmd.Flags().Duration(flagSrcRelayOptimizeInterval, defaultRelayOptimizeInterval, "maximum time interval to delay relays for optimization") - cmd.Flags().Int64(flagSrcRelayOptimizeCount, defaultRelayOptimizeCount, "maximum number of relays to delay for optimization") + cmd.Flags().Uint64(flagSrcRelayOptimizeCount, defaultRelayOptimizeCount, "maximum number of relays to delay for optimization") cmd.Flags().Duration(flagDstRelayOptimizeInterval, defaultRelayOptimizeInterval, "maximum time interval to delay relays for optimization") - cmd.Flags().Int64(flagDstRelayOptimizeCount, defaultRelayOptimizeCount, "maximum number of relays to delay for optimization") + cmd.Flags().Uint64(flagDstRelayOptimizeCount, defaultRelayOptimizeCount, "maximum number of relays to delay for optimization") return cmd } diff --git a/core/service.go b/core/service.go index a10ff07b..19da7815 100644 --- a/core/service.go +++ b/core/service.go @@ -157,24 +157,8 @@ func (srv *RelayService) Serve(ctx context.Context) error { msgs := NewRelayMsgs() - // reset watch start time for packets - if len(pseqs.Dst) > 0 { - resetWatchStartTime(&srv.optimizeRelay.srcRelayPacketStartTime) - } - if len(pseqs.Src) > 0 { - resetWatchStartTime(&srv.optimizeRelay.dstRelayPacketStartTime) - } - - // reset watch start time for acks - if len(aseqs.Dst) > 0 { - resetWatchStartTime(&srv.optimizeRelay.srcRelayAckStartTime) - } - if len(aseqs.Src) > 0 { - resetWatchStartTime(&srv.optimizeRelay.dstRelayAckStartTime) - } - - doExecuteRelaySrc, doExecuteRelayDst := srv.shouldExecuteRelay(pseqs, srv.optimizeRelay.srcRelayPacketStartTime, srv.optimizeRelay.dstRelayPacketStartTime) - doExecuteAckSrc, doExecuteAckDst := srv.shouldExecuteRelay(aseqs, srv.optimizeRelay.srcRelayAckStartTime, srv.optimizeRelay.dstRelayAckStartTime) + doExecuteRelaySrc, doExecuteRelayDst := srv.shouldExecuteRelay(pseqs, &srv.optimizeRelay.srcRelayPacketStartTime, &srv.optimizeRelay.dstRelayPacketStartTime) + doExecuteAckSrc, doExecuteAckDst := srv.shouldExecuteRelay(aseqs, &srv.optimizeRelay.srcRelayAckStartTime, &srv.optimizeRelay.dstRelayAckStartTime) // update clients if m, err := srv.st.UpdateClients(srv.src, srv.dst, doExecuteRelaySrc, doExecuteRelayDst, doExecuteAckSrc, doExecuteAckDst, srv.sh, true); err != nil { @@ -192,13 +176,6 @@ func (srv *RelayService) Serve(ctx context.Context) error { msgs.Merge(m) } - if doExecuteRelaySrc { - srv.optimizeRelay.srcRelayPacketStartTime.AlreadySet = false - } - if doExecuteRelayDst { - srv.optimizeRelay.dstRelayPacketStartTime.AlreadySet = false - } - // relay acks if unrelayed seqs exist if m, err := srv.st.RelayAcknowledgements(srv.src, srv.dst, aseqs, srv.sh, doExecuteAckSrc, doExecuteAckDst); err != nil { logger.Error("failed to relay acknowledgements", err) @@ -206,12 +183,6 @@ func (srv *RelayService) Serve(ctx context.Context) error { } else { msgs.Merge(m) } - if doExecuteAckSrc { - srv.optimizeRelay.srcRelayAckStartTime.AlreadySet = false - } - if doExecuteAckDst { - srv.optimizeRelay.dstRelayAckStartTime.AlreadySet = false - } // send all msgs to src/dst chains srv.st.Send(srv.src, srv.dst, msgs) @@ -219,7 +190,16 @@ func (srv *RelayService) Serve(ctx context.Context) error { return nil } -func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcRelayStartTime, dstRelayStartTime WatchStartTime) (bool, bool) { +func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcStartTime, dstStartTime *WatchStartTime) (bool, bool) { + + // reset watch start time for packets + if len(seqs.Dst) > 0 { + resetWatchStartTime(srcStartTime) + } + if len(seqs.Src) > 0 { + resetWatchStartTime(dstStartTime) + } + srcRelay := false dstRelay := false @@ -234,13 +214,21 @@ func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcRelayStartTim } // time interval - if srcRelayStartTime.AlreadySet && time.Since(srcRelayStartTime.StartTime) >= srv.optimizeRelay.srcOptimizeInterval { + if srcStartTime.AlreadySet && time.Since(srcStartTime.StartTime) >= srv.optimizeRelay.srcOptimizeInterval { srcRelay = true } - if dstRelayStartTime.AlreadySet && time.Since(dstRelayStartTime.StartTime) >= srv.optimizeRelay.dstOptimizeInterval { + if dstStartTime.AlreadySet && time.Since(dstStartTime.StartTime) >= srv.optimizeRelay.dstOptimizeInterval { dstRelay = true } + // set already set to false if relay is executed + if srcRelay { + srcStartTime.AlreadySet = false + } + if dstRelay { + dstStartTime.AlreadySet = false + } + return srcRelay, dstRelay } From c1b9f1ad4ad26722114deba599f71e65aaaa2d86 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 5 Dec 2023 13:12:49 +0900 Subject: [PATCH 12/23] Refactoring test-service Signed-off-by: Dongri Jin --- tests/cases/tm2tm/scripts/test-service | 45 +++++-------------- tests/cases/tm2tm/scripts/utils | 11 +++++ .../cases/tmmock2tmmock/scripts/test-service | 41 ++++------------- tests/cases/tmmock2tmmock/scripts/test-tx | 38 +++------------- tests/cases/tmmock2tmmock/scripts/utils | 29 ++++++++++++ 5 files changed, 65 insertions(+), 99 deletions(-) create mode 100644 tests/cases/tm2tm/scripts/utils create mode 100644 tests/cases/tmmock2tmmock/scripts/utils diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 06b22c59..307135f0 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -11,7 +11,7 @@ - transfer - - - - finality + - - query = 1 - - @@ -21,7 +21,7 @@ - transfer - - - - finality + - - query = 2 - - @@ -41,7 +41,7 @@ - transfer x 3 - - - - finality + - - query 3 - - @@ -56,6 +56,8 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd) RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly RLY="${RLY_BINARY} --debug" +source ${SCRIPT_DIR}/utils + TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) @@ -68,13 +70,7 @@ RLY_PID=$! # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -# query unrelayed-packets 1 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 1 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 1 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -82,13 +78,7 @@ echo "xxxxxxx relay service -> skip xxxxxx" # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -# query unrelayed-packets 2 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 2 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 2 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -96,31 +86,18 @@ echo "xxxxxxx relay service -> skip xxxxxx" sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" +expectUnrelayedPackets 0 + # transfer a token x 3 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -# query unrelayed-packets 3 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 3 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 3 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" -# wait for relay service to execute -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for sendPacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') - if [ $unrelayed -eq 0 ]; then - break - fi -done +expectUnrelayedPackets 0 kill $RLY_PID diff --git a/tests/cases/tm2tm/scripts/utils b/tests/cases/tm2tm/scripts/utils new file mode 100644 index 00000000..7b7ed3d7 --- /dev/null +++ b/tests/cases/tm2tm/scripts/utils @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +expectUnrelayedPackets() { + expect_count=$1 + unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') + if [ $unrelayed_packets -ne ${expect_count} ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 + fi +} diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 8c9a5316..65332112 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -56,6 +56,8 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd) RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly RLY="${RLY_BINARY} --debug" +source ${SCRIPT_DIR}/utils + TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) @@ -69,13 +71,7 @@ RLY_PID=$! ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay -# query unrelayed-packets 1 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 1 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 1 sleep 7 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -84,13 +80,7 @@ echo "xxxxxxx relay service -> skip xxxxxx" ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay -# query unrelayed-packets 2 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 2 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 2 sleep 7 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -98,32 +88,19 @@ echo "xxxxxxx relay service -> skip xxxxxx" sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" +expectUnrelayedPackets 0 + # transfer a token x 3 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay -# query unrelayed-packets 3 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 3 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 3 -sleep 7 # wait for relay-interval +sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" -# wait for relay service to execute -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for sendPacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') - if [ $unrelayed -eq 0 ]; then - break - fi -done +expectUnrelayedPackets 0 kill $RLY_PID diff --git a/tests/cases/tmmock2tmmock/scripts/test-tx b/tests/cases/tmmock2tmmock/scripts/test-tx index cf73c68d..034b2801 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-tx +++ b/tests/cases/tmmock2tmmock/scripts/test-tx @@ -6,6 +6,8 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd) RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly RLY="${RLY_BINARY} --debug" +source ${SCRIPT_DIR}/utils + TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) @@ -20,47 +22,17 @@ echo "Before ibc1 balance: $(${RLY} query balance ibc1 ${TM_ADDRESS1})" # transfer a token (sendPacket) ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -# wait for the finalization of the sendPacket execution -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for sendPacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') - if [ $unrelayed -gt 0 ] - then - break - fi -done +waitRelay "unrelayed-packets" "src" # relay the packet (recvPacket) ${RLY} tx relay --do-refresh ibc01 -# wait for the finalization of the recvPacket execution -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for recvPacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-acknowledgements ibc01 | jq '.dst | length') - if [ $unrelayed -gt 0 ] - then - break - fi -done +waitRelay "unrelayed-acknowledgements" "dst" # relay the ack for the packet (acknowledgePacket) ${RLY} tx acks --do-refresh ibc01 -# wait for the finalization of the recvPacket execution -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for acknowledgePacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-acknowledgements ibc01 | jq '.dst | length') - if [ $unrelayed -eq 0 ] - then - break - fi -done +waitRelay "unrelayed-acknowledgements" "dst" echo "After ibc0 balance: $(${RLY} query balance ibc0 ${TM_ADDRESS0})" echo "After ibc1 balance: $(${RLY} query balance ibc1 ${TM_ADDRESS1})" diff --git a/tests/cases/tmmock2tmmock/scripts/utils b/tests/cases/tmmock2tmmock/scripts/utils new file mode 100644 index 00000000..b13bbc05 --- /dev/null +++ b/tests/cases/tmmock2tmmock/scripts/utils @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +PATH_NAME=ibc01 +RETRY_COUNT=5 +RETRY_INTERVAL=1 + +waitRelay() { + query_type=$1 + filter=".$2 | length" + for i in `seq $RETRY_COUNT` + do + echo "[try:$i] waiting for ${query_type} finalization ..." + sleep $RETRY_INTERVAL + unrelayed=$(${RLY} query ${query_type} ${PATH_NAME} | jq "${filter}") + if [ $unrelayed -gt 0 ]; then + break + fi + done +} + +expectUnrelayedPackets() { + expect_count=$1 + unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') + if [ $unrelayed_packets -ne ${expect_count} ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 + fi +} From 2748d4aa3de8eb07b5caf9a280ad61160912b7ad Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Wed, 6 Dec 2023 13:31:00 +0900 Subject: [PATCH 13/23] Add ack test to service Signed-off-by: Dongri Jin --- cmd/service.go | 4 +-- core/service.go | 16 ++++----- tests/cases/tm2tm/scripts/test-service | 33 ++++++++++++------- tests/cases/tm2tm/scripts/utils | 12 ++++--- .../cases/tmmock2tmmock/scripts/test-service | 29 ++++++++++------ tests/cases/tmmock2tmmock/scripts/utils | 12 ++++--- 6 files changed, 64 insertions(+), 42 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index f6f03c52..e7c38f18 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -73,9 +73,9 @@ func startCmd(ctx *config.Context) *cobra.Command { c[dst], viper.GetDuration(flagRelayInterval), viper.GetDuration(flagSrcRelayOptimizeInterval), - viper.GetInt64(flagSrcRelayOptimizeCount), + viper.GetUint64(flagSrcRelayOptimizeCount), viper.GetDuration(flagDstRelayOptimizeInterval), - viper.GetInt64(flagDstRelayOptimizeCount), + viper.GetUint64(flagDstRelayOptimizeCount), ) }, } diff --git a/core/service.go b/core/service.go index 19da7815..0262aa24 100644 --- a/core/service.go +++ b/core/service.go @@ -14,9 +14,9 @@ func StartService( src, dst *ProvableChain, relayInterval, srcRelayOptimizeInterval time.Duration, - srcRelayOptimizeCount int64, + srcRelayOptimizeCount uint64, dstRelayOptimizaInterval time.Duration, - dstRelayOptimizeCount int64, + dstRelayOptimizeCount uint64, ) error { sh, err := NewSyncHeaders(src, dst) if err != nil { @@ -47,9 +47,9 @@ type RelayService struct { type OptimizeRelay struct { srcOptimizeInterval time.Duration - srcOptimizeCount int64 + srcOptimizeCount uint64 dstOptimizeInterval time.Duration - dstOptimizeCount int64 + dstOptimizeCount uint64 srcRelayPacketStartTime WatchStartTime dstRelayPacketStartTime WatchStartTime @@ -69,9 +69,9 @@ func NewRelayService( sh SyncHeaders, interval, srcOptimizeInterval time.Duration, - srcOptimizeCount int64, + srcOptimizeCount uint64, dstOptimizeInterval time.Duration, - dstOptimizeCount int64, + dstOptimizeCount uint64, ) *RelayService { return &RelayService{ src: src, @@ -206,10 +206,10 @@ func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcStartTime, ds // packet count srcRelayCount := len(seqs.Dst) dstRelayCount := len(seqs.Src) - if int64(srcRelayCount) >= srv.optimizeRelay.srcOptimizeCount { + if uint64(srcRelayCount) >= srv.optimizeRelay.srcOptimizeCount { srcRelay = true } - if int64(dstRelayCount) >= srv.optimizeRelay.dstOptimizeCount { + if uint64(dstRelayCount) >= srv.optimizeRelay.dstOptimizeCount { dstRelay = true } diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 307135f0..02c50438 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -9,20 +9,20 @@ - relay service [query = 0, time = 0] -> skip - transfer + - query = 1 - - - - - query = 1 - - - - - relay service [query = 1, time = 0] -> skip - transfer + - query = 2 - - - - - query = 2 - - - @@ -38,16 +38,17 @@ - - - relay service [query = 2, time = 20] -> exec (time) + - query = 0 - transfer x 3 + - query = 3 - - - - - query 3 - - - - - - relay service [query = 3, time = 10] -> exec (count) + - query = 0 END_COMMENT set -eux @@ -61,16 +62,14 @@ source ${SCRIPT_DIR}/utils TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) -RETRY_COUNT=10 -RETRY_INTERVAL=1 - ${RLY} service start ibc01 --relay-interval 10s --src-relay-optimize-interval 15s --src-relay-optimize-count 3 --dst-relay-optimize-interval 15s --dst-relay-optimize-count 3 & RLY_PID=$! # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -expectUnrelayedPackets 1 +expectUnrelayedCount "unrelayed-packets" "src" 1 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -78,7 +77,8 @@ echo "xxxxxxx relay service -> skip xxxxxx" # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -expectUnrelayedPackets 2 +expectUnrelayedCount "unrelayed-packets" "src" 2 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -86,18 +86,27 @@ echo "xxxxxxx relay service -> skip xxxxxx" sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" -expectUnrelayedPackets 0 +expectUnrelayedCount "unrelayed-packets" "src" 0 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 # transfer a token x 3 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -expectUnrelayedPackets 3 +expectUnrelayedCount "unrelayed-packets" "src" 3 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" -expectUnrelayedPackets 0 +expectUnrelayedCount "unrelayed-packets" "src" 0 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 + +sleep 10 # wait for relay-interval +echo "xxxxxxx relay service -> exec (ack) - time + count xxxxxx" + +expectUnrelayedCount "unrelayed-packets" "src" 0 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 kill $RLY_PID diff --git a/tests/cases/tm2tm/scripts/utils b/tests/cases/tm2tm/scripts/utils index 7b7ed3d7..3667c94d 100644 --- a/tests/cases/tm2tm/scripts/utils +++ b/tests/cases/tm2tm/scripts/utils @@ -1,10 +1,12 @@ #!/usr/bin/env bash -expectUnrelayedPackets() { - expect_count=$1 - unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') - if [ $unrelayed_packets -ne ${expect_count} ]; then - echo "unrelayed_packets: $unrelayed_packets" +expectUnrelayedCount() { + query_type=$1 + filter=".$2 | length" + expect_count=$3 + unrelayed_count=$(${RLY} query ${query_type} ibc01 | jq "${filter}") + if [ $unrelayed_count -ne ${expect_count} ]; then + echo "$query_type: $unrelayed_count" kill $RLY_PID exit 1 fi diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 65332112..d6901e14 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -38,16 +38,17 @@ - - - relay service [query = 2, time = 20] -> exec (time) + - query = 0 - transfer x 3 - - - - finality - - query 3 + - query = 3 - - - - - relay service [query = 3, time = 10] -> exec (count) + - query = 0 END_COMMENT set -eux @@ -61,9 +62,6 @@ source ${SCRIPT_DIR}/utils TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) -RETRY_COUNT=10 -RETRY_INTERVAL=1 - ${RLY} service start ibc01 --relay-interval 10s --src-relay-optimize-interval 15s --src-relay-optimize-count 3 --dst-relay-optimize-interval 15s --dst-relay-optimize-count 3 & RLY_PID=$! @@ -71,7 +69,8 @@ RLY_PID=$! ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay -expectUnrelayedPackets 1 +expectUnrelayedCount "unrelayed-packets" "src" 1 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 sleep 7 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -80,7 +79,8 @@ echo "xxxxxxx relay service -> skip xxxxxx" ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay -expectUnrelayedPackets 2 +expectUnrelayedCount "unrelayed-packets" "src" 2 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 sleep 7 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -88,7 +88,8 @@ echo "xxxxxxx relay service -> skip xxxxxx" sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" -expectUnrelayedPackets 0 +expectUnrelayedCount "unrelayed-packets" "src" 0 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 # transfer a token x 3 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} @@ -96,11 +97,19 @@ ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay -expectUnrelayedPackets 3 +expectUnrelayedCount "unrelayed-packets" "src" 3 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" -expectUnrelayedPackets 0 +expectUnrelayedCount "unrelayed-packets" "src" 0 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 + +sleep 10 # wait for relay-interval +echo "xxxxxxx relay service -> exec (ack) - time + count xxxxxx" + +expectUnrelayedCount "unrelayed-packets" "src" 0 +expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 kill $RLY_PID diff --git a/tests/cases/tmmock2tmmock/scripts/utils b/tests/cases/tmmock2tmmock/scripts/utils index b13bbc05..803ce95e 100644 --- a/tests/cases/tmmock2tmmock/scripts/utils +++ b/tests/cases/tmmock2tmmock/scripts/utils @@ -18,11 +18,13 @@ waitRelay() { done } -expectUnrelayedPackets() { - expect_count=$1 - unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') - if [ $unrelayed_packets -ne ${expect_count} ]; then - echo "unrelayed_packets: $unrelayed_packets" +expectUnrelayedCount() { + query_type=$1 + filter=".$2 | length" + expect_count=$3 + unrelayed_count=$(${RLY} query ${query_type} ibc01 | jq "${filter}") + if [ $unrelayed_count -ne ${expect_count} ]; then + echo "$query_type: $unrelayed_count" kill $RLY_PID exit 1 fi From 60eb5316efdc6193fc5f3fea4b39baad3d85160e Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Thu, 7 Dec 2023 17:49:49 +0900 Subject: [PATCH 14/23] Fix error log Signed-off-by: Dongri Jin --- chains/tendermint/query.go | 22 +++--- core/naive-strategy.go | 16 ++--- core/service.go | 2 +- tests/cases/tm2tm/scripts/test-service | 68 +++++++++++------- .../cases/tmmock2tmmock/scripts/test-service | 71 ++++++++++++------- 5 files changed, 108 insertions(+), 71 deletions(-) diff --git a/chains/tendermint/query.go b/chains/tendermint/query.go index 110384db..d41caba3 100644 --- a/chains/tendermint/query.go +++ b/chains/tendermint/query.go @@ -184,7 +184,7 @@ func (c *Chain) QueryUnreceivedPackets(ctx core.QueryContext, seqs []uint64) ([] PacketCommitmentSequences: seqs, }) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to query unreceived packets: %w height: %v", err, ctx.Height()) } return res.Sequences, nil } @@ -192,14 +192,14 @@ func (c *Chain) QueryUnreceivedPackets(ctx core.QueryContext, seqs []uint64) ([] func (c *Chain) QueryUnfinalizedRelayPackets(ctx core.QueryContext, counterparty core.LightClientICS04Querier) (core.PacketInfoList, error) { res, err := c.queryPacketCommitments(ctx, 0, 1000) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to query packet commitments: %w", err) } var packets core.PacketInfoList for _, ps := range res.Commitments { packet, height, err := c.querySentPacket(ctx, ps.Sequence) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to query sent packet: %w", err) } packets = append(packets, &core.PacketInfo{ Packet: *packet, @@ -210,14 +210,14 @@ func (c *Chain) QueryUnfinalizedRelayPackets(ctx core.QueryContext, counterparty var counterpartyCtx core.QueryContext if counterpartyH, err := counterparty.GetLatestFinalizedHeader(); err != nil { - return nil, err + return nil, fmt.Errorf("failed to get latest finalized header: %w", err) } else { counterpartyCtx = core.NewQueryContext(context.TODO(), counterpartyH.GetHeight()) } seqs, err := counterparty.QueryUnreceivedPackets(counterpartyCtx, packets.ExtractSequenceList()) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to counterparty query unreceived packets: %w height: %v", err, counterpartyCtx.Height()) } packets = packets.Filter(seqs) @@ -233,7 +233,7 @@ func (c *Chain) QueryUnreceivedAcknowledgements(ctx core.QueryContext, seqs []ui PacketAckSequences: seqs, }) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to query unreceived acks: %w height: %v", err, ctx.Height()) } return res.Sequences, nil } @@ -241,18 +241,18 @@ func (c *Chain) QueryUnreceivedAcknowledgements(ctx core.QueryContext, seqs []ui func (c *Chain) QueryUnfinalizedRelayAcknowledgements(ctx core.QueryContext, counterparty core.LightClientICS04Querier) (core.PacketInfoList, error) { res, err := c.queryPacketAcknowledgementCommitments(ctx, 0, 1000) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to query packet acknowledgement commitments: %w", err) } var packets core.PacketInfoList for _, ps := range res.Acknowledgements { packet, rpHeight, err := c.queryReceivedPacket(ctx, ps.Sequence) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to query received packet: %w", err) } ack, _, err := c.queryWrittenAcknowledgement(ctx, ps.Sequence) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to query written acknowledgement: %w", err) } packets = append(packets, &core.PacketInfo{ Packet: *packet, @@ -263,14 +263,14 @@ func (c *Chain) QueryUnfinalizedRelayAcknowledgements(ctx core.QueryContext, cou var counterpartyCtx core.QueryContext if counterpartyH, err := counterparty.GetLatestFinalizedHeader(); err != nil { - return nil, err + return nil, fmt.Errorf("failed to get latest finalized header: %w", err) } else { counterpartyCtx = core.NewQueryContext(context.TODO(), counterpartyH.GetHeight()) } seqs, err := counterparty.QueryUnreceivedAcknowledgements(counterpartyCtx, packets.ExtractSequenceList()) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to counterparty query unreceived acknowledgements: %w, height: %v", err, counterpartyCtx.Height()) } packets = packets.Filter(seqs) diff --git a/core/naive-strategy.go b/core/naive-strategy.go index 0fffbf1b..387186bf 100644 --- a/core/naive-strategy.go +++ b/core/naive-strategy.go @@ -101,7 +101,7 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader now := time.Now() srcPackets, err = src.QueryUnfinalizedRelayPackets(srcCtx, dst) if err != nil { - return err + return fmt.Errorf("failed to query unfinalized relay packets on src chain: %w", err) } logger.TimeTrack(now, "QueryUnfinalizedRelayPackets", "queried_chain", "src", "num_packets", len(srcPackets)) return nil @@ -123,7 +123,7 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader now := time.Now() dstPackets, err = dst.QueryUnfinalizedRelayPackets(dstCtx, src) if err != nil { - return err + return fmt.Errorf("failed to query unfinalized relay packets on dst chain: %w", err) } logger.TimeTrack(now, "QueryUnfinalizedRelayPackets", "queried_chain", "dst", "num_packets", len(dstPackets)) return nil @@ -168,7 +168,7 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader now := time.Now() seqs, err := dst.QueryUnreceivedPackets(dstCtx, srcPackets.ExtractSequenceList()) if err != nil { - return err + return fmt.Errorf("failed to query unreceived packets on dst chain: %w", err) } logger.TimeTrack(now, "QueryUnreceivedPackets", "queried_chain", "dst", "num_seqs", len(seqs)) srcPackets = srcPackets.Filter(seqs) @@ -179,7 +179,7 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader now := time.Now() seqs, err := src.QueryUnreceivedPackets(srcCtx, dstPackets.ExtractSequenceList()) if err != nil { - return err + return fmt.Errorf("failed to query unreceived packets on src chain: %w", err) } logger.TimeTrack(now, "QueryUnreceivedPackets", "queried_chain", "src", "num_seqs", len(seqs)) dstPackets = dstPackets.Filter(seqs) @@ -286,7 +286,7 @@ func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh S now := time.Now() srcAcks, err = src.QueryUnfinalizedRelayAcknowledgements(srcCtx, dst) if err != nil { - return err + return fmt.Errorf("failed to query unfinalized relay acknowledgements on src chain: %w", err) } logger.TimeTrack(now, "QueryUnfinalizedRelayAcknowledgements", "queried_chain", "src", "num_packets", len(srcAcks)) return nil @@ -311,7 +311,7 @@ func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh S now := time.Now() dstAcks, err = dst.QueryUnfinalizedRelayAcknowledgements(dstCtx, src) if err != nil { - return err + return fmt.Errorf("failed to query unfinalized relay acknowledgements on dst chain: %w", err) } logger.TimeTrack(now, "QueryUnfinalizedRelayAcknowledgements", "queried_chain", "dst", "num_packets", len(dstAcks)) return nil @@ -355,7 +355,7 @@ func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh S now := time.Now() seqs, err := dst.QueryUnreceivedAcknowledgements(dstCtx, srcAcks.ExtractSequenceList()) if err != nil { - return err + return fmt.Errorf("failed to query unreceived acknowledgements on dst chain: %w", err) } logger.TimeTrack(now, "QueryUnreceivedAcknowledgements", "queried_chain", "dst", "num_seqs", len(seqs)) srcAcks = srcAcks.Filter(seqs) @@ -368,7 +368,7 @@ func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh S now := time.Now() seqs, err := src.QueryUnreceivedAcknowledgements(srcCtx, dstAcks.ExtractSequenceList()) if err != nil { - return err + return fmt.Errorf("failed to query unreceived acknowledgements on src chain: %w", err) } logger.TimeTrack(now, "QueryUnreceivedAcknowledgements", "queried_chain", "src", "num_seqs", len(seqs)) dstAcks = dstAcks.Filter(seqs) diff --git a/core/service.go b/core/service.go index 0262aa24..7759bc27 100644 --- a/core/service.go +++ b/core/service.go @@ -144,7 +144,7 @@ func (srv *RelayService) Serve(ctx context.Context) error { // get unrelayed packets pseqs, err := srv.st.UnrelayedPackets(srv.src, srv.dst, srv.sh, false) if err != nil { - logger.Error("failed to get unrelayed sequences", err) + logger.Error("failed to get unrelayed packets", err) return err } diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 02c50438..b6b3261e 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -7,48 +7,61 @@ * dst-relay-optimize-interval = 15s * dst-relay-optimize-count = 3 -- relay service [query = 0, time = 0] -> skip - - transfer - - query = 1 +- relay service [packets = 0, time = 0] -> skip + - sleep 2 - + - transfer x 1 + - packets = 1, ack = 0 + - sleep 5 - - - - +- relay service [packets = 1, time = 0] -> skip + - sleep 2 - + - transfer x 1 + - packets = 2, ack = 0 + - sleep 5 - -- relay service [query = 1, time = 0] -> skip - - transfer - - query = 2 - - - +- relay service [packets = 2, time = 10] -> skip + - sleep 10 - - - - -- relay service [query = 2, time = 10] -> skip - - - - +- relay service [packets = 2, time = 20] -> exec (time) + - sleep 2 - + - packets = 0, ack = 2 + - transfer x 3 + - packets = 3, ack = 2 + - sleep 5 - - - +- relay service [packets = 3, time = 10] -> exec (count) + - sleep 2 - -- relay service [query = 2, time = 20] -> exec (time) - - query = 0 - - transfer x 3 - - query = 3 + - packets = 0, ack = 5 + - sleep 8 - - - - - +- relay service [packets = 0, time = 20] -> exec (ack) (time + count) + - sleep 2 - -- relay service [query = 3, time = 10] -> exec (count) - - query = 0 + - packets = 0, ack = 0 + - Finished END_COMMENT set -eux @@ -64,49 +77,54 @@ TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) ${RLY} service start ibc01 --relay-interval 10s --src-relay-optimize-interval 15s --src-relay-optimize-count 3 --dst-relay-optimize-interval 15s --dst-relay-optimize-count 3 & RLY_PID=$! +echo "xxxxxxx relay service [packets = 0, time = 0] -> skip xxxxxx" +sleep 2 # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 1 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 +sleep 5 -sleep 10 # wait for relay-interval -echo "xxxxxxx relay service -> skip xxxxxx" +echo "xxxxxxx relay service [packets = 1, time = 0] -> skip xxxxxx" +sleep 2 -# transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 +sleep 5 -sleep 10 # wait for relay-interval -echo "xxxxxxx relay service -> skip xxxxxx" +echo "xxxxxxx relay service [packets = 2, time = 10] -> skip xxxxxx" +sleep 10 -sleep 10 # wait for relay-interval -echo "xxxxxxx relay service -> exec - time xxxxxx" +echo "xxxxxxx relay service [packets = 2, time = 20] -> exec (time) xxxxxx" +sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 -# transfer a token x 3 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 +sleep 5 -sleep 10 # wait for relay-interval -echo "xxxxxxx relay service -> exec - count xxxxxx" +echo "xxxxxxx relay service [packets = 3, time = 10] -> exec (count) xxxxxx" +sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 +sleep 8 -sleep 10 # wait for relay-interval -echo "xxxxxxx relay service -> exec (ack) - time + count xxxxxx" +echo "xxxxxxx relay service [packets = 0, time = 20] -> exec (ack) (time + count) xxxxxx" +sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 +echo "Finished" kill $RLY_PID diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index d6901e14..c4436e39 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -8,27 +8,27 @@ * dst-relay-optimize-count = 3 - relay service [query = 0, time = 0] -> skip - - transfer - - - - - - finality - - query = 1 + - sleep 2 - + - transfer x 1 - - + - finality + - packets = 1, ack = 0 + - sleep 3 - - relay service [query = 1, time = 0] -> skip - - transfer - - - - - - finality - - query = 2 + - sleep 2 - + - transfer x 1 - - + - finality + - packets = 2, ack = 0 + - sleep 5 - - relay service [query = 2, time = 10] -> skip - - + - sleep 10 - - - @@ -38,17 +38,30 @@ - - - relay service [query = 2, time = 20] -> exec (time) - - query = 0 + - sleep 2 + - + - packets = 0, ack = 2 - transfer x 3 - + - - finality - - query = 3 + - packets = 3, ack = 2 + - sleep 5 +- relay service [query = 3, time = 10] -> exec (count) + - sleep 2 - + - packets = 0, ack = 5 + - sleep 8 - - - -- relay service [query = 3, time = 10] -> exec (count) - - query = 0 + - + - +- relay service [packets = 0, time = 20] -> exec (ack) (time + count) + - sleep 2 + - + - packets = 0, ack = 0 + - Finished END_COMMENT set -eux @@ -64,29 +77,31 @@ TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) ${RLY} service start ibc01 --relay-interval 10s --src-relay-optimize-interval 15s --src-relay-optimize-count 3 --dst-relay-optimize-interval 15s --dst-relay-optimize-count 3 & RLY_PID=$! +echo "xxxxxxx relay service [query = 0, time = 0] -> skip xxxxxx" +sleep 2 -# transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 1 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 +sleep 3 -sleep 7 # wait for relay-interval -echo "xxxxxxx relay service -> skip xxxxxx" +echo "xxxxxxx relay service [query = 1, time = 0] -> skip xxxxxx" +sleep 2 -# transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 +sleep 5 -sleep 7 # wait for relay-interval -echo "xxxxxxx relay service -> skip xxxxxx" +echo "xxxxxxx relay service [query = 2, time = 10] -> skip xxxxxx" +sleep 10 -sleep 10 # wait for relay-interval -echo "xxxxxxx relay service -> exec - time xxxxxx" +echo "xxxxxxx relay service [query = 2, time = 20] -> exec (time) xxxxxx" +sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 @@ -99,17 +114,21 @@ sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 +sleep 5 -sleep 10 # wait for relay-interval -echo "xxxxxxx relay service -> exec - count xxxxxx" +echo "xxxxxxx relay service [query = 3, time = 10] -> exec (count) xxxxxx" +sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 +sleep 8 -sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec (ack) - time + count xxxxxx" +sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 +echo "Finished" + kill $RLY_PID From 5dc1f2ca354d323952df9f97818a6d2ca2c6b7c1 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Thu, 7 Dec 2023 21:41:34 +0900 Subject: [PATCH 15/23] Fix service interval Signed-off-by: Dongri Jin --- tests/cases/tm2tm/scripts/test-service | 34 ++++++------- .../cases/tmmock2tmmock/scripts/test-service | 49 ++++++++++--------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index b6b3261e..a3e9a038 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -1,10 +1,10 @@ #!/bin/bash : <<'END_COMMENT' -* relay-interval = 10s -* src-relay-optimize-interval = 15s +* relay-interval = 20s +* src-relay-optimize-interval = 25s * src-relay-optimize-count = 3 -* dst-relay-optimize-interval = 15s +* dst-relay-optimize-interval = 25s * dst-relay-optimize-count = 3 - relay service [packets = 0, time = 0] -> skip @@ -12,7 +12,7 @@ - - transfer x 1 - packets = 1, ack = 0 - - sleep 5 + - sleep 15 - - - @@ -22,13 +22,13 @@ - - transfer x 1 - packets = 2, ack = 0 - - sleep 5 + - sleep 18 - - - - -- relay service [packets = 2, time = 10] -> skip - - sleep 10 +- relay service [packets = 2, time = 20] -> skip + - sleep 20 - - - @@ -43,21 +43,21 @@ - packets = 0, ack = 2 - transfer x 3 - packets = 3, ack = 2 - - sleep 5 + - sleep 15 - - - -- relay service [packets = 3, time = 10] -> exec (count) +- relay service [packets = 3, time = 20] -> exec (count) - sleep 2 - - packets = 0, ack = 5 - - sleep 8 + - sleep 18 - - - - - -- relay service [packets = 0, time = 20] -> exec (ack) (time + count) +- relay service [packets = 0, time = 40] -> exec (ack) (time + count) - sleep 2 - - packets = 0, ack = 0 @@ -75,7 +75,7 @@ source ${SCRIPT_DIR}/utils TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) -${RLY} service start ibc01 --relay-interval 10s --src-relay-optimize-interval 15s --src-relay-optimize-count 3 --dst-relay-optimize-interval 15s --dst-relay-optimize-count 3 & +${RLY} service start ibc01 --relay-interval 20s --src-relay-optimize-interval 25s --src-relay-optimize-count 3 --dst-relay-optimize-interval 25s --dst-relay-optimize-count 3 & RLY_PID=$! echo "xxxxxxx relay service [packets = 0, time = 0] -> skip xxxxxx" sleep 2 @@ -85,7 +85,7 @@ ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 1 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 5 +sleep 15 echo "xxxxxxx relay service [packets = 1, time = 0] -> skip xxxxxx" sleep 2 @@ -94,10 +94,10 @@ ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 5 +sleep 18 echo "xxxxxxx relay service [packets = 2, time = 10] -> skip xxxxxx" -sleep 10 +sleep 20 echo "xxxxxxx relay service [packets = 2, time = 20] -> exec (time) xxxxxx" sleep 2 @@ -111,14 +111,14 @@ ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 -sleep 5 +sleep 14 echo "xxxxxxx relay service [packets = 3, time = 10] -> exec (count) xxxxxx" sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 -sleep 8 +sleep 18 echo "xxxxxxx relay service [packets = 0, time = 20] -> exec (ack) (time + count) xxxxxx" sleep 2 diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index c4436e39..c2dc1791 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -1,10 +1,10 @@ #!/bin/bash : <<'END_COMMENT' -* relay-interval = 10s -* src-relay-optimize-interval = 15s +* relay-interval = 20s +* src-relay-optimize-interval = 25s * src-relay-optimize-count = 3 -* dst-relay-optimize-interval = 15s +* dst-relay-optimize-interval = 25s * dst-relay-optimize-count = 3 - relay service [query = 0, time = 0] -> skip @@ -15,7 +15,7 @@ - - finality - packets = 1, ack = 0 - - sleep 3 + - sleep 12 - - relay service [query = 1, time = 0] -> skip - sleep 2 @@ -25,10 +25,10 @@ - - finality - packets = 2, ack = 0 - - sleep 5 + - sleep 15 - -- relay service [query = 2, time = 10] -> skip - - sleep 10 +- relay service [query = 2, time = 20] -> skip + - sleep 20 - - - @@ -37,7 +37,7 @@ - - - -- relay service [query = 2, time = 20] -> exec (time) +- relay service [query = 2, time = 40] -> exec (time) - sleep 2 - - packets = 0, ack = 2 @@ -46,18 +46,18 @@ - - finality - packets = 3, ack = 2 - - sleep 5 -- relay service [query = 3, time = 10] -> exec (count) + - sleep 12 +- relay service [query = 3, time = 20] -> exec (count) - sleep 2 - - packets = 0, ack = 5 - - sleep 8 + - sleep 18 - - - - - -- relay service [packets = 0, time = 20] -> exec (ack) (time + count) +- relay service [packets = 0, time = 40] -> exec (ack) (time + count) - sleep 2 - - packets = 0, ack = 0 @@ -75,9 +75,10 @@ source ${SCRIPT_DIR}/utils TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) -${RLY} service start ibc01 --relay-interval 10s --src-relay-optimize-interval 15s --src-relay-optimize-count 3 --dst-relay-optimize-interval 15s --dst-relay-optimize-count 3 & +SECONDS=0 +${RLY} service start ibc01 --relay-interval 20s --src-relay-optimize-interval 25s --src-relay-optimize-count 3 --dst-relay-optimize-interval 25s --dst-relay-optimize-count 3 & RLY_PID=$! -echo "xxxxxxx relay service [query = 0, time = 0] -> skip xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [query = 0, time = 0] -> skip xxxxxx" sleep 2 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} @@ -85,9 +86,9 @@ sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 1 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 3 +sleep 12 -echo "xxxxxxx relay service [query = 1, time = 0] -> skip xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [query = 1, time = 0] -> skip xxxxxx" sleep 2 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} @@ -95,12 +96,12 @@ sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 5 +sleep 15 -echo "xxxxxxx relay service [query = 2, time = 10] -> skip xxxxxx" -sleep 10 +echo "xxxxxxx ${SECONDS} relay service [query = 2, time = 10] -> skip xxxxxx" +sleep 20 -echo "xxxxxxx relay service [query = 2, time = 20] -> exec (time) xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [query = 2, time = 20] -> exec (time) xxxxxx" sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 @@ -114,16 +115,16 @@ sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 -sleep 5 +sleep 12 -echo "xxxxxxx relay service [query = 3, time = 10] -> exec (count) xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [query = 3, time = 10] -> exec (count) xxxxxx" sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 -sleep 8 +sleep 18 -echo "xxxxxxx relay service -> exec (ack) - time + count xxxxxx" +echo "xxxxxxx ${SECONDS} relay service -> exec (ack) - time + count xxxxxx" sleep 2 expectUnrelayedCount "unrelayed-packets" "src" 0 From 72f43b7dc064c238272a92beb0491bf727344a9e Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 12 Dec 2023 14:36:51 +0900 Subject: [PATCH 16/23] Fix test sleep Signed-off-by: Dongri Jin --- tests/cases/tm2tm/scripts/test-service | 36 +++++++++---------- .../cases/tmmock2tmmock/scripts/test-service | 36 +++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index a3e9a038..c6f82325 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -8,21 +8,21 @@ * dst-relay-optimize-count = 3 - relay service [packets = 0, time = 0] -> skip - - sleep 2 + - sleep 4 - - transfer x 1 - packets = 1, ack = 0 - - sleep 15 + - sleep 16 - - - - - relay service [packets = 1, time = 0] -> skip - - sleep 2 + - sleep 4 - - transfer x 1 - packets = 2, ack = 0 - - sleep 18 + - sleep 16 - - - @@ -38,27 +38,27 @@ - - - relay service [packets = 2, time = 20] -> exec (time) - - sleep 2 + - sleep 4 - - packets = 0, ack = 2 - transfer x 3 - packets = 3, ack = 2 - - sleep 15 + - sleep 16 - - - - relay service [packets = 3, time = 20] -> exec (count) - - sleep 2 + - sleep 4 - - packets = 0, ack = 5 - - sleep 18 + - sleep 16 - - - - - - relay service [packets = 0, time = 40] -> exec (ack) (time + count) - - sleep 2 + - sleep 4 - - packets = 0, ack = 0 - Finished @@ -78,29 +78,29 @@ TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) ${RLY} service start ibc01 --relay-interval 20s --src-relay-optimize-interval 25s --src-relay-optimize-count 3 --dst-relay-optimize-interval 25s --dst-relay-optimize-count 3 & RLY_PID=$! echo "xxxxxxx relay service [packets = 0, time = 0] -> skip xxxxxx" -sleep 2 +sleep 4 # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 1 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 15 +sleep 16 echo "xxxxxxx relay service [packets = 1, time = 0] -> skip xxxxxx" -sleep 2 +sleep 4 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 18 +sleep 16 echo "xxxxxxx relay service [packets = 2, time = 10] -> skip xxxxxx" sleep 20 echo "xxxxxxx relay service [packets = 2, time = 20] -> exec (time) xxxxxx" -sleep 2 +sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 @@ -111,17 +111,17 @@ ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 -sleep 14 +sleep 16 echo "xxxxxxx relay service [packets = 3, time = 10] -> exec (count) xxxxxx" -sleep 2 +sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 -sleep 18 +sleep 16 echo "xxxxxxx relay service [packets = 0, time = 20] -> exec (ack) (time + count) xxxxxx" -sleep 2 +sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index c2dc1791..226bbc22 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -8,24 +8,24 @@ * dst-relay-optimize-count = 3 - relay service [query = 0, time = 0] -> skip - - sleep 2 + - sleep 4 - - transfer x 1 - - - finality - packets = 1, ack = 0 - - sleep 12 + - sleep 13 - - relay service [query = 1, time = 0] -> skip - - sleep 2 + - sleep 4 - - transfer x 1 - - - finality - packets = 2, ack = 0 - - sleep 15 + - sleep 13 - - relay service [query = 2, time = 20] -> skip - sleep 20 @@ -38,7 +38,7 @@ - - - relay service [query = 2, time = 40] -> exec (time) - - sleep 2 + - sleep 4 - - packets = 0, ack = 2 - transfer x 3 @@ -46,19 +46,19 @@ - - finality - packets = 3, ack = 2 - - sleep 12 + - sleep 13 - relay service [query = 3, time = 20] -> exec (count) - - sleep 2 + - sleep 4 - - packets = 0, ack = 5 - - sleep 18 + - sleep 16 - - - - - - relay service [packets = 0, time = 40] -> exec (ack) (time + count) - - sleep 2 + - sleep 4 - - packets = 0, ack = 0 - Finished @@ -79,30 +79,30 @@ SECONDS=0 ${RLY} service start ibc01 --relay-interval 20s --src-relay-optimize-interval 25s --src-relay-optimize-count 3 --dst-relay-optimize-interval 25s --dst-relay-optimize-count 3 & RLY_PID=$! echo "xxxxxxx ${SECONDS} relay service [query = 0, time = 0] -> skip xxxxxx" -sleep 2 +sleep 4 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 1 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 12 +sleep 13 echo "xxxxxxx ${SECONDS} relay service [query = 1, time = 0] -> skip xxxxxx" -sleep 2 +sleep 4 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 15 +sleep 13 echo "xxxxxxx ${SECONDS} relay service [query = 2, time = 10] -> skip xxxxxx" sleep 20 echo "xxxxxxx ${SECONDS} relay service [query = 2, time = 20] -> exec (time) xxxxxx" -sleep 2 +sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 @@ -115,17 +115,17 @@ sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 -sleep 12 +sleep 13 echo "xxxxxxx ${SECONDS} relay service [query = 3, time = 10] -> exec (count) xxxxxx" -sleep 2 +sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 -sleep 18 +sleep 16 echo "xxxxxxx ${SECONDS} relay service -> exec (ack) - time + count xxxxxx" -sleep 2 +sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 From 25932145eb008f185d5969908837a51a82bf8f98 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Wed, 20 Dec 2023 20:04:01 +0900 Subject: [PATCH 17/23] Fix service test Signed-off-by: Dongri Jin --- tests/cases/tm2tm/scripts/test-service | 43 +++----------- .../cases/tmmock2tmmock/scripts/test-service | 56 +++++-------------- 2 files changed, 22 insertions(+), 77 deletions(-) diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index c6f82325..f004415d 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -9,57 +9,28 @@ - relay service [packets = 0, time = 0] -> skip - sleep 4 - - - transfer x 1 - packets = 1, ack = 0 - sleep 16 - - - - - - - - - relay service [packets = 1, time = 0] -> skip - sleep 4 - - - transfer x 1 - packets = 2, ack = 0 - sleep 16 - - - - - - - - - relay service [packets = 2, time = 20] -> skip - sleep 20 - - - - - - - - - - - - - - - - -- relay service [packets = 2, time = 20] -> exec (time) +- relay service [packets = 2, time = 40] -> exec (time) - sleep 4 - - - packets = 0, ack = 2 - transfer x 3 - packets = 3, ack = 2 - sleep 16 - - - - - - -- relay service [packets = 3, time = 20] -> exec (count) +- relay service [packets = 3, time = 0] -> exec (count) - sleep 4 - - - packets = 0, ack = 5 - sleep 16 - - - - - - - - - - -- relay service [packets = 0, time = 40] -> exec (ack) (time + count) +- relay service [acks = 5, time = 40] -> exec (time + count) - sleep 4 - - - packets = 0, ack = 0 - Finished END_COMMENT @@ -96,10 +67,10 @@ expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 sleep 16 -echo "xxxxxxx relay service [packets = 2, time = 10] -> skip xxxxxx" +echo "xxxxxxx relay service [packets = 2, time = 20] -> skip xxxxxx" sleep 20 -echo "xxxxxxx relay service [packets = 2, time = 20] -> exec (time) xxxxxx" +echo "xxxxxxx relay service [packets = 2, time = 40] -> exec (time) xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 @@ -113,14 +84,14 @@ expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 sleep 16 -echo "xxxxxxx relay service [packets = 3, time = 10] -> exec (count) xxxxxx" +echo "xxxxxxx relay service [packets = 3, time = 0] -> exec (count) xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 sleep 16 -echo "xxxxxxx relay service [packets = 0, time = 20] -> exec (ack) (time + count) xxxxxx" +echo "xxxxxxx relay service [acks = 5, time = 40] -> exec (time + count) xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 226bbc22..b90a08ba 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -7,59 +7,33 @@ * dst-relay-optimize-interval = 25s * dst-relay-optimize-count = 3 -- relay service [query = 0, time = 0] -> skip +- relay service [packets = 0, time = 0] -> skip - sleep 4 - - - transfer x 1 - - - - - - finality + - sleep 3 finality - packets = 1, ack = 0 - sleep 13 - - -- relay service [query = 1, time = 0] -> skip +- relay service [packets = 1, time = 0] -> skip - sleep 4 - - - transfer x 1 - - - - - - finality + - sleep 3 finality - packets = 2, ack = 0 - sleep 13 - - -- relay service [query = 2, time = 20] -> skip +- relay service [packets = 2, time = 20] -> skip - sleep 20 - - - - - - - - - - - - - - - - -- relay service [query = 2, time = 40] -> exec (time) +- relay service [packets = 2, time = 40] -> exec (time) - sleep 4 - - - packets = 0, ack = 2 - transfer x 3 - - - - - - finality + - sleep 3 finality - packets = 3, ack = 2 - sleep 13 -- relay service [query = 3, time = 20] -> exec (count) +- relay service [packets = 3, time = 0] -> exec (count) - sleep 4 - - - packets = 0, ack = 5 - sleep 16 - - - - - - - - - - -- relay service [packets = 0, time = 40] -> exec (ack) (time + count) +- relay service [acks = 5, time = 40] -> exec (time + count) - sleep 4 - - - packets = 0, ack = 0 - Finished END_COMMENT @@ -78,7 +52,7 @@ TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) SECONDS=0 ${RLY} service start ibc01 --relay-interval 20s --src-relay-optimize-interval 25s --src-relay-optimize-count 3 --dst-relay-optimize-interval 25s --dst-relay-optimize-count 3 & RLY_PID=$! -echo "xxxxxxx ${SECONDS} relay service [query = 0, time = 0] -> skip xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 0, time = 0] -> skip xxxxxx" sleep 4 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} @@ -88,7 +62,7 @@ expectUnrelayedCount "unrelayed-packets" "src" 1 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 sleep 13 -echo "xxxxxxx ${SECONDS} relay service [query = 1, time = 0] -> skip xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 1, time = 0] -> skip xxxxxx" sleep 4 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} @@ -98,10 +72,10 @@ expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 sleep 13 -echo "xxxxxxx ${SECONDS} relay service [query = 2, time = 10] -> skip xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 2, time = 20] -> skip xxxxxx" sleep 20 -echo "xxxxxxx ${SECONDS} relay service [query = 2, time = 20] -> exec (time) xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 2, time = 40] -> exec (time) xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 @@ -117,14 +91,14 @@ expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 sleep 13 -echo "xxxxxxx ${SECONDS} relay service [query = 3, time = 10] -> exec (count) xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 3, time = 0] -> exec (count) xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 sleep 16 -echo "xxxxxxx ${SECONDS} relay service -> exec (ack) - time + count xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [akcs = 5, time = 40] -> exec - time + count xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 From eda21b7a724758d57d135389520a81ef2d850104 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 9 Jan 2024 16:44:18 +0900 Subject: [PATCH 18/23] Remove startTime Use eventHeight Signed-off-by: Dongri Jin --- core/service.go | 87 ++++++------------- tests/cases/tm2tm/scripts/test-service | 34 ++++---- tests/cases/tm2tm/scripts/utils | 4 +- .../cases/tmmock2tmmock/scripts/test-service | 28 +++--- tests/cases/tmmock2tmmock/scripts/utils | 2 +- 5 files changed, 58 insertions(+), 97 deletions(-) diff --git a/core/service.go b/core/service.go index 7759bc27..9ed84531 100644 --- a/core/service.go +++ b/core/service.go @@ -50,16 +50,6 @@ type OptimizeRelay struct { srcOptimizeCount uint64 dstOptimizeInterval time.Duration dstOptimizeCount uint64 - - srcRelayPacketStartTime WatchStartTime - dstRelayPacketStartTime WatchStartTime - srcRelayAckStartTime WatchStartTime - dstRelayAckStartTime WatchStartTime -} - -type WatchStartTime struct { - AlreadySet bool - StartTime time.Time } // NewRelayService returns a new service @@ -84,22 +74,6 @@ func NewRelayService( srcOptimizeCount: srcOptimizeCount, dstOptimizeInterval: dstOptimizeInterval, dstOptimizeCount: dstOptimizeCount, - srcRelayPacketStartTime: WatchStartTime{ - AlreadySet: false, - StartTime: time.Now(), - }, - dstRelayPacketStartTime: WatchStartTime{ - AlreadySet: false, - StartTime: time.Now(), - }, - srcRelayAckStartTime: WatchStartTime{ - AlreadySet: false, - StartTime: time.Now(), - }, - dstRelayAckStartTime: WatchStartTime{ - AlreadySet: false, - StartTime: time.Now(), - }, }, } } @@ -157,9 +131,8 @@ func (srv *RelayService) Serve(ctx context.Context) error { msgs := NewRelayMsgs() - doExecuteRelaySrc, doExecuteRelayDst := srv.shouldExecuteRelay(pseqs, &srv.optimizeRelay.srcRelayPacketStartTime, &srv.optimizeRelay.dstRelayPacketStartTime) - doExecuteAckSrc, doExecuteAckDst := srv.shouldExecuteRelay(aseqs, &srv.optimizeRelay.srcRelayAckStartTime, &srv.optimizeRelay.dstRelayAckStartTime) - + doExecuteRelaySrc, doExecuteRelayDst := srv.shouldExecuteRelay(pseqs) + doExecuteAckSrc, doExecuteAckDst := srv.shouldExecuteRelay(aseqs) // update clients if m, err := srv.st.UpdateClients(srv.src, srv.dst, doExecuteRelaySrc, doExecuteRelayDst, doExecuteAckSrc, doExecuteAckDst, srv.sh, true); err != nil { logger.Error("failed to update clients", err) @@ -190,52 +163,48 @@ func (srv *RelayService) Serve(ctx context.Context) error { return nil } -func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets, srcStartTime, dstStartTime *WatchStartTime) (bool, bool) { +func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets) (bool, bool) { - // reset watch start time for packets - if len(seqs.Dst) > 0 { - resetWatchStartTime(srcStartTime) - } - if len(seqs.Src) > 0 { - resetWatchStartTime(dstStartTime) - } + var err error srcRelay := false dstRelay := false - // packet count - srcRelayCount := len(seqs.Dst) - dstRelayCount := len(seqs.Src) - if uint64(srcRelayCount) >= srv.optimizeRelay.srcOptimizeCount { - srcRelay = true + tsSrc := time.Now() + tsDst := time.Now() + + if len(seqs.Src) > 0 { + tsDst, err = srv.src.Timestamp(seqs.Src[0].EventHeight) + if err != nil { + return false, false + } } - if uint64(dstRelayCount) >= srv.optimizeRelay.dstOptimizeCount { - dstRelay = true + + if len(seqs.Dst) > 0 { + tsSrc, err = srv.dst.Timestamp(seqs.Dst[0].EventHeight) + if err != nil { + return false, false + } } // time interval - if srcStartTime.AlreadySet && time.Since(srcStartTime.StartTime) >= srv.optimizeRelay.srcOptimizeInterval { + if time.Since(tsSrc) >= srv.optimizeRelay.srcOptimizeInterval { srcRelay = true } - if dstStartTime.AlreadySet && time.Since(dstStartTime.StartTime) >= srv.optimizeRelay.dstOptimizeInterval { + if time.Since(tsDst) >= srv.optimizeRelay.dstOptimizeInterval { dstRelay = true } - // set already set to false if relay is executed - if srcRelay { - srcStartTime.AlreadySet = false + // packet count + srcRelayCount := len(seqs.Dst) + dstRelayCount := len(seqs.Src) + + if uint64(srcRelayCount) >= srv.optimizeRelay.srcOptimizeCount { + srcRelay = true } - if dstRelay { - dstStartTime.AlreadySet = false + if uint64(dstRelayCount) >= srv.optimizeRelay.dstOptimizeCount { + dstRelay = true } return srcRelay, dstRelay } - -func resetWatchStartTime(watchStartTime *WatchStartTime) { - if watchStartTime.AlreadySet { - return - } - watchStartTime.AlreadySet = true - watchStartTime.StartTime = time.Now() -} diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index f004415d..9d57e124 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -2,9 +2,9 @@ : <<'END_COMMENT' * relay-interval = 20s -* src-relay-optimize-interval = 25s +* src-relay-optimize-interval = 30s * src-relay-optimize-count = 3 -* dst-relay-optimize-interval = 25s +* dst-relay-optimize-interval = 30s * dst-relay-optimize-count = 3 - relay service [packets = 0, time = 0] -> skip @@ -12,22 +12,20 @@ - transfer x 1 - packets = 1, ack = 0 - sleep 16 -- relay service [packets = 1, time = 0] -> skip +- relay service [packets = 1, time = 20] -> skip - sleep 4 - transfer x 1 - packets = 2, ack = 0 - sleep 16 -- relay service [packets = 2, time = 20] -> skip - - sleep 20 - relay service [packets = 2, time = 40] -> exec (time) - sleep 4 - packets = 0, ack = 2 - transfer x 3 - packets = 3, ack = 2 - sleep 16 -- relay service [packets = 3, time = 0] -> exec (count) +- relay service [packets = 3, time = 20] -> exec (count) - sleep 4 - - packets = 0, ack = 5 + - packets = 0, ack = 3 - sleep 16 - relay service [acks = 5, time = 40] -> exec (time + count) - sleep 4 @@ -46,9 +44,10 @@ source ${SCRIPT_DIR}/utils TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) -${RLY} service start ibc01 --relay-interval 20s --src-relay-optimize-interval 25s --src-relay-optimize-count 3 --dst-relay-optimize-interval 25s --dst-relay-optimize-count 3 & +SECONDS=0 +${RLY} service start ibc01 --relay-interval 20s --src-relay-optimize-interval 30s --src-relay-optimize-count 3 --dst-relay-optimize-interval 30s --dst-relay-optimize-count 3 & RLY_PID=$! -echo "xxxxxxx relay service [packets = 0, time = 0] -> skip xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 0, time = 0] -> skip xxxxxx" sleep 4 # transfer a token @@ -56,21 +55,18 @@ ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 1 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 16 +sleep 13 -echo "xxxxxxx relay service [packets = 1, time = 0] -> skip xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 1, time = 20] -> skip xxxxxx" sleep 4 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 16 +sleep 13 -echo "xxxxxxx relay service [packets = 2, time = 20] -> skip xxxxxx" -sleep 20 - -echo "xxxxxxx relay service [packets = 2, time = 40] -> exec (time) xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 2, time = 40] -> exec (time) xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 @@ -82,16 +78,16 @@ ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 -sleep 16 +sleep 8 -echo "xxxxxxx relay service [packets = 3, time = 0] -> exec (count) xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 3, time = 20] -> exec (count) xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 sleep 16 -echo "xxxxxxx relay service [acks = 5, time = 40] -> exec (time + count) xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [acks = 5, time = 40] -> exec (time + count) xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 diff --git a/tests/cases/tm2tm/scripts/utils b/tests/cases/tm2tm/scripts/utils index 3667c94d..16645cfc 100644 --- a/tests/cases/tm2tm/scripts/utils +++ b/tests/cases/tm2tm/scripts/utils @@ -1,10 +1,12 @@ #!/usr/bin/env bash +PATH_NAME=ibc01 + expectUnrelayedCount() { query_type=$1 filter=".$2 | length" expect_count=$3 - unrelayed_count=$(${RLY} query ${query_type} ibc01 | jq "${filter}") + unrelayed_count=$(${RLY} query ${query_type} ${PATH_NAME} | jq "${filter}") if [ $unrelayed_count -ne ${expect_count} ]; then echo "$query_type: $unrelayed_count" kill $RLY_PID diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index b90a08ba..9d534dcf 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -2,9 +2,9 @@ : <<'END_COMMENT' * relay-interval = 20s -* src-relay-optimize-interval = 25s +* src-relay-optimize-interval = 30s * src-relay-optimize-count = 3 -* dst-relay-optimize-interval = 25s +* dst-relay-optimize-interval = 30s * dst-relay-optimize-count = 3 - relay service [packets = 0, time = 0] -> skip @@ -13,14 +13,12 @@ - sleep 3 finality - packets = 1, ack = 0 - sleep 13 -- relay service [packets = 1, time = 0] -> skip +- relay service [packets = 1, time = 20] -> skip - sleep 4 - transfer x 1 - sleep 3 finality - packets = 2, ack = 0 - sleep 13 -- relay service [packets = 2, time = 20] -> skip - - sleep 20 - relay service [packets = 2, time = 40] -> exec (time) - sleep 4 - packets = 0, ack = 2 @@ -28,7 +26,7 @@ - sleep 3 finality - packets = 3, ack = 2 - sleep 13 -- relay service [packets = 3, time = 0] -> exec (count) +- relay service [packets = 3, time = 20] -> exec (count) - sleep 4 - packets = 0, ack = 5 - sleep 16 @@ -50,7 +48,7 @@ TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) SECONDS=0 -${RLY} service start ibc01 --relay-interval 20s --src-relay-optimize-interval 25s --src-relay-optimize-count 3 --dst-relay-optimize-interval 25s --dst-relay-optimize-count 3 & +${RLY} service start ibc01 --relay-interval 20s --src-relay-optimize-interval 30s --src-relay-optimize-count 3 --dst-relay-optimize-interval 30s --dst-relay-optimize-count 3 & RLY_PID=$! echo "xxxxxxx ${SECONDS} relay service [packets = 0, time = 0] -> skip xxxxxx" sleep 4 @@ -60,9 +58,9 @@ sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 1 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 13 +sleep 10 -echo "xxxxxxx ${SECONDS} relay service [packets = 1, time = 0] -> skip xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 1, time = 20] -> skip xxxxxx" sleep 4 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} @@ -70,10 +68,7 @@ sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 2 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 -sleep 13 - -echo "xxxxxxx ${SECONDS} relay service [packets = 2, time = 20] -> skip xxxxxx" -sleep 20 +sleep 10 echo "xxxxxxx ${SECONDS} relay service [packets = 2, time = 40] -> exec (time) xxxxxx" sleep 4 @@ -81,7 +76,6 @@ sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 -# transfer a token x 3 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} @@ -89,16 +83,16 @@ sleep 3 # finality_delay expectUnrelayedCount "unrelayed-packets" "src" 3 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 2 -sleep 13 +sleep 10 -echo "xxxxxxx ${SECONDS} relay service [packets = 3, time = 0] -> exec (count) xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [packets = 3, time = 20] -> exec (count) xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 sleep 16 -echo "xxxxxxx ${SECONDS} relay service [akcs = 5, time = 40] -> exec - time + count xxxxxx" +echo "xxxxxxx ${SECONDS} relay service [akcs = 3, time = 40] -> exec - time + count xxxxxx" sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 diff --git a/tests/cases/tmmock2tmmock/scripts/utils b/tests/cases/tmmock2tmmock/scripts/utils index 803ce95e..91f4fa10 100644 --- a/tests/cases/tmmock2tmmock/scripts/utils +++ b/tests/cases/tmmock2tmmock/scripts/utils @@ -22,7 +22,7 @@ expectUnrelayedCount() { query_type=$1 filter=".$2 | length" expect_count=$3 - unrelayed_count=$(${RLY} query ${query_type} ibc01 | jq "${filter}") + unrelayed_count=$(${RLY} query ${query_type} ${PATH_NAME} | jq "${filter}") if [ $unrelayed_count -ne ${expect_count} ]; then echo "$query_type: $unrelayed_count" kill $RLY_PID From ef856ef93da49a1a1f2c0a190855ec254f6f1f54 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 9 Jan 2024 17:13:17 +0900 Subject: [PATCH 19/23] Add logger Signed-off-by: Dongri Jin --- core/service.go | 4 +++- tests/cases/tm2tm/scripts/test-service | 3 ++- tests/cases/tmmock2tmmock/scripts/test-service | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/service.go b/core/service.go index 9ed84531..f659b9f6 100644 --- a/core/service.go +++ b/core/service.go @@ -164,7 +164,7 @@ func (srv *RelayService) Serve(ctx context.Context) error { } func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets) (bool, bool) { - + logger := GetChannelPairLogger(srv.src, srv.dst) var err error srcRelay := false @@ -206,5 +206,7 @@ func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets) (bool, bool) { dstRelay = true } + logger.Info("shouldExecuteRelay", "srcRelay", srcRelay, "dstRelay", dstRelay) + return srcRelay, dstRelay } diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 9d57e124..798865f6 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -85,7 +85,7 @@ sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 -sleep 16 +sleep 20 echo "xxxxxxx ${SECONDS} relay service [acks = 5, time = 40] -> exec (time + count) xxxxxx" sleep 4 @@ -94,4 +94,5 @@ expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 0 echo "Finished" + kill $RLY_PID diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 9d534dcf..0fe475a2 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -90,7 +90,7 @@ sleep 4 expectUnrelayedCount "unrelayed-packets" "src" 0 expectUnrelayedCount "unrelayed-acknowledgements" "dst" 5 -sleep 16 +sleep 20 echo "xxxxxxx ${SECONDS} relay service [akcs = 3, time = 40] -> exec - time + count xxxxxx" sleep 4 From 72e4d888541253c9f6e0a953d9883bd428807eda Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 23 Jan 2024 10:34:13 +0900 Subject: [PATCH 20/23] * Fix Error messages * Fix check src, dst timestamp * Fix test case comments Signed-off-by: Dongri Jin --- chains/tendermint/query.go | 2 +- core/service.go | 22 +++++++------------ tests/cases/tm2tm/scripts/test-service | 10 ++++----- .../cases/tmmock2tmmock/scripts/test-service | 8 +++---- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/chains/tendermint/query.go b/chains/tendermint/query.go index d41caba3..76ef41c4 100644 --- a/chains/tendermint/query.go +++ b/chains/tendermint/query.go @@ -217,7 +217,7 @@ func (c *Chain) QueryUnfinalizedRelayPackets(ctx core.QueryContext, counterparty seqs, err := counterparty.QueryUnreceivedPackets(counterpartyCtx, packets.ExtractSequenceList()) if err != nil { - return nil, fmt.Errorf("failed to counterparty query unreceived packets: %w height: %v", err, counterpartyCtx.Height()) + return nil, fmt.Errorf("failed to query counterparty for unreceived packets: error=%w, height=%v", err, counterpartyCtx.Height()) } packets = packets.Filter(seqs) diff --git a/core/service.go b/core/service.go index f659b9f6..b4246bb0 100644 --- a/core/service.go +++ b/core/service.go @@ -165,34 +165,28 @@ func (srv *RelayService) Serve(ctx context.Context) error { func (srv *RelayService) shouldExecuteRelay(seqs *RelayPackets) (bool, bool) { logger := GetChannelPairLogger(srv.src, srv.dst) - var err error srcRelay := false dstRelay := false - tsSrc := time.Now() - tsDst := time.Now() - if len(seqs.Src) > 0 { - tsDst, err = srv.src.Timestamp(seqs.Src[0].EventHeight) + tsDst, err := srv.src.Timestamp(seqs.Src[0].EventHeight) if err != nil { return false, false } + if time.Since(tsDst) >= srv.optimizeRelay.dstOptimizeInterval { + dstRelay = true + } } if len(seqs.Dst) > 0 { - tsSrc, err = srv.dst.Timestamp(seqs.Dst[0].EventHeight) + tsSrc, err := srv.dst.Timestamp(seqs.Dst[0].EventHeight) if err != nil { return false, false } - } - - // time interval - if time.Since(tsSrc) >= srv.optimizeRelay.srcOptimizeInterval { - srcRelay = true - } - if time.Since(tsDst) >= srv.optimizeRelay.dstOptimizeInterval { - dstRelay = true + if time.Since(tsSrc) >= srv.optimizeRelay.srcOptimizeInterval { + srcRelay = true + } } // packet count diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 798865f6..8b8a08f8 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -11,22 +11,22 @@ - sleep 4 - transfer x 1 - packets = 1, ack = 0 - - sleep 16 + - sleep 13 - relay service [packets = 1, time = 20] -> skip - sleep 4 - transfer x 1 - packets = 2, ack = 0 - - sleep 16 + - sleep 13 - relay service [packets = 2, time = 40] -> exec (time) - sleep 4 - packets = 0, ack = 2 - transfer x 3 - packets = 3, ack = 2 - - sleep 16 + - sleep 8 - relay service [packets = 3, time = 20] -> exec (count) - sleep 4 - - packets = 0, ack = 3 - - sleep 16 + - packets = 0, ack = 5 + - sleep 20 - relay service [acks = 5, time = 40] -> exec (time + count) - sleep 4 - packets = 0, ack = 0 diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 0fe475a2..5b42ff0a 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -12,24 +12,24 @@ - transfer x 1 - sleep 3 finality - packets = 1, ack = 0 - - sleep 13 + - sleep 10 - relay service [packets = 1, time = 20] -> skip - sleep 4 - transfer x 1 - sleep 3 finality - packets = 2, ack = 0 - - sleep 13 + - sleep 10 - relay service [packets = 2, time = 40] -> exec (time) - sleep 4 - packets = 0, ack = 2 - transfer x 3 - sleep 3 finality - packets = 3, ack = 2 - - sleep 13 + - sleep 10 - relay service [packets = 3, time = 20] -> exec (count) - sleep 4 - packets = 0, ack = 5 - - sleep 16 + - sleep 20 - relay service [acks = 5, time = 40] -> exec (time + count) - sleep 4 - packets = 0, ack = 0 From af323d14368d3cde72565431a45fe68803afbedb Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 30 Jan 2024 10:24:06 +0900 Subject: [PATCH 21/23] Fix error logs Signed-off-by: Dongri Jin --- chains/tendermint/query.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/chains/tendermint/query.go b/chains/tendermint/query.go index 76ef41c4..58abe6dc 100644 --- a/chains/tendermint/query.go +++ b/chains/tendermint/query.go @@ -184,7 +184,7 @@ func (c *Chain) QueryUnreceivedPackets(ctx core.QueryContext, seqs []uint64) ([] PacketCommitmentSequences: seqs, }) if err != nil { - return nil, fmt.Errorf("failed to query unreceived packets: %w height: %v", err, ctx.Height()) + return nil, fmt.Errorf("failed to query unreceived packets: error=%w height=%v", err, ctx.Height()) } return res.Sequences, nil } @@ -192,14 +192,14 @@ func (c *Chain) QueryUnreceivedPackets(ctx core.QueryContext, seqs []uint64) ([] func (c *Chain) QueryUnfinalizedRelayPackets(ctx core.QueryContext, counterparty core.LightClientICS04Querier) (core.PacketInfoList, error) { res, err := c.queryPacketCommitments(ctx, 0, 1000) if err != nil { - return nil, fmt.Errorf("failed to query packet commitments: %w", err) + return nil, fmt.Errorf("failed to query packet commitments: error=%w height=%v", err, ctx.Height()) } var packets core.PacketInfoList for _, ps := range res.Commitments { packet, height, err := c.querySentPacket(ctx, ps.Sequence) if err != nil { - return nil, fmt.Errorf("failed to query sent packet: %w", err) + return nil, fmt.Errorf("failed to query sent packet: error=%w height=%v", err, ctx.Height()) } packets = append(packets, &core.PacketInfo{ Packet: *packet, @@ -210,7 +210,7 @@ func (c *Chain) QueryUnfinalizedRelayPackets(ctx core.QueryContext, counterparty var counterpartyCtx core.QueryContext if counterpartyH, err := counterparty.GetLatestFinalizedHeader(); err != nil { - return nil, fmt.Errorf("failed to get latest finalized header: %w", err) + return nil, fmt.Errorf("failed to get latest finalized header: error=%w height=%v", err, ctx.Height()) } else { counterpartyCtx = core.NewQueryContext(context.TODO(), counterpartyH.GetHeight()) } @@ -233,7 +233,7 @@ func (c *Chain) QueryUnreceivedAcknowledgements(ctx core.QueryContext, seqs []ui PacketAckSequences: seqs, }) if err != nil { - return nil, fmt.Errorf("failed to query unreceived acks: %w height: %v", err, ctx.Height()) + return nil, fmt.Errorf("failed to query unreceived acks: : error=%w height=%v", err, ctx.Height()) } return res.Sequences, nil } @@ -241,18 +241,18 @@ func (c *Chain) QueryUnreceivedAcknowledgements(ctx core.QueryContext, seqs []ui func (c *Chain) QueryUnfinalizedRelayAcknowledgements(ctx core.QueryContext, counterparty core.LightClientICS04Querier) (core.PacketInfoList, error) { res, err := c.queryPacketAcknowledgementCommitments(ctx, 0, 1000) if err != nil { - return nil, fmt.Errorf("failed to query packet acknowledgement commitments: %w", err) + return nil, fmt.Errorf("failed to query packet acknowledgement commitments: error=%w height=%v", err, ctx.Height()) } var packets core.PacketInfoList for _, ps := range res.Acknowledgements { packet, rpHeight, err := c.queryReceivedPacket(ctx, ps.Sequence) if err != nil { - return nil, fmt.Errorf("failed to query received packet: %w", err) + return nil, fmt.Errorf("failed to query received packet: error=%w height=%v", err, ctx.Height()) } ack, _, err := c.queryWrittenAcknowledgement(ctx, ps.Sequence) if err != nil { - return nil, fmt.Errorf("failed to query written acknowledgement: %w", err) + return nil, fmt.Errorf("failed to query written acknowledgement: error=%w height=%v", err, ctx.Height()) } packets = append(packets, &core.PacketInfo{ Packet: *packet, @@ -263,14 +263,14 @@ func (c *Chain) QueryUnfinalizedRelayAcknowledgements(ctx core.QueryContext, cou var counterpartyCtx core.QueryContext if counterpartyH, err := counterparty.GetLatestFinalizedHeader(); err != nil { - return nil, fmt.Errorf("failed to get latest finalized header: %w", err) + return nil, fmt.Errorf("failed to get latest finalized header: error=%w height=%v", err, ctx.Height()) } else { counterpartyCtx = core.NewQueryContext(context.TODO(), counterpartyH.GetHeight()) } seqs, err := counterparty.QueryUnreceivedAcknowledgements(counterpartyCtx, packets.ExtractSequenceList()) if err != nil { - return nil, fmt.Errorf("failed to counterparty query unreceived acknowledgements: %w, height: %v", err, counterpartyCtx.Height()) + return nil, fmt.Errorf("failed to counterparty query unreceived acknowledgements: error=%w height=%v", err, counterpartyCtx.Height()) } packets = packets.Filter(seqs) From 3d82c6566cdd8810d7d659082cc0862adb97d2a6 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Tue, 30 Jan 2024 20:17:59 +0900 Subject: [PATCH 22/23] Fix error message Signed-off-by: Dongri Jin --- chains/tendermint/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chains/tendermint/query.go b/chains/tendermint/query.go index 58abe6dc..dbb5598d 100644 --- a/chains/tendermint/query.go +++ b/chains/tendermint/query.go @@ -270,7 +270,7 @@ func (c *Chain) QueryUnfinalizedRelayAcknowledgements(ctx core.QueryContext, cou seqs, err := counterparty.QueryUnreceivedAcknowledgements(counterpartyCtx, packets.ExtractSequenceList()) if err != nil { - return nil, fmt.Errorf("failed to counterparty query unreceived acknowledgements: error=%w height=%v", err, counterpartyCtx.Height()) + return nil, fmt.Errorf("failed to query counterparty for unreceived: error=%w height=%v", err, counterpartyCtx.Height()) } packets = packets.Filter(seqs) From 7a4d0faf88e5261d5aa28bdf33b4b7a9f5e6ead9 Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Wed, 31 Jan 2024 11:03:22 +0900 Subject: [PATCH 23/23] Fix error message Signed-off-by: Dongri Jin --- chains/tendermint/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chains/tendermint/query.go b/chains/tendermint/query.go index dbb5598d..949021a8 100644 --- a/chains/tendermint/query.go +++ b/chains/tendermint/query.go @@ -270,7 +270,7 @@ func (c *Chain) QueryUnfinalizedRelayAcknowledgements(ctx core.QueryContext, cou seqs, err := counterparty.QueryUnreceivedAcknowledgements(counterpartyCtx, packets.ExtractSequenceList()) if err != nil { - return nil, fmt.Errorf("failed to query counterparty for unreceived: error=%w height=%v", err, counterpartyCtx.Height()) + return nil, fmt.Errorf("failed to query counterparty for unreceived acknowledgements: error=%w height=%v", err, counterpartyCtx.Height()) } packets = packets.Filter(seqs)