@@ -72,21 +72,7 @@ pub trait BroadcasterInterface: Sync + Send {
72
72
/// A trait indicating a desire to listen for events from the chain
73
73
pub trait ChainListener : Sync + Send {
74
74
/// Notifies a listener that a block was connected.
75
- ///
76
- /// The txn_matched array should be set to references to transactions which matched the
77
- /// relevant installed watch outpoints/txn, or the full set of transactions in the block.
78
- ///
79
- /// Note that if txn_matched includes only matched transactions, and a new
80
- /// transaction/outpoint is watched during a block_connected call, the block *must* be
81
- /// re-scanned with the new transaction/outpoints and block_connected should be called
82
- /// again with the same header and (at least) the new transactions.
83
- ///
84
- /// Note that if non-new transaction/outpoints are be registered during a call, a second call
85
- /// *must not* happen.
86
- ///
87
- /// This also means those counting confirmations using block_connected callbacks should watch
88
- /// for duplicate headers and not count them towards confirmations!
89
- fn block_connected ( & self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ usize ] ) ;
75
+ fn block_connected ( & self , block : & Block , height : u32 ) ;
90
76
/// Notifies a listener that a block was disconnected.
91
77
/// Unlike block_connected, this *must* never be called twice for the same disconnect event.
92
78
/// Height must be the one of the block which was disconnected (not new height of the best chain)
@@ -218,7 +204,7 @@ impl ChainWatchedUtil {
218
204
/// parameters with static lifetimes). Other times you can afford a reference, which is more
219
205
/// efficient, in which case BlockNotifierRef is a more appropriate type. Defining these type
220
206
/// aliases prevents issues such as overly long function definitions.
221
- pub type BlockNotifierArc < C > = Arc < BlockNotifier < ' static , Arc < ChainListener > , C > > ;
207
+ pub type BlockNotifierArc = Arc < BlockNotifier < ' static , Arc < ChainListener > > > ;
222
208
223
209
/// BlockNotifierRef is useful when you want a BlockNotifier that points to ChainListeners
224
210
/// with nonstatic lifetimes. This is useful for when static lifetimes are not needed. Nonstatic
@@ -227,27 +213,24 @@ pub type BlockNotifierArc<C> = Arc<BlockNotifier<'static, Arc<ChainListener>, C>
227
213
/// requires parameters with static lifetimes), in which case BlockNotifierArc is a more
228
214
/// appropriate type. Defining these type aliases for common usages prevents issues such as
229
215
/// overly long function definitions.
230
- pub type BlockNotifierRef < ' a , C > = BlockNotifier < ' a , & ' a ChainListener , C > ;
216
+ pub type BlockNotifierRef < ' a > = BlockNotifier < ' a , & ' a ChainListener > ;
231
217
232
- /// Utility for notifying listeners about new blocks, and handling block rescans if new watch
233
- /// data is registered.
218
+ /// Utility for notifying listeners when blocks are connected or disconnected.
234
219
///
235
220
/// Rather than using a plain BlockNotifier, it is preferable to use either a BlockNotifierArc
236
221
/// or a BlockNotifierRef for conciseness. See their documentation for more details, but essentially
237
222
/// you should default to using a BlockNotifierRef, and use a BlockNotifierArc instead when you
238
223
/// require ChainListeners with static lifetimes, such as when you're using lightning-net-tokio.
239
- pub struct BlockNotifier < ' a , CL : Deref < Target = ChainListener + ' a > + ' a , C : Deref > where C :: Target : ChainWatchInterface {
224
+ pub struct BlockNotifier < ' a , CL : Deref < Target = ChainListener + ' a > + ' a > {
240
225
listeners : Mutex < Vec < CL > > ,
241
- chain_monitor : C ,
242
226
phantom : PhantomData < & ' a ( ) > ,
243
227
}
244
228
245
- impl < ' a , CL : Deref < Target = ChainListener + ' a > + ' a , C : Deref > BlockNotifier < ' a , CL , C > where C :: Target : ChainWatchInterface {
229
+ impl < ' a , CL : Deref < Target = ChainListener + ' a > + ' a > BlockNotifier < ' a , CL > {
246
230
/// Constructs a new BlockNotifier without any listeners.
247
- pub fn new ( chain_monitor : C ) -> BlockNotifier < ' a , CL , C > {
231
+ pub fn new ( ) -> BlockNotifier < ' a , CL > {
248
232
BlockNotifier {
249
233
listeners : Mutex :: new ( Vec :: new ( ) ) ,
250
- chain_monitor,
251
234
phantom : PhantomData ,
252
235
}
253
236
}
@@ -270,36 +253,12 @@ impl<'a, CL: Deref<Target = ChainListener + 'a> + 'a, C: Deref> BlockNotifier<'a
270
253
vec. retain ( |item | !ptr:: eq ( & ( * * item) , & ( * listener) ) ) ;
271
254
}
272
255
273
- /// Notify listeners that a block was connected given a full, unfiltered block.
274
- ///
275
- /// Handles re-scanning the block and calling block_connected again if listeners register new
276
- /// watch data during the callbacks for you (see ChainListener::block_connected for more info).
277
- pub fn block_connected ( & self , block : & Block , height : u32 ) {
278
- let mut reentered = true ;
279
- while reentered {
280
- let matched_indexes = self . chain_monitor . filter_block ( block) ;
281
- let mut matched_txn = Vec :: new ( ) ;
282
- for index in matched_indexes. iter ( ) {
283
- matched_txn. push ( & block. txdata [ * index] ) ;
284
- }
285
- reentered = self . block_connected_checked ( & block. header , height, matched_txn. as_slice ( ) , matched_indexes. as_slice ( ) ) ;
286
- }
287
- }
288
-
289
- /// Notify listeners that a block was connected, given pre-filtered list of transactions in the
290
- /// block which matched the filter (probably using does_match_tx).
291
- ///
292
- /// Returns true if notified listeners registered additional watch data (implying that the
293
- /// block must be re-scanned and this function called again prior to further block_connected
294
- /// calls, see ChainListener::block_connected for more info).
295
- pub fn block_connected_checked ( & self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ usize ] ) -> bool {
296
- let last_seen = self . chain_monitor . reentered ( ) ;
297
-
256
+ /// Notify listeners that a block was connected.
257
+ pub fn block_connected < ' b > ( & self , block : & ' b Block , height : u32 ) {
298
258
let listeners = self . listeners . lock ( ) . unwrap ( ) ;
299
259
for listener in listeners. iter ( ) {
300
- listener. block_connected ( header , height, txn_matched , indexes_of_txn_matched ) ;
260
+ listener. block_connected ( block , height) ;
301
261
}
302
- return last_seen != self . chain_monitor . reentered ( ) ;
303
262
}
304
263
305
264
/// Notify listeners that a block was disconnected.
@@ -410,7 +369,7 @@ mod tests {
410
369
fn register_listener_test ( ) {
411
370
let chanmon_cfgs = create_chanmon_cfgs ( 1 ) ;
412
371
let node_cfgs = create_node_cfgs ( 1 , & chanmon_cfgs) ;
413
- let block_notifier = BlockNotifier :: new ( node_cfgs [ 0 ] . chain_monitor ) ;
372
+ let block_notifier = BlockNotifier :: new ( ) ;
414
373
assert_eq ! ( block_notifier. listeners. lock( ) . unwrap( ) . len( ) , 0 ) ;
415
374
let listener = & node_cfgs[ 0 ] . chan_monitor . simple_monitor as & ChainListener ;
416
375
block_notifier. register_listener ( listener) ;
@@ -424,7 +383,7 @@ mod tests {
424
383
fn unregister_single_listener_test ( ) {
425
384
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
426
385
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
427
- let block_notifier = BlockNotifier :: new ( node_cfgs [ 0 ] . chain_monitor ) ;
386
+ let block_notifier = BlockNotifier :: new ( ) ;
428
387
let listener1 = & node_cfgs[ 0 ] . chan_monitor . simple_monitor as & ChainListener ;
429
388
let listener2 = & node_cfgs[ 1 ] . chan_monitor . simple_monitor as & ChainListener ;
430
389
block_notifier. register_listener ( listener1) ;
@@ -443,7 +402,7 @@ mod tests {
443
402
fn unregister_single_listener_ref_test ( ) {
444
403
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
445
404
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
446
- let block_notifier = BlockNotifier :: new ( node_cfgs [ 0 ] . chain_monitor ) ;
405
+ let block_notifier = BlockNotifier :: new ( ) ;
447
406
block_notifier. register_listener ( & node_cfgs[ 0 ] . chan_monitor . simple_monitor as & ChainListener ) ;
448
407
block_notifier. register_listener ( & node_cfgs[ 1 ] . chan_monitor . simple_monitor as & ChainListener ) ;
449
408
let vec = block_notifier. listeners . lock ( ) . unwrap ( ) ;
@@ -460,7 +419,7 @@ mod tests {
460
419
fn unregister_multiple_of_the_same_listeners_test ( ) {
461
420
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
462
421
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
463
- let block_notifier = BlockNotifier :: new ( node_cfgs [ 0 ] . chain_monitor ) ;
422
+ let block_notifier = BlockNotifier :: new ( ) ;
464
423
let listener1 = & node_cfgs[ 0 ] . chan_monitor . simple_monitor as & ChainListener ;
465
424
let listener2 = & node_cfgs[ 1 ] . chan_monitor . simple_monitor as & ChainListener ;
466
425
block_notifier. register_listener ( listener1) ;
0 commit comments