Skip to content

Commit 74ead94

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 49d4649 commit 74ead94

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
@@ -2947,7 +2950,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29472950
log_error!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!",
29482951
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
29492952
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
2950-
if revocation_sig_claim { "revocation sig" } else { "preimage claim after we'd passed the HTLC resolution back" });
2953+
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" });
29512954
} else {
29522955
log_info!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}",
29532956
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
@@ -3000,31 +3003,21 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30003003
}
30013004
if payment_data.is_none() {
30023005
log_claim!($tx_info, $holder_tx, htlc_output, false);
3003-
let outbound_htlc = $holder_tx == htlc_output.offered;
3004-
if !outbound_htlc || revocation_sig_claim {
3005-
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
3006-
txid: tx.txid(), height, transaction: Some(tx.clone()),
3007-
event: OnchainEvent::HTLCSpendConfirmation {
3008-
commitment_tx_output_idx: input.previous_output.vout,
3009-
onchain_value_satoshis: Some(htlc_value_sats),
3010-
preimage: if accepted_preimage_claim || offered_preimage_claim {
3011-
Some(payment_preimage) } else { None },
3012-
// If this is a payment to us (!outbound_htlc, above),
3013-
// wait for the CSV delay before dropping the HTLC from
3014-
// claimable balance if the claim was an HTLC-Success
3015-
// transaction.
3016-
on_to_local_output_csv: if accepted_preimage_claim {
3017-
Some(self.on_holder_tx_csv) } else { None },
3018-
},
3019-
});
3020-
} else {
3021-
// Outbound claims should always have payment_data, unless
3022-
// we've already failed the HTLC as the commitment transaction
3023-
// which was broadcasted was revoked. In that case, we should
3024-
// spend the HTLC output here immediately, and expose that fact
3025-
// as a Balance, something which we do not yet do.
3026-
// TODO: Track the above as claimable!
3027-
}
3006+
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
3007+
txid: tx.txid(), height, transaction: Some(tx.clone()),
3008+
event: OnchainEvent::HTLCSpendConfirmation {
3009+
commitment_tx_output_idx: input.previous_output.vout,
3010+
onchain_value_satoshis: Some(htlc_value_sats),
3011+
preimage: if accepted_preimage_claim || offered_preimage_claim {
3012+
Some(payment_preimage) } else { None },
3013+
// If this is a payment to us (!outbound_htlc, above),
3014+
// wait for the CSV delay before dropping the HTLC from
3015+
// claimable balance if the claim was an HTLC-Success
3016+
// transaction.
3017+
on_to_local_output_csv: if accepted_preimage_claim {
3018+
Some(self.on_holder_tx_csv) } else { None },
3019+
},
3020+
});
30283021
continue 'outer_loop;
30293022
}
30303023
}

0 commit comments

Comments
 (0)