X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmanager.rs;h=2a7c0949da0a3ce3d7a1b23aceddff3ab4ba1497;hb=d768cc234e1b0e6ee14d87f6cf72a1e20bba531a;hp=5cc9783c008378374b5e7b2527bbec189b2fdf1f;hpb=f952cc27d6d1c3e356ea46a5f63beec1f4105db9;p=rust-lightning diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 5cc9783c..2a7c0949 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -289,7 +289,7 @@ const ERR: () = "You need at least 32 bit pointers (well, usize, but we'll assum /// lifetimes). Other times you can afford a reference, which is more efficient, in which case /// SimpleRefChannelManager is the more appropriate type. Defining these type aliases prevents /// issues such as overly long function definitions. -pub type SimpleArcChannelManager = Arc>>; +pub type SimpleArcChannelManager = Arc, Arc>>; /// SimpleRefChannelManager is a type alias for a ChannelManager reference, and is the reference /// counterpart to the SimpleArcChannelManager type alias. Use this type by default when you don't @@ -297,7 +297,7 @@ pub type SimpleArcChannelManager = Arc = ChannelManager; +pub type SimpleRefChannelManager<'a, 'b, M, T> = ChannelManager; /// Manager which keeps track of a number of channels and sends messages to the appropriate /// channel, also tracking HTLC preimages and forwarding onion packets appropriately. @@ -335,12 +335,15 @@ pub type SimpleRefChannelManager<'a, M> = ChannelManager where M::Target: ManyChannelMonitor { +pub struct ChannelManager + where M::Target: ManyChannelMonitor, + T::Target: BroadcasterInterface, +{ default_configuration: UserConfig, genesis_hash: Sha256dHash, fee_estimator: Arc, monitor: M, - tx_broadcaster: Arc, + tx_broadcaster: T, #[cfg(test)] pub(super) latest_block_height: AtomicUsize, @@ -607,7 +610,10 @@ macro_rules! maybe_break_monitor_err { } } -impl ChannelManager where M::Target: ManyChannelMonitor { +impl ChannelManager + where M::Target: ManyChannelMonitor, + T::Target: BroadcasterInterface, +{ /// Constructs a new ChannelManager to hold several channels and route between them. /// /// This is the main "logic hub" for all channel-related actions, and implements @@ -626,7 +632,7 @@ impl ChannelManager where M::T /// the ChannelManager as a listener to the BlockNotifier and call the BlockNotifier's /// `block_(dis)connected` methods, which will notify all registered listeners in one /// go. - pub fn new(network: Network, feeest: Arc, monitor: M, tx_broadcaster: Arc, logger: Arc,keys_manager: Arc>, config: UserConfig, current_blockchain_height: usize) -> Result, secp256k1::Error> { + pub fn new(network: Network, feeest: Arc, monitor: M, tx_broadcaster: T, logger: Arc,keys_manager: Arc>, config: UserConfig, current_blockchain_height: usize) -> Result, secp256k1::Error> { let secp_ctx = Secp256k1::new(); let res = ChannelManager { @@ -2542,7 +2548,10 @@ impl ChannelManager where M::T } } -impl events::MessageSendEventsProvider for ChannelManager where M::Target: ManyChannelMonitor { +impl events::MessageSendEventsProvider for ChannelManager + where M::Target: ManyChannelMonitor, + T::Target: BroadcasterInterface, +{ fn get_and_clear_pending_msg_events(&self) -> Vec { // TODO: Event release to users and serialization is currently race-y: it's very easy for a // user to serialize a ChannelManager with pending events in it and lose those events on @@ -2567,7 +2576,10 @@ impl events::MessageSendEventsProvider for Ch } } -impl events::EventsProvider for ChannelManager where M::Target: ManyChannelMonitor { +impl events::EventsProvider for ChannelManager + where M::Target: ManyChannelMonitor, + T::Target: BroadcasterInterface, +{ fn get_and_clear_pending_events(&self) -> Vec { // TODO: Event release to users and serialization is currently race-y: it's very easy for a // user to serialize a ChannelManager with pending events in it and lose those events on @@ -2592,7 +2604,10 @@ impl events::EventsProvider for ChannelManage } } -impl ChainListener for ChannelManager where M::Target: ManyChannelMonitor { +impl ChainListener for ChannelManager + where M::Target: ManyChannelMonitor, + T::Target: BroadcasterInterface, +{ fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) { let header_hash = header.bitcoin_hash(); log_trace!(self, "Block {} at height {} connected with {} txn matched", header_hash, height, txn_matched.len()); @@ -2709,7 +2724,10 @@ impl ChainListener for ChannelM } } -impl ChannelMessageHandler for ChannelManager where M::Target: ManyChannelMonitor { +impl ChannelMessageHandler for ChannelManager + where M::Target: ManyChannelMonitor, + T::Target: BroadcasterInterface, +{ fn handle_open_channel(&self, their_node_id: &PublicKey, their_features: InitFeatures, msg: &msgs::OpenChannel) { let _ = self.total_consistency_lock.read().unwrap(); let res = self.internal_open_channel(their_node_id, their_features, msg); @@ -3179,7 +3197,10 @@ impl Readable for HTLCForwardInfo { } } -impl Writeable for ChannelManager where M::Target: ManyChannelMonitor { +impl Writeable for ChannelManager + where M::Target: ManyChannelMonitor, + T::Target: BroadcasterInterface, +{ fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { let _ = self.total_consistency_lock.write().unwrap(); @@ -3250,7 +3271,11 @@ impl Writeable for ChannelManager /// 5) Move the ChannelMonitors into your local ManyChannelMonitor. /// 6) Disconnect/connect blocks on the ChannelManager. /// 7) Register the new ChannelManager with your ChainWatchInterface. -pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref> where M::Target: ManyChannelMonitor { +pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref, T: Deref> + where M::Target: ManyChannelMonitor, + T::Target: BroadcasterInterface, +{ + /// The keys provider which will give us relevant keys. Some keys will be loaded during /// deserialization. pub keys_manager: Arc>, @@ -3269,7 +3294,7 @@ pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref> wh /// The BroadcasterInterface which will be used in the ChannelManager in the future and may be /// used to broadcast the latest local commitment transactions of channels which must be /// force-closed during deserialization. - pub tx_broadcaster: Arc, + pub tx_broadcaster: T, /// The Logger for use in the ChannelManager and which may be used to log information during /// deserialization. pub logger: Arc, @@ -3290,8 +3315,11 @@ pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref> wh pub channel_monitors: &'a mut HashMap>, } -impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable, M: Deref> ReadableArgs> for (Sha256dHash, ChannelManager) where M::Target: ManyChannelMonitor { - fn read(reader: &mut R, args: ChannelManagerReadArgs<'a, ChanSigner, M>) -> Result { +impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref> ReadableArgs> for (Sha256dHash, ChannelManager) + where M::Target: ManyChannelMonitor, + T::Target: BroadcasterInterface, +{ + fn read(reader: &mut R, args: ChannelManagerReadArgs<'a, ChanSigner, M, T>) -> Result { let _ver: u8 = Readable::read(reader)?; let min_ver: u8 = Readable::read(reader)?; if min_ver > SERIALIZATION_VERSION {