origin_node: &Node<'a, 'b, 'c>, expected_paths: &[&[&Node<'a, 'b, 'c>]], skip_last: bool,
our_payment_preimage: PaymentPreimage
) -> u64 {
- let extra_fees = vec![0; expected_paths.len()];
- do_claim_payment_along_route_with_extra_penultimate_hop_fees(origin_node, expected_paths,
- &extra_fees[..], skip_last, our_payment_preimage)
-}
-
-pub fn do_claim_payment_along_route_with_extra_penultimate_hop_fees<'a, 'b, 'c>(
- origin_node: &Node<'a, 'b, 'c>, expected_paths: &[&[&Node<'a, 'b, 'c>]], expected_extra_fees:
- &[u32], skip_last: bool, our_payment_preimage: PaymentPreimage
-) -> u64 {
- assert_eq!(expected_paths.len(), expected_extra_fees.len());
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());
}
expected_paths[0].last().unwrap().node.claim_funds(our_payment_preimage);
- pass_claimed_payment_along_route(origin_node, expected_paths, expected_extra_fees, skip_last, our_payment_preimage)
+ pass_claimed_payment_along_route(
+ ClaimAlongRouteArgs::new(origin_node, expected_paths, our_payment_preimage)
+ .skip_last(skip_last)
+ )
+}
+
+pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
+ pub origin_node: &'a Node<'b, 'c, 'd>,
+ pub expected_paths: &'a [&'a [&'a Node<'b, 'c, 'd>]],
+ pub expected_extra_fees: Vec<u32>,
+ pub skip_last: bool,
+ pub payment_preimage: PaymentPreimage,
+}
+
+impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
+ pub fn new(
+ origin_node: &'a Node<'b, 'c, 'd>, expected_paths: &'a [&'a [&'a Node<'b, 'c, 'd>]],
+ payment_preimage: PaymentPreimage,
+ ) -> Self {
+ Self {
+ origin_node, expected_paths, expected_extra_fees: vec![0; expected_paths.len()],
+ skip_last: false, payment_preimage,
+ }
+ }
+ pub fn skip_last(mut self, skip_last: bool) -> Self {
+ self.skip_last = skip_last;
+ self
+ }
+ pub fn with_expected_extra_fees(mut self, extra_fees: Vec<u32>) -> Self {
+ self.expected_extra_fees = extra_fees;
+ self
+ }
}
-pub fn pass_claimed_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths: &[&[&Node<'a, 'b, 'c>]], expected_extra_fees: &[u32], skip_last: bool, our_payment_preimage: PaymentPreimage) -> u64 {
+pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArgs) -> u64 {
+ let ClaimAlongRouteArgs {
+ origin_node, expected_paths, expected_extra_fees, skip_last,
+ payment_preimage: our_payment_preimage
+ } = args;
let claim_event = expected_paths[0].last().unwrap().node.get_and_clear_pending_events();
assert_eq!(claim_event.len(), 1);
match claim_event[0] {
// Can't use claim_payment_along_route as it doesn't support overpayment, so we break out the
// individual steps here.
+ nodes[3].node.claim_funds(payment_preimage);
let extra_fees = vec![0, total_overpaid_amount];
- let expected_total_fee_msat = do_claim_payment_along_route_with_extra_penultimate_hop_fees(
- &nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], &extra_fees[..], false,
- payment_preimage);
+ let expected_route = &[&[&nodes[1], &nodes[3]][..], &[&nodes[2], &nodes[3]][..]];
+ let args = ClaimAlongRouteArgs::new(&nodes[0], &expected_route[..], payment_preimage)
+ .with_expected_extra_fees(extra_fees);
+ let expected_total_fee_msat = pass_claimed_payment_along_route(args);
expect_payment_sent!(&nodes[0], payment_preimage, Some(expected_total_fee_msat));
}
let mut expected_paths = Vec::new();
for _ in 0..num_mpp_parts { expected_paths_vecs.push(vec!(&nodes[1], &nodes[2])); }
for i in 0..num_mpp_parts { expected_paths.push(&expected_paths_vecs[i][..]); }
- let total_fee_msat = do_claim_payment_along_route_with_extra_penultimate_hop_fees(
- &nodes[0], &expected_paths[..], &vec![skimmed_fee_msat as u32; num_mpp_parts][..], false,
- payment_preimage);
+ expected_paths[0].last().unwrap().node.claim_funds(payment_preimage);
+ let args = ClaimAlongRouteArgs::new(&nodes[0], &expected_paths[..], payment_preimage)
+ .with_expected_extra_fees(vec![skimmed_fee_msat as u32; num_mpp_parts]);
+ let total_fee_msat = pass_claimed_payment_along_route(args);
// The sender doesn't know that the penultimate hop took an extra fee.
expect_payment_sent(&nodes[0], payment_preimage,
Some(Some(total_fee_msat - skimmed_fee_msat * num_mpp_parts as u64)), true, true);
match (known_tlvs, even_tlvs) {
(true, _) => {
nodes[1].node.claim_funds_with_known_custom_tlvs(our_payment_preimage);
- let expected_total_fee_msat = pass_claimed_payment_along_route(&nodes[0], &[&[&nodes[1]]], &[0; 1], false, our_payment_preimage);
+ let expected_total_fee_msat = pass_claimed_payment_along_route(ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], our_payment_preimage));
expect_payment_sent!(&nodes[0], our_payment_preimage, Some(expected_total_fee_msat));
},
(false, false) => {