From: Valentine Wallace Date: Mon, 19 Apr 2021 22:12:51 +0000 (-0400) Subject: Rename RouteHint to RouteHintHop (which is more accurate) X-Git-Tag: v0.0.14~20^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=ad900658ce4d5fc2b6fd74898c726ceed56d85a7;p=rust-lightning Rename RouteHint to RouteHintHop (which is more accurate) --- diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index fb720c991..e80e080f3 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -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(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 { diff --git a/lightning-invoice/src/de.rs b/lightning-invoice/src/de.rs index df92cacd2..17bbaf44d 100644 --- a/lightning-invoice/src/de.rs +++ b/lightning-invoice/src/de.rs @@ -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::::new(); + let mut route_hops = Vec::::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::::new(); - expected.push(RouteHint { + let mut expected = Vec::::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, diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 8820274c3..cdb293d1f 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -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); +pub struct Route(Vec); /// Tag constants as specified in BOLT11 #[allow(missing_docs)] @@ -484,7 +484,7 @@ impl InvoiceBuilder { } /// Adds a private route. - pub fn route(mut self, route: Vec) -> Self { + pub fn route(mut self, route: Vec) -> 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) -> Result { + pub fn new(hops: Vec) -> Result { 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 { + pub fn into_inner(self) -> Vec { self.0 } } -impl Into> for Route { - fn into(self) -> Vec { +impl Into> for Route { + fn into(self) -> Vec { self.into_inner() } } impl Deref for Route { - type Target = Vec; + type Target = Vec; - fn deref(&self) -> &Vec { + fn deref(&self) -> &Vec { &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 { diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 20028d217..08fe95d23 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -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 { /// 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(our_node_id: &PublicKey, network: &NetworkGraph, payee: &PublicKey, payee_features: Option, first_hops: Option<&[&ChannelDetails]>, - last_hops: &[&RouteHint], final_value_msat: u64, final_cltv: u32, logger: L) -> Result where L::Target: Logger { + last_hops: &[&RouteHintHop], final_value_msat: u64, final_cltv: u32, logger: L) -> Result 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(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) -> Vec { + fn last_hops(nodes: &Vec) -> Vec { 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 {