Skip to content

Commit 93efea3

Browse files
author
Antoine Riard
committed
Extract preimage from revoked HTLC-Success to claim backward
1 parent 35853a6 commit 93efea3

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/ln/channelmonitor.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,8 +1873,9 @@ impl ChannelMonitor {
18731873
macro_rules! log_claim {
18741874
($tx_info: expr, $local_tx: expr, $htlc: expr, $source_avail: expr) => {
18751875
// We found the output in question, but aren't failing it backwards
1876-
// as we have no corresponding source. This implies either it is an
1877-
// inbound HTLC or an outbound HTLC on a revoked transaction.
1876+
// as we have no corresponding source and no valid remote commitment txid
1877+
// to try a weak source binding with same-hash, same-value still-valid offered HTLC.
1878+
// This implies either it is an inbound HTLC or an outbound HTLC on a revoked transaction.
18781879
let outbound_htlc = $local_tx == $htlc.offered;
18791880
if ($local_tx && revocation_sig_claim) ||
18801881
(outbound_htlc && !$source_avail && (accepted_preimage_claim || offered_preimage_claim)) {
@@ -1891,6 +1892,21 @@ impl ChannelMonitor {
18911892
}
18921893
}
18931894

1895+
macro_rules! check_htlc_valid_remote {
1896+
($remote_txid: expr, $htlc_output: expr) => {
1897+
if let &Some(txid) = $remote_txid {
1898+
for &(ref pending_htlc, ref pending_source) in self.remote_claimable_outpoints.get(&txid).unwrap() {
1899+
if pending_htlc.payment_hash == $htlc_output.payment_hash && pending_htlc.amount_msat == $htlc_output.amount_msat {
1900+
if let &Some(ref source) = pending_source {
1901+
payment_data = Some(((**source).clone(), $htlc_output.payment_hash));
1902+
break;
1903+
}
1904+
}
1905+
}
1906+
}
1907+
}
1908+
}
1909+
18941910
macro_rules! scan_commitment {
18951911
($htlcs: expr, $tx_info: expr, $local_tx: expr) => {
18961912
for (ref htlc_output, source_option) in $htlcs {
@@ -1903,6 +1919,13 @@ impl ChannelMonitor {
19031919
// has timed out, or we screwed up. In any case, we should now
19041920
// resolve the source HTLC with the original sender.
19051921
payment_data = Some(((*source).clone(), htlc_output.payment_hash));
1922+
} else if !$local_tx {
1923+
log_claim!($tx_info, $local_tx, htlc_output, false);
1924+
if let Storage::Local { ref current_remote_commitment_txid, .. } = self.key_storage {
1925+
check_htlc_valid_remote!(current_remote_commitment_txid, htlc_output);
1926+
} else if let Storage::Local { ref prev_remote_commitment_txid, .. } = self.key_storage {
1927+
check_htlc_valid_remote!(prev_remote_commitment_txid, htlc_output);
1928+
}
19061929
} else {
19071930
log_claim!($tx_info, $local_tx, htlc_output, false);
19081931
continue 'outer_loop;

0 commit comments

Comments
 (0)