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