Skip to content

Commit

Permalink
lightningd: Update 'listpeers' command to print alt-addrs for a peer
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrantil committed Aug 6, 2024
1 parent 39e20f2 commit fb05a06
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
22 changes: 22 additions & 0 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4080,6 +4080,9 @@
"netaddr": [
"127.0.0.1:40119"
],
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a8a5961",
"log": [
{
Expand Down Expand Up @@ -21202,6 +21205,19 @@
]
}
},
"alt_addrs": {
"type": "array",
"description": [
"An array containing zero or more alternative addresses for the peer."
],
"items": {
"type": "string",
"description": [
"Address, e.g. 1.2.3.4:1234."
]
},
"added": "v24.08"
},
"remote_addr": {
"type": "string",
"description": [
Expand Down Expand Up @@ -21258,6 +21274,9 @@
"netaddr": [
"127.0.0.1:44619"
],
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a0a69a2"
}
]
Expand All @@ -21278,6 +21297,9 @@
"netaddr": [
"127.0.0.1:48862"
],
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a0a69a2"
}
]
Expand Down
3 changes: 3 additions & 0 deletions doc/schemas/lightning-commando.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
"netaddr": [
"127.0.0.1:40119"
],
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a8a5961",
"log": [
{
Expand Down
19 changes: 19 additions & 0 deletions doc/schemas/lightning-listpeers.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@
]
}
},
"alt_addrs": {
"type": "array",
"description": [
"An array containing zero or more alternative addresses for the peer."
],
"items": {
"type": "string",
"description": [
"Address, e.g. 1.2.3.4:1234."
]
},
"added": "v24.08"
},
"remote_addr": {
"type": "string",
"description": [
Expand Down Expand Up @@ -335,6 +348,9 @@
"netaddr": [
"127.0.0.1:44619"
],
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a0a69a2"
}
]
Expand All @@ -355,6 +371,9 @@
"netaddr": [
"127.0.0.1:48862"
],
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a0a69a2"
}
]
Expand Down
10 changes: 10 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,7 @@ static void json_add_peer(struct lightningd *ld,
const enum log_level *ll)
{
struct channel *channel;
struct wireaddr_internal *peer_alt_addr;
u32 num_channels;

json_object_start(response, NULL);
Expand All @@ -2254,6 +2255,15 @@ static void json_add_peer(struct lightningd *ld,
fmt_wireaddr(response, p->remote_addr));
}

peer_alt_addr = wallet_get_alt_addr(ld->wallet, &p->id, false);
if (peer_alt_addr) {
json_array_start(response, "alt_addrs");
for (size_t i = 0; i < tal_count(peer_alt_addr); i++)
json_add_string(response, NULL,
fmt_wireaddr_internal(tmpctx, &peer_alt_addr[i]));
json_array_end(response);
}

/* Note: If !PEER_CONNECTED, peer may use different features on reconnect */
json_add_hex_talarr(response, "features", p->their_features);

Expand Down
7 changes: 7 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3710,6 +3710,13 @@ def test_sql(node_factory, bitcoind):
'type': 'string'},
{'name': 'features',
'type': 'hex'}]},
'peers_alt_addrs': {
'columns': [{'name': 'peer_id',
'type': 'pubkey'},
{'name': 'alt_addr',
'type': 'string'},
{'name': 'port',
'type': 'u16'}]},
'peers_netaddr': {
'columns': [{'name': 'row',
'type': 'u64'},
Expand Down

0 comments on commit fb05a06

Please sign in to comment.