Skip to content

Commit f31e1f6

Browse files
committed
f set proper error height in HTLC time outs
1 parent 1e5a59d commit f31e1f6

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,7 +3066,12 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
30663066
// number of blocks we generally consider it to take to do a commitment update,
30673067
// just give up on it and fail he HTLC.
30683068
if height >= htlc.cltv_expiry - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS {
3069-
timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(), htlc.value));
3069+
let mut htlc_msat_height_data = byte_utils::be64_to_array(htlc.value).to_vec();
3070+
htlc_msat_height_data.extend_from_slice(&byte_utils::be32_to_array(height));
3071+
timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(), HTLCFailReason::Reason {
3072+
failure_code: 0x4000 | 15,
3073+
data: htlc_msat_height_data
3074+
}));
30703075
false
30713076
} else { true }
30723077
});
@@ -3077,17 +3082,10 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
30773082
self.finish_force_close_channel(failure);
30783083
}
30793084

3080-
for (source, payment_hash, value) in timed_out_htlcs.drain(..) {
3085+
for (source, payment_hash, reason) in timed_out_htlcs.drain(..) {
30813086
// Call it incorrect_or_unknown_payment_details as the issue, ultimately, is that the
30823087
// user failed to provide us a preimage within the cltv_expiry time window.
3083-
let mut htlc_msat_height_data = byte_utils::be64_to_array(value).to_vec();
3084-
htlc_msat_height_data.extend_from_slice(&byte_utils::be32_to_array(
3085-
self.latest_block_height.load(Ordering::Acquire) as u32,
3086-
));
3087-
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), source, &payment_hash, HTLCFailReason::Reason {
3088-
failure_code: 0x4000 | 15,
3089-
data: htlc_msat_height_data
3090-
});
3088+
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), source, &payment_hash, reason);
30913089
}
30923090
self.latest_block_height.store(height as usize, Ordering::Release);
30933091
*self.last_block_hash.try_lock().expect("block_(dis)connected must not be called in parallel") = header_hash;

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3698,7 +3698,7 @@ fn test_htlc_timeout() {
36983698
assert_eq!(payment_hash, our_payment_hash);
36993699
assert!(rejected_by_dest);
37003700
assert_eq!(error_code.unwrap(), 0x4000 | 15);
3701-
// 100_000 msat as u64, followed by a height of 122 as u32
3701+
// 100_000 msat as u64, followed by a height of 123 as u32
37023702
assert_eq!(&error_data.as_ref().unwrap()[..], &[
37033703
((100_000u64 >> 7*8) & 0xff) as u8,
37043704
((100_000u64 >> 6*8) & 0xff) as u8,
@@ -3708,7 +3708,7 @@ fn test_htlc_timeout() {
37083708
((100_000u64 >> 2*8) & 0xff) as u8,
37093709
((100_000u64 >> 1*8) & 0xff) as u8,
37103710
((100_000u64 >> 0*8) & 0xff) as u8,
3711-
0, 0, 0, 122]);
3711+
0, 0, 0, 123]);
37123712
},
37133713
_ => panic!("Unexpected event"),
37143714
}

0 commit comments

Comments
 (0)