- let events = nodes[0].node.get_and_clear_pending_events();
- 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 123 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, 123]);
- },
- _ => panic!("Unexpected event"),
+ // 100_000 msat as u64, followed by a height of 123 as u32
+ let mut expected_failure_data = byte_utils::be64_to_array(100_000).to_vec();
+ expected_failure_data.extend_from_slice(&byte_utils::be32_to_array(123));
+ expect_payment_failed!(nodes[0], our_payment_hash, true, 0x4000 | 15, &expected_failure_data[..]);
+}
+
+#[test]
+fn test_htlc_timeout() {
+ do_test_htlc_timeout(true);
+ do_test_htlc_timeout(false);
+}
+
+fn do_test_holding_cell_htlc_add_timeouts(forwarded_htlc: bool) {
+ // Tests that HTLCs in the holding cell are timed out after the requisite number of blocks.
+ let chanmon_cfgs = create_chanmon_cfgs(3);
+ let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
+ let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
+ create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
+ create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known());
+
+ // Route a first payment to get the 1 -> 2 channel in awaiting_raa...
+ let route = nodes[1].router.get_route(&nodes[2].node.get_our_node_id(), None, &Vec::new(), 100000, TEST_FINAL_CLTV).unwrap();
+ let (_, first_payment_hash) = get_payment_preimage_hash!(nodes[0]);
+ nodes[1].node.send_payment(&route, first_payment_hash, &None).unwrap();
+ assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);
+ check_added_monitors!(nodes[1], 1);
+
+ // Now attempt to route a second payment, which should be placed in the holding cell
+ let (_, second_payment_hash) = get_payment_preimage_hash!(nodes[0]);
+ if forwarded_htlc {
+ let route = nodes[0].router.get_route(&nodes[2].node.get_our_node_id(), None, &Vec::new(), 100000, TEST_FINAL_CLTV).unwrap();
+ nodes[0].node.send_payment(&route, second_payment_hash, &None).unwrap();
+ check_added_monitors!(nodes[0], 1);
+ let payment_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0));
+ nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
+ commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
+ expect_pending_htlcs_forwardable!(nodes[1]);
+ check_added_monitors!(nodes[1], 0);
+ } else {
+ nodes[1].node.send_payment(&route, second_payment_hash, &None).unwrap();
+ check_added_monitors!(nodes[1], 0);