From: Jeffrey Czyz Date: Mon, 1 Nov 2021 18:14:14 +0000 (-0500) Subject: Parameterize NetGraphMsgHandler with NetworkGraph X-Git-Tag: v0.0.103~3^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=bcdd85227949d17c9a98a9fc0b666bce4a97c856;p=rust-lightning Parameterize NetGraphMsgHandler with NetworkGraph NetworkGraph is owned by NetGraphMsgHandler, but DefaultRouter requires a reference to it. Introduce shared ownership to NetGraphMsgHandler so that both can use the same NetworkGraph. --- diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 2e447dac6..1ed632183 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -161,7 +161,7 @@ type ChannelMan = ChannelManager< EnforcingSigner, Arc, Arc, Arc, Arc, Arc>>, Arc, Arc, Arc, Arc>; -type PeerMan<'a> = PeerManager, Arc, Arc, Arc>>, Arc, IgnoringMessageHandler>; +type PeerMan<'a> = PeerManager, Arc, Arc, Arc, Arc>>, Arc, IgnoringMessageHandler>; struct MoneyLossDetector<'a> { manager: Arc, @@ -380,7 +380,7 @@ pub fn do_test(data: &[u8], logger: &Arc) { }; let channelmanager = Arc::new(ChannelManager::new(fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, params)); let our_id = PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret()); - let network_graph = NetworkGraph::new(genesis_block(network).block_hash()); + let network_graph = Arc::new(NetworkGraph::new(genesis_block(network).block_hash())); let net_graph_msg_handler = Arc::new(NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger))); let scorer = Scorer::with_fixed_penalty(0); diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 95866d7d9..6a89f5e99 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -15,7 +15,7 @@ use lightning::chain::keysinterface::{Sign, KeysInterface}; use lightning::ln::channelmanager::ChannelManager; use lightning::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler}; use lightning::ln::peer_handler::{CustomMessageHandler, PeerManager, SocketDescriptor}; -use lightning::routing::network_graph::NetGraphMsgHandler; +use lightning::routing::network_graph::{NetworkGraph, NetGraphMsgHandler}; use lightning::util::events::{Event, EventHandler, EventsProvider}; use lightning::util::logger::Logger; use std::sync::Arc; @@ -103,7 +103,8 @@ ChannelManagerPersister for Fun where /// Decorates an [`EventHandler`] with common functionality provided by standard [`EventHandler`]s. struct DecoratingEventHandler< E: EventHandler, - N: Deref>, + N: Deref>, + G: Deref, A: Deref, L: Deref, > @@ -114,10 +115,11 @@ where A::Target: chain::Access, L::Target: Logger { impl< E: EventHandler, - N: Deref>, + N: Deref>, + G: Deref, A: Deref, L: Deref, -> EventHandler for DecoratingEventHandler +> EventHandler for DecoratingEventHandler where A::Target: chain::Access, L::Target: Logger { fn handle_event(&self, event: &Event) { if let Some(event_handler) = &self.net_graph_msg_handler { @@ -168,6 +170,7 @@ impl BackgroundProcessor { T: 'static + Deref + Send + Sync, K: 'static + Deref + Send + Sync, F: 'static + Deref + Send + Sync, + G: 'static + Deref + Send + Sync, L: 'static + Deref + Send + Sync, P: 'static + Deref + Send + Sync, Descriptor: 'static + SocketDescriptor + Send + Sync, @@ -177,7 +180,7 @@ impl BackgroundProcessor { CMP: 'static + Send + ChannelManagerPersister, M: 'static + Deref> + Send + Sync, CM: 'static + Deref> + Send + Sync, - NG: 'static + Deref> + Send + Sync, + NG: 'static + Deref> + Send + Sync, UMH: 'static + Deref + Send + Sync, PM: 'static + Deref> + Send + Sync, >( @@ -340,11 +343,12 @@ mod tests { struct Node { node: Arc>, - net_graph_msg_handler: Option, Arc>>>, + net_graph_msg_handler: Option, Arc, Arc>>>, peer_manager: Arc, Arc, Arc, IgnoringMessageHandler>>, chain_monitor: Arc, persister: Arc, tx_broadcaster: Arc, + network_graph: Arc, logger: Arc, best_block: BestBlock, } @@ -382,11 +386,11 @@ mod tests { let best_block = BestBlock::from_genesis(network); 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 network_graph = NetworkGraph::new(genesis_block.header.block_hash()); - let net_graph_msg_handler = Some(Arc::new(NetGraphMsgHandler::new(network_graph, Some(chain_source.clone()), logger.clone()))); + let network_graph = Arc::new(NetworkGraph::new(genesis_block.header.block_hash())); + let net_graph_msg_handler = Some(Arc::new(NetGraphMsgHandler::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 peer_manager = Arc::new(PeerManager::new(msg_handler, keys_manager.get_node_secret(), &seed, logger.clone(), IgnoringMessageHandler{})); - let node = Node { node: manager, net_graph_msg_handler, peer_manager, chain_monitor, persister, tx_broadcaster, logger, best_block }; + let node = Node { node: manager, net_graph_msg_handler, peer_manager, chain_monitor, persister, tx_broadcaster, network_graph, logger, best_block }; nodes.push(node); } @@ -630,8 +634,7 @@ mod tests { // Initiate the background processors to watch each node. let data_dir = nodes[0].persister.get_data_dir(); let persister = move |node: &ChannelManager, Arc, Arc, Arc, Arc>| FilesystemPersister::persist_manager(data_dir.clone(), node); - let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash())); - let router = DefaultRouter::new(network_graph, Arc::clone(&nodes[0].logger)); + let router = DefaultRouter::new(Arc::clone(&nodes[0].network_graph), Arc::clone(&nodes[0].logger)); let scorer = Arc::new(Mutex::new(Scorer::default())); let invoice_payer = Arc::new(InvoicePayer::new(Arc::clone(&nodes[0].node), router, scorer, Arc::clone(&nodes[0].logger), |_: &_| {}, RetryAttempts(2))); let event_handler = Arc::clone(&invoice_payer); diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index bcb1ac1f1..5983e4e28 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -190,6 +190,7 @@ pub struct TestChanMonCfg { pub persister: test_utils::TestPersister, pub logger: test_utils::TestLogger, pub keys_manager: test_utils::TestKeysInterface, + pub network_graph: NetworkGraph, } pub struct NodeCfg<'a> { @@ -199,6 +200,7 @@ pub struct NodeCfg<'a> { pub chain_monitor: test_utils::TestChainMonitor<'a>, pub keys_manager: &'a test_utils::TestKeysInterface, pub logger: &'a test_utils::TestLogger, + pub network_graph: &'a NetworkGraph, pub node_seed: [u8; 32], pub features: InitFeatures, } @@ -209,7 +211,8 @@ pub struct Node<'a, 'b: 'a, 'c: 'b> { pub chain_monitor: &'b test_utils::TestChainMonitor<'c>, pub keys_manager: &'b test_utils::TestKeysInterface, pub node: &'a ChannelManager, &'c test_utils::TestBroadcaster, &'b test_utils::TestKeysInterface, &'c test_utils::TestFeeEstimator, &'c test_utils::TestLogger>, - pub net_graph_msg_handler: NetGraphMsgHandler<&'c test_utils::TestChainSource, &'c test_utils::TestLogger>, + pub network_graph: &'c NetworkGraph, + pub net_graph_msg_handler: NetGraphMsgHandler<&'c NetworkGraph, &'c test_utils::TestChainSource, &'c test_utils::TestLogger>, pub node_seed: [u8; 32], pub network_payment_count: Rc>, pub network_chan_count: Rc>, @@ -243,9 +246,9 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> { let network_graph_ser = &self.net_graph_msg_handler.network_graph; network_graph_ser.write(&mut w).unwrap(); let network_graph_deser = ::read(&mut io::Cursor::new(&w.0)).unwrap(); - assert!(network_graph_deser == self.net_graph_msg_handler.network_graph); + assert!(network_graph_deser == *self.net_graph_msg_handler.network_graph); let net_graph_msg_handler = NetGraphMsgHandler::new( - network_graph_deser, Some(self.chain_source), self.logger + &network_graph_deser, Some(self.chain_source), self.logger ); let mut chan_progress = 0; loop { @@ -1499,8 +1502,9 @@ pub fn create_chanmon_cfgs(node_count: usize) -> Vec { let persister = test_utils::TestPersister::new(); let seed = [i as u8; 32]; 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 }); + chan_mon_cfgs.push(TestChanMonCfg{ tx_broadcaster, fee_estimator, chain_source, logger, persister, keys_manager, network_graph }); } chan_mon_cfgs @@ -1521,6 +1525,7 @@ pub fn create_node_cfgs<'a>(node_count: usize, chanmon_cfgs: &'a Vec(node_count: usize, cfgs: &'b Vec { /// lifetimes). Other times you can afford a reference, which is more efficient, in which case /// SimpleRefPeerManager is the more appropriate type. Defining these type aliases prevents /// issues such as overly long function definitions. -pub type SimpleArcPeerManager = PeerManager>, Arc, Arc>>, Arc, Arc>; +pub type SimpleArcPeerManager = PeerManager>, Arc, Arc, Arc>>, Arc, Arc>; /// 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 @@ -383,7 +383,7 @@ pub type SimpleArcPeerManager = PeerManager = PeerManager, &'e NetGraphMsgHandler<&'g C, &'f L>, &'f L, IgnoringMessageHandler>; +pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, SD, M, T, F, C, L> = PeerManager, &'e NetGraphMsgHandler<&'g NetworkGraph, &'h C, &'f L>, &'f L, IgnoringMessageHandler>; /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls /// socket events into messages which it passes on to its [`MessageHandler`]. diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index 364c9fd88..93701541b 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -186,7 +186,7 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate, }, ); -impl EventHandler for NetGraphMsgHandler +impl, C: Deref, L: Deref> EventHandler for NetGraphMsgHandler where C::Target: chain::Access, L::Target: Logger { fn handle_event(&self, event: &Event) { if let Event::PaymentPathFailed { payment_hash: _, rejected_by_dest: _, network_update, .. } = event { @@ -205,19 +205,19 @@ where C::Target: chain::Access, L::Target: Logger { /// /// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the /// [`NetworkGraph`]. -pub struct NetGraphMsgHandler +pub struct NetGraphMsgHandler, C: Deref, L: Deref> where C::Target: chain::Access, L::Target: Logger { secp_ctx: Secp256k1, /// Representation of the payment channel network - pub network_graph: NetworkGraph, + pub network_graph: G, chain_access: Option, full_syncs_requested: AtomicUsize, pending_events: Mutex>, logger: L, } -impl NetGraphMsgHandler +impl, C: Deref, L: Deref> NetGraphMsgHandler where C::Target: chain::Access, L::Target: Logger { /// Creates a new tracker of the actual state of the network of channels and nodes, @@ -225,7 +225,7 @@ where C::Target: chain::Access, L::Target: Logger /// Chain monitor is used to make sure announced channels exist on-chain, /// channel data is correct, and that the announcement is signed with /// channel owners' keys. - pub fn new(network_graph: NetworkGraph, chain_access: Option, logger: L) -> Self { + pub fn new(network_graph: G, chain_access: Option, logger: L) -> Self { NetGraphMsgHandler { secp_ctx: Secp256k1::verification_only(), network_graph, @@ -288,7 +288,7 @@ macro_rules! secp_verify_sig { }; } -impl RoutingMessageHandler for NetGraphMsgHandler +impl, C: Deref, L: Deref> RoutingMessageHandler for NetGraphMsgHandler where C::Target: chain::Access, L::Target: Logger { fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result { @@ -554,7 +554,7 @@ where C::Target: chain::Access, L::Target: Logger } } -impl MessageSendEventsProvider for NetGraphMsgHandler +impl, C: Deref, L: Deref> MessageSendEventsProvider for NetGraphMsgHandler where C::Target: chain::Access, L::Target: Logger, @@ -1255,18 +1255,24 @@ mod tests { use prelude::*; use sync::Arc; - fn create_net_graph_msg_handler() -> (Secp256k1, NetGraphMsgHandler, Arc>) { + fn create_network_graph() -> NetworkGraph { + let genesis_hash = genesis_block(Network::Testnet).header.block_hash(); + NetworkGraph::new(genesis_hash) + } + + fn create_net_graph_msg_handler(network_graph: &NetworkGraph) -> ( + Secp256k1, NetGraphMsgHandler<&NetworkGraph, Arc, Arc> + ) { let secp_ctx = Secp256k1::new(); let logger = Arc::new(test_utils::TestLogger::new()); - let genesis_hash = genesis_block(Network::Testnet).header.block_hash(); - let network_graph = NetworkGraph::new(genesis_hash); let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger)); (secp_ctx, net_graph_msg_handler) } #[test] fn request_full_sync_finite_times() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap()[..]).unwrap()); assert!(net_graph_msg_handler.should_request_full_sync(&node_id)); @@ -1279,7 +1285,8 @@ mod tests { #[test] fn handling_node_announcements() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); @@ -1422,15 +1429,14 @@ mod tests { // Test if the UTXO lookups were not supported let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()); - let mut net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger)); + let mut net_graph_msg_handler = NetGraphMsgHandler::new(&network_graph, None, Arc::clone(&logger)); match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; { - let network = &net_graph_msg_handler.network_graph; - match network.read_only().channels().get(&unsigned_announcement.short_channel_id) { + match network_graph.read_only().channels().get(&unsigned_announcement.short_channel_id) { None => panic!(), Some(_) => () }; @@ -1447,7 +1453,7 @@ mod tests { let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); *chain_source.utxo_ret.lock().unwrap() = Err(chain::AccessError::UnknownTx); let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()); - net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, Some(chain_source.clone()), Arc::clone(&logger)); + net_graph_msg_handler = NetGraphMsgHandler::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger)); unsigned_announcement.short_channel_id += 1; msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_announcement.encode()[..])[..]); @@ -1482,8 +1488,7 @@ mod tests { }; { - let network = &net_graph_msg_handler.network_graph; - match network.read_only().channels().get(&unsigned_announcement.short_channel_id) { + match network_graph.read_only().channels().get(&unsigned_announcement.short_channel_id) { None => panic!(), Some(_) => () }; @@ -1513,8 +1518,7 @@ mod tests { _ => panic!() }; { - let network = &net_graph_msg_handler.network_graph; - match network.read_only().channels().get(&unsigned_announcement.short_channel_id) { + match network_graph.read_only().channels().get(&unsigned_announcement.short_channel_id) { Some(channel_entry) => { assert_eq!(channel_entry.features, ChannelFeatures::empty()); }, @@ -1572,7 +1576,7 @@ mod tests { let logger: Arc = Arc::new(test_utils::TestLogger::new()); let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()); - let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, Some(chain_source.clone()), Arc::clone(&logger)); + let net_graph_msg_handler = NetGraphMsgHandler::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger)); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); @@ -1644,8 +1648,7 @@ mod tests { }; { - let network = &net_graph_msg_handler.network_graph; - match network.read_only().channels().get(&short_channel_id) { + match network_graph.read_only().channels().get(&short_channel_id) { None => panic!(), Some(channel_info) => { assert_eq!(channel_info.one_to_two.as_ref().unwrap().cltv_expiry_delta, 144); @@ -1741,7 +1744,7 @@ mod tests { let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); let genesis_hash = genesis_block(Network::Testnet).header.block_hash(); let network_graph = NetworkGraph::new(genesis_hash); - let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, Some(chain_source.clone()), &logger); + let net_graph_msg_handler = NetGraphMsgHandler::new(&network_graph, Some(chain_source.clone()), &logger); let secp_ctx = Secp256k1::new(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); @@ -1753,7 +1756,6 @@ mod tests { let short_channel_id = 0; let chain_hash = genesis_block(Network::Testnet).header.block_hash(); - let network_graph = &net_graph_msg_handler.network_graph; { // There is no nodes in the table at the beginning. @@ -1883,7 +1885,8 @@ mod tests { #[test] fn getting_next_channel_announcements() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); @@ -2017,7 +2020,8 @@ mod tests { #[test] fn getting_next_node_announcements() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); @@ -2134,7 +2138,8 @@ mod tests { #[test] fn network_graph_serialization() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); @@ -2191,17 +2196,17 @@ mod tests { Err(_) => panic!() }; - let network = &net_graph_msg_handler.network_graph; let mut w = test_utils::TestVecWriter(Vec::new()); - assert!(!network.read_only().nodes().is_empty()); - assert!(!network.read_only().channels().is_empty()); - network.write(&mut w).unwrap(); - assert!(::read(&mut io::Cursor::new(&w.0)).unwrap() == *network); + assert!(!network_graph.read_only().nodes().is_empty()); + assert!(!network_graph.read_only().channels().is_empty()); + network_graph.write(&mut w).unwrap(); + assert!(::read(&mut io::Cursor::new(&w.0)).unwrap() == network_graph); } #[test] fn calling_sync_routing_table() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let node_privkey_1 = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_privkey_1); @@ -2238,7 +2243,8 @@ mod tests { // The initial implementation allows syncing with the first 5 peers after // which should_request_full_sync will return false { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let init_msg = Init { features: InitFeatures::known() }; for n in 1..7 { let node_privkey = &SecretKey::from_slice(&[n; 32]).unwrap(); @@ -2257,7 +2263,8 @@ mod tests { #[test] fn handling_reply_channel_range() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let node_privkey_1 = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_privkey_1); @@ -2305,7 +2312,8 @@ mod tests { #[test] fn handling_reply_short_channel_ids() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let node_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey); @@ -2334,7 +2342,8 @@ mod tests { #[test] fn handling_query_channel_range() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let chain_hash = genesis_block(Network::Testnet).header.block_hash(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); @@ -2596,7 +2605,7 @@ mod tests { } fn do_handling_query_channel_range( - net_graph_msg_handler: &NetGraphMsgHandler, Arc>, + net_graph_msg_handler: &NetGraphMsgHandler<&NetworkGraph, Arc, Arc>, test_node_id: &PublicKey, msg: QueryChannelRange, expected_ok: bool, @@ -2645,7 +2654,8 @@ mod tests { #[test] fn handling_query_short_channel_ids() { - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(); + let network_graph = create_network_graph(); + let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); let node_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey); diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index c035b4547..056580bbc 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -1524,7 +1524,7 @@ mod tests { // Using the same keys for LN and BTC ids fn add_channel( - net_graph_msg_handler: &NetGraphMsgHandler, Arc>, + net_graph_msg_handler: &NetGraphMsgHandler, Arc, Arc>, secp_ctx: &Secp256k1, 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); @@ -1556,7 +1556,7 @@ mod tests { } fn update_channel( - net_graph_msg_handler: &NetGraphMsgHandler, Arc>, + net_graph_msg_handler: &NetGraphMsgHandler, Arc, Arc>, secp_ctx: &Secp256k1, node_privkey: &SecretKey, update: UnsignedChannelUpdate ) { let msghash = hash_to_message!(&Sha256dHash::hash(&update.encode()[..])[..]); @@ -1572,7 +1572,7 @@ mod tests { } fn add_or_update_node( - net_graph_msg_handler: &NetGraphMsgHandler, Arc>, + net_graph_msg_handler: &NetGraphMsgHandler, Arc, Arc>, secp_ctx: &Secp256k1, node_privkey: &SecretKey, features: NodeFeatures, timestamp: u32 ) { let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey); @@ -1626,11 +1626,11 @@ mod tests { } } - fn build_graph() -> (Secp256k1, NetGraphMsgHandler, sync::Arc>, sync::Arc, sync::Arc) { + fn build_graph() -> (Secp256k1, NetGraphMsgHandler, sync::Arc, sync::Arc>, sync::Arc, sync::Arc) { let secp_ctx = Secp256k1::new(); let logger = Arc::new(test_utils::TestLogger::new()); let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); - let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()); + let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash())); let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger)); // Build network from our_id to node6: // @@ -4211,7 +4211,7 @@ mod tests { // "previous hop" being set to node 3, creating a loop in the path. let secp_ctx = Secp256k1::new(); let logger = Arc::new(test_utils::TestLogger::new()); - let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()); + let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash())); let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger)); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = Scorer::with_fixed_penalty(0);