@@ -144,6 +144,7 @@ pub(super) enum HTLCForwardInfo {
144
144
prev_short_channel_id : u64 ,
145
145
prev_htlc_id : u64 ,
146
146
prev_funding_outpoint : OutPoint ,
147
+ prev_htlc_amount : Option < u64 >
147
148
} ,
148
149
FailHTLC {
149
150
htlc_id : u64 ,
@@ -1365,7 +1366,7 @@ macro_rules! handle_monitor_err {
1365
1366
} else if $resend_commitment { "commitment" }
1366
1367
else if $resend_raa { "RAA" }
1367
1368
else { "nothing" } ,
1368
- ( & $failed_forwards as & Vec <( PendingHTLCInfo , u64 ) >) . len( ) ,
1369
+ ( & $failed_forwards as & Vec <( PendingHTLCInfo , u64 , Option < u64 > ) >) . len( ) ,
1369
1370
( & $failed_fails as & Vec <( HTLCSource , PaymentHash , HTLCFailReason ) >) . len( ) ,
1370
1371
( & $failed_finalized_fulfills as & Vec <HTLCSource >) . len( ) ) ;
1371
1372
if !$resend_commitment {
@@ -1454,7 +1455,7 @@ macro_rules! handle_chan_restoration_locked {
1454
1455
let chanmon_update_is_none = chanmon_update. is_none( ) ;
1455
1456
let counterparty_node_id = $channel_entry. get( ) . get_counterparty_node_id( ) ;
1456
1457
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
1458
1459
if !forwards. is_empty( ) {
1459
1460
htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . unwrap_or( $channel_entry. get( ) . outbound_scid_alias( ) ) ,
1460
1461
$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
3108
3109
None => Err ( APIError :: APIMisuseError { err : "Payment with that InterceptId not found" . to_string ( ) } ) ,
3109
3110
Some ( payment) => {
3110
3111
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 } => {
3112
3113
3113
3114
let routing = match forward_info. routing {
3114
3115
PendingHTLCRouting :: Forward { onion_packet, .. } => {
@@ -3123,7 +3124,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3123
3124
..forward_info
3124
3125
} ;
3125
3126
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 ) ] ) ] ;
3127
3128
3128
3129
self . forward_htlcs ( & mut per_source_pending_forward) ;
3129
3130
@@ -3144,7 +3145,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3144
3145
3145
3146
let mut new_events = Vec :: new ( ) ;
3146
3147
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 ( ) ;
3148
3149
let mut handle_errors = Vec :: new ( ) ;
3149
3150
{
3150
3151
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
3159
3160
match forward_info {
3160
3161
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3161
3162
ref routing, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } ,
3162
- prev_funding_outpoint } => {
3163
+ prev_funding_outpoint, prev_htlc_amount } => {
3163
3164
macro_rules! fail_forward {
3164
3165
( $msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr) => {
3165
3166
{
@@ -3199,13 +3200,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3199
3200
match next_hop {
3200
3201
onion_utils:: Hop :: Receive ( hop_data) => {
3201
3202
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 ) ] ) ) ,
3203
3204
Err ( ReceiveError { err_code, err_data, msg } ) => fail_forward ! ( msg, err_code, err_data, Some ( phantom_shared_secret) )
3204
3205
}
3205
3206
} ,
3206
3207
_ => panic ! ( ) ,
3207
3208
}
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) {
3209
3210
let intercept_id = InterceptId ( Sha256 :: hash ( & incoming_shared_secret) . into_inner ( ) ) ;
3210
3211
let mut pending_intercepts = self . pending_intercepted_payments . lock ( ) . unwrap ( ) ;
3211
3212
match pending_intercepts. entry ( intercept_id) {
@@ -3214,7 +3215,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3214
3215
new_events. push ( events:: Event :: PaymentIntercepted {
3215
3216
short_channel_id : short_chan_id,
3216
3217
payment_hash,
3217
- inbound_amount_msats : 0 ,
3218
+ inbound_amount_msats : prev_htlc_amount . unwrap ( ) ,
3218
3219
expected_outbound_amount_msats : amt_to_forward,
3219
3220
intercept_id
3220
3221
} ) ;
@@ -3250,7 +3251,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3250
3251
routing : PendingHTLCRouting :: Forward {
3251
3252
onion_packet, ..
3252
3253
} , incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } ,
3253
- prev_funding_outpoint } => {
3254
+ prev_funding_outpoint, .. } => {
3254
3255
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) ;
3255
3256
let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
3256
3257
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
3370
3371
match forward_info {
3371
3372
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3372
3373
routing, incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
3373
- prev_funding_outpoint } => {
3374
+ prev_funding_outpoint, .. } => {
3374
3375
let ( cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
3375
3376
PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } => {
3376
3377
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
5002
5003
}
5003
5004
5004
5005
#[ 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 > ) > ) ] ) {
5006
5007
for & mut ( prev_short_channel_id, prev_funding_outpoint, ref mut pending_forwards) in per_source_pending_forwards {
5007
5008
let mut forward_event = None ;
5008
5009
if !pending_forwards. is_empty ( ) {
5009
5010
let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
5010
5011
if channel_state. forward_htlcs . is_empty ( ) {
5011
5012
forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) )
5012
5013
}
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 ( ..) {
5014
5015
match channel_state. forward_htlcs . entry ( match forward_info. routing {
5015
5016
PendingHTLCRouting :: Forward { short_channel_id, .. } => short_channel_id,
5016
5017
PendingHTLCRouting :: Receive { .. } => 0 ,
5017
5018
PendingHTLCRouting :: ReceiveKeysend { .. } => 0 ,
5018
5019
} ) {
5019
5020
hash_map:: Entry :: Occupied ( mut entry) => {
5020
5021
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 } ) ;
5022
5023
} ,
5023
5024
hash_map:: Entry :: Vacant ( entry) => {
5024
5025
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 } ) ) ;
5026
5027
}
5027
5028
}
5028
5029
}
@@ -6640,6 +6641,7 @@ impl_writeable_tlv_based_enum!(HTLCForwardInfo,
6640
6641
( 2 , prev_short_channel_id, required) ,
6641
6642
( 4 , prev_htlc_id, required) ,
6642
6643
( 6 , prev_funding_outpoint, required) ,
6644
+ ( 8 , prev_htlc_amount, option)
6643
6645
} ,
6644
6646
( 1 , FailHTLC ) => {
6645
6647
( 0 , htlc_id, required) ,
0 commit comments