@@ -131,6 +131,14 @@ pub(super) enum PendingHTLCStatus {
131
131
Fail ( HTLCFailureMsg ) ,
132
132
}
133
133
134
+ pub ( super ) struct PendingInterceptedHTLC {
135
+ forward_info : PendingHTLCInfo ,
136
+ prev_short_channel_id : u64 ,
137
+ prev_htlc_id : u64 ,
138
+ prev_funding_outpoint : OutPoint ,
139
+ prev_htlc_amount : u64
140
+ }
141
+
134
142
pub ( super ) enum HTLCForwardInfo {
135
143
AddHTLC {
136
144
forward_info : PendingHTLCInfo ,
@@ -741,9 +749,9 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
741
749
/// Locked *after* channel_state.
742
750
pending_outbound_payments : Mutex < HashMap < PaymentId , PendingOutboundPayment > > ,
743
751
744
- /// Storage for HTLCForwardInfo 's that have been intercepted and bubbled up to the user.
752
+ /// Storage for PendingInterceptedHTLC 's that have been intercepted and bubbled up to the user.
745
753
/// We hold them here until the user tells us what we should to with them.
746
- pending_intercepted_payments : Mutex < HashMap < InterceptId , HTLCForwardInfo > > ,
754
+ pending_intercepted_payments : Mutex < HashMap < InterceptId , PendingInterceptedHTLC > > ,
747
755
748
756
/// The set of outbound SCID aliases across all our channels, including unconfirmed channels
749
757
/// and some closed channels which reached a usable state prior to being closed. This is used
@@ -3090,19 +3098,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3090
3098
} ;
3091
3099
3092
3100
if let Some ( payment) = pending_intercept {
3093
- if let HTLCForwardInfo :: AddHTLC { forward_info, prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, .. } = payment {
3094
-
3095
- let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
3096
- short_channel_id : prev_short_channel_id,
3097
- outpoint : prev_funding_outpoint,
3098
- htlc_id : prev_htlc_id,
3099
- incoming_packet_shared_secret : forward_info. incoming_shared_secret ,
3100
- phantom_shared_secret : None ,
3101
- } ) ;
3101
+ let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
3102
+ short_channel_id : payment. prev_short_channel_id ,
3103
+ outpoint : payment. prev_funding_outpoint ,
3104
+ htlc_id : payment. prev_htlc_id ,
3105
+ incoming_packet_shared_secret : payment. forward_info . incoming_shared_secret ,
3106
+ phantom_shared_secret : None ,
3107
+ } ) ;
3102
3108
3103
- let failure_reason = HTLCFailReason :: Reason { failure_code : 0x4000 | 10 , data : Vec :: new ( ) } ;
3104
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_source, & forward_info. payment_hash , failure_reason) ;
3105
- }
3109
+ let failure_reason = HTLCFailReason :: Reason { failure_code : 0x4000 | 10 , data : Vec :: new ( ) } ;
3110
+ self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_source, & payment. forward_info . payment_hash , failure_reason) ;
3106
3111
}
3107
3112
}
3108
3113
@@ -3119,30 +3124,22 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3119
3124
match pending_intercept {
3120
3125
None => Err ( APIError :: APIMisuseError { err : "Payment with that InterceptId not found" . to_string ( ) } ) ,
3121
3126
Some ( payment) => {
3122
- match payment {
3123
- HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint, prev_htlc_amount } => {
3124
-
3125
- let routing = match forward_info. routing {
3126
- PendingHTLCRouting :: Forward { onion_packet, .. } => {
3127
- PendingHTLCRouting :: Forward { onion_packet, short_channel_id : scid }
3128
- } ,
3129
- _ => forward_info. routing
3130
- } ;
3131
-
3132
- let pending_htlc_info = PendingHTLCInfo {
3133
- amt_to_forward,
3134
- routing,
3135
- ..forward_info
3136
- } ;
3137
-
3138
- let mut per_source_pending_forward = vec ! [ ( prev_short_channel_id, prev_funding_outpoint, vec![ ( pending_htlc_info, prev_htlc_id, prev_htlc_amount) ] ) ] ;
3127
+ let routing = match payment. forward_info . routing {
3128
+ PendingHTLCRouting :: Forward { onion_packet, .. } => {
3129
+ PendingHTLCRouting :: Forward { onion_packet, short_channel_id : scid }
3130
+ } ,
3131
+ _ => payment. forward_info . routing
3132
+ } ;
3139
3133
3140
- self . forward_htlcs ( & mut per_source_pending_forward) ;
3134
+ let pending_htlc_info = PendingHTLCInfo {
3135
+ amt_to_forward,
3136
+ routing,
3137
+ ..payment. forward_info
3138
+ } ;
3141
3139
3142
- Ok ( ( ) )
3143
- } ,
3144
- _ => Err ( APIError :: APIMisuseError { err : "impossible" . to_string ( ) } )
3145
- }
3140
+ let mut per_source_pending_forward = vec ! [ ( payment. prev_short_channel_id, payment. prev_funding_outpoint, vec![ ( pending_htlc_info, payment. prev_htlc_id, Some ( payment. prev_htlc_amount) ) ] ) ] ;
3141
+ self . forward_htlcs ( & mut per_source_pending_forward) ;
3142
+ Ok ( ( ) )
3146
3143
}
3147
3144
}
3148
3145
}
@@ -3169,9 +3166,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3169
3166
None => {
3170
3167
for forward_info in pending_forwards. drain ( ..) {
3171
3168
match forward_info {
3172
- HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3173
- ref routing, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } ,
3174
- prev_funding_outpoint, prev_htlc_amount } => {
3169
+ HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint, prev_htlc_amount } => {
3175
3170
macro_rules! fail_forward {
3176
3171
( $msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr) => {
3177
3172
{
@@ -3180,21 +3175,21 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3180
3175
short_channel_id: prev_short_channel_id,
3181
3176
outpoint: prev_funding_outpoint,
3182
3177
htlc_id: prev_htlc_id,
3183
- incoming_packet_shared_secret: incoming_shared_secret,
3178
+ incoming_packet_shared_secret: forward_info . incoming_shared_secret,
3184
3179
phantom_shared_secret: $phantom_ss,
3185
3180
} ) ;
3186
- failed_forwards. push( ( htlc_source, payment_hash,
3181
+ failed_forwards. push( ( htlc_source, forward_info . payment_hash,
3187
3182
HTLCFailReason :: Reason { failure_code: $err_code, data: $err_data }
3188
3183
) ) ;
3189
3184
continue ;
3190
3185
}
3191
3186
}
3192
3187
}
3193
- if let PendingHTLCRouting :: Forward { onion_packet, .. } = routing {
3188
+ if let PendingHTLCRouting :: Forward { ref onion_packet, .. } = forward_info . routing {
3194
3189
let phantom_secret_res = self . keys_manager . get_node_secret ( Recipient :: PhantomNode ) ;
3195
3190
if phantom_secret_res. is_ok ( ) && fake_scid:: is_valid_phantom ( & self . fake_scid_rand_bytes , short_chan_id) {
3196
3191
let phantom_shared_secret = SharedSecret :: new ( & onion_packet. public_key . unwrap ( ) , & phantom_secret_res. unwrap ( ) ) . secret_bytes ( ) ;
3197
- let next_hop = match onion_utils:: decode_next_hop ( phantom_shared_secret, & onion_packet. hop_data , onion_packet. hmac , payment_hash) {
3192
+ let next_hop = match onion_utils:: decode_next_hop ( phantom_shared_secret, & onion_packet. hop_data , onion_packet. hmac , forward_info . payment_hash ) {
3198
3193
Ok ( res) => res,
3199
3194
Err ( onion_utils:: OnionDecodeErr :: Malformed { err_msg, err_code } ) => {
3200
3195
let sha256_of_onion = Sha256 :: hash ( & onion_packet. hop_data ) . into_inner ( ) ;
@@ -3210,24 +3205,31 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3210
3205
} ;
3211
3206
match next_hop {
3212
3207
onion_utils:: Hop :: Receive ( hop_data) => {
3213
- match self . construct_recv_pending_htlc_info ( hop_data, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value, Some ( phantom_shared_secret) ) {
3208
+ match self . construct_recv_pending_htlc_info ( hop_data, forward_info . incoming_shared_secret , forward_info . payment_hash , forward_info . amt_to_forward , forward_info . outgoing_cltv_value , Some ( phantom_shared_secret) ) {
3214
3209
Ok ( info) => phantom_receives. push ( ( prev_short_channel_id, prev_funding_outpoint, vec ! [ ( info, prev_htlc_id, prev_htlc_amount) ] ) ) ,
3215
3210
Err ( ReceiveError { err_code, err_data, msg } ) => fail_forward ! ( msg, err_code, err_data, Some ( phantom_shared_secret) )
3216
3211
}
3217
3212
} ,
3218
3213
_ => panic ! ( ) ,
3219
3214
}
3220
3215
} else if prev_htlc_amount. is_some ( ) && fake_scid:: is_valid_intercept ( & self . fake_scid_rand_bytes , short_chan_id) {
3221
- let intercept_id = InterceptId ( Sha256 :: hash ( & incoming_shared_secret) . into_inner ( ) ) ;
3216
+ let intercept_id = InterceptId ( Sha256 :: hash ( & forward_info . incoming_shared_secret ) . into_inner ( ) ) ;
3222
3217
let mut pending_intercepts = self . pending_intercepted_payments . lock ( ) . unwrap ( ) ;
3223
3218
match pending_intercepts. entry ( intercept_id) {
3224
3219
hash_map:: Entry :: Vacant ( entry) => {
3225
- entry. insert ( forward_info) ;
3220
+ let pending_intercepted_payment = PendingInterceptedHTLC {
3221
+ forward_info : forward_info. clone ( ) ,
3222
+ prev_short_channel_id,
3223
+ prev_htlc_id,
3224
+ prev_funding_outpoint,
3225
+ prev_htlc_amount : prev_htlc_amount. unwrap ( )
3226
+ } ;
3227
+ entry. insert ( pending_intercepted_payment) ;
3226
3228
new_events. push ( events:: Event :: PaymentIntercepted {
3227
3229
short_channel_id : short_chan_id,
3228
- payment_hash,
3230
+ payment_hash : forward_info . payment_hash ,
3229
3231
inbound_amount_msats : prev_htlc_amount. unwrap ( ) ,
3230
- expected_outbound_amount_msats : amt_to_forward,
3232
+ expected_outbound_amount_msats : forward_info . amt_to_forward ,
3231
3233
intercept_id
3232
3234
} ) ;
3233
3235
} ,
0 commit comments