From: Devrandom Date: Mon, 19 Jul 2021 13:01:58 +0000 (+0200) Subject: Collect all lightning std::sync imports under crate::sync X-Git-Tag: v0.0.100~24^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=rust-lightning;a=commitdiff_plain;h=002a5db5b07fd317545d3aa4f1a217cd40b608e2 Collect all lightning std::sync imports under crate::sync in preparation for no-std sync dummies --- diff --git a/lightning/src/chain/chainmonitor.rs b/lightning/src/chain/chainmonitor.rs index 23fc42f5..12bfebbc 100644 --- a/lightning/src/chain/chainmonitor.rs +++ b/lightning/src/chain/chainmonitor.rs @@ -38,7 +38,7 @@ use util::events; use util::events::EventHandler; use prelude::*; -use std::sync::RwLock; +use sync::RwLock; use core::ops::Deref; /// An implementation of [`chain::Watch`] for monitoring channels. diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index e78faf77..cf368f15 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -55,7 +55,7 @@ use prelude::*; use core::{cmp, mem}; use std::io::Error; use core::ops::Deref; -use std::sync::Mutex; +use sync::Mutex; /// An update generated by the underlying Channel itself which contains some new information the /// ChannelMonitor should be made aware of. @@ -2843,7 +2843,7 @@ mod tests { use util::test_utils::{TestLogger, TestBroadcaster, TestFeeEstimator}; use bitcoin::secp256k1::key::{SecretKey,PublicKey}; use bitcoin::secp256k1::Secp256k1; - use std::sync::{Arc, Mutex}; + use sync::{Arc, Mutex}; use chain::keysinterface::InMemorySigner; use prelude::*; diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index c84e3d2d..10880635 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -53,3 +53,7 @@ mod prelude { #[cfg(feature = "hashbrown")] pub use self::hashbrown::{HashMap, HashSet, hash_map}; } + +mod sync { + pub use ::std::sync::{Arc, Mutex, Condvar, MutexGuard, RwLock, RwLockReadGuard}; +} diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 5f90b030..1e76117f 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -41,7 +41,7 @@ use ln::functional_test_utils::*; use util::test_utils; use prelude::*; -use std::sync::{Arc, Mutex}; +use sync::{Arc, Mutex}; // If persister_fail is true, we have the persister return a PermanentFailure // instead of the higher-level ChainMonitor. diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 87f4e6ea..5065b9ae 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -45,7 +45,8 @@ use prelude::*; use core::{cmp,mem,fmt}; use core::ops::Deref; #[cfg(any(test, feature = "fuzztarget"))] -use std::sync::Mutex; +use sync::Mutex; +use sync; use bitcoin::hashes::hex::ToHex; use bitcoin::blockdata::opcodes::all::OP_PUSHBYTES_0; @@ -374,10 +375,10 @@ pub(super) struct Channel { #[cfg(debug_assertions)] /// Max to_local and to_remote outputs in a locally-generated commitment transaction - holder_max_commitment_tx_output: ::std::sync::Mutex<(u64, u64)>, + holder_max_commitment_tx_output: sync::Mutex<(u64, u64)>, #[cfg(debug_assertions)] /// Max to_local and to_remote outputs in a remote-generated commitment transaction - counterparty_max_commitment_tx_output: ::std::sync::Mutex<(u64, u64)>, + counterparty_max_commitment_tx_output: sync::Mutex<(u64, u64)>, last_sent_closing_fee: Option<(u32, u64, Signature)>, // (feerate, fee, holder_sig) @@ -595,9 +596,9 @@ impl Channel { monitor_pending_failures: Vec::new(), #[cfg(debug_assertions)] - holder_max_commitment_tx_output: ::std::sync::Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)), + holder_max_commitment_tx_output: sync::Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)), #[cfg(debug_assertions)] - counterparty_max_commitment_tx_output: ::std::sync::Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)), + counterparty_max_commitment_tx_output: sync::Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)), last_sent_closing_fee: None, @@ -836,9 +837,9 @@ impl Channel { monitor_pending_failures: Vec::new(), #[cfg(debug_assertions)] - holder_max_commitment_tx_output: ::std::sync::Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)), + holder_max_commitment_tx_output: sync::Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)), #[cfg(debug_assertions)] - counterparty_max_commitment_tx_output: ::std::sync::Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)), + counterparty_max_commitment_tx_output: sync::Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)), last_sent_closing_fee: None, @@ -4943,9 +4944,9 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel feerate_per_kw, #[cfg(debug_assertions)] - holder_max_commitment_tx_output: ::std::sync::Mutex::new((0, 0)), + holder_max_commitment_tx_output: sync::Mutex::new((0, 0)), #[cfg(debug_assertions)] - counterparty_max_commitment_tx_output: ::std::sync::Mutex::new((0, 0)), + counterparty_max_commitment_tx_output: sync::Mutex::new((0, 0)), last_sent_closing_fee, @@ -5023,7 +5024,7 @@ mod tests { use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hashes::Hash; use bitcoin::hash_types::{Txid, WPubkeyHash}; - use std::sync::Arc; + use sync::Arc; use prelude::*; struct TestFeeEstimator { diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 49af4408..ad9ce5df 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -64,7 +64,7 @@ use prelude::*; use core::{cmp, mem}; use core::cell::RefCell; use std::io::{Cursor, Read}; -use std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard}; +use sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard}; use core::sync::atomic::{AtomicUsize, Ordering}; use core::time::Duration; #[cfg(any(test, feature = "allow_wallclock_use"))] @@ -4951,7 +4951,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> #[cfg(test)] mod tests { use ln::channelmanager::PersistenceNotifier; - use std::sync::Arc; + use sync::Arc; use core::sync::atomic::{AtomicBool, Ordering}; use std::thread; use core::time::Duration; @@ -5094,7 +5094,7 @@ pub mod bench { use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::{Block, BlockHeader, Transaction, TxOut}; - use std::sync::{Arc, Mutex}; + use sync::{Arc, Mutex}; use test::Bencher; diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 8bb49ef9..0adea15c 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -42,7 +42,7 @@ use bitcoin::secp256k1::key::PublicKey; use prelude::*; use core::cell::RefCell; use std::rc::Rc; -use std::sync::{Arc, Mutex}; +use sync::{Arc, Mutex}; use core::mem; pub const CHAN_CONFIRM_DEPTH: u32 = 10; diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index ad4d68ae..ca835bd5 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -53,7 +53,7 @@ use regex; use prelude::*; use alloc::collections::BTreeSet; use core::default::Default; -use std::sync::{Arc, Mutex}; +use sync::{Arc, Mutex}; use ln::functional_test_utils::*; use ln::chan_utils::CommitmentTransaction; diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 96ec31c9..0ec24fbf 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -33,7 +33,7 @@ use routing::network_graph::NetGraphMsgHandler; use prelude::*; use alloc::collections::LinkedList; use alloc::fmt::Debug; -use std::sync::{Arc, Mutex}; +use sync::{Arc, Mutex}; use core::sync::atomic::{AtomicUsize, Ordering}; use core::{cmp, hash, fmt, mem}; use core::ops::Deref; @@ -1447,7 +1447,7 @@ mod tests { use bitcoin::secp256k1::key::{SecretKey, PublicKey}; use prelude::*; - use std::sync::{Arc, Mutex}; + use sync::{Arc, Mutex}; use core::sync::atomic::Ordering; #[derive(Clone)] diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index 22cd2a92..9e4813e9 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -35,9 +35,9 @@ use util::scid_utils::{block_from_scid, scid_from_parts, MAX_SCID_BLOCK}; use prelude::*; use alloc::collections::{BTreeMap, btree_map::Entry as BtreeEntry}; use core::{cmp, fmt}; -use std::sync::{RwLock, RwLockReadGuard}; +use sync::{RwLock, RwLockReadGuard}; use core::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Mutex; +use sync::Mutex; use core::ops::Deref; use bitcoin::hashes::hex::ToHex; @@ -1088,7 +1088,7 @@ mod tests { use bitcoin::secp256k1::{All, Secp256k1}; use prelude::*; - use std::sync::Arc; + use sync::Arc; fn create_net_graph_msg_handler() -> (Secp256k1, NetGraphMsgHandler, Arc>) { let secp_ctx = Secp256k1::new(); diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 44b8c8a2..548febbd 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -1198,7 +1198,7 @@ mod tests { use bitcoin::secp256k1::{Secp256k1, All}; use prelude::*; - use std::sync::Arc; + use sync::{self, Arc}; fn get_channel_details(short_channel_id: Option, node_id: PublicKey, features: InitFeatures, outbound_capacity_msat: u64) -> channelmanager::ChannelDetails { @@ -1321,7 +1321,7 @@ mod tests { } } - fn build_graph() -> (Secp256k1, NetGraphMsgHandler, std::sync::Arc>, std::sync::Arc, std::sync::Arc) { + fn build_graph() -> (Secp256k1, NetGraphMsgHandler, sync::Arc>, sync::Arc, sync::Arc) { let secp_ctx = Secp256k1::new(); let logger = Arc::new(test_utils::TestLogger::new()); let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index 26f9d87b..d7ddc38b 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -13,7 +13,7 @@ use chain::keysinterface::{Sign, InMemorySigner, BaseSign}; use prelude::*; use core::cmp; -use std::sync::{Mutex, Arc}; +use sync::{Mutex, Arc}; use bitcoin::blockdata::transaction::{Transaction, SigHashType}; use bitcoin::util::bip143; diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index 98037aac..b34d1f0b 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -124,7 +124,7 @@ pub trait Logger { mod tests { use util::logger::{Logger, Level}; use util::test_utils::TestLogger; - use std::sync::Arc; + use sync::Arc; #[test] fn test_level_show() { diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index b02fef27..fe331f6b 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -13,7 +13,7 @@ use prelude::*; use std::io::{Read, Write}; use core::hash::Hash; -use std::sync::Mutex; +use sync::Mutex; use core::cmp; use bitcoin::secp256k1::Signature; diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 2775697b..fbd5a26d 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -39,7 +39,7 @@ use regex; use prelude::*; use core::time::Duration; -use std::sync::{Mutex, Arc}; +use sync::{Mutex, Arc}; use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use core::{cmp, mem}; use chain::keysinterface::InMemorySigner;