-
Notifications
You must be signed in to change notification settings - Fork 902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: receivable_msat to listpeers #3572
feat: receivable_msat to listpeers #3572
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 5710421
two tiny nits, otherwise lgtm
5710421
to
5c8bfab
Compare
2b8fa7a
to
55a1cef
Compare
49b2350
to
7d1f841
Compare
From my side, I'm more or less okay with this PR, aside I don't like the way I duplicated code (i.e. commit_txfee_spend/recv) with all just changing the Also I think there might be an off by one in current (master) implementation, see https://github.com/ElementsProject/lightning/pull/3572/files/7d1f8416e1af8bf9579914db46da6ce5b5cb394a#diff-e6fd9e4a383e2ab7819a6292c1edf70bR2357 for my remark in the testcase. |
7d1f841
to
71174a7
Compare
71174a7
to
324ec7d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my side, I'm more or less okay with this PR, aside I don't like the way I duplicated code (i.e. commit_txfee_spend/recv) with all just changing the
REMOTE
/LOCAL
orour_config
/their_config
... But any approach to unify the blocks lead to a iffy mess.
We might want to extract the LOCAL
/REMOTE
parameter into the function signature, and then internally use side
and !side
whenever either is used in the function. This is already what we do in a couple of places, and the enum
is such that !LOCAL == REMOTE
and vice-versa :-)
Might save us from future divergence of the two copies of the code.
Otherwise we can follow up with cleanups for the off-by-one once we have identified a cause (I'm confident it's not something introduced in this PR). Opened #3595 so it doesn't get lost.
324ec7d
to
ad2852f
Compare
I'll check if I can come up with something... |
c9d425a
to
784ed72
Compare
Changelog-Added: JSON API: `listpeers` now has `receivable_msat`
784ed72
to
2b4f034
Compare
@cdecker Is there more I can do? I.e. squash lightning/lightningd/peer_control.c Lines 725 to 784 in 2b4f034
Suggestion /* Compute how much we can send/receive via this channel in one payment. */
if (!amount_msat_sub_sat(&spendable, channel->our_msat,
channel->channel_info.their_config.channel_reserve))
spendable = AMOUNT_MSAT(0);
if (!amount_sat_sub_msat(&their_msat, channel->funding, channel->our_msat))
their_msat = AMOUNT_MSAT(0);
if (!amount_msat_sub_sat(&receivable, their_msat, channel->our_config.channel_reserve))
receivable = AMOUNT_MSAT(0);
/* Take away any currently-offered HTLCs. */
subtract_offered_htlcs(channel, &spendable);
subtract_received_htlcs(channel, &receivable);
/* Substract the funders txfees */
if (channel->funder == LOCAL) {
if (!amount_msat_sub_sat(&spendable, spendable,
commit_txfee(channel, spendable, LOCAL)))
spendable = AMOUNT_MSAT(0);
} else {
if (!amount_msat_sub_sat(&receivable, receivable,
commit_txfee(channel, receivable, REMOTE)))
receivable = AMOUNT_MSAT(0);
}
/* Can't offer an HTLC less than the other side will accept. */
if (amount_msat_less(spendable, channel->channel_info.their_config.htlc_minimum))
spendable = AMOUNT_MSAT(0);
if (amount_msat_less(receivable, channel->our_config.htlc_minimum))
receivable = AMOUNT_MSAT(0);
/* Can't offer an HTLC over the max payment threshold either. */
if (amount_msat_greater(spendable, chainparams->max_payment))
spendable = chainparams->max_payment;
if (amount_msat_greater(receivable, chainparams->max_payment))
receivable = chainparams->max_payment;
/* append spendable/receivable to JSON output */
json_add_amount_msat_compat(response, spendable,
"spendable_msatoshi", "spendable_msat");
json_add_amount_msat_compat(response, receivable,
"receivable_msatoshi", "receivable_msat"); |
ACK 2b4f034 |
This adds the
receivable_msat
amount to thelightning-cli listpeers
output. The logic is similar tospendable_msat
and applies for the maximum possible amount in one HTLC in that situation.Adds code, test and manpage - Closes #3555