Skip to content

Commit 9469ce0

Browse files
committed
Track HTLC-Success/HTLC-Timeout claims of revoked outputs
When a counterparty broadcasts a revoked commitment transaction, followed immediately by HTLC-Success/-Timeout spends thereof, we'd like to have an `onchain_events_awaiting_threshold_conf` entry for them. This does so using the `HTLCSpendConfirmation` entry, giving it (slightly) new meaning. Because all existing uses of `HTLCSpendConfirmation` already check if the relevant commitment transaction is revoked first, this should be trivially backwards compatible. We will ultimately figure out if something is being spent via the `OnchainTxHandler`, but to do so we need to look up the output via the HTLC transaction txid, which this allows us to do.
1 parent e76ac33 commit 9469ce0

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ enum OnchainEvent {
369369
/// transaction which appeared on chain.
370370
commitment_tx_output_idx: Option<u32>,
371371
},
372+
/// An output waiting on [`ANTI_REORG_DELAY`] confirmations before we hand the user the
373+
/// [`SpendableOutputDescriptor`].
372374
MaturingOutput {
373375
descriptor: SpendableOutputDescriptor,
374376
},
@@ -390,6 +392,9 @@ enum OnchainEvent {
390392
/// * an inbound HTLC is claimed by us (with a preimage).
391393
/// * a revoked-state HTLC transaction was broadcasted, which was claimed by the revocation
392394
/// signature.
395+
/// * a revoked-state HTLC transaction was broadcasted, which was claimed by an
396+
/// HTLC-Success/HTLC-Failure transaction (and is still claimable with a revocation
397+
/// signature).
393398
HTLCSpendConfirmation {
394399
commitment_tx_output_idx: u32,
395400
/// If the claim was made by either party with a preimage, this is filled in
@@ -2965,7 +2970,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29652970
log_error!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!",
29662971
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
29672972
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
2968-
if revocation_sig_claim { "revocation sig" } else { "preimage claim after we'd passed the HTLC resolution back" });
2973+
if revocation_sig_claim { "revocation sig" } else { "preimage claim after we'd passed the HTLC resolution back. We can likely claim the HTLC output with a revocation claim" });
29692974
} else {
29702975
log_info!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}",
29712976
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
@@ -3012,29 +3017,20 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30123017
if payment_data.is_none() {
30133018
log_claim!($tx_info, $holder_tx, htlc_output, false);
30143019
let outbound_htlc = $holder_tx == htlc_output.offered;
3015-
if !outbound_htlc || revocation_sig_claim {
3016-
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
3017-
txid: tx.txid(), height, transaction: Some(tx.clone()),
3018-
event: OnchainEvent::HTLCSpendConfirmation {
3019-
commitment_tx_output_idx: input.previous_output.vout,
3020-
preimage: if accepted_preimage_claim || offered_preimage_claim {
3021-
Some(payment_preimage) } else { None },
3022-
// If this is a payment to us (!outbound_htlc, above),
3023-
// wait for the CSV delay before dropping the HTLC from
3024-
// claimable balance if the claim was an HTLC-Success
3025-
// transaction.
3026-
on_to_local_output_csv: if accepted_preimage_claim {
3027-
Some(self.on_holder_tx_csv) } else { None },
3028-
},
3029-
});
3030-
} else {
3031-
// Outbound claims should always have payment_data, unless
3032-
// we've already failed the HTLC as the commitment transaction
3033-
// which was broadcasted was revoked. In that case, we should
3034-
// spend the HTLC output here immediately, and expose that fact
3035-
// as a Balance, something which we do not yet do.
3036-
// TODO: Track the above as claimable!
3037-
}
3020+
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
3021+
txid: tx.txid(), height, transaction: Some(tx.clone()),
3022+
event: OnchainEvent::HTLCSpendConfirmation {
3023+
commitment_tx_output_idx: input.previous_output.vout,
3024+
preimage: if accepted_preimage_claim || offered_preimage_claim {
3025+
Some(payment_preimage) } else { None },
3026+
// If this is a payment to us (ie !outbound_htlc), wait for
3027+
// the CSV delay before dropping the HTLC from claimable
3028+
// balance if the claim was an HTLC-Success transaction (ie
3029+
// accepted_preimage_claim).
3030+
on_to_local_output_csv: if accepted_preimage_claim && !outbound_htlc {
3031+
Some(self.on_holder_tx_csv) } else { None },
3032+
},
3033+
});
30383034
continue 'outer_loop;
30393035
}
30403036
}

0 commit comments

Comments
 (0)