Skip to content

Commit ec02534

Browse files
rustyrussellm-schmoock
authored andcommitted
lightningd: don't announce names as DNS by default.
This broke BTCPayServer, so revert. I originally (accidentally!) implemented this such that it broadcast both DNS and IP entries, but Michael reported earlier that they still don't propagage well, so simply suppress them. Signed-off-by: Rusty Russell <[email protected]> Fixes: #5795 Changelog-Changeed: Config: `announce-addr-dns` needs to be set to *true* to put DNS names into node announcements, otherwise they are suppressed. Changelog-Deprecated: Config: `announce-addr-dns` (currently defaults to `false`). This will default to `true` once enough of the network has upgraded to understand DNS entries.
1 parent 0ae6f4d commit ec02534

File tree

7 files changed

+57
-9
lines changed

7 files changed

+57
-9
lines changed

doc/lightning-listconfigs.7.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ On success, an object is returned, containing:
101101
- **accept-htlc-tlv-types** (string, optional): `accept-extra-tlvs-type` fields from config or cmdline, or not present
102102
- **tor-service-password** (string, optional): `tor-service-password` field from config or cmdline, if any
103103
- **dev-allowdustreserve** (boolean, optional): Whether we allow setting dust reserves
104+
- **announce-addr-dns** (boolean, optional): Whether we put DNS entries into node_announcement
104105

105106
[comment]: # (GENERATE-FROM-SCHEMA-END)
106107

@@ -218,4 +219,4 @@ RESOURCES
218219
---------
219220

220221
Main web site: <https://github.com/ElementsProject/lightning>
221-
[comment]: # ( SHA256STAMP:5871ac751654339ed65ab905d61f0bc3afbb8576a33a5c4e9a73d2084f438582)
222+
[comment]: # ( SHA256STAMP:745268f7f4e4eb19d04ec1a221fbb734d89b4a266049cde3adc3131d86423294)

doc/lightningd-config.5.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ its use disables autolisten. If necessary, and 'always-use-proxy'
533533
is not specified, a DNS lookup may be done to resolve 'DNS' or 'TORIPADDRESS'.
534534

535535
If a 'DNS' hostname was given that resolves to a local interface, the daemon
536-
will bind to that interface and also announce that as type 'DNS'.
536+
will bind to that interface: if **announce-addr-dns** is true then it will also announce that as type 'DNS' (rather than announcing the IP address).
537537

538538
* **bind-addr**=*\[IPADDRESS\[:PORT\]\]|SOCKETPATH|DNS\[:PORT\]|DNS\[:PORT\]*
539539

@@ -565,9 +565,12 @@ announced addresses are public (e.g. not localhost).
565565
This option can be used multiple times to add more addresses, and
566566
its use disables autolisten.
567567

568-
Since v22.11 'DNS' hostnames can be used for announcement.
569-
Please note that a lot of mainnet nodes do not yet use, read or propagate this
570-
information correctly.
568+
Since v22.11 'DNS' hostnames can be used for announcement: see **announce-addr-dns**.
569+
570+
* **announce-addr-dns**=*BOOL*
571+
572+
Set to *true* (default is *false), this so that names given as arguments to **addr** and **announce-addr** are published in node announcement messages as names, rather than IP addresses. Please note that most mainnet nodes do not yet use, read or propagate this information correctly.
573+
571574

572575
* **offline**
573576

doc/schemas/listconfigs.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@
294294
"dev-allowdustreserve": {
295295
"type": "boolean",
296296
"description": "Whether we allow setting dust reserves"
297+
},
298+
"announce-addr-dns": {
299+
"type": "boolean",
300+
"description": "Whether we put DNS entries into node_announcement"
297301
}
298302
}
299303
}

lightningd/lightningd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
206206
ld->proposed_wireaddr = tal_arr(ld, struct wireaddr_internal, 0);
207207
ld->proposed_listen_announce = tal_arr(ld, enum addr_listen_announce, 0);
208208

209+
/*~ The network is not yet ready for DNS names inside node_announcements,
210+
* so we disable this by default for now. */
211+
ld->announce_dns = false;
212+
209213
ld->remote_addr_v4 = NULL;
210214
ld->remote_addr_v6 = NULL;
211215
ld->discovered_ip_v4 = NULL;

