Skip to content

Commit 276eda5

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

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/ln/channelmonitor.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,21 @@ impl ChannelMonitor {
18911891
}
18921892
}
18931893

1894+
macro_rules! check_htlc_valid_remote {
1895+
($remote_txid: expr, $htlc_output: expr) => {
1896+
if let &Some(txid) = $remote_txid {
1897+
for &(ref pending_htlc, ref pending_source) in self.remote_claimable_outpoints.get(&txid).unwrap() {
1898+
if pending_htlc.payment_hash == $htlc_output.payment_hash && pending_htlc.amount_msat == $htlc_output.amount_msat {
1899+
if let &Some(ref source) = pending_source {
1900+
payment_data = Some(((**source).clone(), $htlc_output.payment_hash));
1901+
break;
1902+
}
1903+
}
1904+
}
1905+
}
1906+
}
1907+
}
1908+
18941909
macro_rules! scan_commitment {
18951910
($htlcs: expr, $tx_info: expr, $local_tx: expr) => {
18961911
for (ref htlc_output, source_option) in $htlcs {
@@ -1903,6 +1918,12 @@ impl ChannelMonitor {
19031918
// has timed out, or we screwed up. In any case, we should now
19041919
// resolve the source HTLC with the original sender.
19051920
payment_data = Some(((*source).clone(), htlc_output.payment_hash));
1921+
} else if !$local_tx {
1922+
if let Storage::Local { ref current_remote_commitment_txid, .. } = self.key_storage {
1923+
check_htlc_valid_remote!(current_remote_commitment_txid, htlc_output);
1924+
} else if let Storage::Local { ref prev_remote_commitment_txid, .. } = self.key_storage {
1925+
check_htlc_valid_remote!(prev_remote_commitment_txid, htlc_output);
1926+
}
19061927
} else {
19071928
log_claim!($tx_info, $local_tx, htlc_output, false);
19081929
continue 'outer_loop;

0 commit comments

Comments
 (0)