@@ -116,6 +116,7 @@ pub(super) struct PendingHTLCInfo {
116116 payment_hash : PaymentHash ,
117117 pub ( super ) amt_to_forward : u64 ,
118118 pub ( super ) outgoing_cltv_value : u32 ,
119+ pub ( super ) amt_incoming : Option < u64 >
119120}
120121
121122#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
@@ -136,7 +137,6 @@ pub(super) struct PendingInterceptedHTLC {
136137 prev_short_channel_id : u64 ,
137138 prev_htlc_id : u64 ,
138139 prev_funding_outpoint : OutPoint ,
139- prev_htlc_amount : u64
140140}
141141
142142pub ( super ) enum HTLCForwardInfo {
@@ -152,7 +152,6 @@ pub(super) enum HTLCForwardInfo {
152152 prev_short_channel_id : u64 ,
153153 prev_htlc_id : u64 ,
154154 prev_funding_outpoint : OutPoint ,
155- prev_htlc_amount : Option < u64 >
156155 } ,
157156 FailHTLC {
158157 htlc_id : u64 ,
@@ -1374,7 +1373,7 @@ macro_rules! handle_monitor_err {
13741373 } else if $resend_commitment { "commitment" }
13751374 else if $resend_raa { "RAA" }
13761375 else { "nothing" } ,
1377- ( & $failed_forwards as & Vec <( PendingHTLCInfo , u64 , Option < u64 > ) >) . len( ) ,
1376+ ( & $failed_forwards as & Vec <( PendingHTLCInfo , u64 ) >) . len( ) ,
13781377 ( & $failed_fails as & Vec <( HTLCSource , PaymentHash , HTLCFailReason ) >) . len( ) ,
13791378 ( & $failed_finalized_fulfills as & Vec <HTLCSource >) . len( ) ) ;
13801379 if !$resend_commitment {
@@ -1463,7 +1462,7 @@ macro_rules! handle_chan_restoration_locked {
14631462 let chanmon_update_is_none = chanmon_update. is_none( ) ;
14641463 let counterparty_node_id = $channel_entry. get( ) . get_counterparty_node_id( ) ;
14651464 let res = loop {
1466- let forwards: Vec <( PendingHTLCInfo , u64 , Option < u64 > ) > = $pending_forwards; // Force type-checking to resolve
1465+ let forwards: Vec <( PendingHTLCInfo , u64 ) > = $pending_forwards; // Force type-checking to resolve
14671466 if !forwards. is_empty( ) {
14681467 htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . unwrap_or( $channel_entry. get( ) . outbound_scid_alias( ) ) ,
14691468 $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , forwards) ) ;
@@ -2145,7 +2144,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21452144 routing,
21462145 payment_hash,
21472146 incoming_shared_secret : shared_secret,
2148- amt_to_forward : amt_msat,
2147+ amt_to_forward : 0 ,
2148+ amt_incoming : Some ( amt_msat) ,
21492149 outgoing_cltv_value : hop_data. outgoing_cltv_value ,
21502150 } )
21512151 }
@@ -2248,6 +2248,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22482248 incoming_shared_secret : shared_secret,
22492249 amt_to_forward : next_hop_data. amt_to_forward ,
22502250 outgoing_cltv_value : next_hop_data. outgoing_cltv_value ,
2251+ amt_incoming : Some ( msg. amount_msat )
22512252 } )
22522253 }
22532254 } ;
@@ -3137,7 +3138,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31373138 ..payment. forward_info
31383139 } ;
31393140
3140- let mut per_source_pending_forward = vec ! [ ( payment. prev_short_channel_id, payment. prev_funding_outpoint, vec![ ( pending_htlc_info, payment. prev_htlc_id, Some ( payment . prev_htlc_amount ) ) ] ) ] ;
3141+ let mut per_source_pending_forward = vec ! [ ( payment. prev_short_channel_id, payment. prev_funding_outpoint, vec![ ( pending_htlc_info, payment. prev_htlc_id) ] ) ] ;
31413142 self . forward_htlcs ( & mut per_source_pending_forward) ;
31423143 Ok ( ( ) )
31433144 }
@@ -3153,7 +3154,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31533154
31543155 let mut new_events = Vec :: new ( ) ;
31553156 let mut failed_forwards = Vec :: new ( ) ;
3156- let mut phantom_receives: Vec < ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 , Option < u64 > ) > ) > = Vec :: new ( ) ;
3157+ let mut phantom_receives: Vec < ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) > = Vec :: new ( ) ;
31573158 let mut handle_errors = Vec :: new ( ) ;
31583159 {
31593160 let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -3166,7 +3167,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31663167 None => {
31673168 for forward_info in pending_forwards. drain ( ..) {
31683169 match forward_info {
3169- HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint, prev_htlc_amount } => {
3170+ HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint } => {
31703171 macro_rules! fail_forward {
31713172 ( $msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr) => {
31723173 {
@@ -3206,13 +3207,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32063207 match next_hop {
32073208 onion_utils:: Hop :: Receive ( hop_data) => {
32083209 match self . construct_recv_pending_htlc_info ( hop_data, forward_info. incoming_shared_secret , forward_info. payment_hash , forward_info. amt_to_forward , forward_info. outgoing_cltv_value , Some ( phantom_shared_secret) ) {
3209- Ok ( info) => phantom_receives. push ( ( prev_short_channel_id, prev_funding_outpoint, vec ! [ ( info, prev_htlc_id, prev_htlc_amount ) ] ) ) ,
3210+ Ok ( info) => phantom_receives. push ( ( prev_short_channel_id, prev_funding_outpoint, vec ! [ ( info, prev_htlc_id) ] ) ) ,
32103211 Err ( ReceiveError { err_code, err_data, msg } ) => fail_forward ! ( msg, err_code, err_data, Some ( phantom_shared_secret) )
32113212 }
32123213 } ,
32133214 _ => panic ! ( ) ,
32143215 }
3215- } else if prev_htlc_amount . is_some ( ) && fake_scid:: is_valid_intercept ( & self . fake_scid_rand_bytes , short_chan_id) {
3216+ } else if forward_info . amt_incoming . is_some ( ) && fake_scid:: is_valid_intercept ( & self . fake_scid_rand_bytes , short_chan_id) {
32163217 let intercept_id = InterceptId ( Sha256 :: hash ( & forward_info. incoming_shared_secret ) . into_inner ( ) ) ;
32173218 let mut pending_intercepts = self . pending_intercepted_payments . lock ( ) . unwrap ( ) ;
32183219 match pending_intercepts. entry ( intercept_id) {
@@ -3222,13 +3223,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32223223 prev_short_channel_id,
32233224 prev_htlc_id,
32243225 prev_funding_outpoint,
3225- prev_htlc_amount : prev_htlc_amount. unwrap ( )
32263226 } ;
32273227 entry. insert ( pending_intercepted_payment) ;
32283228 new_events. push ( events:: Event :: PaymentIntercepted {
32293229 short_channel_id : short_chan_id,
32303230 payment_hash : forward_info. payment_hash ,
3231- inbound_amount_msats : prev_htlc_amount . unwrap ( ) ,
3231+ inbound_amount_msats : forward_info . amt_incoming . unwrap ( ) ,
32323232 expected_outbound_amount_msats : forward_info. amt_to_forward ,
32333233 intercept_id
32343234 } ) ;
@@ -3263,7 +3263,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32633263 HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
32643264 routing : PendingHTLCRouting :: Forward {
32653265 onion_packet, ..
3266- } , incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } ,
3266+ } , incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value, .. } ,
32673267 prev_funding_outpoint, .. } => {
32683268 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) ;
32693269 let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
@@ -5016,27 +5016,27 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50165016 }
50175017
50185018 #[ inline]
5019- fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 , Option < u64 > ) > ) ] ) {
5019+ fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
50205020 for & mut ( prev_short_channel_id, prev_funding_outpoint, ref mut pending_forwards) in per_source_pending_forwards {
50215021 let mut forward_event = None ;
50225022 if !pending_forwards. is_empty ( ) {
50235023 let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
50245024 if channel_state. forward_htlcs . is_empty ( ) {
50255025 forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) )
50265026 }
5027- for ( forward_info, prev_htlc_id, prev_htlc_amount ) in pending_forwards. drain ( ..) {
5027+ for ( forward_info, prev_htlc_id) in pending_forwards. drain ( ..) {
50285028 match channel_state. forward_htlcs . entry ( match forward_info. routing {
50295029 PendingHTLCRouting :: Forward { short_channel_id, .. } => short_channel_id,
50305030 PendingHTLCRouting :: Receive { .. } => 0 ,
50315031 PendingHTLCRouting :: ReceiveKeysend { .. } => 0 ,
50325032 } ) {
50335033 hash_map:: Entry :: Occupied ( mut entry) => {
50345034 entry. get_mut ( ) . push ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_funding_outpoint,
5035- prev_htlc_id, prev_htlc_amount , forward_info } ) ;
5035+ prev_htlc_id, forward_info } ) ;
50365036 } ,
50375037 hash_map:: Entry :: Vacant ( entry) => {
50385038 entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_funding_outpoint,
5039- prev_htlc_id, prev_htlc_amount , forward_info } ) ) ;
5039+ prev_htlc_id, forward_info } ) ) ;
50405040 }
50415041 }
50425042 }
@@ -6426,7 +6426,8 @@ impl_writeable_tlv_based!(PendingHTLCInfo, {
64266426 ( 2 , incoming_shared_secret, required) ,
64276427 ( 4 , payment_hash, required) ,
64286428 ( 6 , amt_to_forward, required) ,
6429- ( 8 , outgoing_cltv_value, required)
6429+ ( 8 , outgoing_cltv_value, required) ,
6430+ ( 9 , amt_incoming, option) ,
64306431} ) ;
64316432
64326433
@@ -6654,7 +6655,6 @@ impl_writeable_tlv_based_enum!(HTLCForwardInfo,
66546655 ( 2 , prev_short_channel_id, required) ,
66556656 ( 4 , prev_htlc_id, required) ,
66566657 ( 6 , prev_funding_outpoint, required) ,
6657- ( 8 , prev_htlc_amount, option)
66586658 } ,
66596659 ( 1 , FailHTLC ) => {
66606660 ( 0 , htlc_id, required) ,
0 commit comments