@@ -142,6 +142,7 @@ pub(super) struct PendingAddHTLCInfo {
142
142
prev_short_channel_id : u64 ,
143
143
prev_htlc_id : u64 ,
144
144
prev_funding_outpoint : OutPoint ,
145
+ prev_user_channel_id : u128 ,
145
146
}
146
147
147
148
pub ( super ) enum HTLCForwardInfo {
@@ -3025,22 +3026,20 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3025
3026
3026
3027
let mut new_events = Vec :: new ( ) ;
3027
3028
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 ( ) ;
3029
3030
let mut handle_errors = Vec :: new ( ) ;
3030
3031
{
3031
3032
let mut forward_htlcs = HashMap :: new ( ) ;
3032
3033
mem:: swap ( & mut forward_htlcs, & mut self . forward_htlcs . lock ( ) . unwrap ( ) ) ;
3033
3034
3034
3035
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;
3037
3036
if short_chan_id != 0 {
3038
3037
macro_rules! forwarding_channel_not_found {
3039
3038
( ) => {
3040
3039
for forward_info in pending_forwards. drain( ..) {
3041
3040
match forward_info {
3042
3041
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 ,
3044
3043
forward_info: PendingHTLCInfo {
3045
3044
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
3046
3045
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
3106
3105
match next_hop {
3107
3106
onion_utils:: Hop :: Receive ( hop_data) => {
3108
3107
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) ] ) ) ,
3110
3109
Err ( ReceiveError { err_code, err_data, msg } ) => failed_payment!( msg, err_code, err_data, Some ( phantom_shared_secret) )
3111
3110
}
3112
3111
} ,
@@ -3136,6 +3135,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3136
3135
continue ;
3137
3136
}
3138
3137
} ;
3138
+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3139
+ let channel_state = & mut * channel_state_lock;
3139
3140
match channel_state. by_id . entry ( forward_chan_id) {
3140
3141
hash_map:: Entry :: Vacant ( _) => {
3141
3142
forwarding_channel_not_found ! ( ) ;
@@ -3147,7 +3148,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3147
3148
for forward_info in pending_forwards. drain ( ..) {
3148
3149
match forward_info {
3149
3150
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 : _ ,
3151
3152
forward_info : PendingHTLCInfo {
3152
3153
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3153
3154
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
3274
3275
for forward_info in pending_forwards. drain ( ..) {
3275
3276
match forward_info {
3276
3277
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 ,
3278
3279
forward_info : PendingHTLCInfo {
3279
3280
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat, ..
3280
3281
}
@@ -3370,15 +3371,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3370
3371
fail_htlc!( claimable_htlc, payment_hash) ;
3371
3372
} else if total_value == $payment_data. total_msat {
3372
3373
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( ) ) ;
3374
3374
htlcs. push( claimable_htlc) ;
3375
3375
new_events. push( events:: Event :: PaymentReceived {
3376
3376
receiver_node_id: Some ( receiver_node_id) ,
3377
3377
payment_hash,
3378
3378
purpose: purpose( ) ,
3379
3379
amount_msat: total_value,
3380
3380
via_channel_id: Some ( prev_channel_id) ,
3381
- via_user_channel_id,
3381
+ via_user_channel_id: Some ( prev_user_channel_id ) ,
3382
3382
} ) ;
3383
3383
payment_received_generated = true ;
3384
3384
} else {
@@ -3418,14 +3418,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3418
3418
let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3419
3419
e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
3420
3420
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 ( ) ) ;
3422
3421
new_events. push ( events:: Event :: PaymentReceived {
3423
3422
receiver_node_id : Some ( receiver_node_id) ,
3424
3423
payment_hash,
3425
3424
amount_msat : outgoing_amt_msat,
3426
3425
purpose,
3427
3426
via_channel_id : Some ( prev_channel_id) ,
3428
- via_user_channel_id,
3427
+ via_user_channel_id : Some ( prev_user_channel_id ) ,
3429
3428
} ) ;
3430
3429
} ,
3431
3430
hash_map:: Entry :: Occupied ( _) => {
@@ -4397,13 +4396,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4397
4396
commitment_update : Option < msgs:: CommitmentUpdate > , order : RAACommitmentOrder ,
4398
4397
pending_forwards : Vec < ( PendingHTLCInfo , u64 ) > , funding_broadcastable : Option < Transaction > ,
4399
4398
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 ) > ) > {
4401
4400
let mut htlc_forwards = None ;
4402
4401
4403
4402
let counterparty_node_id = channel. get_counterparty_node_id ( ) ;
4404
4403
if !pending_forwards. is_empty ( ) {
4405
4404
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) ) ;
4407
4406
}
4408
4407
4409
4408
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
5064
5063
}
5065
5064
5066
5065
#[ 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 {
5069
5068
let mut forward_event = None ;
5070
5069
if !pending_forwards. is_empty ( ) {
5071
5070
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
5080
5079
} ) {
5081
5080
hash_map:: Entry :: Occupied ( mut entry) => {
5082
5081
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 } ) ) ;
5084
5083
} ,
5085
5084
hash_map:: Entry :: Vacant ( entry) => {
5086
5085
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 } ) ) ) ;
5088
5087
}
5089
5088
}
5090
5089
}
@@ -5143,21 +5142,22 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5143
5142
raa_updates. finalized_claimed_htlcs ,
5144
5143
chan. get ( ) . get_short_channel_id ( )
5145
5144
. 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 ( ) ) )
5147
5147
} ,
5148
5148
hash_map:: Entry :: Vacant ( _) => break Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
5149
5149
}
5150
5150
} ;
5151
5151
self . fail_holding_cell_htlcs ( htlcs_to_fail, msg. channel_id , counterparty_node_id) ;
5152
5152
match res {
5153
5153
Ok ( ( pending_forwards, mut pending_failures, finalized_claim_htlcs,
5154
- short_channel_id, channel_outpoint) ) =>
5154
+ short_channel_id, channel_outpoint, user_channel_id ) ) =>
5155
5155
{
5156
5156
for failure in pending_failures. drain ( ..) {
5157
5157
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : channel_outpoint. to_channel_id ( ) } ;
5158
5158
self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5159
5159
}
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) ] ) ;
5161
5161
self . finalize_claims ( finalized_claim_htlcs) ;
5162
5162
Ok ( ( ) )
5163
5163
} ,
@@ -6135,7 +6135,7 @@ where
6135
6135
}
6136
6136
}
6137
6137
6138
- impl < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
6138
+ impl < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
6139
6139
ChannelMessageHandler for ChannelManager < M , T , K , F , L >
6140
6140
where M :: Target : chain:: Watch < <K :: Target as KeysInterface >:: Signer > ,
6141
6141
T :: Target : BroadcasterInterface ,
@@ -6807,6 +6807,7 @@ impl_writeable_tlv_based_enum!(HTLCFailReason,
6807
6807
6808
6808
impl_writeable_tlv_based ! ( PendingAddHTLCInfo , {
6809
6809
( 0 , forward_info, required) ,
6810
+ ( 1 , prev_user_channel_id, ( default_value, 0 ) ) ,
6810
6811
( 2 , prev_short_channel_id, required) ,
6811
6812
( 4 , prev_htlc_id, required) ,
6812
6813
( 6 , prev_funding_outpoint, required) ,
0 commit comments