@@ -43,6 +43,7 @@ use ln::onchain_utils::{InputDescriptors, PackageTemplate, OnchainRequest, BumpS
43
43
use chain:: chaininterface:: { ChainListener , ChainWatchInterface , BroadcasterInterface , FeeEstimator } ;
44
44
use chain:: transaction:: OutPoint ;
45
45
use chain:: keysinterface:: { SpendableOutputDescriptor , ChannelKeys } ;
46
+ use chain:: utxointerface:: UtxoPool ;
46
47
use util:: logger:: Logger ;
47
48
use util:: ser:: { Readable , MaybeReadable , Writer , Writeable , U48 } ;
48
49
use util:: { byte_utils, events} ;
@@ -188,35 +189,37 @@ impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
188
189
///
189
190
/// If you're using this for local monitoring of your own channels, you probably want to use
190
191
/// `OutPoint` as the key, which will give you a ManyChannelMonitor implementation.
191
- ///
192
192
/// (C-not exported) due to an unconstrained generic in `Key`
193
- pub struct SimpleManyChannelMonitor < Key , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref , C : Deref >
193
+ pub struct SimpleManyChannelMonitor < Key , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref , C : Deref , U : Deref >
194
194
where T :: Target : BroadcasterInterface ,
195
195
F :: Target : FeeEstimator ,
196
196
L :: Target : Logger ,
197
197
C :: Target : ChainWatchInterface ,
198
+ U :: Target : UtxoPool ,
198
199
{
199
200
/// The monitors
200
201
pub monitors : Mutex < HashMap < Key , ChannelMonitor < ChanSigner > > > ,
201
202
chain_monitor : C ,
202
203
broadcaster : T ,
203
204
logger : L ,
204
- fee_estimator : F
205
+ fee_estimator : F ,
206
+ utxo_pool : U ,
205
207
}
206
208
207
- impl < Key : Send + cmp:: Eq + hash:: Hash , ChanSigner : ChannelKeys , T : Deref + Sync + Send , F : Deref + Sync + Send , L : Deref + Sync + Send , C : Deref + Sync + Send >
208
- ChainListener for SimpleManyChannelMonitor < Key , ChanSigner , T , F , L , C >
209
+ impl < Key : Send + cmp:: Eq + hash:: Hash , ChanSigner : ChannelKeys , T : Deref + Sync + Send , F : Deref + Sync + Send , L : Deref + Sync + Send , C : Deref + Sync + Send , U : Deref + Sync + Send >
210
+ ChainListener for SimpleManyChannelMonitor < Key , ChanSigner , T , F , L , C , U >
209
211
where T :: Target : BroadcasterInterface ,
210
212
F :: Target : FeeEstimator ,
211
213
L :: Target : Logger ,
212
214
C :: Target : ChainWatchInterface ,
215
+ U :: Target : UtxoPool
213
216
{
214
217
fn block_connected ( & self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , _indexes_of_txn_matched : & [ usize ] ) {
215
218
let block_hash = header. block_hash ( ) ;
216
219
{
217
220
let mut monitors = self . monitors . lock ( ) . unwrap ( ) ;
218
221
for monitor in monitors. values_mut ( ) {
219
- let txn_outputs = monitor. block_connected ( txn_matched, height, & block_hash, & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
222
+ let txn_outputs = monitor. block_connected ( txn_matched, height, & block_hash, & * self . broadcaster , & * self . fee_estimator , & * self . logger , & * self . utxo_pool ) ;
220
223
221
224
for ( ref txid, ref outputs) in txn_outputs {
222
225
for ( idx, output) in outputs. iter ( ) . enumerate ( ) {
@@ -231,26 +234,28 @@ impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref + Sync
231
234
let block_hash = header. block_hash ( ) ;
232
235
let mut monitors = self . monitors . lock ( ) . unwrap ( ) ;
233
236
for monitor in monitors. values_mut ( ) {
234
- monitor. block_disconnected ( disconnected_height, & block_hash, & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
237
+ monitor. block_disconnected ( disconnected_height, & block_hash, & * self . broadcaster , & * self . fee_estimator , & * self . logger , & * self . utxo_pool ) ;
235
238
}
236
239
}
237
240
}
238
241
239
- impl < Key : Send + cmp:: Eq + hash:: Hash + ' static , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref , C : Deref > SimpleManyChannelMonitor < Key , ChanSigner , T , F , L , C >
242
+ impl < Key : Send + cmp:: Eq + hash:: Hash + ' static , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref , C : Deref , U : Deref > SimpleManyChannelMonitor < Key , ChanSigner , T , F , L , C , U >
240
243
where T :: Target : BroadcasterInterface ,
241
244
F :: Target : FeeEstimator ,
242
245
L :: Target : Logger ,
243
246
C :: Target : ChainWatchInterface ,
247
+ U :: Target : UtxoPool
244
248
{
245
249
/// Creates a new object which can be used to monitor several channels given the chain
246
250
/// interface with which to register to receive notifications.
247
- pub fn new ( chain_monitor : C , broadcaster : T , logger : L , feeest : F ) -> SimpleManyChannelMonitor < Key , ChanSigner , T , F , L , C > {
251
+ pub fn new ( chain_monitor : C , broadcaster : T , logger : L , feeest : F , utxo_pool : U ) -> SimpleManyChannelMonitor < Key , ChanSigner , T , F , L , C , U > {
248
252
let res = SimpleManyChannelMonitor {
249
253
monitors : Mutex :: new ( HashMap :: new ( ) ) ,
250
254
chain_monitor,
251
255
broadcaster,
252
256
logger,
253
257
fee_estimator : feeest,
258
+ utxo_pool,
254
259
} ;
255
260
256
261
res
@@ -291,11 +296,12 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys, T: De
291
296
}
292
297
}
293
298
294
- impl < ChanSigner : ChannelKeys , T : Deref + Sync + Send , F : Deref + Sync + Send , L : Deref + Sync + Send , C : Deref + Sync + Send > ManyChannelMonitor for SimpleManyChannelMonitor < OutPoint , ChanSigner , T , F , L , C >
299
+ impl < ChanSigner : ChannelKeys , T : Deref + Sync + Send , F : Deref + Sync + Send , L : Deref + Sync + Send , C : Deref + Sync + Send , U : Deref + Sync + Send > ManyChannelMonitor for SimpleManyChannelMonitor < OutPoint , ChanSigner , T , F , L , C , U >
295
300
where T :: Target : BroadcasterInterface ,
296
301
F :: Target : FeeEstimator ,
297
302
L :: Target : Logger ,
298
303
C :: Target : ChainWatchInterface ,
304
+ U :: Target : UtxoPool
299
305
{
300
306
type Keys = ChanSigner ;
301
307
@@ -322,11 +328,12 @@ impl<ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L:
322
328
}
323
329
}
324
330
325
- impl < Key : Send + cmp:: Eq + hash:: Hash , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref , C : Deref > events:: EventsProvider for SimpleManyChannelMonitor < Key , ChanSigner , T , F , L , C >
331
+ impl < Key : Send + cmp:: Eq + hash:: Hash , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref , C : Deref , U : Deref > events:: EventsProvider for SimpleManyChannelMonitor < Key , ChanSigner , T , F , L , C , U >
326
332
where T :: Target : BroadcasterInterface ,
327
333
F :: Target : FeeEstimator ,
328
334
L :: Target : Logger ,
329
335
C :: Target : ChainWatchInterface ,
336
+ U :: Target : UtxoPool
330
337
{
331
338
fn get_and_clear_pending_events ( & self ) -> Vec < Event > {
332
339
let mut pending_events = Vec :: new ( ) ;
@@ -1736,10 +1743,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1736
1743
/// Eventually this should be pub and, roughly, implement ChainListener, however this requires
1737
1744
/// &mut self, as well as returns new spendable outputs and outpoints to watch for spending of
1738
1745
/// on-chain.
1739
- fn block_connected < B : Deref , F : Deref , L : Deref > ( & mut self , txn_matched : & [ & Transaction ] , height : u32 , block_hash : & BlockHash , broadcaster : B , fee_estimator : F , logger : L ) -> Vec < ( Txid , Vec < TxOut > ) >
1746
+ fn block_connected < B : Deref , F : Deref , L : Deref , U : Deref > ( & mut self , txn_matched : & [ & Transaction ] , height : u32 , block_hash : & BlockHash , broadcaster : B , fee_estimator : F , logger : L , utxo_pool : U ) -> Vec < ( Txid , Vec < TxOut > ) >
1740
1747
where B :: Target : BroadcasterInterface ,
1741
1748
F :: Target : FeeEstimator ,
1742
1749
L :: Target : Logger ,
1750
+ U :: Target : UtxoPool
1743
1751
{
1744
1752
for tx in txn_matched {
1745
1753
let mut output_val = 0 ;
@@ -1828,8 +1836,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1828
1836
}
1829
1837
}
1830
1838
}
1831
-
1832
- self . onchain_tx_handler . block_connected ( txn_matched, claimable_outpoints, height, & * broadcaster, & * fee_estimator, & * logger) ;
1839
+ self . onchain_tx_handler . block_connected ( txn_matched, claimable_outpoints, height, & * broadcaster, & * fee_estimator, & * logger, & * utxo_pool) ;
1833
1840
1834
1841
self . last_block_hash = block_hash. clone ( ) ;
1835
1842
for & ( ref txid, ref output_scripts) in watch_outputs. iter ( ) {
@@ -1839,10 +1846,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1839
1846
watch_outputs
1840
1847
}
1841
1848
1842
- fn block_disconnected < B : Deref , F : Deref , L : Deref > ( & mut self , height : u32 , block_hash : & BlockHash , broadcaster : B , fee_estimator : F , logger : L )
1849
+ fn block_disconnected < B : Deref , F : Deref , L : Deref , U : Deref > ( & mut self , height : u32 , block_hash : & BlockHash , broadcaster : B , fee_estimator : F , logger : L , utxo_pool : U )
1843
1850
where B :: Target : BroadcasterInterface ,
1844
1851
F :: Target : FeeEstimator ,
1845
1852
L :: Target : Logger ,
1853
+ U :: Target : UtxoPool
1846
1854
{
1847
1855
log_trace ! ( logger, "Block {} at height {} disconnected" , block_hash, height) ;
1848
1856
if let Some ( _) = self . onchain_events_waiting_threshold_conf . remove ( & ( height + ANTI_REORG_DELAY - 1 ) ) {
@@ -1851,7 +1859,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1851
1859
//- maturing spendable output has transaction paying us has been disconnected
1852
1860
}
1853
1861
1854
- self . onchain_tx_handler . block_disconnected ( height, broadcaster, fee_estimator, logger) ;
1862
+ self . onchain_tx_handler . block_disconnected ( height, broadcaster, fee_estimator, logger, utxo_pool ) ;
1855
1863
1856
1864
self . last_block_hash = block_hash. clone ( ) ;
1857
1865
}
0 commit comments