Commit 4f35b852 authored by Andrew Huang's avatar Andrew Huang

Add ability to restrict the networks that op-node discovers peers on

parent 0f0d85ba
......@@ -152,6 +152,13 @@ var (
Value: "",
EnvVars: p2pEnv("STATIC"),
}
NetRestrict = &cli.StringFlag{
Name: "p2p.netrestrict",
Usage: "Comma-separated list of CIDR masks. P2P will only try to connect on these networks",
Required: false,
Value: "",
EnvVars: p2pEnv("NETRESTRICT"),
}
HostMux = &cli.StringFlag{
Name: "p2p.mux",
Usage: "Comma-separated list of multiplexing protocols in order of preference. At least 1 required. Options: 'yamux','mplex'.",
......@@ -322,6 +329,7 @@ var p2pFlags = []cli.Flag{
AdvertiseUDPPort,
Bootnodes,
StaticPeers,
NetRestrict,
HostMux,
HostSecurity,
PeersLo,
......
......@@ -23,6 +23,7 @@ import (
"github.com/urfave/cli/v2"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/netutil"
)
func NewConfig(ctx *cli.Context, rollupCfg *rollup.Config) (*p2p.Config, error) {
......@@ -193,6 +194,13 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error {
conf.Bootnodes = p2p.DefaultBootnodes
}
netRestrict, err := netutil.ParseNetlist(ctx.String(flags.NetRestrict.Name))
if err != nil {
return fmt.Errorf("failed to parse net list: %w", err)
}
conf.NetRestrict = netRestrict
return nil
}
......
......@@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/netutil"
ds "github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p"
pubsub "github.com/libp2p/go-libp2p-pubsub"
......@@ -84,6 +85,7 @@ type Config struct {
AdvertiseUDPPort uint16
Bootnodes []*enode.Node
DiscoveryDB *enode.DB
NetRestrict *netutil.Netlist
StaticPeers []core.Multiaddr
......
......@@ -97,7 +97,7 @@ func (conf *Config) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort
cfg := discover.Config{
PrivateKey: priv,
NetRestrict: nil,
NetRestrict: conf.NetRestrict,
Bootnodes: conf.Bootnodes,
Unhandled: nil, // Not used in dv5
Log: log,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment