Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default port according to network #4900

Merged
merged 2 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bitcoin/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const struct chainparams networks[] = {
0x5b, 0xbf, 0x28, 0xc3, 0x4f, 0x3a, 0x5e,
0x33, 0x2a, 0x1f, 0xc7, 0xb2, 0xb7, 0x3c,
0xf1, 0x88, 0x91, 0x0f}}}},
.rpc_port = 18332,
.rpc_port = 18443,
jsarenik marked this conversation as resolved.
Show resolved Hide resolved
.cli = "bitcoin-cli",
.cli_args = "-regtest",
.cli_min_supported_version = 150000,
Expand Down
29 changes: 17 additions & 12 deletions doc/lightningd-config.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ network.
### Networking options

Note that for simple setups, the implicit *autolisten* option does the
right thing: it will try to bind to port 9735 on IPv4 and IPv6, and will
announce it to peers if it seems like a public address.
right thing: for the mainnet (bitcoin) network it will try to bind to
jsarenik marked this conversation as resolved.
Show resolved Hide resolved
port 9735 on IPv4 and IPv6, and will announce it to peers if it seems
like a public address.

You can instead use *addr* to override this (eg. to change the port), or
precisely control where to bind and what to announce with the
Expand All @@ -360,27 +361,31 @@ Set an IP address (v4 or v6) or automatic Tor address to listen on and

An empty 'IPADDRESS' is a special value meaning bind to IPv4 and/or
IPv6 on all interfaces, '0.0.0.0' means bind to all IPv4
interfaces, '::' means 'bind to all IPv6 interfaces'. If 'PORT' is
not specified, 9735 is used. If we can determine a public IP
address from the resulting binding, the address is announced.
interfaces, '::' means 'bind to all IPv6 interfaces'.
If 'PORT' is not specified, the default port 9735 is used for mainnet
(testnet: 19735, signet: 39735, regtest: 19846).
If we can determine a public IP address from the resulting binding,
the address is announced.

If the argument begins with 'autotor:' then it is followed by the
IPv4 or IPv6 address of the Tor control port (default port 9051),
and this will be used to configure a Tor hidden service for port 9735.
and this will be used to configure a Tor hidden service for port 9735
in case of mainnet (bitcoin) network whereas other networks (testnet,
signet, regtest) will set the same default ports they use for non-Tor
addresses (see above).
The Tor hidden service will be configured to point to the
first IPv4 or IPv6 address we bind to.
first IPv4 or IPv6 address we bind to and is by default unique to
your node's id.

If the argument begins with 'statictor:' then it is followed by the
IPv4 or IPv6 address of the Tor control port (default port 9051),
and this will be used to configure a static Tor hidden service for port 9735.
The Tor hidden service will be configured to point to the
first IPv4 or IPv6 address we bind to and is by default unique to
your nodes id. You can add the text '/torblob=BLOB' followed by up to
and this will be used to configure a static Tor hidden service.
You can add the text '/torblob=BLOB' followed by up to
64 Bytes of text to generate from this text a v3 onion service
address text unique to the first 32 Byte of this text.
You can also use an postfix '/torport=TORPORT' to select the external
tor binding. The result is that over tor your node is accessible by a port
defined by you and possible different from your local node port assignment
defined by you and possibly different from your local node port assignment.

This option can be used multiple times to add more addresses, and
its use disables autolisten. If necessary, and 'always-use-proxy'
Expand Down
5 changes: 4 additions & 1 deletion lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
* NULL. So we start with a zero-length array. */
ld->proposed_wireaddr = tal_arr(ld, struct wireaddr_internal, 0);
ld->proposed_listen_announce = tal_arr(ld, enum addr_listen_announce, 0);
ld->portnum = DEFAULT_PORT;
ld->listen = true;
ld->autolisten = true;
ld->reconnect = true;
Expand Down Expand Up @@ -952,6 +951,10 @@ int main(int argc, char *argv[])
* non-early opts. This also forks if they say --daemon. */
handle_early_opts(ld, argc, argv);

