github.com/ethereum-optimism/optimism@v1.7.2/op-node/flags/p2p_flags.go (about) 1 package flags 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/urfave/cli/v2" 8 9 "github.com/ethereum-optimism/optimism/op-node/p2p" 10 ) 11 12 func p2pEnv(envprefix, v string) []string { 13 return []string{envprefix + "_P2P_" + v} 14 } 15 16 var ( 17 DisableP2PName = "p2p.disable" 18 NoDiscoveryName = "p2p.no-discovery" 19 ScoringName = "p2p.scoring" 20 PeerScoringName = "p2p.scoring.peers" 21 PeerScoreBandsName = "p2p.score.bands" 22 BanningName = "p2p.ban.peers" 23 BanningThresholdName = "p2p.ban.threshold" 24 BanningDurationName = "p2p.ban.duration" 25 TopicScoringName = "p2p.scoring.topics" 26 P2PPrivPathName = "p2p.priv.path" 27 P2PPrivRawName = "p2p.priv.raw" 28 ListenIPName = "p2p.listen.ip" 29 ListenTCPPortName = "p2p.listen.tcp" 30 ListenUDPPortName = "p2p.listen.udp" 31 AdvertiseIPName = "p2p.advertise.ip" 32 AdvertiseTCPPortName = "p2p.advertise.tcp" 33 AdvertiseUDPPortName = "p2p.advertise.udp" 34 BootnodesName = "p2p.bootnodes" 35 StaticPeersName = "p2p.static" 36 NetRestrictName = "p2p.netrestrict" 37 HostMuxName = "p2p.mux" 38 HostSecurityName = "p2p.security" 39 PeersLoName = "p2p.peers.lo" 40 PeersHiName = "p2p.peers.hi" 41 PeersGraceName = "p2p.peers.grace" 42 NATName = "p2p.nat" 43 UserAgentName = "p2p.useragent" 44 TimeoutNegotiationName = "p2p.timeout.negotiation" 45 TimeoutAcceptName = "p2p.timeout.accept" 46 TimeoutDialName = "p2p.timeout.dial" 47 PeerstorePathName = "p2p.peerstore.path" 48 DiscoveryPathName = "p2p.discovery.path" 49 SequencerP2PKeyName = "p2p.sequencer.key" 50 GossipMeshDName = "p2p.gossip.mesh.d" 51 GossipMeshDloName = "p2p.gossip.mesh.lo" 52 GossipMeshDhiName = "p2p.gossip.mesh.dhi" 53 GossipMeshDlazyName = "p2p.gossip.mesh.dlazy" 54 GossipFloodPublishName = "p2p.gossip.mesh.floodpublish" 55 SyncReqRespName = "p2p.sync.req-resp" 56 P2PPingName = "p2p.ping" 57 ) 58 59 func deprecatedP2PFlags(envPrefix string) []cli.Flag { 60 return []cli.Flag{ 61 &cli.StringFlag{ 62 Name: PeerScoringName, 63 Usage: fmt.Sprintf("Deprecated: Use %v instead", ScoringName), 64 Required: false, 65 Hidden: true, 66 Category: P2PCategory, 67 }, 68 &cli.StringFlag{ 69 Name: PeerScoreBandsName, 70 Usage: "Deprecated. This option is ignored and is only present for backwards compatibility.", 71 Required: false, 72 Value: "", 73 Hidden: true, 74 Category: P2PCategory, 75 }, 76 &cli.StringFlag{ 77 Name: TopicScoringName, 78 Usage: fmt.Sprintf("Deprecated: Use %v instead", ScoringName), 79 Required: false, 80 Hidden: true, 81 Category: P2PCategory, 82 }, 83 } 84 } 85 86 // None of these flags are strictly required. 87 // Some are hidden if they are too technical, or not recommended. 88 func P2PFlags(envPrefix string) []cli.Flag { 89 return []cli.Flag{ 90 &cli.BoolFlag{ 91 Name: DisableP2PName, 92 Usage: "Completely disable the P2P stack", 93 Required: false, 94 EnvVars: p2pEnv(envPrefix, "DISABLE"), 95 Category: P2PCategory, 96 }, 97 &cli.BoolFlag{ 98 Name: NoDiscoveryName, 99 Usage: "Disable Discv5 (node discovery)", 100 Required: false, 101 EnvVars: p2pEnv(envPrefix, "NO_DISCOVERY"), 102 Category: P2PCategory, 103 }, 104 &cli.StringFlag{ 105 Name: ScoringName, 106 Usage: "Sets the peer scoring strategy for the P2P stack. Can be one of: none or light.", 107 Required: false, 108 Value: "light", 109 EnvVars: p2pEnv(envPrefix, "PEER_SCORING"), 110 Category: P2PCategory, 111 }, 112 &cli.BoolFlag{ 113 // Banning Flag - whether or not we want to act on the scoring 114 Name: BanningName, 115 Usage: "Enables peer banning.", 116 Value: true, 117 Required: false, 118 EnvVars: p2pEnv(envPrefix, "PEER_BANNING"), 119 Category: P2PCategory, 120 }, 121 &cli.Float64Flag{ 122 Name: BanningThresholdName, 123 Usage: "The minimum score below which peers are disconnected and banned.", 124 Required: false, 125 Value: -100, 126 EnvVars: p2pEnv(envPrefix, "PEER_BANNING_THRESHOLD"), 127 Category: P2PCategory, 128 }, 129 &cli.DurationFlag{ 130 Name: BanningDurationName, 131 Usage: "The duration that peers are banned for.", 132 Required: false, 133 Value: 1 * time.Hour, 134 EnvVars: p2pEnv(envPrefix, "PEER_BANNING_DURATION"), 135 Category: P2PCategory, 136 }, 137 &cli.StringFlag{ 138 Name: P2PPrivPathName, 139 Usage: "Read the hex-encoded 32-byte private key for the peer ID from this txt file. Created if not already exists." + 140 "Important to persist to keep the same network identity after restarting, maintaining the previous advertised identity.", 141 Required: false, 142 Value: "opnode_p2p_priv.txt", 143 EnvVars: p2pEnv(envPrefix, "PRIV_PATH"), 144 TakesFile: true, 145 Category: P2PCategory, 146 }, 147 &cli.StringFlag{ 148 // sometimes it may be ok to not persist the peer priv key as file, and instead pass it directly. 149 Name: P2PPrivRawName, 150 Usage: "The hex-encoded 32-byte private key for the peer ID", 151 Required: false, 152 Hidden: true, 153 Value: "", 154 EnvVars: p2pEnv(envPrefix, "PRIV_RAW"), 155 Category: P2PCategory, 156 }, 157 &cli.StringFlag{ 158 Name: ListenIPName, 159 Usage: "IP to bind LibP2P and Discv5 to", 160 Required: false, 161 Value: "0.0.0.0", 162 EnvVars: p2pEnv(envPrefix, "LISTEN_IP"), 163 Category: P2PCategory, 164 }, 165 &cli.UintFlag{ 166 Name: ListenTCPPortName, 167 Usage: "TCP port to bind LibP2P to. Any available system port if set to 0.", 168 Required: false, 169 Value: 9222, 170 EnvVars: p2pEnv(envPrefix, "LISTEN_TCP_PORT"), 171 Category: P2PCategory, 172 }, 173 &cli.UintFlag{ 174 Name: ListenUDPPortName, 175 Usage: "UDP port to bind Discv5 to. Same as TCP port if left 0.", 176 Required: false, 177 Value: 0, // can simply match the TCP libp2p port 178 EnvVars: p2pEnv(envPrefix, "LISTEN_UDP_PORT"), 179 Category: P2PCategory, 180 }, 181 &cli.StringFlag{ 182 Name: AdvertiseIPName, 183 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.", 184 Required: false, 185 // Ignored by default, nodes can discover their own external IP in the happy case, 186 // by communicating with bootnodes. Fixed IP is recommended for faster bootstrap though. 187 Value: "", 188 EnvVars: p2pEnv(envPrefix, "ADVERTISE_IP"), 189 Category: P2PCategory, 190 }, 191 &cli.UintFlag{ 192 Name: AdvertiseTCPPortName, 193 Usage: "The TCP port to advertise in Discv5, put into the ENR of the node. Set to p2p.listen.tcp value if 0.", 194 Required: false, 195 Value: 0, 196 EnvVars: p2pEnv(envPrefix, "ADVERTISE_TCP"), 197 Category: P2PCategory, 198 }, 199 &cli.UintFlag{ 200 Name: AdvertiseUDPPortName, 201 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.", 202 Required: false, 203 Value: 0, 204 EnvVars: p2pEnv(envPrefix, "ADVERTISE_UDP"), 205 Category: P2PCategory, 206 }, 207 &cli.StringFlag{ 208 Name: BootnodesName, 209 Usage: "Comma-separated base64-format ENR list. Bootnodes to start discovering other node records from.", 210 Required: false, 211 Value: "", 212 EnvVars: p2pEnv(envPrefix, "BOOTNODES"), 213 Category: P2PCategory, 214 }, 215 &cli.StringFlag{ 216 Name: StaticPeersName, 217 Usage: "Comma-separated multiaddr-format peer list. Static connections to make and maintain, these peers will be regarded as trusted. " + 218 "Addresses of the local peer are ignored. Duplicate/Alternative addresses for the same peer all apply, but only a single connection per peer is maintained.", 219 Required: false, 220 Value: "", 221 EnvVars: p2pEnv(envPrefix, "STATIC"), 222 Category: P2PCategory, 223 }, 224 &cli.StringFlag{ 225 Name: NetRestrictName, 226 Usage: "Comma-separated list of CIDR masks. P2P will only try to connect on these networks", 227 Required: false, 228 EnvVars: p2pEnv(envPrefix, "NETRESTRICT"), 229 Category: P2PCategory, 230 }, 231 &cli.StringFlag{ 232 Name: HostMuxName, 233 Usage: "Comma-separated list of multiplexing protocols in order of preference. At least 1 required. Options: 'yamux','mplex'.", 234 Hidden: true, 235 Required: false, 236 Value: "yamux,mplex", 237 EnvVars: p2pEnv(envPrefix, "MUX"), 238 Category: P2PCategory, 239 }, 240 &cli.StringFlag{ 241 Name: HostSecurityName, 242 Usage: "Comma-separated list of transport security protocols in order of preference. At least 1 required. Options: 'noise','tls'. Set to 'none' to disable.", 243 Hidden: true, 244 Required: false, 245 Value: "noise", 246 EnvVars: p2pEnv(envPrefix, "SECURITY"), 247 Category: P2PCategory, 248 }, 249 &cli.UintFlag{ 250 Name: PeersLoName, 251 Usage: "Low-tide peer count. The node actively searches for new peer connections if below this amount.", 252 Required: false, 253 Value: 20, 254 EnvVars: p2pEnv(envPrefix, "PEERS_LO"), 255 Category: P2PCategory, 256 }, 257 &cli.UintFlag{ 258 Name: PeersHiName, 259 Usage: "High-tide peer count. The node starts pruning peer connections slowly after reaching this number.", 260 Required: false, 261 Value: 30, 262 EnvVars: p2pEnv(envPrefix, "PEERS_HI"), 263 Category: P2PCategory, 264 }, 265 &cli.DurationFlag{ 266 Name: PeersGraceName, 267 Usage: "Grace period to keep a newly connected peer around, if it is not misbehaving.", 268 Required: false, 269 Value: 30 * time.Second, 270 EnvVars: p2pEnv(envPrefix, "PEERS_GRACE"), 271 Category: P2PCategory, 272 }, 273 &cli.BoolFlag{ 274 Name: NATName, 275 Usage: "Enable NAT traversal with PMP/UPNP devices to learn external IP.", 276 Required: false, 277 EnvVars: p2pEnv(envPrefix, "NAT"), 278 Category: P2PCategory, 279 }, 280 &cli.StringFlag{ 281 Name: UserAgentName, 282 Usage: "User-agent string to share via LibP2P identify. If empty it defaults to 'optimism'.", 283 Hidden: true, 284 Required: false, 285 Value: "optimism", 286 EnvVars: p2pEnv(envPrefix, "AGENT"), 287 Category: P2PCategory, 288 }, 289 &cli.DurationFlag{ 290 Name: TimeoutNegotiationName, 291 Usage: "Negotiation timeout, time for new peer connections to share their their supported p2p protocols", 292 Hidden: true, 293 Required: false, 294 Value: 10 * time.Second, 295 EnvVars: p2pEnv(envPrefix, "TIMEOUT_NEGOTIATION"), 296 Category: P2PCategory, 297 }, 298 &cli.DurationFlag{ 299 Name: TimeoutAcceptName, 300 Usage: "Accept timeout, time for connection to be accepted.", 301 Hidden: true, 302 Required: false, 303 Value: 10 * time.Second, 304 EnvVars: p2pEnv(envPrefix, "TIMEOUT_ACCEPT"), 305 Category: P2PCategory, 306 }, 307 &cli.DurationFlag{ 308 Name: TimeoutDialName, 309 Usage: "Dial timeout for outgoing connection requests", 310 Hidden: true, 311 Required: false, 312 Value: 10 * time.Second, 313 EnvVars: p2pEnv(envPrefix, "TIMEOUT_DIAL"), 314 Category: P2PCategory, 315 }, 316 &cli.StringFlag{ 317 Name: PeerstorePathName, 318 Usage: "Peerstore database location. Persisted peerstores help recover peers after restarts. " + 319 "Set to 'memory' to never persist the peerstore. Peerstore records will be pruned / expire as necessary. " + 320 "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 321 Required: false, 322 TakesFile: true, 323 Value: "opnode_peerstore_db", 324 EnvVars: p2pEnv(envPrefix, "PEERSTORE_PATH"), 325 Category: P2PCategory, 326 }, 327 &cli.StringFlag{ 328 Name: DiscoveryPathName, 329 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.", 330 Required: false, 331 TakesFile: true, 332 Value: "opnode_discovery_db", 333 EnvVars: p2pEnv(envPrefix, "DISCOVERY_PATH"), 334 Category: P2PCategory, 335 }, 336 &cli.StringFlag{ 337 Name: SequencerP2PKeyName, 338 Usage: "Hex-encoded private key for signing off on p2p application messages as sequencer.", 339 Required: false, 340 Value: "", 341 EnvVars: p2pEnv(envPrefix, "SEQUENCER_KEY"), 342 Category: P2PCategory, 343 }, 344 &cli.UintFlag{ 345 Name: GossipMeshDName, 346 Usage: "Configure GossipSub topic stable mesh target count, a.k.a. desired outbound degree, number of peers to gossip to", 347 Required: false, 348 Hidden: true, 349 Value: p2p.DefaultMeshD, 350 EnvVars: p2pEnv(envPrefix, "GOSSIP_MESH_D"), 351 Category: P2PCategory, 352 }, 353 &cli.UintFlag{ 354 Name: GossipMeshDloName, 355 Usage: "Configure GossipSub topic stable mesh low watermark, a.k.a. lower bound of outbound degree", 356 Required: false, 357 Hidden: true, 358 Value: p2p.DefaultMeshDlo, 359 EnvVars: p2pEnv(envPrefix, "GOSSIP_MESH_DLO"), 360 Category: P2PCategory, 361 }, 362 &cli.UintFlag{ 363 Name: GossipMeshDhiName, 364 Usage: "Configure GossipSub topic stable mesh high watermark, a.k.a. upper bound of outbound degree, additional peers will not receive gossip", 365 Required: false, 366 Hidden: true, 367 Value: p2p.DefaultMeshDhi, 368 EnvVars: p2pEnv(envPrefix, "GOSSIP_MESH_DHI"), 369 Category: P2PCategory, 370 }, 371 &cli.UintFlag{ 372 Name: GossipMeshDlazyName, 373 Usage: "Configure GossipSub gossip target, a.k.a. target degree for gossip only (not messaging like p2p.gossip.mesh.d, just announcements of IHAVE", 374 Required: false, 375 Hidden: true, 376 Value: p2p.DefaultMeshDlazy, 377 EnvVars: p2pEnv(envPrefix, "GOSSIP_MESH_DLAZY"), 378 Category: P2PCategory, 379 }, 380 &cli.BoolFlag{ 381 Name: GossipFloodPublishName, 382 Usage: "Configure GossipSub to publish messages to all known peers on the topic, outside of the mesh, also see Dlazy as less aggressive alternative.", 383 Required: false, 384 Hidden: true, 385 EnvVars: p2pEnv(envPrefix, "GOSSIP_FLOOD_PUBLISH"), 386 Category: P2PCategory, 387 }, 388 &cli.BoolFlag{ 389 Name: SyncReqRespName, 390 Usage: "Enables P2P req-resp alternative sync method, on both server and client side.", 391 Value: true, 392 Required: false, 393 EnvVars: p2pEnv(envPrefix, "SYNC_REQ_RESP"), 394 Category: P2PCategory, 395 }, 396 &cli.BoolFlag{ 397 Name: P2PPingName, 398 Usage: "Enables P2P ping-pong background service", 399 Value: true, // on by default 400 Hidden: true, // hidden, only here to disable in case of bugs. 401 Required: false, 402 EnvVars: p2pEnv(envPrefix, "PING"), 403 }, 404 } 405 }