df-rbf: update channel data on depth reached

When the funding tx reaches depth, update the channel's data to the
"correct" funding transaction info from inflights (if necessary).

This will be necessary if:
    - the transaction has been successfully RBF'd and
    - the lesser fee transaction is the one successfully mined, OR
    - the channel is in the process of being RBF'd
This commit is contained in:
niftynei
2021-01-07 13:03:06 -06:00
committed by Rusty Russell
parent 36f3b13279
commit b8b910e4c4
5 changed files with 50 additions and 1 deletions

View File

@@ -1392,6 +1392,7 @@ cleanup:
void dualopen_tell_depth(struct subd *dualopend,
struct channel *channel,
const struct bitcoin_txid *txid,
u32 depth)
{
const u8 *msg;
@@ -1405,6 +1406,36 @@ void dualopen_tell_depth(struct subd *dualopend,
/* Are we there yet? */
if (to_go == 0) {
assert(channel->scid);
/* Update the channel's info to the correct tx, if we need to */
if (!bitcoin_txid_eq(&channel->funding_txid, txid)) {
struct channel_inflight *inf;
inf = channel_inflight_find(channel, txid);
if (!inf) {
channel_internal_error(channel,
"Txid %s for channel"
" not found in available inflights."
" (peer %s)",
type_to_string(tmpctx,
struct bitcoin_txid,
txid),
type_to_string(tmpctx,
struct node_id,
&channel->peer->id));
return;
}
channel->funding_txid = inf->funding->txid;
channel->funding_outnum = inf->funding->outnum;
channel->funding = inf->funding->total_funds;
channel->our_funds = inf->funding->our_funds;
channel->psbt = clone_psbt(channel, inf->funding_psbt);
channel->last_tx = tal_steal(channel, inf->last_tx);
channel->last_sig = inf->last_sig;
wallet_channel_save(dualopend->ld->wallet, channel);
/* FIXME: delete inflights */
}
msg = towire_dualopend_depth_reached(NULL, depth);
subd_send_msg(dualopend, take(msg));
} else