Skip to content

Commit

Permalink
plugins/spender: fix multifundchannel all on more than 1 channel.
Browse files Browse the repository at this point in the history
We tried to put *everything* into the "all" output, which didn't work
if there were other outputs!

Fixes: #6664
Signed-off-by: Rusty Russell <[email protected]>
Changelog-Fixed: JSON-RPC: `multifundchannel` with `all` as an amount works as expected.
  • Loading branch information
rustyrussell committed Mar 20, 2024
1 parent b752b4a commit d4abea3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 13 additions & 0 deletions plugins/spender/multifundchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,19 @@ after_fundpsbt(struct command *cmd,
|| !amount_msat_to_sat(&all->amount, msat))
goto fail;

/* Subtract amounts we're using for the other outputs */
for (size_t i = 0; i < tal_count(mfc->destinations); i++) {
if (mfc->destinations[i].all)
continue;
if (!amount_sat_sub(&all->amount,
all->amount,
mfc->destinations[i].amount)) {
return mfc_fail(mfc, JSONRPC2_INVALID_PARAMS,
"Insufficient funds for `all`"
" output");
}
}

/* Remove the 'all' flag. */
all->all = false;

Expand Down
1 change: 0 additions & 1 deletion tests/test_opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -2682,7 +2682,6 @@ def test_opening_explicit_channel_type(node_factory, bitcoind):
assert only_one(l3.rpc.listpeerchannels()['channels'])['channel_type']['bits'] == [STATIC_REMOTEKEY]


@pytest.mark.xfail(strict=True)
def test_multifunding_all_amount(node_factory, bitcoind):
l1, l2, l3 = node_factory.get_nodes(3)

Expand Down

0 comments on commit d4abea3

Please sign in to comment.