From ec35fe62a12e392ebf2aed90f8f4124ec9c6f7d7 Mon Sep 17 00:00:00 2001 From: Devrandom Date: Thu, 29 Apr 2021 21:07:28 +0200 Subject: [PATCH] Remove Send and Sync from core crate --- fuzz/src/utils/test_logger.rs | 2 +- lightning-block-sync/src/poll.rs | 6 +++--- lightning-net-tokio/src/lib.rs | 30 +++++++++++++------------- lightning/src/chain/chaininterface.rs | 4 ++-- lightning/src/chain/chainmonitor.rs | 2 +- lightning/src/chain/channelmonitor.rs | 2 +- lightning/src/chain/keysinterface.rs | 4 ++-- lightning/src/chain/mod.rs | 6 +++--- lightning/src/ln/channelmanager.rs | 3 +-- lightning/src/ln/msgs.rs | 4 ++-- lightning/src/routing/network_graph.rs | 2 +- lightning/src/util/logger.rs | 2 +- 12 files changed, 33 insertions(+), 34 deletions(-) diff --git a/fuzz/src/utils/test_logger.rs b/fuzz/src/utils/test_logger.rs index 36e0945f..5046869c 100644 --- a/fuzz/src/utils/test_logger.rs +++ b/fuzz/src/utils/test_logger.rs @@ -11,7 +11,7 @@ use lightning::util::logger::{Logger, Record}; use std::sync::{Arc, Mutex}; use std::io::Write; -pub trait Output : Clone + Sync + Send + 'static { +pub trait Output : Clone + 'static { fn locked_write(&self, data: &[u8]); } diff --git a/lightning-block-sync/src/poll.rs b/lightning-block-sync/src/poll.rs index e769fe85..fbe803b4 100644 --- a/lightning-block-sync/src/poll.rs +++ b/lightning-block-sync/src/poll.rs @@ -160,12 +160,12 @@ impl std::ops::Deref for ValidatedBlock { /// /// Other `Poll` implementations must be built using `ChainPoller` as it provides the only means of /// validating chain data. -pub struct ChainPoller + Sized + Sync + Send, T: BlockSource> { +pub struct ChainPoller + Sized , T: BlockSource> { block_source: B, network: Network, } -impl + Sized + Sync + Send, T: BlockSource> ChainPoller { +impl + Sized , T: BlockSource> ChainPoller { /// Creates a new poller for the given block source. /// /// If the `network` parameter is mainnet, then the difficulty between blocks is checked for @@ -175,7 +175,7 @@ impl + Sized + Sync + Send, T: BlockSource> ChainPoller + Sized + Sync + Send, T: BlockSource> Poll for ChainPoller { +impl + Sized + Send + Sync, T: BlockSource> Poll for ChainPoller { fn poll_chain_tip<'a>(&'a mut self, best_known_chain_tip: ValidatedBlockHeader) -> AsyncBlockSourceResult<'a, ChainTip> { diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 74da58da..6e2a0c22 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -31,12 +31,12 @@ //! use std::sync::Arc; //! //! // Define concrete types for our high-level objects: -//! type TxBroadcaster = dyn lightning::chain::chaininterface::BroadcasterInterface; -//! type FeeEstimator = dyn lightning::chain::chaininterface::FeeEstimator; -//! type Logger = dyn lightning::util::logger::Logger; -//! type ChainAccess = dyn lightning::chain::Access; -//! type ChainFilter = dyn lightning::chain::Filter; -//! type DataPersister = dyn lightning::chain::channelmonitor::Persist; +//! type TxBroadcaster = dyn lightning::chain::chaininterface::BroadcasterInterface + Send + Sync; +//! type FeeEstimator = dyn lightning::chain::chaininterface::FeeEstimator + Send + Sync; +//! type Logger = dyn lightning::util::logger::Logger + Send + Sync; +//! type ChainAccess = dyn lightning::chain::Access + Send + Sync; +//! type ChainFilter = dyn lightning::chain::Filter + Send + Sync; +//! type DataPersister = dyn lightning::chain::channelmonitor::Persist + Send + Sync; //! type ChainMonitor = lightning::chain::chainmonitor::ChainMonitor, Arc, Arc, Arc, Arc>; //! type ChannelManager = Arc>; //! type PeerManager = Arc>; @@ -254,9 +254,9 @@ impl Connection { /// /// See the module-level documentation for how to handle the event_notify mpsc::Sender. pub fn setup_inbound(peer_manager: Arc, Arc, Arc>>, event_notify: mpsc::Sender<()>, stream: StdTcpStream) -> impl std::future::Future where - CMH: ChannelMessageHandler + 'static, - RMH: RoutingMessageHandler + 'static, - L: Logger + 'static + ?Sized { + CMH: ChannelMessageHandler + 'static + Send + Sync, + RMH: RoutingMessageHandler + 'static + Send + Sync, + L: Logger + 'static + ?Sized + Send + Sync { let (reader, write_receiver, read_receiver, us) = Connection::new(event_notify, stream); #[cfg(debug_assertions)] let last_us = Arc::clone(&us); @@ -296,9 +296,9 @@ pub fn setup_inbound(peer_manager: Arc(peer_manager: Arc, Arc, Arc>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, stream: StdTcpStream) -> impl std::future::Future where - CMH: ChannelMessageHandler + 'static, - RMH: RoutingMessageHandler + 'static, - L: Logger + 'static + ?Sized { + CMH: ChannelMessageHandler + 'static + Send + Sync, + RMH: RoutingMessageHandler + 'static + Send + Sync, + L: Logger + 'static + ?Sized + Send + Sync { let (reader, mut write_receiver, read_receiver, us) = Connection::new(event_notify, stream); #[cfg(debug_assertions)] let last_us = Arc::clone(&us); @@ -368,9 +368,9 @@ pub fn setup_outbound(peer_manager: Arc(peer_manager: Arc, Arc, Arc>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, addr: SocketAddr) -> Option> where - CMH: ChannelMessageHandler + 'static, - RMH: RoutingMessageHandler + 'static, - L: Logger + 'static + ?Sized { + CMH: ChannelMessageHandler + 'static + Send + Sync, + RMH: RoutingMessageHandler + 'static + Send + Sync, + L: Logger + 'static + ?Sized + Send + Sync { if let Ok(Ok(stream)) = time::timeout(Duration::from_secs(10), async { TcpStream::connect(&addr).await.map(|s| s.into_std().unwrap()) }).await { Some(setup_outbound(peer_manager, event_notify, their_node_id, stream)) } else { None } diff --git a/lightning/src/chain/chaininterface.rs b/lightning/src/chain/chaininterface.rs index 91e60483..83fee4d6 100644 --- a/lightning/src/chain/chaininterface.rs +++ b/lightning/src/chain/chaininterface.rs @@ -16,7 +16,7 @@ use bitcoin::blockdata::transaction::Transaction; /// An interface to send a transaction to the Bitcoin network. -pub trait BroadcasterInterface: Sync + Send { +pub trait BroadcasterInterface { /// Sends a transaction out to (hopefully) be mined. fn broadcast_transaction(&self, tx: &Transaction); } @@ -37,7 +37,7 @@ pub enum ConfirmationTarget { /// /// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're /// called from inside the library in response to chain events, P2P events, or timer events). -pub trait FeeEstimator: Sync + Send { +pub trait FeeEstimator { /// Gets estimated satoshis of fee required per 1000 Weight-Units. /// /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs diff --git a/lightning/src/chain/chainmonitor.rs b/lightning/src/chain/chainmonitor.rs index 5055305d..f708bfe9 100644 --- a/lightning/src/chain/chainmonitor.rs +++ b/lightning/src/chain/chainmonitor.rs @@ -214,7 +214,7 @@ where } } -impl +impl chain::Watch for ChainMonitor where C::Target: chain::Filter, T::Target: BroadcasterInterface, diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index f0b23c08..c68ee39b 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -2663,7 +2663,7 @@ impl ChannelMonitorImpl { /// transaction and losing money. This is a risk because previous channel states /// are toxic, so it's important that whatever channel state is persisted is /// kept up-to-date. -pub trait Persist: Send + Sync { +pub trait Persist { /// Persist a new channel's data. The data can be stored any way you want, but /// the identifier provided by Rust-Lightning is the channel's outpoint (and /// it is up to you to maintain a correct mapping between the outpoint and the diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 89306c6e..02ee9b5f 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -226,7 +226,7 @@ impl Readable for SpendableOutputDescriptor { /// of LN security model, orthogonal of key management issues. // TODO: We should remove Clone by instead requesting a new Sign copy when we create // ChannelMonitors instead of expecting to clone the one out of the Channel into the monitors. -pub trait BaseSign : Send { +pub trait BaseSign { /// Gets the per-commitment point for a specific commitment number /// /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards. @@ -353,7 +353,7 @@ pub trait Sign: BaseSign + Writeable + Clone { } /// A trait to describe an object which can get user secrets and key material. -pub trait KeysInterface: Send + Sync { +pub trait KeysInterface { /// A type which implements Sign which will be returned by get_channel_signer. type Signer : Sign; diff --git a/lightning/src/chain/mod.rs b/lightning/src/chain/mod.rs index 7f994676..2d62016e 100644 --- a/lightning/src/chain/mod.rs +++ b/lightning/src/chain/mod.rs @@ -36,7 +36,7 @@ pub enum AccessError { /// The `Access` trait defines behavior for accessing chain data and state, such as blocks and /// UTXOs. -pub trait Access: Send + Sync { +pub trait Access { /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`]. /// Returns an error if `genesis_hash` is for a different chain or if such a transaction output /// is unknown. @@ -161,7 +161,7 @@ pub trait Confirm { /// [`ChannelMonitor`]: channelmonitor::ChannelMonitor /// [`ChannelMonitorUpdateErr`]: channelmonitor::ChannelMonitorUpdateErr /// [`PermanentFailure`]: channelmonitor::ChannelMonitorUpdateErr::PermanentFailure -pub trait Watch: Send + Sync { +pub trait Watch { /// Watches a channel identified by `funding_txo` using `monitor`. /// /// Implementations are responsible for watching the chain for the funding transaction along @@ -207,7 +207,7 @@ pub trait Watch: Send + Sync { /// [`TemporaryFailure`]: channelmonitor::ChannelMonitorUpdateErr::TemporaryFailure /// [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki /// [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki -pub trait Filter: Send + Sync { +pub trait Filter { /// Registers interest in a transaction with `txid` and having an output with `script_pubkey` as /// a spending condition. fn register_tx(&self, txid: &Txid, script_pubkey: &Script); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 31529343..451bf8be 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -68,7 +68,6 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::Duration; #[cfg(any(test, feature = "allow_wallclock_use"))] use std::time::Instant; -use std::marker::{Sync, Send}; use std::ops::Deref; use bitcoin::hashes::hex::ToHex; @@ -3764,7 +3763,7 @@ where } } -impl +impl ChannelMessageHandler for ChannelManager where M::Target: chain::Watch, T::Target: BroadcasterInterface, diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 8a7713dc..5cb72842 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -744,7 +744,7 @@ pub enum OptionalField { /// /// Messages MAY be called in parallel when they originate from different their_node_ids, however /// they MUST NOT be called in parallel when the two calls have the same their_node_id. -pub trait ChannelMessageHandler : MessageSendEventsProvider + Send + Sync { +pub trait ChannelMessageHandler : MessageSendEventsProvider { //Channel init: /// Handle an incoming open_channel message from the given peer. fn handle_open_channel(&self, their_node_id: &PublicKey, their_features: InitFeatures, msg: &OpenChannel); @@ -811,7 +811,7 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider + Send + Sync { /// For `gossip_queries` messages there are potential DoS vectors when handling /// inbound queries. Implementors using an on-disk network graph should be aware of /// repeated disk I/O for queries accessing different parts of the network graph. -pub trait RoutingMessageHandler : Send + Sync + MessageSendEventsProvider { +pub trait RoutingMessageHandler : MessageSendEventsProvider { /// Handle an incoming node_announcement message, returning true if it should be forwarded on, /// false or returning an Err otherwise. fn handle_node_announcement(&self, msg: &NodeAnnouncement) -> Result; diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index 04e4eb14..765a3430 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -152,7 +152,7 @@ macro_rules! secp_verify_sig { }; } -impl RoutingMessageHandler for NetGraphMsgHandler where C::Target: chain::Access, L::Target: Logger { +impl RoutingMessageHandler for NetGraphMsgHandler where C::Target: chain::Access, L::Target: Logger { fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result { self.network_graph.write().unwrap().update_node_from_announcement(msg, &self.secp_ctx)?; Ok(msg.contents.excess_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY && diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index acd6d323..2cf0f136 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -117,7 +117,7 @@ impl<'a> Record<'a> { } /// A trait encapsulating the operations required of a logger -pub trait Logger: Sync + Send { +pub trait Logger { /// Logs the `Record` fn log(&self, record: &Record); } -- 2.30.2