@@ -459,6 +459,7 @@ struct ClaimableHTLC {
459
459
cltv_expiry : u32 ,
460
460
value : u64 ,
461
461
onion_payload : OnionPayload ,
462
+ total_msat : u64 ,
462
463
}
463
464
464
465
/// A payment identifier used to uniquely identify a payment to LDK.
@@ -3168,11 +3169,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3168
3169
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3169
3170
routing, incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
3170
3171
prev_funding_outpoint } => {
3171
- let ( cltv_expiry, onion_payload) = match routing {
3172
+ let ( cltv_expiry, total_msat , onion_payload) = match routing {
3172
3173
PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry } =>
3173
- ( incoming_cltv_expiry, OnionPayload :: Invoice ( payment_data) ) ,
3174
+ ( incoming_cltv_expiry, payment_data . total_msat , OnionPayload :: Invoice ( payment_data) ) ,
3174
3175
PendingHTLCRouting :: ReceiveKeysend { payment_preimage, incoming_cltv_expiry } =>
3175
- ( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) ) ,
3176
+ ( incoming_cltv_expiry, amt_to_forward , OnionPayload :: Spontaneous ( payment_preimage) ) ,
3176
3177
_ => {
3177
3178
panic ! ( "short_channel_id == 0 should imply any pending_forward entries are of type Receive" ) ;
3178
3179
}
@@ -3185,6 +3186,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3185
3186
incoming_packet_shared_secret : incoming_shared_secret,
3186
3187
} ,
3187
3188
value : amt_to_forward,
3189
+ total_msat,
3188
3190
cltv_expiry,
3189
3191
onion_payload,
3190
3192
} ;
@@ -3208,7 +3210,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3208
3210
3209
3211
macro_rules! check_total_value {
3210
3212
( $payment_data_total_msat: expr, $payment_secret: expr, $payment_preimage: expr) => { {
3211
- let mut total_value = 0 ;
3212
3213
let mut payment_received_generated = false ;
3213
3214
let htlcs = channel_state. claimable_htlcs. entry( payment_hash)
3214
3215
. or_insert( Vec :: new( ) ) ;
@@ -3219,28 +3220,28 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3219
3220
continue
3220
3221
}
3221
3222
}
3222
- htlcs . push ( claimable_htlc) ;
3223
+ let mut total_value = claimable_htlc. value ;
3223
3224
for htlc in htlcs. iter( ) {
3224
3225
total_value += htlc. value;
3225
3226
match & htlc. onion_payload {
3226
- OnionPayload :: Invoice ( htlc_payment_data ) => {
3227
- if htlc_payment_data . total_msat != $payment_data_total_msat {
3227
+ OnionPayload :: Invoice ( _ ) => {
3228
+ if htlc . total_msat != claimable_htlc . total_msat {
3228
3229
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})" ,
3229
- log_bytes!( payment_hash. 0 ) , $payment_data_total_msat , htlc_payment_data . total_msat) ;
3230
+ log_bytes!( payment_hash. 0 ) , claimable_htlc . total_msat , htlc . total_msat) ;
3230
3231
total_value = msgs:: MAX_VALUE_MSAT ;
3231
3232
}
3232
3233
if total_value >= msgs:: MAX_VALUE_MSAT { break ; }
3233
3234
} ,
3234
3235
_ => unreachable!( ) ,
3235
3236
}
3236
3237
}
3237
- if total_value >= msgs:: MAX_VALUE_MSAT || total_value > $payment_data_total_msat {
3238
+ if total_value >= msgs:: MAX_VALUE_MSAT || total_value > claimable_htlc . total_msat {
3238
3239
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the total value {} ran over expected value {} (or HTLCs were inconsistent)" ,
3239
- log_bytes!( payment_hash. 0 ) , total_value, $payment_data_total_msat ) ;
3240
+ log_bytes!( payment_hash. 0 ) , total_value, claimable_htlc . total_msat ) ;
3240
3241
for htlc in htlcs. iter( ) {
3241
3242
fail_htlc!( htlc) ;
3242
3243
}
3243
- } else if total_value == $payment_data_total_msat {
3244
+ } else if total_value == claimable_htlc . total_msat {
3244
3245
new_events. push( events:: Event :: PaymentReceived {
3245
3246
payment_hash,
3246
3247
purpose: events:: PaymentPurpose :: InvoicePayment {
@@ -3255,6 +3256,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3255
3256
// payment value yet, wait until we receive more
3256
3257
// MPP parts.
3257
3258
}
3259
+ htlcs. push( claimable_htlc) ;
3258
3260
payment_received_generated
3259
3261
} }
3260
3262
}
@@ -5923,13 +5925,14 @@ impl Writeable for ClaimableHTLC {
5923
5925
OnionPayload :: Invoice ( _) => None ,
5924
5926
OnionPayload :: Spontaneous ( preimage) => Some ( preimage. clone ( ) ) ,
5925
5927
} ;
5926
- write_tlv_fields !
5927
- ( writer,
5928
- {
5929
- ( 0 , self . prev_hop, required) , ( 2 , self . value, required) ,
5930
- ( 4 , payment_data, option) , ( 6 , self . cltv_expiry, required) ,
5931
- ( 8 , keysend_preimage, option) ,
5932
- } ) ;
5928
+ write_tlv_fields ! ( writer, {
5929
+ ( 0 , self . prev_hop, required) ,
5930
+ ( 1 , self . total_msat, required) ,
5931
+ ( 2 , self . value, required) ,
5932
+ ( 4 , payment_data, option) ,
5933
+ ( 6 , self . cltv_expiry, required) ,
5934
+ ( 8 , keysend_preimage, option) ,
5935
+ } ) ;
5933
5936
Ok ( ( ) )
5934
5937
}
5935
5938
}
@@ -5940,31 +5943,40 @@ impl Readable for ClaimableHTLC {
5940
5943
let mut value = 0 ;
5941
5944
let mut payment_data: Option < msgs:: FinalOnionHopData > = None ;
5942
5945
let mut cltv_expiry = 0 ;
5946
+ let mut total_msat = None ;
5943
5947
let mut keysend_preimage: Option < PaymentPreimage > = None ;
5944
- read_tlv_fields !
5945
- ( reader,
5946
- {
5947
- ( 0 , prev_hop, required) , ( 2 , value, required) ,
5948
- ( 4 , payment_data, option) , ( 6 , cltv_expiry, required) ,
5949
- ( 8 , keysend_preimage, option)
5950
- } ) ;
5948
+ read_tlv_fields ! ( reader, {
5949
+ ( 0 , prev_hop, required) ,
5950
+ ( 1 , total_msat, option) ,
5951
+ ( 2 , value, required) ,
5952
+ ( 4 , payment_data, option) ,
5953
+ ( 6 , cltv_expiry, required) ,
5954
+ ( 8 , keysend_preimage, option)
5955
+ } ) ;
5951
5956
let onion_payload = match keysend_preimage {
5952
5957
Some ( p) => {
5953
5958
if payment_data. is_some ( ) {
5954
5959
return Err ( DecodeError :: InvalidValue )
5955
5960
}
5961
+ if total_msat. is_none ( ) {
5962
+ total_msat = Some ( value) ;
5963
+ }
5956
5964
OnionPayload :: Spontaneous ( p)
5957
5965
} ,
5958
5966
None => {
5959
5967
if payment_data. is_none ( ) {
5960
5968
return Err ( DecodeError :: InvalidValue )
5961
5969
}
5970
+ if total_msat. is_none ( ) {
5971
+ total_msat = Some ( payment_data. as_ref ( ) . unwrap ( ) . total_msat ) ;
5972
+ }
5962
5973
OnionPayload :: Invoice ( payment_data. unwrap ( ) )
5963
5974
} ,
5964
5975
} ;
5965
5976
Ok ( Self {
5966
5977
prev_hop : prev_hop. 0 . unwrap ( ) ,
5967
5978
value,
5979
+ total_msat : total_msat. unwrap ( ) ,
5968
5980
onion_payload,
5969
5981
cltv_expiry,
5970
5982
} )
0 commit comments