Skip to content

Commit f9b80be

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. Because we ultimately figure out if something is being spent via the `OnchainTxHandler` we could skip this, but it allows us to use the post-HTLC-transaction value instead of the original HTLC value for claimable outputs.
1 parent cdeb078 commit f9b80be

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ enum OnchainEvent {
393393
/// * an inbound HTLC is claimed by us (with a preimage).
394394
/// * a revoked-state HTLC transaction was broadcasted, which was claimed by the revocation
395395
/// signature.
396+
/// * a revoked-state HTLC transaction was broadcasted, which was claimed by an
397+
/// HTLC-Success/HTLC-Failure transaction (and is still claimable with a revocation
398+
/// signature).
396399
HTLCSpendConfirmation {
397400
commitment_tx_output_idx: u32,
398401
/// If the HTLC was claimed by an HTLC-Success or HTLC-Timeout transaction, this is the
@@ -2894,7 +2897,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
28942897
log_error!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!",
28952898
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
28962899
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
2897-
if revocation_sig_claim { "revocation sig" } else { "preimage claim after we'd passed the HTLC resolution back" });
2900+
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" });
28982901
} else {
28992902
log_info!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}",
29002903
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
@@ -2947,31 +2950,21 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29472950
}
29482951
if payment_data.is_none() {
29492952
log_claim!($tx_info, $holder_tx, htlc_output, false);
2950-
let outbound_htlc = $holder_tx == htlc_output.offered;
2951-
if !outbound_htlc || revocation_sig_claim {
2952-
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
2953-
txid: tx.txid(), height, transaction: Some(tx.clone()),
2954-
event: OnchainEvent::HTLCSpendConfirmation {
2955-
commitment_tx_output_idx: input.previous_output.vout,
2956-
onchain_value_satoshis: Some(htlc_value_sats),
2957-
preimage: if accepted_preimage_claim || offered_preimage_claim {
2958-
Some(payment_preimage) } else { None },
2959-
// If this is a payment to us (!outbound_htlc, above),
2960-
// wait for the CSV delay before dropping the HTLC from
2961-
// claimable balance if the claim was an HTLC-Success
2962-
// transaction.
2963-
on_to_local_output_csv: if accepted_preimage_claim {
2964-
Some(self.on_holder_tx_csv) } else { None },
2965-
},
2966-
});
2967-
} else {
2968-
// Outbound claims should always have payment_data, unless
2969-
// we've already failed the HTLC as the commitment transaction
2970-
// which was broadcasted was revoked. In that case, we should
2971-
// spend the HTLC output here immediately, and expose that fact
2972-
// as a Balance, something which we do not yet do.
2973-
// TODO: Track the above as claimable!
2974-
}
2953+
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
2954+
txid: tx.txid(), height, transaction: Some(tx.clone()),
2955+
event: OnchainEvent::HTLCSpendConfirmation {
2956+
commitment_tx_output_idx: input.previous_output.vout,
2957+
onchain_value_satoshis: Some(htlc_value_sats),
2958+
preimage: if accepted_preimage_claim || offered_preimage_claim {
2959+
Some(payment_preimage) } else { None },
2960+
// If this is a payment to us (!outbound_htlc, above),
2961+
// wait for the CSV delay before dropping the HTLC from
2962+
// claimable balance if the claim was an HTLC-Success
2963+
// transaction.
2964+
on_to_local_output_csv: if accepted_preimage_claim {
2965+
Some(self.on_holder_tx_csv) } else { None },
2966+
},
2967+
});
29752968
continue 'outer_loop;
29762969
}
29772970
}

0 commit comments

Comments
 (0)