From fcfccb4a23f578e375a90a32be2d95b305c24d7d Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Tue, 6 Sep 2022 23:10:56 +0100 Subject: [PATCH] bkp: debug invalid peer_id Signed-off-by: Vincenzo Palazzo --- doc/lightning-listpeers.7.md | 3 ++- lightningd/dual_open_control.c | 1 + lightningd/peer_control.c | 1 + plugins/bkpr/bookkeeper.c | 11 +++++------ tests/test_opening.py | 14 +++++++------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/doc/lightning-listpeers.7.md b/doc/lightning-listpeers.7.md index ecff713bfdf1..52d8e9b5a937 100644 --- a/doc/lightning-listpeers.7.md +++ b/doc/lightning-listpeers.7.md @@ -72,4 +72,5 @@ If **connected** is *true*: - **features** (hex): bitmap of BOLT #9 features from peer's INIT message - **remote\_addr** (string, optional): The public IPv4/6 address the peer sees us from, e.g. 1.2.3.4:1234 -[comment]: # ( SHA256STAMP:4029720c7824ee1d6d029bbf0df18702ada64527f7df987438f55dea1ca6797d) +======= +[comment]: # ( SHA256STAMP:8ea63ab95c5ca859442a6b0e8e4e112bb51710da6001dcfac23a7def949bbd7e) diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 474ba2899e23..ac09f8f21e88 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -125,6 +125,7 @@ void json_add_unsaved_channel(struct json_stream *response, oa = channel->open_attempt; + assert(peer); json_object_start(response, NULL); json_add_node_id(response, "peer_id", &peer->id); json_add_bool(response, "peer_connected", peer->connected); diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 776fb11cbf3b..5d455047cff8 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -690,6 +690,7 @@ static void json_add_channel(struct lightningd *ld, struct state_change_entry *state_changes; u32 feerate; + assert(peer); json_object_start(response, key); json_add_node_id(response, "peer_id", &peer->id); json_add_bool(response, "peer_connected", peer->connected); diff --git a/plugins/bkpr/bookkeeper.c b/plugins/bkpr/bookkeeper.c index e301281654b5..ff8d785a022f 100644 --- a/plugins/bkpr/bookkeeper.c +++ b/plugins/bkpr/bookkeeper.c @@ -1,6 +1,4 @@ -#include "common/status_levels.h" #include "config.h" -#include "lightningd/log.h" #include #include #include @@ -618,7 +616,6 @@ static bool new_missed_channel_account(struct command *cmd, size_t i; const jsmntok_t *curr_chan, *chan_arr_tok; - plugin_log(cmd->plugin, LOG_DBG, "new_missed_channel_account JSON payload: %s", buf); chan_arr_tok = json_get_member(buf, result, "channels"); assert(chan_arr_tok && chan_arr_tok->type == JSMN_ARRAY); @@ -632,12 +629,14 @@ static bool new_missed_channel_account(struct command *cmd, bool ok, is_opener, is_leased; err = json_scan(tmpctx, buf, curr_chan, - "{channel_id:%," + "{peer_id:%," + "channel_id:%," "funding_txid:%," "funding_outnum:%," "funding:{local_funds_msat:%," "remote_funds_msat:%}," "opener:%}", + JSON_SCAN(json_to_node_id, &peer_id), JSON_SCAN_TAL(tmpctx, json_strdup, &chan_id), JSON_SCAN(json_to_txid, &opt.txid), JSON_SCAN(json_to_number, &opt.n), @@ -850,7 +849,7 @@ static struct command_result *log_error(struct command *cmd, return notification_handled(cmd); } -static struct command_result * listpeerchannels_multi_done(struct command *cmd, +static struct command_result *listpeerchannels_multi_done(struct command *cmd, const char *buf, const jsmntok_t *result, struct new_account_info **new_accts) @@ -901,7 +900,6 @@ static struct command_result * listpeerchannels_multi_done(struct command *cmd, info->timestamp - 1, credit_diff, debit_diff); } - plugin_log(cmd->plugin, LOG_DBG, "Snapshot balances updated"); return notification_handled(cmd); } @@ -909,6 +907,7 @@ static struct command_result * listpeerchannels_multi_done(struct command *cmd, static char *do_account_close_checks(const tal_t *ctx, struct chain_event *e, struct account *acct) + { struct account *closed_acct; diff --git a/tests/test_opening.py b/tests/test_opening.py index 24ccf9503c99..77caae8e0ba7 100644 --- a/tests/test_opening.py +++ b/tests/test_opening.py @@ -1772,12 +1772,12 @@ def test_zeroreserve(node_factory, bitcoind): wait_for(lambda: l3.channel_state(l1) == 'CHANNELD_NORMAL') # Now make sure we all agree on each others reserves - l1c1 = l1.rpc.listpeers(l2.info['id'])['peers'][0]['channels'][0] - l2c1 = l2.rpc.listpeers(l1.info['id'])['peers'][0]['channels'][0] - l2c2 = l2.rpc.listpeers(l3.info['id'])['peers'][0]['channels'][0] - l3c2 = l3.rpc.listpeers(l2.info['id'])['peers'][0]['channels'][0] - l3c3 = l3.rpc.listpeers(l1.info['id'])['peers'][0]['channels'][0] - l1c3 = l1.rpc.listpeers(l3.info['id'])['peers'][0]['channels'][0] + l1c1 = l1.rpc.listpeerchannels(l2.info['id'])['channels'][0] + l2c1 = l2.rpc.listpeerchannels(l1.info['id'])['channels'][0] + l2c2 = l2.rpc.listpeerchannels(l3.info['id'])['channels'][0] + l3c2 = l3.rpc.listpeerchannels(l2.info['id'])['channels'][0] + l3c3 = l3.rpc.listpeerchannels(l1.info['id'])['channels'][0] + l1c3 = l1.rpc.listpeerchannels(l3.info['id'])['channels'][0] # l1 imposed a 0sat reserve on l2, while l2 imposed the default 1% reserve on l1 assert l1c1['their_reserve_msat'] == l2c1['our_reserve_msat'] == Millisatoshi('0sat') @@ -1797,7 +1797,7 @@ def test_zeroreserve(node_factory, bitcoind): l2.drain(l1) # Remember that this is the reserve l1 imposed on l2, so l2 can drain completely - l2c1 = l2.rpc.listpeers(l1.info['id'])['peers'][0]['channels'][0] + l2c1 = l2.rpc.listpeerchannels(l1.info['id'])['channels'][0] # And despite us briefly being above dust (with a to_us output), # closing should result in the output being trimmed again since we