cmd/devp2p: add node filter for snap + fix arg error (#21950)

This commit is contained in:
Martin Holst Swende 2020-12-03 13:16:20 +01:00 committed by GitHub
parent 0b2f1446bb
commit d7a64dc02b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {
@ -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
}
@ -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
}