Skip to content

Commit ed778f7

Browse files
f move InflightHtlcs to router.rs
1 parent 9dc68e8 commit ed778f7

File tree

4 files changed

+42
-43
lines changed

4 files changed

+42
-43
lines changed

lightning-invoice/src/payment.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
//! #
3636
//! # use lightning::io;
3737
//! # use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
38-
//! # use lightning::ln::channelmanager::{ChannelDetails, InFlightHtlcs, PaymentId, PaymentSendFailure};
38+
//! # use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure};
3939
//! # use lightning::ln::msgs::LightningError;
4040
//! # use lightning::routing::gossip::NodeId;
41-
//! # use lightning::routing::router::{Route, RouteHop, RouteParameters};
41+
//! # use lightning::routing::router::{InFlightHtlcs, Route, RouteHop, RouteParameters};
4242
//! # use lightning::routing::scoring::{ChannelUsage, Score};
4343
//! # use lightning::util::events::{Event, EventHandler, EventsProvider};
4444
//! # use lightning::util::logger::{Logger, Record};
@@ -141,10 +141,10 @@ use bitcoin_hashes::sha256::Hash as Sha256;
141141

142142
use crate::prelude::*;
143143
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
144-
use lightning::ln::channelmanager::{ChannelDetails, InFlightHtlcs, PaymentId, PaymentSendFailure};
144+
use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure};
145145
use lightning::ln::msgs::LightningError;
146146
use lightning::routing::gossip::NodeId;
147-
use lightning::routing::router::{PaymentParameters, Route, RouteHop, RouteParameters};
147+
use lightning::routing::router::{InFlightHtlcs, PaymentParameters, Route, RouteHop, RouteParameters};
148148
use lightning::util::errors::APIError;
149149
use lightning::util::events::{Event, EventHandler};
150150
use lightning::util::logger::Logger;
@@ -735,12 +735,12 @@ mod tests {
735735
use crate::utils::{ScorerAccountingForInFlightHtlcs, create_invoice_from_channelmanager_and_duration_since_epoch};
736736
use bitcoin_hashes::sha256::Hash as Sha256;
737737
use lightning::ln::PaymentPreimage;
738-
use lightning::ln::channelmanager::{self, InFlightHtlcs};
738+
use lightning::ln::channelmanager;
739739
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
740740
use lightning::ln::functional_test_utils::*;
741741
use lightning::ln::msgs::{ChannelMessageHandler, ErrorAction, LightningError};
742742
use lightning::routing::gossip::{EffectiveCapacity, NodeId};
743-
use lightning::routing::router::{PaymentParameters, Route, RouteHop};
743+
use lightning::routing::router::{InFlightHtlcs, PaymentParameters, Route, RouteHop};
744744
use lightning::routing::scoring::{ChannelUsage, LockableScore, Score};
745745
use lightning::util::test_utils::TestLogger;
746746
use lightning::util::errors::APIError;

lightning-invoice/src/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use lightning::chain;
1010
use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
1111
use lightning::chain::keysinterface::{Recipient, KeysInterface, Sign};
1212
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
13-
use lightning::ln::channelmanager::{ChannelDetails, ChannelManager, InFlightHtlcs, PaymentId, PaymentSendFailure, MIN_FINAL_CLTV_EXPIRY};
13+
use lightning::ln::channelmanager::{ChannelDetails, ChannelManager, PaymentId, PaymentSendFailure, MIN_FINAL_CLTV_EXPIRY};
1414
#[cfg(feature = "std")]
1515
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_CLTV_EXPIRY_DELTA};
1616
use lightning::ln::inbound_payment::{create, create_from_hash, ExpandedKey};
1717
use lightning::ln::msgs::LightningError;
1818
use lightning::routing::gossip::{NetworkGraph, NodeId, RoutingFees};
19-
use lightning::routing::router::{Route, RouteHint, RouteHintHop, RouteParameters, find_route, RouteHop};
19+
use lightning::routing::router::{InFlightHtlcs, Route, RouteHint, RouteHintHop, RouteParameters, find_route, RouteHop};
2020
use lightning::routing::scoring::{ChannelUsage, LockableScore, Score};
2121
use lightning::util::logger::Logger;
2222
use secp256k1::PublicKey;

lightning/src/ln/channelmanager.rs

