@@ -2261,50 +2261,38 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2261
2261
}
2262
2262
2263
2263
pub fn get_update_fulfill_htlc_and_commit < L : Deref > ( & mut self , htlc_id : u64 , payment_preimage : PaymentPreimage , logger : & L ) -> UpdateFulfillCommitFetch where L :: Target : Logger {
2264
- let release_cs_monitor = self . context . pending_monitor_updates . iter ( ) . all ( |upd| !upd . blocked ) ;
2264
+ let release_cs_monitor = self . context . pending_monitor_updates . is_empty ( ) ;
2265
2265
match self . get_update_fulfill_htlc ( htlc_id, payment_preimage, logger) {
2266
2266
UpdateFulfillFetch :: NewClaim { mut monitor_update, htlc_value_msat, msg } => {
2267
2267
// Even if we aren't supposed to let new monitor updates with commitment state
2268
2268
// updates run, we still need to push the preimage ChannelMonitorUpdateStep no
2269
2269
// matter what. Sadly, to push a new monitor update which flies before others
2270
2270
// already queued, we have to insert it into the pending queue and update the
2271
2271
// update_ids of all the following monitors.
2272
- let unblocked_update_pos = if release_cs_monitor && msg. is_some ( ) {
2272
+ if release_cs_monitor && msg. is_some ( ) {
2273
2273
let mut additional_update = self . build_commitment_no_status_check ( logger) ;
2274
2274
// build_commitment_no_status_check may bump latest_monitor_id but we want them
2275
2275
// to be strictly increasing by one, so decrement it here.
2276
2276
self . context . latest_monitor_update_id = monitor_update. update_id ;
2277
2277
monitor_update. updates . append ( & mut additional_update. updates ) ;
2278
- self . context . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
2279
- update : monitor_update, blocked : false ,
2280
- } ) ;
2281
- self . context . pending_monitor_updates . len ( ) - 1
2282
2278
} else {
2283
- let insert_pos = self . context . pending_monitor_updates . iter ( ) . position ( |upd| upd. blocked )
2284
- . unwrap_or ( self . context . pending_monitor_updates . len ( ) ) ;
2285
- let new_mon_id = self . context . pending_monitor_updates . get ( insert_pos)
2279
+ let new_mon_id = self . context . pending_monitor_updates . get ( 0 )
2286
2280
. map ( |upd| upd. update . update_id ) . unwrap_or ( monitor_update. update_id ) ;
2287
2281
monitor_update. update_id = new_mon_id;
2288
- self . context . pending_monitor_updates . insert ( insert_pos, PendingChannelMonitorUpdate {
2289
- update : monitor_update, blocked : false ,
2290
- } ) ;
2291
- for held_update in self . context . pending_monitor_updates . iter_mut ( ) . skip ( insert_pos + 1 ) {
2282
+ for held_update in self . context . pending_monitor_updates . iter_mut ( ) {
2292
2283
held_update. update . update_id += 1 ;
2293
2284
}
2294
2285
if msg. is_some ( ) {
2295
- debug_assert ! ( false , "If there is a pending blocked monitor we should have MonitorUpdateInProgress set" ) ;
2296
2286
let update = self . build_commitment_no_status_check ( logger) ;
2297
2287
self . context . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
2298
2288
update, blocked : true ,
2299
2289
} ) ;
2300
2290
}
2301
- insert_pos
2302
- } ;
2291
+ }
2292
+
2303
2293
self . monitor_updating_paused ( false , msg. is_some ( ) , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
2304
2294
UpdateFulfillCommitFetch :: NewClaim {
2305
- monitor_update : self . context . pending_monitor_updates . get ( unblocked_update_pos)
2306
- . expect ( "We just pushed the monitor update" ) . update . clone ( ) ,
2307
- htlc_value_msat,
2295
+ monitor_update, htlc_value_msat,
2308
2296
}
2309
2297
} ,
2310
2298
UpdateFulfillFetch :: DuplicateClaim { } => UpdateFulfillCommitFetch :: DuplicateClaim { } ,
@@ -3341,8 +3329,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3341
3329
}
3342
3330
3343
3331
match self . free_holding_cell_htlcs ( logger) {
3344
- ( Some ( _) , htlcs_to_fail) => {
3345
- let mut additional_update = self . context . pending_monitor_updates . pop ( ) . unwrap ( ) . update ;
3332
+ ( Some ( mut additional_update) , htlcs_to_fail) => {
3346
3333
// free_holding_cell_htlcs may bump latest_monitor_id multiple times but we want them to be
3347
3334
// strictly increasing by one, so decrement it here.
3348
3335
self . context . latest_monitor_update_id = monitor_update. update_id ;
@@ -3558,12 +3545,9 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3558
3545
{
3559
3546
assert_eq ! ( self . context. channel_state & ChannelState :: MonitorUpdateInProgress as u32 , ChannelState :: MonitorUpdateInProgress as u32 ) ;
3560
3547
self . context . channel_state &= !( ChannelState :: MonitorUpdateInProgress as u32 ) ;
3561
- let mut found_blocked = false ;
3562
- self . context . pending_monitor_updates . retain ( |upd| {
3563
- if found_blocked { debug_assert ! ( upd. blocked, "No mons may be unblocked after a blocked one" ) ; }
3564
- if upd. blocked { found_blocked = true ; }
3565
- upd. blocked
3566
- } ) ;
3548
+ for upd in self . context . pending_monitor_updates . iter ( ) {
3549
+ debug_assert ! ( upd. blocked) ;
3550
+ }
3567
3551
3568
3552
// If we're past (or at) the FundingSent stage on an outbound channel, try to
3569
3553
// (re-)broadcast the funding transaction as we may have declined to broadcast it when we
@@ -4430,48 +4414,31 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
4430
4414
/// Returns the next blocked monitor update, if one exists, and a bool which indicates a
4431
4415
/// further blocked monitor update exists after the next.
4432
4416
pub fn unblock_next_blocked_monitor_update ( & mut self ) -> Option < ( ChannelMonitorUpdate , bool ) > {
4433
- for i in 0 ..self . context . pending_monitor_updates . len ( ) {
4434
- if self . context . pending_monitor_updates [ i] . blocked {
4435
- self . context . pending_monitor_updates [ i] . blocked = false ;
4436
- return Some ( ( self . context . pending_monitor_updates [ i] . update . clone ( ) ,
4437
- self . context . pending_monitor_updates . len ( ) > i + 1 ) ) ;
4438
- }
4417
+ for upd in self . context . pending_monitor_updates . iter ( ) {
4418
+ debug_assert ! ( upd. blocked) ;
4439
4419
}
4440
- None
4420
+ if self . context . pending_monitor_updates . is_empty ( ) { return None ; }
4421
+ Some ( ( self . context . pending_monitor_updates . remove ( 0 ) . update ,
4422
+ !self . context . pending_monitor_updates . is_empty ( ) ) )
4441
4423
}
4442
4424
4443
4425
/// Pushes a new monitor update into our monitor update queue, returning it if it should be
4444
4426
/// immediately given to the user for persisting or `None` if it should be held as blocked.
4445
4427
fn push_ret_blockable_mon_update ( & mut self , update : ChannelMonitorUpdate )
4446
4428
-> Option < ChannelMonitorUpdate > {
4447
- let release_monitor = self . context . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
4448
- self . context . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
4449
- update, blocked : !release_monitor,
4450
- } ) ;
4451
- if release_monitor { self . context . pending_monitor_updates . last ( ) . map ( |upd| upd. update . clone ( ) ) } else { None }
4452
- }
4453
-
4454
- pub fn no_monitor_updates_pending ( & self ) -> bool {
4455
- self . context . pending_monitor_updates . is_empty ( )
4456
- }
4457
-
4458
- pub fn complete_all_mon_updates_through ( & mut self , update_id : u64 ) {
4459
- self . context . pending_monitor_updates . retain ( |upd| {
4460
- if upd. update . update_id <= update_id {
4461
- assert ! ( !upd. blocked, "Completed update must have flown" ) ;
4462
- false
4463
- } else { true }
4464
- } ) ;
4465
- }
4466
-
4467
- pub fn complete_one_mon_update ( & mut self , update_id : u64 ) {
4468
- self . context . pending_monitor_updates . retain ( |upd| upd. update . update_id != update_id) ;
4429
+ let release_monitor = self . context . pending_monitor_updates . is_empty ( ) ;
4430
+ if !release_monitor {
4431
+ self . context . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
4432
+ update, blocked : true ,
4433
+ } ) ;
4434
+ None
4435
+ } else {
4436
+ Some ( update)
4437
+ }
4469
4438
}
4470
4439
4471
- /// Returns an iterator over all unblocked monitor updates which have not yet completed.
4472
- pub fn uncompleted_unblocked_mon_updates ( & self ) -> impl Iterator < Item =& ChannelMonitorUpdate > {
4473
- self . context . pending_monitor_updates . iter ( )
4474
- . filter_map ( |upd| if upd. blocked { None } else { Some ( & upd. update ) } )
4440
+ pub fn blocked_monitor_updates_pending ( & self ) -> usize {
4441
+ self . context . pending_monitor_updates . len ( )
4475
4442
}
4476
4443
4477
4444
/// Returns true if the channel is awaiting the persistence of the initial ChannelMonitor.
0 commit comments