Skip to content

Commit

Permalink
lightningd: don't cap spendable_msat/receivable_msat for wumbo channels.
Browse files Browse the repository at this point in the history
If we both support large channels, we can actually send giant HTLCs.

This, in turn, fixes pay (which relies on this field!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Plugins: `pay` now knows it can use locally-connected wumbo channels for large payments.
Fixes: ElementsProject#5250
Fixes: ElementsProject#5417
  • Loading branch information
rustyrussell authored and cdecker committed Nov 30, 2022
1 parent cfcbb66 commit 6c42c8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lightningd/peer_control.c
Expand Up @@ -613,6 +613,7 @@ static void subtract_received_htlcs(const struct channel *channel,
struct amount_msat channel_amount_spendable(const struct channel *channel)
{
struct amount_msat spendable;
bool wumbo;

/* Compute how much we can send via this channel in one payment. */
if (!amount_msat_sub_sat(&spendable,
Expand All @@ -636,16 +637,23 @@ struct amount_msat channel_amount_spendable(const struct channel *channel)
channel->channel_info.their_config.htlc_minimum))
return AMOUNT_MSAT(0);

wumbo = feature_negotiated(channel->peer->ld->our_features,
channel->peer->their_features,
OPT_LARGE_CHANNELS);

/* We can't offer an HTLC over the max payment threshold either. */
if (amount_msat_greater(spendable, chainparams->max_payment))
if (amount_msat_greater(spendable, chainparams->max_payment)
&& !wumbo) {
spendable = chainparams->max_payment;
}

return spendable;
}

struct amount_msat channel_amount_receivable(const struct channel *channel)
{
struct amount_msat their_msat, receivable;
bool wumbo;

/* Compute how much we can receive via this channel in one payment */
if (!amount_sat_sub_msat(&their_msat,
Expand All @@ -672,9 +680,15 @@ struct amount_msat channel_amount_receivable(const struct channel *channel)
if (amount_msat_less(receivable, channel->our_config.htlc_minimum))
return AMOUNT_MSAT(0);

wumbo = feature_negotiated(channel->peer->ld->our_features,
channel->peer->their_features,
OPT_LARGE_CHANNELS);

/* They can't offer an HTLC over the max payment threshold either. */
if (amount_msat_greater(receivable, chainparams->max_payment))
if (amount_msat_greater(receivable, chainparams->max_payment)
&& !wumbo) {
receivable = chainparams->max_payment;
}

return receivable;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_connection.py
Expand Up @@ -3407,7 +3407,6 @@ def test_pay_disconnect_stress(node_factory, executor):

@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
@pytest.mark.xfail(strict=True)
def test_wumbo_channels(node_factory, bitcoind):
l1, l2, l3 = node_factory.get_nodes(3,
opts=[{'large-channels': None},
Expand Down

0 comments on commit 6c42c8b

Please sign in to comment.