Skip to content

Commit

Permalink
listpeers: add latest feerate and actual last fee amount.
Browse files Browse the repository at this point in the history
Users have no idea what they would pay for unilateral closes.
At least this gives them a clue!

Reported-by: @Az0re on IRC.

Changelog-Added: JSON-RPC: `listpeers` now shows latest feerate and unilaral close fee.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Mar 3, 2021
1 parent 4deb931 commit 1c99e63
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 7 deletions.
9 changes: 8 additions & 1 deletion doc/lightning-listpeers.7

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

4 changes: 4 additions & 0 deletions doc/lightning-listpeers.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ state, or in various circumstances:
* *out\_fulfilled\_msat*: A string describing the total amount of all
outgoing HTLCs offered *and successfully claimed* over this channel;
a number followed by a string unit.
* *scratch_txid*: The txid of the latest transaction (what we would sign and
send to chain if the channel were to fail now).
* *last_tx_fee*: The fee on that latest transaction.
* *feerate*: An object containing the latest feerate as both *perkw* and *perkb*.
* *htlcs*: An array of objects describing the HTLCs currently in-flight
in the channel.

Expand Down
11 changes: 11 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ static void json_add_channel(struct lightningd *ld,
struct amount_sat peer_funded_sats;
struct peer *p = channel->peer;
struct state_change_entry *state_changes;
u32 feerate;

json_object_start(response, key);
json_add_string(response, "state", channel_state_name(channel));
Expand All @@ -706,7 +707,17 @@ static void json_add_channel(struct lightningd *ld,
bitcoin_txid(channel->last_tx, &txid);

json_add_txid(response, "scratch_txid", &txid);
json_add_amount_sat_only(response, "last_tx_fee",
bitcoin_tx_compute_fee(channel->last_tx));
}

json_object_start(response, "feerate");
feerate = get_feerate(channel->fee_states, channel->opener, LOCAL);
json_add_u32(response, feerate_style_name(FEERATE_PER_KSIPA), feerate);
json_add_u32(response, feerate_style_name(FEERATE_PER_KBYTE),
feerate_to_style(feerate, FEERATE_PER_KBYTE));
json_object_end(response);

if (channel->owner)
json_add_string(response, "owner", channel->owner->name);

Expand Down
6 changes: 6 additions & 0 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ void json_add_amount_sat_compat(struct json_stream *result UNNEEDED,
const char *msatfieldname)

{ fprintf(stderr, "json_add_amount_sat_compat called!\n"); abort(); }
/* Generated stub for json_add_amount_sat_only */
void json_add_amount_sat_only(struct json_stream *result UNNEEDED,
const char *msatfieldname UNNEEDED,
struct amount_sat sat)

{ fprintf(stderr, "json_add_amount_sat_only called!\n"); abort(); }
/* Generated stub for json_add_bolt11 */
void json_add_bolt11(struct json_stream *response UNNEEDED,
const struct bolt11 *b11 UNNEEDED)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,8 @@ def test_multifunding_feerates(node_factory, bitcoind):
Test feerate parameters for multifundchannel
'''
funding_tx_feerate = '10000perkw'
commitment_tx_feerate = '2000perkw'
commitment_tx_feerate_int = 2000
commitment_tx_feerate = str(commitment_tx_feerate_int) + 'perkw'

l1, l2, l3 = node_factory.get_nodes(3, opts={'log-level': 'debug'})

Expand All @@ -1626,6 +1627,11 @@ def _connect_str(node):
expected_fee = int(funding_tx_feerate[:-5]) * weight // 1000
assert expected_fee == entry['fees']['base'] * 10 ** 8

assert only_one(only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'])['feerate']['perkw'] == commitment_tx_feerate_int
assert only_one(only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'])['feerate']['perkb'] == commitment_tx_feerate_int * 4

txfee = only_one(only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'])['last_tx_fee']

# We get the expected close txid, force close the channel, then fish
# the details about the transaction out of the mempoool entry
close_txid = only_one(only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'])['scratch_txid']
Expand All @@ -1652,6 +1658,7 @@ def _connect_str(node):
expected_fee += 330

assert expected_fee == entry['fees']['base'] * 10 ** 8
assert Millisatoshi(str(expected_fee) + 'sat') == Millisatoshi(txfee)


def test_multifunding_param_failures(node_factory):
Expand Down
2 changes: 1 addition & 1 deletion wallet/db_postgres_sqlgen.c

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

2 changes: 1 addition & 1 deletion wallet/db_sqlite3_sqlgen.c

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

6 changes: 3 additions & 3 deletions wallet/statements_gettextgen.po

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

6 changes: 6 additions & 0 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ void json_add_amount_sat_compat(struct json_stream *result UNNEEDED,
const char *msatfieldname)

{ fprintf(stderr, "json_add_amount_sat_compat called!\n"); abort(); }
/* Generated stub for json_add_amount_sat_only */
void json_add_amount_sat_only(struct json_stream *result UNNEEDED,
const char *msatfieldname UNNEEDED,
struct amount_sat sat)

{ fprintf(stderr, "json_add_amount_sat_only called!\n"); abort(); }
/* Generated stub for json_add_bool */
void json_add_bool(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
bool value UNNEEDED)
Expand Down

0 comments on commit 1c99e63

Please sign in to comment.