From 81a280d8a3da7908d3f8410d024529cee20a830f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 31 Jan 2024 13:46:19 +1030 Subject: [PATCH] lightningd: expose `reestablished` field. This is useful to see if we've really made progress, or just bounced off the peer (e.g. it doesn't know the channel, or we have fallen behind somehow). Changelog-Added: JSON-RPC: `listpeerchannels` new field `reestablished` set once we've exchanged `channel_reestablish` messages. Signed-off-by: Rusty Russell --- doc/lightning-listpeerchannels.7.md | 6 +++++- doc/lightning-sql.7.md | 3 ++- doc/schemas/listpeerchannels.schema.json | 27 ++++++++++++++++++++++++ lightningd/channel_gossip.c | 6 +++++- lightningd/peer_control.c | 3 +++ tests/test_plugin.py | 2 ++ 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/doc/lightning-listpeerchannels.7.md b/doc/lightning-listpeerchannels.7.md index a3c3bc0b6..c7a209433 100644 --- a/doc/lightning-listpeerchannels.7.md +++ b/doc/lightning-listpeerchannels.7.md @@ -133,6 +133,10 @@ On success, an object containing **channels** is returned. It is an array of ob - **state** (string): Status of the HTLC (one of "RCVD\_ADD\_HTLC", "RCVD\_ADD\_COMMIT", "SENT\_ADD\_REVOCATION", "SENT\_ADD\_ACK\_COMMIT", "RCVD\_ADD\_ACK\_REVOCATION", "SENT\_REMOVE\_HTLC", "SENT\_REMOVE\_COMMIT", "RCVD\_REMOVE\_REVOCATION", "RCVD\_REMOVE\_ACK\_COMMIT", "SENT\_REMOVE\_ACK\_REVOCATION") +If **peer\_connected** is *true*: + + - **reestablished** (boolean, optional): True if we have successfully exchanged reestablish messages this connection + If **close\_to** is present: - **close\_to\_addr** (string, optional): The bitcoin address we will close to (present if close\_to\_addr is a standardized address) @@ -215,4 +219,4 @@ Main web site: Lightning RFC site (BOLT \#9): -[comment]: # ( SHA256STAMP:a7fc3b30593a04b6b04c1516aeb2039f6ab4e29cf12f81b306a8a068273c3604) +[comment]: # ( SHA256STAMP:8cad14f36d38722182a8fdccc393e93d121d97999d2487decfa09d53c991a8ae) diff --git a/doc/lightning-sql.7.md b/doc/lightning-sql.7.md index dd2aef8d2..478635366 100644 --- a/doc/lightning-sql.7.md +++ b/doc/lightning-sql.7.md @@ -352,6 +352,7 @@ The following tables are currently supported: - `local_trimmed` (type `boolean`, sqltype `INTEGER`) - `status` (type `string`, sqltype `TEXT`) - `state` (type `string`, sqltype `TEXT`) + - `reestablished` (type `boolean`, sqltype `INTEGER`) - `close_to_addr` (type `string`, sqltype `TEXT`) - `last_tx_fee_msat` (type `msat`, sqltype `INTEGER`) - `direction` (type `u32`, sqltype `INTEGER`) @@ -530,4 +531,4 @@ RESOURCES --------- Main web site: -[comment]: # ( SHA256STAMP:5c5e14f8fde75b877080c0c10feb786f1d2fefbb61a62aecb8d003d1d54627e9) +[comment]: # ( SHA256STAMP:f17b33523de930b61d6397a730c40b2254929cf38930629b9be66f3d52947d0e) diff --git a/doc/schemas/listpeerchannels.schema.json b/doc/schemas/listpeerchannels.schema.json index e731f6c2c..5588b687c 100644 --- a/doc/schemas/listpeerchannels.schema.json +++ b/doc/schemas/listpeerchannels.schema.json @@ -28,6 +28,7 @@ "type": "boolean", "description": "A boolean flag that is set to true if the peer is online" }, + "reestablished": {}, "state": { "type": "string", "enum": [ @@ -634,6 +635,7 @@ "alias": {}, "peer_id": {}, "peer_connected": {}, + "reestablished": {}, "state": { "type": "string", "enum": [ @@ -679,6 +681,7 @@ "status": {}, "peer_id": {}, "peer_connected": {}, + "reestablished": {}, "state": { "type": "string", "enum": [ @@ -703,6 +706,26 @@ } }, "allOf": [ + { + "if": { + "properties": { + "peer_connected": { + "type": "boolean", + "enum": [ + true + ] + } + } + }, + "then": { + "properties": { + "reestablished": { + "type": "boolean", + "description": "True if we have successfully exchanged reestablish messages this connection" + } + } + } + }, { "if": { "required": [ @@ -716,6 +739,7 @@ "state": {}, "peer_id": {}, "peer_connected": {}, + "reestablished": {}, "scratch_txid": {}, "channel_type": {}, "feerate": {}, @@ -807,6 +831,7 @@ "state": {}, "peer_id": {}, "peer_connected": {}, + "reestablished": {}, "alias": {}, "scratch_txid": {}, "channel_type": {}, @@ -898,6 +923,7 @@ "alias": {}, "peer_id": {}, "peer_connected": {}, + "reestablished": {}, "state": {}, "scratch_txid": {}, "channel_type": {}, @@ -991,6 +1017,7 @@ "state": {}, "peer_id": {}, "peer_connected": {}, + "reestablished": {}, "scratch_txid": {}, "channel_type": {}, "feerate": {}, diff --git a/lightningd/channel_gossip.c b/lightningd/channel_gossip.c index fea95deea..385b6c8f7 100644 --- a/lightningd/channel_gossip.c +++ b/lightningd/channel_gossip.c @@ -410,8 +410,10 @@ static void send_channel_announce_sigs(struct channel *channel) return; /* Wait until we've exchanged reestablish messages */ - if (!channel->reestablished) + if (!channel->reestablished) { + log_debug(channel->log, "channel_gossip: not sending channel_announcement_sigs until reestablished"); return; + } ca = create_channel_announcement(tmpctx, channel, *channel->scid, NULL, NULL, NULL, NULL); @@ -843,6 +845,7 @@ void channel_gossip_init_done(struct lightningd *ld) void channel_gossip_channel_reestablished(struct channel *channel) { channel->reestablished = true; + log_debug(channel->log, "channel_gossip: reestablished"); /* Ignore unsaved channels */ if (!channel->channel_gossip) @@ -879,6 +882,7 @@ void channel_gossip_channel_reestablished(struct channel *channel) void channel_gossip_channel_disconnect(struct channel *channel) { + log_debug(channel->log, "channel_gossip: NO LONGER reestablished"); channel->reestablished = false; } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index e4e57a2fe..9d6c1605b 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -825,6 +825,9 @@ static void json_add_channel(struct lightningd *ld, if (peer) { json_add_node_id(response, "peer_id", &peer->id); json_add_bool(response, "peer_connected", peer->connected == PEER_CONNECTED); + if (peer->connected == PEER_CONNECTED) { + json_add_bool(response, "reestablished", channel->reestablished); + } json_add_channel_type(response, "channel_type", channel->type); if (channel->ignore_fee_limits) { json_add_bool(response, "ignore_fee_limits", channel->ignore_fee_limits); diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 0d341e64e..ccc8667b0 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -3840,6 +3840,8 @@ def test_sql(node_factory, bitcoind): 'type': 'u64'}, {'name': 'out_fulfilled_msat', 'type': 'msat'}, + {'name': 'reestablished', + 'type': 'boolean'}, {'name': 'close_to_addr', 'type': 'string'}, {'name': 'last_tx_fee_msat',