-35
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use crate::ln::channel::{Channel, ChannelError, ChannelUpdateStatus, UpdateFulfi
4646
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
4747
#[cfg(any(feature = "_test_utils", test))]
4848
use crate::ln::features::InvoiceFeatures;
49-
use crate::routing::gossip::NodeId;
5049
use crate::routing::router::{PaymentParameters, Route, RouteHop, RoutePath, RouteParameters};
5150
use crate::ln::msgs;
5251
use crate::ln::onion_utils;
@@ -72,40 +71,6 @@ use core::sync::atomic::{AtomicUsize, Ordering};
7271
use core::time::Duration;
7372
use core::ops::Deref;
7473

75-
/// A map with liquidity value (in msat) keyed by a short channel id and the direction the HTLC
76-
/// is traveling in. The direction boolean is determined by checking if the HTLC source's public
77-
/// key is less than its destination. See [`InFlightHtlcs::used_liquidity_msat`] for more
78-
/// details.
79-
#[cfg(not(any(test, feature = "_test_utils")))]
80-
pub struct InFlightHtlcs(HashMap<(u64, bool), u64>);
81-
#[cfg(any(test, feature = "_test_utils"))]
82-
pub struct InFlightHtlcs(pub HashMap<(u64, bool), u64>);
83-
84-
impl InFlightHtlcs {
85-
/// Create a new `InFlightHtlcs` via a mapping from:
86-
/// (short_channel_id, source_pubkey < target_pubkey) -> used_liquidity_msat
87-
pub fn new(inflight_map: HashMap<(u64, bool), u64>) -> Self {
88-
InFlightHtlcs(inflight_map)
89-
}
90-
91-
/// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
92-
/// id.
93-
pub fn used_liquidity_msat(&self, source: &NodeId, target: &NodeId, channel_scid: u64) -> Option<u64> {
94-
self.0.get(&(channel_scid, source < target)).map(|v| *v)
95-
}
96-
}
97-
98-
impl Writeable for InFlightHtlcs {
99-
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> { self.0.write(writer) }
100-
}
101-
102-
impl Readable for InFlightHtlcs {
103-
fn read<R: io::Read>(reader: &mut R) -> Result<Self, msgs::DecodeError> {
104-
let infight_map: HashMap<(u64, bool), u64> = Readable::read(reader)?;
105-
Ok(Self(infight_map))
106-
}
107-
}
108-
10974
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
11075
//
11176
// Upon receipt of an HTLC from a peer, we'll give it a PendingHTLCStatus indicating if it should

lightning/src/routing/router.rs

+34
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,40 @@ use alloc::collections::BinaryHeap;
2929
use core::cmp;
3030
use core::ops::Deref;
3131

32+
/// A map with liquidity value (in msat) keyed by a short channel id and the direction the HTLC
33+
/// is traveling in. The direction boolean is determined by checking if the HTLC source's public
34+
/// key is less than its destination. See [`InFlightHtlcs::used_liquidity_msat`] for more
35+
/// details.
36+
#[cfg(not(any(test, feature = "_test_utils")))]
37+
pub struct InFlightHtlcs(HashMap<(u64, bool), u64>);
38+
#[cfg(any(test, feature = "_test_utils"))]
39+
pub struct InFlightHtlcs(pub HashMap<(u64, bool), u64>);
40+
41+
impl InFlightHtlcs {
42+
/// Create a new `InFlightHtlcs` via a mapping from:
43+
/// (short_channel_id, source_pubkey < target_pubkey) -> used_liquidity_msat
44+
pub fn new(inflight_map: HashMap<(u64, bool), u64>) -> Self {
45+
InFlightHtlcs(inflight_map)
46+
}
47+
48+
/// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
49+
/// id.
50+
pub fn used_liquidity_msat(&self, source: &NodeId, target: &NodeId, channel_scid: u64) -> Option<u64> {
51+
self.0.get(&(channel_scid, source < target)).map(|v| *v)
52+
}
53+
}
54+
55+
impl Writeable for InFlightHtlcs {
56+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> { self.0.write(writer) }
57+
}
58+
59+
impl Readable for InFlightHtlcs {
60+
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
61+
let infight_map: HashMap<(u64, bool), u64> = Readable::read(reader)?;
62+
Ok(Self(infight_map))
63+
}
64+
}
65+
3266
/// A hop in a route
3367
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
3468
pub struct RouteHop {

0 commit comments

Comments
 (0)