@@ -577,13 +577,13 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, M, T, F, L> = C
577577// | |
578578// | |__`pending_intercepted_htlcs`
579579// |
580- // |__`pending_inbound_payments `
580+ // |__`per_peer_state `
581581// | |
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`
585585// | |
586- // | |__`per_peer_state`
586+ // | |__`pending_outbound_payments` // This field's struct contains a map of pending outbounds
587587// | |
588588// | |__`peer_state`
589589// | |
@@ -1709,7 +1709,7 @@ where
17091709
17101710 // Update the monitor with the shutdown script if necessary.
17111711 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) ;
17131713 let ( result, is_permanent) =
17141714 handle_monitor_update_res ! ( self , update_res, chan_entry. get_mut( ) , RAACommitmentOrder :: CommitmentFirst , chan_entry. key( ) , NO_UPDATE ) ;
17151715 if is_permanent {
@@ -1807,7 +1807,7 @@ where
18071807 // force-closing. The monitor update on the required in-memory copy should broadcast
18081808 // the latest local state, which is the best we can do anyway. Thus, it is safe to
18091809 // 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) ;
18111811 }
18121812 }
18131813
@@ -2336,7 +2336,7 @@ where
23362336 chan)
23372337 } {
23382338 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) ;
23402340 let chan_id = chan. get ( ) . channel_id ( ) ;
23412341 match ( update_err,
23422342 handle_monitor_update_res ! ( self , update_err, chan,
@@ -3284,7 +3284,7 @@ where
32843284 BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) => {
32853285 // The channel has already been closed, so no use bothering to care about the
32863286 // monitor updating completing.
3287- let _ = self . chain_monitor . update_channel ( funding_txo, update) ;
3287+ let _ = self . chain_monitor . update_channel ( funding_txo, & update) ;
32883288 } ,
32893289 }
32903290 }
@@ -3570,9 +3570,12 @@ where
35703570 // Ensure that no peer state channel storage lock is not held when calling this
35713571 // function.
35723572 // 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+ }
35763579 }
35773580
35783581 //TODO: There is a timing attack here where if a node fails an HTLC back to us they can
@@ -3807,7 +3810,7 @@ where
38073810 match chan. get_mut ( ) . get_update_fulfill_htlc_and_commit ( prev_hop. htlc_id , payment_preimage, & self . logger ) {
38083811 Ok ( msgs_monitor_option) => {
38093812 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) {
38113814 ChannelMonitorUpdateStatus :: Completed => { } ,
38123815 e => {
38133816 log_given_level ! ( self . logger, if e == ChannelMonitorUpdateStatus :: PermanentFailure { Level :: Error } else { Level :: Debug } ,
@@ -3844,7 +3847,7 @@ where
38443847 }
38453848 } ,
38463849 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) {
38483851 ChannelMonitorUpdateStatus :: Completed => { } ,
38493852 e => {
38503853 // TODO: This needs to be handled somehow - if we receive a monitor update
@@ -3880,7 +3883,7 @@ where
38803883 } ;
38813884 // We update the ChannelMonitor on the backward link, after
38823885 // 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) ;
38843887 if update_res != ChannelMonitorUpdateStatus :: Completed {
38853888 // TODO: This needs to be handled somehow - if we receive a monitor update
38863889 // with a preimage we *must* somehow manage to propagate it to the upstream
@@ -4449,7 +4452,7 @@ where
44494452
44504453 // Update the monitor with the shutdown script if necessary.
44514454 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) ;
44534456 let ( result, is_permanent) =
44544457 handle_monitor_update_res ! ( self , update_res, chan_entry. get_mut( ) , RAACommitmentOrder :: CommitmentFirst , chan_entry. key( ) , NO_UPDATE ) ;
44554458 if is_permanent {
@@ -4650,13 +4653,13 @@ where
46504653 Err ( ( None , e) ) => try_chan_entry ! ( self , Err ( e) , chan) ,
46514654 Err ( ( Some ( update) , e) ) => {
46524655 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) ;
46544657 try_chan_entry ! ( self , Err ( e) , chan) ;
46554658 unreachable ! ( ) ;
46564659 } ,
46574660 Ok ( res) => res
46584661 } ;
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) ;
46604663 if let Err ( e) = handle_monitor_update_res ! ( self , update_res, chan, RAACommitmentOrder :: RevokeAndACKFirst , true , commitment_signed. is_some( ) ) {
46614664 return Err ( e) ;
46624665 }
@@ -4792,7 +4795,7 @@ where
47924795 let raa_updates = break_chan_entry ! ( self ,
47934796 chan. get_mut( ) . revoke_and_ack( & msg, & self . logger) , chan) ;
47944797 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 ) ;
47964799 if was_paused_for_mon_update {
47974800 assert ! ( update_res != ChannelMonitorUpdateStatus :: Completed ) ;
47984801 assert ! ( raa_updates. commitment_update. is_none( ) ) ;
@@ -5097,7 +5100,7 @@ where
50975100 ) ) ;
50985101 }
50995102 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) {
51015104 ChannelMonitorUpdateStatus :: Completed => {
51025105 pending_msg_events. push ( events:: MessageSendEvent :: UpdateHTLCs {
51035106 node_id : chan. get_counterparty_node_id ( ) ,
@@ -6739,6 +6742,8 @@ where
67396742 }
67406743 }
67416744
6745+ let per_peer_state = self . per_peer_state . write ( ) . unwrap ( ) ;
6746+
67426747 let pending_inbound_payments = self . pending_inbound_payments . lock ( ) . unwrap ( ) ;
67436748 let claimable_payments = self . claimable_payments . lock ( ) . unwrap ( ) ;
67446749 let pending_outbound_payments = self . pending_outbound_payments . pending_outbound_payments . lock ( ) . unwrap ( ) ;
@@ -6754,7 +6759,6 @@ where
67546759 htlc_purposes. push ( purpose) ;
67556760 }
67566761
6757- let per_peer_state = self . per_peer_state . write ( ) . unwrap ( ) ;
67586762 ( per_peer_state. len ( ) as u64 ) . write ( writer) ?;
67596763 for ( peer_pubkey, peer_state_mutex) in per_peer_state. iter ( ) {
67606764 peer_pubkey. write ( writer) ?;
0 commit comments