@@ -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 : & [ u32 ] ) ;
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,32 +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).
256
+ /// Notify listeners that a block was connected.
277
257
pub fn block_connected < ' b > ( & self , block : & ' b Block , height : u32 ) {
278
- let mut reentered = true ;
279
- while reentered {
280
- let ( matched, matched_index) = self . chain_monitor . filter_block ( block) ;
281
- reentered = self . block_connected_checked ( & block. header , height, matched. as_slice ( ) , matched_index. as_slice ( ) ) ;
282
- }
283
- }
284
-
285
- /// Notify listeners that a block was connected, given pre-filtered list of transactions in the
286
- /// block which matched the filter (probably using does_match_tx).
287
- ///
288
- /// Returns true if notified listeners registered additional watch data (implying that the
289
- /// block must be re-scanned and this function called again prior to further block_connected
290
- /// calls, see ChainListener::block_connected for more info).
291
- pub fn block_connected_checked ( & self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ u32 ] ) -> bool {
292
- let last_seen = self . chain_monitor . reentered ( ) ;
293
-
294
258
let listeners = self . listeners . lock ( ) . unwrap ( ) ;
295
259
for listener in listeners. iter ( ) {
296
- listener. block_connected ( header , height, txn_matched , indexes_of_txn_matched ) ;
260
+ listener. block_connected ( block , height) ;
297
261
}
298
- return last_seen != self . chain_monitor . reentered ( ) ;
299
262
}
300
263
301
264
/// Notify listeners that a block was disconnected.
@@ -408,7 +371,7 @@ mod tests {
408
371
fn register_listener_test ( ) {
409
372
let chanmon_cfgs = create_chanmon_cfgs ( 1 ) ;
410
373
let node_cfgs = create_node_cfgs ( 1 , & chanmon_cfgs) ;
411
- let block_notifier = BlockNotifier :: new ( node_cfgs [ 0 ] . chain_monitor ) ;
374
+ let block_notifier = BlockNotifier :: new ( ) ;
412
375
assert_eq ! ( block_notifier. listeners. lock( ) . unwrap( ) . len( ) , 0 ) ;
413
376
let listener = & node_cfgs[ 0 ] . chan_monitor . simple_monitor as & ChainListener ;
414
377
block_notifier. register_listener ( listener) ;
@@ -422,7 +385,7 @@ mod tests {
422
385
fn unregister_single_listener_test ( ) {
423
386
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
424
387
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
425
- let block_notifier = BlockNotifier :: new ( node_cfgs [ 0 ] . chain_monitor ) ;
388
+ let block_notifier = BlockNotifier :: new ( ) ;
426
389
let listener1 = & node_cfgs[ 0 ] . chan_monitor . simple_monitor as & ChainListener ;
427
390
let listener2 = & node_cfgs[ 1 ] . chan_monitor . simple_monitor as & ChainListener ;
428
391
block_notifier. register_listener ( listener1) ;
@@ -441,7 +404,7 @@ mod tests {
441
404
fn unregister_single_listener_ref_test ( ) {
442
405
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
443
406
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
444
- let block_notifier = BlockNotifier :: new ( node_cfgs [ 0 ] . chain_monitor ) ;
407
+ let block_notifier = BlockNotifier :: new ( ) ;
445
408
block_notifier. register_listener ( & node_cfgs[ 0 ] . chan_monitor . simple_monitor as & ChainListener ) ;
446
409
block_notifier. register_listener ( & node_cfgs[ 1 ] . chan_monitor . simple_monitor as & ChainListener ) ;
447
410
let vec = block_notifier. listeners . lock ( ) . unwrap ( ) ;
@@ -458,7 +421,7 @@ mod tests {
458
421
fn unregister_multiple_of_the_same_listeners_test ( ) {
459
422
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
460
423
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
461
- let block_notifier = BlockNotifier :: new ( node_cfgs [ 0 ] . chain_monitor ) ;
424
+ let block_notifier = BlockNotifier :: new ( ) ;
462
425
let listener1 = & node_cfgs[ 0 ] . chan_monitor . simple_monitor as & ChainListener ;
463
426
let listener2 = & node_cfgs[ 1 ] . chan_monitor . simple_monitor as & ChainListener ;
464
427
block_notifier. register_listener ( listener1) ;
0 commit comments