@@ -366,6 +366,7 @@ 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
@@ -3031,12 +3033,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3031
3033
if let PendingHTLCRouting :: Forward { onion_packet, .. } = routing {
3032
3034
let phantom_secret_res = self . keys_manager . get_node_secret ( Recipient :: PhantomNode ) ;
3033
3035
if phantom_secret_res. is_ok ( ) && fake_scid:: is_valid_phantom ( & self . fake_scid_rand_bytes , short_chan_id) {
3034
- let shared_secret = {
3036
+ let phantom_shared_secret = {
3035
3037
let mut arr = [ 0 ; 32 ] ;
3036
3038
arr. copy_from_slice ( & SharedSecret :: new ( & onion_packet. public_key . unwrap ( ) , & phantom_secret_res. unwrap ( ) ) [ ..] ) ;
3037
3039
arr
3038
3040
} ;
3039
- let next_hop = match onion_utils:: decode_next_hop ( shared_secret , & onion_packet. hop_data , onion_packet. hmac , payment_hash) {
3041
+ let next_hop = match onion_utils:: decode_next_hop ( phantom_shared_secret , & onion_packet. hop_data , onion_packet. hmac , payment_hash) {
3040
3042
Ok ( res) => res,
3041
3043
Err ( onion_utils:: OnionDecodeErr :: Malformed { err_msg, err_code } ) => {
3042
3044
fail_forward ! ( err_msg, err_code, Vec :: new( ) ) ;
@@ -3047,7 +3049,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3047
3049
} ;
3048
3050
match next_hop {
3049
3051
onion_utils:: Hop :: Receive ( hop_data) => {
3050
- match self . construct_recv_pending_htlc_info ( hop_data, shared_secret , payment_hash, amt_to_forward, outgoing_cltv_value) {
3052
+ match self . construct_recv_pending_htlc_info ( hop_data, incoming_shared_secret , payment_hash, amt_to_forward, outgoing_cltv_value, Some ( phantom_shared_secret ) ) {
3051
3053
Ok ( info) => phantom_receives. push ( ( prev_short_channel_id, prev_funding_outpoint, vec ! [ ( info, prev_htlc_id) ] ) ) ,
3052
3054
Err ( ReceiveError { err_code, err_data, msg } ) => fail_forward ! ( msg, err_code, err_data)
3053
3055
}
@@ -3207,11 +3209,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3207
3209
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3208
3210
routing, incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
3209
3211
prev_funding_outpoint } => {
3210
- let ( cltv_expiry, onion_payload) = match routing {
3211
- PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry } =>
3212
- ( incoming_cltv_expiry, OnionPayload :: Invoice ( payment_data) ) ,
3212
+ let ( cltv_expiry, onion_payload, phantom_shared_secret ) = match routing {
3213
+ PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } =>
3214
+ ( incoming_cltv_expiry, OnionPayload :: Invoice ( payment_data) , phantom_shared_secret ) ,
3213
3215
PendingHTLCRouting :: ReceiveKeysend { payment_preimage, incoming_cltv_expiry } =>
3214
- ( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) ) ,
3216
+ ( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) , None ) ,
3215
3217
_ => {
3216
3218
panic ! ( "short_channel_id == 0 should imply any pending_forward entries are of type Receive" ) ;
3217
3219
}
@@ -5979,6 +5981,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
5979
5981
} ,
5980
5982
( 1 , Receive ) => {
5981
5983
( 0 , payment_data, required) ,
5984
+ ( 1 , phantom_shared_secret, option) ,
5982
5985
( 2 , incoming_cltv_expiry, required) ,
5983
5986
} ,
5984
5987
( 2 , ReceiveKeysend ) => {
0 commit comments