Skip to content

Commit 5a1f212

Browse files
committed
Remove redundant payment preimag hashing in HTLC claim pipeline
Currently, when we receive an HTLC claim from a peer, we first hash the preimage they gave us before removing the HTLC, then immediately pass the preimage to the inbound channel and hash the preimage again before removing the HTLC and sending our peer an `update_fulfill_htlc`. This second hash is actually only asserted on, never used in any meaningful way as we have the htlc data present in the same code. Here we simply drop this second hash and move it into a `debug_assert`.
1 parent 9e69922 commit 5a1f212

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

lightning/src/ln/channel.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2206,8 +2206,6 @@ impl<SP: Deref> Channel<SP> where
22062206
}
22072207
assert_eq!(self.context.channel_state & ChannelState::ShutdownComplete as u32, 0);
22082208

2209-
let payment_hash_calc = PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).into_inner());
2210-
22112209
// ChannelManager may generate duplicate claims/fails due to HTLC update events from
22122210
// on-chain ChannelsMonitors during block rescan. Ideally we'd figure out a way to drop
22132211
// these, but for now we just have to treat them as normal.
@@ -2216,7 +2214,7 @@ impl<SP: Deref> Channel<SP> where
22162214
let mut htlc_value_msat = 0;
22172215
for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
22182216
if htlc.htlc_id == htlc_id_arg {
2219-
assert_eq!(htlc.payment_hash, payment_hash_calc);
2217+
debug_assert_eq!(htlc.payment_hash, PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).into_inner()));
22202218
log_debug!(logger, "Claiming inbound HTLC id {} with payment hash {} with preimage {}",
22212219
htlc.htlc_id, htlc.payment_hash, payment_preimage_arg);
22222220
match htlc.state {

0 commit comments

Comments
 (0)