Add find_route test util
authorValentine Wallace <vwallace@protonmail.com>
Sun, 22 Oct 2023 23:05:02 +0000 (18:05 -0500)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 12 Dec 2023 23:38:59 +0000 (18:38 -0500)
And use it in the multihop blinded path receive failure test. Will be used in
the next commit to test receiving an invalid blinded final onion payload.

We can't use the existing get_route test util here because blinded payments
rely on the sender adding a random shadow CLTV offset to the final hop; without
this the payment will be failed with cltv-expiry-too-soon.

lightning/src/ln/blinded_payment_tests.rs
lightning/src/ln/functional_test_utils.rs

index c14c75a5e02a56244c7fcebd5a51252b1916a714..c8b835debaf7fd426f6ea8710580e89c2cb0e406 100644 (file)
@@ -474,6 +474,8 @@ fn multi_hop_receiver_fail() {
                nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&chan_upd_1_2],
                &chanmon_cfgs[2].keys_manager);
 
+       let route = find_route(&nodes[0], &route_params).unwrap();
+       node_cfgs[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
        nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
        check_added_monitors(&nodes[0], 1);
        pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], amt_msat, payment_hash, payment_secret);
index d3d2e3322cafb79f58573d6e18aa7deb84672709..5828ca8038ca241a8d8c6d96464cbe3555bfc1ef 100644 (file)
@@ -1971,6 +1971,18 @@ pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Rou
        )
 }
 
+/// Like `get_route` above, but adds a random CLTV offset to the final hop.
+pub fn find_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, msgs::LightningError> {
+       let scorer = TestScorer::new();
+       let keys_manager = TestKeysInterface::new(&[0u8; 32], bitcoin::network::constants::Network::Testnet);
+       let random_seed_bytes = keys_manager.get_secure_random_bytes();
+       router::find_route(
+               &send_node.node.get_our_node_id(), route_params, &send_node.network_graph,
+               Some(&send_node.node.list_usable_channels().iter().collect::<Vec<_>>()),
+               send_node.logger, &scorer, &Default::default(), &random_seed_bytes
+       )
+}
+
 /// Gets a route from the given sender to the node described in `payment_params`.
 ///
 /// Don't use this, use the identically-named function instead.