]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Move `Rout{ingFees,eHint{,Hop}}` to `lightning-types`
authorMatt Corallo <git@bluematt.me>
Fri, 9 Aug 2024 00:29:25 +0000 (00:29 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 13 Aug 2024 12:54:59 +0000 (12:54 +0000)
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This takes one more step, moving the routing types
`lightning-invoice` uses into `lightning-types`.

lightning-types/src/lib.rs
lightning-types/src/routing.rs [new file with mode: 0644]
lightning/src/routing/gossip.rs
lightning/src/routing/router.rs

index 0174bcc9b3da2b6f1f069dc6590e987e5c663f8c..aa21ec7cd592b8891933e888aabae5d8246f4bcd 100644 (file)
@@ -24,3 +24,4 @@ extern crate alloc;
 extern crate core;
 
 pub mod payment;
+pub mod routing;
diff --git a/lightning-types/src/routing.rs b/lightning-types/src/routing.rs
new file mode 100644 (file)
index 0000000..2335af2
--- /dev/null
@@ -0,0 +1,50 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+//! Various types which describe routes or information about partial routes within the lightning
+//! network.
+
+use alloc::vec::Vec;
+
+use bitcoin::secp256k1::PublicKey;
+
+/// Fees for routing via a given channel or a node
+#[derive(Eq, PartialEq, Copy, Clone, Debug, Hash, Ord, PartialOrd)]
+pub struct RoutingFees {
+       /// Flat routing fee in millisatoshis.
+       pub base_msat: u32,
+       /// Liquidity-based routing fee in millionths of a routed amount.
+       /// In other words, 10000 is 1%.
+       pub proportional_millionths: u32,
+}
+
+/// A list of hops along a payment path terminating with a channel to the recipient.
+#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
+pub struct RouteHint(pub Vec<RouteHintHop>);
+
+/// A channel descriptor for a hop along a payment path.
+///
+/// While this generally comes from BOLT 11's `r` field, this struct includes more fields than are
+/// available in BOLT 11. Thus, encoding and decoding this via `lightning-invoice` is lossy, as
+/// fields not supported in BOLT 11 will be stripped.
+#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
+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
+       pub short_channel_id: u64,
+       /// The fees which must be paid to use this channel
+       pub fees: RoutingFees,
+       /// The difference in CLTV values between this node and the next node.
+       pub cltv_expiry_delta: u16,
+       /// The minimum value, in msat, which must be relayed to the next hop.
+       pub htlc_minimum_msat: Option<u64>,
+       /// The maximum value in msat available for routing with a single HTLC.
+       pub htlc_maximum_msat: Option<u64>,
+}
index 31f93db905c90b316bb8835af9346f4ea2e794b0..22a3f6e79800e8d446c160cbe83b401d1813afb9 100644 (file)
@@ -45,6 +45,8 @@ use core::str::FromStr;
 use core::sync::atomic::{AtomicUsize, Ordering};
 use core::{cmp, fmt};
 
+pub use lightning_types::routing::RoutingFees;
+
 #[cfg(feature = "std")]
 use std::time::{SystemTime, UNIX_EPOCH};
 
@@ -1212,16 +1214,6 @@ impl EffectiveCapacity {
        }
 }
 
-/// Fees for routing via a given channel or a node
-#[derive(Eq, PartialEq, Copy, Clone, Debug, Hash, Ord, PartialOrd)]
-pub struct RoutingFees {
-       /// Flat routing fee in millisatoshis.
-       pub base_msat: u32,
-       /// Liquidity-based routing fee in millionths of a routed amount.
-       /// In other words, 10000 is 1%.
-       pub proportional_millionths: u32,
-}
-
 impl_writeable_tlv_based!(RoutingFees, {
        (0, base_msat, required),
        (2, proportional_millionths, required)
index dac9ada3800b2c21a22a4563cb025f542a249c86..bf894f0ebb6de49fdae6a62b8078b5644ac36e75 100644 (file)
@@ -22,7 +22,7 @@ use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
 use crate::ln::onion_utils;
 use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice};
 use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath};
-use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
+use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId};
 use crate::routing::scoring::{ChannelUsage, LockableScore, ScoreLookUp};
 use crate::sign::EntropySource;
 use crate::util::ser::{Writeable, Readable, ReadableArgs, Writer};
@@ -35,6 +35,10 @@ use alloc::collections::BinaryHeap;
 use core::{cmp, fmt};
 use core::ops::Deref;
 
+use lightning_types::routing::RoutingFees;
+
+pub use lightning_types::routing::{RouteHint, RouteHintHop};
+
 /// A [`Router`] implemented using [`find_route`].
 ///
 /// # Privacy
@@ -1099,10 +1103,6 @@ impl ReadableArgs<bool> for Features {
        }
 }
 
-/// A list of hops along a payment path terminating with a channel to the recipient.
-#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
-pub struct RouteHint(pub Vec<RouteHintHop>);
-
 impl Writeable for RouteHint {
        fn write<W: crate::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                (self.0.len() as u64).write(writer)?;
@@ -1124,27 +1124,6 @@ impl Readable for RouteHint {
        }
 }
 
-/// A channel descriptor for a hop along a payment path.
-///
-/// While this generally comes from BOLT 11's `r` field, this struct includes more fields than are
-/// available in BOLT 11. Thus, encoding and decoding this via `lightning-invoice` is lossy, as
-/// fields not supported in BOLT 11 will be stripped.
-#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
-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
-       pub short_channel_id: u64,
-       /// The fees which must be paid to use this channel
-       pub fees: RoutingFees,
-       /// The difference in CLTV values between this node and the next node.
-       pub cltv_expiry_delta: u16,
-       /// The minimum value, in msat, which must be relayed to the next hop.
-       pub htlc_minimum_msat: Option<u64>,
-       /// The maximum value in msat available for routing with a single HTLC.
-       pub htlc_maximum_msat: Option<u64>,
-}
-
 impl_writeable_tlv_based!(RouteHintHop, {
        (0, src_node_id, required),
        (1, htlc_minimum_msat, option),