@@ -142,6 +142,7 @@ pub(super) struct PendingAddHTLCInfo {
142142 prev_short_channel_id : u64 ,
143143 prev_htlc_id : u64 ,
144144 prev_funding_outpoint : OutPoint ,
145+ prev_user_channel_id : u128 ,
145146}
146147
147148pub ( super ) enum HTLCForwardInfo {
@@ -3025,22 +3026,20 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
30253026
30263027 let mut new_events = Vec :: new ( ) ;
30273028 let mut failed_forwards = Vec :: new ( ) ;
3028- let mut phantom_receives: Vec < ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) > = Vec :: new ( ) ;
3029+ let mut phantom_receives: Vec < ( u64 , OutPoint , u128 , Vec < ( PendingHTLCInfo , u64 ) > ) > = Vec :: new ( ) ;
30293030 let mut handle_errors = Vec :: new ( ) ;
30303031 {
30313032 let mut forward_htlcs = HashMap :: new ( ) ;
30323033 mem:: swap ( & mut forward_htlcs, & mut self . forward_htlcs . lock ( ) . unwrap ( ) ) ;
30333034
30343035 for ( short_chan_id, mut pending_forwards) in forward_htlcs {
3035- let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3036- let channel_state = & mut * channel_state_lock;
30373036 if short_chan_id != 0 {
30383037 macro_rules! forwarding_channel_not_found {
30393038 ( ) => {
30403039 for forward_info in pending_forwards. drain( ..) {
30413040 match forward_info {
30423041 HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3043- prev_short_channel_id, prev_htlc_id, prev_funding_outpoint,
3042+ prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id ,
30443043 forward_info: PendingHTLCInfo {
30453044 routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
30463045 outgoing_cltv_value, incoming_amt_msat: _
@@ -3106,7 +3105,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
31063105 match next_hop {
31073106 onion_utils:: Hop :: Receive ( hop_data) => {
31083107 match self . construct_recv_pending_htlc_info( hop_data, incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value, Some ( phantom_shared_secret) ) {
3109- Ok ( info) => phantom_receives. push( ( prev_short_channel_id, prev_funding_outpoint, vec![ ( info, prev_htlc_id) ] ) ) ,
3108+ Ok ( info) => phantom_receives. push( ( prev_short_channel_id, prev_funding_outpoint, prev_user_channel_id , vec![ ( info, prev_htlc_id) ] ) ) ,
31103109 Err ( ReceiveError { err_code, err_data, msg } ) => failed_payment!( msg, err_code, err_data, Some ( phantom_shared_secret) )
31113110 }
31123111 } ,
@@ -3136,6 +3135,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
31363135 continue ;
31373136 }
31383137 } ;
3138+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3139+ let channel_state = & mut * channel_state_lock;
31393140 match channel_state. by_id . entry ( forward_chan_id) {
31403141 hash_map:: Entry :: Vacant ( _) => {
31413142 forwarding_channel_not_found ! ( ) ;
@@ -3147,7 +3148,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
31473148 for forward_info in pending_forwards. drain ( ..) {
31483149 match forward_info {
31493150 HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3150- prev_short_channel_id, prev_htlc_id, prev_funding_outpoint ,
3151+ prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id : _ ,
31513152 forward_info : PendingHTLCInfo {
31523153 incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
31533154 routing : PendingHTLCRouting :: Forward { onion_packet, .. } , incoming_amt_msat : _,
@@ -3274,7 +3275,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
32743275 for forward_info in pending_forwards. drain ( ..) {
32753276 match forward_info {
32763277 HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3277- prev_short_channel_id, prev_htlc_id, prev_funding_outpoint,
3278+ prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id ,
32783279 forward_info : PendingHTLCInfo {
32793280 routing, incoming_shared_secret, payment_hash, outgoing_amt_msat, ..
32803281 }
@@ -3370,15 +3371,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
33703371 fail_htlc!( claimable_htlc, payment_hash) ;
33713372 } else if total_value == $payment_data. total_msat {
33723373 let prev_channel_id = prev_funding_outpoint. to_channel_id( ) ;
3373- let via_user_channel_id = channel_state. by_id. get( & prev_channel_id) . map( |chan| chan. get_user_id( ) ) ;
33743374 htlcs. push( claimable_htlc) ;
33753375 new_events. push( events:: Event :: PaymentReceived {
33763376 receiver_node_id: Some ( receiver_node_id) ,
33773377 payment_hash,
33783378 purpose: purpose( ) ,
33793379 amount_msat: total_value,
33803380 via_channel_id: Some ( prev_channel_id) ,
3381- via_user_channel_id,
3381+ via_user_channel_id: Some ( prev_user_channel_id ) ,
33823382 } ) ;
33833383 payment_received_generated = true ;
33843384 } else {
@@ -3418,14 +3418,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
34183418 let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
34193419 e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
34203420 let prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ;
3421- let via_user_channel_id = channel_state. by_id . get ( & prev_channel_id) . map ( |chan| chan. get_user_id ( ) ) ;
34223421 new_events. push ( events:: Event :: PaymentReceived {
34233422 receiver_node_id : Some ( receiver_node_id) ,
34243423 payment_hash,
34253424 amount_msat : outgoing_amt_msat,
34263425 purpose,
34273426 via_channel_id : Some ( prev_channel_id) ,
3428- via_user_channel_id,
3427+ via_user_channel_id : Some ( prev_user_channel_id ) ,
34293428 } ) ;
34303429 } ,
34313430 hash_map:: Entry :: Occupied ( _) => {
@@ -4397,13 +4396,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43974396 commitment_update : Option < msgs:: CommitmentUpdate > , order : RAACommitmentOrder ,
43984397 pending_forwards : Vec < ( PendingHTLCInfo , u64 ) > , funding_broadcastable : Option < Transaction > ,
43994398 channel_ready : Option < msgs:: ChannelReady > , announcement_sigs : Option < msgs:: AnnouncementSignatures > )
4400- -> Option < ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) > {
4399+ -> Option < ( u64 , OutPoint , u128 , Vec < ( PendingHTLCInfo , u64 ) > ) > {
44014400 let mut htlc_forwards = None ;
44024401
44034402 let counterparty_node_id = channel. get_counterparty_node_id ( ) ;
44044403 if !pending_forwards. is_empty ( ) {
44054404 htlc_forwards = Some ( ( channel. get_short_channel_id ( ) . unwrap_or ( channel. outbound_scid_alias ( ) ) ,
4406- channel. get_funding_txo ( ) . unwrap ( ) , pending_forwards) ) ;
4405+ channel. get_funding_txo ( ) . unwrap ( ) , channel . get_user_id ( ) , pending_forwards) ) ;
44074406 }
44084407
44094408 if let Some ( msg) = channel_ready {
@@ -5064,8 +5063,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
50645063 }
50655064
50665065 #[ inline]
5067- fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
5068- for & mut ( prev_short_channel_id, prev_funding_outpoint, ref mut pending_forwards) in per_source_pending_forwards {
5066+ fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , u128 , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
5067+ for & mut ( prev_short_channel_id, prev_funding_outpoint, prev_user_channel_id , ref mut pending_forwards) in per_source_pending_forwards {
50695068 let mut forward_event = None ;
50705069 if !pending_forwards. is_empty ( ) {
50715070 let mut forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ;
@@ -5080,11 +5079,11 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
50805079 } ) {
50815080 hash_map:: Entry :: Occupied ( mut entry) => {
50825081 entry. get_mut ( ) . push ( HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
5083- prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, forward_info } ) ) ;
5082+ prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_user_channel_id , forward_info } ) ) ;
50845083 } ,
50855084 hash_map:: Entry :: Vacant ( entry) => {
50865085 entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
5087- prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, forward_info } ) ) ) ;
5086+ prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_user_channel_id , forward_info } ) ) ) ;
50885087 }
50895088 }
50905089 }
@@ -5143,21 +5142,22 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
51435142 raa_updates. finalized_claimed_htlcs ,
51445143 chan. get ( ) . get_short_channel_id ( )
51455144 . unwrap_or ( chan. get ( ) . outbound_scid_alias ( ) ) ,
5146- chan. get ( ) . get_funding_txo ( ) . unwrap ( ) ) )
5145+ chan. get ( ) . get_funding_txo ( ) . unwrap ( ) ,
5146+ chan. get ( ) . get_user_id ( ) ) )
51475147 } ,
51485148 hash_map:: Entry :: Vacant ( _) => break Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
51495149 }
51505150 } ;
51515151 self . fail_holding_cell_htlcs ( htlcs_to_fail, msg. channel_id , counterparty_node_id) ;
51525152 match res {
51535153 Ok ( ( pending_forwards, mut pending_failures, finalized_claim_htlcs,
5154- short_channel_id, channel_outpoint) ) =>
5154+ short_channel_id, channel_outpoint, user_channel_id ) ) =>
51555155 {
51565156 for failure in pending_failures. drain ( ..) {
51575157 let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : channel_outpoint. to_channel_id ( ) } ;
51585158 self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
51595159 }
5160- self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, pending_forwards) ] ) ;
5160+ self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, user_channel_id , pending_forwards) ] ) ;
51615161 self . finalize_claims ( finalized_claim_htlcs) ;
51625162 Ok ( ( ) )
51635163 } ,
@@ -6135,7 +6135,7 @@ where
61356135 }
61366136}
61376137
6138- impl < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
6138+ impl < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
61396139 ChannelMessageHandler for ChannelManager < M , T , K , F , L >
61406140 where M :: Target : chain:: Watch < <K :: Target as KeysInterface >:: Signer > ,
61416141 T :: Target : BroadcasterInterface ,
@@ -6807,6 +6807,7 @@ impl_writeable_tlv_based_enum!(HTLCFailReason,
68076807
68086808impl_writeable_tlv_based ! ( PendingAddHTLCInfo , {
68096809 ( 0 , forward_info, required) ,
6810+ ( 1 , prev_user_channel_id, ( default_value, 0 ) ) ,
68106811 ( 2 , prev_short_channel_id, required) ,
68116812 ( 4 , prev_htlc_id, required) ,
68126813 ( 6 , prev_funding_outpoint, required) ,
0 commit comments