Skip to content

Commit a25ce5c

Browse files
committed
Replace get_route with get_route_and_payment_hash
The interface for get_route will change to take a scorer. Using get_route_and_payment_hash whenever possible allows for keeping the scorer inside get_route_and_payment_hash rather than at every call site. Replace get_route_and_payment_hash with get_route wherever possible. Additionally, update get_route_and_payment_hash to use the sending node's logger and useable channels.
1 parent fea8b04 commit a25ce5c

File tree

7 files changed

+213
-371
lines changed

7 files changed

+213
-371
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 47 additions & 91 deletions
Large diffs are not rendered by default.

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5744,12 +5744,10 @@ mod tests {
57445744
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
57455745
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
57465746
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
5747-
let logger = test_utils::TestLogger::new();
57485747

57495748
// First, send a partial MPP payment.
5750-
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
5751-
let route = get_route(&nodes[0].node.get_our_node_id(), &net_graph_msg_handler.network_graph, &nodes[1].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 100_000, TEST_FINAL_CLTV, &logger).unwrap();
5752-
let (payment_preimage, our_payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[1]);
5749+
let (route, our_payment_hash, payment_preimage, payment_secret) =
5750+
get_route_and_payment_hash!(&nodes[0], nodes[1], 100_000);
57535751
let mpp_id = MppId([42; 32]);
57545752
// Use the utility function send_payment_along_path to send the payment with MPP data which
57555753
// indicates there are more HTLCs coming.
@@ -6001,12 +5999,10 @@ mod tests {
60015999
let chan_2_id = create_announced_chan_between_nodes(&nodes, 0, 2, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
60026000
let chan_3_id = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
60036001
let chan_4_id = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
6004-
let logger = test_utils::TestLogger::new();
60056002

60066003
// Marshall an MPP route.
6007-
let (_, payment_hash, _) = get_payment_preimage_hash!(&nodes[3]);
6008-
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
6009-
let mut route = get_route(&nodes[0].node.get_our_node_id(), &net_graph_msg_handler.network_graph, &nodes[3].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &[], 100000, TEST_FINAL_CLTV, &logger).unwrap();
6004+
let (mut route, payment_hash, _, _) =
6005+
get_route_and_payment_hash!(&nodes[0], nodes[3], 100000);
60106006
let path = route.paths[0].clone();
60116007
route.paths.push(path);
60126008
route.paths[0][0].pubkey = nodes[1].node.get_our_node_id();

lightning/src/ln/functional_test_utils.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,16 @@ macro_rules! commitment_signed_dance {
964964
#[macro_export]
965965
macro_rules! get_payment_preimage_hash {
966966
($dest_node: expr) => {
967+
{
968+
get_payment_preimage_hash!($dest_node, None)
969+
}
970+
};
971+
($dest_node: expr, $min_value_msat: expr) => {
967972
{
968973
let payment_preimage = PaymentPreimage([*$dest_node.network_payment_count.borrow(); 32]);
969974
*$dest_node.network_payment_count.borrow_mut() += 1;
970975
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
971-
let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, None, 7200, 0).unwrap();
976+
let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200, 0).unwrap();
972977
(payment_preimage, payment_hash, payment_secret)
973978
}
974979
}
@@ -977,11 +982,17 @@ macro_rules! get_payment_preimage_hash {
977982
#[cfg(test)]
978983
macro_rules! get_route_and_payment_hash {
979984
($send_node: expr, $recv_node: expr, $recv_value: expr) => {{
980-
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!($recv_node);
985+
get_route_and_payment_hash!($send_node, $recv_node, vec![], $recv_value, TEST_FINAL_CLTV)
986+
}};
987+
($send_node: expr, $recv_node: expr, $last_hops: expr, $recv_value: expr, $cltv: expr) => {{
988+
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!($recv_node, Some($recv_value));
981989
let net_graph_msg_handler = &$send_node.net_graph_msg_handler;
982-
let route = get_route(&$send_node.node.get_our_node_id(),
983-
&net_graph_msg_handler.network_graph,
984-
&$recv_node.node.get_our_node_id(), None, None, &Vec::new(), $recv_value, TEST_FINAL_CLTV, $send_node.logger).unwrap();
990+
let route = ::routing::router::get_route(
991+
&$send_node.node.get_our_node_id(), &net_graph_msg_handler.network_graph,
992+
&$recv_node.node.get_our_node_id(), Some(::ln::features::InvoiceFeatures::known()),
993+
Some(&$send_node.node.list_usable_channels().iter().collect::<Vec<_>>()),
994+
&$last_hops, $recv_value, $cltv, $send_node.logger
995+
).unwrap();
985996
(route, payment_hash, payment_preimage, payment_secret)
986997
}}
987998
}

0 commit comments

Comments
 (0)