@@ -74,64 +74,14 @@ where C::Target: chain::Filter,
74
74
P :: Target : channelmonitor:: Persist < ChannelSigner > ,
75
75
{
76
76
/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
77
- /// of a channel and reacting accordingly based on transactions in the connected block . See
77
+ /// of a channel and reacting accordingly based on transactions in the given chain data . See
78
78
/// [`ChannelMonitor::block_connected`] for details. Any HTLCs that were resolved on chain will
79
79
/// be returned by [`chain::Watch::release_pending_monitor_events`].
80
80
///
81
81
/// Calls back to [`chain::Filter`] if any monitor indicated new outputs to watch. Subsequent
82
82
/// calls must not exclude any transactions matching the new outputs nor any in-block
83
83
/// descendants of such transactions. It is not necessary to re-fetch the block to obtain
84
84
/// updated `txdata`.
85
- pub fn block_connected ( & self , header : & BlockHeader , txdata : & TransactionData , height : u32 ) {
86
- self . process_chain_data ( header, txdata, |monitor, txdata| {
87
- monitor. block_connected (
88
- header, txdata, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
89
- } ) ;
90
- }
91
-
92
- /// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
93
- /// of a channel and reacting accordingly to newly confirmed transactions. For details, see
94
- /// [`ChannelMonitor::transactions_confirmed`].
95
- ///
96
- /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
97
- /// blocks. May be called before or after [`update_best_block`] for transactions in the
98
- /// corresponding block. See [`update_best_block`] for further calling expectations.
99
- ///
100
- /// [`block_connected`]: Self::block_connected
101
- /// [`update_best_block`]: Self::update_best_block
102
- pub fn transactions_confirmed ( & self , header : & BlockHeader , txdata : & TransactionData , height : u32 ) {
103
- self . process_chain_data ( header, txdata, |monitor, txdata| {
104
- monitor. transactions_confirmed (
105
- header, txdata, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
106
- } ) ;
107
- }
108
-
109
- /// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
110
- /// of a channel and reacting accordingly based on the new chain tip. For details, see
111
- /// [`ChannelMonitor::update_best_block`].
112
- ///
113
- /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
114
- /// blocks. May be called before or after [`transactions_confirmed`] for the corresponding
115
- /// block.
116
- ///
117
- /// Must be called after new blocks become available for the most recent block. Intermediary
118
- /// blocks, however, may be safely skipped. In the event of a chain re-organization, this only
119
- /// needs to be called for the most recent block assuming `transaction_unconfirmed` is called
120
- /// for any affected transactions.
121
- ///
122
- /// [`block_connected`]: Self::block_connected
123
- /// [`transactions_confirmed`]: Self::transactions_confirmed
124
- /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
125
- pub fn update_best_block ( & self , header : & BlockHeader , height : u32 ) {
126
- self . process_chain_data ( header, & [ ] , |monitor, txdata| {
127
- // While in practice there shouldn't be any recursive calls when given empty txdata,
128
- // it's still possible if a chain::Filter implementation returns a transaction.
129
- debug_assert ! ( txdata. is_empty( ) ) ;
130
- monitor. update_best_block (
131
- header, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
132
- } ) ;
133
- }
134
-
135
85
fn process_chain_data < FN > ( & self , header : & BlockHeader , txdata : & TransactionData , process : FN )
136
86
where
137
87
FN : Fn ( & ChannelMonitor < ChannelSigner > , & TransactionData ) -> Vec < TransactionOutputs >
@@ -172,46 +122,6 @@ where C::Target: chain::Filter,
172
122
}
173
123
}
174
124
175
- /// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
176
- /// of a channel based on the disconnected block. See [`ChannelMonitor::block_disconnected`] for
177
- /// details.
178
- pub fn block_disconnected ( & self , header : & BlockHeader , disconnected_height : u32 ) {
179
- let monitors = self . monitors . read ( ) . unwrap ( ) ;
180
- for monitor in monitors. values ( ) {
181
- monitor. block_disconnected ( header, disconnected_height, & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
182
- }
183
- }
184
-
185
- /// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
186
- /// of a channel based on transactions unconfirmed as a result of a chain reorganization. See
187
- /// [`ChannelMonitor::transaction_unconfirmed`] for details.
188
- ///
189
- /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
190
- /// than blocks. May be called before or after [`update_best_block`] for transactions in the
191
- /// corresponding block. See [`update_best_block`] for further calling expectations.
192
- ///
193
- /// [`block_disconnected`]: Self::block_disconnected
194
- /// [`update_best_block`]: Self::update_best_block
195
- pub fn transaction_unconfirmed ( & self , txid : & Txid ) {
196
- let monitors = self . monitors . read ( ) . unwrap ( ) ;
197
- for monitor in monitors. values ( ) {
198
- monitor. transaction_unconfirmed ( txid, & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
199
- }
200
- }
201
-
202
- /// Returns the set of txids that should be monitored for re-organization out of the chain.
203
- pub fn get_relevant_txids ( & self ) -> Vec < Txid > {
204
- let mut txids = Vec :: new ( ) ;
205
- let monitors = self . monitors . read ( ) . unwrap ( ) ;
206
- for monitor in monitors. values ( ) {
207
- txids. append ( & mut monitor. get_relevant_txids ( ) ) ;
208
- }
209
-
210
- txids. sort_unstable ( ) ;
211
- txids. dedup ( ) ;
212
- txids
213
- }
214
-
215
125
/// Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
216
126
///
217
127
/// When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
@@ -231,7 +141,7 @@ where C::Target: chain::Filter,
231
141
}
232
142
}
233
143
234
- impl < ChannelSigner : Sign , C : Deref + Send + Sync , T : Deref + Send + Sync , F : Deref + Send + Sync , L : Deref + Send + Sync , P : Deref + Send + Sync >
144
+ impl < ChannelSigner : Sign , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref >
235
145
chain:: Listen for ChainMonitor < ChannelSigner , C , T , F , L , P >
236
146
where
237
147
ChannelSigner : Sign ,
@@ -242,12 +152,67 @@ where
242
152
P :: Target : channelmonitor:: Persist < ChannelSigner > ,
243
153
{
244
154
fn block_connected ( & self , block : & Block , height : u32 ) {
155
+ let header = & block. header ;
245
156
let txdata: Vec < _ > = block. txdata . iter ( ) . enumerate ( ) . collect ( ) ;
246
- ChainMonitor :: block_connected ( self , & block. header , & txdata, height) ;
157
+ self . process_chain_data ( header, & txdata, |monitor, txdata| {
158
+ monitor. block_connected (
159
+ header, txdata, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
160
+ } ) ;
247
161
}
248
162
249
163
fn block_disconnected ( & self , header : & BlockHeader , height : u32 ) {
250
- ChainMonitor :: block_disconnected ( self , header, height) ;
164
+ let monitors = self . monitors . read ( ) . unwrap ( ) ;
165
+ for monitor in monitors. values ( ) {
166
+ monitor. block_disconnected (
167
+ header, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
168
+ }
169
+ }
170
+ }
171
+
172
+ impl < ChannelSigner : Sign , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref >
173
+ chain:: Confirm for ChainMonitor < ChannelSigner , C , T , F , L , P >
174
+ where
175
+ ChannelSigner : Sign ,
176
+ C :: Target : chain:: Filter ,
177
+ T :: Target : BroadcasterInterface ,
178
+ F :: Target : FeeEstimator ,
179
+ L :: Target : Logger ,
180
+ P :: Target : channelmonitor:: Persist < ChannelSigner > ,
181
+ {
182
+ fn transactions_confirmed ( & self , header : & BlockHeader , txdata : & TransactionData , height : u32 ) {
183
+ self . process_chain_data ( header, txdata, |monitor, txdata| {
184
+ monitor. transactions_confirmed (
185
+ header, txdata, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
186
+ } ) ;
187
+ }
188
+
189
+ fn transaction_unconfirmed ( & self , txid : & Txid ) {
190
+ let monitors = self . monitors . read ( ) . unwrap ( ) ;
191
+ for monitor in monitors. values ( ) {
192
+ monitor. transaction_unconfirmed ( txid, & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
193
+ }
194
+ }
195
+
196
+ fn best_block_updated ( & self , header : & BlockHeader , height : u32 ) {
197
+ self . process_chain_data ( header, & [ ] , |monitor, txdata| {
198
+ // While in practice there shouldn't be any recursive calls when given empty txdata,
199
+ // it's still possible if a chain::Filter implementation returns a transaction.
200
+ debug_assert ! ( txdata. is_empty( ) ) ;
201
+ monitor. best_block_updated (
202
+ header, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
203
+ } ) ;
204
+ }
205
+
206
+ fn get_relevant_txids ( & self ) -> Vec < Txid > {
207
+ let mut txids = Vec :: new ( ) ;
208
+ let monitors = self . monitors . read ( ) . unwrap ( ) ;
209
+ for monitor in monitors. values ( ) {
210
+ txids. append ( & mut monitor. get_relevant_txids ( ) ) ;
211
+ }
212
+
213
+ txids. sort_unstable ( ) ;
214
+ txids. dedup ( ) ;
215
+ txids
251
216
}
252
217
}
253
218
0 commit comments