Skip to content

Commit

Permalink
plugin: Add a status field to htlcs in listpeers
Browse files Browse the repository at this point in the history
Annotating the htlc in `listpeers` with their current status, and
which plugin is currently holding on to them with their
`htlc_accepted` hook can help us debug where plugins may go wrong.

Changelog-Added: jsonrpc: HTLCs in `listpeers` are now annotated with a status if they are waiting on an `htlc_accepted` hook of a plugin.
  • Loading branch information
cdecker committed Jun 3, 2021
1 parent 0d0b5a7 commit 54c2cfe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ static void json_add_htlcs(struct lightningd *ld,
channel->our_config.dust_limit, LOCAL,
channel->option_anchor_outputs))
json_add_bool(response, "local_trimmed", true);
if (hin->status != NULL)
json_add_string(response, "status", hin->status);
json_object_end(response);
}

Expand Down
8 changes: 7 additions & 1 deletion lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,14 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p,
struct plugin *plugin)
{
const struct route_step *rs = p->route_step;
const struct htlc_in *hin = p->hin;
struct htlc_in *hin = p->hin;
s32 expiry = hin->cltv_expiry, blockheight = p->ld->topology->tip->height;

tal_free(hin->status);
hin->status =
tal_fmt(hin, "Waiting for the htlc_accepted hook of plugin %s",
plugin->shortname);

json_object_start(s, "onion");

json_add_hex_talarr(s, "payload", rs->raw_payload);
Expand Down
7 changes: 7 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,13 @@ def test_htlc_accepted_hook_direct_restart(node_factory, executor):
f1 = executor.submit(l1.rpc.pay, i1)

l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')

# Check that the status mentions the HTLC being held
l2.rpc.listpeers()
peers = l2.rpc.listpeers()['peers']
htlc_status = peers[0]['channels'][0]['htlcs'][0].get('status', None)
assert htlc_status == "Waiting for the htlc_accepted hook of plugin hold_htlcs.py"

needle = l2.daemon.logsearch_start
l2.restart()

Expand Down

0 comments on commit 54c2cfe

Please sign in to comment.