-pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], skip_last: bool, our_payment_hash: PaymentHash) {
- assert!(expected_route.last().unwrap().node.fail_htlc_backwards(&our_payment_hash));
- expect_pending_htlcs_forwardable!(expected_route.last().unwrap());
- check_added_monitors!(expected_route.last().unwrap(), 1);
+pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths_slice: &[&[&Node<'a, 'b, 'c>]], skip_last: bool, our_payment_hash: PaymentHash) {
+ let mut expected_paths: Vec<_> = expected_paths_slice.iter().collect();
+ for path in expected_paths.iter() {
+ assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
+ }
+ assert!(expected_paths[0].last().unwrap().node.fail_htlc_backwards(&our_payment_hash));
+ expect_pending_htlcs_forwardable!(expected_paths[0].last().unwrap());
+ check_added_monitors!(expected_paths[0].last().unwrap(), expected_paths.len());
+
+ let mut per_path_msgs: Vec<((msgs::UpdateFailHTLC, msgs::CommitmentSigned), PublicKey)> = Vec::with_capacity(expected_paths.len());
+ let events = expected_paths[0].last().unwrap().node.get_and_clear_pending_msg_events();
+ assert_eq!(events.len(), expected_paths.len());
+ for ev in events.iter() {
+ let (update_fail, commitment_signed, node_id) = match ev {
+ &MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => {
+ assert!(update_add_htlcs.is_empty());
+ assert!(update_fulfill_htlcs.is_empty());
+ assert_eq!(update_fail_htlcs.len(), 1);
+ assert!(update_fail_malformed_htlcs.is_empty());
+ assert!(update_fee.is_none());
+ (update_fail_htlcs[0].clone(), commitment_signed.clone(), node_id.clone())
+ },
+ _ => panic!("Unexpected event"),
+ };
+ per_path_msgs.push(((update_fail, commitment_signed), node_id));
+ }
+ per_path_msgs.sort_unstable_by(|(_, node_id_a), (_, node_id_b)| node_id_a.cmp(node_id_b));
+ expected_paths.sort_unstable_by(|path_a, path_b| path_a[path_a.len() - 2].node.get_our_node_id().cmp(&path_b[path_b.len() - 2].node.get_our_node_id()));
+
+ for (i, (expected_route, (path_msgs, next_hop))) in expected_paths.iter().zip(per_path_msgs.drain(..)).enumerate() {
+ let mut next_msgs = Some(path_msgs);
+ let mut expected_next_node = next_hop;
+ let mut prev_node = expected_route.last().unwrap();