mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
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:
parent
36f3b13279
commit
b8b910e4c4
@ -372,6 +372,18 @@ struct channel *peer_active_channel(struct peer *peer)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct channel_inflight *channel_inflight_find(struct channel *channel,
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
struct channel_inflight *inflight;
|
||||
list_for_each(&channel->inflights, inflight, list) {
|
||||
if (bitcoin_txid_eq(txid, &inflight->funding->txid))
|
||||
return inflight;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct channel *peer_normal_channel(struct peer *peer)
|
||||
{
|
||||
struct channel *channel;
|
||||
|
@ -262,6 +262,10 @@ new_inflight(struct channel *channel,
|
||||
struct bitcoin_tx *last_tx STEALS,
|
||||
const struct bitcoin_signature last_sig);
|
||||
|
||||
/* Given a txid, find an inflight channel stub. Returns NULL if none found */
|
||||
struct channel_inflight *channel_inflight_find(struct channel *channel,
|
||||
const struct bitcoin_txid *txid);
|
||||
|
||||
void delete_channel(struct channel *channel STEALS);
|
||||
|
||||
const char *channel_state_name(const struct channel *channel);
|
||||
|
@ -639,7 +639,8 @@ bool channel_tell_depth(struct lightningd *ld,
|
||||
}
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
dualopen_tell_depth(channel->owner, channel, depth);
|
||||
dualopen_tell_depth(channel->owner, channel,
|
||||
txid, depth);
|
||||
return true;
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
} else if (channel->state != CHANNELD_AWAITING_LOCKIN
|
||||
|
@ -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
|
||||
|
@ -17,5 +17,6 @@ void peer_restart_dualopend(struct peer *peer,
|
||||
|
||||
void dualopen_tell_depth(struct subd *dualopend,
|
||||
struct channel *channel,
|
||||
const struct bitcoin_txid *txid,
|
||||
u32 depth);
|
||||
#endif /* LIGHTNING_LIGHTNINGD_DUAL_OPEN_CONTROL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user