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 Sep 5, 2024
1 parent 017e1ae commit f60b453
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
34 changes: 31 additions & 3 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5524,7 +5524,16 @@
"netaddr": [
"127.0.0.1:34785"
],
"features": "08a0802a8a59a1"
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a8a5961",
"log": [
{
"type": "SKIPPED",
"num_skipped": 30
}
]
}
]
}
Expand Down Expand Up @@ -23963,6 +23972,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.11"
},
"remote_addr": {
"type": "string",
"description": [
Expand Down Expand Up @@ -24019,7 +24041,10 @@
"netaddr": [
"127.0.0.1:34785"
],
"features": "08a0802a8a59a1"
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a0a69a2"
}
]
}
Expand Down Expand Up @@ -24057,7 +24082,10 @@
"netaddr": [
"127.0.0.1:47032"
],
"features": "08a0802a8a59a1"
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a0a69a2"
}
]
}
Expand Down
11 changes: 10 additions & 1 deletion doc/schemas/lightning-commando.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@
"netaddr": [
"127.0.0.1:34785"
],
"features": "08a0802a8a59a1"
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a8a5961",
"log": [
{
"type": "SKIPPED",
"num_skipped": 30
}
]
}
]
}
Expand Down
23 changes: 21 additions & 2 deletions doc/schemas/lightning-listpeers.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,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.11"
},
"remote_addr": {
"type": "string",
"description": [
Expand Down Expand Up @@ -338,7 +351,10 @@
"netaddr": [
"127.0.0.1:34785"
],
"features": "08a0802a8a59a1"
"alt_addrs": [
"127.0.0.1:34321"
],
"features": "08a0000a0a69a2"
}
]
}
Expand Down Expand Up @@ -376,7 +392,10 @@
"netaddr": [
"127.0.0.1:47032"
],
"features": "08a0802a8a59a1"
"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 @@ -2236,6 +2236,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 @@ -2258,6 +2259,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
10 changes: 10 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3709,6 +3709,13 @@ def test_sql(node_factory, bitcoind):
'type': 'string'},
{'name': 'features',
'type': 'hex'}]},
'peers_alt_addrs': {
'columns': [{'name': 'row',
'type': 'u64'},
{'name': 'arrindex',
'type': 'u64'},
{'name': 'alt_addrs',
'type': 'string'}]},
'peers_netaddr': {
'columns': [{'name': 'row',
'type': 'u64'},
Expand Down Expand Up @@ -4128,6 +4135,9 @@ def test_sql(node_factory, bitcoind):

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

# First column is always rowid!
Expand Down

0 comments on commit f60b453

Please sign in to comment.