@@ -358,7 +358,7 @@ mod inbound_payment {
358
358
// our payment, which we can use to decode errors or inform the user that the payment was sent.
359
359
360
360
#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
361
- enum PendingHTLCRouting {
361
+ pub ( super ) enum PendingHTLCRouting {
362
362
Forward {
363
363
onion_packet : msgs:: OnionPacket ,
364
364
short_channel_id : u64 , // This should be NonZero<u64> eventually when we bump MSRV
@@ -375,8 +375,8 @@ enum PendingHTLCRouting {
375
375
376
376
#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
377
377
pub ( super ) struct PendingHTLCInfo {
378
- routing : PendingHTLCRouting ,
379
- incoming_shared_secret : [ u8 ; 32 ] ,
378
+ pub ( super ) routing : PendingHTLCRouting ,
379
+ pub ( super ) incoming_shared_secret : [ u8 ; 32 ] ,
380
380
payment_hash : PaymentHash ,
381
381
pub ( super ) amt_to_forward : u64 ,
382
382
pub ( super ) outgoing_cltv_value : u32 ,
@@ -3011,45 +3011,62 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3011
3011
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3012
3012
routing, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } ,
3013
3013
prev_funding_outpoint } => {
3014
+ macro_rules! get_failure_htlc_source {
3015
+ ( ) => {
3016
+ HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
3017
+ short_channel_id: prev_short_channel_id,
3018
+ outpoint: prev_funding_outpoint,
3019
+ htlc_id: prev_htlc_id,
3020
+ incoming_packet_shared_secret: incoming_shared_secret,
3021
+ } )
3022
+ }
3023
+ }
3014
3024
macro_rules! fail_forward {
3015
3025
( $msg: expr, $err_code: expr, $err_data: expr) => {
3016
3026
{
3017
3027
log_info!( self . logger, "Failed to accept/forward incoming HTLC: {}" , $msg) ;
3018
- let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
3019
- short_channel_id: short_chan_id,
3020
- outpoint: prev_funding_outpoint,
3021
- htlc_id: prev_htlc_id,
3022
- incoming_packet_shared_secret: incoming_shared_secret,
3023
- } ) ;
3024
- failed_forwards. push( ( htlc_source, payment_hash,
3028
+ failed_forwards. push( ( get_failure_htlc_source!( ) , payment_hash,
3025
3029
HTLCFailReason :: Reason { failure_code: $err_code, data: $err_data }
3026
3030
) ) ;
3027
3031
continue ;
3028
3032
}
3029
3033
}
3030
3034
}
3035
+ macro_rules! fail_phantom_forward {
3036
+ ( $msg: expr, $err_code: expr, $err_data: expr, $phantom_shared_secret: expr) => {
3037
+ {
3038
+ log_info!( self . logger, "Failed to accept/forward incoming phantom node HTLC: {}" , $msg) ;
3039
+ let packet = onion_utils:: build_failure_packet( & $phantom_shared_secret, $err_code, & $err_data[ ..] ) . encode( ) ;
3040
+ let error_data = onion_utils:: encrypt_failure_packet( & $phantom_shared_secret, & packet) ;
3041
+ failed_forwards. push( ( get_failure_htlc_source!( ) , payment_hash,
3042
+ HTLCFailReason :: LightningError { err: error_data }
3043
+ ) ) ;
3044
+ continue ;
3045
+ }
3046
+ }
3047
+ }
3031
3048
if let PendingHTLCRouting :: Forward { onion_packet, .. } = routing {
3032
3049
let phantom_secret_res = self . keys_manager . get_node_secret ( Recipient :: PhantomNode ) ;
3033
3050
if phantom_secret_res. is_ok ( ) && fake_scid:: is_valid_phantom ( & self . fake_scid_rand_bytes , short_chan_id) {
3034
- let shared_secret = {
3051
+ let phantom_shared_secret = {
3035
3052
let mut arr = [ 0 ; 32 ] ;
3036
3053
arr. copy_from_slice ( & SharedSecret :: new ( & onion_packet. public_key . unwrap ( ) , & phantom_secret_res. unwrap ( ) ) [ ..] ) ;
3037
3054
arr
3038
3055
} ;
3039
- let next_hop = match onion_utils:: decode_next_hop ( shared_secret , & onion_packet. hop_data , onion_packet. hmac , payment_hash) {
3056
+ let next_hop = match onion_utils:: decode_next_hop ( phantom_shared_secret , & onion_packet. hop_data , onion_packet. hmac , payment_hash) {
3040
3057
Ok ( res) => res,
3041
3058
Err ( onion_utils:: OnionDecodeErr :: Malformed { err_msg, err_code } ) => {
3042
- fail_forward ! ( err_msg, err_code, Vec :: new( ) ) ;
3059
+ fail_phantom_forward ! ( err_msg, err_code, Vec :: new( ) , phantom_shared_secret ) ;
3043
3060
} ,
3044
3061
Err ( onion_utils:: OnionDecodeErr :: Relay { err_msg, err_code } ) => {
3045
- fail_forward ! ( err_msg, err_code, Vec :: new( ) ) ;
3062
+ fail_phantom_forward ! ( err_msg, err_code, Vec :: new( ) , phantom_shared_secret ) ;
3046
3063
} ,
3047
3064
} ;
3048
3065
match next_hop {
3049
3066
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) {
3067
+ match self . construct_recv_pending_htlc_info ( hop_data, phantom_shared_secret , payment_hash, amt_to_forward, outgoing_cltv_value) {
3051
3068
Ok ( info) => phantom_receives. push ( ( prev_short_channel_id, prev_funding_outpoint, vec ! [ ( info, prev_htlc_id) ] ) ) ,
3052
- Err ( ReceiveError { err_code, err_data, msg } ) => fail_forward ! ( msg, err_code, err_data)
3069
+ Err ( ReceiveError { err_code, err_data, msg } ) => fail_phantom_forward ! ( msg, err_code, err_data, phantom_shared_secret )
3053
3070
}
3054
3071
} ,
3055
3072
_ => panic ! ( ) ,
0 commit comments