mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-01-19 05:43:55 +01:00
Parameterize Simple*ChannelManager with DefaultRouter and ProbScorer
This commit is contained in:
parent
3a1982c741
commit
682bb9b0ae
@ -584,6 +584,7 @@ mod tests {
|
|||||||
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler};
|
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler};
|
||||||
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
|
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
|
||||||
use lightning::routing::router::DefaultRouter;
|
use lightning::routing::router::DefaultRouter;
|
||||||
|
use lightning::routing::scoring::{ProbabilisticScoringParameters, ProbabilisticScorer};
|
||||||
use lightning::util::config::UserConfig;
|
use lightning::util::config::UserConfig;
|
||||||
use lightning::util::events::{Event, MessageSendEventsProvider, MessageSendEvent};
|
use lightning::util::events::{Event, MessageSendEventsProvider, MessageSendEvent};
|
||||||
use lightning::util::ser::Writeable;
|
use lightning::util::ser::Writeable;
|
||||||
@ -598,7 +599,6 @@ mod tests {
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use bitcoin::hashes::Hash;
|
use bitcoin::hashes::Hash;
|
||||||
use bitcoin::TxMerkleNode;
|
use bitcoin::TxMerkleNode;
|
||||||
use lightning::routing::scoring::{FixedPenaltyScorer};
|
|
||||||
use lightning_rapid_gossip_sync::RapidGossipSync;
|
use lightning_rapid_gossip_sync::RapidGossipSync;
|
||||||
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};
|
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};
|
||||||
|
|
||||||
@ -620,7 +620,7 @@ mod tests {
|
|||||||
type RGS = Arc<RapidGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestLogger>>>;
|
type RGS = Arc<RapidGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestLogger>>>;
|
||||||
|
|
||||||
struct Node {
|
struct Node {
|
||||||
node: Arc<SimpleArcChannelManager<ChainMonitor, test_utils::TestBroadcaster, test_utils::TestFeeEstimator, DefaultRouter<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestLogger>, Arc<Mutex<FixedPenaltyScorer>>>, test_utils::TestLogger>>,
|
node: Arc<SimpleArcChannelManager<ChainMonitor, test_utils::TestBroadcaster, test_utils::TestFeeEstimator, test_utils::TestLogger>>,
|
||||||
p2p_gossip_sync: PGS,
|
p2p_gossip_sync: PGS,
|
||||||
rapid_gossip_sync: RGS,
|
rapid_gossip_sync: RGS,
|
||||||
peer_manager: Arc<PeerManager<TestDescriptor, Arc<test_utils::TestChannelMessageHandler>, Arc<test_utils::TestRoutingMessageHandler>, IgnoringMessageHandler, Arc<test_utils::TestLogger>, IgnoringMessageHandler>>,
|
peer_manager: Arc<PeerManager<TestDescriptor, Arc<test_utils::TestChannelMessageHandler>, Arc<test_utils::TestRoutingMessageHandler>, IgnoringMessageHandler, Arc<test_utils::TestLogger>, IgnoringMessageHandler>>,
|
||||||
@ -630,7 +630,7 @@ mod tests {
|
|||||||
network_graph: Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
|
network_graph: Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
|
||||||
logger: Arc<test_utils::TestLogger>,
|
logger: Arc<test_utils::TestLogger>,
|
||||||
best_block: BestBlock,
|
best_block: BestBlock,
|
||||||
scorer: Arc<Mutex<FixedPenaltyScorer>>,
|
scorer: Arc<Mutex<ProbabilisticScorer<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestLogger>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
@ -731,7 +731,8 @@ mod tests {
|
|||||||
let network = Network::Testnet;
|
let network = Network::Testnet;
|
||||||
let genesis_block = genesis_block(network);
|
let genesis_block = genesis_block(network);
|
||||||
let network_graph = Arc::new(NetworkGraph::new(genesis_block.header.block_hash(), logger.clone()));
|
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 seed = [i as u8; 32];
|
||||||
let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), seed, scorer.clone()));
|
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));
|
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
||||||
|
@ -31,14 +31,13 @@
|
|||||||
//! // Define concrete types for our high-level objects:
|
//! // Define concrete types for our high-level objects:
|
||||||
//! type TxBroadcaster = dyn lightning::chain::chaininterface::BroadcasterInterface + Send + Sync;
|
//! type TxBroadcaster = dyn lightning::chain::chaininterface::BroadcasterInterface + Send + Sync;
|
||||||
//! type FeeEstimator = dyn lightning::chain::chaininterface::FeeEstimator + 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 Logger = dyn lightning::util::logger::Logger + Send + Sync;
|
||||||
//! type ChainAccess = dyn lightning::chain::Access + Send + Sync;
|
//! type ChainAccess = dyn lightning::chain::Access + Send + Sync;
|
||||||
//! type ChainFilter = dyn lightning::chain::Filter + Send + Sync;
|
//! type ChainFilter = dyn lightning::chain::Filter + Send + Sync;
|
||||||
//! type DataPersister = dyn lightning::chain::chainmonitor::Persist<lightning::chain::keysinterface::InMemorySigner> + Send + Sync;
|
//! type DataPersister = dyn lightning::chain::chainmonitor::Persist<lightning::chain::keysinterface::InMemorySigner> + Send + Sync;
|
||||||
//! type ChainMonitor = lightning::chain::chainmonitor::ChainMonitor<lightning::chain::keysinterface::InMemorySigner, Arc<ChainFilter>, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>, Arc<DataPersister>>;
|
//! type ChainMonitor = lightning::chain::chainmonitor::ChainMonitor<lightning::chain::keysinterface::InMemorySigner, Arc<ChainFilter>, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>, Arc<DataPersister>>;
|
||||||
//! type ChannelManager = Arc<lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor, TxBroadcaster, FeeEstimator, Router, Logger>>;
|
//! type ChannelManager = Arc<lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor, TxBroadcaster, FeeEstimator, Logger>>;
|
||||||
//! type PeerManager = Arc<lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChainMonitor, TxBroadcaster, FeeEstimator, ChainAccess, Router, Logger>>;
|
//! type PeerManager = Arc<lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChainMonitor, TxBroadcaster, FeeEstimator, ChainAccess, Logger>>;
|
||||||
//!
|
//!
|
||||||
//! // Connect to node with pubkey their_node_id at addr:
|
//! // Connect to node with pubkey their_node_id at addr:
|
||||||
//! async fn connect_to_node(peer_manager: PeerManager, chain_monitor: Arc<ChainMonitor>, channel_manager: ChannelManager, their_node_id: PublicKey, addr: SocketAddr) {
|
//! async fn connect_to_node(peer_manager: PeerManager, chain_monitor: Arc<ChainMonitor>, channel_manager: ChannelManager, their_node_id: PublicKey, addr: SocketAddr) {
|
||||||
|
@ -46,7 +46,9 @@ use crate::ln::channel::{Channel, ChannelError, ChannelUpdateStatus, UpdateFulfi
|
|||||||
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
|
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
|
||||||
#[cfg(any(feature = "_test_utils", test))]
|
#[cfg(any(feature = "_test_utils", test))]
|
||||||
use crate::ln::features::InvoiceFeatures;
|
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::msgs;
|
||||||
use crate::ln::onion_utils;
|
use crate::ln::onion_utils;
|
||||||
use crate::ln::onion_utils::HTLCFailReason;
|
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
|
/// 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
|
/// 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
|
/// 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
|
/// issues such as overly long function definitions. Note that the ChannelManager can take any type
|
||||||
/// type that implements KeysInterface for its keys manager, but this type alias chooses the
|
/// that implements KeysInterface or Router for its keys manager and router, respectively, but this
|
||||||
/// concrete type of the KeysManager.
|
/// type alias chooses the concrete types of KeysManager and DefaultRouter.
|
||||||
///
|
///
|
||||||
/// (C-not exported) as Arcs don't make sense in bindings
|
/// (C-not exported) as Arcs don't make sense in bindings
|
||||||
pub type SimpleArcChannelManager<M, T, F, R, L> = ChannelManager<Arc<M>, Arc<T>, Arc<KeysManager>, Arc<F>, Arc<R>, Arc<L>>;
|
pub type SimpleArcChannelManager<M, T, F, L> = ChannelManager<
|
||||||
|
Arc<M>,
|
||||||
|
Arc<T>,
|
||||||
|
Arc<KeysManager>,
|
||||||
|
Arc<F>,
|
||||||
|
Arc<DefaultRouter<
|
||||||
|
Arc<NetworkGraph<Arc<L>>>,
|
||||||
|
Arc<L>,
|
||||||
|
Arc<Mutex<ProbabilisticScorer<Arc<NetworkGraph<Arc<L>>>, Arc<L>>>>
|
||||||
|
>>,
|
||||||
|
Arc<L>
|
||||||
|
>;
|
||||||
|
|
||||||
/// SimpleRefChannelManager is a type alias for a ChannelManager reference, and is the reference
|
/// 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
|
/// 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
|
/// 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).
|
/// 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
|
/// 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
|
/// issues such as overly long function definitions. Note that the ChannelManager can take any type
|
||||||
/// type that implements KeysInterface for its keys manager, but this type alias chooses the
|
/// that implements KeysInterface or Router for its keys manager and router, respectively, but this
|
||||||
/// concrete type of the KeysManager.
|
/// type alias chooses the concrete types of KeysManager and DefaultRouter.
|
||||||
///
|
///
|
||||||
/// (C-not exported) as Arcs don't make sense in bindings
|
/// (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<ProbabilisticScorer<&'f NetworkGraph<&'g L>, &'g L>>>, &'g L>;
|
||||||
|
|
||||||
/// Manager which keeps track of a number of channels and sends messages to the appropriate
|
/// 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.
|
/// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
|
||||||
|
@ -491,7 +491,7 @@ impl Peer {
|
|||||||
/// issues such as overly long function definitions.
|
/// issues such as overly long function definitions.
|
||||||
///
|
///
|
||||||
/// (C-not exported) as `Arc`s don't make sense in bindings.
|
/// (C-not exported) as `Arc`s don't make sense in bindings.
|
||||||
pub type SimpleArcPeerManager<SD, M, T, F, C, R, L> = PeerManager<SD, Arc<SimpleArcChannelManager<M, T, F, R, L>>, Arc<P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, Arc<C>, Arc<L>>>, Arc<SimpleArcOnionMessenger<L>>, Arc<L>, IgnoringMessageHandler>;
|
pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArcChannelManager<M, T, F, L>>, Arc<P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, Arc<C>, Arc<L>>>, Arc<SimpleArcOnionMessenger<L>>, Arc<L>, IgnoringMessageHandler>;
|
||||||
|
|
||||||
/// SimpleRefPeerManager is a type alias for a PeerManager reference, and is the reference
|
/// 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
|
/// counterpart to the SimpleArcPeerManager type alias. Use this type by default when you don't
|
||||||
@ -501,7 +501,7 @@ pub type SimpleArcPeerManager<SD, M, T, F, C, R, L> = PeerManager<SD, Arc<Simple
|
|||||||
/// helps with issues such as long function definitions.
|
/// helps with issues such as long function definitions.
|
||||||
///
|
///
|
||||||
/// (C-not exported) as general type aliases don't make sense in bindings.
|
/// (C-not exported) as general type aliases don't make sense in bindings.
|
||||||
pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l, SD, M, T, F, C, R, L> = PeerManager<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, M, T, F, R, L>, &'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<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'm, M, T, F, L>, &'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
|
/// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
|
||||||
/// socket events into messages which it passes on to its [`MessageHandler`].
|
/// socket events into messages which it passes on to its [`MessageHandler`].
|
||||||
|
Loading…
Reference in New Issue
Block a user