@@ -44,7 +44,7 @@ use util::{byte_utils, events};
44
44
45
45
use std:: collections:: { HashMap , hash_map} ;
46
46
use std:: sync:: Mutex ;
47
- use std:: { hash , cmp, mem} ;
47
+ use std:: { cmp, mem} ;
48
48
use std:: ops:: Deref ;
49
49
50
50
/// An update generated by the underlying Channel itself which contains some new information the
@@ -154,28 +154,22 @@ pub struct HTLCUpdate {
154
154
}
155
155
impl_writeable ! ( HTLCUpdate , 0 , { payment_hash, payment_preimage, source } ) ;
156
156
157
- /// A simple implementation of a [`chain::Watch`] and ChainListener. Can be used to create a
158
- /// watchtower or watch our own channels.
157
+ /// An implementation of a [`chain::Watch`] and ChainListener.
159
158
///
160
- /// Note that you must provide your own key by which to refer to channels.
161
- ///
162
- /// If you're accepting remote monitors (ie are implementing a watchtower), you must verify that
163
- /// users cannot overwrite a given channel by providing a duplicate key. ie you should probably
164
- /// index by a PublicKey which is required to sign any updates.
165
- ///
166
- /// If you're using this for local monitoring of your own channels, you probably want to use
167
- /// `OutPoint` as the key, which will give you a [`chain::Watch`] implementation.
159
+ /// May be used in conjunction with [`ChannelManager`] to monitor channels locally or used
160
+ /// independently to monitor channels remotely.
168
161
///
169
162
/// [`chain::Watch`]: ../../chain/trait.Watch.html
170
- pub struct ChainMonitor < Key , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref >
163
+ /// [`ChannelManager`]: ../channelmanager/struct.ChannelManager.html
164
+ pub struct ChainMonitor < ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref >
171
165
where T :: Target : BroadcasterInterface ,
172
166
F :: Target : FeeEstimator ,
173
167
L :: Target : Logger ,
174
168
{
175
169
#[ cfg( test) ] // Used in ChannelManager tests to manipulate channels directly
176
- pub monitors : Mutex < HashMap < Key , ChannelMonitor < ChanSigner > > > ,
170
+ pub monitors : Mutex < HashMap < OutPoint , ChannelMonitor < ChanSigner > > > ,
177
171
#[ cfg( not( test) ) ]
178
- monitors : Mutex < HashMap < Key , ChannelMonitor < ChanSigner > > > ,
172
+ monitors : Mutex < HashMap < OutPoint , ChannelMonitor < ChanSigner > > > ,
179
173
watch_events : Mutex < WatchEventQueue > ,
180
174
broadcaster : T ,
181
175
logger : L ,
@@ -224,8 +218,8 @@ impl WatchEventQueue {
224
218
}
225
219
}
226
220
227
- impl < Key : Send + cmp :: Eq + hash :: Hash , ChanSigner : ChannelKeys , T : Deref + Sync + Send , F : Deref + Sync + Send , L : Deref + Sync + Send >
228
- ChainListener for ChainMonitor < Key , ChanSigner , T , F , L >
221
+ impl < ChanSigner : ChannelKeys , T : Deref + Sync + Send , F : Deref + Sync + Send , L : Deref + Sync + Send >
222
+ ChainListener for ChainMonitor < ChanSigner , T , F , L >
229
223
where T :: Target : BroadcasterInterface ,
230
224
F :: Target : FeeEstimator ,
231
225
L :: Target : Logger ,
@@ -255,14 +249,14 @@ impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref + Sync
255
249
}
256
250
}
257
251
258
- impl < Key : Send + cmp :: Eq + hash :: Hash + ' static , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref > ChainMonitor < Key , ChanSigner , T , F , L >
252
+ impl < ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref > ChainMonitor < ChanSigner , T , F , L >
259
253
where T :: Target : BroadcasterInterface ,
260
254
F :: Target : FeeEstimator ,
261
255
L :: Target : Logger ,
262
256
{
263
257
/// Creates a new object which can be used to monitor several channels given the chain
264
258
/// interface with which to register to receive notifications.
265
- pub fn new ( broadcaster : T , logger : L , feeest : F ) -> ChainMonitor < Key , ChanSigner , T , F , L > {
259
+ pub fn new ( broadcaster : T , logger : L , feeest : F ) -> Self {
266
260
Self {
267
261
monitors : Mutex :: new ( HashMap :: new ( ) ) ,
268
262
watch_events : Mutex :: new ( WatchEventQueue :: new ( ) ) ,
@@ -272,12 +266,12 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys, T: De
272
266
}
273
267
}
274
268
275
- /// Adds or updates the monitor which monitors the channel referred to by the given key .
276
- pub fn add_monitor_by_key ( & self , key : Key , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , MonitorUpdateError > {
269
+ /// Adds or updates the monitor which monitors the channel referred to by the given outpoint .
270
+ pub fn add_monitor ( & self , outpoint : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , MonitorUpdateError > {
277
271
let mut watch_events = self . watch_events . lock ( ) . unwrap ( ) ;
278
272
let mut monitors = self . monitors . lock ( ) . unwrap ( ) ;
279
- let entry = match monitors. entry ( key ) {
280
- hash_map:: Entry :: Occupied ( _) => return Err ( MonitorUpdateError ( "Channel monitor for given key is already present" ) ) ,
273
+ let entry = match monitors. entry ( outpoint ) {
274
+ hash_map:: Entry :: Occupied ( _) => return Err ( MonitorUpdateError ( "Channel monitor for given outpoint is already present" ) ) ,
281
275
hash_map:: Entry :: Vacant ( e) => e,
282
276
} ;
283
277
{
@@ -295,10 +289,10 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys, T: De
295
289
Ok ( ( ) )
296
290
}
297
291
298
- /// Updates the monitor which monitors the channel referred to by the given key .
299
- pub fn update_monitor_by_key ( & self , key : Key , update : ChannelMonitorUpdate ) -> Result < ( ) , MonitorUpdateError > {
292
+ /// Updates the monitor which monitors the channel referred to by the given outpoint .
293
+ pub fn update_monitor ( & self , outpoint : OutPoint , update : ChannelMonitorUpdate ) -> Result < ( ) , MonitorUpdateError > {
300
294
let mut monitors = self . monitors . lock ( ) . unwrap ( ) ;
301
- match monitors. get_mut ( & key ) {
295
+ match monitors. get_mut ( & outpoint ) {
302
296
Some ( orig_monitor) => {
303
297
log_trace ! ( self . logger, "Updating Channel Monitor for channel {}" , log_funding_info!( orig_monitor) ) ;
304
298
orig_monitor. update_monitor ( update, & self . broadcaster , & self . logger )
@@ -308,22 +302,22 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys, T: De
308
302
}
309
303
}
310
304
311
- impl < ChanSigner : ChannelKeys , T : Deref + Sync + Send , F : Deref + Sync + Send , L : Deref + Sync + Send > chain:: Watch for ChainMonitor < OutPoint , ChanSigner , T , F , L >
305
+ impl < ChanSigner : ChannelKeys , T : Deref + Sync + Send , F : Deref + Sync + Send , L : Deref + Sync + Send > chain:: Watch for ChainMonitor < ChanSigner , T , F , L >
312
306
where T :: Target : BroadcasterInterface ,
313
307
F :: Target : FeeEstimator ,
314
308
L :: Target : Logger ,
315
309
{
316
310
type Keys = ChanSigner ;
317
311
318
312
fn watch_channel ( & self , funding_txo : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > {
319
- match self . add_monitor_by_key ( funding_txo, monitor) {
313
+ match self . add_monitor ( funding_txo, monitor) {
320
314
Ok ( _) => Ok ( ( ) ) ,
321
315
Err ( _) => Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ,
322
316
}
323
317
}
324
318
325
319
fn update_channel ( & self , funding_txo : OutPoint , update : ChannelMonitorUpdate ) -> Result < ( ) , ChannelMonitorUpdateErr > {
326
- match self . update_monitor_by_key ( funding_txo, update) {
320
+ match self . update_monitor ( funding_txo, update) {
327
321
Ok ( _) => Ok ( ( ) ) ,
328
322
Err ( _) => Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ,
329
323
}
@@ -338,7 +332,7 @@ impl<ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L:
338
332
}
339
333
}
340
334
341
- impl < Key : Send + cmp :: Eq + hash :: Hash , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref > events:: EventsProvider for ChainMonitor < Key , ChanSigner , T , F , L >
335
+ impl < ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref > events:: EventsProvider for ChainMonitor < ChanSigner , T , F , L >
342
336
where T :: Target : BroadcasterInterface ,
343
337
F :: Target : FeeEstimator ,
344
338
L :: Target : Logger ,
@@ -352,7 +346,7 @@ impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref, F: De
352
346
}
353
347
}
354
348
355
- impl < Key : Send + cmp :: Eq + hash :: Hash , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref > chain:: WatchEventProvider for ChainMonitor < Key , ChanSigner , T , F , L >
349
+ impl < ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref > chain:: WatchEventProvider for ChainMonitor < ChanSigner , T , F , L >
356
350
where T :: Target : BroadcasterInterface ,
357
351
F :: Target : FeeEstimator ,
358
352
L :: Target : Logger ,
0 commit comments