@@ -577,13 +577,13 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, M, T, F, L> = C
577
577
// | |
578
578
// | |__`pending_intercepted_htlcs`
579
579
// |
580
- // |__`pending_inbound_payments `
580
+ // |__`per_peer_state `
581
581
// | |
582
- // | |__`claimable_payments `
583
- // | |
584
- // | |__`pending_outbound_payments` // This field's struct contains a map of pending outbounds
582
+ // | |__`pending_inbound_payments `
583
+ // | |
584
+ // | |__`claimable_payments`
585
585
// | |
586
- // | |__`per_peer_state`
586
+ // | |__`pending_outbound_payments` // This field's struct contains a map of pending outbounds
587
587
// | |
588
588
// | |__`peer_state`
589
589
// | |
@@ -1709,7 +1709,7 @@ where
1709
1709
1710
1710
// Update the monitor with the shutdown script if necessary.
1711
1711
if let Some ( monitor_update) = monitor_update {
1712
- let update_res = self . chain_monitor . update_channel ( chan_entry. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) ;
1712
+ let update_res = self . chain_monitor . update_channel ( chan_entry. get ( ) . get_funding_txo ( ) . unwrap ( ) , & monitor_update) ;
1713
1713
let ( result, is_permanent) =
1714
1714
handle_monitor_update_res ! ( self , update_res, chan_entry. get_mut( ) , RAACommitmentOrder :: CommitmentFirst , chan_entry. key( ) , NO_UPDATE ) ;
1715
1715
if is_permanent {
@@ -1807,7 +1807,7 @@ where
1807
1807
// force-closing. The monitor update on the required in-memory copy should broadcast
1808
1808
// the latest local state, which is the best we can do anyway. Thus, it is safe to
1809
1809
// ignore the result here.
1810
- let _ = self . chain_monitor . update_channel ( funding_txo, monitor_update) ;
1810
+ let _ = self . chain_monitor . update_channel ( funding_txo, & monitor_update) ;
1811
1811
}
1812
1812
}
1813
1813
@@ -2336,7 +2336,7 @@ where
2336
2336
chan)
2337
2337
} {
2338
2338
Some ( ( update_add, commitment_signed, monitor_update) ) => {
2339
- let update_err = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) ;
2339
+ let update_err = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , & monitor_update) ;
2340
2340
let chan_id = chan. get ( ) . channel_id ( ) ;
2341
2341
match ( update_err,
2342
2342
handle_monitor_update_res ! ( self , update_err, chan,
@@ -3284,7 +3284,7 @@ where
3284
3284
BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) => {
3285
3285
// The channel has already been closed, so no use bothering to care about the
3286
3286
// monitor updating completing.
3287
- let _ = self . chain_monitor . update_channel ( funding_txo, update) ;
3287
+ let _ = self . chain_monitor . update_channel ( funding_txo, & update) ;
3288
3288
} ,
3289
3289
}
3290
3290
}
@@ -3570,9 +3570,12 @@ where
3570
3570
// Ensure that no peer state channel storage lock is not held when calling this
3571
3571
// function.
3572
3572
// This ensures that future code doesn't introduce a lock_order requirement for
3573
- // `forward_htlcs` to be locked after the `per_peer_state` locks, which calling this
3574
- // function with the `per_peer_state` aquired would.
3575
- assert ! ( self . per_peer_state. try_write( ) . is_ok( ) ) ;
3573
+ // `forward_htlcs` to be locked after the `per_peer_state` peer locks, which calling
3574
+ // this function with any `per_peer_state` peer lock aquired would.
3575
+ let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
3576
+ for ( _, peer) in per_peer_state. iter ( ) {
3577
+ assert ! ( peer. try_lock( ) . is_ok( ) ) ;
3578
+ }
3576
3579
}
3577
3580
3578
3581
//TODO: There is a timing attack here where if a node fails an HTLC back to us they can
@@ -3807,7 +3810,7 @@ where
3807
3810
match chan. get_mut ( ) . get_update_fulfill_htlc_and_commit ( prev_hop. htlc_id , payment_preimage, & self . logger ) {
3808
3811
Ok ( msgs_monitor_option) => {
3809
3812
if let UpdateFulfillCommitFetch :: NewClaim { msgs, htlc_value_msat, monitor_update } = msgs_monitor_option {
3810
- match self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) {
3813
+ match self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , & monitor_update) {
3811
3814
ChannelMonitorUpdateStatus :: Completed => { } ,
3812
3815
e => {
3813
3816
log_given_level ! ( self . logger, if e == ChannelMonitorUpdateStatus :: PermanentFailure { Level :: Error } else { Level :: Debug } ,
@@ -3844,7 +3847,7 @@ where
3844
3847
}
3845
3848
} ,
3846
3849
Err ( ( e, monitor_update) ) => {
3847
- match self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) {
3850
+ match self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , & monitor_update) {
3848
3851
ChannelMonitorUpdateStatus :: Completed => { } ,
3849
3852
e => {
3850
3853
// TODO: This needs to be handled somehow - if we receive a monitor update
@@ -3880,7 +3883,7 @@ where
3880
3883
} ;
3881
3884
// We update the ChannelMonitor on the backward link, after
3882
3885
// receiving an `update_fulfill_htlc` from the forward link.
3883
- let update_res = self . chain_monitor . update_channel ( prev_hop. outpoint , preimage_update) ;
3886
+ let update_res = self . chain_monitor . update_channel ( prev_hop. outpoint , & preimage_update) ;
3884
3887
if update_res != ChannelMonitorUpdateStatus :: Completed {
3885
3888
// TODO: This needs to be handled somehow - if we receive a monitor update
3886
3889
// with a preimage we *must* somehow manage to propagate it to the upstream
@@ -4449,7 +4452,7 @@ where
4449
4452
4450
4453
// Update the monitor with the shutdown script if necessary.
4451
4454
if let Some ( monitor_update) = monitor_update {
4452
- let update_res = self . chain_monitor . update_channel ( chan_entry. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) ;
4455
+ let update_res = self . chain_monitor . update_channel ( chan_entry. get ( ) . get_funding_txo ( ) . unwrap ( ) , & monitor_update) ;
4453
4456
let ( result, is_permanent) =
4454
4457
handle_monitor_update_res ! ( self , update_res, chan_entry. get_mut( ) , RAACommitmentOrder :: CommitmentFirst , chan_entry. key( ) , NO_UPDATE ) ;
4455
4458
if is_permanent {
@@ -4650,13 +4653,13 @@ where
4650
4653
Err ( ( None , e) ) => try_chan_entry ! ( self , Err ( e) , chan) ,
4651
4654
Err ( ( Some ( update) , e) ) => {
4652
4655
assert ! ( chan. get( ) . is_awaiting_monitor_update( ) ) ;
4653
- let _ = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , update) ;
4656
+ let _ = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , & update) ;
4654
4657
try_chan_entry ! ( self , Err ( e) , chan) ;
4655
4658
unreachable ! ( ) ;
4656
4659
} ,
4657
4660
Ok ( res) => res
4658
4661
} ;
4659
- let update_res = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) ;
4662
+ let update_res = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , & monitor_update) ;
4660
4663
if let Err ( e) = handle_monitor_update_res ! ( self , update_res, chan, RAACommitmentOrder :: RevokeAndACKFirst , true , commitment_signed. is_some( ) ) {
4661
4664
return Err ( e) ;
4662
4665
}
@@ -4792,7 +4795,7 @@ where
4792
4795
let raa_updates = break_chan_entry ! ( self ,
4793
4796
chan. get_mut( ) . revoke_and_ack( & msg, & self . logger) , chan) ;
4794
4797
htlcs_to_fail = raa_updates. holding_cell_failed_htlcs ;
4795
- let update_res = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , raa_updates. monitor_update ) ;
4798
+ let update_res = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , & raa_updates. monitor_update ) ;
4796
4799
if was_paused_for_mon_update {
4797
4800
assert ! ( update_res != ChannelMonitorUpdateStatus :: Completed ) ;
4798
4801
assert ! ( raa_updates. commitment_update. is_none( ) ) ;
@@ -5097,7 +5100,7 @@ where
5097
5100
) ) ;
5098
5101
}
5099
5102
if let Some ( ( commitment_update, monitor_update) ) = commitment_opt {
5100
- match self . chain_monitor . update_channel ( chan. get_funding_txo ( ) . unwrap ( ) , monitor_update) {
5103
+ match self . chain_monitor . update_channel ( chan. get_funding_txo ( ) . unwrap ( ) , & monitor_update) {
5101
5104
ChannelMonitorUpdateStatus :: Completed => {
5102
5105
pending_msg_events. push ( events:: MessageSendEvent :: UpdateHTLCs {
5103
5106
node_id : chan. get_counterparty_node_id ( ) ,
@@ -6739,6 +6742,8 @@ where
6739
6742
}
6740
6743
}
6741
6744
6745
+ let per_peer_state = self . per_peer_state . write ( ) . unwrap ( ) ;
6746
+
6742
6747
let pending_inbound_payments = self . pending_inbound_payments . lock ( ) . unwrap ( ) ;
6743
6748
let claimable_payments = self . claimable_payments . lock ( ) . unwrap ( ) ;
6744
6749
let pending_outbound_payments = self . pending_outbound_payments . pending_outbound_payments . lock ( ) . unwrap ( ) ;
@@ -6754,7 +6759,6 @@ where
6754
6759
htlc_purposes. push ( purpose) ;
6755
6760
}
6756
6761
6757
- let per_peer_state = self . per_peer_state . write ( ) . unwrap ( ) ;
6758
6762
( per_peer_state. len ( ) as u64 ) . write ( writer) ?;
6759
6763
for ( peer_pubkey, peer_state_mutex) in per_peer_state. iter ( ) {
6760
6764
peer_pubkey. write ( writer) ?;
0 commit comments