]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Replace Arc with reference in some tests
authorJeffrey Czyz <jkczyz@gmail.com>
Mon, 13 Jun 2022 22:25:10 +0000 (17:25 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Mon, 13 Jun 2022 23:28:01 +0000 (18:28 -0500)
fuzz/src/process_network_graph.rs
fuzz/src/router.rs
lightning/src/routing/gossip.rs

index ae38d678a4d25aa127567216e761912feb434df3..8b6462e81e48c95ab30d3db7409b3c63a18be28a 100644 (file)
@@ -9,8 +9,8 @@ use std::sync::Arc;
 /// Actual fuzz test, method signature and name are fixed
 fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
        let block_hash = bitcoin::BlockHash::default();
-       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
-       let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash, logger);
+       let logger = test_logger::TestLogger::new("".to_owned(), out);
+       let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash, &logger);
        let rapid_sync = RapidGossipSync::new(&network_graph);
        let _ = rapid_sync.update_network_graph(data);
 }
index 21fb2dc152a5fa9aa72f0b79dbca24ef63fad2a3..f3af5bdc1eec018d4e51245821861ceebe325fa3 100644 (file)
@@ -159,10 +159,10 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                }
        }
 
-       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
+       let logger = test_logger::TestLogger::new("".to_owned(), out);
 
        let our_pubkey = get_pubkey!();
-       let net_graph = NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), Arc::clone(&logger));
+       let net_graph = NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), &logger);
 
        let mut node_pks = HashSet::new();
        let mut scid = 42;
@@ -269,7 +269,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                        };
                                        let _ = find_route(&our_pubkey, &route_params, &net_graph.read_only(),
                                                first_hops.map(|c| c.iter().collect::<Vec<_>>()).as_ref().map(|a| a.as_slice()),
-                                               Arc::clone(&logger), &scorer, &random_seed_bytes);
+                                               &logger, &scorer, &random_seed_bytes);
                                }
                        },
                }
index f404e77b2b825ba894e4a193d693eb222cbbf769..bd2b9d06eb04d501573ce36467ec1b329f0c8cde 100644 (file)
@@ -1632,7 +1632,6 @@ mod tests {
                UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate,
                ReplyChannelRange, QueryChannelRange, QueryShortChannelIds, MAX_VALUE_MSAT};
        use util::test_utils;
-       use util::logger::Logger;
        use util::ser::{ReadableArgs, Writeable};
        use util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider};
        use util::scid_utils::scid_from_parts;
@@ -1829,7 +1828,7 @@ mod tests {
        #[test]
        fn handling_channel_announcements() {
                let secp_ctx = Secp256k1::new();
-               let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::new());
+               let logger = test_utils::TestLogger::new();
 
                let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
                let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
@@ -1839,8 +1838,8 @@ mod tests {
 
                // Test if the UTXO lookups were not supported
                let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
-               let mut gossip_sync = P2PGossipSync::new(&network_graph, None, Arc::clone(&logger));
+               let network_graph = NetworkGraph::new(genesis_hash, &logger);
+               let mut gossip_sync = P2PGossipSync::new(&network_graph, None, &logger);
                match gossip_sync.handle_channel_announcement(&valid_announcement) {
                        Ok(res) => assert!(res),
                        _ => panic!()
@@ -1861,10 +1860,10 @@ mod tests {
                };
 
                // Test if an associated transaction were not on-chain (or not confirmed).
-               let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
+               let chain_source = test_utils::TestChainSource::new(Network::Testnet);
                *chain_source.utxo_ret.lock().unwrap() = Err(chain::AccessError::UnknownTx);
-               let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
-               gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger));
+               let network_graph = NetworkGraph::new(genesis_hash, &logger);
+               gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger);
 
                let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| {
                        unsigned_announcement.short_channel_id += 1;
@@ -1945,11 +1944,11 @@ mod tests {
        #[test]
        fn handling_channel_update() {
                let secp_ctx = Secp256k1::new();
-               let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::new());
-               let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
+               let logger = test_utils::TestLogger::new();
+               let chain_source = test_utils::TestChainSource::new(Network::Testnet);
                let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
-               let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger));
+               let network_graph = NetworkGraph::new(genesis_hash, &logger);
+               let gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger);
 
                let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
                let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
@@ -2151,10 +2150,10 @@ mod tests {
        fn test_channel_timeouts() {
                // Test the removal of channels with `remove_stale_channels`.
                let logger = test_utils::TestLogger::new();
-               let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
+               let chain_source = test_utils::TestChainSource::new(Network::Testnet);
                let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
                let network_graph = NetworkGraph::new(genesis_hash, &logger);
-               let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), &logger);
+               let gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger);
                let secp_ctx = Secp256k1::new();
 
                let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();