Skip to content

Commit 91dc91f

Browse files
authored
Merge pull request #325 from TheBlueMatt/2019-03-322-cleanup
Extract preimage from revoked HTLC-Success to claim backward
2 parents d22650c + 3cc7666 commit 91dc91f

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/ln/channelmonitor.rs

Lines changed: 30 additions & 3 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,22 @@ 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+
log_claim!("revoked remote commitment tx", false, pending_htlc, true);
1902+
payment_data = Some(((**source).clone(), $htlc_output.payment_hash));
1903+
break;
1904+
}
1905+
}
1906+
}
1907+
}
1908+
}
1909+
}
1910+
18941911
macro_rules! scan_commitment {
18951912
($htlcs: expr, $tx_info: expr, $local_tx: expr) => {
18961913
for (ref htlc_output, source_option) in $htlcs {
@@ -1903,7 +1920,17 @@ impl ChannelMonitor {
19031920
// has timed out, or we screwed up. In any case, we should now
19041921
// resolve the source HTLC with the original sender.
19051922
payment_data = Some(((*source).clone(), htlc_output.payment_hash));
1906-
} else {
1923+
} else if !$local_tx {
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+
}
1927+
if payment_data.is_none() {
1928+
if let Storage::Local { ref prev_remote_commitment_txid, .. } = self.key_storage {
1929+
check_htlc_valid_remote!(prev_remote_commitment_txid, htlc_output);
1930+
}
1931+
}
1932+
}
1933+
if payment_data.is_none() {
19071934
log_claim!($tx_info, $local_tx, htlc_output, false);
19081935
continue 'outer_loop;
19091936
}

0 commit comments

Comments
 (0)