From: Matt Corallo Date: Fri, 9 Aug 2024 00:29:25 +0000 (+0000) Subject: Move `Rout{ingFees,eHint{,Hop}}` to `lightning-types` X-Git-Tag: v0.0.124-beta~14^2~9 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=b97d742f91fdb9cee8ecccb10f1fef3edb5c4600;p=rust-lightning Move `Rout{ingFees,eHint{,Hop}}` to `lightning-types` `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`. --- diff --git a/lightning-types/src/lib.rs b/lightning-types/src/lib.rs index 0174bcc9b..aa21ec7cd 100644 --- a/lightning-types/src/lib.rs +++ b/lightning-types/src/lib.rs @@ -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 index 000000000..2335af2f1 --- /dev/null +++ b/lightning-types/src/routing.rs @@ -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 or the MIT license +// , 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); + +/// 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, + /// The maximum value in msat available for routing with a single HTLC. + pub htlc_maximum_msat: Option, +} diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 31f93db90..22a3f6e79 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -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) diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index dac9ada38..bf894f0eb 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -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 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); - impl Writeable for RouteHint { fn write(&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, - /// The maximum value in msat available for routing with a single HTLC. - pub htlc_maximum_msat: Option, -} - impl_writeable_tlv_based!(RouteHintHop, { (0, src_node_id, required), (1, htlc_minimum_msat, option),