@@ -366,6 +366,7 @@ pub(super) enum PendingHTLCRouting {
366
366
Receive {
367
367
payment_data : msgs:: FinalOnionHopData ,
368
368
incoming_cltv_expiry : u32 , // Used to track when we should expire pending HTLCs that go unclaimed
369
+ phantom_shared_secret : Option < [ u8 ; 32 ] > ,
369
370
} ,
370
371
ReceiveKeysend {
371
372
payment_preimage : PaymentPreimage ,
@@ -2072,7 +2073,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2072
2073
}
2073
2074
2074
2075
fn construct_recv_pending_htlc_info ( & self , hop_data : msgs:: OnionHopData , shared_secret : [ u8 ; 32 ] ,
2075
- payment_hash : PaymentHash , amt_msat : u64 , cltv_expiry : u32 ) -> Result < PendingHTLCInfo , ReceiveError >
2076
+ payment_hash : PaymentHash , amt_msat : u64 , cltv_expiry : u32 , phantom_shared_secret : Option < [ u8 ; 32 ] > ) -> Result < PendingHTLCInfo , ReceiveError >
2076
2077
{
2077
2078
// final_incorrect_cltv_expiry
2078
2079
if hop_data. outgoing_cltv_value != cltv_expiry {
@@ -2129,6 +2130,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2129
2130
PendingHTLCRouting :: Receive {
2130
2131
payment_data : data,
2131
2132
incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2133
+ phantom_shared_secret,
2132
2134
}
2133
2135
} else if let Some ( payment_preimage) = keysend_preimage {
2134
2136
// We need to check that the sender knows the keysend preimage before processing this
@@ -2232,7 +2234,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2232
2234
let pending_forward_info = match next_hop {
2233
2235
onion_utils:: Hop :: Receive ( next_hop_data) => {
2234
2236
// OUR PAYMENT!
2235
- match self . construct_recv_pending_htlc_info ( next_hop_data, shared_secret, msg. payment_hash , msg. amount_msat , msg. cltv_expiry ) {
2237
+ match self . construct_recv_pending_htlc_info ( next_hop_data, shared_secret, msg. payment_hash , msg. amount_msat , msg. cltv_expiry , None ) {
2236
2238
Ok ( info) => {
2237
2239
// Note that we could obviously respond immediately with an update_fulfill_htlc
2238
2240
// message, however that would leak that we are the recipient of this payment, so
@@ -3061,7 +3063,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3061
3063
} ;
3062
3064
match next_hop {
3063
3065
onion_utils:: Hop :: Receive ( hop_data) => {
3064
- match self . construct_recv_pending_htlc_info ( hop_data, phantom_shared_secret , payment_hash, amt_to_forward, outgoing_cltv_value) {
3066
+ match self . construct_recv_pending_htlc_info ( hop_data, incoming_shared_secret , payment_hash, amt_to_forward, outgoing_cltv_value, Some ( phantom_shared_secret ) ) {
3065
3067
Ok ( info) => phantom_receives. push ( ( prev_short_channel_id, prev_funding_outpoint, vec ! [ ( info, prev_htlc_id) ] ) ) ,
3066
3068
Err ( ReceiveError { err_code, err_data, msg } ) => fail_phantom_forward ! ( msg, err_code, err_data, phantom_shared_secret)
3067
3069
}
@@ -3221,11 +3223,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3221
3223
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3222
3224
routing, incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
3223
3225
prev_funding_outpoint } => {
3224
- let ( cltv_expiry, onion_payload) = match routing {
3225
- PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry } =>
3226
- ( incoming_cltv_expiry, OnionPayload :: Invoice ( payment_data) ) ,
3226
+ let ( cltv_expiry, onion_payload, phantom_shared_secret ) = match routing {
3227
+ PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } =>
3228
+ ( incoming_cltv_expiry, OnionPayload :: Invoice ( payment_data) , phantom_shared_secret ) ,
3227
3229
PendingHTLCRouting :: ReceiveKeysend { payment_preimage, incoming_cltv_expiry } =>
3228
- ( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) ) ,
3230
+ ( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) , None ) ,
3229
3231
_ => {
3230
3232
panic ! ( "short_channel_id == 0 should imply any pending_forward entries are of type Receive" ) ;
3231
3233
}
@@ -3248,13 +3250,20 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3248
3250
htlc_msat_height_data. extend_from_slice(
3249
3251
& byte_utils:: be32_to_array( self . best_block. read( ) . unwrap( ) . height( ) ) ,
3250
3252
) ;
3253
+ let failure_code = 0x4000 | 15 ;
3254
+ let failure_reason = if let Some ( phantom_ss) = phantom_shared_secret {
3255
+ let packet = onion_utils:: build_failure_packet( & phantom_ss, failure_code, & htlc_msat_height_data[ ..] ) . encode( ) ;
3256
+ let error_data = onion_utils:: encrypt_failure_packet( & phantom_ss, & packet) ;
3257
+ HTLCFailReason :: LightningError { err: error_data }
3258
+ } else {
3259
+ HTLCFailReason :: Reason { failure_code, data: htlc_msat_height_data }
3260
+ } ;
3251
3261
failed_forwards. push( ( HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
3252
3262
short_channel_id: $htlc. prev_hop. short_channel_id,
3253
3263
outpoint: prev_funding_outpoint,
3254
3264
htlc_id: $htlc. prev_hop. htlc_id,
3255
3265
incoming_packet_shared_secret: $htlc. prev_hop. incoming_packet_shared_secret,
3256
- } ) , payment_hash,
3257
- HTLCFailReason :: Reason { failure_code: 0x4000 | 15 , data: htlc_msat_height_data }
3266
+ } ) , payment_hash, failure_reason
3258
3267
) ) ;
3259
3268
}
3260
3269
}
@@ -5993,6 +6002,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
5993
6002
} ,
5994
6003
( 1 , Receive ) => {
5995
6004
( 0 , payment_data, required) ,
6005
+ ( 1 , phantom_shared_secret, option) ,
5996
6006
( 2 , incoming_cltv_expiry, required) ,
5997
6007
} ,
5998
6008
( 2 , ReceiveKeysend ) => {
0 commit comments