lightningd/lightningd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ struct lightningd {
234234
/* If they force db upgrade on or off this is set. */
235235
bool *db_upgrade_ok;
236236

237+
/* Announce names in config as DNS records (recently BOLT 7 addition) */
238+
bool announce_dns;
239+
237240
#if DEVELOPER
238241
/* If we want to debug a subdaemon/plugin. */
239242
const char *dev_debug_subprocess;

lightningd/options.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ static char *opt_add_addr_withtype(const char *arg,
230230
if (is_ipaddr(address)
231231
|| is_toraddr(address)
232232
|| is_wildcardaddr(address)
233+
|| (is_dnsaddr(address) && !ld->announce_dns)
233234
|| ala != ADDR_ANNOUNCE) {
234235
if (!parse_wireaddr_internal(arg, &wi, ld->portnum,
235236
wildcard_ok, dns_ok, false,
@@ -254,7 +255,7 @@ static char *opt_add_addr_withtype(const char *arg,
254255
}
255256

256257
/* Add ADDR_TYPE_DNS to announce DNS hostnames */
257-
if (is_dnsaddr(address) && ala & ADDR_ANNOUNCE) {
258+
if (is_dnsaddr(address) && ld->announce_dns && (ala & ADDR_ANNOUNCE)) {
258259
/* BOLT-hostnames #7:
259260
* The origin node:
260261
* ...
@@ -1103,6 +1104,10 @@ static void register_opts(struct lightningd *ld)
11031104
opt_register_early_noarg("--experimental-shutdown-wrong-funding",
11041105
opt_set_shutdown_wrong_funding, ld,
11051106
"EXPERIMENTAL: allow shutdown with alternate txids");
1107+
opt_register_early_arg("--announce-addr-dns",
1108+
opt_set_bool_arg, opt_show_bool,
1109+
&ld->announce_dns,
1110+
"Use DNS entries in --announce-addr and --addr (not widely supported!)");
11061111

11071112
opt_register_noarg("--help|-h", opt_lightningd_usage, ld,
11081113
"Print this message.");

tests/test_gossip.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def test_announce_address(node_factory, bitcoind):
117117
"""Make sure our announcements are well formed."""
118118

119119
# We do not allow announcement of duplicates.
120-
opts = {'disable-dns': None, 'announce-addr':
120+
opts = {'announce-addr-dns': True,
121+
'announce-addr':
121122
['4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion',
122123
'1.2.3.4:1234',
123124
'example.com:1236',
@@ -158,6 +159,31 @@ def test_announce_address(node_factory, bitcoind):
158159
assert addresses_dns[0]['port'] == 1236
159160

160161

162+
def test_announce_dns_suppressed(node_factory, bitcoind):
163+
"""By default announce DNS names as IPs"""
164+
opts = {'announce-addr': 'example.com:1236',
165+
'start': False}
166+
l1, l2 = node_factory.get_nodes(2, opts=[opts, {}])
167+
# Remove unwanted disable-dns option!
168+
del l1.daemon.opts['disable-dns']
169+
l1.start()
170+
171+
# Need a channel so l1 will announce itself.
172+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
173+
scid, _ = l1.fundchannel(l2, 10**6)
174+
bitcoind.generate_block(5)
175+
176+
# Wait for l2 to see l1, with addresses.
177+
wait_for(lambda: l2.rpc.listnodes(l1.info['id'])['nodes'] != [])
178+
wait_for(lambda: 'addresses' in only_one(l2.rpc.listnodes(l1.info['id'])['nodes']))
179+
180+
addresses = only_one(l2.rpc.listnodes(l1.info['id'])['nodes'])['addresses']
181+
assert len(addresses) == 1
182+
assert addresses[0]['type'] == 'ipv4'
183+
assert addresses[0]['address'] != 'example.com'
184+
assert addresses[0]['port'] == 1236
185+
186+
161187
@pytest.mark.developer("gossip without DEVELOPER=1 is slow")
162188
def test_announce_and_connect_via_dns(node_factory, bitcoind):
163189
""" Test that DNS annoucements propagate and can be used when connecting.
@@ -176,6 +202,7 @@ def test_announce_and_connect_via_dns(node_factory, bitcoind):
176202
- 'dev-allow-localhost' must not be set, so it does not resolve localhost anyway.
177203
"""
178204
opts1 = {'disable-dns': None,
205+
'announce-addr-dns': True,
179206
'announce-addr': ['localhost.localdomain:12345'], # announce dns
180207
'bind-addr': ['127.0.0.1:12345', '[::1]:12345']} # and bind local IPs
181208
opts3 = {'may_reconnect': True}
@@ -225,7 +252,8 @@ def test_announce_and_connect_via_dns(node_factory, bitcoind):
225252
def test_only_announce_one_dns(node_factory, bitcoind):
226253
# and test that we can't announce more than one DNS address
227254
l1 = node_factory.get_node(expect_fail=True, start=False,
228-
options={'announce-addr': ['localhost.localdomain:12345', 'example.com:12345']})
255+
options={'announce-addr-dns': True,
256+
'announce-addr': ['localhost.localdomain:12345', 'example.com:12345']})
229257
l1.daemon.start(wait_for_initialized=False, stderr_redir=True)
230258
wait_for(lambda: l1.daemon.is_in_stderr("Only one DNS can be announced"))
231259

@@ -234,7 +262,7 @@ def test_announce_dns_without_port(node_factory, bitcoind):
234262
""" Checks that the port of a DNS announcement is set to the corresponding
235263
network port. In this case regtest 19846
236264
"""
237-
opts = {'announce-addr': ['example.com']}
265+
opts = {'announce-addr-dns': True, 'announce-addr': ['example.com']}
238266
l1 = node_factory.get_node(options=opts)
239267

240268
# 'address': [{'type': 'dns', 'address': 'example.com', 'port': 0}]

0 commit comments

Comments
 (0)