Commit 46f73228 authored by Joshua Gutow's avatar Joshua Gutow Committed by GitHub

Merge pull request #7548 from anikaraghu/anika/p2pflags

fix: pass in env var prefix for p2p flags
parents d7fad694 8069210f
No related merge requests found
...@@ -37,7 +37,7 @@ var Flags = []cli.Flag{ ...@@ -37,7 +37,7 @@ var Flags = []cli.Flag{
} }
func init() { func init() {
Flags = append(Flags, flags.P2pFlags...) Flags = append(Flags, flags.P2PFlags(envVarPrefix)...)
Flags = append(Flags, opmetrics.CLIFlags(envVarPrefix)...) Flags = append(Flags, opmetrics.CLIFlags(envVarPrefix)...)
Flags = append(Flags, oplog.CLIFlags(envVarPrefix)...) Flags = append(Flags, oplog.CLIFlags(envVarPrefix)...)
} }
...@@ -309,7 +309,7 @@ var optionalFlags = []cli.Flag{ ...@@ -309,7 +309,7 @@ var optionalFlags = []cli.Flag{
var Flags []cli.Flag var Flags []cli.Flag
func init() { func init() {
optionalFlags = append(optionalFlags, P2pFlags...) optionalFlags = append(optionalFlags, P2PFlags(EnvVarPrefix)...)
optionalFlags = append(optionalFlags, oplog.CLIFlags(EnvVarPrefix)...) optionalFlags = append(optionalFlags, oplog.CLIFlags(EnvVarPrefix)...)
Flags = append(requiredFlags, optionalFlags...) Flags = append(requiredFlags, optionalFlags...)
} }
......
...@@ -9,343 +9,343 @@ import ( ...@@ -9,343 +9,343 @@ import (
"github.com/ethereum-optimism/optimism/op-node/p2p" "github.com/ethereum-optimism/optimism/op-node/p2p"
) )
func p2pEnv(v string) []string { func p2pEnv(envprefix, v string) []string {
return prefixEnvVars("P2P_" + v) return []string{envprefix + "_P2P_" + v}
} }
var ( var (
DisableP2P = &cli.BoolFlag{ DisableP2PName = "p2p.disable"
Name: "p2p.disable", NoDiscoveryName = "p2p.no-discovery"
Usage: "Completely disable the P2P stack", ScoringName = "p2p.scoring"
Required: false, PeerScoringName = "p2p.scoring.peers"
EnvVars: p2pEnv("DISABLE"), PeerScoreBandsName = "p2p.score.bands"
} BanningName = "p2p.ban.peers"
NoDiscovery = &cli.BoolFlag{ BanningThresholdName = "p2p.ban.threshold"
Name: "p2p.no-discovery", BanningDurationName = "p2p.ban.duration"
Usage: "Disable Discv5 (node discovery)", TopicScoringName = "p2p.scoring.topics"
Required: false, P2PPrivPathName = "p2p.priv.path"
EnvVars: p2pEnv("NO_DISCOVERY"), P2PPrivRawName = "p2p.priv.raw"
} ListenIPName = "p2p.listen.ip"
Scoring = &cli.StringFlag{ ListenTCPPortName = "p2p.listen.tcp"
Name: "p2p.scoring", ListenUDPPortName = "p2p.listen.udp"
Usage: "Sets the peer scoring strategy for the P2P stack. Can be one of: none or light.", AdvertiseIPName = "p2p.advertise.ip"
Required: false, AdvertiseTCPPortName = "p2p.advertise.tcp"
Value: "light", AdvertiseUDPPortName = "p2p.advertise.udp"
EnvVars: p2pEnv("PEER_SCORING"), BootnodesName = "p2p.bootnodes"
} StaticPeersName = "p2p.static"
PeerScoring = &cli.StringFlag{ NetRestrictName = "p2p.netrestrict"
Name: "p2p.scoring.peers", HostMuxName = "p2p.mux"
Usage: fmt.Sprintf("Deprecated: Use %v instead", Scoring.Name), HostSecurityName = "p2p.security"
Required: false, PeersLoName = "p2p.peers.lo"
Hidden: true, PeersHiName = "p2p.peers.hi"
} PeersGraceName = "p2p.peers.grace"
PeerScoreBands = &cli.StringFlag{ NATName = "p2p.nat"
Name: "p2p.score.bands", UserAgentName = "p2p.useragent"
Usage: "Deprecated. This option is ignored and is only present for backwards compatibility.", TimeoutNegotiationName = "p2p.timeout.negotiation"
Required: false, TimeoutAcceptName = "p2p.timeout.accept"
Value: "", TimeoutDialName = "p2p.timeout.dial"
Hidden: true, PeerstorePathName = "p2p.peerstore.path"
} DiscoveryPathName = "p2p.discovery.path"
SequencerP2PKeyName = "p2p.sequencer.key"
// Banning Flag - whether or not we want to act on the scoring GossipMeshDName = "p2p.gossip.mesh.d"
Banning = &cli.BoolFlag{ GossipMeshDloName = "p2p.gossip.mesh.lo"
Name: "p2p.ban.peers", GossipMeshDhiName = "p2p.gossip.mesh.dhi"
Usage: "Enables peer banning.", GossipMeshDlazyName = "p2p.gossip.mesh.dlazy"
Value: true, GossipFloodPublishName = "p2p.gossip.mesh.floodpublish"
Required: false, SyncReqRespName = "p2p.sync.req-resp"
EnvVars: p2pEnv("PEER_BANNING"),
}
BanningThreshold = &cli.Float64Flag{
Name: "p2p.ban.threshold",
Usage: "The minimum score below which peers are disconnected and banned.",
Required: false,
Value: -100,
EnvVars: p2pEnv("PEER_BANNING_THRESHOLD"),
}
BanningDuration = &cli.DurationFlag{
Name: "p2p.ban.duration",
Usage: "The duration that peers are banned for.",
Required: false,
Value: 1 * time.Hour,
EnvVars: p2pEnv("PEER_BANNING_DURATION"),
}
TopicScoring = &cli.StringFlag{
Name: "p2p.scoring.topics",
Usage: fmt.Sprintf("Deprecated: Use %v instead", Scoring.Name),
Required: false,
Hidden: true,
}
P2PPrivPath = &cli.StringFlag{
Name: "p2p.priv.path",
Usage: "Read the hex-encoded 32-byte private key for the peer ID from this txt file. Created if not already exists." +
"Important to persist to keep the same network identity after restarting, maintaining the previous advertised identity.",
Required: false,
Value: "opnode_p2p_priv.txt",
EnvVars: p2pEnv("PRIV_PATH"),
TakesFile: true,
}
P2PPrivRaw = &cli.StringFlag{
// sometimes it may be ok to not persist the peer priv key as file, and instead pass it directly.
Name: "p2p.priv.raw",
Usage: "The hex-encoded 32-byte private key for the peer ID",
Required: false,
Hidden: true,
Value: "",
EnvVars: p2pEnv("PRIV_RAW"),
}
ListenIP = &cli.StringFlag{
Name: "p2p.listen.ip",
Usage: "IP to bind LibP2P and Discv5 to",
Required: false,
Value: "0.0.0.0",
EnvVars: p2pEnv("LISTEN_IP"),
}
ListenTCPPort = &cli.UintFlag{
Name: "p2p.listen.tcp",
Usage: "TCP port to bind LibP2P to. Any available system port if set to 0.",
Required: false,
Value: 9222,
EnvVars: p2pEnv("LISTEN_TCP_PORT"),
}
ListenUDPPort = &cli.UintFlag{
Name: "p2p.listen.udp",
Usage: "UDP port to bind Discv5 to. Same as TCP port if left 0.",
Required: false,
Value: 0, // can simply match the TCP libp2p port
EnvVars: p2pEnv("LISTEN_UDP_PORT"),
}
AdvertiseIP = &cli.StringFlag{
Name: "p2p.advertise.ip",
Usage: "The IP address to advertise in Discv5, put into the ENR of the node. This may also be a hostname / domain name to resolve to an IP.",
Required: false,
// Ignored by default, nodes can discover their own external IP in the happy case,
// by communicating with bootnodes. Fixed IP is recommended for faster bootstrap though.
Value: "",
EnvVars: p2pEnv("ADVERTISE_IP"),
}
AdvertiseTCPPort = &cli.UintFlag{
Name: "p2p.advertise.tcp",
Usage: "The TCP port to advertise in Discv5, put into the ENR of the node. Set to p2p.listen.tcp value if 0.",
Required: false,
Value: 0,
EnvVars: p2pEnv("ADVERTISE_TCP"),
}
AdvertiseUDPPort = &cli.UintFlag{
Name: "p2p.advertise.udp",
Usage: "The UDP port to advertise in Discv5 as fallback if not determined by Discv5, put into the ENR of the node. Set to p2p.listen.udp value if 0.",
Required: false,
Value: 0,
EnvVars: p2pEnv("ADVERTISE_UDP"),
}
Bootnodes = &cli.StringFlag{
Name: "p2p.bootnodes",
Usage: "Comma-separated base64-format ENR list. Bootnodes to start discovering other node records from.",
Required: false,
Value: "",
EnvVars: p2pEnv("BOOTNODES"),
}
StaticPeers = &cli.StringFlag{
Name: "p2p.static",
Usage: "Comma-separated multiaddr-format peer list. Static connections to make and maintain, these peers will be regarded as trusted.",
Required: false,
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,
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'.",
Hidden: true,
Required: false,
Value: "yamux,mplex",
EnvVars: p2pEnv("MUX"),
}
HostSecurity = &cli.StringFlag{
Name: "p2p.security",
Usage: "Comma-separated list of transport security protocols in order of preference. At least 1 required. Options: 'noise','tls'. Set to 'none' to disable.",
Hidden: true,
Required: false,
Value: "noise",
EnvVars: p2pEnv("SECURITY"),
}
PeersLo = &cli.UintFlag{
Name: "p2p.peers.lo",
Usage: "Low-tide peer count. The node actively searches for new peer connections if below this amount.",
Required: false,
Value: 20,
EnvVars: p2pEnv("PEERS_LO"),
}
PeersHi = &cli.UintFlag{
Name: "p2p.peers.hi",
Usage: "High-tide peer count. The node starts pruning peer connections slowly after reaching this number.",
Required: false,
Value: 30,
EnvVars: p2pEnv("PEERS_HI"),
}
PeersGrace = &cli.DurationFlag{
Name: "p2p.peers.grace",
Usage: "Grace period to keep a newly connected peer around, if it is not misbehaving.",
Required: false,
Value: 30 * time.Second,
EnvVars: p2pEnv("PEERS_GRACE"),
}
NAT = &cli.BoolFlag{
Name: "p2p.nat",
Usage: "Enable NAT traversal with PMP/UPNP devices to learn external IP.",
Required: false,
EnvVars: p2pEnv("NAT"),
}
UserAgent = &cli.StringFlag{
Name: "p2p.useragent",
Usage: "User-agent string to share via LibP2P identify. If empty it defaults to 'optimism'.",
Hidden: true,
Required: false,
Value: "optimism",
EnvVars: p2pEnv("AGENT"),
}
TimeoutNegotiation = &cli.DurationFlag{
Name: "p2p.timeout.negotiation",
Usage: "Negotiation timeout, time for new peer connections to share their their supported p2p protocols",
Hidden: true,
Required: false,
Value: 10 * time.Second,
EnvVars: p2pEnv("TIMEOUT_NEGOTIATION"),
}
TimeoutAccept = &cli.DurationFlag{
Name: "p2p.timeout.accept",
Usage: "Accept timeout, time for connection to be accepted.",
Hidden: true,
Required: false,
Value: 10 * time.Second,
EnvVars: p2pEnv("TIMEOUT_ACCEPT"),
}
TimeoutDial = &cli.DurationFlag{
Name: "p2p.timeout.dial",
Usage: "Dial timeout for outgoing connection requests",
Hidden: true,
Required: false,
Value: 10 * time.Second,
EnvVars: p2pEnv("TIMEOUT_DIAL"),
}
PeerstorePath = &cli.StringFlag{
Name: "p2p.peerstore.path",
Usage: "Peerstore database location. Persisted peerstores help recover peers after restarts. " +
"Set to 'memory' to never persist the peerstore. Peerstore records will be pruned / expire as necessary. " +
"Warning: a copy of the priv network key of the local peer will be persisted here.", // TODO: bad design of libp2p, maybe we can avoid this from happening
Required: false,
TakesFile: true,
Value: "opnode_peerstore_db",
EnvVars: p2pEnv("PEERSTORE_PATH"),
}
DiscoveryPath = &cli.StringFlag{
Name: "p2p.discovery.path",
Usage: "Discovered ENRs are persisted in a database to recover from a restart without having to bootstrap the discovery process again. Set to 'memory' to never persist the peerstore.",
Required: false,
TakesFile: true,
Value: "opnode_discovery_db",
EnvVars: p2pEnv("DISCOVERY_PATH"),
}
SequencerP2PKeyFlag = &cli.StringFlag{
Name: "p2p.sequencer.key",
Usage: "Hex-encoded private key for signing off on p2p application messages as sequencer.",
Required: false,
Value: "",
EnvVars: p2pEnv("SEQUENCER_KEY"),
}
GossipMeshDFlag = &cli.UintFlag{
Name: "p2p.gossip.mesh.d",
Usage: "Configure GossipSub topic stable mesh target count, a.k.a. desired outbound degree, number of peers to gossip to",
Required: false,
Hidden: true,
Value: p2p.DefaultMeshD,
EnvVars: p2pEnv("GOSSIP_MESH_D"),
}
GossipMeshDloFlag = &cli.UintFlag{
Name: "p2p.gossip.mesh.lo",
Usage: "Configure GossipSub topic stable mesh low watermark, a.k.a. lower bound of outbound degree",
Required: false,
Hidden: true,
Value: p2p.DefaultMeshDlo,
EnvVars: p2pEnv("GOSSIP_MESH_DLO"),
}
GossipMeshDhiFlag = &cli.UintFlag{
Name: "p2p.gossip.mesh.dhi",
Usage: "Configure GossipSub topic stable mesh high watermark, a.k.a. upper bound of outbound degree, additional peers will not receive gossip",
Required: false,
Hidden: true,
Value: p2p.DefaultMeshDhi,
EnvVars: p2pEnv("GOSSIP_MESH_DHI"),
}
GossipMeshDlazyFlag = &cli.UintFlag{
Name: "p2p.gossip.mesh.dlazy",
Usage: "Configure GossipSub gossip target, a.k.a. target degree for gossip only (not messaging like p2p.gossip.mesh.d, just announcements of IHAVE",
Required: false,
Hidden: true,
Value: p2p.DefaultMeshDlazy,
EnvVars: p2pEnv("GOSSIP_MESH_DLAZY"),
}
GossipFloodPublishFlag = &cli.BoolFlag{
Name: "p2p.gossip.mesh.floodpublish",
Usage: "Configure GossipSub to publish messages to all known peers on the topic, outside of the mesh, also see Dlazy as less aggressive alternative.",
Required: false,
Hidden: true,
EnvVars: p2pEnv("GOSSIP_FLOOD_PUBLISH"),
}
SyncReqRespFlag = &cli.BoolFlag{
Name: "p2p.sync.req-resp",
Usage: "Enables P2P req-resp alternative sync method, on both server and client side.",
Value: true,
Required: false,
EnvVars: p2pEnv("SYNC_REQ_RESP"),
}
) )
// None of these flags are strictly required. // None of these flags are strictly required.
// Some are hidden if they are too technical, or not recommended. // Some are hidden if they are too technical, or not recommended.
var P2pFlags = []cli.Flag{ func P2PFlags(envPrefix string) []cli.Flag {
DisableP2P, return []cli.Flag{
NoDiscovery, &cli.BoolFlag{
P2PPrivPath, Name: DisableP2PName,
P2PPrivRaw, Usage: "Completely disable the P2P stack",
Scoring, Required: false,
PeerScoring, EnvVars: p2pEnv(envPrefix, "DISABLE"),
PeerScoreBands, },
Banning, &cli.BoolFlag{
BanningThreshold, Name: NoDiscoveryName,
BanningDuration, Usage: "Disable Discv5 (node discovery)",
TopicScoring, Required: false,
ListenIP, EnvVars: p2pEnv(envPrefix, "NO_DISCOVERY"),
ListenTCPPort, },
ListenUDPPort, &cli.StringFlag{
AdvertiseIP, Name: ScoringName,
AdvertiseTCPPort, Usage: "Sets the peer scoring strategy for the P2P stack. Can be one of: none or light.",
AdvertiseUDPPort, Required: false,
Bootnodes, Value: "light",
StaticPeers, EnvVars: p2pEnv(envPrefix, "PEER_SCORING"),
NetRestrict, },
HostMux, &cli.StringFlag{
HostSecurity, Name: PeerScoringName,
PeersLo, Usage: fmt.Sprintf("Deprecated: Use %v instead", ScoringName),
PeersHi, Required: false,
PeersGrace, Hidden: true,
NAT, },
UserAgent, &cli.StringFlag{
TimeoutNegotiation, Name: PeerScoreBandsName,
TimeoutAccept, Usage: "Deprecated. This option is ignored and is only present for backwards compatibility.",
TimeoutDial, Required: false,
PeerstorePath, Value: "",
DiscoveryPath, Hidden: true,
SequencerP2PKeyFlag, },
GossipMeshDFlag, &cli.BoolFlag{
GossipMeshDloFlag, // Banning Flag - whether or not we want to act on the scoring
GossipMeshDhiFlag, Name: BanningName,
GossipMeshDlazyFlag, Usage: "Enables peer banning.",
GossipFloodPublishFlag, Value: true,
SyncReqRespFlag, Required: false,
EnvVars: p2pEnv(envPrefix, "PEER_BANNING"),
},
&cli.Float64Flag{
Name: BanningThresholdName,
Usage: "The minimum score below which peers are disconnected and banned.",
Required: false,
Value: -100,
EnvVars: p2pEnv(envPrefix, "PEER_BANNING_THRESHOLD"),
},
&cli.DurationFlag{
Name: BanningDurationName,
Usage: "The duration that peers are banned for.",
Required: false,
Value: 1 * time.Hour,
EnvVars: p2pEnv(envPrefix, "PEER_BANNING_DURATION"),
},
&cli.StringFlag{
Name: TopicScoringName,
Usage: fmt.Sprintf("Deprecated: Use %v instead", ScoringName),
Required: false,
Hidden: true,
},
&cli.StringFlag{
Name: P2PPrivPathName,
Usage: "Read the hex-encoded 32-byte private key for the peer ID from this txt file. Created if not already exists." +
"Important to persist to keep the same network identity after restarting, maintaining the previous advertised identity.",
Required: false,
Value: "opnode_p2p_priv.txt",
EnvVars: p2pEnv(envPrefix, "PRIV_PATH"),
TakesFile: true,
},
&cli.StringFlag{
// sometimes it may be ok to not persist the peer priv key as file, and instead pass it directly.
Name: P2PPrivRawName,
Usage: "The hex-encoded 32-byte private key for the peer ID",
Required: false,
Hidden: true,
Value: "",
EnvVars: p2pEnv(envPrefix, "PRIV_RAW"),
},
&cli.StringFlag{
Name: ListenIPName,
Usage: "IP to bind LibP2P and Discv5 to",
Required: false,
Value: "0.0.0.0",
EnvVars: p2pEnv(envPrefix, "LISTEN_IP"),
},
&cli.UintFlag{
Name: ListenTCPPortName,
Usage: "TCP port to bind LibP2P to. Any available system port if set to 0.",
Required: false,
Value: 9222,
EnvVars: p2pEnv(envPrefix, "LISTEN_TCP_PORT"),
},
&cli.UintFlag{
Name: ListenUDPPortName,
Usage: "UDP port to bind Discv5 to. Same as TCP port if left 0.",
Required: false,
Value: 0, // can simply match the TCP libp2p port
EnvVars: p2pEnv(envPrefix, "LISTEN_UDP_PORT"),
},
&cli.StringFlag{
Name: AdvertiseIPName,
Usage: "The IP address to advertise in Discv5, put into the ENR of the node. This may also be a hostname / domain name to resolve to an IP.",
Required: false,
// Ignored by default, nodes can discover their own external IP in the happy case,
// by communicating with bootnodes. Fixed IP is recommended for faster bootstrap though.
Value: "",
EnvVars: p2pEnv(envPrefix, "ADVERTISE_IP"),
},
&cli.UintFlag{
Name: AdvertiseTCPPortName,
Usage: "The TCP port to advertise in Discv5, put into the ENR of the node. Set to p2p.listen.tcp value if 0.",
Required: false,
Value: 0,
EnvVars: p2pEnv(envPrefix, "ADVERTISE_TCP"),
},
&cli.UintFlag{
Name: AdvertiseUDPPortName,
Usage: "The UDP port to advertise in Discv5 as fallback if not determined by Discv5, put into the ENR of the node. Set to p2p.listen.udp value if 0.",
Required: false,
Value: 0,
EnvVars: p2pEnv(envPrefix, "ADVERTISE_UDP"),
},
&cli.StringFlag{
Name: BootnodesName,
Usage: "Comma-separated base64-format ENR list. Bootnodes to start discovering other node records from.",
Required: false,
Value: "",
EnvVars: p2pEnv(envPrefix, "BOOTNODES"),
},
&cli.StringFlag{
Name: StaticPeersName,
Usage: "Comma-separated multiaddr-format peer list. Static connections to make and maintain, these peers will be regarded as trusted.",
Required: false,
Value: "",
EnvVars: p2pEnv(envPrefix, "STATIC"),
},
&cli.StringFlag{
Name: NetRestrictName,
Usage: "Comma-separated list of CIDR masks. P2P will only try to connect on these networks",
Required: false,
EnvVars: p2pEnv(envPrefix, "NETRESTRICT"),
},
&cli.StringFlag{
Name: HostMuxName,
Usage: "Comma-separated list of multiplexing protocols in order of preference. At least 1 required. Options: 'yamux','mplex'.",
Hidden: true,
Required: false,
Value: "yamux,mplex",
EnvVars: p2pEnv(envPrefix, "MUX"),
},
&cli.StringFlag{
Name: HostSecurityName,
Usage: "Comma-separated list of transport security protocols in order of preference. At least 1 required. Options: 'noise','tls'. Set to 'none' to disable.",
Hidden: true,
Required: false,
Value: "noise",
EnvVars: p2pEnv(envPrefix, "SECURITY"),
},
&cli.UintFlag{
Name: PeersLoName,
Usage: "Low-tide peer count. The node actively searches for new peer connections if below this amount.",
Required: false,
Value: 20,
EnvVars: p2pEnv(envPrefix, "PEERS_LO"),
},
&cli.UintFlag{
Name: PeersHiName,
Usage: "High-tide peer count. The node starts pruning peer connections slowly after reaching this number.",
Required: false,
Value: 30,
EnvVars: p2pEnv(envPrefix, "PEERS_HI"),
},
&cli.DurationFlag{
Name: PeersGraceName,
Usage: "Grace period to keep a newly connected peer around, if it is not misbehaving.",
Required: false,
Value: 30 * time.Second,
EnvVars: p2pEnv(envPrefix, "PEERS_GRACE"),
},
&cli.BoolFlag{
Name: NATName,
Usage: "Enable NAT traversal with PMP/UPNP devices to learn external IP.",
Required: false,
EnvVars: p2pEnv(envPrefix, "NAT"),
},
&cli.StringFlag{
Name: UserAgentName,
Usage: "User-agent string to share via LibP2P identify. If empty it defaults to 'optimism'.",
Hidden: true,
Required: false,
Value: "optimism",
EnvVars: p2pEnv(envPrefix, "AGENT"),
},
&cli.DurationFlag{
Name: TimeoutNegotiationName,
Usage: "Negotiation timeout, time for new peer connections to share their their supported p2p protocols",
Hidden: true,
Required: false,
Value: 10 * time.Second,
EnvVars: p2pEnv(envPrefix, "TIMEOUT_NEGOTIATION"),
},
&cli.DurationFlag{
Name: TimeoutAcceptName,
Usage: "Accept timeout, time for connection to be accepted.",
Hidden: true,
Required: false,
Value: 10 * time.Second,
EnvVars: p2pEnv(envPrefix, "TIMEOUT_ACCEPT"),
},
&cli.DurationFlag{
Name: TimeoutDialName,
Usage: "Dial timeout for outgoing connection requests",
Hidden: true,
Required: false,
Value: 10 * time.Second,
EnvVars: p2pEnv(envPrefix, "TIMEOUT_DIAL"),
},
&cli.StringFlag{
Name: PeerstorePathName,
Usage: "Peerstore database location. Persisted peerstores help recover peers after restarts. " +
"Set to 'memory' to never persist the peerstore. Peerstore records will be pruned / expire as necessary. " +
"Warning: a copy of the priv network key of the local peer will be persisted here.", // TODO: bad design of libp2p, maybe we can avoid this from happening
Required: false,
TakesFile: true,
Value: "opnode_peerstore_db",
EnvVars: p2pEnv(envPrefix, "PEERSTORE_PATH"),
},
&cli.StringFlag{
Name: DiscoveryPathName,
Usage: "Discovered ENRs are persisted in a database to recover from a restart without having to bootstrap the discovery process again. Set to 'memory' to never persist the peerstore.",
Required: false,
TakesFile: true,
Value: "opnode_discovery_db",
EnvVars: p2pEnv(envPrefix, "DISCOVERY_PATH"),
},
&cli.StringFlag{
Name: SequencerP2PKeyName,
Usage: "Hex-encoded private key for signing off on p2p application messages as sequencer.",
Required: false,
Value: "",
EnvVars: p2pEnv(envPrefix, "SEQUENCER_KEY"),
},
&cli.UintFlag{
Name: GossipMeshDName,
Usage: "Configure GossipSub topic stable mesh target count, a.k.a. desired outbound degree, number of peers to gossip to",
Required: false,
Hidden: true,
Value: p2p.DefaultMeshD,
EnvVars: p2pEnv(envPrefix, "GOSSIP_MESH_D"),
},
&cli.UintFlag{
Name: GossipMeshDloName,
Usage: "Configure GossipSub topic stable mesh low watermark, a.k.a. lower bound of outbound degree",
Required: false,
Hidden: true,
Value: p2p.DefaultMeshDlo,
EnvVars: p2pEnv(envPrefix, "GOSSIP_MESH_DLO"),
},
&cli.UintFlag{
Name: GossipMeshDhiName,
Usage: "Configure GossipSub topic stable mesh high watermark, a.k.a. upper bound of outbound degree, additional peers will not receive gossip",
Required: false,
Hidden: true,
Value: p2p.DefaultMeshDhi,
EnvVars: p2pEnv(envPrefix, "GOSSIP_MESH_DHI"),
},
&cli.UintFlag{
Name: GossipMeshDlazyName,
Usage: "Configure GossipSub gossip target, a.k.a. target degree for gossip only (not messaging like p2p.gossip.mesh.d, just announcements of IHAVE",
Required: false,
Hidden: true,
Value: p2p.DefaultMeshDlazy,
EnvVars: p2pEnv(envPrefix, "GOSSIP_MESH_DLAZY"),
},
&cli.BoolFlag{
Name: GossipFloodPublishName,
Usage: "Configure GossipSub to publish messages to all known peers on the topic, outside of the mesh, also see Dlazy as less aggressive alternative.",
Required: false,
Hidden: true,
EnvVars: p2pEnv(envPrefix, "GOSSIP_FLOOD_PUBLISH"),
},
&cli.BoolFlag{
Name: SyncReqRespName,
Usage: "Enables P2P req-resp alternative sync method, on both server and client side.",
Value: true,
Required: false,
EnvVars: p2pEnv(envPrefix, "SYNC_REQ_RESP"),
},
}
} }
...@@ -29,7 +29,7 @@ import ( ...@@ -29,7 +29,7 @@ import (
func NewConfig(ctx *cli.Context, rollupCfg *rollup.Config) (*p2p.Config, error) { func NewConfig(ctx *cli.Context, rollupCfg *rollup.Config) (*p2p.Config, error) {
conf := &p2p.Config{} conf := &p2p.Config{}
if ctx.Bool(flags.DisableP2P.Name) { if ctx.Bool(flags.DisableP2PName) {
conf.DisableP2P = true conf.DisableP2P = true
return conf, nil return conf, nil
} }
...@@ -64,7 +64,7 @@ func NewConfig(ctx *cli.Context, rollupCfg *rollup.Config) (*p2p.Config, error) ...@@ -64,7 +64,7 @@ func NewConfig(ctx *cli.Context, rollupCfg *rollup.Config) (*p2p.Config, error)
return nil, fmt.Errorf("failed to load banning option: %w", err) return nil, fmt.Errorf("failed to load banning option: %w", err)
} }
conf.EnableReqRespSync = ctx.Bool(flags.SyncReqRespFlag.Name) conf.EnableReqRespSync = ctx.Bool(flags.SyncReqRespName)
return conf, nil return conf, nil
} }
...@@ -84,13 +84,13 @@ func validatePort(p uint) (uint16, error) { ...@@ -84,13 +84,13 @@ func validatePort(p uint) (uint16, error) {
// loadScoringParams loads the peer scoring options from the CLI context. // loadScoringParams loads the peer scoring options from the CLI context.
func loadScoringParams(conf *p2p.Config, ctx *cli.Context, rollupCfg *rollup.Config) error { func loadScoringParams(conf *p2p.Config, ctx *cli.Context, rollupCfg *rollup.Config) error {
scoringLevel := ctx.String(flags.Scoring.Name) scoringLevel := ctx.String(flags.ScoringName)
// Check old names for backwards compatibility // Check old names for backwards compatibility
if scoringLevel == "" { if scoringLevel == "" {
scoringLevel = ctx.String(flags.PeerScoring.Name) scoringLevel = ctx.String(flags.PeerScoringName)
} }
if scoringLevel == "" { if scoringLevel == "" {
scoringLevel = ctx.String(flags.TopicScoring.Name) scoringLevel = ctx.String(flags.TopicScoringName)
} }
if scoringLevel != "" { if scoringLevel != "" {
params, err := p2p.GetScoringParams(scoringLevel, rollupCfg) params, err := p2p.GetScoringParams(scoringLevel, rollupCfg)
...@@ -105,14 +105,14 @@ func loadScoringParams(conf *p2p.Config, ctx *cli.Context, rollupCfg *rollup.Con ...@@ -105,14 +105,14 @@ func loadScoringParams(conf *p2p.Config, ctx *cli.Context, rollupCfg *rollup.Con
// loadBanningOptions loads whether or not to ban peers from the CLI context. // loadBanningOptions loads whether or not to ban peers from the CLI context.
func loadBanningOptions(conf *p2p.Config, ctx *cli.Context) error { func loadBanningOptions(conf *p2p.Config, ctx *cli.Context) error {
conf.BanningEnabled = ctx.Bool(flags.Banning.Name) conf.BanningEnabled = ctx.Bool(flags.BanningName)
conf.BanningThreshold = ctx.Float64(flags.BanningThreshold.Name) conf.BanningThreshold = ctx.Float64(flags.BanningThresholdName)
conf.BanningDuration = ctx.Duration(flags.BanningDuration.Name) conf.BanningDuration = ctx.Duration(flags.BanningDurationName)
return nil return nil
} }
func loadListenOpts(conf *p2p.Config, ctx *cli.Context) error { func loadListenOpts(conf *p2p.Config, ctx *cli.Context) error {
listenIP := ctx.String(flags.ListenIP.Name) listenIP := ctx.String(flags.ListenIPName)
if listenIP != "" { // optional if listenIP != "" { // optional
conf.ListenIP = net.ParseIP(listenIP) conf.ListenIP = net.ParseIP(listenIP)
if conf.ListenIP == nil { if conf.ListenIP == nil {
...@@ -120,11 +120,11 @@ func loadListenOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -120,11 +120,11 @@ func loadListenOpts(conf *p2p.Config, ctx *cli.Context) error {
} }
} }
var err error var err error
conf.ListenTCPPort, err = validatePort(ctx.Uint(flags.ListenTCPPort.Name)) conf.ListenTCPPort, err = validatePort(ctx.Uint(flags.ListenTCPPortName))
if err != nil { if err != nil {
return fmt.Errorf("bad listen TCP port: %w", err) return fmt.Errorf("bad listen TCP port: %w", err)
} }
conf.ListenUDPPort, err = validatePort(ctx.Uint(flags.ListenUDPPort.Name)) conf.ListenUDPPort, err = validatePort(ctx.Uint(flags.ListenUDPPortName))
if err != nil { if err != nil {
return fmt.Errorf("bad listen UDP port: %w", err) return fmt.Errorf("bad listen UDP port: %w", err)
} }
...@@ -132,20 +132,20 @@ func loadListenOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -132,20 +132,20 @@ func loadListenOpts(conf *p2p.Config, ctx *cli.Context) error {
} }
func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error { func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error {
if ctx.Bool(flags.NoDiscovery.Name) { if ctx.Bool(flags.NoDiscoveryName) {
conf.NoDiscovery = true conf.NoDiscovery = true
} }
var err error var err error
conf.AdvertiseTCPPort, err = validatePort(ctx.Uint(flags.AdvertiseTCPPort.Name)) conf.AdvertiseTCPPort, err = validatePort(ctx.Uint(flags.AdvertiseTCPPortName))
if err != nil { if err != nil {
return fmt.Errorf("bad advertised TCP port: %w", err) return fmt.Errorf("bad advertised TCP port: %w", err)
} }
conf.AdvertiseUDPPort, err = validatePort(ctx.Uint(flags.AdvertiseUDPPort.Name)) conf.AdvertiseUDPPort, err = validatePort(ctx.Uint(flags.AdvertiseUDPPortName))
if err != nil { if err != nil {
return fmt.Errorf("bad advertised UDP port: %w", err) return fmt.Errorf("bad advertised UDP port: %w", err)
} }
adIP := ctx.String(flags.AdvertiseIP.Name) adIP := ctx.String(flags.AdvertiseIPName)
if adIP != "" { // optional if adIP != "" { // optional
ips, err := net.LookupIP(adIP) ips, err := net.LookupIP(adIP)
if err != nil { if err != nil {
...@@ -163,7 +163,7 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -163,7 +163,7 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error {
} }
} }
dbPath := ctx.String(flags.DiscoveryPath.Name) dbPath := ctx.String(flags.DiscoveryPathName)
if dbPath == "" { if dbPath == "" {
dbPath = "opnode_discovery_db" dbPath = "opnode_discovery_db"
} }
...@@ -176,7 +176,7 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -176,7 +176,7 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error {
} }
bootnodes := make([]*enode.Node, 0) bootnodes := make([]*enode.Node, 0)
records := strings.Split(ctx.String(flags.Bootnodes.Name), ",") records := strings.Split(ctx.String(flags.BootnodesName), ",")
for i, recordB64 := range records { for i, recordB64 := range records {
recordB64 = strings.TrimSpace(recordB64) recordB64 = strings.TrimSpace(recordB64)
if recordB64 == "" { // ignore empty records if recordB64 == "" { // ignore empty records
...@@ -194,8 +194,8 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -194,8 +194,8 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error {
conf.Bootnodes = p2p.DefaultBootnodes conf.Bootnodes = p2p.DefaultBootnodes
} }
if ctx.IsSet(flags.NetRestrict.Name) { if ctx.IsSet(flags.NetRestrictName) {
netRestrict, err := netutil.ParseNetlist(ctx.String(flags.NetRestrict.Name)) netRestrict, err := netutil.ParseNetlist(ctx.String(flags.NetRestrictName))
if err != nil { if err != nil {
return fmt.Errorf("failed to parse net list: %w", err) return fmt.Errorf("failed to parse net list: %w", err)
} }
...@@ -206,7 +206,7 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -206,7 +206,7 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error {
} }
func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error { func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error {
addrs := strings.Split(ctx.String(flags.StaticPeers.Name), ",") addrs := strings.Split(ctx.String(flags.StaticPeersName), ",")
for i, addr := range addrs { for i, addr := range addrs {
addr = strings.TrimSpace(addr) addr = strings.TrimSpace(addr)
if addr == "" { if addr == "" {
...@@ -219,7 +219,7 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -219,7 +219,7 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error {
conf.StaticPeers = append(conf.StaticPeers, a) conf.StaticPeers = append(conf.StaticPeers, a)
} }
for _, v := range strings.Split(ctx.String(flags.HostMux.Name), ",") { for _, v := range strings.Split(ctx.String(flags.HostMuxName), ",") {
v = strings.ToLower(strings.TrimSpace(v)) v = strings.ToLower(strings.TrimSpace(v))
switch v { switch v {
case "yamux": case "yamux":
...@@ -231,7 +231,7 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -231,7 +231,7 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error {
} }
} }
secArr := strings.Split(ctx.String(flags.HostSecurity.Name), ",") secArr := strings.Split(ctx.String(flags.HostSecurityName), ",")
for _, v := range secArr { for _, v := range secArr {
v = strings.ToLower(strings.TrimSpace(v)) v = strings.ToLower(strings.TrimSpace(v))
switch v { switch v {
...@@ -249,16 +249,16 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -249,16 +249,16 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error {
} }
} }
conf.PeersLo = ctx.Uint(flags.PeersLo.Name) conf.PeersLo = ctx.Uint(flags.PeersLoName)
conf.PeersHi = ctx.Uint(flags.PeersHi.Name) conf.PeersHi = ctx.Uint(flags.PeersHiName)
conf.PeersGrace = ctx.Duration(flags.PeersGrace.Name) conf.PeersGrace = ctx.Duration(flags.PeersGraceName)
conf.NAT = ctx.Bool(flags.NAT.Name) conf.NAT = ctx.Bool(flags.NATName)
conf.UserAgent = ctx.String(flags.UserAgent.Name) conf.UserAgent = ctx.String(flags.UserAgentName)
conf.TimeoutNegotiation = ctx.Duration(flags.TimeoutNegotiation.Name) conf.TimeoutNegotiation = ctx.Duration(flags.TimeoutNegotiationName)
conf.TimeoutAccept = ctx.Duration(flags.TimeoutAccept.Name) conf.TimeoutAccept = ctx.Duration(flags.TimeoutAcceptName)
conf.TimeoutDial = ctx.Duration(flags.TimeoutDial.Name) conf.TimeoutDial = ctx.Duration(flags.TimeoutDialName)
peerstorePath := ctx.String(flags.PeerstorePath.Name) peerstorePath := ctx.String(flags.PeerstorePathName)
if peerstorePath == "" { if peerstorePath == "" {
return errors.New("peerstore path must be specified, use 'memory' to explicitly not persist peer records") return errors.New("peerstore path must be specified, use 'memory' to explicitly not persist peer records")
} }
...@@ -279,11 +279,11 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -279,11 +279,11 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error {
} }
func loadNetworkPrivKey(ctx *cli.Context) (*crypto.Secp256k1PrivateKey, error) { func loadNetworkPrivKey(ctx *cli.Context) (*crypto.Secp256k1PrivateKey, error) {
raw := ctx.String(flags.P2PPrivRaw.Name) raw := ctx.String(flags.P2PPrivRawName)
if raw != "" { if raw != "" {
return parsePriv(raw) return parsePriv(raw)
} }
keyPath := ctx.String(flags.P2PPrivPath.Name) keyPath := ctx.String(flags.P2PPrivPathName)
if keyPath == "" { if keyPath == "" {
return nil, errors.New("no p2p private key path specified, cannot auto-generate key without path") return nil, errors.New("no p2p private key path specified, cannot auto-generate key without path")
} }
...@@ -333,10 +333,10 @@ func parsePriv(data string) (*crypto.Secp256k1PrivateKey, error) { ...@@ -333,10 +333,10 @@ func parsePriv(data string) (*crypto.Secp256k1PrivateKey, error) {
} }
func loadGossipOptions(conf *p2p.Config, ctx *cli.Context) error { func loadGossipOptions(conf *p2p.Config, ctx *cli.Context) error {
conf.MeshD = ctx.Int(flags.GossipMeshDFlag.Name) conf.MeshD = ctx.Int(flags.GossipMeshDName)
conf.MeshDLo = ctx.Int(flags.GossipMeshDloFlag.Name) conf.MeshDLo = ctx.Int(flags.GossipMeshDloName)
conf.MeshDHi = ctx.Int(flags.GossipMeshDhiFlag.Name) conf.MeshDHi = ctx.Int(flags.GossipMeshDhiName)
conf.MeshDLazy = ctx.Int(flags.GossipMeshDlazyFlag.Name) conf.MeshDLazy = ctx.Int(flags.GossipMeshDlazyName)
conf.FloodPublish = ctx.Bool(flags.GossipFloodPublishFlag.Name) conf.FloodPublish = ctx.Bool(flags.GossipFloodPublishName)
return nil return nil
} }
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
// LoadSignerSetup loads a configuration for a Signer to be set up later // LoadSignerSetup loads a configuration for a Signer to be set up later
func LoadSignerSetup(ctx *cli.Context) (p2p.SignerSetup, error) { func LoadSignerSetup(ctx *cli.Context) (p2p.SignerSetup, error) {
key := ctx.String(flags.SequencerP2PKeyFlag.Name) key := ctx.String(flags.SequencerP2PKeyName)
if key != "" { if key != "" {
// Mnemonics are bad because they leak *all* keys when they leak. // Mnemonics are bad because they leak *all* keys when they leak.
// Unencrypted keys from file are bad because they are easy to leak (and we are not checking file permissions). // Unencrypted keys from file are bad because they are easy to leak (and we are not checking file permissions).
......
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