Skip to content

Commit 4cc93b8

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 0b7523d commit 4cc93b8

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
@@ -2961,7 +2966,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29612966
log_error!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!",
29622967
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
29632968
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
2964-
if revocation_sig_claim { "revocation sig" } else { "preimage claim after we'd passed the HTLC resolution back" });
2969+
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" });
29652970
} else {
29662971
log_info!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}",
29672972
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
@@ -3008,29 +3013,20 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30083013
if payment_data.is_none() {
30093014
log_claim!($tx_info, $holder_tx, htlc_output, false);
30103015
let outbound_htlc = $holder_tx == htlc_output.offered;
3011-
if !outbound_htlc || revocation_sig_claim {
3012-
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
3013-
txid: tx.txid(), height, transaction: Some(tx.clone()),
3014-
event: OnchainEvent::HTLCSpendConfirmation {
3015-
commitment_tx_output_idx: input.previous_output.vout,
3016-
preimage: if accepted_preimage_claim || offered_preimage_claim {
3017-
Some(payment_preimage) } else { None },
3018-
// If this is a payment to us (!outbound_htlc, above),
3019-
// wait for the CSV delay before dropping the HTLC from
3020-
// claimable balance if the claim was an HTLC-Success
3021-
// transaction.
3022-
on_to_local_output_csv: if accepted_preimage_claim {
3023-
Some(self.on_holder_tx_csv) } else { None },
3024-
},
3025-
});
3026-
} else {
3027-
// Outbound claims should always have payment_data, unless
3028-
// we've already failed the HTLC as the commitment transaction
3029-
// which was broadcasted was revoked. In that case, we should
3030-
// spend the HTLC output here immediately, and expose that fact
3031-
// as a Balance, something which we do not yet do.
3032-
// TODO: Track the above as claimable!
3033-
}
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 (ie !outbound_htlc), wait for
3023+
// the CSV delay before dropping the HTLC from claimable
3024+
// balance if the claim was an HTLC-Success transaction (ie
3025+
// accepted_preimage_claim).
3026+
on_to_local_output_csv: if accepted_preimage_claim && !outbound_htlc {
3027+
Some(self.on_holder_tx_csv) } else { None },
3028+
},
3029+
});
30343030
continue 'outer_loop;
30353031
}
30363032
}

0 commit comments

Comments
 (0)