Skip to content

Commit

Permalink
cmd/devp2p: add node filter for snap + fix arg error (ethereum#21950)
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman authored and enriquefynn committed Feb 15, 2021
1 parent 634e83c commit 2d5aa79
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/devp2p/nodesetcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var filterFlags = map[string]nodeFilterC{
"-min-age": {1, minAgeFilter},
"-eth-network": {1, ethFilter},
"-les-server": {0, lesFilter},
"-snap": {0, snapFilter},
}

func parseFilters(args []string) ([]nodeFilter, error) {
Expand All @@ -104,15 +105,15 @@ func parseFilters(args []string) ([]nodeFilter, error) {
if !ok {
return nil, fmt.Errorf("invalid filter %q", args[0])
}
if len(args) < fc.narg {
return nil, fmt.Errorf("filter %q wants %d arguments, have %d", args[0], fc.narg, len(args))
if len(args)-1 < fc.narg {
return nil, fmt.Errorf("filter %q wants %d arguments, have %d", args[0], fc.narg, len(args)-1)
}
filter, err := fc.fn(args[1:])
filter, err := fc.fn(args[1 : 1+fc.narg])
if err != nil {
return nil, fmt.Errorf("%s: %v", args[0], err)
}
filters = append(filters, filter)
args = args[fc.narg+1:]
args = args[1+fc.narg:]
}
return filters, nil
}
Expand Down Expand Up @@ -191,3 +192,13 @@ func lesFilter(args []string) (nodeFilter, error) {
}
return f, nil
}

func snapFilter(args []string) (nodeFilter, error) {
f := func(n nodeJSON) bool {
var snap struct {
_ []rlp.RawValue `rlp:"tail"`
}
return n.N.Load(enr.WithEntry("snap", &snap)) == nil
}
return f, nil
}

0 comments on commit 2d5aa79

Please sign in to comment.