X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmanager.rs;fp=lightning%2Fsrc%2Fln%2Fchannelmanager.rs;h=fa71fee3732f059d4a49f7456b3fc10e1ce1a53c;hb=f328094b49dcbc9967d17d5706992a6bf167de23;hp=3e4d3df9a9ba30602b983faf281c694be91bc342;hpb=030c49cf781bf1892bf9451d5d0da28132f8397e;p=rust-lightning diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 3e4d3df9..fa71fee3 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -34,7 +34,7 @@ use ln::features::InitFeatures; use ln::msgs; use ln::onion_utils; use ln::msgs::{ChannelMessageHandler, DecodeError, LightningError}; -use chain::keysinterface::{ChannelKeys, KeysInterface, InMemoryChannelKeys}; +use chain::keysinterface::{ChannelKeys, KeysInterface, KeysManager, InMemoryChannelKeys}; use util::config::UserConfig; use util::{byte_utils, events}; use util::ser::{Readable, ReadableArgs, Writeable, Writer}; @@ -292,16 +292,20 @@ const ERR: () = "You need at least 32 bit pointers (well, usize, but we'll assum /// when you're using lightning-net-tokio (since tokio::spawn requires parameters with static /// 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, Arc>>; +/// issues such as overly long function definitions. Note that the ChannelManager can take any +/// type that implements KeysInterface for its keys manager, but this type alias chooses the +/// concrete type of the KeysManager. +pub type SimpleArcChannelManager = Arc, 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 /// need a ChannelManager with a static lifetime. You'll need a static lifetime in cases such as /// usage of lightning-net-tokio (since tokio::spawn requires parameters with static lifetimes). /// But if this is not necessary, using a reference is more efficient. Defining these type aliases -/// helps with issues such as long function definitions. -pub type SimpleRefChannelManager<'a, 'b, M, T> = ChannelManager; +/// helps with issues such as long function definitions. Note that the ChannelManager can take any +/// type that implements KeysInterface for its keys manager, but this type alias chooses the +/// concrete type of the KeysManager. +pub type SimpleRefChannelManager<'a, 'b, 'c, 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. @@ -339,9 +343,10 @@ pub type SimpleRefChannelManager<'a, 'b, M, T> = ChannelManager +pub struct ChannelManager where M::Target: ManyChannelMonitor, T::Target: BroadcasterInterface, + K::Target: KeysInterface, { default_configuration: UserConfig, genesis_hash: Sha256dHash, @@ -376,7 +381,7 @@ pub struct ChannelManager /// Taken first everywhere where we are making changes before any other locks. total_consistency_lock: RwLock<()>, - keys_manager: Arc>, + keys_manager: K, logger: Arc, } @@ -612,9 +617,10 @@ macro_rules! maybe_break_monitor_err { } } -impl ChannelManager +impl ChannelManager where M::Target: ManyChannelMonitor, T::Target: BroadcasterInterface, + K::Target: KeysInterface, { /// Constructs a new ChannelManager to hold several channels and route between them. /// @@ -634,7 +640,7 @@ impl ChannelManager, monitor: M, tx_broadcaster: T, 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: K, config: UserConfig, current_blockchain_height: usize) -> Result, secp256k1::Error> { let secp_ctx = Secp256k1::new(); let res = ChannelManager { @@ -2563,9 +2569,10 @@ impl ChannelManager events::MessageSendEventsProvider for ChannelManager +impl events::MessageSendEventsProvider for ChannelManager where M::Target: ManyChannelMonitor, T::Target: BroadcasterInterface, + K::Target: KeysInterface, { 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 @@ -2591,9 +2598,10 @@ impl events::MessageSendEventsProvi } } -impl events::EventsProvider for ChannelManager +impl events::EventsProvider for ChannelManager where M::Target: ManyChannelMonitor, T::Target: BroadcasterInterface, + K::Target: KeysInterface, { 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 @@ -2619,9 +2627,11 @@ impl events::EventsProvider for Cha } } -impl ChainListener for ChannelManager +impl + ChainListener for ChannelManager where M::Target: ManyChannelMonitor, T::Target: BroadcasterInterface, + K::Target: KeysInterface, { fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) { let header_hash = header.bitcoin_hash(); @@ -2739,9 +2749,11 @@ impl Ch } } -impl ChannelMessageHandler for ChannelManager +impl + ChannelMessageHandler for ChannelManager where M::Target: ManyChannelMonitor, T::Target: BroadcasterInterface, + K::Target: KeysInterface, { fn handle_open_channel(&self, their_node_id: &PublicKey, their_features: InitFeatures, msg: &msgs::OpenChannel) { let _ = self.total_consistency_lock.read().unwrap(); @@ -3212,9 +3224,10 @@ impl Readable for HTLCForwardInfo { } } -impl Writeable for ChannelManager +impl Writeable for ChannelManager where M::Target: ManyChannelMonitor, T::Target: BroadcasterInterface, + K::Target: KeysInterface, { fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { let _ = self.total_consistency_lock.write().unwrap(); @@ -3286,14 +3299,15 @@ impl Writeable for Chan /// 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, T: Deref> +pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref, T: Deref, K: Deref> where M::Target: ManyChannelMonitor, T::Target: BroadcasterInterface, + K::Target: KeysInterface, { /// The keys provider which will give us relevant keys. Some keys will be loaded during /// deserialization. - pub keys_manager: Arc>, + pub keys_manager: K, /// The fee_estimator for use in the ChannelManager in the future. /// @@ -3330,11 +3344,13 @@ pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref, T: pub channel_monitors: &'a mut HashMap>, } -impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref> ReadableArgs> for (Sha256dHash, ChannelManager) +impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref> + ReadableArgs> for (Sha256dHash, ChannelManager) where M::Target: ManyChannelMonitor, T::Target: BroadcasterInterface, + K::Target: KeysInterface, { - fn read(reader: &mut R, args: ChannelManagerReadArgs<'a, ChanSigner, M, T>) -> Result { + fn read(reader: &mut R, args: ChannelManagerReadArgs<'a, ChanSigner, M, T, K>) -> Result { let _ver: u8 = Readable::read(reader)?; let min_ver: u8 = Readable::read(reader)?; if min_ver > SERIALIZATION_VERSION {