@@ -144,6 +144,7 @@ pub(super) enum HTLCForwardInfo {
144144 prev_short_channel_id : u64 ,
145145 prev_htlc_id : u64 ,
146146 prev_funding_outpoint : OutPoint ,
147+ prev_htlc_amount : Option < u64 >
147148 } ,
148149 FailHTLC {
149150 htlc_id : u64 ,
@@ -1454,7 +1455,7 @@ macro_rules! handle_chan_restoration_locked {
14541455 let chanmon_update_is_none = chanmon_update. is_none( ) ;
14551456 let counterparty_node_id = $channel_entry. get( ) . get_counterparty_node_id( ) ;
14561457 let res = loop {
1457- let forwards: Vec <( PendingHTLCInfo , u64 ) > = $pending_forwards; // Force type-checking to resolve
1458+ let forwards: Vec <( PendingHTLCInfo , u64 , Option < u64 > ) > = $pending_forwards; // Force type-checking to resolve
14581459 if !forwards. is_empty( ) {
14591460 htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . unwrap_or( $channel_entry. get( ) . outbound_scid_alias( ) ) ,
14601461 $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , forwards) ) ;
@@ -3108,7 +3109,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31083109 None => Err ( APIError :: APIMisuseError { err : "Payment with that InterceptId not found" . to_string ( ) } ) ,
31093110 Some ( payment) => {
31103111 match payment {
3111- HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint } => {
3112+ HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint, prev_htlc_amount } => {
31123113
31133114 let routing = match forward_info. routing {
31143115 PendingHTLCRouting :: Forward { onion_packet, .. } => {
@@ -3123,7 +3124,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31233124 ..forward_info
31243125 } ;
31253126
3126- let mut per_source_pending_forward = vec ! [ ( prev_short_channel_id, prev_funding_outpoint, vec![ ( pending_htlc_info, prev_htlc_id) ] ) ] ;
3127+ let mut per_source_pending_forward = vec ! [ ( prev_short_channel_id, prev_funding_outpoint, vec![ ( pending_htlc_info, prev_htlc_id, prev_htlc_amount ) ] ) ] ;
31273128
31283129 self . forward_htlcs ( & mut per_source_pending_forward) ;
31293130
@@ -3144,7 +3145,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31443145
31453146 let mut new_events = Vec :: new ( ) ;
31463147 let mut failed_forwards = Vec :: new ( ) ;
3147- let mut phantom_receives: Vec < ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) > = Vec :: new ( ) ;
3148+ let mut phantom_receives: Vec < ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 , Option < u64 > ) > ) > = Vec :: new ( ) ;
31483149 let mut handle_errors = Vec :: new ( ) ;
31493150 {
31503151 let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -3159,7 +3160,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31593160 match forward_info {
31603161 HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
31613162 ref routing, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } ,
3162- prev_funding_outpoint } => {
3163+ prev_funding_outpoint, prev_htlc_amount } => {
31633164 macro_rules! fail_forward {
31643165 ( $msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr) => {
31653166 {
@@ -3199,13 +3200,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31993200 match next_hop {
32003201 onion_utils:: Hop :: Receive ( hop_data) => {
32013202 match self . construct_recv_pending_htlc_info ( hop_data, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value, Some ( phantom_shared_secret) ) {
3202- Ok ( info) => phantom_receives. push ( ( prev_short_channel_id, prev_funding_outpoint, vec ! [ ( info, prev_htlc_id) ] ) ) ,
3203+ Ok ( info) => phantom_receives. push ( ( prev_short_channel_id, prev_funding_outpoint, vec ! [ ( info, prev_htlc_id, prev_htlc_amount ) ] ) ) ,
32033204 Err ( ReceiveError { err_code, err_data, msg } ) => fail_forward ! ( msg, err_code, err_data, Some ( phantom_shared_secret) )
32043205 }
32053206 } ,
32063207 _ => panic ! ( ) ,
32073208 }
3208- } else if fake_scid:: is_valid_intercept ( & self . fake_scid_rand_bytes , short_chan_id) {
3209+ } else if prev_htlc_amount . is_some ( ) && fake_scid:: is_valid_intercept ( & self . fake_scid_rand_bytes , short_chan_id) {
32093210 let intercept_id = InterceptId ( Sha256 :: hash ( & incoming_shared_secret) . into_inner ( ) ) ;
32103211 let mut pending_intercepts = self . pending_intercepted_payments . lock ( ) . unwrap ( ) ;
32113212 match pending_intercepts. entry ( intercept_id) {
@@ -3214,7 +3215,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32143215 new_events. push ( events:: Event :: PaymentIntercepted {
32153216 short_channel_id : short_chan_id,
32163217 payment_hash,
3217- inbound_amount_msats : 0 ,
3218+ inbound_amount_msats : prev_htlc_amount . unwrap ( ) ,
32183219 expected_outbound_amount_msats : amt_to_forward,
32193220 intercept_id
32203221 } ) ;
@@ -3250,7 +3251,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32503251 routing : PendingHTLCRouting :: Forward {
32513252 onion_packet, ..
32523253 } , incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } ,
3253- prev_funding_outpoint } => {
3254+ prev_funding_outpoint, prev_htlc_amount } => {
32543255 log_trace ! ( self . logger, "Adding HTLC from short id {} with payment_hash {} to channel with short id {} after delay" , prev_short_channel_id, log_bytes!( payment_hash. 0 ) , short_chan_id) ;
32553256 let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
32563257 short_channel_id : prev_short_channel_id,
@@ -3370,7 +3371,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33703371 match forward_info {
33713372 HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
33723373 routing, incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
3373- prev_funding_outpoint } => {
3374+ prev_funding_outpoint, prev_htlc_amount } => {
33743375 let ( cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
33753376 PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } => {
33763377 let _legacy_hop_data = Some ( payment_data. clone ( ) ) ;
@@ -5002,27 +5003,27 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50025003 }
50035004
50045005 #[ inline]
5005- fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
5006+ fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 , Option < u64 > ) > ) ] ) {
50065007 for & mut ( prev_short_channel_id, prev_funding_outpoint, ref mut pending_forwards) in per_source_pending_forwards {
50075008 let mut forward_event = None ;
50085009 if !pending_forwards. is_empty ( ) {
50095010 let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
50105011 if channel_state. forward_htlcs . is_empty ( ) {
50115012 forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) )
50125013 }
5013- for ( forward_info, prev_htlc_id) in pending_forwards. drain ( ..) {
5014+ for ( forward_info, prev_htlc_id, prev_htlc_amount ) in pending_forwards. drain ( ..) {
50145015 match channel_state. forward_htlcs . entry ( match forward_info. routing {
50155016 PendingHTLCRouting :: Forward { short_channel_id, .. } => short_channel_id,
50165017 PendingHTLCRouting :: Receive { .. } => 0 ,
50175018 PendingHTLCRouting :: ReceiveKeysend { .. } => 0 ,
50185019 } ) {
50195020 hash_map:: Entry :: Occupied ( mut entry) => {
50205021 entry. get_mut ( ) . push ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_funding_outpoint,
5021- prev_htlc_id, forward_info } ) ;
5022+ prev_htlc_id, prev_htlc_amount , forward_info } ) ;
50225023 } ,
50235024 hash_map:: Entry :: Vacant ( entry) => {
50245025 entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_funding_outpoint,
5025- prev_htlc_id, forward_info } ) ) ;
5026+ prev_htlc_id, prev_htlc_amount , forward_info } ) ) ;
50265027 }
50275028 }
50285029 }
@@ -6640,6 +6641,7 @@ impl_writeable_tlv_based_enum!(HTLCForwardInfo,
66406641 ( 2 , prev_short_channel_id, required) ,
66416642 ( 4 , prev_htlc_id, required) ,
66426643 ( 6 , prev_funding_outpoint, required) ,
6644+ ( 8 , prev_htlc_amount, option)
66436645 } ,
66446646 ( 1 , FailHTLC ) => {
66456647 ( 0 , htlc_id, required) ,
0 commit comments