Skip to content

Commit c187d77

Browse files
committed
f Rebase on lightningdevkit#596
1 parent 4738ab8 commit c187d77

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3051,9 +3051,13 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
30513051
for (source, payment_hash, value) in timed_out_htlcs.drain(..) {
30523052
// Call it preimage_unknown as the issue, ultimately, is that the user failed to
30533053
// provide us a preimage within the cltv_expiry time window.
3054+
let mut htlc_msat_height_data = byte_utils::be64_to_array(value).to_vec();
3055+
htlc_msat_height_data.extend_from_slice(&byte_utils::be32_to_array(
3056+
self.latest_block_height.load(Ordering::Acquire) as u32,
3057+
));
30543058
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), source, &payment_hash, HTLCFailReason::Reason {
30553059
failure_code: 0x4000 | 15,
3056-
data: byte_utils::be64_to_array(value).to_vec()
3060+
data: htlc_msat_height_data
30573061
});
30583062
}
30593063
self.latest_block_height.store(height as usize, Ordering::Release);

lightning/src/ln/functional_tests.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,11 +3695,22 @@ fn test_htlc_timeout() {
36953695
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_timeout_updates.update_fail_htlcs[0]);
36963696
commitment_signed_dance!(nodes[0], nodes[1], htlc_timeout_updates.commitment_signed, false);
36973697
let events = nodes[0].node.get_and_clear_pending_events();
3698-
match events[0] {
3699-
Event::PaymentFailed { payment_hash, rejected_by_dest, error_code } => {
3698+
match &events[0] {
3699+
&Event::PaymentFailed { payment_hash, rejected_by_dest, error_code, ref error_data } => {
37003700
assert_eq!(payment_hash, our_payment_hash);
37013701
assert!(rejected_by_dest);
37023702
assert_eq!(error_code.unwrap(), 0x4000 | 15);
3703+
// 100_000 msat as u64, followed by a height of 122 as u32
3704+
assert_eq!(&error_data.as_ref().unwrap()[..], &[
3705+
((100_000u64 >> 7*8) & 0xff) as u8,
3706+
((100_000u64 >> 6*8) & 0xff) as u8,
3707+
((100_000u64 >> 5*8) & 0xff) as u8,
3708+
((100_000u64 >> 4*8) & 0xff) as u8,
3709+
((100_000u64 >> 3*8) & 0xff) as u8,
3710+
((100_000u64 >> 2*8) & 0xff) as u8,
3711+
((100_000u64 >> 1*8) & 0xff) as u8,
3712+
((100_000u64 >> 0*8) & 0xff) as u8,
3713+
0, 0, 0, 122]);
37033714
},
37043715
_ => panic!("Unexpected event"),
37053716
}

0 commit comments

Comments
 (0)