]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Reduce RwLock usage in public interface of NetworkGraph
authorMatt Corallo <git@bluematt.me>
Thu, 11 Jun 2020 19:23:35 +0000 (15:23 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 22 Jun 2020 17:42:28 +0000 (13:42 -0400)
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
lightning/src/routing/network_graph.rs

index 41cd1610e203b39307e57d11fff72e5d3978ee6d..c7e60c9bddf913f4391b4720dc7afc9612031609 100644 (file)
@@ -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 = <NetworkGraph>::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 {
index 3168a1fd8503be206063bf23fa9abbd177180699..d683d38fbce5525b963513b587e3754cec783c35 100644 (file)
@@ -59,10 +59,10 @@ impl<C: Deref, L: Deref> NetGraphMsgHandler<C, L> 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<NetworkGraph>) -> 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,