@@ -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,59 @@ 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
+ let htlc_failure_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
3015
+ short_channel_id : prev_short_channel_id,
3016
+ outpoint : prev_funding_outpoint,
3017
+ htlc_id : prev_htlc_id,
3018
+ incoming_packet_shared_secret : incoming_shared_secret,
3019
+ } ) ;
3014
3020
macro_rules! fail_forward {
3015
3021
( $msg: expr, $err_code: expr, $err_data: expr) => {
3016
3022
{
3017
3023
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,
3024
+ failed_forwards. push( ( htlc_failure_source, payment_hash,
3025
3025
HTLCFailReason :: Reason { failure_code: $err_code, data: $err_data }
3026
3026
) ) ;
3027
3027
continue ;
3028
3028
}
3029
3029
}
3030
3030
}
3031
+ macro_rules! fail_phantom_forward {
3032
+ ( $msg: expr, $err_code: expr, $err_data: expr, $phantom_shared_secret: expr) => {
3033
+ {
3034
+ log_info!( self . logger, "Failed to accept/forward incoming phantom node HTLC: {}" , $msg) ;
3035
+ let packet = onion_utils:: build_failure_packet( & $phantom_shared_secret, $err_code, & $err_data[ ..] ) . encode( ) ;
3036
+ let error_data = onion_utils:: encrypt_failure_packet( & $phantom_shared_secret, & packet) ;
3037
+ failed_forwards. push( ( htlc_failure_source, payment_hash,
3038
+ HTLCFailReason :: LightningError { err: error_data }
3039
+ ) ) ;
3040
+ continue ;
3041
+ }
3042
+ }
3043
+ }
3031
3044
if let PendingHTLCRouting :: Forward { onion_packet, .. } = routing {
3032
3045
let phantom_secret_res = self . keys_manager . get_node_secret ( Recipient :: PhantomNode ) ;
3033
3046
if phantom_secret_res. is_ok ( ) && fake_scid:: is_valid_phantom ( & self . fake_scid_rand_bytes , short_chan_id) {
3034
- let shared_secret = {
3047
+ let phantom_shared_secret = {
3035
3048
let mut arr = [ 0 ; 32 ] ;
3036
3049
arr. copy_from_slice ( & SharedSecret :: new ( & onion_packet. public_key . unwrap ( ) , & phantom_secret_res. unwrap ( ) ) [ ..] ) ;
3037
3050
arr
3038
3051
} ;
3039
- let next_hop = match onion_utils:: decode_next_hop ( shared_secret , & onion_packet. hop_data , onion_packet. hmac , payment_hash) {
3052
+ let next_hop = match onion_utils:: decode_next_hop ( phantom_shared_secret , & onion_packet. hop_data , onion_packet. hmac , payment_hash) {
3040
3053
Ok ( res) => res,
3041
3054
Err ( onion_utils:: OnionDecodeErr :: Malformed { err_msg, err_code } ) => {
3042
- fail_forward ! ( err_msg, err_code, Vec :: new( ) ) ;
3055
+ let sha256_of_onion = Sha256 :: hash ( & onion_packet. hop_data ) . into_inner ( ) ;
3056
+ fail_forward ! ( err_msg, err_code, sha256_of_onion. to_vec( ) ) ;
3043
3057
} ,
3044
3058
Err ( onion_utils:: OnionDecodeErr :: Relay { err_msg, err_code } ) => {
3045
- fail_forward ! ( err_msg, err_code, Vec :: new( ) ) ;
3059
+ fail_phantom_forward ! ( err_msg, err_code, Vec :: new( ) , phantom_shared_secret ) ;
3046
3060
} ,
3047
3061
} ;
3048
3062
match next_hop {
3049
3063
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) {
3064
+ match self . construct_recv_pending_htlc_info ( hop_data, phantom_shared_secret , payment_hash, amt_to_forward, outgoing_cltv_value) {
3051
3065
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)
3066
+ Err ( ReceiveError { err_code, err_data, msg } ) => fail_phantom_forward ! ( msg, err_code, err_data, phantom_shared_secret )
3053
3067
}
3054
3068
} ,
3055
3069
_ => panic ! ( ) ,
0 commit comments