Rename RouteHint to RouteHintHop (which is more accurate)
authorValentine Wallace <vwallace@protonmail.com>
Mon, 19 Apr 2021 22:12:51 +0000 (18:12 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 20 Apr 2021 20:26:56 +0000 (16:26 -0400)
fuzz/src/router.rs
lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs
lightning/src/routing/router.rs

index fb720c9916c2d7b38ee653df9fea675f3f8ea23f..e80e080f31786bc76b40b10bc9b6fb96d27c8e2a 100644 (file)
@@ -15,7 +15,7 @@ use lightning::chain;
 use lightning::ln::channelmanager::ChannelDetails;
 use lightning::ln::features::InitFeatures;
 use lightning::ln::msgs;
-use lightning::routing::router::{get_route, RouteHint};
+use lightning::routing::router::{get_route, RouteHintHop};
 use lightning::util::logger::Logger;
 use lightning::util::ser::Readable;
 use lightning::routing::network_graph::{NetworkGraph, RoutingFees};
@@ -224,7 +224,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                        for _ in 0..count {
                                                scid += 1;
                                                let rnid = node_pks.iter().skip(slice_to_be16(get_slice!(2))as usize % node_pks.len()).next().unwrap();
-                                               last_hops_vec.push(RouteHint {
+                                               last_hops_vec.push(RouteHintHop {
                                                        src_node_id: *rnid,
                                                        short_channel_id: scid,
                                                        fees: RoutingFees {
index df92cacd2a47e64c824fc3ce2b7cab87265d1c48..17bbaf44d8f399cf1bce2dd7a362538451bf77fa 100644 (file)
@@ -11,7 +11,7 @@ use bech32::{u5, FromBase32};
 use bitcoin_hashes::Hash;
 use bitcoin_hashes::sha256;
 use lightning::routing::network_graph::RoutingFees;
-use lightning::routing::router::RouteHint;
+use lightning::routing::router::RouteHintHop;
 
 use num_traits::{CheckedAdd, CheckedMul};
 
@@ -577,7 +577,7 @@ impl FromBase32 for Route {
                        return Err(ParseError::UnexpectedEndOfTaggedFields);
                }
 
-               let mut route_hops = Vec::<RouteHint>::new();
+               let mut route_hops = Vec::<RouteHintHop>::new();
 
                let mut bytes = bytes.as_slice();
                while !bytes.is_empty() {
@@ -587,7 +587,7 @@ impl FromBase32 for Route {
                        let mut channel_id: [u8; 8] = Default::default();
                        channel_id.copy_from_slice(&hop_bytes[33..41]);
 
-                       let hop = RouteHint {
+                       let hop = RouteHintHop {
                                src_node_id: PublicKey::from_slice(&hop_bytes[0..33])?,
                                short_channel_id: parse_int_be(&channel_id, 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
@@ -938,7 +938,7 @@ mod test {
        #[test]
        fn test_parse_route() {
                use lightning::routing::network_graph::RoutingFees;
-               use lightning::routing::router::RouteHint;
+               use lightning::routing::router::RouteHintHop;
                use ::Route;
                use bech32::FromBase32;
                use de::parse_int_be;
@@ -948,8 +948,8 @@ mod test {
                        fqxu92d8lr6fvg0r5gv0heeeqgcrqlnm6jhphu9y00rrhy4grqszsvpcgpy9qqqqqqgqqqqq7qqzq".as_bytes()
                );
 
-               let mut expected = Vec::<RouteHint>::new();
-               expected.push(RouteHint {
+               let mut expected = Vec::<RouteHintHop>::new();
+               expected.push(RouteHintHop {
                        src_node_id: PublicKey::from_slice(
                                &[
                                        0x02u8, 0x9e, 0x03, 0xa9, 0x01, 0xb8, 0x55, 0x34, 0xff, 0x1e, 0x92, 0xc4, 0x3c,
@@ -966,7 +966,7 @@ mod test {
                        htlc_minimum_msat: None,
                        htlc_maximum_msat: None
                });
-               expected.push(RouteHint {
+               expected.push(RouteHintHop {
                        src_node_id: PublicKey::from_slice(
                                &[
                                        0x03u8, 0x9e, 0x03, 0xa9, 0x01, 0xb8, 0x55, 0x34, 0xff, 0x1e, 0x92, 0xc4, 0x3c,
index 8820274c38146d26a8c146518b057652054f7a08..cdb293d1f1f6e41e3d1c9f20f88e95e2d597fbed 100644 (file)
@@ -26,7 +26,7 @@ use bitcoin_hashes::Hash;
 use bitcoin_hashes::sha256;
 #[cfg(any(doc, test))]
 use lightning::routing::network_graph::RoutingFees;
-use lightning::routing::router::RouteHint;
+use lightning::routing::router::RouteHintHop;
 
 use secp256k1::key::PublicKey;
 use secp256k1::{Message, Secp256k1};
@@ -387,7 +387,7 @@ pub struct Signature(pub RecoverableSignature);
 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
 ///
 #[derive(Eq, PartialEq, Debug, Clone)]
-pub struct Route(Vec<RouteHint>);
+pub struct Route(Vec<RouteHintHop>);
 
 /// Tag constants as specified in BOLT11
 #[allow(missing_docs)]
@@ -484,7 +484,7 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
        }
 
        /// Adds a private route.
-       pub fn route(mut self, route: Vec<RouteHint>) -> Self {
+       pub fn route(mut self, route: Vec<RouteHintHop>) -> Self {
                match Route::new(route) {
                        Ok(r) => self.tagged_fields.push(TaggedField::Route(r)),
                        Err(e) => self.error = Some(e),
@@ -1144,7 +1144,7 @@ impl ExpiryTime {
 
 impl Route {
        /// Create a new (partial) route from a list of hops
-       pub fn new(hops: Vec<RouteHint>) -> Result<Route, CreationError> {
+       pub fn new(hops: Vec<RouteHintHop>) -> Result<Route, CreationError> {
                if hops.len() <= 12 {
                        Ok(Route(hops))
                } else {
@@ -1153,21 +1153,21 @@ impl Route {
        }
 
        /// Returrn the underlying vector of hops
-       pub fn into_inner(self) -> Vec<RouteHint> {
+       pub fn into_inner(self) -> Vec<RouteHintHop> {
                self.0
        }
 }
 
-impl Into<Vec<RouteHint>> for Route {
-       fn into(self) -> Vec<RouteHint> {
+impl Into<Vec<RouteHintHop>> for Route {
+       fn into(self) -> Vec<RouteHintHop> {
                self.into_inner()
        }
 }
 
 impl Deref for Route {
-       type Target = Vec<RouteHint>;
+       type Target = Vec<RouteHintHop>;
 
-       fn deref(&self) -> &Vec<RouteHint> {
+       fn deref(&self) -> &Vec<RouteHintHop> {
                &self.0
        }
 }
@@ -1443,7 +1443,7 @@ mod test {
                        .build_raw();
                assert_eq!(long_desc_res, Err(CreationError::DescriptionTooLong));
 
-               let route_hop = RouteHint {
+               let route_hop = RouteHintHop {
                        src_node_id: PublicKey::from_slice(
                                        &[
                                                0x03, 0x9e, 0x03, 0xa9, 0x01, 0xb8, 0x55, 0x34, 0xff, 0x1e, 0x92, 0xc4,
@@ -1494,7 +1494,7 @@ mod test {
                let public_key = PublicKey::from_secret_key(&secp_ctx, &private_key);
 
                let route_1 = vec![
-                       RouteHint {
+                       RouteHintHop {
                                src_node_id: public_key.clone(),
                                short_channel_id: de::parse_int_be(&[123; 8], 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
@@ -1505,7 +1505,7 @@ mod test {
                                htlc_minimum_msat: None,
                                htlc_maximum_msat: None,
                        },
-                       RouteHint {
+                       RouteHintHop {
                                src_node_id: public_key.clone(),
                                short_channel_id: de::parse_int_be(&[42; 8], 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
@@ -1519,7 +1519,7 @@ mod test {
                ];
 
                let route_2 = vec![
-                       RouteHint {
+                       RouteHintHop {
                                src_node_id: public_key.clone(),
                                short_channel_id: 0,
                                fees: RoutingFees {
@@ -1530,7 +1530,7 @@ mod test {
                                htlc_minimum_msat: None,
                                htlc_maximum_msat: None,
                        },
-                       RouteHint {
+                       RouteHintHop {
                                src_node_id: public_key.clone(),
                                short_channel_id: de::parse_int_be(&[1; 8], 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
index 20028d217ef867ccdee175f0c68b53d01d05fa59..08fe95d2305293e7440a04bc407a4110b87c3901 100644 (file)
@@ -118,7 +118,7 @@ impl Readable for Route {
 
 /// A channel descriptor which provides a last-hop route to get_route
 #[derive(Eq, PartialEq, Debug, Clone)]
-pub struct RouteHint {
+pub struct RouteHintHop {
        /// The node_id of the non-target end of the route
        pub src_node_id: PublicKey,
        /// The short_channel_id of this channel
@@ -176,7 +176,7 @@ struct DummyDirectionalChannelInfo {
 /// These fee values are useful to choose hops as we traverse the graph "payee-to-payer".
 #[derive(Clone)]
 struct PathBuildingHop<'a> {
-       // The RouteHint fields which will eventually be used if this hop is used in a final Route.
+       // The RouteHintHop fields which will eventually be used if this hop is used in a final Route.
        // Note that node_features is calculated separately after our initial graph walk.
        pubkey: PublicKey,
        short_channel_id: u64,
@@ -353,7 +353,7 @@ fn compute_fees(amount_msat: u64, channel_fees: RoutingFees) -> Option<u64> {
 /// equal), however the enabled/disabled bit on such channels as well as the
 /// htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node.
 pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, payee: &PublicKey, payee_features: Option<InvoiceFeatures>, first_hops: Option<&[&ChannelDetails]>,
-       last_hops: &[&RouteHint], final_value_msat: u64, final_cltv: u32, logger: L) -> Result<Route, LightningError> where L::Target: Logger {
+       last_hops: &[&RouteHintHop], final_value_msat: u64, final_cltv: u32, logger: L) -> Result<Route, LightningError> where L::Target: Logger {
        // TODO: Obviously *only* using total fee cost sucks. We should consider weighting by
        // uptime/success in using a node in the past.
        if *payee == *our_node_id {
@@ -1163,7 +1163,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
 
 #[cfg(test)]
 mod tests {
-       use routing::router::{get_route, RouteHint, RoutingFees};
+       use routing::router::{get_route, RouteHintHop, RoutingFees};
        use routing::network_graph::{NetworkGraph, NetGraphMsgHandler};
        use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};
        use ln::msgs::{ErrorAction, LightningError, OptionalField, UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingMessageHandler,
@@ -2084,19 +2084,19 @@ mod tests {
                assert_eq!(route.paths[0][1].channel_features.le_flags(), &id_to_feature_flags(13));
        }
 
-       fn last_hops(nodes: &Vec<PublicKey>) -> Vec<RouteHint> {
+       fn last_hops(nodes: &Vec<PublicKey>) -> Vec<RouteHintHop> {
                let zero_fees = RoutingFees {
                        base_msat: 0,
                        proportional_millionths: 0,
                };
-               vec!(RouteHint {
+               vec!(RouteHintHop {
                        src_node_id: nodes[3].clone(),
                        short_channel_id: 8,
                        fees: zero_fees,
                        cltv_expiry_delta: (8 << 8) | 1,
                        htlc_minimum_msat: None,
                        htlc_maximum_msat: None,
-               }, RouteHint {
+               }, RouteHintHop {
                        src_node_id: nodes[4].clone(),
                        short_channel_id: 9,
                        fees: RoutingFees {
@@ -2106,7 +2106,7 @@ mod tests {
                        cltv_expiry_delta: (9 << 8) | 1,
                        htlc_minimum_msat: None,
                        htlc_maximum_msat: None,
-               }, RouteHint {
+               }, RouteHintHop {
                        src_node_id: nodes[5].clone(),
                        short_channel_id: 10,
                        fees: zero_fees,
@@ -2124,7 +2124,7 @@ mod tests {
                // Simple test across 2, 3, 5, and 4 via a last_hop channel
 
                // First check that lst hop can't have its source as the payee.
-               let invalid_last_hop = RouteHint {
+               let invalid_last_hop = RouteHintHop {
                        src_node_id: nodes[6],
                        short_channel_id: 8,
                        fees: RoutingFees {
@@ -2309,7 +2309,7 @@ mod tests {
                let target_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&hex::decode(format!("{:02}", 43).repeat(32)).unwrap()[..]).unwrap());
 
                // If we specify a channel to a middle hop, that overrides our local channel view and that gets used
-               let last_hops = vec![RouteHint {
+               let last_hops = vec![RouteHintHop {
                        src_node_id: middle_node_id,
                        short_channel_id: 8,
                        fees: RoutingFees {