mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-01-19 05:43:55 +01:00
Parameterize NetworkGraph with Logger
P2PGossipSync logs before delegating to NetworkGraph in its EventHandler. In order to share this handling with RapidGossipSync, NetworkGraph needs to take a logger so that it can implement EventHandler instead.
This commit is contained in:
parent
0f73d6adcf
commit
67736b7480
@ -163,7 +163,7 @@ type ChannelMan = ChannelManager<
|
|||||||
EnforcingSigner,
|
EnforcingSigner,
|
||||||
Arc<chainmonitor::ChainMonitor<EnforcingSigner, Arc<dyn chain::Filter>, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<TestPersister>>>,
|
Arc<chainmonitor::ChainMonitor<EnforcingSigner, Arc<dyn chain::Filter>, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<TestPersister>>>,
|
||||||
Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>;
|
Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>;
|
||||||
type PeerMan<'a> = PeerManager<Peer<'a>, Arc<ChannelMan>, Arc<P2PGossipSync<Arc<NetworkGraph>, Arc<dyn chain::Access>, Arc<dyn Logger>>>, Arc<dyn Logger>, IgnoringMessageHandler>;
|
type PeerMan<'a> = PeerManager<Peer<'a>, Arc<ChannelMan>, Arc<P2PGossipSync<Arc<NetworkGraph<Arc<dyn Logger>>>, Arc<dyn chain::Access>, Arc<dyn Logger>>>, Arc<dyn Logger>, IgnoringMessageHandler>;
|
||||||
|
|
||||||
struct MoneyLossDetector<'a> {
|
struct MoneyLossDetector<'a> {
|
||||||
manager: Arc<ChannelMan>,
|
manager: Arc<ChannelMan>,
|
||||||
@ -395,7 +395,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
|
|||||||
// it's easier to just increment the counter here so the keys don't change.
|
// it's easier to just increment the counter here so the keys don't change.
|
||||||
keys_manager.counter.fetch_sub(1, Ordering::AcqRel);
|
keys_manager.counter.fetch_sub(1, Ordering::AcqRel);
|
||||||
let our_id = PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret(Recipient::Node).unwrap());
|
let our_id = PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret(Recipient::Node).unwrap());
|
||||||
let network_graph = Arc::new(NetworkGraph::new(genesis_block(network).block_hash()));
|
let network_graph = Arc::new(NetworkGraph::new(genesis_block(network).block_hash(), Arc::clone(&logger)));
|
||||||
let gossip_sync = Arc::new(P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger)));
|
let gossip_sync = Arc::new(P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger)));
|
||||||
let scorer = FixedPenaltyScorer::with_penalty(0);
|
let scorer = FixedPenaltyScorer::with_penalty(0);
|
||||||
|
|
||||||
@ -460,7 +460,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
|
|||||||
final_cltv_expiry_delta: 42,
|
final_cltv_expiry_delta: 42,
|
||||||
};
|
};
|
||||||
let random_seed_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();
|
let random_seed_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();
|
||||||
let route = match find_route(&our_id, ¶ms, &network_graph, None, Arc::clone(&logger), &scorer, &random_seed_bytes) {
|
let route = match find_route(&our_id, ¶ms, &network_graph.read_only(), None, Arc::clone(&logger), &scorer, &random_seed_bytes) {
|
||||||
Ok(route) => route,
|
Ok(route) => route,
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
@ -484,7 +484,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
|
|||||||
final_cltv_expiry_delta: 42,
|
final_cltv_expiry_delta: 42,
|
||||||
};
|
};
|
||||||
let random_seed_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();
|
let random_seed_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();
|
||||||
let mut route = match find_route(&our_id, ¶ms, &network_graph, None, Arc::clone(&logger), &scorer, &random_seed_bytes) {
|
let mut route = match find_route(&our_id, ¶ms, &network_graph.read_only(), None, Arc::clone(&logger), &scorer, &random_seed_bytes) {
|
||||||
Ok(route) => route,
|
Ok(route) => route,
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
|
@ -1,22 +1,27 @@
|
|||||||
// Imports that need to be added manually
|
// Imports that need to be added manually
|
||||||
|
use lightning::util::logger::Logger;
|
||||||
use lightning_rapid_gossip_sync::RapidGossipSync;
|
use lightning_rapid_gossip_sync::RapidGossipSync;
|
||||||
|
|
||||||
use utils::test_logger;
|
use utils::test_logger;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Actual fuzz test, method signature and name are fixed
|
/// Actual fuzz test, method signature and name are fixed
|
||||||
fn do_test(data: &[u8]) {
|
fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
|
||||||
let block_hash = bitcoin::BlockHash::default();
|
let block_hash = bitcoin::BlockHash::default();
|
||||||
let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash);
|
let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
|
||||||
|
let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash, logger);
|
||||||
let rapid_sync = RapidGossipSync::new(&network_graph);
|
let rapid_sync = RapidGossipSync::new(&network_graph);
|
||||||
let _ = rapid_sync.update_network_graph(data);
|
let _ = rapid_sync.update_network_graph(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Method that needs to be added manually, {name}_test
|
/// Method that needs to be added manually, {name}_test
|
||||||
pub fn process_network_graph_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
|
pub fn process_network_graph_test<Out: test_logger::Output>(data: &[u8], out: Out) {
|
||||||
do_test(data);
|
do_test(data, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Method that needs to be added manually, {name}_run
|
/// Method that needs to be added manually, {name}_run
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn process_network_graph_run(data: *const u8, datalen: usize) {
|
pub extern "C" fn process_network_graph_run(data: *const u8, datalen: usize) {
|
||||||
do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
|
do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull {});
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
|
|||||||
let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
|
let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
|
||||||
|
|
||||||
let our_pubkey = get_pubkey!();
|
let our_pubkey = get_pubkey!();
|
||||||
let net_graph = NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash());
|
let net_graph = NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), Arc::clone(&logger));
|
||||||
|
|
||||||
let mut node_pks = HashSet::new();
|
let mut node_pks = HashSet::new();
|
||||||
let mut scid = 42;
|
let mut scid = 42;
|
||||||
@ -267,7 +267,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
|
|||||||
final_value_msat: slice_to_be64(get_slice!(8)),
|
final_value_msat: slice_to_be64(get_slice!(8)),
|
||||||
final_cltv_expiry_delta: slice_to_be32(get_slice!(4)),
|
final_cltv_expiry_delta: slice_to_be32(get_slice!(4)),
|
||||||
};
|
};
|
||||||
let _ = find_route(&our_pubkey, &route_params, &net_graph,
|
let _ = find_route(&our_pubkey, &route_params, &net_graph.read_only(),
|
||||||
first_hops.map(|c| c.iter().collect::<Vec<_>>()).as_ref().map(|a| a.as_slice()),
|
first_hops.map(|c| c.iter().collect::<Vec<_>>()).as_ref().map(|a| a.as_slice()),
|
||||||
Arc::clone(&logger), &scorer, &random_seed_bytes);
|
Arc::clone(&logger), &scorer, &random_seed_bytes);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ const FIRST_NETWORK_PRUNE_TIMER: u64 = 1;
|
|||||||
struct DecoratingEventHandler<
|
struct DecoratingEventHandler<
|
||||||
E: EventHandler,
|
E: EventHandler,
|
||||||
P: Deref<Target = P2PGossipSync<G, A, L>>,
|
P: Deref<Target = P2PGossipSync<G, A, L>>,
|
||||||
G: Deref<Target = NetworkGraph>,
|
G: Deref<Target = NetworkGraph<L>>,
|
||||||
A: Deref,
|
A: Deref,
|
||||||
L: Deref,
|
L: Deref,
|
||||||
>
|
>
|
||||||
@ -106,7 +106,7 @@ where A::Target: chain::Access, L::Target: Logger {
|
|||||||
impl<
|
impl<
|
||||||
E: EventHandler,
|
E: EventHandler,
|
||||||
P: Deref<Target = P2PGossipSync<G, A, L>>,
|
P: Deref<Target = P2PGossipSync<G, A, L>>,
|
||||||
G: Deref<Target = NetworkGraph>,
|
G: Deref<Target = NetworkGraph<L>>,
|
||||||
A: Deref,
|
A: Deref,
|
||||||
L: Deref,
|
L: Deref,
|
||||||
> EventHandler for DecoratingEventHandler<E, P, G, A, L>
|
> EventHandler for DecoratingEventHandler<E, P, G, A, L>
|
||||||
@ -173,7 +173,7 @@ impl BackgroundProcessor {
|
|||||||
T: 'static + Deref + Send + Sync,
|
T: 'static + Deref + Send + Sync,
|
||||||
K: 'static + Deref + Send + Sync,
|
K: 'static + Deref + Send + Sync,
|
||||||
F: 'static + Deref + Send + Sync,
|
F: 'static + Deref + Send + Sync,
|
||||||
G: 'static + Deref<Target = NetworkGraph> + Send + Sync,
|
G: 'static + Deref<Target = NetworkGraph<L>> + Send + Sync,
|
||||||
L: 'static + Deref + Send + Sync,
|
L: 'static + Deref + Send + Sync,
|
||||||
P: 'static + Deref + Send + Sync,
|
P: 'static + Deref + Send + Sync,
|
||||||
Descriptor: 'static + SocketDescriptor + Send + Sync,
|
Descriptor: 'static + SocketDescriptor + Send + Sync,
|
||||||
@ -188,7 +188,7 @@ impl BackgroundProcessor {
|
|||||||
PM: 'static + Deref<Target = PeerManager<Descriptor, CMH, RMH, L, UMH>> + Send + Sync,
|
PM: 'static + Deref<Target = PeerManager<Descriptor, CMH, RMH, L, UMH>> + Send + Sync,
|
||||||
S: 'static + Deref<Target = SC> + Send + Sync,
|
S: 'static + Deref<Target = SC> + Send + Sync,
|
||||||
SC: WriteableScore<'a>,
|
SC: WriteableScore<'a>,
|
||||||
RGS: 'static + Deref<Target = RapidGossipSync<G>> + Send
|
RGS: 'static + Deref<Target = RapidGossipSync<G, L>> + Send
|
||||||
>(
|
>(
|
||||||
persister: PS, event_handler: EH, chain_monitor: M, channel_manager: CM,
|
persister: PS, event_handler: EH, chain_monitor: M, channel_manager: CM,
|
||||||
p2p_gossip_sync: Option<PGS>, peer_manager: PM, logger: L, scorer: Option<S>,
|
p2p_gossip_sync: Option<PGS>, peer_manager: PM, logger: L, scorer: Option<S>,
|
||||||
@ -442,16 +442,16 @@ mod tests {
|
|||||||
|
|
||||||
struct Node {
|
struct Node {
|
||||||
node: Arc<SimpleArcChannelManager<ChainMonitor, test_utils::TestBroadcaster, test_utils::TestFeeEstimator, test_utils::TestLogger>>,
|
node: Arc<SimpleArcChannelManager<ChainMonitor, test_utils::TestBroadcaster, test_utils::TestFeeEstimator, test_utils::TestLogger>>,
|
||||||
p2p_gossip_sync: Option<Arc<P2PGossipSync<Arc<NetworkGraph>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>>>,
|
p2p_gossip_sync: Option<Arc<P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>>>,
|
||||||
peer_manager: Arc<PeerManager<TestDescriptor, Arc<test_utils::TestChannelMessageHandler>, Arc<test_utils::TestRoutingMessageHandler>, Arc<test_utils::TestLogger>, IgnoringMessageHandler>>,
|
peer_manager: Arc<PeerManager<TestDescriptor, Arc<test_utils::TestChannelMessageHandler>, Arc<test_utils::TestRoutingMessageHandler>, Arc<test_utils::TestLogger>, IgnoringMessageHandler>>,
|
||||||
chain_monitor: Arc<ChainMonitor>,
|
chain_monitor: Arc<ChainMonitor>,
|
||||||
persister: Arc<FilesystemPersister>,
|
persister: Arc<FilesystemPersister>,
|
||||||
tx_broadcaster: Arc<test_utils::TestBroadcaster>,
|
tx_broadcaster: Arc<test_utils::TestBroadcaster>,
|
||||||
network_graph: Arc<NetworkGraph>,
|
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<FixedPenaltyScorer>>,
|
||||||
rapid_gossip_sync: Option<Arc<RapidGossipSync<Arc<NetworkGraph>>>>
|
rapid_gossip_sync: Option<Arc<RapidGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestLogger>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Node {
|
impl Drop for Node {
|
||||||
@ -546,7 +546,7 @@ mod tests {
|
|||||||
let best_block = BestBlock::from_genesis(network);
|
let best_block = BestBlock::from_genesis(network);
|
||||||
let params = ChainParameters { network, best_block };
|
let params = ChainParameters { network, best_block };
|
||||||
let manager = Arc::new(ChannelManager::new(fee_estimator.clone(), chain_monitor.clone(), tx_broadcaster.clone(), logger.clone(), keys_manager.clone(), UserConfig::default(), params));
|
let manager = Arc::new(ChannelManager::new(fee_estimator.clone(), chain_monitor.clone(), tx_broadcaster.clone(), logger.clone(), keys_manager.clone(), UserConfig::default(), params));
|
||||||
let network_graph = Arc::new(NetworkGraph::new(genesis_block.header.block_hash()));
|
let network_graph = Arc::new(NetworkGraph::new(genesis_block.header.block_hash(), logger.clone()));
|
||||||
let p2p_gossip_sync = Some(Arc::new(P2PGossipSync::new(network_graph.clone(), Some(chain_source.clone()), logger.clone())));
|
let p2p_gossip_sync = Some(Arc::new(P2PGossipSync::new(network_graph.clone(), Some(chain_source.clone()), logger.clone())));
|
||||||
let msg_handler = MessageHandler { chan_handler: Arc::new(test_utils::TestChannelMessageHandler::new()), route_handler: Arc::new(test_utils::TestRoutingMessageHandler::new() )};
|
let msg_handler = MessageHandler { chan_handler: Arc::new(test_utils::TestChannelMessageHandler::new()), route_handler: Arc::new(test_utils::TestRoutingMessageHandler::new() )};
|
||||||
let peer_manager = Arc::new(PeerManager::new(msg_handler, keys_manager.get_node_secret(Recipient::Node).unwrap(), &seed, logger.clone(), IgnoringMessageHandler{}));
|
let peer_manager = Arc::new(PeerManager::new(msg_handler, keys_manager.get_node_secret(Recipient::Node).unwrap(), &seed, logger.clone(), IgnoringMessageHandler{}));
|
||||||
|
@ -440,13 +440,13 @@ fn filter_channels(channels: Vec<ChannelDetails>, min_inbound_capacity_msat: Opt
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A [`Router`] implemented using [`find_route`].
|
/// A [`Router`] implemented using [`find_route`].
|
||||||
pub struct DefaultRouter<G: Deref<Target = NetworkGraph>, L: Deref> where L::Target: Logger {
|
pub struct DefaultRouter<G: Deref<Target = NetworkGraph<L>>, L: Deref> where L::Target: Logger {
|
||||||
network_graph: G,
|
network_graph: G,
|
||||||
logger: L,
|
logger: L,
|
||||||
random_seed_bytes: Mutex<[u8; 32]>,
|
random_seed_bytes: Mutex<[u8; 32]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Deref<Target = NetworkGraph>, L: Deref> DefaultRouter<G, L> where L::Target: Logger {
|
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> DefaultRouter<G, L> where L::Target: Logger {
|
||||||
/// Creates a new router using the given [`NetworkGraph`], a [`Logger`], and a randomness source
|
/// Creates a new router using the given [`NetworkGraph`], a [`Logger`], and a randomness source
|
||||||
/// `random_seed_bytes`.
|
/// `random_seed_bytes`.
|
||||||
pub fn new(network_graph: G, logger: L, random_seed_bytes: [u8; 32]) -> Self {
|
pub fn new(network_graph: G, logger: L, random_seed_bytes: [u8; 32]) -> Self {
|
||||||
@ -455,18 +455,19 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref> DefaultRouter<G, L> where L::Tar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Deref<Target = NetworkGraph>, L: Deref, S: Score> Router<S> for DefaultRouter<G, L>
|
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Score> Router<S> for DefaultRouter<G, L>
|
||||||
where L::Target: Logger {
|
where L::Target: Logger {
|
||||||
fn find_route(
|
fn find_route(
|
||||||
&self, payer: &PublicKey, params: &RouteParameters, _payment_hash: &PaymentHash,
|
&self, payer: &PublicKey, params: &RouteParameters, _payment_hash: &PaymentHash,
|
||||||
first_hops: Option<&[&ChannelDetails]>, scorer: &S
|
first_hops: Option<&[&ChannelDetails]>, scorer: &S
|
||||||
) -> Result<Route, LightningError> {
|
) -> Result<Route, LightningError> {
|
||||||
|
let network_graph = self.network_graph.read_only();
|
||||||
let random_seed_bytes = {
|
let random_seed_bytes = {
|
||||||
let mut locked_random_seed_bytes = self.random_seed_bytes.lock().unwrap();
|
let mut locked_random_seed_bytes = self.random_seed_bytes.lock().unwrap();
|
||||||
*locked_random_seed_bytes = sha256::Hash::hash(&*locked_random_seed_bytes).into_inner();
|
*locked_random_seed_bytes = sha256::Hash::hash(&*locked_random_seed_bytes).into_inner();
|
||||||
*locked_random_seed_bytes
|
*locked_random_seed_bytes
|
||||||
};
|
};
|
||||||
find_route(payer, params, &*self.network_graph, first_hops, &*self.logger, scorer, &random_seed_bytes)
|
find_route(payer, params, &network_graph, first_hops, &*self.logger, scorer, &random_seed_bytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,12 +567,12 @@ mod test {
|
|||||||
final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32,
|
final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32,
|
||||||
};
|
};
|
||||||
let first_hops = nodes[0].node.list_usable_channels();
|
let first_hops = nodes[0].node.list_usable_channels();
|
||||||
let network_graph = node_cfgs[0].network_graph;
|
let network_graph = &node_cfgs[0].network_graph;
|
||||||
let logger = test_utils::TestLogger::new();
|
let logger = test_utils::TestLogger::new();
|
||||||
let scorer = test_utils::TestScorer::with_penalty(0);
|
let scorer = test_utils::TestScorer::with_penalty(0);
|
||||||
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
||||||
let route = find_route(
|
let route = find_route(
|
||||||
&nodes[0].node.get_our_node_id(), &route_params, network_graph,
|
&nodes[0].node.get_our_node_id(), &route_params, &network_graph.read_only(),
|
||||||
Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
|
Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
@ -842,12 +843,12 @@ mod test {
|
|||||||
final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32,
|
final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32,
|
||||||
};
|
};
|
||||||
let first_hops = nodes[0].node.list_usable_channels();
|
let first_hops = nodes[0].node.list_usable_channels();
|
||||||
let network_graph = node_cfgs[0].network_graph;
|
let network_graph = &node_cfgs[0].network_graph;
|
||||||
let logger = test_utils::TestLogger::new();
|
let logger = test_utils::TestLogger::new();
|
||||||
let scorer = test_utils::TestScorer::with_penalty(0);
|
let scorer = test_utils::TestScorer::with_penalty(0);
|
||||||
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
||||||
let route = find_route(
|
let route = find_route(
|
||||||
&nodes[0].node.get_our_node_id(), ¶ms, network_graph,
|
&nodes[0].node.get_our_node_id(), ¶ms, &network_graph.read_only(),
|
||||||
Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
|
Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
|
||||||
).unwrap();
|
).unwrap();
|
||||||
let (payment_event, fwd_idx) = {
|
let (payment_event, fwd_idx) = {
|
||||||
|
@ -32,8 +32,15 @@
|
|||||||
//! use lightning::routing::gossip::NetworkGraph;
|
//! use lightning::routing::gossip::NetworkGraph;
|
||||||
//! use lightning_rapid_gossip_sync::RapidGossipSync;
|
//! use lightning_rapid_gossip_sync::RapidGossipSync;
|
||||||
//!
|
//!
|
||||||
|
//! # use lightning::util::logger::{Logger, Record};
|
||||||
|
//! # struct FakeLogger {}
|
||||||
|
//! # impl Logger for FakeLogger {
|
||||||
|
//! # fn log(&self, record: &Record) { unimplemented!() }
|
||||||
|
//! # }
|
||||||
|
//! # let logger = FakeLogger {};
|
||||||
|
//!
|
||||||
//! let block_hash = genesis_block(Network::Bitcoin).header.block_hash();
|
//! let block_hash = genesis_block(Network::Bitcoin).header.block_hash();
|
||||||
//! let network_graph = NetworkGraph::new(block_hash);
|
//! let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
//! let rapid_sync = RapidGossipSync::new(&network_graph);
|
//! let rapid_sync = RapidGossipSync::new(&network_graph);
|
||||||
//! let new_last_sync_timestamp_result = rapid_sync.sync_network_graph_with_file_path("./rapid_sync.lngossip");
|
//! let new_last_sync_timestamp_result = rapid_sync.sync_network_graph_with_file_path("./rapid_sync.lngossip");
|
||||||
//! ```
|
//! ```
|
||||||
@ -63,6 +70,7 @@ use std::ops::Deref;
|
|||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use lightning::routing::gossip::NetworkGraph;
|
use lightning::routing::gossip::NetworkGraph;
|
||||||
|
use lightning::util::logger::Logger;
|
||||||
|
|
||||||
use crate::error::GraphSyncError;
|
use crate::error::GraphSyncError;
|
||||||
|
|
||||||
@ -76,12 +84,13 @@ pub mod processing;
|
|||||||
/// See [crate-level documentation] for usage.
|
/// See [crate-level documentation] for usage.
|
||||||
///
|
///
|
||||||
/// [crate-level documentation]: crate
|
/// [crate-level documentation]: crate
|
||||||
pub struct RapidGossipSync<NG: Deref<Target=NetworkGraph>> {
|
pub struct RapidGossipSync<NG: Deref<Target=NetworkGraph<L>>, L: Deref>
|
||||||
|
where L::Target: Logger {
|
||||||
network_graph: NG,
|
network_graph: NG,
|
||||||
is_initial_sync_complete: AtomicBool
|
is_initial_sync_complete: AtomicBool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<NG: Deref<Target=NetworkGraph>> RapidGossipSync<NG> {
|
impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
|
||||||
/// Instantiate a new [`RapidGossipSync`] instance
|
/// Instantiate a new [`RapidGossipSync`] instance
|
||||||
pub fn new(network_graph: NG) -> Self {
|
pub fn new(network_graph: NG) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -128,6 +137,7 @@ mod tests {
|
|||||||
|
|
||||||
use lightning::ln::msgs::DecodeError;
|
use lightning::ln::msgs::DecodeError;
|
||||||
use lightning::routing::gossip::NetworkGraph;
|
use lightning::routing::gossip::NetworkGraph;
|
||||||
|
use lightning::util::test_utils::TestLogger;
|
||||||
use crate::RapidGossipSync;
|
use crate::RapidGossipSync;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -187,7 +197,8 @@ mod tests {
|
|||||||
let graph_sync_test_file = sync_test.get_test_file_path();
|
let graph_sync_test_file = sync_test.get_test_file_path();
|
||||||
|
|
||||||
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
let network_graph = NetworkGraph::new(block_hash);
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
|
|
||||||
assert_eq!(network_graph.read_only().channels().len(), 0);
|
assert_eq!(network_graph.read_only().channels().len(), 0);
|
||||||
|
|
||||||
@ -219,7 +230,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn measure_native_read_from_file() {
|
fn measure_native_read_from_file() {
|
||||||
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
let network_graph = NetworkGraph::new(block_hash);
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
|
|
||||||
assert_eq!(network_graph.read_only().channels().len(), 0);
|
assert_eq!(network_graph.read_only().channels().len(), 0);
|
||||||
|
|
||||||
@ -254,14 +266,16 @@ pub mod bench {
|
|||||||
|
|
||||||
use lightning::ln::msgs::DecodeError;
|
use lightning::ln::msgs::DecodeError;
|
||||||
use lightning::routing::gossip::NetworkGraph;
|
use lightning::routing::gossip::NetworkGraph;
|
||||||
|
use lightning::util::test_utils::TestLogger;
|
||||||
|
|
||||||
use crate::RapidGossipSync;
|
use crate::RapidGossipSync;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_reading_full_graph_from_file(b: &mut Bencher) {
|
fn bench_reading_full_graph_from_file(b: &mut Bencher) {
|
||||||
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
|
let logger = TestLogger::new();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let network_graph = NetworkGraph::new(block_hash);
|
let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
let rapid_sync = RapidGossipSync::new(&network_graph);
|
let rapid_sync = RapidGossipSync::new(&network_graph);
|
||||||
let sync_result = rapid_sync.sync_network_graph_with_file_path("./res/full_graph.lngossip");
|
let sync_result = rapid_sync.sync_network_graph_with_file_path("./res/full_graph.lngossip");
|
||||||
if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
|
if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
|
||||||
|
@ -11,6 +11,7 @@ use lightning::ln::msgs::{
|
|||||||
DecodeError, ErrorAction, LightningError, OptionalField, UnsignedChannelUpdate,
|
DecodeError, ErrorAction, LightningError, OptionalField, UnsignedChannelUpdate,
|
||||||
};
|
};
|
||||||
use lightning::routing::gossip::NetworkGraph;
|
use lightning::routing::gossip::NetworkGraph;
|
||||||
|
use lightning::util::logger::Logger;
|
||||||
use lightning::util::ser::{BigSize, Readable};
|
use lightning::util::ser::{BigSize, Readable};
|
||||||
|
|
||||||
use crate::error::GraphSyncError;
|
use crate::error::GraphSyncError;
|
||||||
@ -26,7 +27,7 @@ const GOSSIP_PREFIX: [u8; 4] = [76, 68, 75, 1];
|
|||||||
/// avoid malicious updates being able to trigger excessive memory allocation.
|
/// avoid malicious updates being able to trigger excessive memory allocation.
|
||||||
const MAX_INITIAL_NODE_ID_VECTOR_CAPACITY: u32 = 50_000;
|
const MAX_INITIAL_NODE_ID_VECTOR_CAPACITY: u32 = 50_000;
|
||||||
|
|
||||||
impl<NG: Deref<Target=NetworkGraph>> RapidGossipSync<NG> {
|
impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
|
||||||
/// Update network graph from binary data.
|
/// Update network graph from binary data.
|
||||||
/// Returns the last sync timestamp to be used the next time rapid sync data is queried.
|
/// Returns the last sync timestamp to be used the next time rapid sync data is queried.
|
||||||
///
|
///
|
||||||
@ -236,6 +237,7 @@ mod tests {
|
|||||||
|
|
||||||
use lightning::ln::msgs::DecodeError;
|
use lightning::ln::msgs::DecodeError;
|
||||||
use lightning::routing::gossip::NetworkGraph;
|
use lightning::routing::gossip::NetworkGraph;
|
||||||
|
use lightning::util::test_utils::TestLogger;
|
||||||
|
|
||||||
use crate::error::GraphSyncError;
|
use crate::error::GraphSyncError;
|
||||||
use crate::RapidGossipSync;
|
use crate::RapidGossipSync;
|
||||||
@ -243,7 +245,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn network_graph_fails_to_update_from_clipped_input() {
|
fn network_graph_fails_to_update_from_clipped_input() {
|
||||||
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
let network_graph = NetworkGraph::new(block_hash);
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
|
|
||||||
let example_input = vec![
|
let example_input = vec![
|
||||||
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
|
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
|
||||||
@ -282,7 +285,8 @@ mod tests {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
let network_graph = NetworkGraph::new(block_hash);
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
|
|
||||||
assert_eq!(network_graph.read_only().channels().len(), 0);
|
assert_eq!(network_graph.read_only().channels().len(), 0);
|
||||||
|
|
||||||
@ -315,7 +319,8 @@ mod tests {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
let network_graph = NetworkGraph::new(block_hash);
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
|
|
||||||
assert_eq!(network_graph.read_only().channels().len(), 0);
|
assert_eq!(network_graph.read_only().channels().len(), 0);
|
||||||
|
|
||||||
@ -351,7 +356,8 @@ mod tests {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
let network_graph = NetworkGraph::new(block_hash);
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
|
|
||||||
assert_eq!(network_graph.read_only().channels().len(), 0);
|
assert_eq!(network_graph.read_only().channels().len(), 0);
|
||||||
|
|
||||||
@ -417,7 +423,8 @@ mod tests {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
let network_graph = NetworkGraph::new(block_hash);
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
|
|
||||||
assert_eq!(network_graph.read_only().channels().len(), 0);
|
assert_eq!(network_graph.read_only().channels().len(), 0);
|
||||||
|
|
||||||
@ -476,7 +483,8 @@ mod tests {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
let block_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
let network_graph = NetworkGraph::new(block_hash);
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||||
|
|
||||||
assert_eq!(network_graph.read_only().channels().len(), 0);
|
assert_eq!(network_graph.read_only().channels().len(), 0);
|
||||||
|
|
||||||
|
@ -7358,8 +7358,8 @@ mod tests {
|
|||||||
final_cltv_expiry_delta: TEST_FINAL_CLTV,
|
final_cltv_expiry_delta: TEST_FINAL_CLTV,
|
||||||
};
|
};
|
||||||
let route = find_route(
|
let route = find_route(
|
||||||
&nodes[0].node.get_our_node_id(), &route_params, nodes[0].network_graph, None,
|
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph.read_only(),
|
||||||
nodes[0].logger, &scorer, &random_seed_bytes
|
None, nodes[0].logger, &scorer, &random_seed_bytes
|
||||||
).unwrap();
|
).unwrap();
|
||||||
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap();
|
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap();
|
||||||
check_added_monitors!(nodes[0], 1);
|
check_added_monitors!(nodes[0], 1);
|
||||||
@ -7389,8 +7389,8 @@ mod tests {
|
|||||||
// To start (2), send a keysend payment but don't claim it.
|
// To start (2), send a keysend payment but don't claim it.
|
||||||
let payment_preimage = PaymentPreimage([42; 32]);
|
let payment_preimage = PaymentPreimage([42; 32]);
|
||||||
let route = find_route(
|
let route = find_route(
|
||||||
&nodes[0].node.get_our_node_id(), &route_params, nodes[0].network_graph, None,
|
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph.read_only(),
|
||||||
nodes[0].logger, &scorer, &random_seed_bytes
|
None, nodes[0].logger, &scorer, &random_seed_bytes
|
||||||
).unwrap();
|
).unwrap();
|
||||||
let (payment_hash, _) = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap();
|
let (payment_hash, _) = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap();
|
||||||
check_added_monitors!(nodes[0], 1);
|
check_added_monitors!(nodes[0], 1);
|
||||||
@ -7453,8 +7453,9 @@ mod tests {
|
|||||||
let scorer = test_utils::TestScorer::with_penalty(0);
|
let scorer = test_utils::TestScorer::with_penalty(0);
|
||||||
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
||||||
let route = find_route(
|
let route = find_route(
|
||||||
&payer_pubkey, &route_params, network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
|
&payer_pubkey, &route_params, &network_graph.read_only(),
|
||||||
nodes[0].logger, &scorer, &random_seed_bytes
|
Some(&first_hops.iter().collect::<Vec<_>>()), nodes[0].logger, &scorer,
|
||||||
|
&random_seed_bytes
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let test_preimage = PaymentPreimage([42; 32]);
|
let test_preimage = PaymentPreimage([42; 32]);
|
||||||
@ -7497,8 +7498,9 @@ mod tests {
|
|||||||
let scorer = test_utils::TestScorer::with_penalty(0);
|
let scorer = test_utils::TestScorer::with_penalty(0);
|
||||||
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
||||||
let route = find_route(
|
let route = find_route(
|
||||||
&payer_pubkey, &route_params, network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
|
&payer_pubkey, &route_params, &network_graph.read_only(),
|
||||||
nodes[0].logger, &scorer, &random_seed_bytes
|
Some(&first_hops.iter().collect::<Vec<_>>()), nodes[0].logger, &scorer,
|
||||||
|
&random_seed_bytes
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let test_preimage = PaymentPreimage([42; 32]);
|
let test_preimage = PaymentPreimage([42; 32]);
|
||||||
@ -7690,7 +7692,7 @@ pub mod bench {
|
|||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
let dummy_graph = NetworkGraph::new(genesis_hash);
|
let dummy_graph = NetworkGraph::new(genesis_hash, &logger_a);
|
||||||
|
|
||||||
let mut payment_count: u64 = 0;
|
let mut payment_count: u64 = 0;
|
||||||
macro_rules! send_payment {
|
macro_rules! send_payment {
|
||||||
|
@ -27,7 +27,7 @@ use util::test_utils::{panicking, TestChainMonitor};
|
|||||||
use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose};
|
use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose};
|
||||||
use util::errors::APIError;
|
use util::errors::APIError;
|
||||||
use util::config::UserConfig;
|
use util::config::UserConfig;
|
||||||
use util::ser::{ReadableArgs, Writeable, Readable};
|
use util::ser::{ReadableArgs, Writeable};
|
||||||
|
|
||||||
use bitcoin::blockdata::block::{Block, BlockHeader};
|
use bitcoin::blockdata::block::{Block, BlockHeader};
|
||||||
use bitcoin::blockdata::constants::genesis_block;
|
use bitcoin::blockdata::constants::genesis_block;
|
||||||
@ -257,7 +257,6 @@ pub struct TestChanMonCfg {
|
|||||||
pub persister: test_utils::TestPersister,
|
pub persister: test_utils::TestPersister,
|
||||||
pub logger: test_utils::TestLogger,
|
pub logger: test_utils::TestLogger,
|
||||||
pub keys_manager: test_utils::TestKeysInterface,
|
pub keys_manager: test_utils::TestKeysInterface,
|
||||||
pub network_graph: NetworkGraph,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NodeCfg<'a> {
|
pub struct NodeCfg<'a> {
|
||||||
@ -267,7 +266,7 @@ pub struct NodeCfg<'a> {
|
|||||||
pub chain_monitor: test_utils::TestChainMonitor<'a>,
|
pub chain_monitor: test_utils::TestChainMonitor<'a>,
|
||||||
pub keys_manager: &'a test_utils::TestKeysInterface,
|
pub keys_manager: &'a test_utils::TestKeysInterface,
|
||||||
pub logger: &'a test_utils::TestLogger,
|
pub logger: &'a test_utils::TestLogger,
|
||||||
pub network_graph: &'a NetworkGraph,
|
pub network_graph: NetworkGraph<&'a test_utils::TestLogger>,
|
||||||
pub node_seed: [u8; 32],
|
pub node_seed: [u8; 32],
|
||||||
pub features: InitFeatures,
|
pub features: InitFeatures,
|
||||||
}
|
}
|
||||||
@ -278,8 +277,8 @@ pub struct Node<'a, 'b: 'a, 'c: 'b> {
|
|||||||
pub chain_monitor: &'b test_utils::TestChainMonitor<'c>,
|
pub chain_monitor: &'b test_utils::TestChainMonitor<'c>,
|
||||||
pub keys_manager: &'b test_utils::TestKeysInterface,
|
pub keys_manager: &'b test_utils::TestKeysInterface,
|
||||||
pub node: &'a ChannelManager<EnforcingSigner, &'b TestChainMonitor<'c>, &'c test_utils::TestBroadcaster, &'b test_utils::TestKeysInterface, &'c test_utils::TestFeeEstimator, &'c test_utils::TestLogger>,
|
pub node: &'a ChannelManager<EnforcingSigner, &'b TestChainMonitor<'c>, &'c test_utils::TestBroadcaster, &'b test_utils::TestKeysInterface, &'c test_utils::TestFeeEstimator, &'c test_utils::TestLogger>,
|
||||||
pub network_graph: &'c NetworkGraph,
|
pub network_graph: &'b NetworkGraph<&'c test_utils::TestLogger>,
|
||||||
pub gossip_sync: P2PGossipSync<&'c NetworkGraph, &'c test_utils::TestChainSource, &'c test_utils::TestLogger>,
|
pub gossip_sync: P2PGossipSync<&'b NetworkGraph<&'c test_utils::TestLogger>, &'c test_utils::TestChainSource, &'c test_utils::TestLogger>,
|
||||||
pub node_seed: [u8; 32],
|
pub node_seed: [u8; 32],
|
||||||
pub network_payment_count: Rc<RefCell<u8>>,
|
pub network_payment_count: Rc<RefCell<u8>>,
|
||||||
pub network_chan_count: Rc<RefCell<u32>>,
|
pub network_chan_count: Rc<RefCell<u32>>,
|
||||||
@ -311,7 +310,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
|
|||||||
{
|
{
|
||||||
let mut w = test_utils::TestVecWriter(Vec::new());
|
let mut w = test_utils::TestVecWriter(Vec::new());
|
||||||
self.network_graph.write(&mut w).unwrap();
|
self.network_graph.write(&mut w).unwrap();
|
||||||
let network_graph_deser = <NetworkGraph>::read(&mut io::Cursor::new(&w.0)).unwrap();
|
let network_graph_deser = <NetworkGraph<_>>::read(&mut io::Cursor::new(&w.0), self.logger).unwrap();
|
||||||
assert!(network_graph_deser == *self.network_graph);
|
assert!(network_graph_deser == *self.network_graph);
|
||||||
let gossip_sync = P2PGossipSync::new(
|
let gossip_sync = P2PGossipSync::new(
|
||||||
&network_graph_deser, Some(self.chain_source), self.logger
|
&network_graph_deser, Some(self.chain_source), self.logger
|
||||||
@ -1923,9 +1922,8 @@ pub fn create_chanmon_cfgs(node_count: usize) -> Vec<TestChanMonCfg> {
|
|||||||
let persister = test_utils::TestPersister::new();
|
let persister = test_utils::TestPersister::new();
|
||||||
let seed = [i as u8; 32];
|
let seed = [i as u8; 32];
|
||||||
let keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
|
let keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
|
||||||
let network_graph = NetworkGraph::new(chain_source.genesis_hash);
|
|
||||||
|
|
||||||
chan_mon_cfgs.push(TestChanMonCfg{ tx_broadcaster, fee_estimator, chain_source, logger, persister, keys_manager, network_graph });
|
chan_mon_cfgs.push(TestChanMonCfg{ tx_broadcaster, fee_estimator, chain_source, logger, persister, keys_manager });
|
||||||
}
|
}
|
||||||
|
|
||||||
chan_mon_cfgs
|
chan_mon_cfgs
|
||||||
@ -1946,7 +1944,7 @@ pub fn create_node_cfgs<'a>(node_count: usize, chanmon_cfgs: &'a Vec<TestChanMon
|
|||||||
keys_manager: &chanmon_cfgs[i].keys_manager,
|
keys_manager: &chanmon_cfgs[i].keys_manager,
|
||||||
node_seed: seed,
|
node_seed: seed,
|
||||||
features: InitFeatures::known(),
|
features: InitFeatures::known(),
|
||||||
network_graph: &chanmon_cfgs[i].network_graph,
|
network_graph: NetworkGraph::new(chanmon_cfgs[i].chain_source.genesis_hash, &chanmon_cfgs[i].logger),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1992,7 +1990,7 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
|
|||||||
let connect_style = Rc::new(RefCell::new(ConnectStyle::random_style()));
|
let connect_style = Rc::new(RefCell::new(ConnectStyle::random_style()));
|
||||||
|
|
||||||
for i in 0..node_count {
|
for i in 0..node_count {
|
||||||
let gossip_sync = P2PGossipSync::new(cfgs[i].network_graph, None, cfgs[i].logger);
|
let gossip_sync = P2PGossipSync::new(&cfgs[i].network_graph, None, cfgs[i].logger);
|
||||||
nodes.push(Node{
|
nodes.push(Node{
|
||||||
chain_source: cfgs[i].chain_source, tx_broadcaster: cfgs[i].tx_broadcaster,
|
chain_source: cfgs[i].chain_source, tx_broadcaster: cfgs[i].tx_broadcaster,
|
||||||
chain_monitor: &cfgs[i].chain_monitor, keys_manager: &cfgs[i].keys_manager,
|
chain_monitor: &cfgs[i].chain_monitor, keys_manager: &cfgs[i].keys_manager,
|
||||||
|
@ -23,6 +23,7 @@ use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, PaymentId, RAAC
|
|||||||
use ln::channel::{Channel, ChannelError};
|
use ln::channel::{Channel, ChannelError};
|
||||||
use ln::{chan_utils, onion_utils};
|
use ln::{chan_utils, onion_utils};
|
||||||
use ln::chan_utils::{htlc_success_tx_weight, htlc_timeout_tx_weight, HTLCOutputInCommitment};
|
use ln::chan_utils::{htlc_success_tx_weight, htlc_timeout_tx_weight, HTLCOutputInCommitment};
|
||||||
|
use routing::gossip::NetworkGraph;
|
||||||
use routing::router::{PaymentParameters, Route, RouteHop, RouteParameters, find_route, get_route};
|
use routing::router::{PaymentParameters, Route, RouteHop, RouteParameters, find_route, get_route};
|
||||||
use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};
|
use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};
|
||||||
use ln::msgs;
|
use ln::msgs;
|
||||||
@ -5802,7 +5803,8 @@ fn test_key_derivation_params() {
|
|||||||
let seed = [42; 32];
|
let seed = [42; 32];
|
||||||
let keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
|
let keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
|
||||||
let chain_monitor = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &chanmon_cfgs[0].persister, &keys_manager);
|
let chain_monitor = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &chanmon_cfgs[0].persister, &keys_manager);
|
||||||
let node = NodeCfg { chain_source: &chanmon_cfgs[0].chain_source, logger: &chanmon_cfgs[0].logger, tx_broadcaster: &chanmon_cfgs[0].tx_broadcaster, fee_estimator: &chanmon_cfgs[0].fee_estimator, chain_monitor, keys_manager: &keys_manager, network_graph: &chanmon_cfgs[0].network_graph, node_seed: seed, features: InitFeatures::known() };
|
let network_graph = NetworkGraph::new(chanmon_cfgs[0].chain_source.genesis_hash, &chanmon_cfgs[0].logger);
|
||||||
|
let node = NodeCfg { chain_source: &chanmon_cfgs[0].chain_source, logger: &chanmon_cfgs[0].logger, tx_broadcaster: &chanmon_cfgs[0].tx_broadcaster, fee_estimator: &chanmon_cfgs[0].fee_estimator, chain_monitor, keys_manager: &keys_manager, network_graph, node_seed: seed, features: InitFeatures::known() };
|
||||||
let mut node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
|
let mut node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
|
||||||
node_cfgs.remove(0);
|
node_cfgs.remove(0);
|
||||||
node_cfgs.insert(0, node);
|
node_cfgs.insert(0, node);
|
||||||
@ -9860,7 +9862,7 @@ fn test_keysend_payments_to_public_node() {
|
|||||||
};
|
};
|
||||||
let scorer = test_utils::TestScorer::with_penalty(0);
|
let scorer = test_utils::TestScorer::with_penalty(0);
|
||||||
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
||||||
let route = find_route(&payer_pubkey, &route_params, network_graph, None, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
|
let route = find_route(&payer_pubkey, &route_params, &network_graph.read_only(), None, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
|
||||||
|
|
||||||
let test_preimage = PaymentPreimage([42; 32]);
|
let test_preimage = PaymentPreimage([42; 32]);
|
||||||
let (payment_hash, _) = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage)).unwrap();
|
let (payment_hash, _) = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage)).unwrap();
|
||||||
@ -9896,8 +9898,8 @@ fn test_keysend_payments_to_private_node() {
|
|||||||
let scorer = test_utils::TestScorer::with_penalty(0);
|
let scorer = test_utils::TestScorer::with_penalty(0);
|
||||||
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
|
||||||
let route = find_route(
|
let route = find_route(
|
||||||
&payer_pubkey, &route_params, network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
|
&payer_pubkey, &route_params, &network_graph.read_only(),
|
||||||
nodes[0].logger, &scorer, &random_seed_bytes
|
Some(&first_hops.iter().collect::<Vec<_>>()), nodes[0].logger, &scorer, &random_seed_bytes
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let test_preimage = PaymentPreimage([42; 32]);
|
let test_preimage = PaymentPreimage([42; 32]);
|
||||||
|
@ -387,7 +387,7 @@ impl Peer {
|
|||||||
/// issues such as overly long function definitions.
|
/// issues such as overly long function definitions.
|
||||||
///
|
///
|
||||||
/// (C-not exported) as Arcs don't make sense in bindings
|
/// (C-not exported) as Arcs don't make sense in bindings
|
||||||
pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArcChannelManager<M, T, F, L>>, Arc<P2PGossipSync<Arc<NetworkGraph>, Arc<C>, Arc<L>>>, Arc<L>, Arc<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<L>, Arc<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
|
||||||
@ -397,7 +397,7 @@ pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArc
|
|||||||
/// helps with issues such as long function definitions.
|
/// helps with issues such as long function definitions.
|
||||||
///
|
///
|
||||||
/// (C-not exported) as Arcs don't make sense in bindings
|
/// (C-not exported) as Arcs don't make sense in bindings
|
||||||
pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, SD, M, T, F, C, L> = PeerManager<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L>, &'e P2PGossipSync<&'g NetworkGraph, &'h C, &'f L>, &'f L, IgnoringMessageHandler>;
|
pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, SD, M, T, F, C, L> = PeerManager<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L>, &'e P2PGossipSync<&'g NetworkGraph<&'f L>, &'h C, &'f 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`].
|
||||||
|
@ -28,7 +28,7 @@ use ln::msgs::{DecodeError, ErrorAction, Init, LightningError, RoutingMessageHan
|
|||||||
use ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, OptionalField, GossipTimestampFilter};
|
use ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, OptionalField, GossipTimestampFilter};
|
||||||
use ln::msgs::{QueryChannelRange, ReplyChannelRange, QueryShortChannelIds, ReplyShortChannelIdsEnd};
|
use ln::msgs::{QueryChannelRange, ReplyChannelRange, QueryShortChannelIds, ReplyShortChannelIdsEnd};
|
||||||
use ln::msgs;
|
use ln::msgs;
|
||||||
use util::ser::{Writeable, Readable, Writer};
|
use util::ser::{Readable, ReadableArgs, Writeable, Writer};
|
||||||
use util::logger::{Logger, Level};
|
use util::logger::{Logger, Level};
|
||||||
use util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider};
|
use util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider};
|
||||||
use util::scid_utils::{block_from_scid, scid_from_parts, MAX_SCID_BLOCK};
|
use util::scid_utils::{block_from_scid, scid_from_parts, MAX_SCID_BLOCK};
|
||||||
@ -122,30 +122,16 @@ impl Readable for NodeId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the network as nodes and channels between them
|
/// Represents the network as nodes and channels between them
|
||||||
pub struct NetworkGraph {
|
pub struct NetworkGraph<L: Deref> where L::Target: Logger {
|
||||||
secp_ctx: Secp256k1<secp256k1::VerifyOnly>,
|
secp_ctx: Secp256k1<secp256k1::VerifyOnly>,
|
||||||
last_rapid_gossip_sync_timestamp: Mutex<Option<u32>>,
|
last_rapid_gossip_sync_timestamp: Mutex<Option<u32>>,
|
||||||
genesis_hash: BlockHash,
|
genesis_hash: BlockHash,
|
||||||
|
_logger: L,
|
||||||
// Lock order: channels -> nodes
|
// Lock order: channels -> nodes
|
||||||
channels: RwLock<BTreeMap<u64, ChannelInfo>>,
|
channels: RwLock<BTreeMap<u64, ChannelInfo>>,
|
||||||
nodes: RwLock<BTreeMap<NodeId, NodeInfo>>,
|
nodes: RwLock<BTreeMap<NodeId, NodeInfo>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for NetworkGraph {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
let channels = self.channels.read().unwrap();
|
|
||||||
let nodes = self.nodes.read().unwrap();
|
|
||||||
let last_rapid_gossip_sync_timestamp = self.get_last_rapid_gossip_sync_timestamp();
|
|
||||||
Self {
|
|
||||||
secp_ctx: Secp256k1::verification_only(),
|
|
||||||
genesis_hash: self.genesis_hash.clone(),
|
|
||||||
channels: RwLock::new(channels.clone()),
|
|
||||||
nodes: RwLock::new(nodes.clone()),
|
|
||||||
last_rapid_gossip_sync_timestamp: Mutex::new(last_rapid_gossip_sync_timestamp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A read-only view of [`NetworkGraph`].
|
/// A read-only view of [`NetworkGraph`].
|
||||||
pub struct ReadOnlyNetworkGraph<'a> {
|
pub struct ReadOnlyNetworkGraph<'a> {
|
||||||
channels: RwLockReadGuard<'a, BTreeMap<u64, ChannelInfo>>,
|
channels: RwLockReadGuard<'a, BTreeMap<u64, ChannelInfo>>,
|
||||||
@ -198,7 +184,7 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref> EventHandler for P2PGossipSync<G, C, L>
|
impl<G: Deref<Target=NetworkGraph<L>>, C: Deref, L: Deref> EventHandler for P2PGossipSync<G, C, L>
|
||||||
where C::Target: chain::Access, L::Target: Logger {
|
where C::Target: chain::Access, L::Target: Logger {
|
||||||
fn handle_event(&self, event: &Event) {
|
fn handle_event(&self, event: &Event) {
|
||||||
if let Event::PaymentPathFailed { payment_hash: _, rejected_by_dest: _, network_update, .. } = event {
|
if let Event::PaymentPathFailed { payment_hash: _, rejected_by_dest: _, network_update, .. } = event {
|
||||||
@ -217,7 +203,7 @@ where C::Target: chain::Access, L::Target: Logger {
|
|||||||
///
|
///
|
||||||
/// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
|
/// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
|
||||||
/// [`NetworkGraph`].
|
/// [`NetworkGraph`].
|
||||||
pub struct P2PGossipSync<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref>
|
pub struct P2PGossipSync<G: Deref<Target=NetworkGraph<L>>, C: Deref, L: Deref>
|
||||||
where C::Target: chain::Access, L::Target: Logger
|
where C::Target: chain::Access, L::Target: Logger
|
||||||
{
|
{
|
||||||
network_graph: G,
|
network_graph: G,
|
||||||
@ -227,7 +213,7 @@ where C::Target: chain::Access, L::Target: Logger
|
|||||||
logger: L,
|
logger: L,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref> P2PGossipSync<G, C, L>
|
impl<G: Deref<Target=NetworkGraph<L>>, C: Deref, L: Deref> P2PGossipSync<G, C, L>
|
||||||
where C::Target: chain::Access, L::Target: Logger
|
where C::Target: chain::Access, L::Target: Logger
|
||||||
{
|
{
|
||||||
/// Creates a new tracker of the actual state of the network of channels and nodes,
|
/// Creates a new tracker of the actual state of the network of channels and nodes,
|
||||||
@ -316,7 +302,7 @@ macro_rules! secp_verify_sig {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref> RoutingMessageHandler for P2PGossipSync<G, C, L>
|
impl<G: Deref<Target=NetworkGraph<L>>, C: Deref, L: Deref> RoutingMessageHandler for P2PGossipSync<G, C, L>
|
||||||
where C::Target: chain::Access, L::Target: Logger
|
where C::Target: chain::Access, L::Target: Logger
|
||||||
{
|
{
|
||||||
fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> {
|
fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> {
|
||||||
@ -605,7 +591,7 @@ where C::Target: chain::Access, L::Target: Logger
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref> MessageSendEventsProvider for P2PGossipSync<G, C, L>
|
impl<G: Deref<Target=NetworkGraph<L>>, C: Deref, L: Deref> MessageSendEventsProvider for P2PGossipSync<G, C, L>
|
||||||
where
|
where
|
||||||
C::Target: chain::Access,
|
C::Target: chain::Access,
|
||||||
L::Target: Logger,
|
L::Target: Logger,
|
||||||
@ -975,7 +961,7 @@ impl_writeable_tlv_based!(NodeInfo, {
|
|||||||
const SERIALIZATION_VERSION: u8 = 1;
|
const SERIALIZATION_VERSION: u8 = 1;
|
||||||
const MIN_SERIALIZATION_VERSION: u8 = 1;
|
const MIN_SERIALIZATION_VERSION: u8 = 1;
|
||||||
|
|
||||||
impl Writeable for NetworkGraph {
|
impl<L: Deref> Writeable for NetworkGraph<L> where L::Target: Logger {
|
||||||
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
|
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
|
||||||
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
|
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
|
||||||
|
|
||||||
@ -1001,8 +987,8 @@ impl Writeable for NetworkGraph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Readable for NetworkGraph {
|
impl<L: Deref> ReadableArgs<L> for NetworkGraph<L> where L::Target: Logger {
|
||||||
fn read<R: io::Read>(reader: &mut R) -> Result<NetworkGraph, DecodeError> {
|
fn read<R: io::Read>(reader: &mut R, _logger: L) -> Result<NetworkGraph<L>, DecodeError> {
|
||||||
let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
|
let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
|
||||||
|
|
||||||
let genesis_hash: BlockHash = Readable::read(reader)?;
|
let genesis_hash: BlockHash = Readable::read(reader)?;
|
||||||
@ -1029,6 +1015,7 @@ impl Readable for NetworkGraph {
|
|||||||
Ok(NetworkGraph {
|
Ok(NetworkGraph {
|
||||||
secp_ctx: Secp256k1::verification_only(),
|
secp_ctx: Secp256k1::verification_only(),
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
|
_logger,
|
||||||
channels: RwLock::new(channels),
|
channels: RwLock::new(channels),
|
||||||
nodes: RwLock::new(nodes),
|
nodes: RwLock::new(nodes),
|
||||||
last_rapid_gossip_sync_timestamp: Mutex::new(last_rapid_gossip_sync_timestamp),
|
last_rapid_gossip_sync_timestamp: Mutex::new(last_rapid_gossip_sync_timestamp),
|
||||||
@ -1036,7 +1023,7 @@ impl Readable for NetworkGraph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for NetworkGraph {
|
impl<L: Deref> fmt::Display for NetworkGraph<L> where L::Target: Logger {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
writeln!(f, "Network map\n[Channels]")?;
|
writeln!(f, "Network map\n[Channels]")?;
|
||||||
for (key, val) in self.channels.read().unwrap().iter() {
|
for (key, val) in self.channels.read().unwrap().iter() {
|
||||||
@ -1050,7 +1037,7 @@ impl fmt::Display for NetworkGraph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for NetworkGraph {
|
impl<L: Deref> PartialEq for NetworkGraph<L> where L::Target: Logger {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.genesis_hash == other.genesis_hash &&
|
self.genesis_hash == other.genesis_hash &&
|
||||||
*self.channels.read().unwrap() == *other.channels.read().unwrap() &&
|
*self.channels.read().unwrap() == *other.channels.read().unwrap() &&
|
||||||
@ -1058,12 +1045,13 @@ impl PartialEq for NetworkGraph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetworkGraph {
|
impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
|
||||||
/// Creates a new, empty, network graph.
|
/// Creates a new, empty, network graph.
|
||||||
pub fn new(genesis_hash: BlockHash) -> NetworkGraph {
|
pub fn new(genesis_hash: BlockHash, _logger: L) -> NetworkGraph<L> {
|
||||||
Self {
|
Self {
|
||||||
secp_ctx: Secp256k1::verification_only(),
|
secp_ctx: Secp256k1::verification_only(),
|
||||||
genesis_hash,
|
genesis_hash,
|
||||||
|
_logger,
|
||||||
channels: RwLock::new(BTreeMap::new()),
|
channels: RwLock::new(BTreeMap::new()),
|
||||||
nodes: RwLock::new(BTreeMap::new()),
|
nodes: RwLock::new(BTreeMap::new()),
|
||||||
last_rapid_gossip_sync_timestamp: Mutex::new(None),
|
last_rapid_gossip_sync_timestamp: Mutex::new(None),
|
||||||
@ -1651,7 +1639,7 @@ mod tests {
|
|||||||
ReplyChannelRange, QueryChannelRange, QueryShortChannelIds, MAX_VALUE_MSAT};
|
ReplyChannelRange, QueryChannelRange, QueryShortChannelIds, MAX_VALUE_MSAT};
|
||||||
use util::test_utils;
|
use util::test_utils;
|
||||||
use util::logger::Logger;
|
use util::logger::Logger;
|
||||||
use util::ser::{Readable, Writeable};
|
use util::ser::{ReadableArgs, Writeable};
|
||||||
use util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider};
|
use util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider};
|
||||||
use util::scid_utils::scid_from_parts;
|
use util::scid_utils::scid_from_parts;
|
||||||
|
|
||||||
@ -1675,13 +1663,15 @@ mod tests {
|
|||||||
use prelude::*;
|
use prelude::*;
|
||||||
use sync::Arc;
|
use sync::Arc;
|
||||||
|
|
||||||
fn create_network_graph() -> NetworkGraph {
|
fn create_network_graph() -> NetworkGraph<Arc<test_utils::TestLogger>> {
|
||||||
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
NetworkGraph::new(genesis_hash)
|
let logger = Arc::new(test_utils::TestLogger::new());
|
||||||
|
NetworkGraph::new(genesis_hash, logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_gossip_sync(network_graph: &NetworkGraph) -> (
|
fn create_gossip_sync(network_graph: &NetworkGraph<Arc<test_utils::TestLogger>>) -> (
|
||||||
Secp256k1<All>, P2PGossipSync<&NetworkGraph, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>
|
Secp256k1<All>, P2PGossipSync<&NetworkGraph<Arc<test_utils::TestLogger>>,
|
||||||
|
Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>
|
||||||
) {
|
) {
|
||||||
let secp_ctx = Secp256k1::new();
|
let secp_ctx = Secp256k1::new();
|
||||||
let logger = Arc::new(test_utils::TestLogger::new());
|
let logger = Arc::new(test_utils::TestLogger::new());
|
||||||
@ -1854,7 +1844,8 @@ mod tests {
|
|||||||
let valid_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx);
|
let valid_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx);
|
||||||
|
|
||||||
// Test if the UTXO lookups were not supported
|
// Test if the UTXO lookups were not supported
|
||||||
let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
|
let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
|
||||||
let mut gossip_sync = P2PGossipSync::new(&network_graph, None, Arc::clone(&logger));
|
let mut gossip_sync = P2PGossipSync::new(&network_graph, None, Arc::clone(&logger));
|
||||||
match gossip_sync.handle_channel_announcement(&valid_announcement) {
|
match gossip_sync.handle_channel_announcement(&valid_announcement) {
|
||||||
Ok(res) => assert!(res),
|
Ok(res) => assert!(res),
|
||||||
@ -1878,7 +1869,7 @@ mod tests {
|
|||||||
// Test if an associated transaction were not on-chain (or not confirmed).
|
// Test if an associated transaction were not on-chain (or not confirmed).
|
||||||
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
||||||
*chain_source.utxo_ret.lock().unwrap() = Err(chain::AccessError::UnknownTx);
|
*chain_source.utxo_ret.lock().unwrap() = Err(chain::AccessError::UnknownTx);
|
||||||
let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
|
let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
|
||||||
gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger));
|
gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger));
|
||||||
|
|
||||||
let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| {
|
let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| {
|
||||||
@ -1962,7 +1953,8 @@ mod tests {
|
|||||||
let secp_ctx = Secp256k1::new();
|
let secp_ctx = Secp256k1::new();
|
||||||
let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::new());
|
let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::new());
|
||||||
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
||||||
let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
|
let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
|
||||||
let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger));
|
let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger));
|
||||||
|
|
||||||
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
|
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
|
||||||
@ -2065,7 +2057,7 @@ mod tests {
|
|||||||
let logger = test_utils::TestLogger::new();
|
let logger = test_utils::TestLogger::new();
|
||||||
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
||||||
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
let network_graph = NetworkGraph::new(genesis_hash);
|
let network_graph = NetworkGraph::new(genesis_hash, &logger);
|
||||||
let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), &logger);
|
let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), &logger);
|
||||||
let secp_ctx = Secp256k1::new();
|
let secp_ctx = Secp256k1::new();
|
||||||
|
|
||||||
@ -2169,7 +2161,7 @@ mod tests {
|
|||||||
let logger = test_utils::TestLogger::new();
|
let logger = test_utils::TestLogger::new();
|
||||||
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
||||||
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
let network_graph = NetworkGraph::new(genesis_hash);
|
let network_graph = NetworkGraph::new(genesis_hash, &logger);
|
||||||
let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), &logger);
|
let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), &logger);
|
||||||
let secp_ctx = Secp256k1::new();
|
let secp_ctx = Secp256k1::new();
|
||||||
|
|
||||||
@ -2382,7 +2374,9 @@ mod tests {
|
|||||||
assert!(!network_graph.read_only().nodes().is_empty());
|
assert!(!network_graph.read_only().nodes().is_empty());
|
||||||
assert!(!network_graph.read_only().channels().is_empty());
|
assert!(!network_graph.read_only().channels().is_empty());
|
||||||
network_graph.write(&mut w).unwrap();
|
network_graph.write(&mut w).unwrap();
|
||||||
assert!(<NetworkGraph>::read(&mut io::Cursor::new(&w.0)).unwrap() == network_graph);
|
|
||||||
|
let logger = Arc::new(test_utils::TestLogger::new());
|
||||||
|
assert!(<NetworkGraph<_>>::read(&mut io::Cursor::new(&w.0), logger).unwrap() == network_graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -2392,7 +2386,9 @@ mod tests {
|
|||||||
|
|
||||||
let mut w = test_utils::TestVecWriter(Vec::new());
|
let mut w = test_utils::TestVecWriter(Vec::new());
|
||||||
network_graph.write(&mut w).unwrap();
|
network_graph.write(&mut w).unwrap();
|
||||||
let reassembled_network_graph: NetworkGraph = Readable::read(&mut io::Cursor::new(&w.0)).unwrap();
|
|
||||||
|
let logger = Arc::new(test_utils::TestLogger::new());
|
||||||
|
let reassembled_network_graph: NetworkGraph<_> = ReadableArgs::read(&mut io::Cursor::new(&w.0), logger).unwrap();
|
||||||
assert!(reassembled_network_graph == network_graph);
|
assert!(reassembled_network_graph == network_graph);
|
||||||
assert_eq!(reassembled_network_graph.get_last_rapid_gossip_sync_timestamp().unwrap(), 42);
|
assert_eq!(reassembled_network_graph.get_last_rapid_gossip_sync_timestamp().unwrap(), 42);
|
||||||
}
|
}
|
||||||
@ -2681,7 +2677,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn do_handling_query_channel_range(
|
fn do_handling_query_channel_range(
|
||||||
gossip_sync: &P2PGossipSync<&NetworkGraph, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
|
gossip_sync: &P2PGossipSync<&NetworkGraph<Arc<test_utils::TestLogger>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
|
||||||
test_node_id: &PublicKey,
|
test_node_id: &PublicKey,
|
||||||
msg: QueryChannelRange,
|
msg: QueryChannelRange,
|
||||||
expected_ok: bool,
|
expected_ok: bool,
|
||||||
@ -2754,18 +2750,20 @@ mod benches {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn read_network_graph(bench: &mut Bencher) {
|
fn read_network_graph(bench: &mut Bencher) {
|
||||||
|
let logger = ::util::test_utils::TestLogger::new();
|
||||||
let mut d = ::routing::router::test_utils::get_route_file().unwrap();
|
let mut d = ::routing::router::test_utils::get_route_file().unwrap();
|
||||||
let mut v = Vec::new();
|
let mut v = Vec::new();
|
||||||
d.read_to_end(&mut v).unwrap();
|
d.read_to_end(&mut v).unwrap();
|
||||||
bench.iter(|| {
|
bench.iter(|| {
|
||||||
let _ = NetworkGraph::read(&mut std::io::Cursor::new(&v)).unwrap();
|
let _ = NetworkGraph::read(&mut std::io::Cursor::new(&v), &logger).unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn write_network_graph(bench: &mut Bencher) {
|
fn write_network_graph(bench: &mut Bencher) {
|
||||||
|
let logger = ::util::test_utils::TestLogger::new();
|
||||||
let mut d = ::routing::router::test_utils::get_route_file().unwrap();
|
let mut d = ::routing::router::test_utils::get_route_file().unwrap();
|
||||||
let net_graph = NetworkGraph::read(&mut d).unwrap();
|
let net_graph = NetworkGraph::read(&mut d, &logger).unwrap();
|
||||||
bench.iter(|| {
|
bench.iter(|| {
|
||||||
let _ = net_graph.encode();
|
let _ = net_graph.encode();
|
||||||
});
|
});
|
||||||
|
@ -17,7 +17,7 @@ use bitcoin::secp256k1::PublicKey;
|
|||||||
use ln::channelmanager::ChannelDetails;
|
use ln::channelmanager::ChannelDetails;
|
||||||
use ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures};
|
use ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures};
|
||||||
use ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
|
use ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
|
||||||
use routing::gossip::{DirectedChannelInfoWithUpdate, EffectiveCapacity, NetworkGraph, ReadOnlyNetworkGraph, NodeId, RoutingFees};
|
use routing::gossip::{DirectedChannelInfoWithUpdate, EffectiveCapacity, ReadOnlyNetworkGraph, NodeId, RoutingFees};
|
||||||
use routing::scoring::{ChannelUsage, Score};
|
use routing::scoring::{ChannelUsage, Score};
|
||||||
use util::ser::{Writeable, Readable, Writer};
|
use util::ser::{Writeable, Readable, Writer};
|
||||||
use util::logger::{Level, Logger};
|
use util::logger::{Level, Logger};
|
||||||
@ -369,7 +369,7 @@ enum CandidateRouteHop<'a> {
|
|||||||
FirstHop {
|
FirstHop {
|
||||||
details: &'a ChannelDetails,
|
details: &'a ChannelDetails,
|
||||||
},
|
},
|
||||||
/// A hop found in the [`NetworkGraph`], where the channel capacity may or may not be known.
|
/// A hop found in the [`ReadOnlyNetworkGraph`], where the channel capacity may be unknown.
|
||||||
PublicHop {
|
PublicHop {
|
||||||
info: DirectedChannelInfoWithUpdate<'a>,
|
info: DirectedChannelInfoWithUpdate<'a>,
|
||||||
short_channel_id: u64,
|
short_channel_id: u64,
|
||||||
@ -650,8 +650,8 @@ fn default_node_features() -> NodeFeatures {
|
|||||||
/// Private routing paths between a public node and the target may be included in `params.payee`.
|
/// Private routing paths between a public node and the target may be included in `params.payee`.
|
||||||
///
|
///
|
||||||
/// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
|
/// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
|
||||||
/// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of our local
|
/// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
|
||||||
/// channels from [`NetworkGraph`] will be ignored, and only those in `first_hops` will be used.
|
/// from `network_graph` will be ignored, and only those in `first_hops` will be used.
|
||||||
///
|
///
|
||||||
/// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
|
/// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
|
||||||
/// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
|
/// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
|
||||||
@ -670,16 +670,17 @@ fn default_node_features() -> NodeFeatures {
|
|||||||
///
|
///
|
||||||
/// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
|
/// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
|
||||||
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
|
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
|
||||||
|
/// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
|
||||||
pub fn find_route<L: Deref, S: Score>(
|
pub fn find_route<L: Deref, S: Score>(
|
||||||
our_node_pubkey: &PublicKey, route_params: &RouteParameters, network: &NetworkGraph,
|
our_node_pubkey: &PublicKey, route_params: &RouteParameters,
|
||||||
first_hops: Option<&[&ChannelDetails]>, logger: L, scorer: &S, random_seed_bytes: &[u8; 32]
|
network_graph: &ReadOnlyNetworkGraph, first_hops: Option<&[&ChannelDetails]>, logger: L,
|
||||||
|
scorer: &S, random_seed_bytes: &[u8; 32]
|
||||||
) -> Result<Route, LightningError>
|
) -> Result<Route, LightningError>
|
||||||
where L::Target: Logger {
|
where L::Target: Logger {
|
||||||
let network_graph = network.read_only();
|
let mut route = get_route(our_node_pubkey, &route_params.payment_params, network_graph, first_hops,
|
||||||
let mut route = get_route(our_node_pubkey, &route_params.payment_params, &network_graph, first_hops,
|
|
||||||
route_params.final_value_msat, route_params.final_cltv_expiry_delta, logger, scorer,
|
route_params.final_value_msat, route_params.final_cltv_expiry_delta, logger, scorer,
|
||||||
random_seed_bytes)?;
|
random_seed_bytes)?;
|
||||||
add_random_cltv_offset(&mut route, &route_params.payment_params, &network_graph, random_seed_bytes);
|
add_random_cltv_offset(&mut route, &route_params.payment_params, network_graph, random_seed_bytes);
|
||||||
Ok(route)
|
Ok(route)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1787,11 +1788,10 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
|
|||||||
///
|
///
|
||||||
/// Re-uses logic from `find_route`, so the restrictions described there also apply here.
|
/// Re-uses logic from `find_route`, so the restrictions described there also apply here.
|
||||||
pub fn build_route_from_hops<L: Deref>(
|
pub fn build_route_from_hops<L: Deref>(
|
||||||
our_node_pubkey: &PublicKey, hops: &[PublicKey], route_params: &RouteParameters, network: &NetworkGraph,
|
our_node_pubkey: &PublicKey, hops: &[PublicKey], route_params: &RouteParameters,
|
||||||
logger: L, random_seed_bytes: &[u8; 32]
|
network_graph: &ReadOnlyNetworkGraph, logger: L, random_seed_bytes: &[u8; 32]
|
||||||
) -> Result<Route, LightningError>
|
) -> Result<Route, LightningError>
|
||||||
where L::Target: Logger {
|
where L::Target: Logger {
|
||||||
let network_graph = network.read_only();
|
|
||||||
let mut route = build_route_from_hops_internal(
|
let mut route = build_route_from_hops_internal(
|
||||||
our_node_pubkey, hops, &route_params.payment_params, &network_graph,
|
our_node_pubkey, hops, &route_params.payment_params, &network_graph,
|
||||||
route_params.final_value_msat, route_params.final_cltv_expiry_delta, logger, random_seed_bytes)?;
|
route_params.final_value_msat, route_params.final_cltv_expiry_delta, logger, random_seed_bytes)?;
|
||||||
@ -1926,7 +1926,7 @@ mod tests {
|
|||||||
|
|
||||||
// Using the same keys for LN and BTC ids
|
// Using the same keys for LN and BTC ids
|
||||||
fn add_channel(
|
fn add_channel(
|
||||||
gossip_sync: &P2PGossipSync<Arc<NetworkGraph>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
|
gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
|
||||||
secp_ctx: &Secp256k1<All>, node_1_privkey: &SecretKey, node_2_privkey: &SecretKey, features: ChannelFeatures, short_channel_id: u64
|
secp_ctx: &Secp256k1<All>, node_1_privkey: &SecretKey, node_2_privkey: &SecretKey, features: ChannelFeatures, short_channel_id: u64
|
||||||
) {
|
) {
|
||||||
let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey);
|
let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey);
|
||||||
@ -1958,7 +1958,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_channel(
|
fn update_channel(
|
||||||
gossip_sync: &P2PGossipSync<Arc<NetworkGraph>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
|
gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
|
||||||
secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, update: UnsignedChannelUpdate
|
secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, update: UnsignedChannelUpdate
|
||||||
) {
|
) {
|
||||||
let msghash = hash_to_message!(&Sha256dHash::hash(&update.encode()[..])[..]);
|
let msghash = hash_to_message!(&Sha256dHash::hash(&update.encode()[..])[..]);
|
||||||
@ -1974,7 +1974,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_or_update_node(
|
fn add_or_update_node(
|
||||||
gossip_sync: &P2PGossipSync<Arc<NetworkGraph>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
|
gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
|
||||||
secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, features: NodeFeatures, timestamp: u32
|
secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, features: NodeFeatures, timestamp: u32
|
||||||
) {
|
) {
|
||||||
let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey);
|
let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey);
|
||||||
@ -2029,14 +2029,15 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn build_line_graph() -> (
|
fn build_line_graph() -> (
|
||||||
Secp256k1<All>, sync::Arc<NetworkGraph>, P2PGossipSync<sync::Arc<NetworkGraph>,
|
Secp256k1<All>, sync::Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
|
||||||
sync::Arc<test_utils::TestChainSource>, sync::Arc<crate::util::test_utils::TestLogger>>,
|
P2PGossipSync<sync::Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, sync::Arc<test_utils::TestChainSource>, sync::Arc<test_utils::TestLogger>>,
|
||||||
sync::Arc<test_utils::TestChainSource>, sync::Arc<test_utils::TestLogger>,
|
sync::Arc<test_utils::TestChainSource>, sync::Arc<test_utils::TestLogger>,
|
||||||
) {
|
) {
|
||||||
let secp_ctx = Secp256k1::new();
|
let secp_ctx = Secp256k1::new();
|
||||||
let logger = Arc::new(test_utils::TestLogger::new());
|
let logger = Arc::new(test_utils::TestLogger::new());
|
||||||
let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
||||||
let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
|
let network_graph = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
|
||||||
let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
|
let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
|
||||||
|
|
||||||
// Build network from our_id to node 19:
|
// Build network from our_id to node 19:
|
||||||
@ -2081,15 +2082,16 @@ mod tests {
|
|||||||
|
|
||||||
fn build_graph() -> (
|
fn build_graph() -> (
|
||||||
Secp256k1<All>,
|
Secp256k1<All>,
|
||||||
sync::Arc<NetworkGraph>,
|
sync::Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
|
||||||
P2PGossipSync<sync::Arc<NetworkGraph>, sync::Arc<test_utils::TestChainSource>, sync::Arc<crate::util::test_utils::TestLogger>>,
|
P2PGossipSync<sync::Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, sync::Arc<test_utils::TestChainSource>, sync::Arc<test_utils::TestLogger>>,
|
||||||
sync::Arc<test_utils::TestChainSource>,
|
sync::Arc<test_utils::TestChainSource>,
|
||||||
sync::Arc<test_utils::TestLogger>,
|
sync::Arc<test_utils::TestLogger>,
|
||||||
) {
|
) {
|
||||||
let secp_ctx = Secp256k1::new();
|
let secp_ctx = Secp256k1::new();
|
||||||
let logger = Arc::new(test_utils::TestLogger::new());
|
let logger = Arc::new(test_utils::TestLogger::new());
|
||||||
let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
|
||||||
let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
|
let network_graph = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
|
||||||
let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
|
let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
|
||||||
// Build network from our_id to node6:
|
// Build network from our_id to node6:
|
||||||
//
|
//
|
||||||
@ -3489,8 +3491,12 @@ mod tests {
|
|||||||
let scorer = test_utils::TestScorer::with_penalty(0);
|
let scorer = test_utils::TestScorer::with_penalty(0);
|
||||||
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
|
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
|
||||||
let random_seed_bytes = keys_manager.get_secure_random_bytes();
|
let random_seed_bytes = keys_manager.get_secure_random_bytes();
|
||||||
get_route(&source_node_id, &payment_params, &NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()).read_only(),
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
Some(&our_chans.iter().collect::<Vec<_>>()), route_val, 42, &test_utils::TestLogger::new(), &scorer, &random_seed_bytes)
|
let logger = test_utils::TestLogger::new();
|
||||||
|
let network_graph = NetworkGraph::new(genesis_hash, &logger);
|
||||||
|
let route = get_route(&source_node_id, &payment_params, &network_graph.read_only(),
|
||||||
|
Some(&our_chans.iter().collect::<Vec<_>>()), route_val, 42, &logger, &scorer, &random_seed_bytes);
|
||||||
|
route
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -4882,8 +4888,9 @@ mod tests {
|
|||||||
// payment) htlc_minimum_msat. In the original algorithm, this resulted in node4's
|
// payment) htlc_minimum_msat. In the original algorithm, this resulted in node4's
|
||||||
// "previous hop" being set to node 3, creating a loop in the path.
|
// "previous hop" being set to node 3, creating a loop in the path.
|
||||||
let secp_ctx = Secp256k1::new();
|
let secp_ctx = Secp256k1::new();
|
||||||
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
let logger = Arc::new(test_utils::TestLogger::new());
|
let logger = Arc::new(test_utils::TestLogger::new());
|
||||||
let network = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
|
let network = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
|
||||||
let gossip_sync = P2PGossipSync::new(Arc::clone(&network), None, Arc::clone(&logger));
|
let gossip_sync = P2PGossipSync::new(Arc::clone(&network), None, Arc::clone(&logger));
|
||||||
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
|
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
|
||||||
let scorer = test_utils::TestScorer::with_penalty(0);
|
let scorer = test_utils::TestScorer::with_penalty(0);
|
||||||
@ -5148,8 +5155,9 @@ mod tests {
|
|||||||
// route over multiple channels with the same first hop.
|
// route over multiple channels with the same first hop.
|
||||||
let secp_ctx = Secp256k1::new();
|
let secp_ctx = Secp256k1::new();
|
||||||
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
|
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
|
||||||
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
let logger = Arc::new(test_utils::TestLogger::new());
|
let logger = Arc::new(test_utils::TestLogger::new());
|
||||||
let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
|
let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
|
||||||
let scorer = test_utils::TestScorer::with_penalty(0);
|
let scorer = test_utils::TestScorer::with_penalty(0);
|
||||||
let payment_params = PaymentParameters::from_node_id(nodes[0]).with_features(InvoiceFeatures::known());
|
let payment_params = PaymentParameters::from_node_id(nodes[0]).with_features(InvoiceFeatures::known());
|
||||||
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
|
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
|
||||||
@ -5587,7 +5595,7 @@ mod tests {
|
|||||||
seed
|
seed
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no-std"))]
|
#[cfg(not(feature = "no-std"))]
|
||||||
use util::ser::Readable;
|
use util::ser::ReadableArgs;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(feature = "no-std"))]
|
#[cfg(not(feature = "no-std"))]
|
||||||
@ -5601,7 +5609,8 @@ mod tests {
|
|||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let graph = NetworkGraph::read(&mut d).unwrap();
|
let logger = test_utils::TestLogger::new();
|
||||||
|
let graph = NetworkGraph::read(&mut d, &logger).unwrap();
|
||||||
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
|
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
|
||||||
let random_seed_bytes = keys_manager.get_secure_random_bytes();
|
let random_seed_bytes = keys_manager.get_secure_random_bytes();
|
||||||
|
|
||||||
@ -5617,7 +5626,6 @@ mod tests {
|
|||||||
let payment_params = PaymentParameters::from_node_id(dst);
|
let payment_params = PaymentParameters::from_node_id(dst);
|
||||||
let amt = seed as u64 % 200_000_000;
|
let amt = seed as u64 % 200_000_000;
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let logger = test_utils::TestLogger::new();
|
|
||||||
let scorer = ProbabilisticScorer::new(params, &graph, &logger);
|
let scorer = ProbabilisticScorer::new(params, &graph, &logger);
|
||||||
if get_route(src, &payment_params, &graph.read_only(), None, amt, 42, &logger, &scorer, &random_seed_bytes).is_ok() {
|
if get_route(src, &payment_params, &graph.read_only(), None, amt, 42, &logger, &scorer, &random_seed_bytes).is_ok() {
|
||||||
continue 'load_endpoints;
|
continue 'load_endpoints;
|
||||||
@ -5638,7 +5646,8 @@ mod tests {
|
|||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let graph = NetworkGraph::read(&mut d).unwrap();
|
let logger = test_utils::TestLogger::new();
|
||||||
|
let graph = NetworkGraph::read(&mut d, &logger).unwrap();
|
||||||
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
|
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
|
||||||
let random_seed_bytes = keys_manager.get_secure_random_bytes();
|
let random_seed_bytes = keys_manager.get_secure_random_bytes();
|
||||||
|
|
||||||
@ -5654,7 +5663,6 @@ mod tests {
|
|||||||
let payment_params = PaymentParameters::from_node_id(dst).with_features(InvoiceFeatures::known());
|
let payment_params = PaymentParameters::from_node_id(dst).with_features(InvoiceFeatures::known());
|
||||||
let amt = seed as u64 % 200_000_000;
|
let amt = seed as u64 % 200_000_000;
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let logger = test_utils::TestLogger::new();
|
|
||||||
let scorer = ProbabilisticScorer::new(params, &graph, &logger);
|
let scorer = ProbabilisticScorer::new(params, &graph, &logger);
|
||||||
if get_route(src, &payment_params, &graph.read_only(), None, amt, 42, &logger, &scorer, &random_seed_bytes).is_ok() {
|
if get_route(src, &payment_params, &graph.read_only(), None, amt, 42, &logger, &scorer, &random_seed_bytes).is_ok() {
|
||||||
continue 'load_endpoints;
|
continue 'load_endpoints;
|
||||||
@ -5700,9 +5708,10 @@ mod benches {
|
|||||||
use chain::keysinterface::{KeysManager,KeysInterface};
|
use chain::keysinterface::{KeysManager,KeysInterface};
|
||||||
use ln::channelmanager::{ChannelCounterparty, ChannelDetails};
|
use ln::channelmanager::{ChannelCounterparty, ChannelDetails};
|
||||||
use ln::features::{InitFeatures, InvoiceFeatures};
|
use ln::features::{InitFeatures, InvoiceFeatures};
|
||||||
|
use routing::gossip::NetworkGraph;
|
||||||
use routing::scoring::{FixedPenaltyScorer, ProbabilisticScorer, ProbabilisticScoringParameters};
|
use routing::scoring::{FixedPenaltyScorer, ProbabilisticScorer, ProbabilisticScoringParameters};
|
||||||
use util::logger::{Logger, Record};
|
use util::logger::{Logger, Record};
|
||||||
use util::test_utils::TestLogger;
|
use util::ser::ReadableArgs;
|
||||||
|
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
|
||||||
@ -5711,9 +5720,9 @@ mod benches {
|
|||||||
fn log(&self, _record: &Record) {}
|
fn log(&self, _record: &Record) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_network_graph() -> NetworkGraph {
|
fn read_network_graph(logger: &DummyLogger) -> NetworkGraph<&DummyLogger> {
|
||||||
let mut d = test_utils::get_route_file().unwrap();
|
let mut d = test_utils::get_route_file().unwrap();
|
||||||
NetworkGraph::read(&mut d).unwrap()
|
NetworkGraph::read(&mut d, logger).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn payer_pubkey() -> PublicKey {
|
fn payer_pubkey() -> PublicKey {
|
||||||
@ -5760,22 +5769,24 @@ mod benches {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn generate_routes_with_zero_penalty_scorer(bench: &mut Bencher) {
|
fn generate_routes_with_zero_penalty_scorer(bench: &mut Bencher) {
|
||||||
let network_graph = read_network_graph();
|
let logger = DummyLogger {};
|
||||||
|
let network_graph = read_network_graph(&logger);
|
||||||
let scorer = FixedPenaltyScorer::with_penalty(0);
|
let scorer = FixedPenaltyScorer::with_penalty(0);
|
||||||
generate_routes(bench, &network_graph, scorer, InvoiceFeatures::empty());
|
generate_routes(bench, &network_graph, scorer, InvoiceFeatures::empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn generate_mpp_routes_with_zero_penalty_scorer(bench: &mut Bencher) {
|
fn generate_mpp_routes_with_zero_penalty_scorer(bench: &mut Bencher) {
|
||||||
let network_graph = read_network_graph();
|
let logger = DummyLogger {};
|
||||||
|
let network_graph = read_network_graph(&logger);
|
||||||
let scorer = FixedPenaltyScorer::with_penalty(0);
|
let scorer = FixedPenaltyScorer::with_penalty(0);
|
||||||
generate_routes(bench, &network_graph, scorer, InvoiceFeatures::known());
|
generate_routes(bench, &network_graph, scorer, InvoiceFeatures::known());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn generate_routes_with_probabilistic_scorer(bench: &mut Bencher) {
|
fn generate_routes_with_probabilistic_scorer(bench: &mut Bencher) {
|
||||||
let logger = TestLogger::new();
|
let logger = DummyLogger {};
|
||||||
let network_graph = read_network_graph();
|
let network_graph = read_network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
||||||
generate_routes(bench, &network_graph, scorer, InvoiceFeatures::empty());
|
generate_routes(bench, &network_graph, scorer, InvoiceFeatures::empty());
|
||||||
@ -5783,15 +5794,16 @@ mod benches {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn generate_mpp_routes_with_probabilistic_scorer(bench: &mut Bencher) {
|
fn generate_mpp_routes_with_probabilistic_scorer(bench: &mut Bencher) {
|
||||||
let logger = TestLogger::new();
|
let logger = DummyLogger {};
|
||||||
let network_graph = read_network_graph();
|
let network_graph = read_network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
||||||
generate_routes(bench, &network_graph, scorer, InvoiceFeatures::known());
|
generate_routes(bench, &network_graph, scorer, InvoiceFeatures::known());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_routes<S: Score>(
|
fn generate_routes<S: Score>(
|
||||||
bench: &mut Bencher, graph: &NetworkGraph, mut scorer: S, features: InvoiceFeatures
|
bench: &mut Bencher, graph: &NetworkGraph<&DummyLogger>, mut scorer: S,
|
||||||
|
features: InvoiceFeatures
|
||||||
) {
|
) {
|
||||||
let nodes = graph.read_only().nodes().clone();
|
let nodes = graph.read_only().nodes().clone();
|
||||||
let payer = payer_pubkey();
|
let payer = payer_pubkey();
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
//! # impl Logger for FakeLogger {
|
//! # impl Logger for FakeLogger {
|
||||||
//! # fn log(&self, record: &Record) { unimplemented!() }
|
//! # fn log(&self, record: &Record) { unimplemented!() }
|
||||||
//! # }
|
//! # }
|
||||||
//! # fn find_scored_route(payer: PublicKey, route_params: RouteParameters, network_graph: NetworkGraph) {
|
//! # fn find_scored_route(payer: PublicKey, route_params: RouteParameters, network_graph: NetworkGraph<&FakeLogger>) {
|
||||||
//! # let logger = FakeLogger {};
|
//! # let logger = FakeLogger {};
|
||||||
//! #
|
//! #
|
||||||
//! // Use the default channel penalties.
|
//! // Use the default channel penalties.
|
||||||
@ -43,7 +43,7 @@
|
|||||||
//! let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
//! let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
||||||
//! # let random_seed_bytes = [42u8; 32];
|
//! # let random_seed_bytes = [42u8; 32];
|
||||||
//!
|
//!
|
||||||
//! let route = find_route(&payer, &route_params, &network_graph, None, &logger, &scorer, &random_seed_bytes);
|
//! let route = find_route(&payer, &route_params, &network_graph.read_only(), None, &logger, &scorer, &random_seed_bytes);
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
@ -293,7 +293,8 @@ pub type ProbabilisticScorer<G, L> = ProbabilisticScorerUsingTime::<G, L, Config
|
|||||||
/// Probabilistic [`Score`] implementation.
|
/// Probabilistic [`Score`] implementation.
|
||||||
///
|
///
|
||||||
/// (C-not exported) generally all users should use the [`ProbabilisticScorer`] type alias.
|
/// (C-not exported) generally all users should use the [`ProbabilisticScorer`] type alias.
|
||||||
pub struct ProbabilisticScorerUsingTime<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> where L::Target: Logger {
|
pub struct ProbabilisticScorerUsingTime<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time>
|
||||||
|
where L::Target: Logger {
|
||||||
params: ProbabilisticScoringParameters,
|
params: ProbabilisticScoringParameters,
|
||||||
network_graph: G,
|
network_graph: G,
|
||||||
logger: L,
|
logger: L,
|
||||||
@ -389,7 +390,7 @@ struct DirectedChannelLiquidity<L: Deref<Target = u64>, T: Time, U: Deref<Target
|
|||||||
half_life: Duration,
|
half_life: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> ProbabilisticScorerUsingTime<G, L, T> where L::Target: Logger {
|
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerUsingTime<G, L, T> where L::Target: Logger {
|
||||||
/// Creates a new scorer using the given scoring parameters for sending payments from a node
|
/// Creates a new scorer using the given scoring parameters for sending payments from a node
|
||||||
/// through a network graph.
|
/// through a network graph.
|
||||||
pub fn new(params: ProbabilisticScoringParameters, network_graph: G, logger: L) -> Self {
|
pub fn new(params: ProbabilisticScoringParameters, network_graph: G, logger: L) -> Self {
|
||||||
@ -650,7 +651,7 @@ impl<L: DerefMut<Target = u64>, T: Time, U: DerefMut<Target = T>> DirectedChanne
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Score for ProbabilisticScorerUsingTime<G, L, T> where L::Target: Logger {
|
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for ProbabilisticScorerUsingTime<G, L, T> where L::Target: Logger {
|
||||||
fn channel_penalty_msat(
|
fn channel_penalty_msat(
|
||||||
&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage
|
&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
@ -1050,7 +1051,7 @@ mod approx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Writeable for ProbabilisticScorerUsingTime<G, L, T> where L::Target: Logger {
|
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Writeable for ProbabilisticScorerUsingTime<G, L, T> where L::Target: Logger {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
|
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
|
||||||
write_tlv_fields!(w, {
|
write_tlv_fields!(w, {
|
||||||
@ -1060,7 +1061,7 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Writeable for Probabili
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time>
|
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time>
|
||||||
ReadableArgs<(ProbabilisticScoringParameters, G, L)> for ProbabilisticScorerUsingTime<G, L, T> where L::Target: Logger {
|
ReadableArgs<(ProbabilisticScoringParameters, G, L)> for ProbabilisticScorerUsingTime<G, L, T> where L::Target: Logger {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn read<R: Read>(
|
fn read<R: Read>(
|
||||||
@ -1163,7 +1164,7 @@ mod tests {
|
|||||||
// `ProbabilisticScorer` tests
|
// `ProbabilisticScorer` tests
|
||||||
|
|
||||||
/// A probabilistic scorer for testing with time that can be manually advanced.
|
/// A probabilistic scorer for testing with time that can be manually advanced.
|
||||||
type ProbabilisticScorer<'a> = ProbabilisticScorerUsingTime::<&'a NetworkGraph, &'a TestLogger, SinceEpoch>;
|
type ProbabilisticScorer<'a> = ProbabilisticScorerUsingTime::<&'a NetworkGraph<&'a TestLogger>, &'a TestLogger, SinceEpoch>;
|
||||||
|
|
||||||
fn sender_privkey() -> SecretKey {
|
fn sender_privkey() -> SecretKey {
|
||||||
SecretKey::from_slice(&[41; 32]).unwrap()
|
SecretKey::from_slice(&[41; 32]).unwrap()
|
||||||
@ -1191,9 +1192,9 @@ mod tests {
|
|||||||
NodeId::from_pubkey(&recipient_pubkey())
|
NodeId::from_pubkey(&recipient_pubkey())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn network_graph() -> NetworkGraph {
|
fn network_graph(logger: &TestLogger) -> NetworkGraph<&TestLogger> {
|
||||||
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
let mut network_graph = NetworkGraph::new(genesis_hash);
|
let mut network_graph = NetworkGraph::new(genesis_hash, logger);
|
||||||
add_channel(&mut network_graph, 42, source_privkey(), target_privkey());
|
add_channel(&mut network_graph, 42, source_privkey(), target_privkey());
|
||||||
add_channel(&mut network_graph, 43, target_privkey(), recipient_privkey());
|
add_channel(&mut network_graph, 43, target_privkey(), recipient_privkey());
|
||||||
|
|
||||||
@ -1201,7 +1202,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_channel(
|
fn add_channel(
|
||||||
network_graph: &mut NetworkGraph, short_channel_id: u64, node_1_key: SecretKey,
|
network_graph: &mut NetworkGraph<&TestLogger>, short_channel_id: u64, node_1_key: SecretKey,
|
||||||
node_2_key: SecretKey
|
node_2_key: SecretKey
|
||||||
) {
|
) {
|
||||||
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
@ -1234,7 +1235,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_channel(
|
fn update_channel(
|
||||||
network_graph: &mut NetworkGraph, short_channel_id: u64, node_key: SecretKey, flags: u8
|
network_graph: &mut NetworkGraph<&TestLogger>, short_channel_id: u64, node_key: SecretKey,
|
||||||
|
flags: u8
|
||||||
) {
|
) {
|
||||||
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
|
||||||
let secp_ctx = Secp256k1::new();
|
let secp_ctx = Secp256k1::new();
|
||||||
@ -1291,7 +1293,7 @@ mod tests {
|
|||||||
fn liquidity_bounds_directed_from_lowest_node_id() {
|
fn liquidity_bounds_directed_from_lowest_node_id() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let last_updated = SinceEpoch::now();
|
let last_updated = SinceEpoch::now();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let mut scorer = ProbabilisticScorer::new(params, &network_graph, &logger)
|
let mut scorer = ProbabilisticScorer::new(params, &network_graph, &logger)
|
||||||
.with_channel(42,
|
.with_channel(42,
|
||||||
@ -1366,7 +1368,7 @@ mod tests {
|
|||||||
fn resets_liquidity_upper_bound_when_crossed_by_lower_bound() {
|
fn resets_liquidity_upper_bound_when_crossed_by_lower_bound() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let last_updated = SinceEpoch::now();
|
let last_updated = SinceEpoch::now();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let mut scorer = ProbabilisticScorer::new(params, &network_graph, &logger)
|
let mut scorer = ProbabilisticScorer::new(params, &network_graph, &logger)
|
||||||
.with_channel(42,
|
.with_channel(42,
|
||||||
@ -1424,7 +1426,7 @@ mod tests {
|
|||||||
fn resets_liquidity_lower_bound_when_crossed_by_upper_bound() {
|
fn resets_liquidity_lower_bound_when_crossed_by_upper_bound() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let last_updated = SinceEpoch::now();
|
let last_updated = SinceEpoch::now();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let mut scorer = ProbabilisticScorer::new(params, &network_graph, &logger)
|
let mut scorer = ProbabilisticScorer::new(params, &network_graph, &logger)
|
||||||
.with_channel(42,
|
.with_channel(42,
|
||||||
@ -1481,7 +1483,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn increased_penalty_nearing_liquidity_upper_bound() {
|
fn increased_penalty_nearing_liquidity_upper_bound() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
..ProbabilisticScoringParameters::zero_penalty()
|
..ProbabilisticScoringParameters::zero_penalty()
|
||||||
@ -1527,7 +1529,7 @@ mod tests {
|
|||||||
fn constant_penalty_outside_liquidity_bounds() {
|
fn constant_penalty_outside_liquidity_bounds() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let last_updated = SinceEpoch::now();
|
let last_updated = SinceEpoch::now();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
..ProbabilisticScoringParameters::zero_penalty()
|
..ProbabilisticScoringParameters::zero_penalty()
|
||||||
@ -1556,7 +1558,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn does_not_further_penalize_own_channel() {
|
fn does_not_further_penalize_own_channel() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
..ProbabilisticScoringParameters::zero_penalty()
|
..ProbabilisticScoringParameters::zero_penalty()
|
||||||
@ -1584,7 +1586,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn sets_liquidity_lower_bound_on_downstream_failure() {
|
fn sets_liquidity_lower_bound_on_downstream_failure() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
..ProbabilisticScoringParameters::zero_penalty()
|
..ProbabilisticScoringParameters::zero_penalty()
|
||||||
@ -1618,7 +1620,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn sets_liquidity_upper_bound_on_failure() {
|
fn sets_liquidity_upper_bound_on_failure() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
..ProbabilisticScoringParameters::zero_penalty()
|
..ProbabilisticScoringParameters::zero_penalty()
|
||||||
@ -1652,7 +1654,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn reduces_liquidity_upper_bound_along_path_on_success() {
|
fn reduces_liquidity_upper_bound_along_path_on_success() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
..ProbabilisticScoringParameters::zero_penalty()
|
..ProbabilisticScoringParameters::zero_penalty()
|
||||||
@ -1683,7 +1685,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn decays_liquidity_bounds_over_time() {
|
fn decays_liquidity_bounds_over_time() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
liquidity_offset_half_life: Duration::from_secs(10),
|
liquidity_offset_half_life: Duration::from_secs(10),
|
||||||
@ -1762,7 +1764,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn decays_liquidity_bounds_without_shift_overflow() {
|
fn decays_liquidity_bounds_without_shift_overflow() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
liquidity_offset_half_life: Duration::from_secs(10),
|
liquidity_offset_half_life: Duration::from_secs(10),
|
||||||
@ -1793,7 +1795,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn restricts_liquidity_bounds_after_decay() {
|
fn restricts_liquidity_bounds_after_decay() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
liquidity_offset_half_life: Duration::from_secs(10),
|
liquidity_offset_half_life: Duration::from_secs(10),
|
||||||
@ -1837,7 +1839,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn restores_persisted_liquidity_bounds() {
|
fn restores_persisted_liquidity_bounds() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
liquidity_offset_half_life: Duration::from_secs(10),
|
liquidity_offset_half_life: Duration::from_secs(10),
|
||||||
@ -1873,7 +1875,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn decays_persisted_liquidity_bounds() {
|
fn decays_persisted_liquidity_bounds() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters {
|
let params = ProbabilisticScoringParameters {
|
||||||
liquidity_penalty_multiplier_msat: 1_000,
|
liquidity_penalty_multiplier_msat: 1_000,
|
||||||
liquidity_offset_half_life: Duration::from_secs(10),
|
liquidity_offset_half_life: Duration::from_secs(10),
|
||||||
@ -1913,7 +1915,7 @@ mod tests {
|
|||||||
// Shows the scores of "realistic" sends of 100k sats over channels of 1-10m sats (with a
|
// Shows the scores of "realistic" sends of 100k sats over channels of 1-10m sats (with a
|
||||||
// 50k sat reserve).
|
// 50k sat reserve).
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
||||||
let source = source_node_id();
|
let source = source_node_id();
|
||||||
@ -1970,7 +1972,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn adds_base_penalty_to_liquidity_penalty() {
|
fn adds_base_penalty_to_liquidity_penalty() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let source = source_node_id();
|
let source = source_node_id();
|
||||||
let target = target_node_id();
|
let target = target_node_id();
|
||||||
let usage = ChannelUsage {
|
let usage = ChannelUsage {
|
||||||
@ -1996,7 +1998,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn adds_amount_penalty_to_liquidity_penalty() {
|
fn adds_amount_penalty_to_liquidity_penalty() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let source = source_node_id();
|
let source = source_node_id();
|
||||||
let target = target_node_id();
|
let target = target_node_id();
|
||||||
let usage = ChannelUsage {
|
let usage = ChannelUsage {
|
||||||
@ -2025,7 +2027,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn calculates_log10_without_overflowing_u64_max_value() {
|
fn calculates_log10_without_overflowing_u64_max_value() {
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
let network_graph = network_graph();
|
let network_graph = network_graph(&logger);
|
||||||
let source = source_node_id();
|
let source = source_node_id();
|
||||||
let target = target_node_id();
|
let target = target_node_id();
|
||||||
let usage = ChannelUsage {
|
let usage = ChannelUsage {
|
||||||
@ -2044,8 +2046,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn accounts_for_inflight_htlc_usage() {
|
fn accounts_for_inflight_htlc_usage() {
|
||||||
let network_graph = network_graph();
|
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
||||||
let source = source_node_id();
|
let source = source_node_id();
|
||||||
@ -2064,8 +2066,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn removes_uncertainity_when_exact_liquidity_known() {
|
fn removes_uncertainity_when_exact_liquidity_known() {
|
||||||
let network_graph = network_graph();
|
|
||||||
let logger = TestLogger::new();
|
let logger = TestLogger::new();
|
||||||
|
let network_graph = network_graph(&logger);
|
||||||
let params = ProbabilisticScoringParameters::default();
|
let params = ProbabilisticScoringParameters::default();
|
||||||
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
|
||||||
let source = source_node_id();
|
let source = source_node_id();
|
||||||
|
@ -38,7 +38,7 @@ pub trait Persister<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L:
|
|||||||
fn persist_manager(&self, channel_manager: &ChannelManager<Signer, M, T, K, F, L>) -> Result<(), io::Error>;
|
fn persist_manager(&self, channel_manager: &ChannelManager<Signer, M, T, K, F, L>) -> Result<(), io::Error>;
|
||||||
|
|
||||||
/// Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
|
/// Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
|
||||||
fn persist_graph(&self, network_graph: &NetworkGraph) -> Result<(), io::Error>;
|
fn persist_graph(&self, network_graph: &NetworkGraph<L>) -> Result<(), io::Error>;
|
||||||
|
|
||||||
/// Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
|
/// Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
|
||||||
fn persist_scorer(&self, scorer: &S) -> Result<(), io::Error>;
|
fn persist_scorer(&self, scorer: &S) -> Result<(), io::Error>;
|
||||||
@ -58,7 +58,7 @@ impl<'a, A: KVStorePersister, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Der
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Persist the given [`NetworkGraph`] to disk with the name "network_graph", returning an error if persistence failed.
|
/// Persist the given [`NetworkGraph`] to disk with the name "network_graph", returning an error if persistence failed.
|
||||||
fn persist_graph(&self, network_graph: &NetworkGraph) -> Result<(), io::Error> {
|
fn persist_graph(&self, network_graph: &NetworkGraph<L>) -> Result<(), io::Error> {
|
||||||
self.persist("network_graph", network_graph)
|
self.persist("network_graph", network_graph)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user