Skip to content

Commit 36d25c4

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 cdbd336 commit 36d25c4

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

0 commit comments

Comments
 (0)