Skip to content

Commit ad1a568

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

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/ln/channelmonitor.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,23 +1870,17 @@ impl ChannelMonitor {
18701870
let accepted_preimage_claim = input.witness.len() == 5 && input.witness[4].len() == ACCEPTED_HTLC_SCRIPT_WEIGHT;
18711871
let offered_preimage_claim = input.witness.len() == 3 && input.witness[2].len() == OFFERED_HTLC_SCRIPT_WEIGHT;
18721872

1873-
macro_rules! log_claim {
1874-
($tx_info: expr, $local_tx: expr, $htlc: expr, $source_avail: expr) => {
1875-
// 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.
1878-
let outbound_htlc = $local_tx == $htlc.offered;
1879-
if ($local_tx && revocation_sig_claim) ||
1880-
(outbound_htlc && !$source_avail && (accepted_preimage_claim || offered_preimage_claim)) {
1881-
log_error!(self, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!",
1882-
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
1883-
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
1884-
if revocation_sig_claim { "revocation sig" } else { "preimage claim after we'd passed the HTLC resolution back" });
1885-
} else {
1886-
log_info!(self, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}",
1887-
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
1888-
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
1889-
if revocation_sig_claim { "revocation sig" } else if accepted_preimage_claim || offered_preimage_claim { "preimage" } else { "timeout" });
1873+
macro_rules! check_htlc_valid_remote {
1874+
($remote_txid: expr, $htlc_output: expr) => {
1875+
if let &Some(txid) = $remote_txid {
1876+
for &(ref pending_htlc, ref pending_source) in self.remote_claimable_outpoints.get(&txid).unwrap() {
1877+
if pending_htlc.payment_hash == $htlc_output.payment_hash && pending_htlc.amount_msat == $htlc_output.amount_msat {
1878+
if let &Some(ref source) = pending_source {
1879+
payment_data = Some(((**source).clone(), $htlc_output.payment_hash));
1880+
break;
1881+
}
1882+
}
1883+
}
18901884
}
18911885
}
18921886
}
@@ -1903,9 +1897,12 @@ impl ChannelMonitor {
19031897
// has timed out, or we screwed up. In any case, we should now
19041898
// resolve the source HTLC with the original sender.
19051899
payment_data = Some(((*source).clone(), htlc_output.payment_hash));
1906-
} else {
1907-
log_claim!($tx_info, $local_tx, htlc_output, false);
1908-
continue 'outer_loop;
1900+
} else if !$local_tx {
1901+
if let Storage::Local { ref current_remote_commitment_txid, .. } = self.key_storage {
1902+
check_htlc_valid_remote!(current_remote_commitment_txid, htlc_output);
1903+
} else if let Storage::Local { ref prev_remote_commitment_txid, .. } = self.key_storage {
1904+
check_htlc_valid_remote!(prev_remote_commitment_txid, htlc_output);
1905+
}
19091906
}
19101907
}
19111908
}

0 commit comments

Comments
 (0)