Skip to content

Commit 3a8bf89

Browse files
committed
Test we consider route hints if we are the src of the first hop
Previously, we would only consider route hints if the entry point was in our first hops or in the network graph. We fixed this by also considering hints if our own node ID was the first src. Here, we add test coverage for this behavior.
1 parent 154cd3c commit 3a8bf89

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

lightning/src/routing/router.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7841,6 +7841,57 @@ mod tests {
78417841
assert_eq!(route.paths[0].hops[1].short_channel_id, 45);
78427842
assert_eq!(route.get_total_fees(), 123);
78437843
}
7844+
7845+
#[test]
7846+
fn allow_us_being_first_hint() {
7847+
// Check that we consider a route hint even if we are the src of the first hop.
7848+
let secp_ctx = Secp256k1::new();
7849+
let logger = Arc::new(ln_test_utils::TestLogger::new());
7850+
let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, Arc::clone(&logger)));
7851+
let scorer = ln_test_utils::TestScorer::new();
7852+
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
7853+
let random_seed_bytes = keys_manager.get_secure_random_bytes();
7854+
let config = UserConfig::default();
7855+
7856+
let (_, our_node_id, _, nodes) = get_nodes(&secp_ctx);
7857+
7858+
let amt_msat = 1_000_000;
7859+
let dest_node_id = nodes[1];
7860+
7861+
let first_hop = get_channel_details(Some(1), nodes[0], channelmanager::provided_init_features(&config), 10_000_000);
7862+
let first_hops = vec![first_hop];
7863+
7864+
let route_hint = RouteHint(vec![RouteHintHop {
7865+
src_node_id: our_node_id,
7866+
short_channel_id: 44,
7867+
fees: RoutingFees {
7868+
base_msat: 123,
7869+
proportional_millionths: 0,
7870+
},
7871+
cltv_expiry_delta: 10,
7872+
htlc_minimum_msat: None,
7873+
htlc_maximum_msat: None,
7874+
}]);
7875+
7876+
let payment_params = PaymentParameters::from_node_id(dest_node_id, 42)
7877+
.with_route_hints(vec![route_hint]).unwrap()
7878+
.with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
7879+
7880+
let route_params = RouteParameters::from_payment_params_and_value(
7881+
payment_params, amt_msat);
7882+
7883+
7884+
let route = get_route(&our_node_id, &route_params, &network_graph.read_only(),
7885+
Some(&first_hops.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
7886+
&Default::default(), &random_seed_bytes).unwrap();
7887+
7888+
assert_eq!(route.paths.len(), 1);
7889+
assert_eq!(route.get_total_amount(), amt_msat);
7890+
assert_eq!(route.get_total_fees(), 0);
7891+
assert_eq!(route.paths[0].hops.len(), 1);
7892+
7893+
assert_eq!(route.paths[0].hops[0].short_channel_id, 44);
7894+
}
78447895
}
78457896

78467897
#[cfg(all(any(test, ldk_bench), not(feature = "no-std")))]

0 commit comments

Comments
 (0)