From 682bb9b0ae4df2cd3042316a9cb99811fbb8595c Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 21 Dec 2022 20:43:02 -0500 Subject: [PATCH] Parameterize Simple*ChannelManager with DefaultRouter and ProbScorer --- lightning-background-processor/src/lib.rs | 9 ++++--- lightning-net-tokio/src/lib.rs | 5 ++-- lightning/src/ln/channelmanager.rs | 31 ++++++++++++++++------- lightning/src/ln/peer_handler.rs | 4 +-- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 9fc24905..199295b9 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -584,6 +584,7 @@ mod tests { use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler}; use lightning::routing::gossip::{NetworkGraph, P2PGossipSync}; use lightning::routing::router::DefaultRouter; + use lightning::routing::scoring::{ProbabilisticScoringParameters, ProbabilisticScorer}; use lightning::util::config::UserConfig; use lightning::util::events::{Event, MessageSendEventsProvider, MessageSendEvent}; use lightning::util::ser::Writeable; @@ -598,7 +599,6 @@ mod tests { use std::time::Duration; use bitcoin::hashes::Hash; use bitcoin::TxMerkleNode; - use lightning::routing::scoring::{FixedPenaltyScorer}; use lightning_rapid_gossip_sync::RapidGossipSync; use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER}; @@ -620,7 +620,7 @@ mod tests { type RGS = Arc>>, Arc>>; struct Node { - node: Arc>>, Arc, Arc>>, test_utils::TestLogger>>, + node: Arc>, p2p_gossip_sync: PGS, rapid_gossip_sync: RGS, peer_manager: Arc, Arc, IgnoringMessageHandler, Arc, IgnoringMessageHandler>>, @@ -630,7 +630,7 @@ mod tests { network_graph: Arc>>, logger: Arc, best_block: BestBlock, - scorer: Arc>, + scorer: Arc>>, Arc>>>, } impl Node { @@ -731,7 +731,8 @@ mod tests { let network = Network::Testnet; let genesis_block = genesis_block(network); let network_graph = Arc::new(NetworkGraph::new(genesis_block.header.block_hash(), logger.clone())); - let scorer = Arc::new(Mutex::new(test_utils::TestScorer::with_penalty(0))); + let params = ProbabilisticScoringParameters::default(); + let scorer = Arc::new(Mutex::new(ProbabilisticScorer::new(params, network_graph.clone(), logger.clone()))); let seed = [i as u8; 32]; let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), seed, scorer.clone())); let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 43bffac6..7a7cc4bb 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -31,14 +31,13 @@ //! // Define concrete types for our high-level objects: //! type TxBroadcaster = dyn lightning::chain::chaininterface::BroadcasterInterface + Send + Sync; //! type FeeEstimator = dyn lightning::chain::chaininterface::FeeEstimator + Send + Sync; -//! type Router = dyn lightning::routing::router::Router + Send + Sync; //! type Logger = dyn lightning::util::logger::Logger + Send + Sync; //! type ChainAccess = dyn lightning::chain::Access + Send + Sync; //! type ChainFilter = dyn lightning::chain::Filter + Send + Sync; //! type DataPersister = dyn lightning::chain::chainmonitor::Persist + Send + Sync; //! type ChainMonitor = lightning::chain::chainmonitor::ChainMonitor, Arc, Arc, Arc, Arc>; -//! type ChannelManager = Arc>; -//! type PeerManager = Arc>; +//! type ChannelManager = Arc>; +//! type PeerManager = Arc>; //! //! // Connect to node with pubkey their_node_id at addr: //! async fn connect_to_node(peer_manager: PeerManager, chain_monitor: Arc, channel_manager: ChannelManager, their_node_id: PublicKey, addr: SocketAddr) { diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 7d5ccc31..03a150e4 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -46,7 +46,9 @@ use crate::ln::channel::{Channel, ChannelError, ChannelUpdateStatus, UpdateFulfi use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures}; #[cfg(any(feature = "_test_utils", test))] use crate::ln::features::InvoiceFeatures; -use crate::routing::router::{InFlightHtlcs, PaymentParameters, Route, RouteHop, RoutePath, Router}; +use crate::routing::gossip::NetworkGraph; +use crate::routing::router::{DefaultRouter, InFlightHtlcs, PaymentParameters, Route, RouteHop, RoutePath, Router}; +use crate::routing::scoring::ProbabilisticScorer; use crate::ln::msgs; use crate::ln::onion_utils; use crate::ln::onion_utils::HTLCFailReason; @@ -490,24 +492,35 @@ struct PendingInboundPayment { /// when you're using lightning-net-tokio (since tokio::spawn requires parameters with static /// lifetimes). Other times you can afford a reference, which is more efficient, in which case /// SimpleRefChannelManager is the more appropriate type. Defining these type aliases prevents -/// issues such as overly long function definitions. Note that the ChannelManager can take any -/// type that implements KeysInterface for its keys manager, but this type alias chooses the -/// concrete type of the KeysManager. +/// issues such as overly long function definitions. Note that the ChannelManager can take any type +/// that implements KeysInterface or Router for its keys manager and router, respectively, but this +/// type alias chooses the concrete types of KeysManager and DefaultRouter. /// /// (C-not exported) as Arcs don't make sense in bindings -pub type SimpleArcChannelManager = ChannelManager, Arc, Arc, Arc, Arc, Arc>; +pub type SimpleArcChannelManager = ChannelManager< + Arc, + Arc, + Arc, + Arc, + Arc>>, + Arc, + Arc>>, Arc>>> + >>, + Arc +>; /// SimpleRefChannelManager is a type alias for a ChannelManager reference, and is the reference /// counterpart to the SimpleArcChannelManager type alias. Use this type by default when you don't /// need a ChannelManager with a static lifetime. You'll need a static lifetime in cases such as /// usage of lightning-net-tokio (since tokio::spawn requires parameters with static lifetimes). /// But if this is not necessary, using a reference is more efficient. Defining these type aliases -/// helps with issues such as long function definitions. Note that the ChannelManager can take any -/// type that implements KeysInterface for its keys manager, but this type alias chooses the -/// concrete type of the KeysManager. +/// issues such as overly long function definitions. Note that the ChannelManager can take any type +/// that implements KeysInterface or Router for its keys manager and router, respectively, but this +/// type alias chooses the concrete types of KeysManager and DefaultRouter. /// /// (C-not exported) as Arcs don't make sense in bindings -pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, M, T, F, R, L> = ChannelManager<&'a M, &'b T, &'c KeysManager, &'d F, &'e R, &'f L>; +pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, M, T, F, L> = ChannelManager<&'a M, &'b T, &'c KeysManager, &'d F, &'e DefaultRouter<&'f NetworkGraph<&'g L>, &'g L, &'h Mutex, &'g L>>>, &'g L>; /// Manager which keeps track of a number of channels and sends messages to the appropriate /// channel, also tracking HTLC preimages and forwarding onion packets appropriately. diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 46fed2f1..d851d29d 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -491,7 +491,7 @@ impl Peer { /// issues such as overly long function definitions. /// /// (C-not exported) as `Arc`s don't make sense in bindings. -pub type SimpleArcPeerManager = PeerManager>, Arc>>, Arc, Arc>>, Arc>, Arc, IgnoringMessageHandler>; +pub type SimpleArcPeerManager = PeerManager>, Arc>>, Arc, Arc>>, Arc>, Arc, IgnoringMessageHandler>; /// SimpleRefPeerManager is a type alias for a PeerManager reference, and is the reference /// counterpart to the SimpleArcPeerManager type alias. Use this type by default when you don't @@ -501,7 +501,7 @@ pub type SimpleArcPeerManager = PeerManager = PeerManager, &'f P2PGossipSync<&'g NetworkGraph<&'f L>, &'h C, &'f L>, &'i SimpleRefOnionMessenger<'j, 'k, L>, &'f L, IgnoringMessageHandler>; +pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l, 'm, SD, M, T, F, C, L> = PeerManager, &'f P2PGossipSync<&'g NetworkGraph<&'f L>, &'h C, &'f L>, &'i SimpleRefOnionMessenger<'j, 'k, L>, &'f L, IgnoringMessageHandler>; /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls /// socket events into messages which it passes on to its [`MessageHandler`]. -- 2.30.2