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