cmd/devp2p: make -eth-network filter actually work

This commit is contained in:
Felix Lange 2019-10-17 15:00:26 +02:00
parent d9f697c03c
commit 00d05619d8

View file

@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/core/forkid" "github.com/ethereum/go-ethereum/core/forkid"
"github.com/ethereum/go-ethereum/p2p/enr" "github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"gopkg.in/urfave/cli.v1" "gopkg.in/urfave/cli.v1"
) )
@ -154,19 +155,18 @@ func minAgeFilter(args []string) (nodeFilter, error) {
} }
func ethFilter(args []string) (nodeFilter, error) { func ethFilter(args []string) (nodeFilter, error) {
// var config *params.ChainConfig var filter func(forkid.ID) error
// switch args[0] { switch args[0] {
// case "mainnet": case "mainnet":
// config = params.MainnetChainConfig filter = forkid.NewStaticFilter(params.MainnetChainConfig, params.MainnetGenesisHash)
// case "rinkeby": case "rinkeby":
// config = params.RinkebyChainConfig filter = forkid.NewStaticFilter(params.RinkebyChainConfig, params.RinkebyGenesisHash)
// case "goerli": case "goerli":
// config = params.GoerliChainConfig filter = forkid.NewStaticFilter(params.GoerliChainConfig, params.GoerliGenesisHash)
// default: default:
// return nil, fmt.Errorf("unknown network %q", args[0]) return nil, fmt.Errorf("unknown network %q", args[0])
// } }
forkFilter := forkid.NewFilter(nil)
f := func(n nodeJSON) bool { f := func(n nodeJSON) bool {
var eth struct { var eth struct {
ForkID forkid.ID ForkID forkid.ID
@ -175,7 +175,7 @@ func ethFilter(args []string) (nodeFilter, error) {
if n.N.Load(enr.WithEntry("eth", &eth)) != nil { if n.N.Load(enr.WithEntry("eth", &eth)) != nil {
return false return false
} }
return forkFilter(eth.ForkID) == nil return filter(eth.ForkID) == nil
} }
return f, nil return f, nil
} }