Skip to content

Commit b97d742

Browse files
committed
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`.
1 parent 4624caf commit b97d742

File tree

4 files changed

+58
-36
lines changed

4 files changed

+58
-36
lines changed

lightning-types/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ extern crate alloc;
2424
extern crate core;
2525

2626
pub mod payment;
27+
pub mod routing;

lightning-types/src/routing.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
//! Various types which describe routes or information about partial routes within the lightning
11+
//! network.
12+
13+
use alloc::vec::Vec;
14+
15+
use bitcoin::secp256k1::PublicKey;
16+
17+
/// Fees for routing via a given channel or a node
18+
#[derive(Eq, PartialEq, Copy, Clone, Debug, Hash, Ord, PartialOrd)]
19+
pub struct RoutingFees {
20+
/// Flat routing fee in millisatoshis.
21+
pub base_msat: u32,
22+
/// Liquidity-based routing fee in millionths of a routed amount.
23+
/// In other words, 10000 is 1%.
24+
pub proportional_millionths: u32,
25+
}
26+
27+
/// A list of hops along a payment path terminating with a channel to the recipient.
28+
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
29+
pub struct RouteHint(pub Vec<RouteHintHop>);
30+
31+
/// A channel descriptor for a hop along a payment path.
32+
///
33+
/// While this generally comes from BOLT 11's `r` field, this struct includes more fields than are
34+
/// available in BOLT 11. Thus, encoding and decoding this via `lightning-invoice` is lossy, as
35+
/// fields not supported in BOLT 11 will be stripped.
36+
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
37+
pub struct RouteHintHop {
38+
/// The node_id of the non-target end of the route
39+
pub src_node_id: PublicKey,
40+
/// The short_channel_id of this channel
41+
pub short_channel_id: u64,
42+
/// The fees which must be paid to use this channel
43+
pub fees: RoutingFees,
44+
/// The difference in CLTV values between this node and the next node.
45+
pub cltv_expiry_delta: u16,
46+
/// The minimum value, in msat, which must be relayed to the next hop.
47+
pub htlc_minimum_msat: Option<u64>,
48+
/// The maximum value in msat available for routing with a single HTLC.
49+
pub htlc_maximum_msat: Option<u64>,
50+
}

lightning/src/routing/gossip.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ use core::str::FromStr;
4545
use core::sync::atomic::{AtomicUsize, Ordering};
4646
use core::{cmp, fmt};
4747

48+
pub use lightning_types::routing::RoutingFees;
49+
4850
#[cfg(feature = "std")]
4951
use std::time::{SystemTime, UNIX_EPOCH};
5052

@@ -1212,16 +1214,6 @@ impl EffectiveCapacity {
12121214
}
12131215
}
12141216

1215-
/// Fees for routing via a given channel or a node
1216-
#[derive(Eq, PartialEq, Copy, Clone, Debug, Hash, Ord, PartialOrd)]
1217-
pub struct RoutingFees {
1218-
/// Flat routing fee in millisatoshis.
1219-
pub base_msat: u32,
1220-
/// Liquidity-based routing fee in millionths of a routed amount.
1221-
/// In other words, 10000 is 1%.
1222-
pub proportional_millionths: u32,
1223-
}
1224-
12251217
impl_writeable_tlv_based!(RoutingFees, {
12261218
(0, base_msat, required),
12271219
(2, proportional_millionths, required)

lightning/src/routing/router.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
2222
use crate::ln::onion_utils;
2323
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice};
2424
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath};
25-
use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
25+
use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId};
2626
use crate::routing::scoring::{ChannelUsage, LockableScore, ScoreLookUp};
2727
use crate::sign::EntropySource;
2828
use crate::util::ser::{Writeable, Readable, ReadableArgs, Writer};
@@ -35,6 +35,10 @@ use alloc::collections::BinaryHeap;
3535
use core::{cmp, fmt};
3636
use core::ops::Deref;
3737

38+
use lightning_types::routing::RoutingFees;
39+
40+
pub use lightning_types::routing::{RouteHint, RouteHintHop};
41+
3842
/// A [`Router`] implemented using [`find_route`].
3943
///
4044
/// # Privacy
@@ -1099,10 +1103,6 @@ impl ReadableArgs<bool> for Features {
10991103
}
11001104
}
11011105

1102-
/// A list of hops along a payment path terminating with a channel to the recipient.
1103-
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
1104-
pub struct RouteHint(pub Vec<RouteHintHop>);
1105-
11061106
impl Writeable for RouteHint {
11071107
fn write<W: crate::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
11081108
(self.0.len() as u64).write(writer)?;
@@ -1124,27 +1124,6 @@ impl Readable for RouteHint {
11241124
}
11251125
}
11261126

1127-
/// A channel descriptor for a hop along a payment path.
1128-
///
1129-
/// While this generally comes from BOLT 11's `r` field, this struct includes more fields than are
1130-
/// available in BOLT 11. Thus, encoding and decoding this via `lightning-invoice` is lossy, as
1131-
/// fields not supported in BOLT 11 will be stripped.
1132-
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
1133-
pub struct RouteHintHop {
1134-
/// The node_id of the non-target end of the route
1135-
pub src_node_id: PublicKey,
1136-
/// The short_channel_id of this channel
1137-
pub short_channel_id: u64,
1138-
/// The fees which must be paid to use this channel
1139-
pub fees: RoutingFees,
1140-
/// The difference in CLTV values between this node and the next node.
1141-
pub cltv_expiry_delta: u16,
1142-
/// The minimum value, in msat, which must be relayed to the next hop.
1143-
pub htlc_minimum_msat: Option<u64>,
1144-
/// The maximum value in msat available for routing with a single HTLC.
1145-
pub htlc_maximum_msat: Option<u64>,
1146-
}
1147-
11481127
impl_writeable_tlv_based!(RouteHintHop, {
11491128
(0, src_node_id, required),
11501129
(1, htlc_minimum_msat, option),

0 commit comments

Comments
 (0)