Skip to content

Commit 5016084

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 57a91f0 commit 5016084

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
@@ -2202,8 +2202,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
22022202
}
22032203
assert_eq!(self.context.channel_state & ChannelState::ShutdownComplete as u32, 0);
22042204

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

0 commit comments

Comments
 (0)