Skip to content

Commit

Permalink
closingd: add notifications for feerate ranges.
Browse files Browse the repository at this point in the history
This allows cmdline users to have more idea what's going on.

Inspired-by: #4777
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: `close` now notifies about the feeranges each side uses.
  • Loading branch information
rustyrussell committed Sep 15, 2021
1 parent c62d38f commit 20dbce5
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 5 deletions.
36 changes: 34 additions & 2 deletions closingd/closingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@
#define REQ_FD STDIN_FILENO
#define HSM_FD 6

static void notify(enum log_level level, const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
wire_sync_write(REQ_FD,
take(towire_closingd_notification(NULL,
level,
tal_vfmt(tmpctx, fmt,
ap))));

va_end(ap);
}

static struct bitcoin_tx *close_tx(const tal_t *ctx,
const struct chainparams *chainparams,
struct per_peer_state *pps,
Expand Down Expand Up @@ -192,6 +206,10 @@ static void send_offer(struct per_peer_state *pps,
close_tlvs->fee_range
= cast_const(struct tlv_closing_signed_tlvs_fee_range *,
tlv_fees);
notify(LOG_INFORM, "Sending closing fee offer %s, with range %s-%s",
type_to_string(tmpctx, struct amount_sat, &fee_to_offer),
type_to_string(tmpctx, struct amount_sat, &tlv_fees->min_fee_satoshis),
type_to_string(tmpctx, struct amount_sat, &tlv_fees->max_fee_satoshis));
} else
close_tlvs = NULL;

Expand Down Expand Up @@ -345,10 +363,23 @@ receive_offer(struct per_peer_state *pps,
type_to_string(tmpctx, struct amount_sat, &received_fee));

if (tlv_fees) {
if (close_tlvs)
if (close_tlvs) {
*tlv_fees = tal_steal(tlv_fees, close_tlvs->fee_range);
else
} else {
*tlv_fees = NULL;
}
}

if (close_tlvs && close_tlvs->fee_range) {
notify(LOG_INFORM, "Received closing fee offer %s, with range %s-%s",
type_to_string(tmpctx, struct amount_sat, &received_fee),
type_to_string(tmpctx, struct amount_sat,
&close_tlvs->fee_range->min_fee_satoshis),
type_to_string(tmpctx, struct amount_sat,
&close_tlvs->fee_range->max_fee_satoshis));
} else {
notify(LOG_INFORM, "Received closing fee offer %s, without range",
type_to_string(tmpctx, struct amount_sat, &received_fee));
}

/* Master sorts out what is best offer, we just tell it any above min */
Expand Down Expand Up @@ -1080,4 +1111,5 @@ int main(int argc, char *argv[])
daemon_shutdown();

return 0;

}
6 changes: 6 additions & 0 deletions closingd/closingd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <common/cryptomsg.h>
#include <common/htlc_wire.h>
#include <common/per_peer_state.h>
#include <common/status_wire.h>
# Begin! (passes peer fd, gossipd-client fd)
msgtype,closingd_init,2001
msgdata,closingd_init,chainparams,chainparams,
Expand Down Expand Up @@ -31,6 +32,11 @@ msgdata,closingd_init,use_quickclose,bool,
msgdata,closingd_init,dev_fast_gossip,bool,
msgdata,closingd_init,shutdown_wrong_funding,?bitcoin_outpoint,

# Message for any commands waiting.
msgtype,closingd_notification,2003
msgdata,closingd_notification,level,enum log_level,
msgdata,closingd_notification,message,wirestring,

# We received an offer, save signature.
msgtype,closingd_received_signature,2002
msgdata,closingd_received_signature,signature,bitcoin_signature,
Expand Down
28 changes: 27 additions & 1 deletion closingd/closingd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion closingd/closingd_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions lightningd/closing_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,25 @@ static void peer_closing_complete(struct channel *channel, const u8 *msg)
"Closing complete");
}

static void peer_closing_notify(struct channel *channel, const u8 *msg)
{
char *message;
struct close_command *i;
enum log_level level;

if (!fromwire_closingd_notification(msg, msg, &level, &message)) {
channel_internal_error(channel, "Bad closing_notify %s",
tal_hex(msg, msg));
return;
}

list_for_each(&channel->peer->ld->close_commands, i, list) {
if (i->channel != channel)
continue;
json_notify_fmt(i->cmd, level, "%s", message);
}
}

static unsigned closing_msg(struct subd *sd, const u8 *msg, const int *fds UNUSED)
{
enum closingd_wire t = fromwire_peektype(msg);
Expand All @@ -296,6 +315,10 @@ static unsigned closing_msg(struct subd *sd, const u8 *msg, const int *fds UNUSE
peer_closing_complete(sd->channel, msg);
break;

case WIRE_CLOSINGD_NOTIFICATION:
peer_closing_notify(sd->channel, msg);
break;

/* We send these, not receive them */
case WIRE_CLOSINGD_INIT:
case WIRE_CLOSINGD_RECEIVED_SIGNATURE_REPLY:
Expand Down
18 changes: 17 additions & 1 deletion tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3318,8 +3318,14 @@ def test_close_feerate_range(node_factory, bitcoind, chainparams):
"""Test the quick-close fee range negotiation"""
l1, l2 = node_factory.line_graph(2)

notifications = []

def save_notifications(message, progress, request, **kwargs):
notifications.append(message)

# Lowball the range here.
l1.rpc.close(l2.info['id'], feerange=['253perkw', 'normal'])
with l1.rpc.notify(save_notifications):
l1.rpc.close(l2.info['id'], feerange=['253perkw', 'normal'])

if not chainparams['elements']:
l1_range = [138, 4110]
Expand All @@ -3335,6 +3341,16 @@ def test_close_feerate_range(node_factory, bitcoind, chainparams):
overlap = [max(l1_range[0], l2_range[0]), min(l1_range[1], l2_range[1])]
l1.daemon.wait_for_log('performing quickclose in range {}sat-{}sat'.format(overlap[0], overlap[1]))

log = l1.daemon.is_in_log('Their actual closing tx fee is .*sat')
rate = re.match('.*Their actual closing tx fee is ([0-9]*sat).*', log).group(1)

assert notifications == ['Sending closing fee offer {}, with range {}sat-{}sat'.format(rate,
l1_range[0],
l1_range[1]),
'Received closing fee offer {}, with range {}sat-{}sat'.format(rate,
l2_range[0],
l2_range[1])]


def test_close_twice(node_factory, executor):
# First feerate is too low, second fixes it.
Expand Down

0 comments on commit 20dbce5

Please sign in to comment.