Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inflights ordering, crashfix #4521

Merged
merged 20 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0ce2cc3
df-test: test for a failed rbf attempt, currently crashes
niftynei May 7, 2021
6b88e97
df-tests: add better explainer for test logic
niftynei May 7, 2021
8eca244
df-rbf: order inflights by funding_feerate
niftynei May 7, 2021
fbc556c
inflights: add checks that there's actually an inflight
niftynei May 7, 2021
d9313b2
listpeers: add inflights info
niftynei May 19, 2021
b8e7fcb
df-rbf: test that, with enough bumps, we can eventually add to mempool
niftynei May 19, 2021
a296e01
rbf: on close, drop every inflight transaction's commitment
niftynei May 20, 2021
8c904cc
listpeers: show the inflight's 'commitment tx' txid
niftynei May 20, 2021
2bdf27f
listpeers: always show all the inflights
niftynei May 20, 2021
689e6e9
dev-sign-last-tx: include inflight signed txs
niftynei May 20, 2021
125739d
inflights: save the whole psbt to the database
niftynei May 20, 2021
18df398
rbf-tests: check every inflight has signed commitment produced
niftynei May 20, 2021
da60f41
open-rbf: we broadcast all the commitments for a channel when closed
niftynei May 20, 2021
df2edec
inflights: relax assertion channel funding_txid is last inflight txid
niftynei May 20, 2021
2270edd
rbf: update the channel's funding_txid to match what's mined
niftynei May 20, 2021
6da93d4
rbf: when a channel is open, remove all the inflights
niftynei May 20, 2021
9f28405
rbf: when a peer is activated, also keep track of all of its inflights
niftynei May 20, 2021
97e9143
nit: add another debug log
niftynei May 20, 2021
30166ed
rbf-test: confirm that rbf'd inflight is opened and closed as expected
niftynei May 20, 2021
2d4f3d0
dual-open: save our now updated info about broadcast state
niftynei May 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions lightningd/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ new_inflight(struct channel *channel,
struct amount_sat total_funds,
struct amount_sat our_funds,
struct wally_psbt *psbt STEALS,
struct bitcoin_tx *last_tx STEALS,
struct bitcoin_tx *last_tx,
const struct bitcoin_signature last_sig)
{
struct wally_psbt *last_tx_psbt_clone;
struct channel_inflight *inflight
= tal(channel, struct channel_inflight);
struct funding_info *funding
Expand All @@ -177,7 +178,10 @@ new_inflight(struct channel *channel,
inflight->channel = channel;
inflight->remote_tx_sigs = false;
inflight->funding_psbt = tal_steal(inflight, psbt);
inflight->last_tx = tal_steal(inflight, last_tx);

/* Make a 'clone' of this tx */
last_tx_psbt_clone = clone_psbt(inflight, last_tx->psbt);
inflight->last_tx = bitcoin_tx_with_psbt(inflight, last_tx_psbt_clone);
inflight->last_sig = last_sig;
inflight->tx_broadcast = false;

Expand Down Expand Up @@ -726,15 +730,9 @@ void channel_fail_forget(struct channel *channel, const char *fmt, ...)
struct channel_inflight *
channel_current_inflight(const struct channel *channel)
{
struct channel_inflight *inflight;
/* The last inflight should always be the one in progress */
inflight = list_tail(&channel->inflights,
struct channel_inflight,
list);
if (inflight)
assert(bitcoin_txid_eq(&channel->funding_txid,
&inflight->funding->txid));
return inflight;
return list_tail(&channel->inflights,
struct channel_inflight, list);
}

u32 channel_last_funding_feerate(const struct channel *channel)
Expand Down
2 changes: 2 additions & 0 deletions lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ bool channel_tell_depth(struct lightningd *ld,
return true;
}

log_debug(channel->log,
"Funding tx %s confirmed, telling peer", txidstr);
dualopen_tell_depth(channel->owner, channel,
txid, depth);
return true;
Expand Down
85 changes: 47 additions & 38 deletions lightningd/dual_open_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,12 @@ openchannel2_sign_hook_cb(struct openchannel2_psbt_payload *payload STEALS)
}

inflight = channel_current_inflight(channel);
if (!inflight) {
log_broken(channel->log,
"No current channel inflight");
msg = towire_dualopend_fail(NULL, "No current channel inflight");
goto send_msg;
}

/* Check that we've got the same / correct PSBT */
psbt_txid(NULL, payload->psbt, &txid, NULL);
Expand Down Expand Up @@ -1020,9 +1026,9 @@ static struct amount_sat calculate_reserve(struct channel_config *their_config,
return reserve;
}

static void channel_update_reserve(struct channel *channel,
struct channel_config *their_config,
struct amount_sat funding_total)
void channel_update_reserve(struct channel *channel,
struct channel_config *their_config,
struct amount_sat funding_total)
{
struct amount_sat reserve;

Expand Down Expand Up @@ -1068,8 +1074,11 @@ wallet_update_channel(struct lightningd *ld,
channel->our_msat = our_msat;
channel->msat_to_us_min = our_msat;
channel->msat_to_us_max = our_msat;
channel->last_tx = tal_steal(channel, remote_commit);
channel->last_sig = *remote_commit_sig;

channel_set_last_tx(channel,
tal_steal(channel, remote_commit),
remote_commit_sig,
TX_CHANNEL_UNILATERAL);

/* Update in database */
wallet_channel_save(ld->wallet, channel);
Expand Down Expand Up @@ -1138,8 +1147,11 @@ wallet_commit_channel(struct lightningd *ld,
channel->our_msat = our_msat;
channel->msat_to_us_min = our_msat;
channel->msat_to_us_max = our_msat;

channel->last_tx = tal_steal(channel, remote_commit);
channel->last_sig = *remote_commit_sig;
channel->last_tx_type = TX_CHANNEL_UNILATERAL;

channel->channel_info = *channel_info;
channel->fee_states = new_fee_states(channel,
channel->opener,
Expand Down Expand Up @@ -1398,6 +1410,13 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend,
}

inflight = channel_current_inflight(channel);
if (!inflight) {
channel_internal_error(channel,
"No inflight found for channel %s",
type_to_string(tmpctx, struct channel,
channel));
return;
}

/* Once we've sent our sigs to the peer, we're fine
* to broadcast the transaction, even if they haven't
Expand All @@ -1420,6 +1439,8 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend,
return;
}

/* Saves the now finalized version of the psbt */
wallet_inflight_save(dualopend->ld->wallet, inflight);
send_funding_tx(channel, take(wtx));

/* Must be in an "init" state */
Expand Down Expand Up @@ -1518,6 +1539,9 @@ static void handle_channel_locked(struct subd *dualopend,
"Lockin complete");
channel_record_open(channel);

/* Empty out the inflights */
wallet_channel_clear_inflights(dualopend->ld->wallet, channel);

/* FIXME: LND sigs/update_fee msgs? */
peer_start_channeld(channel, pps, NULL, false);
return;
Expand All @@ -1539,40 +1563,14 @@ void dualopen_tell_depth(struct subd *dualopend,
/* Are we there yet? */
if (to_go == 0) {
assert(channel->scid);
assert(bitcoin_txid_eq(&channel->funding_txid, txid));

channel_set_billboard(channel, false,
tal_fmt(tmpctx, "Funding depth reached"
" %d confirmations, alerting peer"
" we're locked-in.",
to_go));

/* 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->last_tx = tal_steal(channel, inf->last_tx);
channel->last_sig = inf->last_sig;

/* Update the reserve */
channel_update_reserve(channel,
&channel->channel_info.their_config,
inf->funding->total_funds);

wallet_channel_save(dualopend->ld->wallet, channel);
/* FIXME: delete inflights */
}
msg = towire_dualopend_depth_reached(NULL, depth);
subd_send_msg(dualopend, take(msg));
} else
Expand Down Expand Up @@ -1723,6 +1721,14 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend,
}

inflight = channel_current_inflight(channel);
if (!inflight) {
channel_internal_error(channel,
"No inflight found for channel %s",
type_to_string(tmpctx, struct channel,
channel));
return;
}

/* Save that we've gotten their sigs. Sometimes
* the peer doesn't send any sigs (no inputs), otherwise
* we could just check the PSBT was finalized */
Expand Down Expand Up @@ -2906,11 +2912,14 @@ void peer_restart_dualopend(struct peer *peer,
&min_effective_htlc_capacity);

inflight = channel_current_inflight(channel);
assert(inflight);

/* Get the first inflight to figure out the original feerate
* for this channel. It's fine if it's the same as the current */
first_inflight = list_top(&channel->inflights,
struct channel_inflight,
list);
assert(first_inflight);
msg = towire_dualopend_reinit(NULL,
chainparams,
peer->ld->our_features,
Expand Down
4 changes: 4 additions & 0 deletions lightningd/dual_open_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ void channel_unsaved_close_conn(struct channel *channel, const char *why);

void json_add_unsaved_channel(struct json_stream *response,
const struct channel *channel);

void channel_update_reserve(struct channel *channel,
struct channel_config *their_config,
struct amount_sat funding_total);
#endif /* LIGHTNING_LIGHTNINGD_DUAL_OPEN_CONTROL_H */
Loading