cmd, node: initialize ports with --instance
Description
This PR adds a new CLI flag called --instance <value>, used to configure ports when running multiple nodes on the same machine to avoid port conflicts. This is only applicable for port, authrpc.port, discovery,port, http.port, ws.port.
The calculation of port numbers is as follows:
authrpc.port = 8551 (default) + `instance`*100 - 100
http.port = 8545 (default) - `instance` + 1
ws.port = 8546 (default) + `instance`*2 - 2
port = 30303 (default) + `instance` - 1
discovery.port = 30303 (default) + `instance` - 1
In a scenario where the user specify both --instance and the supported port list (i.e. port, authrpc.port, ...), then the ports specified will supersede the port values configured by --instance.
Example
Usage: geth --instance 2
authrpc.port = 8651
http.port = 8544
ws.port = 8548
port = 30304
discovery.port = 30304
Usage: geth --instance 2 --authrpc.port 8551
authrpc.port = 8551
http.port = 8544
ws.port = 8548
port = 30304
discovery.port = 30304
Usage: geth --instance 201
Fatal: Instance number 201 is too high, maximum is 200
Credits
This flag is inspired by reth.
I can see how this flag would be useful when running multiple local nodes on the same host. Because the main use-case for this is for testing, I would opt to not include this flag in Geth.
Primarily, I think users would need to run multiple nodes in this scenario:
- Running different nodes on mainnet and testnets
- Running different L1 nodes
- Running L1 and L2 nodes (perhaps fork of geth)
- Testing
For me, I encountered the need to run multiple nodes when I was running 1 mainnet node and 2 testnet nodes. So having this flag would save me some time figuring out the correct ports. For users that are not that familiar with ports, this will save them some trouble.
We're a bit torn on this really. There is some UX nicety in not having to care about port numbers, but
- Is it really so annoying to configure a couple ports?
- You still need to port forward / point beacon clients to it, so it's not that "natural" to guess what instance N will get you.
Apologies, I missed the notification.
Is it really so annoying to configure a couple ports?
I do not think that port configuration is annoying until the point that it's unbearable. I just think the --instance flag is really convenient for me to set multiple ports at the same time, without having to bother checking if the port numbers are used or not. This is especially true when I run other software that are either geth forks or have the same default port configurations. Another scenario that I found useful is when I deploy a private blockchain with local hosted nodes.
You still need to port forward / point beacon clients to it, so it's not that "natural" to guess what instance N will get you.
I believe the only port that users really have to bother with is the authrpc port. They can either calculate the resulting port number from the given formula or just overwrite it with the authrpc port flag.
Overall, this feature doesn't completely solve the ports UX "problem", but IMO it certainly is a nice-to-have flag as the port numbers can always be overwritten by the respective port flags anyways.
Been going back and forth a bit on this. Whilst we kind of agree it's cute, it doesn't really feel that useful in the grand scheme of things. You need to set the datadir explicitly anyway, hooking the beacon clients into it also requires knowing the algorithm the magic thing does (or cross standardising the flag across all EL/CLs). All in all, it feels like a solution to a problem people don't really have, apart of an occasional user.