@@ -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,7 +3026,7 @@ 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 ( ) ; 
@@ -3038,7 +3039,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
30383039							for  forward_info in pending_forwards. drain( ..)  { 
30393040								match  forward_info { 
30403041									HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo  { 
3041- 										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 , 
30423043										forward_info:  PendingHTLCInfo  { 
30433044											routing,  incoming_shared_secret,  payment_hash,  outgoing_amt_msat, 
30443045											outgoing_cltv_value,  incoming_amt_msat:  _
@@ -3104,7 +3105,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
31043105												match  next_hop { 
31053106													onion_utils:: Hop :: Receive ( hop_data)  => { 
31063107														match  self . construct_recv_pending_htlc_info( hop_data,  incoming_shared_secret,  payment_hash,  outgoing_amt_msat,  outgoing_cltv_value,  Some ( phantom_shared_secret) )  { 
3107- 															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) ] ) ) , 
31083109															Err ( ReceiveError  {  err_code,  err_data,  msg } )  => failed_payment!( msg,  err_code,  err_data,  Some ( phantom_shared_secret) ) 
31093110														} 
31103111													} , 
@@ -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								} 
@@ -3369,12 +3370,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
33693370												log_bytes!( payment_hash. 0 ) ,  total_value,  $payment_data. total_msat) ; 
33703371											fail_htlc!( claimable_htlc,  payment_hash) ; 
33713372										}  else if  total_value == $payment_data. total_msat { 
3373+ 											let  prev_channel_id = prev_funding_outpoint. to_channel_id( ) ; 
33723374											htlcs. push( claimable_htlc) ; 
33733375											new_events. push( events:: Event :: PaymentReceived  { 
33743376												receiver_node_id:  Some ( receiver_node_id) , 
33753377												payment_hash, 
33763378												purpose:  purpose( ) , 
33773379												amount_msat:  total_value, 
3380+ 												via_channel_id:  Some ( prev_channel_id) , 
3381+ 												via_user_channel_id:  Some ( prev_user_channel_id) , 
33783382											} ) ; 
33793383											payment_received_generated = true ; 
33803384										}  else { 
@@ -3413,11 +3417,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
34133417													hash_map:: Entry :: Vacant ( e)  => { 
34143418														let  purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ; 
34153419														e. insert ( ( purpose. clone ( ) ,  vec ! [ claimable_htlc] ) ) ; 
3420+ 														let  prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ; 
34163421														new_events. push ( events:: Event :: PaymentReceived  { 
34173422															receiver_node_id :  Some ( receiver_node_id) , 
34183423															payment_hash, 
34193424															amount_msat :  outgoing_amt_msat, 
34203425															purpose, 
3426+ 															via_channel_id :  Some ( prev_channel_id) , 
3427+ 															via_user_channel_id :  Some ( prev_user_channel_id) , 
34213428														} ) ; 
34223429													} , 
34233430													hash_map:: Entry :: Occupied ( _)  => { 
@@ -4389,13 +4396,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43894396		commitment_update :  Option < msgs:: CommitmentUpdate > ,  order :  RAACommitmentOrder , 
43904397		pending_forwards :  Vec < ( PendingHTLCInfo ,  u64 ) > ,  funding_broadcastable :  Option < Transaction > , 
43914398		channel_ready :  Option < msgs:: ChannelReady > ,  announcement_sigs :  Option < msgs:: AnnouncementSignatures > ) 
4392- 	-> Option < ( u64 ,  OutPoint ,  Vec < ( PendingHTLCInfo ,  u64 ) > ) >  { 
4399+ 	-> Option < ( u64 ,  OutPoint ,  u128 ,   Vec < ( PendingHTLCInfo ,  u64 ) > ) >  { 
43934400		let  mut  htlc_forwards = None ; 
43944401
43954402		let  counterparty_node_id = channel. get_counterparty_node_id ( ) ; 
43964403		if  !pending_forwards. is_empty ( )  { 
43974404			htlc_forwards = Some ( ( channel. get_short_channel_id ( ) . unwrap_or ( channel. outbound_scid_alias ( ) ) , 
4398- 				channel. get_funding_txo ( ) . unwrap ( ) ,  pending_forwards) ) ; 
4405+ 				channel. get_funding_txo ( ) . unwrap ( ) ,  channel . get_user_id ( ) ,   pending_forwards) ) ; 
43994406		} 
44004407
44014408		if  let  Some ( msg)  = channel_ready { 
@@ -5056,8 +5063,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
50565063	} 
50575064
50585065	#[ inline]  
5059- 	fn  forward_htlcs ( & self ,  per_source_pending_forwards :  & mut  [ ( u64 ,  OutPoint ,  Vec < ( PendingHTLCInfo ,  u64 ) > ) ] )  { 
5060- 		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 { 
50615068			let  mut  forward_event = None ; 
50625069			if  !pending_forwards. is_empty ( )  { 
50635070				let  mut  forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ; 
@@ -5072,11 +5079,11 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
50725079					} )  { 
50735080						hash_map:: Entry :: Occupied ( mut  entry)  => { 
50745081							entry. get_mut ( ) . push ( HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo  { 
5075- 								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 } ) ) ; 
50765083						} , 
50775084						hash_map:: Entry :: Vacant ( entry)  => { 
50785085							entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo  { 
5079- 								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 } ) ) ) ; 
50805087						} 
50815088					} 
50825089				} 
@@ -5135,21 +5142,22 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
51355142							raa_updates. finalized_claimed_htlcs , 
51365143							chan. get ( ) . get_short_channel_id ( ) 
51375144								. unwrap_or ( chan. get ( ) . outbound_scid_alias ( ) ) , 
5138- 							chan. get ( ) . get_funding_txo ( ) . unwrap ( ) ) ) 
5145+ 							chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , 
5146+ 							chan. get ( ) . get_user_id ( ) ) ) 
51395147				} , 
51405148				hash_map:: Entry :: Vacant ( _)  => break  Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) ,  msg. channel_id ) ) 
51415149			} 
51425150		} ; 
51435151		self . fail_holding_cell_htlcs ( htlcs_to_fail,  msg. channel_id ,  counterparty_node_id) ; 
51445152		match  res { 
51455153			Ok ( ( pending_forwards,  mut  pending_failures,  finalized_claim_htlcs, 
5146- 				short_channel_id,  channel_outpoint) )  =>
5154+ 				short_channel_id,  channel_outpoint,  user_channel_id ) )  =>
51475155			{ 
51485156				for  failure in  pending_failures. drain ( ..)  { 
51495157					let  receiver = HTLCDestination :: NextHopChannel  {  node_id :  Some ( * counterparty_node_id) ,  channel_id :  channel_outpoint. to_channel_id ( )  } ; 
51505158					self . fail_htlc_backwards_internal ( failure. 0 ,  & failure. 1 ,  failure. 2 ,  receiver) ; 
51515159				} 
5152- 				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) ] ) ; 
51535161				self . finalize_claims ( finalized_claim_htlcs) ; 
51545162				Ok ( ( ) ) 
51555163			} , 
@@ -6127,7 +6135,7 @@ where
61276135	} 
61286136} 
61296137
6130- impl < M :  Deref   ,  T :  Deref   ,  K :  Deref   ,  F :  Deref   ,  L :  Deref  > 
6138+ impl < M :  Deref ,  T :  Deref ,  K :  Deref ,  F :  Deref ,  L :  Deref  > 
61316139	ChannelMessageHandler  for  ChannelManager < M ,  T ,  K ,  F ,  L > 
61326140	where  M :: Target :  chain:: Watch < <K :: Target  as  KeysInterface >:: Signer > , 
61336141        T :: Target :  BroadcasterInterface , 
@@ -6799,6 +6807,7 @@ impl_writeable_tlv_based_enum!(HTLCFailReason,
67996807
68006808impl_writeable_tlv_based ! ( PendingAddHTLCInfo ,  { 
68016809	( 0 ,  forward_info,  required) , 
6810+ 	( 1 ,  prev_user_channel_id,  ( default_value,  0 ) ) , 
68026811	( 2 ,  prev_short_channel_id,  required) , 
68036812	( 4 ,  prev_htlc_id,  required) , 
68046813	( 6 ,  prev_funding_outpoint,  required) , 
0 commit comments