@@ -2264,34 +2264,25 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2264
2264
}
2265
2265
2266
2266
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 {
2267
- let release_cs_monitor = self . context . pending_monitor_updates . iter ( ) . all ( |upd| !upd . blocked ) ;
2267
+ let release_cs_monitor = self . context . pending_monitor_updates . is_empty ( ) ;
2268
2268
match self . get_update_fulfill_htlc ( htlc_id, payment_preimage, logger) {
2269
2269
UpdateFulfillFetch :: NewClaim { mut monitor_update, htlc_value_msat, msg } => {
2270
2270
// Even if we aren't supposed to let new monitor updates with commitment state
2271
2271
// updates run, we still need to push the preimage ChannelMonitorUpdateStep no
2272
2272
// matter what. Sadly, to push a new monitor update which flies before others
2273
2273
// already queued, we have to insert it into the pending queue and update the
2274
2274
// update_ids of all the following monitors.
2275
- let unblocked_update_pos = if release_cs_monitor && msg. is_some ( ) {
2275
+ if release_cs_monitor && msg. is_some ( ) {
2276
2276
let mut additional_update = self . build_commitment_no_status_check ( logger) ;
2277
2277
// build_commitment_no_status_check may bump latest_monitor_id but we want them
2278
2278
// to be strictly increasing by one, so decrement it here.
2279
2279
self . context . latest_monitor_update_id = monitor_update. update_id ;
2280
2280
monitor_update. updates . append ( & mut additional_update. updates ) ;
2281
- self . context . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
2282
- update : monitor_update, blocked : false ,
2283
- } ) ;
2284
- self . context . pending_monitor_updates . len ( ) - 1
2285
2281
} else {
2286
- let insert_pos = self . context . pending_monitor_updates . iter ( ) . position ( |upd| upd. blocked )
2287
- . unwrap_or ( self . context . pending_monitor_updates . len ( ) ) ;
2288
- let new_mon_id = self . context . pending_monitor_updates . get ( insert_pos)
2282
+ let new_mon_id = self . context . pending_monitor_updates . get ( 0 )
2289
2283
. map ( |upd| upd. update . update_id ) . unwrap_or ( monitor_update. update_id ) ;
2290
2284
monitor_update. update_id = new_mon_id;
2291
- self . context . pending_monitor_updates . insert ( insert_pos, PendingChannelMonitorUpdate {
2292
- update : monitor_update, blocked : false ,
2293
- } ) ;
2294
- for held_update in self . context . pending_monitor_updates . iter_mut ( ) . skip ( insert_pos + 1 ) {
2285
+ for held_update in self . context . pending_monitor_updates . iter_mut ( ) {
2295
2286
held_update. update . update_id += 1 ;
2296
2287
}
2297
2288
if msg. is_some ( ) {
@@ -2301,14 +2292,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2301
2292
update, blocked : true ,
2302
2293
} ) ;
2303
2294
}
2304
- insert_pos
2305
- } ;
2306
- self . monitor_updating_paused ( false , msg. is_some ( ) , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
2307
- UpdateFulfillCommitFetch :: NewClaim {
2308
- monitor_update : self . context . pending_monitor_updates . get ( unblocked_update_pos)
2309
- . expect ( "We just pushed the monitor update" ) . update . clone ( ) ,
2310
- htlc_value_msat,
2311
2295
}
2296
+
2297
+ self . monitor_updating_paused ( false , msg. is_some ( ) , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
2298
+ UpdateFulfillCommitFetch :: NewClaim { monitor_update, htlc_value_msat, }
2312
2299
} ,
2313
2300
UpdateFulfillFetch :: DuplicateClaim { } => UpdateFulfillCommitFetch :: DuplicateClaim { } ,
2314
2301
}
@@ -3349,8 +3336,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3349
3336
}
3350
3337
3351
3338
match self . free_holding_cell_htlcs ( logger) {
3352
- ( Some ( _) , htlcs_to_fail) => {
3353
- let mut additional_update = self . context . pending_monitor_updates . pop ( ) . unwrap ( ) . update ;
3339
+ ( Some ( mut additional_update) , htlcs_to_fail) => {
3354
3340
// free_holding_cell_htlcs may bump latest_monitor_id multiple times but we want them to be
3355
3341
// strictly increasing by one, so decrement it here.
3356
3342
self . context . latest_monitor_update_id = monitor_update. update_id ;
@@ -3566,12 +3552,9 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3566
3552
{
3567
3553
assert_eq ! ( self . context. channel_state & ChannelState :: MonitorUpdateInProgress as u32 , ChannelState :: MonitorUpdateInProgress as u32 ) ;
3568
3554
self . context . channel_state &= !( ChannelState :: MonitorUpdateInProgress as u32 ) ;
3569
- let mut found_blocked = false ;
3570
- self . context . pending_monitor_updates . retain ( |upd| {
3571
- if found_blocked { debug_assert ! ( upd. blocked, "No mons may be unblocked after a blocked one" ) ; }
3572
- if upd. blocked { found_blocked = true ; }
3573
- upd. blocked
3574
- } ) ;
3555
+ for upd in self . context . pending_monitor_updates . iter ( ) {
3556
+ debug_assert ! ( upd. blocked) ;
3557
+ }
3575
3558
3576
3559
// If we're past (or at) the FundingSent stage on an outbound channel, try to
3577
3560
// (re-)broadcast the funding transaction as we may have declined to broadcast it when we
@@ -4439,48 +4422,31 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
4439
4422
/// Returns the next blocked monitor update, if one exists, and a bool which indicates a
4440
4423
/// further blocked monitor update exists after the next.
4441
4424
pub fn unblock_next_blocked_monitor_update ( & mut self ) -> Option < ( ChannelMonitorUpdate , bool ) > {
4442
- for i in 0 ..self . context . pending_monitor_updates . len ( ) {
4443
- if self . context . pending_monitor_updates [ i] . blocked {
4444
- self . context . pending_monitor_updates [ i] . blocked = false ;
4445
- return Some ( ( self . context . pending_monitor_updates [ i] . update . clone ( ) ,
4446
- self . context . pending_monitor_updates . len ( ) > i + 1 ) ) ;
4447
- }
4425
+ for upd in self . context . pending_monitor_updates . iter ( ) {
4426
+ debug_assert ! ( upd. blocked) ;
4448
4427
}
4449
- None
4428
+ if self . context . pending_monitor_updates . is_empty ( ) { return None ; }
4429
+ Some ( ( self . context . pending_monitor_updates . remove ( 0 ) . update ,
4430
+ !self . context . pending_monitor_updates . is_empty ( ) ) )
4450
4431
}
4451
4432
4452
4433
/// Pushes a new monitor update into our monitor update queue, returning it if it should be
4453
4434
/// immediately given to the user for persisting or `None` if it should be held as blocked.
4454
4435
fn push_ret_blockable_mon_update ( & mut self , update : ChannelMonitorUpdate )
4455
4436
-> Option < ChannelMonitorUpdate > {
4456
- let release_monitor = self . context . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
4457
- self . context . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
4458
- update, blocked : !release_monitor,
4459
- } ) ;
4460
- if release_monitor { self . context . pending_monitor_updates . last ( ) . map ( |upd| upd. update . clone ( ) ) } else { None }
4461
- }
4462
-
4463
- pub fn no_monitor_updates_pending ( & self ) -> bool {
4464
- self . context . pending_monitor_updates . is_empty ( )
4465
- }
4466
-
4467
- pub fn complete_all_mon_updates_through ( & mut self , update_id : u64 ) {
4468
- self . context . pending_monitor_updates . retain ( |upd| {
4469
- if upd. update . update_id <= update_id {
4470
- assert ! ( !upd. blocked, "Completed update must have flown" ) ;
4471
- false
4472
- } else { true }
4473
- } ) ;
4474
- }
4475
-
4476
- pub fn complete_one_mon_update ( & mut self , update_id : u64 ) {
4477
- self . context . pending_monitor_updates . retain ( |upd| upd. update . update_id != update_id) ;
4437
+ let release_monitor = self . context . pending_monitor_updates . is_empty ( ) ;
4438
+ if !release_monitor {
4439
+ self . context . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
4440
+ update, blocked : true ,
4441
+ } ) ;
4442
+ None
4443
+ } else {
4444
+ Some ( update)
4445
+ }
4478
4446
}
4479
4447
4480
- /// Returns an iterator over all unblocked monitor updates which have not yet completed.
4481
- pub fn uncompleted_unblocked_mon_updates ( & self ) -> impl Iterator < Item =& ChannelMonitorUpdate > {
4482
- self . context . pending_monitor_updates . iter ( )
4483
- . filter_map ( |upd| if upd. blocked { None } else { Some ( & upd. update ) } )
4448
+ pub fn blocked_monitor_updates_pending ( & self ) -> usize {
4449
+ self . context . pending_monitor_updates . len ( )
4484
4450
}
4485
4451
4486
4452
/// Returns true if the channel is awaiting the persistence of the initial ChannelMonitor.
0 commit comments