/*~ Set the default portnum according to the used network
* similarly to what Bitcoin Core does to ports by default. */
ld->portnum = DEFAULT_PORT + chainparams->rpc_port - 8332;

/*~ Initialize all the plugins we just registered, so they can
* do their thing and tell us about themselves (including
* options registration). */
Expand Down
16 changes: 5 additions & 11 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def test_announce_address(node_factory, bitcoind):
l1.daemon.wait_for_log(r"\[OUT\] 0101.*47"
"010102030404d2"
"017f000001...."
"02000000000000000000000000000000002607"
"04e00533f3e8f2aedaa8969b3d0fa03a96e857bbb28064dca5e147e934244b9ba50230032607")
"0200000000000000000000000000000000...."
"04e00533f3e8f2aedaa8969b3d0fa03a96e857bbb28064dca5e147e934244b9ba5023003....")
return

# We should see it send node announce with all addresses (257 = 0x0101)
Expand All @@ -154,8 +154,8 @@ def test_announce_address(node_factory, bitcoind):
l1.daemon.wait_for_log(r"\[OUT\] 0101.*0063"
"010102030404d2" # IPv4 01 1.2.3.4:1234
"017f000001...." # IPv4 01 127.0.0.1:wxyz
"02000000000000000000000000000000002607" # IPv6 02 :::9735
"04e00533f3e8f2aedaa8969b3d0fa03a96e857bbb28064dca5e147e934244b9ba50230032607" # TORv3 04
"0200000000000000000000000000000000...." # IPv6 02 :::<any_port>
"04e00533f3e8f2aedaa8969b3d0fa03a96e857bbb28064dca5e147e934244b9ba5023003...." # TORv3 04
"05096c6f63616c686f737404d3" # DNS 05 len localhost:1235
"050b6578616d706c652e636f6d04d4") # DNS 05 len example.com:1236

Expand Down Expand Up @@ -1018,10 +1018,7 @@ def test_gossip_addresses(node_factory, bitcoind):
l1 = node_factory.get_node(options={
'announce-addr': [
'[::]:3',
'[::]',
'127.0.0.1:2',
'127.0.0.1',
'vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion',
'4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion:1234'
],
})
Expand All @@ -1036,10 +1033,7 @@ def test_gossip_addresses(node_factory, bitcoind):
nodes = l2.rpc.listnodes(l1.info['id'])['nodes']
assert len(nodes) == 1 and nodes[0]['addresses'] == [
{'type': 'ipv4', 'address': '127.0.0.1', 'port': 2},
{'type': 'ipv4', 'address': '127.0.0.1', 'port': 9735},
{'type': 'ipv6', 'address': '::', 'port': 3},
{'type': 'ipv6', 'address': '::', 'port': 9735},
{'type': 'torv3', 'address': 'vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion', 'port': 9735},
jsarenik marked this conversation as resolved.
Show resolved Hide resolved
{'type': 'torv3', 'address': '4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion', 'port': 1234},
]

Expand Down Expand Up @@ -1911,7 +1905,7 @@ def test_statictor_onions(node_factory):
})

assert l1.daemon.is_in_log('127.0.0.1:{}'.format(l1.port))
assert l2.daemon.is_in_log('x2y4zvh4fn5q3eouuh7nxnc7zeawrqoutljrup2xjtiyxgx3emgkemad.onion:9735,127.0.0.1:{}'.format(l2.port))
assert l2.daemon.is_in_log('x2y4zvh4fn5q3eouuh7nxnc7zeawrqoutljrup2xjtiyxgx3emgkemad.onion:{},127.0.0.1:{}'.format(l2.port, l2.port))


@pytest.mark.developer("needs a running Tor service instance at port 9151 or 9051")
Expand Down