@@ -3952,7 +3952,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
39523952 }
39533953 }
39543954
3955- fn claim_funds_internal ( & self , mut channel_state_lock : MutexGuard < ChannelHolder < Signer > > , source : HTLCSource , payment_preimage : PaymentPreimage , forwarded_htlc_value_msat : Option < u64 > , from_onchain : bool ) {
3955+ fn claim_funds_internal ( & self , mut channel_state_lock : MutexGuard < ChannelHolder < Signer > > , source : HTLCSource , payment_preimage : PaymentPreimage , forwarded_htlc_value_msat : Option < u64 > , from_onchain : bool , next_channel_id : [ u8 ; 32 ] ) {
39563956 match source {
39573957 HTLCSource :: OutboundRoute { session_priv, payment_id, path, .. } => {
39583958 mem:: drop ( channel_state_lock) ;
@@ -4043,12 +4043,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
40434043 } else { None } ;
40444044
40454045 let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
4046+ let prev_channel_id = Some ( prev_outpoint. to_channel_id ( ) ) ;
4047+ let next_channel_id = Some ( next_channel_id) ;
40464048
4047- let source_channel_id = Some ( prev_outpoint. to_channel_id ( ) ) ;
40484049 pending_events. push ( events:: Event :: PaymentForwarded {
4049- source_channel_id,
40504050 fee_earned_msat,
40514051 claim_from_onchain_tx : from_onchain,
4052+ prev_channel_id,
4053+ next_channel_id,
40524054 } ) ;
40534055 }
40544056 }
@@ -4501,7 +4503,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45014503 hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
45024504 }
45034505 } ;
4504- self . claim_funds_internal ( channel_lock, htlc_source, msg. payment_preimage . clone ( ) , Some ( forwarded_htlc_value) , false ) ;
4506+ self . claim_funds_internal ( channel_lock, htlc_source, msg. payment_preimage . clone ( ) , Some ( forwarded_htlc_value) , false , msg . channel_id ) ;
45054507 Ok ( ( ) )
45064508 }
45074509
@@ -4821,48 +4823,50 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48214823 let mut failed_channels = Vec :: new ( ) ;
48224824 let mut pending_monitor_events = self . chain_monitor . release_pending_monitor_events ( ) ;
48234825 let has_pending_monitor_events = !pending_monitor_events. is_empty ( ) ;
4824- for monitor_event in pending_monitor_events. drain ( ..) {
4825- match monitor_event {
4826- MonitorEvent :: HTLCEvent ( htlc_update) => {
4827- if let Some ( preimage) = htlc_update. payment_preimage {
4828- log_trace ! ( self . logger, "Claiming HTLC with preimage {} from our monitor" , log_bytes!( preimage. 0 ) ) ;
4829- self . claim_funds_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , preimage, htlc_update. onchain_value_satoshis . map ( |v| v * 1000 ) , true ) ;
4830- } else {
4831- log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
4832- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } ) ;
4833- }
4834- } ,
4835- MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
4836- MonitorEvent :: UpdateFailed ( funding_outpoint) => {
4837- let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4838- let channel_state = & mut * channel_lock;
4839- let by_id = & mut channel_state. by_id ;
4840- let pending_msg_events = & mut channel_state. pending_msg_events ;
4841- if let hash_map:: Entry :: Occupied ( chan_entry) = by_id. entry ( funding_outpoint. to_channel_id ( ) ) {
4842- let mut chan = remove_channel ! ( self , channel_state, chan_entry) ;
4843- failed_channels. push ( chan. force_shutdown ( false ) ) ;
4844- if let Ok ( update) = self . get_channel_update_for_broadcast ( & chan) {
4845- pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
4846- msg : update
4847- } ) ;
4848- }
4849- let reason = if let MonitorEvent :: UpdateFailed ( _) = monitor_event {
4850- ClosureReason :: ProcessingError { err : "Failed to persist ChannelMonitor update during chain sync" . to_string ( ) }
4826+ for ( funding_txo, mut monitor_events) in pending_monitor_events. drain ( ..) {
4827+ for monitor_event in monitor_events. drain ( ..) {
4828+ match monitor_event {
4829+ MonitorEvent :: HTLCEvent ( htlc_update) => {
4830+ if let Some ( preimage) = htlc_update. payment_preimage {
4831+ log_trace ! ( self . logger, "Claiming HTLC with preimage {} from our monitor" , log_bytes!( preimage. 0 ) ) ;
4832+ self . claim_funds_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , preimage, htlc_update. onchain_value_satoshis . map ( |v| v * 1000 ) , true , funding_txo. to_channel_id ( ) ) ;
48514833 } else {
4852- ClosureReason :: CommitmentTxConfirmed
4853- } ;
4854- self . issue_channel_close_events ( & chan, reason) ;
4855- pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
4856- node_id : chan. get_counterparty_node_id ( ) ,
4857- action : msgs:: ErrorAction :: SendErrorMessage {
4858- msg : msgs:: ErrorMessage { channel_id : chan. channel_id ( ) , data : "Channel force-closed" . to_owned ( ) }
4859- } ,
4860- } ) ;
4861- }
4862- } ,
4863- MonitorEvent :: UpdateCompleted { funding_txo, monitor_update_id } => {
4864- self . channel_monitor_updated ( & funding_txo, monitor_update_id) ;
4865- } ,
4834+ log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
4835+ self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } ) ;
4836+ }
4837+ } ,
4838+ MonitorEvent :: CommitmentTxConfirmed ( funding_txo) |
4839+ MonitorEvent :: UpdateFailed ( funding_txo) => {
4840+ let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4841+ let channel_state = & mut * channel_lock;
4842+ let by_id = & mut channel_state. by_id ;
4843+ let pending_msg_events = & mut channel_state. pending_msg_events ;
4844+ if let hash_map:: Entry :: Occupied ( chan_entry) = by_id. entry ( funding_txo. to_channel_id ( ) ) {
4845+ let mut chan = remove_channel ! ( self , channel_state, chan_entry) ;
4846+ failed_channels. push ( chan. force_shutdown ( false ) ) ;
4847+ if let Ok ( update) = self . get_channel_update_for_broadcast ( & chan) {
4848+ pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
4849+ msg : update
4850+ } ) ;
4851+ }
4852+ let reason = if let MonitorEvent :: UpdateFailed ( _) = monitor_event {
4853+ ClosureReason :: ProcessingError { err : "Failed to persist ChannelMonitor update during chain sync" . to_string ( ) }
4854+ } else {
4855+ ClosureReason :: CommitmentTxConfirmed
4856+ } ;
4857+ self . issue_channel_close_events ( & chan, reason) ;
4858+ pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
4859+ node_id : chan. get_counterparty_node_id ( ) ,
4860+ action : msgs:: ErrorAction :: SendErrorMessage {
4861+ msg : msgs:: ErrorMessage { channel_id : chan. channel_id ( ) , data : "Channel force-closed" . to_owned ( ) }
4862+ } ,
4863+ } ) ;
4864+ }
4865+ } ,
4866+ MonitorEvent :: UpdateCompleted { funding_txo, monitor_update_id } => {
4867+ self . channel_monitor_updated ( & funding_txo, monitor_update_id) ;
4868+ } ,
4869+ }
48664870 }
48674871 }
48684872
0 commit comments