From c33a4442678a0b2f95bedc619190d091cd90fa45 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 11 Jun 2020 15:23:35 -0400 Subject: [PATCH] Reduce RwLock usage in public interface of NetworkGraph This isn't a big difference in the API, but it avoids needing to wrap a given NetworkGraph in a RwLock before passing it, which makes it much easier to generate C bindings for. --- lightning/src/ln/functional_test_utils.rs | 4 ++-- lightning/src/routing/network_graph.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 41cd1610e..c7e60c9bd 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -31,7 +31,7 @@ use bitcoin::secp256k1::key::PublicKey; use std::cell::RefCell; use std::rc::Rc; -use std::sync::{Mutex, RwLock}; +use std::sync::Mutex; use std::mem; use std::collections::HashMap; @@ -103,7 +103,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> { let network_graph_deser = ::read(&mut ::std::io::Cursor::new(&w.0)).unwrap(); assert!(network_graph_deser == *self.net_graph_msg_handler.network_graph.read().unwrap()); let net_graph_msg_handler = NetGraphMsgHandler::from_net_graph( - self.chain_monitor, self.logger, RwLock::new(network_graph_deser) + self.chain_monitor, self.logger, network_graph_deser ); let mut chan_progress = 0; loop { diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index 3168a1fd8..d683d38fb 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -59,10 +59,10 @@ impl NetGraphMsgHandler where C::Target: ChainWatchInt /// Creates a new tracker of the actual state of the network of channels and nodes, /// assuming an existing Network Graph. - pub fn from_net_graph(chain_monitor: C, logger: L, network_graph: RwLock) -> Self { + pub fn from_net_graph(chain_monitor: C, logger: L, network_graph: NetworkGraph) -> Self { NetGraphMsgHandler { secp_ctx: Secp256k1::verification_only(), - network_graph, + network_graph: RwLock::new(network_graph), full_syncs_requested: AtomicUsize::new(0), chain_monitor, logger, -- 2.39.5