Skip to content

Commit

Permalink
f Rebase on lightningdevkit#596
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Apr 24, 2020
1 parent 4738ab8 commit c187d77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3051,9 +3051,13 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
for (source, payment_hash, value) in timed_out_htlcs.drain(..) {
// Call it preimage_unknown as the issue, ultimately, is that the user failed to
// provide us a preimage within the cltv_expiry time window.
let mut htlc_msat_height_data = byte_utils::be64_to_array(value).to_vec();
htlc_msat_height_data.extend_from_slice(&byte_utils::be32_to_array(
self.latest_block_height.load(Ordering::Acquire) as u32,
));
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), source, &payment_hash, HTLCFailReason::Reason {
failure_code: 0x4000 | 15,
data: byte_utils::be64_to_array(value).to_vec()
data: htlc_msat_height_data
});
}
self.latest_block_height.store(height as usize, Ordering::Release);
Expand Down
15 changes: 13 additions & 2 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3695,11 +3695,22 @@ fn test_htlc_timeout() {
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_timeout_updates.update_fail_htlcs[0]);
commitment_signed_dance!(nodes[0], nodes[1], htlc_timeout_updates.commitment_signed, false);
let events = nodes[0].node.get_and_clear_pending_events();
match events[0] {
Event::PaymentFailed { payment_hash, rejected_by_dest, error_code } => {
match &events[0] {
&Event::PaymentFailed { payment_hash, rejected_by_dest, error_code, ref error_data } => {
assert_eq!(payment_hash, our_payment_hash);
assert!(rejected_by_dest);
assert_eq!(error_code.unwrap(), 0x4000 | 15);
// 100_000 msat as u64, followed by a height of 122 as u32
assert_eq!(&error_data.as_ref().unwrap()[..], &[
((100_000u64 >> 7*8) & 0xff) as u8,
((100_000u64 >> 6*8) & 0xff) as u8,
((100_000u64 >> 5*8) & 0xff) as u8,
((100_000u64 >> 4*8) & 0xff) as u8,
((100_000u64 >> 3*8) & 0xff) as u8,
((100_000u64 >> 2*8) & 0xff) as u8,
((100_000u64 >> 1*8) & 0xff) as u8,
((100_000u64 >> 0*8) & 0xff) as u8,
0, 0, 0, 122]);
},
_ => panic!("Unexpected event"),
}
Expand Down

0 comments on commit c187d77

Please sign in to comment.