Skip to content

Commit f60b453

Browse files
committed
lightningd: Update 'listpeers' command to print alt-addrs for a peer
1 parent 017e1ae commit f60b453

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5524,7 +5524,16 @@
55245524
"netaddr": [
55255525
"127.0.0.1:34785"
55265526
],
5527-
"features": "08a0802a8a59a1"
5527+
"alt_addrs": [
5528+
"127.0.0.1:34321"
5529+
],
5530+
"features": "08a0000a8a5961",
5531+
"log": [
5532+
{
5533+
"type": "SKIPPED",
5534+
"num_skipped": 30
5535+
}
5536+
]
55285537
}
55295538
]
55305539
}
@@ -23963,6 +23972,19 @@
2396323972
]
2396423973
}
2396523974
},
23975+
"alt_addrs": {
23976+
"type": "array",
23977+
"description": [
23978+
"An array containing zero or more alternative addresses for the peer."
23979+
],
23980+
"items": {
23981+
"type": "string",
23982+
"description": [
23983+
"Address, e.g. 1.2.3.4:1234."
23984+
]
23985+
},
23986+
"added": "v24.11"
23987+
},
2396623988
"remote_addr": {
2396723989
"type": "string",
2396823990
"description": [
@@ -24019,7 +24041,10 @@
2401924041
"netaddr": [
2402024042
"127.0.0.1:34785"
2402124043
],
24022-
"features": "08a0802a8a59a1"
24044+
"alt_addrs": [
24045+
"127.0.0.1:34321"
24046+
],
24047+
"features": "08a0000a0a69a2"
2402324048
}
2402424049
]
2402524050
}
@@ -24057,7 +24082,10 @@
2405724082
"netaddr": [
2405824083
"127.0.0.1:47032"
2405924084
],
24060-
"features": "08a0802a8a59a1"
24085+
"alt_addrs": [
24086+
"127.0.0.1:34321"
24087+
],
24088+
"features": "08a0000a0a69a2"
2406124089
}
2406224090
]
2406324091
}

doc/schemas/lightning-commando.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,16 @@
146146
"netaddr": [
147147
"127.0.0.1:34785"
148148
],
149-
"features": "08a0802a8a59a1"
149+
"alt_addrs": [
150+
"127.0.0.1:34321"
151+
],
152+
"features": "08a0000a8a5961",
153+
"log": [
154+
{
155+
"type": "SKIPPED",
156+
"num_skipped": 30
157+
}
158+
]
150159
}
151160
]
152161
}

doc/schemas/lightning-listpeers.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@
282282
]
283283
}
284284
},
285+
"alt_addrs": {
286+
"type": "array",
287+
"description": [
288+
"An array containing zero or more alternative addresses for the peer."
289+
],
290+
"items": {
291+
"type": "string",
292+
"description": [
293+
"Address, e.g. 1.2.3.4:1234."
294+
]
295+
},
296+
"added": "v24.11"
297+
},
285298
"remote_addr": {
286299
"type": "string",
287300
"description": [
@@ -338,7 +351,10 @@
338351
"netaddr": [
339352
"127.0.0.1:34785"
340353
],
341-
"features": "08a0802a8a59a1"
354+
"alt_addrs": [
355+
"127.0.0.1:34321"
356+
],
357+
"features": "08a0000a0a69a2"
342358
}
343359
]
344360
}
@@ -376,7 +392,10 @@
376392
"netaddr": [
377393
"127.0.0.1:47032"
378394
],
379-
"features": "08a0802a8a59a1"
395+
"alt_addrs": [
396+
"127.0.0.1:34321"
397+
],
398+
"features": "08a0000a0a69a2"
380399
}
381400
]
382401
}

lightningd/peer_control.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,7 @@ static void json_add_peer(struct lightningd *ld,
22362236
const enum log_level *ll)
22372237
{
22382238
struct channel *channel;
2239+
struct wireaddr_internal *peer_alt_addr;
22392240
u32 num_channels;
22402241

22412242
json_object_start(response, NULL);
@@ -2258,6 +2259,15 @@ static void json_add_peer(struct lightningd *ld,
22582259
fmt_wireaddr(response, p->remote_addr));
22592260
}
22602261

2262+
peer_alt_addr = wallet_get_alt_addr(ld->wallet, &p->id, false);
2263+
if (peer_alt_addr) {
2264+
json_array_start(response, "alt_addrs");
2265+
for (size_t i = 0; i < tal_count(peer_alt_addr); i++)
2266+
json_add_string(response, NULL,
2267+
fmt_wireaddr_internal(tmpctx, &peer_alt_addr[i]));
2268+
json_array_end(response);
2269+
}
2270+
22612271
/* Note: If !PEER_CONNECTED, peer may use different features on reconnect */
22622272
json_add_hex_talarr(response, "features", p->their_features);
22632273

tests/test_plugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,6 +3709,13 @@ def test_sql(node_factory, bitcoind):
37093709
'type': 'string'},
37103710
{'name': 'features',
37113711
'type': 'hex'}]},
3712+
'peers_alt_addrs': {
3713+
'columns': [{'name': 'row',
3714+
'type': 'u64'},
3715+
{'name': 'arrindex',
3716+
'type': 'u64'},
3717+
{'name': 'alt_addrs',
3718+
'type': 'string'}]},
37123719
'peers_netaddr': {
37133720
'columns': [{'name': 'row',
37143721
'type': 'u64'},
@@ -4128,6 +4135,9 @@ def test_sql(node_factory, bitcoind):
41284135

41294136
for table, schema in expected_schemas.items():
41304137
ret = l2.rpc.sql("SELECT * FROM {};".format(table))
4138+
if table == 'peers_alt_addrs' and not ret['rows']:
4139+
print(f"Skipping empty check for table {table} as it's expected to be empty.")
4140+
continue
41314141
assert len(ret['rows'][0]) == 1 + len(schema['columns'])
41324142

41334143
# First column is always rowid!

0 commit comments

Comments
 (0)