Skip to content

Commit

Permalink
fix counterparty path filter (#1000)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
agouin authored Sep 23, 2022
1 parent 15840b7 commit 5db81ab
Show file tree
Hide file tree
Showing 13 changed files with 434 additions and 22 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ibctest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,24 @@ jobs:
- name: ibctest
run: make ibctest-multiple
path-filter:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.18
uses: actions/setup-go@v1
with:
go-version: 1.18
id: go

- name: checkout relayer
uses: actions/checkout@v2

- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: ibctest
run: make ibctest-path-filter
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ ibctest-legacy:
ibctest-multiple:
cd ibctest && go test -race -v -run TestRelayerMultiplePathsSingleProcess .

ibctest-path-filter:
cd ibctest && go test -race -v -run TestPathFilter .

coverage:
@echo "viewing test coverage..."
@go tool cover --html=coverage.out
Expand Down
14 changes: 14 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
flagProcessor = "processor"
flagInitialBlockHistory = "block-history"
flagMemo = "memo"
flagFilterRule = "filter-rule"
flagFilterChannels = "filter-channels"
)

const (
Expand Down Expand Up @@ -152,6 +154,18 @@ func fileFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
return cmd
}

func pathFilterFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(flagFilterRule, "", `filter rule ("allowlist", "denylist", or "" for no filtering)`)
if err := v.BindPFlag(flagFilterRule, cmd.Flags().Lookup(flagFilterRule)); err != nil {
panic(err)
}
cmd.Flags().String(flagFilterChannels, "", "channels from source chain perspective to filter")
if err := v.BindPFlag(flagFilterRule, cmd.Flags().Lookup(flagFilterRule)); err != nil {
panic(err)
}
return cmd
}

func timeoutFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagTimeout, "t", "10s", "timeout between relayer runs")
if err := v.BindPFlag(flagTimeout, cmd.Flags().Lookup(flagTimeout)); err != nil {
Expand Down
48 changes: 48 additions & 0 deletions cmd/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/cosmos/relayer/v2/relayer"
"github.com/cosmos/relayer/v2/relayer/processor"
"github.com/google/go-github/v43/github"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
Expand All @@ -30,6 +31,7 @@ This includes the client, connection, and channel ids from both the source and d
pathsAddCmd(a),
pathsAddDirCmd(a),
pathsNewCmd(a),
pathsUpdateCmd(a),
pathsFetchCmd(a),
pathsDeleteCmd(a),
)
Expand Down Expand Up @@ -260,6 +262,52 @@ $ %s pth n ibc-0 ibc-1 demo-path`, appName, appName)),
return channelParameterFlags(a.Viper, cmd)
}

func pathsUpdateCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "update path_name",
Aliases: []string{"n"},
Short: `Update a path such as the filter rule ("allowlist", "denylist", or "" for no filtering) and channels`,
Args: withUsage(cobra.ExactArgs(1)),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s paths update demo-path --filter-rule allowlist --filter-channels channel-0,channel-1
$ %s paths update demo-path --filter-rule denylist --filter-channels channel-0,channel-1`,
appName, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]

filterRule, err := cmd.Flags().GetString(flagFilterRule)
if err != nil {
return err
}
if filterRule != "" && filterRule != processor.RuleAllowList && filterRule != processor.RuleDenyList {
return fmt.Errorf(`invalid filter rule : "%s". valid rules: ("", "%s", "%s")`, filterRule, processor.RuleAllowList, processor.RuleDenyList)
}

filterChannels, err := cmd.Flags().GetString(flagFilterChannels)
if err != nil {
return err
}

var channelList []string

if filterChannels != "" {
channelList = strings.Split(filterChannels, ",")
}

p := a.Config.Paths.MustGet(name)

p.Filter = relayer.ChannelFilter{
Rule: filterRule,
ChannelList: channelList,
}

return a.OverwriteConfig(a.Config)
},
}
cmd = pathFilterFlags(a.Viper, cmd)
return cmd
}

// pathsFetchCmd attempts to fetch the json files containing the path metadata, for each configured chain, from GitHub
func pathsFetchCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion ibctest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/cosmos/relayer/v2 v2.0.0
github.com/docker/docker v20.10.17+incompatible
github.com/moby/moby v20.10.17+incompatible
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220919160614-77d0523e3378
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922235050-6baac8c666ea
github.com/stretchr/testify v1.8.0
go.uber.org/zap v1.22.0
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
Expand Down
6 changes: 6 additions & 0 deletions ibctest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,12 @@ github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220916051004-abcda680ee7d h1
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220916051004-abcda680ee7d/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220919160614-77d0523e3378 h1:xlSrlegNKmohCgDUdsXsCU2NZkQbl+/DNOjTcG5eVII=
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220919160614-77d0523e3378/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922165058-44b91229244d h1:MoeKypPrHDOPk2FuBsN5mMwoqqXmx+pCPRj5XrLCX+I=
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922165058-44b91229244d/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922201145-4874b4d2e6ed h1:3/i6HIkTZEw7NYKXKFoyuxw6+JfXCjRsLDRLIqZnsGg=
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922201145-4874b4d2e6ed/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922235050-6baac8c666ea h1:jQvO399MoK7+NLigd7Vj7lGsa1Y7LWt8uTtbYGPTyYo=
github.com/strangelove-ventures/ibctest/v5 v5.0.0-20220922235050-6baac8c666ea/go.mod h1:C284t8FhFrldr1BfQHDLsAMMzAWczTgeruePi7M6TmA=
github.com/strangelove-ventures/lens v0.5.2-0.20220822201013-1e7ffd450f20 h1:nYM1gFMJHbV3aYdiNCCS5jfBe/uMkORHwg8DSWZ5MRA=
github.com/strangelove-ventures/lens v0.5.2-0.20220822201013-1e7ffd450f20/go.mod h1:qrmVarKca7XLvuTEkR9jO50FrOprxQxukbmB7fpVrVo=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
Expand Down
Loading

0 comments on commit 5db81ab

Please sign in to comment.