Skip to content

Commit

Permalink
lightningd: add direct close outputs to listfunds (mutual close).
Browse files Browse the repository at this point in the history
We had a complaint that you can't CPFP a mutual close, which you
should be able to do.

Fixes: #6692
Changelog-Fixed: wallet: close change outputs show up immediately in `listfunds` so you can CPFP.
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Oct 2, 2023
1 parent cf505ea commit 7db541a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ static struct bitcoin_tx *sign_and_send_last(const tal_t *ctx,
tx = sign_last_tx(ctx, channel, last_tx, last_sig);
bitcoin_txid(tx, &txid);
wallet_transaction_add(ld->wallet, tx->wtx, 0, 0);
wallet_extract_owned_outputs(ld->wallet, tx->wtx, false, NULL, NULL);

/* Remember anchor information for commit_tx_boost */
adet = create_anchor_details(NULL, channel, tx);
Expand Down
1 change: 0 additions & 1 deletion tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3874,7 +3874,6 @@ def test_closing_minfee(node_factory, bitcoind):
bitcoind.generate_block(1, wait_for_mempool=txid)


@pytest.mark.xfail(strict=True)
def test_closing_cpfp(node_factory, bitcoind):
l1, l2 = node_factory.line_graph(2)

Expand Down
8 changes: 5 additions & 3 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ struct wallet *wallet_new(struct lightningd *ld, struct timers *timers)
*
* This can fail if we've already seen UTXO.
*/
static bool wallet_add_utxo(struct wallet *w, struct utxo *utxo,
static bool wallet_add_utxo(struct wallet *w,
const struct utxo *utxo,
enum wallet_output_type type)
{
struct db_stmt *stmt;
Expand Down Expand Up @@ -2573,7 +2574,8 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *wtx,
{
int num_utxos = 0;

*total = AMOUNT_SAT(0);
if (total)
*total = AMOUNT_SAT(0);
for (size_t output = 0; output < wtx->num_outputs; output++) {
struct utxo *utxo;
u32 index;
Expand Down Expand Up @@ -2646,7 +2648,7 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *wtx,

outpointfilter_add(w->owned_outpoints, &utxo->outpoint);

if (!amount_sat_add(total, *total, utxo->amount))
if (total && !amount_sat_add(total, *total, utxo->amount))
fatal("Cannot add utxo output %zu/%zu %s + %s",
output, wtx->num_outputs,
type_to_string(tmpctx, struct amount_sat, total),
Expand Down
1 change: 1 addition & 0 deletions wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ bool wallet_has_funds(struct wallet *wallet,
const struct utxo **excludes,
u32 current_blockheight,
struct amount_sat sats);

/**
* wallet_add_onchaind_utxo - Add a UTXO with spending info from onchaind.
*
Expand Down

0 comments on commit 7db541a

Please sign in to comment.