@@ -210,24 +210,13 @@ struct MonitorHolder<ChannelSigner: WriteableEcdsaChannelSigner> {
210
210
/// [`ChannelMonitorUpdateStatus::InProgress`], and then calls channel_monitor_updated
211
211
/// immediately, racing our insertion of the pending update into the contained Vec.
212
212
pending_monitor_updates : Mutex < Vec < MonitorUpdateId > > ,
213
- /// The last block height at which no [`UpdateOrigin::ChainSync`] monitor updates were present
214
- /// in `pending_monitor_updates`.
215
- /// If it's been more than [`LATENCY_GRACE_PERIOD_BLOCKS`] since we started waiting on a chain
216
- /// sync event, we let monitor events return to `ChannelManager` because we cannot hold them up
217
- /// forever or we'll end up with HTLC preimages waiting to feed back into an upstream channel
218
- /// forever, risking funds loss.
219
- last_chain_persist_height : AtomicUsize ,
220
213
}
221
214
222
215
impl < ChannelSigner : WriteableEcdsaChannelSigner > MonitorHolder < ChannelSigner > {
223
216
fn has_pending_offchain_updates ( & self , pending_monitor_updates_lock : & MutexGuard < Vec < MonitorUpdateId > > ) -> bool {
224
217
pending_monitor_updates_lock. iter ( ) . any ( |update_id|
225
218
if let UpdateOrigin :: OffChain ( _) = update_id. contents { true } else { false } )
226
219
}
227
- fn has_pending_chainsync_updates ( & self , pending_monitor_updates_lock : & MutexGuard < Vec < MonitorUpdateId > > ) -> bool {
228
- pending_monitor_updates_lock. iter ( ) . any ( |update_id|
229
- if let UpdateOrigin :: ChainSync ( _) = update_id. contents { true } else { false } )
230
- }
231
220
}
232
221
233
222
/// A read-only reference to a current ChannelMonitor.
@@ -315,7 +304,7 @@ where C::Target: chain::Filter,
315
304
for funding_outpoint in funding_outpoints. iter ( ) {
316
305
let monitor_lock = self . monitors . read ( ) . unwrap ( ) ;
317
306
if let Some ( monitor_state) = monitor_lock. get ( funding_outpoint) {
318
- if self . update_monitor_with_chain_data ( header, best_height , txdata, & process, funding_outpoint, & monitor_state) . is_err ( ) {
307
+ if self . update_monitor_with_chain_data ( header, txdata, & process, funding_outpoint, & monitor_state) . is_err ( ) {
319
308
// Take the monitors lock for writing so that we poison it and any future
320
309
// operations going forward fail immediately.
321
310
core:: mem:: drop ( monitor_lock) ;
@@ -330,7 +319,7 @@ where C::Target: chain::Filter,
330
319
let monitor_states = self . monitors . write ( ) . unwrap ( ) ;
331
320
for ( funding_outpoint, monitor_state) in monitor_states. iter ( ) {
332
321
if !funding_outpoints. contains ( funding_outpoint) {
333
- if self . update_monitor_with_chain_data ( header, best_height , txdata, & process, funding_outpoint, & monitor_state) . is_err ( ) {
322
+ if self . update_monitor_with_chain_data ( header, txdata, & process, funding_outpoint, & monitor_state) . is_err ( ) {
334
323
log_error ! ( self . logger, "{}" , err_str) ;
335
324
panic ! ( "{}" , err_str) ;
336
325
}
@@ -349,8 +338,8 @@ where C::Target: chain::Filter,
349
338
}
350
339
351
340
fn update_monitor_with_chain_data < FN > (
352
- & self , header : & Header , best_height : Option < u32 > , txdata : & TransactionData ,
353
- process : FN , funding_outpoint : & OutPoint , monitor_state : & MonitorHolder < ChannelSigner >
341
+ & self , header : & Header , txdata : & TransactionData , process : FN , funding_outpoint : & OutPoint ,
342
+ monitor_state : & MonitorHolder < ChannelSigner >
354
343
) -> Result < ( ) , ( ) > where FN : Fn ( & ChannelMonitor < ChannelSigner > , & TransactionData ) -> Vec < TransactionOutputs > {
355
344
let monitor = & monitor_state. monitor ;
356
345
let logger = WithChannelMonitor :: from ( & self . logger , & monitor) ;
@@ -362,14 +351,6 @@ where C::Target: chain::Filter,
362
351
contents : UpdateOrigin :: ChainSync ( chain_sync_update_id) ,
363
352
} ;
364
353
let mut pending_monitor_updates = monitor_state. pending_monitor_updates . lock ( ) . unwrap ( ) ;
365
- if let Some ( height) = best_height {
366
- if !monitor_state. has_pending_chainsync_updates ( & pending_monitor_updates) {
367
- // If there are not ChainSync persists awaiting completion, go ahead and
368
- // set last_chain_persist_height here - we wouldn't want the first
369
- // InProgress to always immediately be considered "overly delayed".
370
- monitor_state. last_chain_persist_height . store ( height as usize , Ordering :: Release ) ;
371
- }
372
- }
373
354
374
355
log_trace ! ( logger, "Syncing Channel Monitor for channel {} for block-data update_id {}" ,
375
356
log_funding_info!( monitor) ,
@@ -560,23 +541,7 @@ where C::Target: chain::Filter,
560
541
monitor_update_id: monitor_data. monitor. get_latest_update_id( ) ,
561
542
} ] , monitor_data. monitor . get_counterparty_node_id ( ) ) ) ;
562
543
} ,
563
- MonitorUpdateId { contents : UpdateOrigin :: ChainSync ( completed_update_id) } => {
564
- let monitor_has_pending_updates =
565
- monitor_data. has_pending_chainsync_updates ( & pending_monitor_updates) ;
566
- log_debug ! ( self . logger, "Completed chain sync monitor update {} for channel with funding outpoint {:?}, {}" ,
567
- completed_update_id,
568
- funding_txo,
569
- if monitor_has_pending_updates {
570
- "still have pending chain sync updates"
571
- } else {
572
- "all chain sync updates complete, releasing pending MonitorEvents"
573
- } ) ;
574
- if !monitor_has_pending_updates {
575
- monitor_data. last_chain_persist_height . store ( self . highest_chain_height . load ( Ordering :: Acquire ) , Ordering :: Release ) ;
576
- // The next time release_pending_monitor_events is called, any events for this
577
- // ChannelMonitor will be returned.
578
- }
579
- } ,
544
+ MonitorUpdateId { contents : UpdateOrigin :: ChainSync ( _) } => { } ,
580
545
}
581
546
self . event_notifier . notify ( ) ;
582
547
Ok ( ( ) )
@@ -831,7 +796,6 @@ where C::Target: chain::Filter,
831
796
entry. insert ( MonitorHolder {
832
797
monitor,
833
798
pending_monitor_updates : Mutex :: new ( pending_monitor_updates) ,
834
- last_chain_persist_height : AtomicUsize :: new ( self . highest_chain_height . load ( Ordering :: Acquire ) ) ,
835
799
} ) ;
836
800
Ok ( persist_res)
837
801
}
0 commit comments