Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

Commit 5db81ab

Browse files
authored
fix counterparty path filter (#1000)
* fix counterparty path filter * Filter fix test * Add denylist test and add makefile and gh action * Slim test for non-self-hosted runner * Update ibctest to latest main * Make better assertion for denylist acks. Constants for allowlist/denylist. Validate filterRule in CLI * Use isolated prometheus registry per relayer instance instead of prometheus default registry * run path filter tests in parallel
1 parent 15840b7 commit 5db81ab

13 files changed

Lines changed: 434 additions & 22 deletions

File tree

.github/workflows/ibctest.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,24 @@ jobs:
7070
7171
- name: ibctest
7272
run: make ibctest-multiple
73+
path-filter:
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Set up Go 1.18
77+
uses: actions/setup-go@v1
78+
with:
79+
go-version: 1.18
80+
id: go
81+
82+
- name: checkout relayer
83+
uses: actions/checkout@v2
84+
85+
- uses: actions/cache@v1
86+
with:
87+
path: ~/go/pkg/mod
88+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
89+
restore-keys: |
90+
${{ runner.os }}-go-
91+
92+
- name: ibctest
93+
run: make ibctest-path-filter

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ ibctest-legacy:
8787
ibctest-multiple:
8888
cd ibctest && go test -race -v -run TestRelayerMultiplePathsSingleProcess .
8989

90+
ibctest-path-filter:
91+
cd ibctest && go test -race -v -run TestPathFilter .
92+
9093
coverage:
9194
@echo "viewing test coverage..."
9295
@go tool cover --html=coverage.out

cmd/flags.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const (
4545
flagProcessor = "processor"
4646
flagInitialBlockHistory = "block-history"
4747
flagMemo = "memo"
48+
flagFilterRule = "filter-rule"
49+
flagFilterChannels = "filter-channels"
4850
)
4951

5052
const (
@@ -152,6 +154,18 @@ func fileFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
152154
return cmd
153155
}
154156

157+
func pathFilterFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
158+
cmd.Flags().String(flagFilterRule, "", `filter rule ("allowlist", "denylist", or "" for no filtering)`)
159+
if err := v.BindPFlag(flagFilterRule, cmd.Flags().Lookup(flagFilterRule)); err != nil {
160+
panic(err)
161+
}
162+
cmd.Flags().String(flagFilterChannels, "", "channels from source chain perspective to filter")
163+
if err := v.BindPFlag(flagFilterRule, cmd.Flags().Lookup(flagFilterRule)); err != nil {
164+
panic(err)
165+
}
166+
return cmd
167+
}
168+
155169
func timeoutFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
156170
cmd.Flags().StringP(flagTimeout, "t", "10s", "timeout between relayer runs")
157171
if err := v.BindPFlag(flagTimeout, cmd.Flags().Lookup(flagTimeout)); err != nil {

cmd/paths.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/cosmos/relayer/v2/relayer"
12+
"github.com/cosmos/relayer/v2/relayer/processor"
1213
"github.com/google/go-github/v43/github"
1314
"github.com/spf13/cobra"
1415
"gopkg.in/yaml.v3"
@@ -30,6 +31,7 @@ This includes the client, connection, and channel ids from both the source and d
3031
pathsAddCmd(a),
3132
pathsAddDirCmd(a),
3233
pathsNewCmd(a),
34+
pathsUpdateCmd(a),
3335
pathsFetchCmd(a),
3436
pathsDeleteCmd(a),
3537
)
@@ -260,6 +262,52 @@ $ %s pth n ibc-0 ibc-1 demo-path`, appName, appName)),
260262
return channelParameterFlags(a.Viper, cmd)
261263
}
262264

265+
func pathsUpdateCmd(a *appState) *cobra.Command {
266+
cmd := &cobra.Command{
267+
Use: "update path_name",
268+
Aliases: []string{"n"},
269+
Short: `Update a path such as the filter rule ("allowlist", "denylist", or "" for no filtering) and channels`,
270+
Args: withUsage(cobra.ExactArgs(1)),
271+
Example: strings.TrimSpace(fmt.Sprintf(`
272+
$ %s paths update demo-path --filter-rule allowlist --filter-channels channel-0,channel-1
273+
$ %s paths update demo-path --filter-rule denylist --filter-channels channel-0,channel-1`,
274+
appName, appName)),
275+
RunE: func(cmd *cobra.Command, args []string) error {
276+
name := args[0]
277+
278+
filterRule, err := cmd.Flags().GetString(flagFilterRule)
279+
if err != nil {
280+
return err
281+
}
282+
if filterRule != "" && filterRule != processor.RuleAllowList && filterRule != processor.RuleDenyList {
283+
return fmt.Errorf(`invalid filter rule : "%s". valid rules: ("", "%s", "%s")`, filterRule, processor.RuleAllowList, processor.RuleDenyList)
284+
}
285+
286+
filterChannels, err := cmd.Flags().GetString(flagFilterChannels)
287+
if err != nil {
288+
return err
289+
}
290+
291+
var channelList []string
292+
293+
if filterChannels != "" {
294+
channelList = strings.Split(filterChannels, ",")
295+
}
296+
297+
p := a.Config.Paths.MustGet(name)
298+
299+
p.Filter = relayer.ChannelFilter{
300+
Rule: filterRule,
301+
ChannelList: channelList,
302+
}
303+
304+
return a.OverwriteConfig(a.Config)
305+
},
306+
}
307+
cmd = pathFilterFlags(a.Viper, cmd)
308+
return cmd
309+
}
310+
263311
// pathsFetchCmd attempts to fetch the json files containing the path metadata, for each configured chain, from GitHub
264312
func pathsFetchCmd(a *appState) *cobra.Command {
265313
cmd := &cobra.Command{

ibctest/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/cosmos/relayer/v2 v2.0.0
99
github.com/docker/docker v20.10.17+incompatible
1010
github.com/moby/moby v20.10.17+incompatible
11-
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220919160614-77d0523e3378
11+
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922235050-6baac8c666ea
1212
github.com/stretchr/testify v1.8.0
1313
go.uber.org/zap v1.22.0
1414
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29

ibctest/go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,12 @@ github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220916051004-abcda680ee7d h1
14761476
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220916051004-abcda680ee7d/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
14771477
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220919160614-77d0523e3378 h1:xlSrlegNKmohCgDUdsXsCU2NZkQbl+/DNOjTcG5eVII=
14781478
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220919160614-77d0523e3378/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
1479+
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922165058-44b91229244d h1:MoeKypPrHDOPk2FuBsN5mMwoqqXmx+pCPRj5XrLCX+I=
1480+
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922165058-44b91229244d/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
1481+
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922201145-4874b4d2e6ed h1:3/i6HIkTZEw7NYKXKFoyuxw6+JfXCjRsLDRLIqZnsGg=
1482+
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922201145-4874b4d2e6ed/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
1483+
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922235050-6baac8c666ea h1:jQvO399MoK7+NLigd7Vj7lGsa1Y7LWt8uTtbYGPTyYo=
1484+
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922235050-6baac8c666ea/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
14791485
github.com/strangelove-ventures/lens v0.5.2-0.20220822201013-1e7ffd450f20 h1:nYM1gFMJHbV3aYdiNCCS5jfBe/uMkORHwg8DSWZ5MRA=
14801486
github.com/strangelove-ventures/lens v0.5.2-0.20220822201013-1e7ffd450f20/go.mod h1:qrmVarKca7XLvuTEkR9jO50FrOprxQxukbmB7fpVrVo=
14811487
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=

0 commit comments

Comments
 (0)