Skip to content

Commit c20e7fa

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 ef1ca9b commit c20e7fa

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ enum OnchainEvent {
390390
/// * an inbound HTLC is claimed by us (with a preimage).
391391
/// * a revoked-state HTLC transaction was broadcasted, which was claimed by the revocation
392392
/// signature.
393+
/// * a revoked-state HTLC transaction was broadcasted, which was claimed by an
394+
/// HTLC-Success/HTLC-Failure transaction (and is still claimable with a revocation
395+
/// signature).
393396
HTLCSpendConfirmation {
394397
commitment_tx_output_idx: u32,
395398
/// If the claim was made by either party with a preimage, this is filled in
@@ -2934,7 +2937,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29342937
log_error!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!",
29352938
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
29362939
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
2937-
if revocation_sig_claim { "revocation sig" } else { "preimage claim after we'd passed the HTLC resolution back" });
2940+
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" });
29382941
} else {
29392942
log_info!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}",
29402943
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
@@ -2980,30 +2983,20 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29802983
}
29812984
if payment_data.is_none() {
29822985
log_claim!($tx_info, $holder_tx, htlc_output, false);
2983-
let outbound_htlc = $holder_tx == htlc_output.offered;
2984-
if !outbound_htlc || revocation_sig_claim {
2985-
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
2986-
txid: tx.txid(), height, transaction: Some(tx.clone()),
2987-
event: OnchainEvent::HTLCSpendConfirmation {
2988-
commitment_tx_output_idx: input.previous_output.vout,
2989-
preimage: if accepted_preimage_claim || offered_preimage_claim {
2990-
Some(payment_preimage) } else { None },
2991-
// If this is a payment to us (!outbound_htlc, above),
2992-
// wait for the CSV delay before dropping the HTLC from
2993-
// claimable balance if the claim was an HTLC-Success
2994-
// transaction.
2995-
on_to_local_output_csv: if accepted_preimage_claim {
2996-
Some(self.on_holder_tx_csv) } else { None },
2997-
},
2998-
});
2999-
} else {
3000-
// Outbound claims should always have payment_data, unless
3001-
// we've already failed the HTLC as the commitment transaction
3002-
// which was broadcasted was revoked. In that case, we should
3003-
// spend the HTLC output here immediately, and expose that fact
3004-
// as a Balance, something which we do not yet do.
3005-
// TODO: Track the above as claimable!
3006-
}
2986+
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
2987+
txid: tx.txid(), height, transaction: Some(tx.clone()),
2988+
event: OnchainEvent::HTLCSpendConfirmation {
2989+
commitment_tx_output_idx: input.previous_output.vout,
2990+
preimage: if accepted_preimage_claim || offered_preimage_claim {
2991+
Some(payment_preimage) } else { None },
2992+
// If this is a payment to us (!outbound_htlc, above),
2993+
// wait for the CSV delay before dropping the HTLC from
2994+
// claimable balance if the claim was an HTLC-Success
2995+
// transaction.
2996+
on_to_local_output_csv: if accepted_preimage_claim {
2997+
Some(self.on_holder_tx_csv) } else { None },
2998+
},
2999+
});
30073000
continue 'outer_loop;
30083001
}
30093002
}

0 commit comments

Comments
 (0)