Skip to content

Commit

Permalink
lightningd: fix dual-funding case where we coop close and an RBF conf…
Browse files Browse the repository at this point in the history
…irms.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Oct 2, 2023
1 parent 2f39465 commit 79d0409
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,25 @@ static enum watch_result funding_spent(struct channel *channel,
size_t inputnum UNUSED,
const struct block *block);

/* We coop-closed channel: if another inflight confirms, force close */
static enum watch_result closed_inflight_depth_cb(struct lightningd *ld,
const struct bitcoin_txid *txid,
const struct bitcoin_tx *tx,
unsigned int depth,
struct channel_inflight *inflight)
{
if (depth == 0)
return KEEP_WATCHING;

/* This is now the main tx. */
update_channel_from_inflight(ld, inflight->channel, inflight);
channel_fail_permanent(inflight->channel,
REASON_UNKNOWN,
"Inflight tx %s confirmed after mutual close",
type_to_string(tmpctx, struct bitcoin_txid, txid));
return DELETE_WATCH;
}

void drop_to_chain(struct lightningd *ld, struct channel *channel,
bool cooperative)
{
Expand Down Expand Up @@ -366,6 +385,22 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel,

resolve_close_command(ld, channel, cooperative, tx);
}

/* In cooperative mode, we're assuming that we closed the right one:
* this might not happen if we're splicing, or dual-funding still
* opening. So, if we get any unexpected inflight confirming, we
* force close. */
if (cooperative) {
list_for_each(&channel->inflights, inflight, list) {
if (bitcoin_outpoint_eq(&inflight->funding->outpoint,
&channel->funding)) {
continue;
}
watch_txid(inflight, ld->topology,
&inflight->funding->outpoint.txid,
closed_inflight_depth_cb, inflight);
}
}
}

void resend_closing_transactions(struct lightningd *ld)
Expand Down

0 comments on commit 79d0409

Please sign in to comment.