diff --git a/ARCH.md b/ARCH.md index 5b9304cce00..9efccd9c9dd 100644 --- a/ARCH.md +++ b/ARCH.md @@ -11,10 +11,10 @@ receive `ChannelMonitorUpdate`s from `ChannelManager` and persist them to disk b channel steps forward. There are two additional important structures that you may use either on the same device -as the `ChannelManager` or on a separate one. `NetGraphMsgHandler` handles receiving channel -and node announcements, which are then used to calculate routes by `get_route` for sending payments. -`PeerManager` handles the authenticated and encrypted communication protocol, -monitoring for liveness of peers, routing messages to `ChannelManager` and `NetGraphMsgHandler` +as the `ChannelManager` or on a separate one. `P2PGossipSync` handles receiving channel +and node announcements, which are then used to calculate routes by `find_route` for sending +payments. `PeerManager` handles the authenticated and encrypted communication protocol, +monitoring for liveness of peers, routing messages to `ChannelManager` and `P2PGossipSync` instances directly, and receiving messages from them via the `EventsProvider` interface. These structs communicate with each other using a public API, so that you can easily add @@ -56,7 +56,7 @@ At a high level, some of the common interfaces fit together as follows: | ----------------- \ / ---------------- | ^ \ / | (as RoutingMessageHandler) | v v - \ ---------------------- --------- ----------------- - -----------------> | NetGraphMsgHandler | | Event | | chain::Filter | - ---------------------- --------- ----------------- + \ ----------------- --------- ----------------- + -----------------> | P2PGossipSync | | Event | | chain::Filter | + ----------------- --------- ----------------- ``` diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 00b123b84dd..a59d78e1c54 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -37,7 +37,7 @@ use lightning::ln::channelmanager::{ChainParameters, ChannelManager}; use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,IgnoringMessageHandler}; use lightning::ln::msgs::DecodeError; use lightning::ln::script::ShutdownScript; -use lightning::routing::network_graph::{NetGraphMsgHandler, NetworkGraph}; +use lightning::routing::gossip::{P2PGossipSync, NetworkGraph}; use lightning::routing::router::{find_route, PaymentParameters, RouteParameters}; use lightning::routing::scoring::FixedPenaltyScorer; use lightning::util::config::UserConfig; @@ -163,7 +163,7 @@ type ChannelMan = ChannelManager< EnforcingSigner, Arc, Arc, Arc, Arc, Arc>>, Arc, Arc, Arc, Arc>; -type PeerMan<'a> = PeerManager, Arc, Arc, Arc, Arc>>, Arc, IgnoringMessageHandler>; +type PeerMan<'a> = PeerManager, Arc, Arc, Arc, Arc>>, Arc, IgnoringMessageHandler>; struct MoneyLossDetector<'a> { manager: Arc, @@ -396,13 +396,13 @@ pub fn do_test(data: &[u8], logger: &Arc) { 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 network_graph = Arc::new(NetworkGraph::new(genesis_block(network).block_hash())); - let net_graph_msg_handler = Arc::new(NetGraphMsgHandler::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 peers = RefCell::new([false; 256]); let mut loss_detector = MoneyLossDetector::new(&peers, channelmanager.clone(), monitor.clone(), PeerManager::new(MessageHandler { chan_handler: channelmanager.clone(), - route_handler: net_graph_msg_handler.clone(), + route_handler: gossip_sync.clone(), }, our_network_key, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0], Arc::clone(&logger), IgnoringMessageHandler{})); let mut should_forward = false; diff --git a/fuzz/src/process_network_graph.rs b/fuzz/src/process_network_graph.rs index a71ae0e221b..118862569d0 100644 --- a/fuzz/src/process_network_graph.rs +++ b/fuzz/src/process_network_graph.rs @@ -5,7 +5,7 @@ use utils::test_logger; /// Actual fuzz test, method signature and name are fixed fn do_test(data: &[u8]) { let block_hash = bitcoin::BlockHash::default(); - let network_graph = lightning::routing::network_graph::NetworkGraph::new(block_hash); + let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash); let rapid_sync = RapidGossipSync::new(&network_graph); let _ = rapid_sync.update_network_graph(data); } diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index bb6ba2c6e51..ec12ff7e144 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -16,11 +16,11 @@ use lightning::chain::transaction::OutPoint; use lightning::ln::channelmanager::{ChannelDetails, ChannelCounterparty}; use lightning::ln::features::InitFeatures; use lightning::ln::msgs; +use lightning::routing::gossip::{NetworkGraph, RoutingFees}; use lightning::routing::router::{find_route, PaymentParameters, RouteHint, RouteHintHop, RouteParameters}; use lightning::routing::scoring::FixedPenaltyScorer; use lightning::util::logger::Logger; use lightning::util::ser::Readable; -use lightning::routing::network_graph::{NetworkGraph, RoutingFees}; use bitcoin::hashes::Hash; use bitcoin::secp256k1::PublicKey; @@ -196,7 +196,7 @@ pub fn do_test(data: &[u8], out: Out) { }, 4 => { let short_channel_id = slice_to_be64(get_slice!(8)); - net_graph.close_channel_from_update(short_channel_id, false); + net_graph.channel_failed(short_channel_id, false); }, _ if node_pks.is_empty() => {}, _ => { diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 0fab3e61a4a..2e947a7041a 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -18,7 +18,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::{NetworkGraph, NetGraphMsgHandler}; +use lightning::routing::gossip::{NetworkGraph, P2PGossipSync}; use lightning::routing::scoring::WriteableScore; use lightning::util::events::{Event, EventHandler, EventsProvider}; use lightning::util::logger::Logger; @@ -40,7 +40,7 @@ use std::ops::Deref; /// [`ChannelManager`] persistence should be done in the background. /// * Calling [`ChannelManager::timer_tick_occurred`] and [`PeerManager::timer_tick_occurred`] /// at the appropriate intervals. -/// * Calling [`NetworkGraph::remove_stale_channels`] (if a [`NetGraphMsgHandler`] is provided to +/// * Calling [`NetworkGraph::remove_stale_channels`] (if a [`P2PGossipSync`] is provided to /// [`BackgroundProcessor::start`]). /// /// It will also call [`PeerManager::process_events`] periodically though this shouldn't be relied @@ -93,26 +93,26 @@ const FIRST_NETWORK_PRUNE_TIMER: u64 = 1; /// Decorates an [`EventHandler`] with common functionality provided by standard [`EventHandler`]s. struct DecoratingEventHandler< E: EventHandler, - N: Deref>, + P: Deref>, G: Deref, A: Deref, L: Deref, > where A::Target: chain::Access, L::Target: Logger { event_handler: E, - net_graph_msg_handler: Option, + p2p_gossip_sync: Option

, } impl< E: EventHandler, - N: Deref>, + P: 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 { + if let Some(event_handler) = &self.p2p_gossip_sync { event_handler.handle_event(event); } self.event_handler.handle_event(event); @@ -147,7 +147,7 @@ impl BackgroundProcessor { /// `event_handler` is responsible for handling events that users should be notified of (e.g., /// payment failed). [`BackgroundProcessor`] may decorate the given [`EventHandler`] with common /// functionality implemented by other handlers. - /// * [`NetGraphMsgHandler`] if given will update the [`NetworkGraph`] based on payment failures. + /// * [`P2PGossipSync`] if given will update the [`NetworkGraph`] based on payment failures. /// /// # Rapid Gossip Sync /// @@ -162,8 +162,8 @@ impl BackgroundProcessor { /// [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable /// [`Persister::persist_manager`]: lightning::util::persist::Persister::persist_manager /// [`Persister::persist_graph`]: lightning::util::persist::Persister::persist_graph - /// [`NetworkGraph`]: lightning::routing::network_graph::NetworkGraph - /// [`NetworkGraph::write`]: lightning::routing::network_graph::NetworkGraph#impl-Writeable + /// [`NetworkGraph`]: lightning::routing::gossip::NetworkGraph + /// [`NetworkGraph::write`]: lightning::routing::gossip::NetworkGraph#impl-Writeable pub fn start< 'a, Signer: 'static + Sign, @@ -183,7 +183,7 @@ impl BackgroundProcessor { PS: 'static + Deref + Send, M: 'static + Deref> + Send + Sync, CM: 'static + Deref> + Send + Sync, - NG: 'static + Deref> + Send + Sync, + PGS: 'static + Deref> + Send + Sync, UMH: 'static + Deref + Send + Sync, PM: 'static + Deref> + Send + Sync, S: 'static + Deref + Send + Sync, @@ -191,7 +191,7 @@ impl BackgroundProcessor { RGS: 'static + Deref> + Send >( persister: PS, event_handler: EH, chain_monitor: M, channel_manager: CM, - net_graph_msg_handler: Option, peer_manager: PM, logger: L, scorer: Option, + p2p_gossip_sync: Option, peer_manager: PM, logger: L, scorer: Option, rapid_gossip_sync: Option ) -> Self where @@ -211,7 +211,7 @@ impl BackgroundProcessor { let stop_thread = Arc::new(AtomicBool::new(false)); let stop_thread_clone = stop_thread.clone(); let handle = thread::spawn(move || -> Result<(), std::io::Error> { - let event_handler = DecoratingEventHandler { event_handler, net_graph_msg_handler: net_graph_msg_handler.as_ref().map(|t| t.deref()) }; + let event_handler = DecoratingEventHandler { event_handler, p2p_gossip_sync: p2p_gossip_sync.as_ref().map(|t| t.deref()) }; log_trace!(logger, "Calling ChannelManager's timer_tick_occurred on startup"); channel_manager.timer_tick_occurred(); @@ -298,7 +298,7 @@ impl BackgroundProcessor { None } }, - None => net_graph_msg_handler.as_ref().map(|handler| handler.network_graph()) + None => p2p_gossip_sync.as_ref().map(|sync| sync.network_graph()) }; if let Some(network_graph_reference) = graph_to_prune { @@ -337,8 +337,8 @@ impl BackgroundProcessor { } // Persist NetworkGraph on exit - if let Some(ref handler) = net_graph_msg_handler { - persister.persist_graph(handler.network_graph())?; + if let Some(ref gossip_sync) = p2p_gossip_sync { + persister.persist_graph(gossip_sync.network_graph())?; } Ok(()) @@ -408,7 +408,7 @@ mod tests { use lightning::ln::features::{ChannelFeatures, InitFeatures}; use lightning::ln::msgs::{ChannelMessageHandler, Init}; use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler}; - use lightning::routing::network_graph::{NetworkGraph, NetGraphMsgHandler}; + use lightning::routing::gossip::{NetworkGraph, P2PGossipSync}; use lightning::util::config::UserConfig; use lightning::util::events::{Event, MessageSendEventsProvider, MessageSendEvent}; use lightning::util::ser::Writeable; @@ -442,7 +442,7 @@ mod tests { struct Node { node: Arc>, - net_graph_msg_handler: Option, Arc, Arc>>>, + p2p_gossip_sync: Option, Arc, Arc>>>, peer_manager: Arc, Arc, Arc, IgnoringMessageHandler>>, chain_monitor: Arc, persister: Arc, @@ -547,12 +547,12 @@ mod tests { 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 = 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 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 peer_manager = Arc::new(PeerManager::new(msg_handler, keys_manager.get_node_secret(Recipient::Node).unwrap(), &seed, logger.clone(), IgnoringMessageHandler{})); let scorer = Arc::new(Mutex::new(test_utils::TestScorer::with_penalty(0))); let rapid_gossip_sync = None; - let node = Node { node: manager, net_graph_msg_handler, peer_manager, chain_monitor, persister, tx_broadcaster, network_graph, logger, best_block, scorer, rapid_gossip_sync }; + let node = Node { node: manager, p2p_gossip_sync, peer_manager, chain_monitor, persister, tx_broadcaster, network_graph, logger, best_block, scorer, rapid_gossip_sync }; nodes.push(node); } @@ -650,7 +650,7 @@ mod tests { let data_dir = nodes[0].persister.get_data_dir(); let persister = Arc::new(Persister::new(data_dir)); let event_handler = |_: &_| {}; - let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); macro_rules! check_persisted_data { ($node: expr, $filepath: expr) => { @@ -695,7 +695,7 @@ mod tests { // Check network graph is persisted let filepath = get_full_filepath("test_background_processor_persister_0".to_string(), "network_graph".to_string()); - if let Some(ref handler) = nodes[0].net_graph_msg_handler { + if let Some(ref handler) = nodes[0].p2p_gossip_sync { let network_graph = handler.network_graph(); check_persisted_data!(network_graph, filepath.clone()); } @@ -715,7 +715,7 @@ mod tests { let data_dir = nodes[0].persister.get_data_dir(); let persister = Arc::new(Persister::new(data_dir)); let event_handler = |_: &_| {}; - let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); loop { let log_entries = nodes[0].logger.lines.lock().unwrap(); let desired_log = "Calling ChannelManager's timer_tick_occurred".to_string(); @@ -738,7 +738,7 @@ mod tests { let data_dir = nodes[0].persister.get_data_dir(); let persister = Arc::new(Persister::new(data_dir).with_manager_error(std::io::ErrorKind::Other, "test")); let event_handler = |_: &_| {}; - let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); match bg_processor.join() { Ok(_) => panic!("Expected error persisting manager"), Err(e) => { @@ -755,7 +755,7 @@ mod tests { let data_dir = nodes[0].persister.get_data_dir(); let persister = Arc::new(Persister::new(data_dir).with_graph_error(std::io::ErrorKind::Other, "test")); let event_handler = |_: &_| {}; - let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); match bg_processor.stop() { Ok(_) => panic!("Expected error persisting network graph"), @@ -773,7 +773,7 @@ mod tests { let data_dir = nodes[0].persister.get_data_dir(); let persister = Arc::new(Persister::new(data_dir).with_scorer_error(std::io::ErrorKind::Other, "test")); let event_handler = |_: &_| {}; - let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); match bg_processor.stop() { Ok(_) => panic!("Expected error persisting scorer"), @@ -796,7 +796,7 @@ mod tests { let event_handler = move |event: &Event| { sender.send(handle_funding_generation_ready!(event, channel_value)).unwrap(); }; - let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); // Open a channel and check that the FundingGenerationReady event was handled. begin_open_channel!(nodes[0], nodes[1], channel_value); @@ -821,7 +821,7 @@ mod tests { let (sender, receiver) = std::sync::mpsc::sync_channel(1); let event_handler = move |event: &Event| sender.send(event.clone()).unwrap(); let persister = Arc::new(Persister::new(data_dir)); - let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); // Force close the channel and check that the SpendableOutputs event was handled. nodes[0].node.force_close_channel(&nodes[0].node.list_channels()[0].channel_id, &nodes[1].node.get_our_node_id()).unwrap(); @@ -845,7 +845,7 @@ mod tests { let data_dir = nodes[0].persister.get_data_dir(); let persister = Arc::new(Persister::new(data_dir)); let event_handler = |_: &_| {}; - let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); loop { let log_entries = nodes[0].logger.lines.lock().unwrap(); @@ -874,7 +874,7 @@ mod tests { assert_eq!(network_graph.read_only().channels().len(), 1); let event_handler = |_: &_| {}; - let background_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), Some(rapid_sync.clone())); + let background_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), Some(rapid_sync.clone())); loop { let log_entries = nodes[0].logger.lines.lock().unwrap(); @@ -928,7 +928,7 @@ mod tests { let router = DefaultRouter::new(Arc::clone(&nodes[0].network_graph), Arc::clone(&nodes[0].logger), random_seed_bytes); let invoice_payer = Arc::new(InvoicePayer::new(Arc::clone(&nodes[0].node), router, Arc::clone(&nodes[0].scorer), Arc::clone(&nodes[0].logger), |_: &_| {}, Retry::Attempts(2))); let event_handler = Arc::clone(&invoice_payer); - let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].p2p_gossip_sync.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), nodes[0].rapid_gossip_sync.clone()); assert!(bg_processor.stop().is_ok()); } } diff --git a/lightning-invoice/src/de.rs b/lightning-invoice/src/de.rs index e9b639c1013..b4eb04a3d21 100644 --- a/lightning-invoice/src/de.rs +++ b/lightning-invoice/src/de.rs @@ -13,7 +13,7 @@ use bitcoin_hashes::Hash; use bitcoin_hashes::sha256; use crate::prelude::*; use lightning::ln::PaymentSecret; -use lightning::routing::network_graph::RoutingFees; +use lightning::routing::gossip::RoutingFees; use lightning::routing::router::{RouteHint, RouteHintHop}; use num_traits::{CheckedAdd, CheckedMul}; @@ -909,7 +909,7 @@ mod test { #[test] fn test_parse_route() { - use lightning::routing::network_graph::RoutingFees; + use lightning::routing::gossip::RoutingFees; use lightning::routing::router::{RouteHint, RouteHintHop}; use ::PrivateRoute; use bech32::FromBase32; diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 008d3344b55..609b33b2d50 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -45,7 +45,7 @@ use bitcoin_hashes::sha256; use lightning::ln::PaymentSecret; use lightning::ln::features::InvoiceFeatures; #[cfg(any(doc, test))] -use lightning::routing::network_graph::RoutingFees; +use lightning::routing::gossip::RoutingFees; use lightning::routing::router::RouteHint; use lightning::util::invoice::construct_invoice_preimage; diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index c095f74dd16..e672b89c919 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -38,7 +38,7 @@ //! # use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; //! # use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure}; //! # use lightning::ln::msgs::LightningError; -//! # use lightning::routing::network_graph::NodeId; +//! # use lightning::routing::gossip::NodeId; //! # use lightning::routing::router::{Route, RouteHop, RouteParameters}; //! # use lightning::routing::scoring::{ChannelUsage, Score}; //! # use lightning::util::events::{Event, EventHandler, EventsProvider}; @@ -602,7 +602,7 @@ mod tests { use lightning::ln::features::{ChannelFeatures, NodeFeatures, InitFeatures}; use lightning::ln::functional_test_utils::*; use lightning::ln::msgs::{ChannelMessageHandler, ErrorAction, LightningError}; - use lightning::routing::network_graph::NodeId; + use lightning::routing::gossip::NodeId; use lightning::routing::router::{PaymentParameters, Route, RouteHop}; use lightning::routing::scoring::ChannelUsage; use lightning::util::test_utils::TestLogger; diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index 9f6691564ca..04cfb3f1470 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -15,9 +15,9 @@ use lightning::ln::channelmanager::{ChannelDetails, ChannelManager, PaymentId, P use lightning::ln::channelmanager::{PhantomRouteHints, MIN_CLTV_EXPIRY_DELTA}; use lightning::ln::inbound_payment::{create, create_from_hash, ExpandedKey}; use lightning::ln::msgs::LightningError; -use lightning::routing::scoring::Score; -use lightning::routing::network_graph::{NetworkGraph, RoutingFees}; +use lightning::routing::gossip::{NetworkGraph, RoutingFees}; use lightning::routing::router::{Route, RouteHint, RouteHintHop, RouteParameters, find_route}; +use lightning::routing::scoring::Score; use lightning::util::logger::Logger; use secp256k1::PublicKey; use core::ops::Deref; diff --git a/lightning-invoice/tests/ser_de.rs b/lightning-invoice/tests/ser_de.rs index 1d9c481513d..ffac702ce1a 100644 --- a/lightning-invoice/tests/ser_de.rs +++ b/lightning-invoice/tests/ser_de.rs @@ -9,8 +9,8 @@ use bitcoin_hashes::hex::FromHex; use bitcoin_hashes::{sha256, Hash}; use bech32::u5; use lightning::ln::PaymentSecret; +use lightning::routing::gossip::RoutingFees; use lightning::routing::router::{RouteHint, RouteHintHop}; -use lightning::routing::network_graph::RoutingFees; use lightning_invoice::*; use secp256k1::PublicKey; use secp256k1::ecdsa::{RecoverableSignature, RecoveryId}; diff --git a/lightning-rapid-gossip-sync/src/lib.rs b/lightning-rapid-gossip-sync/src/lib.rs index e2e7807e398..278cede3974 100644 --- a/lightning-rapid-gossip-sync/src/lib.rs +++ b/lightning-rapid-gossip-sync/src/lib.rs @@ -29,7 +29,7 @@ //! ``` //! use bitcoin::blockdata::constants::genesis_block; //! use bitcoin::Network; -//! use lightning::routing::network_graph::NetworkGraph; +//! use lightning::routing::gossip::NetworkGraph; //! use lightning_rapid_gossip_sync::RapidGossipSync; //! //! let block_hash = genesis_block(Network::Bitcoin).header.block_hash(); @@ -62,7 +62,7 @@ use std::fs::File; use std::ops::Deref; use std::sync::atomic::{AtomicBool, Ordering}; -use lightning::routing::network_graph::NetworkGraph; +use lightning::routing::gossip::NetworkGraph; use crate::error::GraphSyncError; @@ -127,7 +127,7 @@ mod tests { use bitcoin::Network; use lightning::ln::msgs::DecodeError; - use lightning::routing::network_graph::NetworkGraph; + use lightning::routing::gossip::NetworkGraph; use crate::RapidGossipSync; #[test] @@ -253,7 +253,7 @@ pub mod bench { use bitcoin::Network; use lightning::ln::msgs::DecodeError; - use lightning::routing::network_graph::NetworkGraph; + use lightning::routing::gossip::NetworkGraph; use crate::RapidGossipSync; @@ -271,6 +271,7 @@ pub mod bench { println!("{}", error_string); return; } + #[cfg(require_route_graph_test)] panic!("{}", error_string); } assert!(sync_result.is_ok()) diff --git a/lightning-rapid-gossip-sync/src/processing.rs b/lightning-rapid-gossip-sync/src/processing.rs index 6ffc6f58ea8..21c1ce29a99 100644 --- a/lightning-rapid-gossip-sync/src/processing.rs +++ b/lightning-rapid-gossip-sync/src/processing.rs @@ -10,7 +10,7 @@ use bitcoin::secp256k1::PublicKey; use lightning::ln::msgs::{ DecodeError, ErrorAction, LightningError, OptionalField, UnsignedChannelUpdate, }; -use lightning::routing::network_graph::NetworkGraph; +use lightning::routing::gossip::NetworkGraph; use lightning::util::ser::{BigSize, Readable}; use crate::error::GraphSyncError; @@ -235,7 +235,7 @@ mod tests { use bitcoin::Network; use lightning::ln::msgs::DecodeError; - use lightning::routing::network_graph::NetworkGraph; + use lightning::routing::gossip::NetworkGraph; use crate::error::GraphSyncError; use crate::RapidGossipSync; diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 770fe813941..495b507426c 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -1901,9 +1901,9 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: (channel_id, create_chan_between_nodes_with_value_b(&nodes[1], &nodes[0], &channel_ready)) }; for node in nodes.iter() { - assert!(node.net_graph_msg_handler.handle_channel_announcement(&announcement).unwrap()); - node.net_graph_msg_handler.handle_channel_update(&as_update).unwrap(); - node.net_graph_msg_handler.handle_channel_update(&bs_update).unwrap(); + assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap()); + node.gossip_sync.handle_channel_update(&as_update).unwrap(); + node.gossip_sync.handle_channel_update(&bs_update).unwrap(); } send_payment(&nodes[0], &[&nodes[1]], 8000000); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 17a52e29e4a..1d43fa0a460 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -13,10 +13,11 @@ //! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those //! upon reconnect to the relevant peer(s). //! -//! It does not manage routing logic (see routing::router::get_route for that) nor does it manage constructing +//! It does not manage routing logic (see [`find_route`] for that) nor does it manage constructing //! on-chain transactions (it only monitors the chain to watch for any force-closes that might //! imply it needs to fail HTLCs/payments/channels it manages). //! +//! [`find_route`]: crate::routing::router::find_route use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::transaction::Transaction; @@ -1777,12 +1778,14 @@ impl ChannelMana self.list_channels_with_filter(|_| true) } - /// Gets the list of usable channels, in random order. Useful as an argument to - /// get_route to ensure non-announced channels are used. + /// Gets the list of usable channels, in random order. Useful as an argument to [`find_route`] + /// to ensure non-announced channels are used. /// /// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the /// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria /// are. + /// + /// [`find_route`]: crate::routing::router::find_route pub fn list_usable_channels(&self) -> Vec { // Note we use is_live here instead of usable which leads to somewhat confused // internal/external nomenclature, but that's ok cause that's probably what the user @@ -3765,7 +3768,7 @@ impl ChannelMana .. } => { // we get a fail_malformed_htlc from the first hop // TODO: We'd like to generate a NetworkUpdate for temporary - // failures here, but that would be insufficient as get_route + // failures here, but that would be insufficient as find_route // generally ignores its view of our own channels as we provide them via // ChannelDetails. // TODO: For non-temporary failures, we really should be closing the @@ -7564,7 +7567,7 @@ pub mod bench { use ln::features::{InitFeatures, InvoiceFeatures}; use ln::functional_test_utils::*; use ln::msgs::{ChannelMessageHandler, Init}; - use routing::network_graph::NetworkGraph; + use routing::gossip::NetworkGraph; use routing::router::{PaymentParameters, get_route}; use util::test_utils; use util::config::UserConfig; diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 8929a977438..594f02fc52e 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -15,7 +15,7 @@ use chain::channelmonitor::ChannelMonitor; use chain::transaction::OutPoint; use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; use ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, PaymentId, MIN_CLTV_EXPIRY_DELTA}; -use routing::network_graph::{NetGraphMsgHandler, NetworkGraph}; +use routing::gossip::{P2PGossipSync, NetworkGraph}; use routing::router::{PaymentParameters, Route, get_route}; use ln::features::{InitFeatures, InvoiceFeatures}; use ln::msgs; @@ -279,7 +279,7 @@ pub struct Node<'a, 'b: 'a, 'c: 'b> { 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 network_graph: &'c NetworkGraph, - pub net_graph_msg_handler: NetGraphMsgHandler<&'c NetworkGraph, &'c test_utils::TestChainSource, &'c test_utils::TestLogger>, + pub gossip_sync: P2PGossipSync<&'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>, @@ -313,13 +313,13 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> { self.network_graph.write(&mut w).unwrap(); let network_graph_deser = ::read(&mut io::Cursor::new(&w.0)).unwrap(); assert!(network_graph_deser == *self.network_graph); - let net_graph_msg_handler = NetGraphMsgHandler::new( + let gossip_sync = P2PGossipSync::new( &network_graph_deser, Some(self.chain_source), self.logger ); let mut chan_progress = 0; loop { - let orig_announcements = self.net_graph_msg_handler.get_next_channel_announcements(chan_progress, 255); - let deserialized_announcements = net_graph_msg_handler.get_next_channel_announcements(chan_progress, 255); + let orig_announcements = self.gossip_sync.get_next_channel_announcements(chan_progress, 255); + let deserialized_announcements = gossip_sync.get_next_channel_announcements(chan_progress, 255); assert!(orig_announcements == deserialized_announcements); chan_progress = match orig_announcements.last() { Some(announcement) => announcement.0.contents.short_channel_id + 1, @@ -328,8 +328,8 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> { } let mut node_progress = None; loop { - let orig_announcements = self.net_graph_msg_handler.get_next_node_announcements(node_progress.as_ref(), 255); - let deserialized_announcements = net_graph_msg_handler.get_next_node_announcements(node_progress.as_ref(), 255); + let orig_announcements = self.gossip_sync.get_next_node_announcements(node_progress.as_ref(), 255); + let deserialized_announcements = gossip_sync.get_next_node_announcements(node_progress.as_ref(), 255); assert!(orig_announcements == deserialized_announcements); node_progress = match orig_announcements.last() { Some(announcement) => Some(announcement.contents.node_id), @@ -876,11 +876,11 @@ pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec { + &Some($crate::routing::gossip::NetworkUpdate::ChannelUpdateMessage { ref msg }) if !chan_closed => { if let Some(scid) = $conditions.expected_blamed_scid { assert_eq!(msg.contents.short_channel_id, scid); } assert_eq!(msg.contents.flags & 2, 0); }, - &Some($crate::routing::network_graph::NetworkUpdate::ChannelClosed { short_channel_id, is_permanent }) if chan_closed => { + &Some($crate::routing::gossip::NetworkUpdate::ChannelFailure { short_channel_id, is_permanent }) if chan_closed => { if let Some(scid) = $conditions.expected_blamed_scid { assert_eq!(short_channel_id, scid); } @@ -1992,11 +1992,11 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec(nodes: &Vec(_name: &str, test_case: panic!("channel_update not found!"); } }, - &NetworkUpdate::ChannelClosed { ref short_channel_id, ref is_permanent } => { - if let NetworkUpdate::ChannelClosed { short_channel_id: ref expected_short_channel_id, is_permanent: ref expected_is_permanent } = expected_channel_update.unwrap() { + &NetworkUpdate::ChannelFailure { ref short_channel_id, ref is_permanent } => { + if let NetworkUpdate::ChannelFailure { short_channel_id: ref expected_short_channel_id, is_permanent: ref expected_is_permanent } = expected_channel_update.unwrap() { assert!(*short_channel_id == *expected_short_channel_id); assert!(*is_permanent == *expected_is_permanent); } else { @@ -283,7 +283,7 @@ fn test_fee_failures() { let short_channel_id = channels[0].0.contents.short_channel_id; run_onion_failure_test("fee_insufficient", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| { msg.amount_msat -= 1; - }, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id)); + }, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true}), Some(short_channel_id)); // In an earlier version, we spuriously failed to forward payments if the expected feerate // changed between the channel open and the payment. @@ -343,7 +343,7 @@ fn test_onion_failure() { // describing a length-1 TLV payload, which is obviously bogus. new_payloads[0].data[0] = 1; msg.onion_routing_packet = onion_utils::construct_onion_packet_bogus_hopdata(new_payloads, onion_keys, [0; 32], &payment_hash); - }, ||{}, true, Some(PERM|22), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id)); + }, ||{}, true, Some(PERM|22), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id)); // final node failure let short_channel_id = channels[1].0.contents.short_channel_id; @@ -360,7 +360,7 @@ fn test_onion_failure() { // length-1 TLV payload, which is obviously bogus. new_payloads[1].data[0] = 1; msg.onion_routing_packet = onion_utils::construct_onion_packet_bogus_hopdata(new_payloads, onion_keys, [0; 32], &payment_hash); - }, ||{}, false, Some(PERM|22), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id)); + }, ||{}, false, Some(PERM|22), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id)); // the following three with run_onion_failure_test_with_fail_intercept() test only the origin node // receiving simulated fail messages @@ -471,7 +471,7 @@ fn test_onion_failure() { let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap(); msg.reason = onion_utils::build_first_hop_failure_packet(onion_keys[0].shared_secret.as_ref(), PERM|8, &[0;0]); // short_channel_id from the processing node - }, ||{}, true, Some(PERM|8), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id)); + }, ||{}, true, Some(PERM|8), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id)); let short_channel_id = channels[1].0.contents.short_channel_id; run_onion_failure_test_with_fail_intercept("required_channel_feature_missing", 100, &nodes, &route, &payment_hash, &payment_secret, |msg| { @@ -481,13 +481,13 @@ fn test_onion_failure() { let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap(); msg.reason = onion_utils::build_first_hop_failure_packet(onion_keys[0].shared_secret.as_ref(), PERM|9, &[0;0]); // short_channel_id from the processing node - }, ||{}, true, Some(PERM|9), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id)); + }, ||{}, true, Some(PERM|9), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id)); let mut bogus_route = route.clone(); bogus_route.paths[0][1].short_channel_id -= 1; let short_channel_id = bogus_route.paths[0][1].short_channel_id; run_onion_failure_test("unknown_next_peer", 0, &nodes, &bogus_route, &payment_hash, &payment_secret, |_| {}, ||{}, true, Some(PERM|10), - Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent:true}), Some(short_channel_id)); + Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent:true}), Some(short_channel_id)); let short_channel_id = channels[1].0.contents.short_channel_id; let amt_to_forward = nodes[1].node.channel_state.lock().unwrap().by_id.get(&channels[1].2).unwrap().get_counterparty_htlc_minimum_msat() - 1; @@ -511,13 +511,13 @@ fn test_onion_failure() { let short_channel_id = channels[0].0.contents.short_channel_id; run_onion_failure_test("fee_insufficient", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| { msg.amount_msat -= 1; - }, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id)); + }, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true}), Some(short_channel_id)); let short_channel_id = channels[0].0.contents.short_channel_id; run_onion_failure_test("incorrect_cltv_expiry", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| { // need to violate: cltv_expiry - cltv_expiry_delta >= outgoing_cltv_value msg.cltv_expiry -= 1; - }, || {}, true, Some(UPDATE|13), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id)); + }, || {}, true, Some(UPDATE|13), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true}), Some(short_channel_id)); let short_channel_id = channels[1].0.contents.short_channel_id; run_onion_failure_test("expiry_too_soon", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| { diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 9e4ae058f8d..1df374d7e00 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -11,7 +11,7 @@ use ln::{PaymentHash, PaymentPreimage, PaymentSecret}; use ln::channelmanager::HTLCSource; use ln::msgs; use ln::wire::Encode; -use routing::network_graph::NetworkUpdate; +use routing::gossip::NetworkUpdate; use routing::router::RouteHop; use util::chacha20::{ChaCha20, ChaChaReader}; use util::errors::{self, APIError}; @@ -395,7 +395,7 @@ pub(super) fn process_onion_failure(secp_ctx: & } else if error_code & PERM == PERM { if !payment_failed { - network_update = Some(NetworkUpdate::ChannelClosed { + network_update = Some(NetworkUpdate::ChannelFailure { short_channel_id: failing_route_hop.short_channel_id, is_permanent: true, }); @@ -440,7 +440,7 @@ pub(super) fn process_onion_failure(secp_ctx: & if is_chan_update_invalid { // This probably indicates the node which forwarded // to the node in question corrupted something. - network_update = Some(NetworkUpdate::ChannelClosed { + network_update = Some(NetworkUpdate::ChannelFailure { short_channel_id: route_hop.short_channel_id, is_permanent: true, }); diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 68a7ef95270..d86cddb13db 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -12,8 +12,8 @@ //! Instead of actually servicing sockets ourselves we require that you implement the //! SocketDescriptor interface and use that to receive actions which you should perform on the //! socket, and call into PeerManager with bytes read from the socket. The PeerManager will then -//! call into the provided message handlers (probably a ChannelManager and NetGraphmsgHandler) with messages -//! they should handle, and encoding/sending response messages. +//! call into the provided message handlers (probably a ChannelManager and P2PGossipSync) with +//! messages they should handle, and encoding/sending response messages. use bitcoin::secp256k1::{self, Secp256k1, SecretKey, PublicKey}; @@ -25,10 +25,10 @@ use util::ser::{VecWriter, Writeable, Writer}; use ln::peer_channel_encryptor::{PeerChannelEncryptor,NextNoiseStep}; use ln::wire; use ln::wire::Encode; +use routing::gossip::{NetworkGraph, P2PGossipSync}; use util::atomic_counter::AtomicCounter; use util::events::{MessageSendEvent, MessageSendEventsProvider}; use util::logger::Logger; -use routing::network_graph::{NetworkGraph, NetGraphMsgHandler}; use prelude::*; use io; @@ -208,10 +208,9 @@ pub struct MessageHandler where /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager pub chan_handler: CM, /// A message handler which handles messages updating our knowledge of the network channel - /// graph. Usually this is just a [`NetGraphMsgHandler`] object or an - /// [`IgnoringMessageHandler`]. + /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`]. /// - /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler + /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync pub route_handler: RM, } @@ -388,7 +387,7 @@ impl Peer { /// issues such as overly long function definitions. /// /// (C-not exported) as Arcs don't make sense in bindings -pub type SimpleArcPeerManager = PeerManager>, Arc, 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 @@ -398,7 +397,7 @@ pub type SimpleArcPeerManager = PeerManager = PeerManager, &'e NetGraphMsgHandler<&'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, &'e P2PGossipSync<&'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/ln/priv_short_conf_tests.rs b/lightning/src/ln/priv_short_conf_tests.rs index 754e20a4ff1..13f66805b74 100644 --- a/lightning/src/ln/priv_short_conf_tests.rs +++ b/lightning/src/ln/priv_short_conf_tests.rs @@ -15,7 +15,7 @@ use chain::{ChannelMonitorUpdateErr, Watch}; use chain::channelmonitor::ChannelMonitor; use chain::keysinterface::{Recipient, KeysInterface}; use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, MIN_CLTV_EXPIRY_DELTA}; -use routing::network_graph::RoutingFees; +use routing::gossip::RoutingFees; use routing::router::{PaymentParameters, RouteHint, RouteHintHop}; use ln::features::{InitFeatures, InvoiceFeatures}; use ln::msgs; @@ -236,9 +236,9 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) { assert_eq!(announcement, bs_announcement); for node in nodes { - assert!(node.net_graph_msg_handler.handle_channel_announcement(&announcement).unwrap()); - node.net_graph_msg_handler.handle_channel_update(&as_update).unwrap(); - node.net_graph_msg_handler.handle_channel_update(&bs_update).unwrap(); + assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap()); + node.gossip_sync.handle_channel_update(&as_update).unwrap(); + node.gossip_sync.handle_channel_update(&bs_update).unwrap(); } } #[test] diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/gossip.rs similarity index 92% rename from lightning/src/routing/network_graph.rs rename to lightning/src/routing/gossip.rs index 18b846cbf88..52cda7173ad 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/gossip.rs @@ -162,17 +162,17 @@ pub enum NetworkUpdate { /// The update to apply via [`NetworkGraph::update_channel`]. msg: ChannelUpdate, }, - /// An error indicating only that a channel has been closed, which should be applied via - /// [`NetworkGraph::close_channel_from_update`]. - ChannelClosed { + /// An error indicating that a channel failed to route a payment, which should be applied via + /// [`NetworkGraph::channel_failed`]. + ChannelFailure { /// The short channel id of the closed channel. short_channel_id: u64, /// Whether the channel should be permanently removed or temporarily disabled until a new /// `channel_update` message is received. is_permanent: bool, }, - /// An error indicating only that a node has failed, which should be applied via - /// [`NetworkGraph::fail_node`]. + /// An error indicating that a node failed to route a payment, which should be applied via + /// [`NetworkGraph::node_failed`]. NodeFailure { /// The node id of the failed node. node_id: PublicKey, @@ -186,7 +186,7 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate, (0, ChannelUpdateMessage) => { (0, msg, required), }, - (2, ChannelClosed) => { + (2, ChannelFailure) => { (0, short_channel_id, required), (2, is_permanent, required), }, @@ -196,7 +196,7 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate, }, ); -impl, C: Deref, L: Deref> EventHandler for NetGraphMsgHandler +impl, C: Deref, L: Deref> EventHandler for P2PGossipSync 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 { @@ -215,7 +215,7 @@ where C::Target: chain::Access, L::Target: Logger { /// /// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the /// [`NetworkGraph`]. -pub struct NetGraphMsgHandler, C: Deref, L: Deref> +pub struct P2PGossipSync, C: Deref, L: Deref> where C::Target: chain::Access, L::Target: Logger { secp_ctx: Secp256k1, @@ -226,7 +226,7 @@ where C::Target: chain::Access, L::Target: Logger logger: L, } -impl, C: Deref, L: Deref> NetGraphMsgHandler +impl, C: Deref, L: Deref> P2PGossipSync where C::Target: chain::Access, L::Target: Logger { /// Creates a new tracker of the actual state of the network of channels and nodes, @@ -235,7 +235,7 @@ where C::Target: chain::Access, L::Target: Logger /// channel data is correct, and that the announcement is signed with /// channel owners' keys. pub fn new(network_graph: G, chain_access: Option, logger: L) -> Self { - NetGraphMsgHandler { + P2PGossipSync { secp_ctx: Secp256k1::verification_only(), network_graph, full_syncs_requested: AtomicUsize::new(0), @@ -253,7 +253,7 @@ where C::Target: chain::Access, L::Target: Logger } /// Gets a reference to the underlying [`NetworkGraph`] which was provided in - /// [`NetGraphMsgHandler::new`]. + /// [`P2PGossipSync::new`]. /// /// (C-not exported) as bindings don't support a reference-to-a-reference yet pub fn network_graph(&self) -> &G { @@ -282,15 +282,15 @@ where C::Target: chain::Access, L::Target: Logger log_debug!(self.logger, "Updating channel with channel_update from a payment failure. Channel {} is {}.", short_channel_id, status); let _ = self.network_graph.update_channel(msg, &self.secp_ctx); }, - NetworkUpdate::ChannelClosed { short_channel_id, is_permanent } => { + NetworkUpdate::ChannelFailure { short_channel_id, is_permanent } => { let action = if is_permanent { "Removing" } else { "Disabling" }; log_debug!(self.logger, "{} channel graph entry for {} due to a payment failure.", action, short_channel_id); - self.network_graph.close_channel_from_update(short_channel_id, is_permanent); + self.network_graph.channel_failed(short_channel_id, is_permanent); }, NetworkUpdate::NodeFailure { ref node_id, is_permanent } => { let action = if is_permanent { "Removing" } else { "Disabling" }; log_debug!(self.logger, "{} node graph entry for {} due to a payment failure.", action, node_id); - self.network_graph.fail_node(node_id, is_permanent); + self.network_graph.node_failed(node_id, is_permanent); }, } } @@ -316,7 +316,7 @@ macro_rules! secp_verify_sig { }; } -impl, C: Deref, L: Deref> RoutingMessageHandler for NetGraphMsgHandler +impl, C: Deref, L: Deref> RoutingMessageHandler for P2PGossipSync where C::Target: chain::Access, L::Target: Logger { fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result { @@ -605,7 +605,7 @@ where C::Target: chain::Access, L::Target: Logger } } -impl, C: Deref, L: Deref> MessageSendEventsProvider for NetGraphMsgHandler +impl, C: Deref, L: Deref> MessageSendEventsProvider for P2PGossipSync where C::Target: chain::Access, L::Target: Logger, @@ -1102,7 +1102,7 @@ impl NetworkGraph { /// For an already known node (from channel announcements), update its stored properties from a /// given node announcement. /// - /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's + /// You probably don't want to call this directly, instead relying on a P2PGossipSync's /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. pub fn update_node_from_announcement(&self, msg: &msgs::NodeAnnouncement, secp_ctx: &Secp256k1) -> Result<(), LightningError> { @@ -1154,7 +1154,7 @@ impl NetworkGraph { /// Store or update channel info from a channel announcement. /// - /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's + /// You probably don't want to call this directly, instead relying on a P2PGossipSync's /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. /// @@ -1328,11 +1328,11 @@ impl NetworkGraph { self.add_channel_between_nodes(msg.short_channel_id, chan_info, utxo_value) } - /// Close a channel if a corresponding HTLC fail was sent. + /// Marks a channel in the graph as failed if a corresponding HTLC fail was sent. /// If permanent, removes a channel from the local storage. /// May cause the removal of nodes too, if this was their last channel. /// If not permanent, makes channels unavailable for routing. - pub fn close_channel_from_update(&self, short_channel_id: u64, is_permanent: bool) { + pub fn channel_failed(&self, short_channel_id: u64, is_permanent: bool) { let mut channels = self.channels.write().unwrap(); if is_permanent { if let Some(chan) = channels.remove(&short_channel_id) { @@ -1352,7 +1352,7 @@ impl NetworkGraph { } /// Marks a node in the graph as failed. - pub fn fail_node(&self, _node_id: &PublicKey, is_permanent: bool) { + pub fn node_failed(&self, _node_id: &PublicKey, is_permanent: bool) { if is_permanent { // TODO: Wholly remove the node } else { @@ -1426,7 +1426,7 @@ impl NetworkGraph { /// For an already known (from announcement) channel, update info about one of the directions /// of the channel. /// - /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's + /// You probably don't want to call this directly, instead relying on a P2PGossipSync's /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. /// @@ -1643,7 +1643,7 @@ mod tests { use chain; use ln::PaymentHash; use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; - use routing::network_graph::{NetGraphMsgHandler, NetworkGraph, NetworkUpdate, MAX_EXCESS_BYTES_FOR_RELAY}; + use routing::gossip::{P2PGossipSync, NetworkGraph, NetworkUpdate, MAX_EXCESS_BYTES_FOR_RELAY}; use ln::msgs::{Init, OptionalField, RoutingMessageHandler, UnsignedNodeAnnouncement, NodeAnnouncement, UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate, ReplyChannelRange, QueryChannelRange, QueryShortChannelIds, MAX_VALUE_MSAT}; @@ -1678,27 +1678,27 @@ mod tests { NetworkGraph::new(genesis_hash) } - fn create_net_graph_msg_handler(network_graph: &NetworkGraph) -> ( - Secp256k1, NetGraphMsgHandler<&NetworkGraph, Arc, Arc> + fn create_gossip_sync(network_graph: &NetworkGraph) -> ( + Secp256k1, P2PGossipSync<&NetworkGraph, Arc, Arc> ) { let secp_ctx = Secp256k1::new(); let logger = Arc::new(test_utils::TestLogger::new()); - let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger)); - (secp_ctx, net_graph_msg_handler) + let gossip_sync = P2PGossipSync::new(network_graph, None, Arc::clone(&logger)); + (secp_ctx, gossip_sync) } #[test] fn request_full_sync_finite_times() { let network_graph = create_network_graph(); - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); + let (secp_ctx, gossip_sync) = create_gossip_sync(&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)); - assert!(net_graph_msg_handler.should_request_full_sync(&node_id)); - assert!(net_graph_msg_handler.should_request_full_sync(&node_id)); - assert!(net_graph_msg_handler.should_request_full_sync(&node_id)); - assert!(net_graph_msg_handler.should_request_full_sync(&node_id)); - assert!(!net_graph_msg_handler.should_request_full_sync(&node_id)); + assert!(gossip_sync.should_request_full_sync(&node_id)); + assert!(gossip_sync.should_request_full_sync(&node_id)); + assert!(gossip_sync.should_request_full_sync(&node_id)); + assert!(gossip_sync.should_request_full_sync(&node_id)); + assert!(gossip_sync.should_request_full_sync(&node_id)); + assert!(!gossip_sync.should_request_full_sync(&node_id)); } fn get_signed_node_announcement(f: F, node_key: &SecretKey, secp_ctx: &Secp256k1) -> NodeAnnouncement { @@ -1783,14 +1783,14 @@ mod tests { #[test] fn handling_node_announcements() { let network_graph = create_network_graph(); - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); + let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let zero_hash = Sha256dHash::hash(&[0; 32]); let valid_announcement = get_signed_node_announcement(|_| {}, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(&valid_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!("No existing channels for node_announcement", e.err) }; @@ -1798,19 +1798,19 @@ mod tests { { // Announce a channel to add a corresponding node. let valid_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; } - match net_graph_msg_handler.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(&valid_announcement) { Ok(res) => assert!(res), Err(_) => panic!() }; let fake_msghash = hash_to_message!(&zero_hash); - match net_graph_msg_handler.handle_node_announcement( + match gossip_sync.handle_node_announcement( &NodeAnnouncement { signature: secp_ctx.sign_ecdsa(&fake_msghash, node_1_privkey), contents: valid_announcement.contents.clone() @@ -1824,7 +1824,7 @@ mod tests { unsigned_announcement.excess_data.resize(MAX_EXCESS_BYTES_FOR_RELAY + 1, 0); }, node_1_privkey, &secp_ctx); // Return false because contains excess data. - match net_graph_msg_handler.handle_node_announcement(&announcement_with_data) { + match gossip_sync.handle_node_announcement(&announcement_with_data) { Ok(res) => assert!(!res), Err(_) => panic!() }; @@ -1834,7 +1834,7 @@ mod tests { let outdated_announcement = get_signed_node_announcement(|unsigned_announcement| { unsigned_announcement.timestamp += 1000 - 10; }, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_node_announcement(&outdated_announcement) { + match gossip_sync.handle_node_announcement(&outdated_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Update older than last processed update") }; @@ -1853,8 +1853,8 @@ 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)); - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + let mut gossip_sync = P2PGossipSync::new(&network_graph, None, Arc::clone(&logger)); + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; @@ -1868,7 +1868,7 @@ mod tests { // If we receive announcement for the same channel (with UTXO lookups disabled), // drop new one on the floor, since we can't see any changes. - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Already have knowledge of channel") }; @@ -1877,12 +1877,12 @@ 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)); + gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger)); let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id += 1; }, node_1_privkey, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Channel announced without corresponding UTXO entry") }; @@ -1892,7 +1892,7 @@ mod tests { let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id += 2; }, node_1_privkey, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; @@ -1907,7 +1907,7 @@ mod tests { // If we receive announcement for the same channel (but TX is not confirmed), // drop new one on the floor, since we can't see any changes. *chain_source.utxo_ret.lock().unwrap() = Err(chain::AccessError::UnknownTx); - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Channel announced without corresponding UTXO entry") }; @@ -1918,7 +1918,7 @@ mod tests { unsigned_announcement.features = ChannelFeatures::empty(); unsigned_announcement.short_channel_id += 2; }, node_1_privkey, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; @@ -1936,20 +1936,20 @@ mod tests { unsigned_announcement.short_channel_id += 3; unsigned_announcement.excess_data.resize(MAX_EXCESS_BYTES_FOR_RELAY + 1, 0); }, node_1_privkey, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(!res), _ => panic!() }; let mut invalid_sig_announcement = valid_announcement.clone(); invalid_sig_announcement.contents.excess_data = Vec::new(); - match net_graph_msg_handler.handle_channel_announcement(&invalid_sig_announcement) { + match gossip_sync.handle_channel_announcement(&invalid_sig_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Invalid signature on channel_announcement message") }; let channel_to_itself_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_announcement(&channel_to_itself_announcement) { + match gossip_sync.handle_channel_announcement(&channel_to_itself_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Channel announcement node had a channel with itself") }; @@ -1961,7 +1961,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 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_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); @@ -1976,7 +1976,7 @@ mod tests { let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); short_channel_id = valid_channel_announcement.contents.short_channel_id; - match net_graph_msg_handler.handle_channel_announcement(&valid_channel_announcement) { + match gossip_sync.handle_channel_announcement(&valid_channel_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -1984,7 +1984,7 @@ mod tests { } let valid_channel_update = get_signed_channel_update(|_| {}, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(&valid_channel_update) { Ok(res) => assert!(res), _ => panic!() }; @@ -2004,7 +2004,7 @@ mod tests { unsigned_channel_update.excess_data.resize(MAX_EXCESS_BYTES_FOR_RELAY + 1, 0); }, node_1_privkey, &secp_ctx); // Return false because contains excess data - match net_graph_msg_handler.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(&valid_channel_update) { Ok(res) => assert!(!res), _ => panic!() }; @@ -2013,7 +2013,7 @@ mod tests { unsigned_channel_update.timestamp += 110; unsigned_channel_update.short_channel_id += 1; }, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(&valid_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Couldn't find channel for update") }; @@ -2022,7 +2022,7 @@ mod tests { unsigned_channel_update.htlc_maximum_msat = OptionalField::Present(MAX_VALUE_MSAT + 1); unsigned_channel_update.timestamp += 110; }, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(&valid_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "htlc_maximum_msat is larger than maximum possible msats") }; @@ -2031,7 +2031,7 @@ mod tests { unsigned_channel_update.htlc_maximum_msat = OptionalField::Present(amount_sats * 1000 + 1); unsigned_channel_update.timestamp += 110; }, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(&valid_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "htlc_maximum_msat is larger than channel capacity or capacity is bogus") }; @@ -2041,7 +2041,7 @@ mod tests { let valid_channel_update = get_signed_channel_update(|unsigned_channel_update| { unsigned_channel_update.timestamp += 100; }, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(&valid_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Update had same timestamp as last processed update") }; @@ -2052,7 +2052,7 @@ mod tests { let zero_hash = Sha256dHash::hash(&[0; 32]); let fake_msghash = hash_to_message!(&zero_hash); invalid_sig_channel_update.signature = secp_ctx.sign_ecdsa(&fake_msghash, node_1_privkey); - match net_graph_msg_handler.handle_channel_update(&invalid_sig_channel_update) { + match gossip_sync.handle_channel_update(&invalid_sig_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Invalid signature on channel_update message") }; @@ -2064,7 +2064,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 gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), &logger); let secp_ctx = Secp256k1::new(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); @@ -2087,7 +2087,7 @@ mod tests { let valid_channel_update = get_signed_channel_update(|_| {}, node_1_privkey, &secp_ctx); assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none()); - net_graph_msg_handler.handle_event(&Event::PaymentPathFailed { + gossip_sync.handle_event(&Event::PaymentPathFailed { payment_id: None, payment_hash: PaymentHash([0; 32]), rejected_by_dest: false, @@ -2114,13 +2114,13 @@ mod tests { } }; - net_graph_msg_handler.handle_event(&Event::PaymentPathFailed { + gossip_sync.handle_event(&Event::PaymentPathFailed { payment_id: None, payment_hash: PaymentHash([0; 32]), rejected_by_dest: false, all_paths_failed: true, path: vec![], - network_update: Some(NetworkUpdate::ChannelClosed { + network_update: Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: false, }), @@ -2139,13 +2139,13 @@ mod tests { } // Permanent closing deletes a channel - net_graph_msg_handler.handle_event(&Event::PaymentPathFailed { + gossip_sync.handle_event(&Event::PaymentPathFailed { payment_id: None, payment_hash: PaymentHash([0; 32]), rejected_by_dest: false, all_paths_failed: true, path: vec![], - network_update: Some(NetworkUpdate::ChannelClosed { + network_update: Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true, }), @@ -2168,7 +2168,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 gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), &logger); let secp_ctx = Secp256k1::new(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); @@ -2181,7 +2181,7 @@ mod tests { assert!(network_graph.read_only().channels().get(&short_channel_id).is_some()); let valid_channel_update = get_signed_channel_update(|_| {}, node_1_privkey, &secp_ctx); - assert!(net_graph_msg_handler.handle_channel_update(&valid_channel_update).is_ok()); + assert!(gossip_sync.handle_channel_update(&valid_channel_update).is_ok()); assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_some()); network_graph.remove_stale_channels_with_time(100 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS); @@ -2211,12 +2211,12 @@ mod tests { #[test] fn getting_next_channel_announcements() { let network_graph = create_network_graph(); - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); + let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); // Channels were not announced yet. - let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(0, 1); + let channels_with_announcements = gossip_sync.get_next_channel_announcements(0, 1); assert_eq!(channels_with_announcements.len(), 0); let short_channel_id; @@ -2224,14 +2224,14 @@ mod tests { // Announce a channel we will update let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); short_channel_id = valid_channel_announcement.contents.short_channel_id; - match net_graph_msg_handler.handle_channel_announcement(&valid_channel_announcement) { + match gossip_sync.handle_channel_announcement(&valid_channel_announcement) { Ok(_) => (), Err(_) => panic!() }; } // Contains initial channel announcement now. - let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(short_channel_id, 1); + let channels_with_announcements = gossip_sync.get_next_channel_announcements(short_channel_id, 1); assert_eq!(channels_with_announcements.len(), 1); if let Some(channel_announcements) = channels_with_announcements.first() { let &(_, ref update_1, ref update_2) = channel_announcements; @@ -2247,14 +2247,14 @@ mod tests { let valid_channel_update = get_signed_channel_update(|unsigned_channel_update| { unsigned_channel_update.timestamp = 101; }, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(&valid_channel_update) { Ok(_) => (), Err(_) => panic!() }; } // Now contains an initial announcement and an update. - let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(short_channel_id, 1); + let channels_with_announcements = gossip_sync.get_next_channel_announcements(short_channel_id, 1); assert_eq!(channels_with_announcements.len(), 1); if let Some(channel_announcements) = channels_with_announcements.first() { let &(_, ref update_1, ref update_2) = channel_announcements; @@ -2270,14 +2270,14 @@ mod tests { unsigned_channel_update.timestamp = 102; unsigned_channel_update.excess_data = [1; MAX_EXCESS_BYTES_FOR_RELAY + 1].to_vec(); }, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(&valid_channel_update) { Ok(_) => (), Err(_) => panic!() }; } // Test that announcements with excess data won't be returned - let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(short_channel_id, 1); + let channels_with_announcements = gossip_sync.get_next_channel_announcements(short_channel_id, 1); assert_eq!(channels_with_announcements.len(), 1); if let Some(channel_announcements) = channels_with_announcements.first() { let &(_, ref update_1, ref update_2) = channel_announcements; @@ -2288,26 +2288,26 @@ mod tests { } // Further starting point have no channels after it - let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(short_channel_id + 1000, 1); + let channels_with_announcements = gossip_sync.get_next_channel_announcements(short_channel_id + 1000, 1); assert_eq!(channels_with_announcements.len(), 0); } #[test] fn getting_next_node_announcements() { let network_graph = create_network_graph(); - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); + let (secp_ctx, gossip_sync) = create_gossip_sync(&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); // No nodes yet. - let next_announcements = net_graph_msg_handler.get_next_node_announcements(None, 10); + let next_announcements = gossip_sync.get_next_node_announcements(None, 10); assert_eq!(next_announcements.len(), 0); { // Announce a channel to add 2 nodes let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_announcement(&valid_channel_announcement) { + match gossip_sync.handle_channel_announcement(&valid_channel_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -2315,28 +2315,28 @@ mod tests { // Nodes were never announced - let next_announcements = net_graph_msg_handler.get_next_node_announcements(None, 3); + let next_announcements = gossip_sync.get_next_node_announcements(None, 3); assert_eq!(next_announcements.len(), 0); { let valid_announcement = get_signed_node_announcement(|_| {}, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(&valid_announcement) { Ok(_) => (), Err(_) => panic!() }; let valid_announcement = get_signed_node_announcement(|_| {}, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(&valid_announcement) { Ok(_) => (), Err(_) => panic!() }; } - let next_announcements = net_graph_msg_handler.get_next_node_announcements(None, 3); + let next_announcements = gossip_sync.get_next_node_announcements(None, 3); assert_eq!(next_announcements.len(), 2); // Skip the first node. - let next_announcements = net_graph_msg_handler.get_next_node_announcements(Some(&node_id_1), 2); + let next_announcements = gossip_sync.get_next_node_announcements(Some(&node_id_1), 2); assert_eq!(next_announcements.len(), 1); { @@ -2345,33 +2345,33 @@ mod tests { unsigned_announcement.timestamp += 10; unsigned_announcement.excess_data = [1; MAX_EXCESS_BYTES_FOR_RELAY + 1].to_vec(); }, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(&valid_announcement) { Ok(res) => assert!(!res), Err(_) => panic!() }; } - let next_announcements = net_graph_msg_handler.get_next_node_announcements(Some(&node_id_1), 2); + let next_announcements = gossip_sync.get_next_node_announcements(Some(&node_id_1), 2); assert_eq!(next_announcements.len(), 0); } #[test] fn network_graph_serialization() { let network_graph = create_network_graph(); - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); + let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); // Announce a channel to add a corresponding node. let valid_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; let valid_announcement = get_signed_node_announcement(|_| {}, node_1_privkey, &secp_ctx); - match net_graph_msg_handler.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(&valid_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -2385,7 +2385,7 @@ mod tests { #[test] fn network_graph_tlv_serialization() { - let mut network_graph = create_network_graph(); + let network_graph = create_network_graph(); network_graph.set_last_rapid_gossip_sync_timestamp(42); let mut w = test_utils::TestVecWriter(Vec::new()); @@ -2401,7 +2401,7 @@ mod tests { use std::time::{SystemTime, UNIX_EPOCH}; let network_graph = create_network_graph(); - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); + let (secp_ctx, gossip_sync) = create_gossip_sync(&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); @@ -2410,16 +2410,16 @@ mod tests { // It should ignore if gossip_queries feature is not enabled { let init_msg = Init { features: InitFeatures::known().clear_gossip_queries(), remote_network_address: None }; - net_graph_msg_handler.peer_connected(&node_id_1, &init_msg); - let events = net_graph_msg_handler.get_and_clear_pending_msg_events(); + gossip_sync.peer_connected(&node_id_1, &init_msg); + let events = gossip_sync.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 0); } // It should send a gossip_timestamp_filter with the correct information { let init_msg = Init { features: InitFeatures::known(), remote_network_address: None }; - net_graph_msg_handler.peer_connected(&node_id_1, &init_msg); - let events = net_graph_msg_handler.get_and_clear_pending_msg_events(); + gossip_sync.peer_connected(&node_id_1, &init_msg); + let events = gossip_sync.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); match &events[0] { MessageSendEvent::SendGossipTimestampFilter{ node_id, msg } => { @@ -2438,7 +2438,7 @@ mod tests { #[test] fn handling_query_channel_range() { let network_graph = create_network_graph(); - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); + let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let chain_hash = genesis_block(Network::Testnet).header.block_hash(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); @@ -2462,7 +2462,7 @@ mod tests { let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id = scid; }, node_1_privkey, node_2_privkey, &secp_ctx); - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(_) => (), _ => panic!() }; @@ -2470,7 +2470,7 @@ mod tests { // Error when number_of_blocks=0 do_handling_query_channel_range( - &net_graph_msg_handler, + &gossip_sync, &node_id_2, QueryChannelRange { chain_hash: chain_hash.clone(), @@ -2489,7 +2489,7 @@ mod tests { // Error when wrong chain do_handling_query_channel_range( - &net_graph_msg_handler, + &gossip_sync, &node_id_2, QueryChannelRange { chain_hash: genesis_block(Network::Bitcoin).header.block_hash(), @@ -2508,7 +2508,7 @@ mod tests { // Error when first_blocknum > 0xffffff do_handling_query_channel_range( - &net_graph_msg_handler, + &gossip_sync, &node_id_2, QueryChannelRange { chain_hash: chain_hash.clone(), @@ -2527,7 +2527,7 @@ mod tests { // Empty reply when max valid SCID block num do_handling_query_channel_range( - &net_graph_msg_handler, + &gossip_sync, &node_id_2, QueryChannelRange { chain_hash: chain_hash.clone(), @@ -2548,7 +2548,7 @@ mod tests { // No results in valid query range do_handling_query_channel_range( - &net_graph_msg_handler, + &gossip_sync, &node_id_2, QueryChannelRange { chain_hash: chain_hash.clone(), @@ -2569,7 +2569,7 @@ mod tests { // Overflow first_blocknum + number_of_blocks do_handling_query_channel_range( - &net_graph_msg_handler, + &gossip_sync, &node_id_2, QueryChannelRange { chain_hash: chain_hash.clone(), @@ -2592,7 +2592,7 @@ mod tests { // Single block exactly full do_handling_query_channel_range( - &net_graph_msg_handler, + &gossip_sync, &node_id_2, QueryChannelRange { chain_hash: chain_hash.clone(), @@ -2615,7 +2615,7 @@ mod tests { // Multiple split on new block do_handling_query_channel_range( - &net_graph_msg_handler, + &gossip_sync, &node_id_2, QueryChannelRange { chain_hash: chain_hash.clone(), @@ -2647,7 +2647,7 @@ mod tests { // Multiple split on same block do_handling_query_channel_range( - &net_graph_msg_handler, + &gossip_sync, &node_id_2, QueryChannelRange { chain_hash: chain_hash.clone(), @@ -2679,7 +2679,7 @@ mod tests { } fn do_handling_query_channel_range( - net_graph_msg_handler: &NetGraphMsgHandler<&NetworkGraph, Arc, Arc>, + gossip_sync: &P2PGossipSync<&NetworkGraph, Arc, Arc>, test_node_id: &PublicKey, msg: QueryChannelRange, expected_ok: bool, @@ -2688,7 +2688,7 @@ mod tests { let mut max_firstblocknum = msg.first_blocknum.saturating_sub(1); let mut c_lightning_0_9_prev_end_blocknum = max_firstblocknum; let query_end_blocknum = msg.end_blocknum(); - let result = net_graph_msg_handler.handle_query_channel_range(test_node_id, msg); + let result = gossip_sync.handle_query_channel_range(test_node_id, msg); if expected_ok { assert!(result.is_ok()); @@ -2696,7 +2696,7 @@ mod tests { assert!(result.is_err()); } - let events = net_graph_msg_handler.get_and_clear_pending_msg_events(); + let events = gossip_sync.get_and_clear_pending_msg_events(); assert_eq!(events.len(), expected_replies.len()); for i in 0..events.len() { @@ -2729,13 +2729,13 @@ mod tests { #[test] fn handling_query_short_channel_ids() { let network_graph = create_network_graph(); - let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph); + let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let node_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey); let chain_hash = genesis_block(Network::Testnet).header.block_hash(); - let result = net_graph_msg_handler.handle_query_short_channel_ids(&node_id, QueryShortChannelIds { + let result = gossip_sync.handle_query_short_channel_ids(&node_id, QueryShortChannelIds { chain_hash, short_channel_ids: vec![0x0003e8_000000_0000], }); diff --git a/lightning/src/routing/mod.rs b/lightning/src/routing/mod.rs index a3ab6c0c1b3..c7babbe3027 100644 --- a/lightning/src/routing/mod.rs +++ b/lightning/src/routing/mod.rs @@ -9,6 +9,6 @@ //! Structs and impls for receiving messages about the network and storing the topology live here. -pub mod network_graph; +pub mod gossip; pub mod router; pub mod scoring; diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 5d4d4ac1238..301ae76ddbb 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -9,7 +9,7 @@ //! The top-level routing/network map tracking logic lives here. //! -//! You probably want to create a NetGraphMsgHandler and use that as your RoutingMessageHandler and then +//! You probably want to create a P2PGossipSync and use that as your RoutingMessageHandler and then //! interrogate it to get routes for your own payments. use bitcoin::secp256k1::PublicKey; @@ -17,8 +17,8 @@ use bitcoin::secp256k1::PublicKey; use ln::channelmanager::ChannelDetails; use ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures}; use ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT}; +use routing::gossip::{DirectedChannelInfoWithUpdate, EffectiveCapacity, NetworkGraph, ReadOnlyNetworkGraph, NodeId, RoutingFees}; use routing::scoring::{ChannelUsage, Score}; -use routing::network_graph::{DirectedChannelInfoWithUpdate, EffectiveCapacity, NetworkGraph, ReadOnlyNetworkGraph, NodeId, RoutingFees}; use util::ser::{Writeable, Readable, Writer}; use util::logger::{Level, Logger}; use util::chacha20::ChaCha20; @@ -1858,7 +1858,7 @@ fn build_route_from_hops_internal( #[cfg(test)] mod tests { - use routing::network_graph::{NetworkGraph, NetGraphMsgHandler, NodeId}; + use routing::gossip::{NetworkGraph, P2PGossipSync, NodeId}; use routing::router::{get_route, build_route_from_hops_internal, add_random_cltv_offset, default_node_features, PaymentParameters, Route, RouteHint, RouteHintHop, RouteHop, RoutingFees, DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, MAX_PATH_LENGTH_ESTIMATE}; @@ -1926,7 +1926,7 @@ mod tests { // Using the same keys for LN and BTC ids fn add_channel( - net_graph_msg_handler: &NetGraphMsgHandler, Arc, Arc>, + gossip_sync: &P2PGossipSync, 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); @@ -1951,14 +1951,14 @@ mod tests { bitcoin_signature_2: secp_ctx.sign_ecdsa(&msghash, node_2_privkey), contents: unsigned_announcement.clone(), }; - match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; } fn update_channel( - net_graph_msg_handler: &NetGraphMsgHandler, Arc, Arc>, + gossip_sync: &P2PGossipSync, Arc, Arc>, secp_ctx: &Secp256k1, node_privkey: &SecretKey, update: UnsignedChannelUpdate ) { let msghash = hash_to_message!(&Sha256dHash::hash(&update.encode()[..])[..]); @@ -1967,14 +1967,14 @@ mod tests { contents: update.clone() }; - match net_graph_msg_handler.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(&valid_channel_update) { Ok(res) => assert!(res), Err(_) => panic!() }; } fn add_or_update_node( - net_graph_msg_handler: &NetGraphMsgHandler, Arc, Arc>, + gossip_sync: &P2PGossipSync, Arc, Arc>, secp_ctx: &Secp256k1, node_privkey: &SecretKey, features: NodeFeatures, timestamp: u32 ) { let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey); @@ -1994,7 +1994,7 @@ mod tests { contents: unsigned_announcement.clone() }; - match net_graph_msg_handler.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(&valid_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -2029,7 +2029,7 @@ mod tests { } fn build_line_graph() -> ( - Secp256k1, sync::Arc, NetGraphMsgHandler, + Secp256k1, sync::Arc, P2PGossipSync, sync::Arc, sync::Arc>, sync::Arc, sync::Arc, ) { @@ -2037,7 +2037,7 @@ mod tests { let logger = Arc::new(test_utils::TestLogger::new()); 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 net_graph_msg_handler = NetGraphMsgHandler::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: // our_id -1(1)2- node0 -1(2)2- node1 - ... - node19 @@ -2046,9 +2046,9 @@ mod tests { for (idx, (cur_privkey, next_privkey)) in core::iter::once(&our_privkey) .chain(privkeys.iter()).zip(privkeys.iter()).enumerate() { let cur_short_channel_id = (idx as u64) + 1; - add_channel(&net_graph_msg_handler, &secp_ctx, &cur_privkey, &next_privkey, + add_channel(&gossip_sync, &secp_ctx, &cur_privkey, &next_privkey, ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), cur_short_channel_id); - update_channel(&net_graph_msg_handler, &secp_ctx, &cur_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &cur_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: cur_short_channel_id, timestamp: idx as u32, @@ -2060,7 +2060,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &next_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &next_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: cur_short_channel_id, timestamp: (idx as u32)+1, @@ -2072,17 +2072,17 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, next_privkey, + add_or_update_node(&gossip_sync, &secp_ctx, next_privkey, NodeFeatures::from_le_bytes(id_to_feature_flags(1)), 0); } - (secp_ctx, network_graph, net_graph_msg_handler, chain_monitor, logger) + (secp_ctx, network_graph, gossip_sync, chain_monitor, logger) } fn build_graph() -> ( Secp256k1, sync::Arc, - NetGraphMsgHandler, sync::Arc, sync::Arc>, + P2PGossipSync, sync::Arc, sync::Arc>, sync::Arc, sync::Arc, ) { @@ -2090,7 +2090,7 @@ mod tests { let logger = Arc::new(test_utils::TestLogger::new()); 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 net_graph_msg_handler = NetGraphMsgHandler::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: // // -1(1)2- node0 -1(3)2- @@ -2152,8 +2152,8 @@ mod tests { let (our_privkey, _, privkeys, _) = get_nodes(&secp_ctx); - add_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, &privkeys[0], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[0], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1); + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 1, @@ -2166,10 +2166,10 @@ mod tests { excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[0], NodeFeatures::from_le_bytes(id_to_feature_flags(1)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[0], NodeFeatures::from_le_bytes(id_to_feature_flags(1)), 0); - add_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2); + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 1, @@ -2181,7 +2181,7 @@ mod tests { fee_proportional_millionths: u32::max_value(), excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 1, @@ -2194,10 +2194,10 @@ mod tests { excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[1], NodeFeatures::from_le_bytes(id_to_feature_flags(2)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[1], NodeFeatures::from_le_bytes(id_to_feature_flags(2)), 0); - add_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, &privkeys[7], ChannelFeatures::from_le_bytes(id_to_feature_flags(12)), 12); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[7], ChannelFeatures::from_le_bytes(id_to_feature_flags(12)), 12); + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 1, @@ -2209,7 +2209,7 @@ mod tests { fee_proportional_millionths: u32::max_value(), excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 1, @@ -2222,10 +2222,10 @@ mod tests { excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[7], NodeFeatures::from_le_bytes(id_to_feature_flags(8)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[7], NodeFeatures::from_le_bytes(id_to_feature_flags(8)), 0); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3); + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 1, @@ -2237,7 +2237,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 1, @@ -2250,8 +2250,8 @@ mod tests { excess_data: Vec::new() }); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[1], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4); + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 1, @@ -2263,7 +2263,7 @@ mod tests { fee_proportional_millionths: 1000000, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 1, @@ -2276,8 +2276,8 @@ mod tests { excess_data: Vec::new() }); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(13)), 13); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[7], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(13)), 13); + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 1, @@ -2289,7 +2289,7 @@ mod tests { fee_proportional_millionths: 2000000, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 1, @@ -2302,10 +2302,10 @@ mod tests { excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[2], NodeFeatures::from_le_bytes(id_to_feature_flags(3)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[2], NodeFeatures::from_le_bytes(id_to_feature_flags(3)), 0); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6); + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 1, @@ -2317,7 +2317,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 1, @@ -2330,8 +2330,8 @@ mod tests { excess_data: Vec::new(), }); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(11)), 11); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(11)), 11); + update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 11, timestamp: 1, @@ -2343,7 +2343,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[3], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[3], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 11, timestamp: 1, @@ -2356,12 +2356,12 @@ mod tests { excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[4], NodeFeatures::from_le_bytes(id_to_feature_flags(5)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[4], NodeFeatures::from_le_bytes(id_to_feature_flags(5)), 0); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[3], NodeFeatures::from_le_bytes(id_to_feature_flags(4)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[3], NodeFeatures::from_le_bytes(id_to_feature_flags(4)), 0); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], &privkeys[5], ChannelFeatures::from_le_bytes(id_to_feature_flags(7)), 7); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[5], ChannelFeatures::from_le_bytes(id_to_feature_flags(7)), 7); + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 7, timestamp: 1, @@ -2373,7 +2373,7 @@ mod tests { fee_proportional_millionths: 1000000, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[5], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[5], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 7, timestamp: 1, @@ -2386,9 +2386,9 @@ mod tests { excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[5], NodeFeatures::from_le_bytes(id_to_feature_flags(6)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[5], NodeFeatures::from_le_bytes(id_to_feature_flags(6)), 0); - (secp_ctx, network_graph, net_graph_msg_handler, chain_monitor, logger) + (secp_ctx, network_graph, gossip_sync, chain_monitor, logger) } #[test] @@ -2448,7 +2448,7 @@ mod tests { #[test] fn htlc_minimum_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let payment_params = PaymentParameters::from_node_id(nodes[2]); let scorer = test_utils::TestScorer::with_penalty(0); @@ -2458,7 +2458,7 @@ mod tests { // Simple route to 2 via 1 // Disable other paths - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -2470,7 +2470,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 2, @@ -2482,7 +2482,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 2, @@ -2494,7 +2494,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 2, @@ -2506,7 +2506,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 7, timestamp: 2, @@ -2521,7 +2521,7 @@ mod tests { // Check against amount_to_transfer_over_msat. // Set minimal HTLC of 200_000_000 msat. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 3, @@ -2536,7 +2536,7 @@ mod tests { // Second hop only allows to forward 199_999_999 at most, thus not allowing the first hop to // be used. - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 3, @@ -2555,7 +2555,7 @@ mod tests { } else { panic!(); } // Lift the restriction on the first hop. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 4, @@ -2575,7 +2575,7 @@ mod tests { #[test] fn htlc_minimum_overpay_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); let scorer = test_utils::TestScorer::with_penalty(0); @@ -2585,7 +2585,7 @@ mod tests { // A route to node#2 via two paths. // One path allows transferring 35-40 sats, another one also allows 35-40 sats. // Thus, they can't send 60 without overpaying. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -2597,7 +2597,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 3, @@ -2611,7 +2611,7 @@ mod tests { }); // Make 0 fee. - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 2, @@ -2623,7 +2623,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 2, @@ -2637,7 +2637,7 @@ mod tests { }); // Disable other paths - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 3, @@ -2658,7 +2658,7 @@ mod tests { // Now, test that if there are 2 paths, a "cheaper" by fee path wouldn't be prioritized // while taking even more fee to match htlc_minimum_msat. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 4, @@ -2670,7 +2670,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 3, @@ -2682,7 +2682,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 4, @@ -2713,7 +2713,7 @@ mod tests { #[test] fn disable_channels_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let payment_params = PaymentParameters::from_node_id(nodes[2]); let scorer = test_utils::TestScorer::with_penalty(0); @@ -2721,7 +2721,7 @@ mod tests { let random_seed_bytes = keys_manager.get_secure_random_bytes(); // // Disable channels 4 and 12 by flags=2 - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 2, @@ -2733,7 +2733,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -2773,7 +2773,7 @@ mod tests { #[test] fn disable_node_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let payment_params = PaymentParameters::from_node_id(nodes[2]); let scorer = test_utils::TestScorer::with_penalty(0); @@ -2783,9 +2783,9 @@ mod tests { // Disable nodes 1, 2, and 8 by requiring unknown feature bits let mut unknown_features = NodeFeatures::known(); unknown_features.set_unknown_feature_required(); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[0], unknown_features.clone(), 1); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[1], unknown_features.clone(), 1); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[7], unknown_features.clone(), 1); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[0], unknown_features.clone(), 1); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[1], unknown_features.clone(), 1); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[7], unknown_features.clone(), 1); // If all nodes require some features we don't understand, route should fail if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, 42, Arc::clone(&logger), &scorer, &random_seed_bytes) { @@ -3128,7 +3128,7 @@ mod tests { #[test] fn multi_hint_last_hops_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let last_hops = multi_hop_last_hops_hint([nodes[2], nodes[3]]); let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops.clone()); @@ -3139,7 +3139,7 @@ mod tests { // Test shows that multiple hop hints are considered. // Disabling channels 6 & 7 by flags=2 - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 2, @@ -3151,7 +3151,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 7, timestamp: 2, @@ -3198,7 +3198,7 @@ mod tests { #[test] fn private_multi_hint_last_hops_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let non_announced_privkey = SecretKey::from_slice(&hex::decode(format!("{:02x}", 0xf0).repeat(32)).unwrap()[..]).unwrap(); @@ -3211,7 +3211,7 @@ mod tests { // Test shows that multiple hop hints are considered. // Disabling channels 6 & 7 by flags=2 - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 2, @@ -3223,7 +3223,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 7, timestamp: 2, @@ -3541,7 +3541,7 @@ mod tests { fn available_amount_while_routing_test() { // Tests whether we choose the correct available channel amount while routing. - let (secp_ctx, network_graph, mut net_graph_msg_handler, chain_monitor, logger) = build_graph(); + let (secp_ctx, network_graph, mut gossip_sync, chain_monitor, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -3552,7 +3552,7 @@ mod tests { // our node to node2 via node0: channels {1, 3}. // First disable all other paths. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -3564,7 +3564,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -3579,7 +3579,7 @@ mod tests { // Make the first channel (#1) very permissive, // and we will be testing all limits on the second channel. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 2, @@ -3594,7 +3594,7 @@ mod tests { // First, let's see if routing works if we have absolutely no idea about the available amount. // In this case, it should be set to 250_000 sats. - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 2, @@ -3627,7 +3627,7 @@ mod tests { // Check that setting next_outbound_htlc_limit_msat in first_hops limits the channels. // Disable channel #1 and use another first hop. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 3, @@ -3662,7 +3662,7 @@ mod tests { } // Enable channel #1 back. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 4, @@ -3677,7 +3677,7 @@ mod tests { // Now let's see if routing works if we know only htlc_maximum_msat. - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 3, @@ -3712,7 +3712,7 @@ mod tests { // We can't change UTXO capacity on the fly, so we'll disable // the existing channel and add another one with the capacity we need. - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 4, @@ -3732,10 +3732,10 @@ mod tests { .push_opcode(opcodes::all::OP_CHECKMULTISIG).into_script().to_v0_p2wsh(); *chain_monitor.utxo_ret.lock().unwrap() = Ok(TxOut { value: 15, script_pubkey: good_script.clone() }); - net_graph_msg_handler.add_chain_access(Some(chain_monitor)); + gossip_sync.add_chain_access(Some(chain_monitor)); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 333); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 333); + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 333, timestamp: 1, @@ -3747,7 +3747,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 333, timestamp: 1, @@ -3779,7 +3779,7 @@ mod tests { } // Now let's see if routing chooses htlc_maximum_msat over UTXO capacity. - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 333, timestamp: 6, @@ -3815,7 +3815,7 @@ mod tests { fn available_liquidity_last_hop_test() { // Check that available liquidity properly limits the path even when only // one of the latter hops is limited. - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -3827,7 +3827,7 @@ mod tests { // Total capacity: 50 sats. // Disable other potential paths. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -3839,7 +3839,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 7, timestamp: 2, @@ -3854,7 +3854,7 @@ mod tests { // Limit capacities - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -3866,7 +3866,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 2, @@ -3879,7 +3879,7 @@ mod tests { excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 2, @@ -3891,7 +3891,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 11, timestamp: 2, @@ -3940,7 +3940,7 @@ mod tests { #[test] fn ignore_fee_first_hop_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -3948,7 +3948,7 @@ mod tests { let payment_params = PaymentParameters::from_node_id(nodes[2]); // Path via node0 is channels {1, 3}. Limit them to 100 and 50 sats (total limit 50). - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 2, @@ -3960,7 +3960,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 2, @@ -3988,7 +3988,7 @@ mod tests { #[test] fn simple_mpp_route_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -4004,7 +4004,7 @@ mod tests { // Their aggregate capacity will be 50 + 60 + 180 = 290 sats. // Path via node0 is channels {1, 3}. Limit them to 100 and 50 sats (total limit 50). - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 2, @@ -4016,7 +4016,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 2, @@ -4031,7 +4031,7 @@ mod tests { // Path via node7 is channels {12, 13}. Limit them to 60 and 60 sats // (total limit 60). - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -4043,7 +4043,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 2, @@ -4058,7 +4058,7 @@ mod tests { // Path via node1 is channels {2, 4}. Limit them to 200 and 180 sats // (total capacity 180 sats). - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -4070,7 +4070,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 2, @@ -4121,7 +4121,7 @@ mod tests { #[test] fn long_mpp_route_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -4136,7 +4136,7 @@ mod tests { // are used twice will have 200 sats capacity. // Disable other potential paths. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -4148,7 +4148,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 7, timestamp: 2, @@ -4162,7 +4162,7 @@ mod tests { }); // Path via {node0, node2} is channels {1, 3, 5}. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 2, @@ -4174,7 +4174,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 2, @@ -4188,8 +4188,8 @@ mod tests { }); // Capacity of 200 sats because this channel will be used by 3rd path as well. - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5); + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 5, timestamp: 2, @@ -4205,7 +4205,7 @@ mod tests { // Path via {node7, node2, node4} is channels {12, 13, 6, 11}. // Add 100 sats to the capacities of {12, 13}, because these channels // are also used for 3rd path. 100 sats for the rest. Total capacity: 100 sats. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -4217,7 +4217,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 2, @@ -4230,7 +4230,7 @@ mod tests { excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 2, @@ -4242,7 +4242,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 11, timestamp: 2, @@ -4285,7 +4285,7 @@ mod tests { #[test] fn mpp_cheaper_route_test() { - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -4304,7 +4304,7 @@ mod tests { // are used twice will have 200 sats capacity. // Disable other potential paths. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -4316,7 +4316,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 7, timestamp: 2, @@ -4330,7 +4330,7 @@ mod tests { }); // Path via {node0, node2} is channels {1, 3, 5}. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 2, @@ -4342,7 +4342,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 2, @@ -4356,8 +4356,8 @@ mod tests { }); // Capacity of 200 sats because this channel will be used by 3rd path as well. - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5); + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 5, timestamp: 2, @@ -4373,7 +4373,7 @@ mod tests { // Path via {node7, node2, node4} is channels {12, 13, 6, 11}. // Add 100 sats to the capacities of {12, 13}, because these channels // are also used for 3rd path. 100 sats for the rest. Total capacity: 100 sats. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -4385,7 +4385,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 2, @@ -4398,7 +4398,7 @@ mod tests { excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 2, @@ -4410,7 +4410,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 11, timestamp: 2, @@ -4454,7 +4454,7 @@ mod tests { // This test makes sure that MPP algorithm properly takes into account // fees charged on the channels, by making the fees impactful: // if the fee is not properly accounted for, the behavior is different. - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -4471,7 +4471,7 @@ mod tests { // It's fine to ignore this concern for now. // Disable other potential paths. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -4484,7 +4484,7 @@ mod tests { excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 7, timestamp: 2, @@ -4498,7 +4498,7 @@ mod tests { }); // Path via {node0, node2} is channels {1, 3, 5}. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 2, @@ -4510,7 +4510,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 2, @@ -4523,8 +4523,8 @@ mod tests { excess_data: Vec::new() }); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5); + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 5, timestamp: 2, @@ -4547,7 +4547,7 @@ mod tests { // - channel 12 capacity is 250 sats // - fee for channel 6 is 150 sats // Let's test this by enforcing these 2 conditions and removing other limits. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -4559,7 +4559,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 2, @@ -4572,7 +4572,7 @@ mod tests { excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 2, @@ -4584,7 +4584,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 11, timestamp: 2, @@ -4635,7 +4635,7 @@ mod tests { // to only have the remaining to-collect amount in available liquidity. // // This bug appeared in production in some specific channel configurations. - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -4655,7 +4655,7 @@ mod tests { // would first use the no-fee route and then fail to find a path along the second route as // we think we can only send up to 1 additional sat over the last-hop but refuse to as its // under 5% of our payment amount. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 2, @@ -4667,7 +4667,7 @@ mod tests { fee_proportional_millionths: u32::max_value(), excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -4679,7 +4679,7 @@ mod tests { fee_proportional_millionths: u32::max_value(), excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 2, @@ -4691,7 +4691,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 2, @@ -4725,7 +4725,7 @@ mod tests { fn drop_lowest_channel_mpp_route_test() { // This test checks that low-capacity channel is dropped when after // path finding we realize that we found more capacity than we need. - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -4742,7 +4742,7 @@ mod tests { // Their aggregate capacity will be 50 + 60 + 20 = 130 sats. // Path via node0 is channels {1, 3}. Limit them to 100 and 50 sats (total limit 50); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 2, @@ -4754,7 +4754,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 2, @@ -4768,7 +4768,7 @@ mod tests { }); // Path via node7 is channels {12, 13}. Limit them to 60 and 60 sats (total limit 60); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -4780,7 +4780,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 13, timestamp: 2, @@ -4794,7 +4794,7 @@ mod tests { }); // Path via node1 is channels {2, 4}. Limit them to 20 and 20 sats (total capacity 20 sats). - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -4806,7 +4806,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 2, @@ -4884,15 +4884,15 @@ mod tests { let secp_ctx = Secp256k1::new(); let logger = Arc::new(test_utils::TestLogger::new()); let network = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash())); - let net_graph_msg_handler = NetGraphMsgHandler::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 scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); let random_seed_bytes = keys_manager.get_secure_random_bytes(); let payment_params = PaymentParameters::from_node_id(nodes[6]); - add_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6); + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 6, timestamp: 1, @@ -4904,10 +4904,10 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[1], NodeFeatures::from_le_bytes(id_to_feature_flags(1)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[1], NodeFeatures::from_le_bytes(id_to_feature_flags(1)), 0); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[1], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5); + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 5, timestamp: 1, @@ -4919,10 +4919,10 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[4], NodeFeatures::from_le_bytes(id_to_feature_flags(4)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[4], NodeFeatures::from_le_bytes(id_to_feature_flags(4)), 0); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4); + update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 1, @@ -4934,10 +4934,10 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[3], NodeFeatures::from_le_bytes(id_to_feature_flags(3)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[3], NodeFeatures::from_le_bytes(id_to_feature_flags(3)), 0); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[3], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[3], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[3], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3); + update_channel(&gossip_sync, &secp_ctx, &privkeys[3], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 3, timestamp: 1, @@ -4949,10 +4949,10 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[2], NodeFeatures::from_le_bytes(id_to_feature_flags(2)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[2], NodeFeatures::from_le_bytes(id_to_feature_flags(2)), 0); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2); + update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 1, @@ -4965,8 +4965,8 @@ mod tests { excess_data: Vec::new() }); - add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], &privkeys[6], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { + add_channel(&gossip_sync, &secp_ctx, &privkeys[4], &privkeys[6], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1); + update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 1, timestamp: 1, @@ -4978,7 +4978,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[6], NodeFeatures::from_le_bytes(id_to_feature_flags(6)), 0); + add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[6], NodeFeatures::from_le_bytes(id_to_feature_flags(6)), 0); { // Now ensure the route flows simply over nodes 1 and 4 to 6. @@ -5015,7 +5015,7 @@ mod tests { // Test that if, while walking the graph, we find a hop that has exactly enough liquidity // for us, including later hop fees, we take it. In the first version of our MPP algorithm // we calculated fees on a higher value, resulting in us ignoring such paths. - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, _, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -5024,7 +5024,7 @@ mod tests { // We modify the graph to set the htlc_maximum of channel 2 to below the value we wish to // send. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -5037,7 +5037,7 @@ mod tests { excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 12, timestamp: 2, @@ -5079,7 +5079,7 @@ mod tests { // htlc_maximum_msat, we don't end up undershooting a later htlc_minimum_msat. In the // initial version of MPP we'd accept such routes but reject them while recalculating fees, // resulting in us thinking there is no possible path, even if other paths exist. - let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); + let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_penalty(0); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); @@ -5089,7 +5089,7 @@ mod tests { // We modify the graph to set the htlc_minimum of channel 2 and 4 as needed - channel 2 // gets an htlc_maximum_msat of 80_000 and channel 4 an htlc_minimum_msat of 90_000. We // then try to send 90_000. - update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 2, timestamp: 2, @@ -5101,7 +5101,7 @@ mod tests { fee_proportional_millionths: 0, excess_data: Vec::new() }); - update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { + update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { chain_hash: genesis_block(Network::Testnet).header.block_hash(), short_channel_id: 4, timestamp: 2, diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index 339979b1b02..54400624dce 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -17,7 +17,7 @@ //! ``` //! # extern crate bitcoin; //! # -//! # use lightning::routing::network_graph::NetworkGraph; +//! # use lightning::routing::gossip::NetworkGraph; //! # use lightning::routing::router::{RouteParameters, find_route}; //! # use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters}; //! # use lightning::chain::keysinterface::{KeysManager, KeysInterface}; @@ -55,7 +55,7 @@ //! [`find_route`]: crate::routing::router::find_route use ln::msgs::DecodeError; -use routing::network_graph::{EffectiveCapacity, NetworkGraph, NodeId}; +use routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId}; use routing::router::RouteHop; use util::ser::{Readable, ReadableArgs, Writeable, Writer}; use util::logger::Logger; @@ -1120,9 +1120,9 @@ mod tests { use ln::features::{ChannelFeatures, NodeFeatures}; use ln::msgs::{ChannelAnnouncement, ChannelUpdate, OptionalField, UnsignedChannelAnnouncement, UnsignedChannelUpdate}; - use routing::scoring::{ChannelUsage, Score}; - use routing::network_graph::{EffectiveCapacity, NetworkGraph, NodeId}; + use routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId}; use routing::router::RouteHop; + use routing::scoring::{ChannelUsage, Score}; use util::ser::{ReadableArgs, Writeable}; use util::test_utils::TestLogger; diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index 0a886b93f6e..db5b064f1f0 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -21,7 +21,7 @@ use ln::features::ChannelTypeFeatures; use ln::msgs; use ln::msgs::DecodeError; use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; -use routing::network_graph::NetworkUpdate; +use routing::gossip::NetworkUpdate; use util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper}; use routing::router::{RouteHop, RouteParameters}; @@ -337,10 +337,10 @@ pub enum Event { /// payment route. /// /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into - /// account the update. [`NetGraphMsgHandler`] is capable of doing this. + /// account the update. [`P2PGossipSync`] is capable of doing this. /// - /// [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph - /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler + /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph + /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync network_update: Option, /// For both single-path and multi-path payments, this is set if all paths of the payment have /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the diff --git a/lightning/src/util/persist.rs b/lightning/src/util/persist.rs index 5c124c21afd..117eff491b3 100644 --- a/lightning/src/util/persist.rs +++ b/lightning/src/util/persist.rs @@ -13,7 +13,7 @@ use bitcoin::hashes::hex::ToHex; use io::{self}; use routing::scoring::WriteableScore; -use crate::{chain::{keysinterface::{Sign, KeysInterface}, self, transaction::{OutPoint}, chaininterface::{BroadcasterInterface, FeeEstimator}, chainmonitor::{Persist, MonitorUpdateId}, channelmonitor::{ChannelMonitor, ChannelMonitorUpdate}}, ln::channelmanager::ChannelManager, routing::network_graph::NetworkGraph}; +use crate::{chain::{keysinterface::{Sign, KeysInterface}, self, transaction::{OutPoint}, chaininterface::{BroadcasterInterface, FeeEstimator}, chainmonitor::{Persist, MonitorUpdateId}, channelmonitor::{ChannelMonitor, ChannelMonitorUpdate}}, ln::channelmanager::ChannelManager, routing::gossip::NetworkGraph}; use super::{logger::Logger, ser::Writeable}; /// Trait for a key-value store for persisting some writeable object at some key