@@ -3302,11 +3302,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3302
3302
}
3303
3303
log_debug ! ( logger, "Received valid commitment_signed from peer in channel {}, updated HTLC state but awaiting a monitor update resolution to reply." ,
3304
3304
log_bytes!( self . channel_id) ) ;
3305
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
3306
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
3307
- update : monitor_update, blocked : !release_monitor
3308
- } ) ;
3309
- return Ok ( if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None } ) ;
3305
+ return Ok ( self . push_ret_blockable_mon_update ( monitor_update) ) ;
3310
3306
}
3311
3307
3312
3308
let need_commitment_signed = if need_commitment && ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == 0 {
@@ -3323,12 +3319,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3323
3319
3324
3320
log_debug ! ( logger, "Received valid commitment_signed from peer in channel {}, updating HTLC state and responding with{} a revoke_and_ack." ,
3325
3321
log_bytes!( self . channel_id( ) ) , if need_commitment_signed { " our own commitment_signed and" } else { "" } ) ;
3326
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
3327
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
3328
- update : monitor_update, blocked : !release_monitor,
3329
- } ) ;
3330
3322
self . monitor_updating_paused ( true , need_commitment_signed, false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
3331
- return Ok ( if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd . update ) } else { None } ) ;
3323
+ return Ok ( self . push_ret_blockable_mon_update ( monitor_update ) ) ;
3332
3324
}
3333
3325
3334
3326
/// Public version of the below, checking relevant preconditions first.
@@ -3443,12 +3435,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3443
3435
update_add_htlcs. len( ) , update_fulfill_htlcs. len( ) , update_fail_htlcs. len( ) ) ;
3444
3436
3445
3437
self . monitor_updating_paused ( false , true , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
3446
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
3447
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
3448
- update : monitor_update, blocked : !release_monitor,
3449
- } ) ;
3450
- ( if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None } ,
3451
- htlcs_to_fail)
3438
+ ( self . push_ret_blockable_mon_update ( monitor_update) , htlcs_to_fail)
3452
3439
} else {
3453
3440
( None , Vec :: new ( ) )
3454
3441
}
@@ -3656,12 +3643,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3656
3643
self . monitor_pending_failures . append ( & mut revoked_htlcs) ;
3657
3644
self . monitor_pending_finalized_fulfills . append ( & mut finalized_claimed_htlcs) ;
3658
3645
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} but awaiting a monitor update resolution to reply." , log_bytes!( self . channel_id( ) ) ) ;
3659
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
3660
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
3661
- update : monitor_update, blocked : !release_monitor,
3662
- } ) ;
3663
- return Ok ( ( Vec :: new ( ) ,
3664
- if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None } ) ) ;
3646
+ return Ok ( ( Vec :: new ( ) , self . push_ret_blockable_mon_update ( monitor_update) ) ) ;
3665
3647
}
3666
3648
3667
3649
match self . free_holding_cell_htlcs ( logger) {
@@ -3673,12 +3655,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3673
3655
monitor_update. updates . append ( & mut additional_update. updates ) ;
3674
3656
3675
3657
self . monitor_updating_paused ( false , true , false , to_forward_infos, revoked_htlcs, finalized_claimed_htlcs) ;
3676
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
3677
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
3678
- update : monitor_update, blocked : !release_monitor,
3679
- } ) ;
3680
- Ok ( ( htlcs_to_fail,
3681
- if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None } ) )
3658
+ Ok ( ( htlcs_to_fail, self . push_ret_blockable_mon_update ( monitor_update) ) )
3682
3659
} ,
3683
3660
( None , htlcs_to_fail) => {
3684
3661
if require_commitment {
@@ -3692,21 +3669,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3692
3669
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {}. Responding with a commitment update with {} HTLCs failed." ,
3693
3670
log_bytes!( self . channel_id( ) ) , update_fail_htlcs. len( ) + update_fail_malformed_htlcs. len( ) ) ;
3694
3671
self . monitor_updating_paused ( false , true , false , to_forward_infos, revoked_htlcs, finalized_claimed_htlcs) ;
3695
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
3696
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
3697
- update : monitor_update, blocked : !release_monitor,
3698
- } ) ;
3699
- Ok ( ( htlcs_to_fail,
3700
- if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None } ) )
3672
+ Ok ( ( htlcs_to_fail, self . push_ret_blockable_mon_update ( monitor_update) ) )
3701
3673
} else {
3702
3674
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} with no reply necessary." , log_bytes!( self . channel_id( ) ) ) ;
3703
3675
self . monitor_updating_paused ( false , false , false , to_forward_infos, revoked_htlcs, finalized_claimed_htlcs) ;
3704
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
3705
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
3706
- update : monitor_update, blocked : !release_monitor,
3707
- } ) ;
3708
- Ok ( ( htlcs_to_fail,
3709
- if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None } ) )
3676
+ Ok ( ( htlcs_to_fail, self . push_ret_blockable_mon_update ( monitor_update) ) )
3710
3677
}
3711
3678
}
3712
3679
}
@@ -4443,11 +4410,9 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
4443
4410
} ] ,
4444
4411
} ;
4445
4412
self . monitor_updating_paused ( false , false , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
4446
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
4447
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
4448
- update : monitor_update, blocked : !release_monitor,
4449
- } ) ;
4450
- if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None }
4413
+ if self . push_blockable_mon_update ( monitor_update) {
4414
+ self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update )
4415
+ } else { None }
4451
4416
} else { None } ;
4452
4417
let shutdown = if send_shutdown {
4453
4418
Some ( msgs:: Shutdown {
@@ -5032,6 +4997,25 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5032
4997
None
5033
4998
}
5034
4999
5000
+ /// Pushes a new monitor update into our monitor update queue, returning whether it should be
5001
+ /// immediately given to the user for persisting or if it should be held as blocked.
5002
+ fn push_blockable_mon_update ( & mut self , update : ChannelMonitorUpdate ) -> bool {
5003
+ let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
5004
+ self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
5005
+ update, blocked : !release_monitor
5006
+ } ) ;
5007
+ release_monitor
5008
+ }
5009
+
5010
+ /// Pushes a new monitor update into our monitor update queue, returning a reference to it if
5011
+ /// it should be immediately given to the user for persisting or `None` if it should be held as
5012
+ /// blocked.
5013
+ fn push_ret_blockable_mon_update ( & mut self , update : ChannelMonitorUpdate )
5014
+ -> Option < & ChannelMonitorUpdate > {
5015
+ let release_monitor = self . push_blockable_mon_update ( update) ;
5016
+ if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None }
5017
+ }
5018
+
5035
5019
pub fn no_monitor_updates_pending ( & self ) -> bool {
5036
5020
self . pending_monitor_updates . is_empty ( )
5037
5021
}
@@ -6085,12 +6069,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
6085
6069
Some ( _) => {
6086
6070
let monitor_update = self . build_commitment_no_status_check ( logger) ;
6087
6071
self . monitor_updating_paused ( false , true , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
6088
-
6089
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
6090
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
6091
- update : monitor_update, blocked : !release_monitor,
6092
- } ) ;
6093
- Ok ( if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None } )
6072
+ Ok ( self . push_ret_blockable_mon_update ( monitor_update) )
6094
6073
} ,
6095
6074
None => Ok ( None )
6096
6075
}
@@ -6179,11 +6158,9 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
6179
6158
} ] ,
6180
6159
} ;
6181
6160
self . monitor_updating_paused ( false , false , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
6182
- let release_monitor = self . pending_monitor_updates . iter ( ) . all ( |upd| !upd. blocked ) ;
6183
- self . pending_monitor_updates . push ( PendingChannelMonitorUpdate {
6184
- update : monitor_update, blocked : !release_monitor,
6185
- } ) ;
6186
- if release_monitor { self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update ) } else { None }
6161
+ if self . push_blockable_mon_update ( monitor_update) {
6162
+ self . pending_monitor_updates . last ( ) . map ( |upd| & upd. update )
6163
+ } else { None }
6187
6164
} else { None } ;
6188
6165
let shutdown = msgs:: Shutdown {
6189
6166
channel_id : self . channel_id ,
0 commit comments