@@ -93,24 +93,33 @@ where C::Target: chain::Filter,
93
93
/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events
94
94
/// [`chain::Filter`]: ../trait.Filter.html
95
95
pub fn block_connected ( & self , header : & BlockHeader , txdata : & TransactionData , height : u32 ) {
96
+ let mut dependent_txdata = Vec :: new ( ) ;
96
97
let monitors = self . monitors . read ( ) . unwrap ( ) ;
97
98
for monitor in monitors. values ( ) {
98
99
let mut txn_outputs = monitor. block_connected ( header, txdata, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
99
100
101
+ // Register any new outputs with the chain source for filtering, storing any dependent
102
+ // transactions from within the block that previously had not been included in txdata.
100
103
if let Some ( ref chain_source) = self . chain_source {
101
104
for ( txid, outputs) in txn_outputs. drain ( ..) {
102
105
for ( idx, output) in outputs. iter ( ) {
103
- // Register any new outputs with the chain source for filtering and recurse
104
- // if it indicates that there are dependent transactions within the block
105
- // that had not been previously included in txdata.
106
106
let outpoint = OutPoint { txid, index : * idx as u16 } ;
107
- if let Some ( ( index, tx) ) = chain_source. register_output ( & outpoint, & output. script_pubkey ) {
108
- self . block_connected ( header, & [ ( index, & tx) ] , height) ;
107
+ let script_pubkey = & output. script_pubkey ;
108
+ if let Some ( tx) = chain_source. register_output ( & outpoint, script_pubkey) {
109
+ dependent_txdata. push ( tx) ;
109
110
}
110
111
}
111
112
}
112
113
}
113
114
}
115
+
116
+ // Recursively call for any dependent transactions that were identified by the chain source.
117
+ if !dependent_txdata. is_empty ( ) {
118
+ dependent_txdata. sort_unstable_by_key ( |( index, _tx) | * index) ;
119
+ dependent_txdata. dedup_by_key ( |( index, _tx) | * index) ;
120
+ let txdata: Vec < _ > = dependent_txdata. iter ( ) . map ( |( index, tx) | ( * index, tx) ) . collect ( ) ;
121
+ self . block_connected ( header, & txdata, height) ;
122
+ }
114
123
}
115
124
116
125
/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
0 commit comments