From dfdf9259d72b02bc94960624f5ccafb0f0c20cc3 Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 23 Feb 2021 20:58:28 -0600 Subject: [PATCH] listpeers: include feerate info for RBF-candidate channels Changelog-Added: JSON-RPC: `listpeers` now includes 'last_feerate', 'next_feerate', 'initial_feerate' and 'next_fee_step' for channels in state DUALOPEND_AWAITING_LOCKIN fixup! listpeers: include feerate info for RBF-candidate channels --- lightningd/peer_control.c | 29 +++++++++++++++++++++ lightningd/test/run-invoice-select-inchan.c | 3 +++ 2 files changed, 32 insertions(+) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 9d1a04e8f..e35185e32 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -759,6 +759,35 @@ static void json_add_channel(struct lightningd *ld, type_to_string(tmpctx, struct channel_id, &channel->cid)); json_add_txid(response, "funding_txid", &channel->funding_txid); + if (channel->state == DUALOPEND_AWAITING_LOCKIN) { + struct channel_inflight *initial; + u32 last_feerate, next_feerate, feerate; + u8 feestep; + + last_feerate = channel_last_funding_feerate(channel); + assert(last_feerate > 0); + next_feerate = last_feerate + last_feerate / 4; + + initial = list_top(&channel->inflights, + struct channel_inflight, list); + feerate = initial->funding->feerate; + + json_add_string(response, "initial_feerate", + tal_fmt(tmpctx, "%d%s", feerate, + feerate_style_name(FEERATE_PER_KSIPA))); + json_add_string(response, "last_feerate", + tal_fmt(tmpctx, "%d%s", last_feerate, + feerate_style_name(FEERATE_PER_KSIPA))); + json_add_string(response, "next_feerate", + tal_fmt(tmpctx, "%d%s", next_feerate, + feerate_style_name(FEERATE_PER_KSIPA))); + + /* Now we derive the feestep */ + for (feestep = 0; feerate < next_feerate; feestep++) + feerate += feerate / 4; + json_add_num(response, "next_fee_step", feestep); + } + if (channel->shutdown_scriptpubkey[LOCAL]) { char *addr = encode_scriptpubkey_to_addr(tmpctx, chainparams, diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 094c5d0e1..cc7502627 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -82,6 +82,9 @@ struct htlc_out *channel_has_htlc_out(struct channel *channel UNNEEDED) /* Generated stub for channel_internal_error */ void channel_internal_error(struct channel *channel UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "channel_internal_error called!\n"); abort(); } +/* Generated stub for channel_last_funding_feerate */ +u32 channel_last_funding_feerate(const struct channel *channel UNNEEDED) +{ fprintf(stderr, "channel_last_funding_feerate called!\n"); abort(); } /* Generated stub for channel_set_billboard */ void channel_set_billboard(struct channel *channel UNNEEDED, bool perm UNNEEDED, const char *str TAKES UNNEEDED)