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 committed Nov 15, 2022
1 parent ed105e3 commit b6553be
Show file tree
Hide file tree
Showing 9 changed files with 419 additions and 13 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
Loading

0 comments on commit b6553be

Please sign in to comment.