@@ -173,6 +173,7 @@ struct ClaimableHTLC {
173
173
value : u64 ,
174
174
onion_payload : OnionPayload ,
175
175
timer_ticks : u8 ,
176
+ total_msat : u64 ,
176
177
}
177
178
178
179
/// A payment identifier used to uniquely identify a payment to LDK.
@@ -3091,11 +3092,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3091
3092
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3092
3093
routing, incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
3093
3094
prev_funding_outpoint } => {
3094
- let ( cltv_expiry, onion_payload, phantom_shared_secret) = match routing {
3095
+ let ( cltv_expiry, total_msat , onion_payload, phantom_shared_secret) = match routing {
3095
3096
PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } =>
3096
- ( incoming_cltv_expiry, OnionPayload :: Invoice ( payment_data) , phantom_shared_secret) ,
3097
+ ( incoming_cltv_expiry, payment_data . total_msat , OnionPayload :: Invoice ( payment_data) , phantom_shared_secret) ,
3097
3098
PendingHTLCRouting :: ReceiveKeysend { payment_preimage, incoming_cltv_expiry } =>
3098
- ( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) , None ) ,
3099
+ ( incoming_cltv_expiry, amt_to_forward , OnionPayload :: Spontaneous ( payment_preimage) , None ) ,
3099
3100
_ => {
3100
3101
panic ! ( "short_channel_id == 0 should imply any pending_forward entries are of type Receive" ) ;
3101
3102
}
@@ -3110,6 +3111,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3110
3111
} ,
3111
3112
value : amt_to_forward,
3112
3113
timer_ticks : 0 ,
3114
+ total_msat,
3113
3115
cltv_expiry,
3114
3116
onion_payload,
3115
3117
} ;
@@ -3148,23 +3150,21 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3148
3150
for htlc in htlcs. iter( ) {
3149
3151
total_value += htlc. value;
3150
3152
match & htlc. onion_payload {
3151
- OnionPayload :: Invoice ( htlc_payment_data ) => {
3152
- if htlc_payment_data . total_msat != $payment_data_total_msat {
3153
+ OnionPayload :: Invoice ( _ ) => {
3154
+ if htlc . total_msat != claimable_htlc . total_msat {
3153
3155
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})" ,
3154
- log_bytes!( payment_hash. 0 ) , $payment_data_total_msat , htlc_payment_data . total_msat) ;
3156
+ log_bytes!( payment_hash. 0 ) , claimable_htlc . total_msat , htlc . total_msat) ;
3155
3157
total_value = msgs:: MAX_VALUE_MSAT ;
3156
3158
}
3157
3159
if total_value >= msgs:: MAX_VALUE_MSAT { break ; }
3158
3160
} ,
3159
3161
_ => unreachable!( ) ,
3160
3162
}
3161
3163
}
3162
- if total_value >= msgs:: MAX_VALUE_MSAT || total_value > $payment_data_total_msat {
3164
+ if total_value >= msgs:: MAX_VALUE_MSAT || total_value > claimable_htlc . total_msat {
3163
3165
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the total value {} ran over expected value {} (or HTLCs were inconsistent)" ,
3164
- log_bytes!( payment_hash. 0 ) , total_value, $payment_data_total_msat) ;
3165
- fail_htlc!( claimable_htlc) ;
3166
- } else if total_value == $payment_data_total_msat {
3167
- htlcs. push( claimable_htlc) ;
3166
+ log_bytes!( payment_hash. 0 ) , total_value, claimable_htlc. total_msat) ;
3167
+ } else if total_value == claimable_htlc. total_msat {
3168
3168
new_events. push( events:: Event :: PaymentReceived {
3169
3169
payment_hash,
3170
3170
purpose: events:: PaymentPurpose :: InvoicePayment {
@@ -3178,8 +3178,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3178
3178
// Nothing to do - we haven't reached the total
3179
3179
// payment value yet, wait until we receive more
3180
3180
// MPP parts.
3181
- htlcs. push( claimable_htlc) ;
3182
3181
}
3182
+ htlcs. push( claimable_htlc) ;
3183
3183
payment_received_generated
3184
3184
} }
3185
3185
}
@@ -3202,9 +3202,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3202
3202
continue
3203
3203
}
3204
3204
} ;
3205
- let payment_data_total_msat = payment_data. total_msat ;
3206
3205
let payment_secret = payment_data. payment_secret . clone ( ) ;
3207
- check_total_value ! ( payment_data_total_msat , payment_secret, payment_preimage) ;
3206
+ check_total_value ! ( payment_data . total_msat , payment_secret, payment_preimage) ;
3208
3207
} ,
3209
3208
OnionPayload :: Spontaneous ( preimage) => {
3210
3209
match channel_state. claimable_htlcs . entry ( payment_hash) {
@@ -6069,13 +6068,14 @@ impl Writeable for ClaimableHTLC {
6069
6068
OnionPayload :: Invoice ( _) => None ,
6070
6069
OnionPayload :: Spontaneous ( preimage) => Some ( preimage. clone ( ) ) ,
6071
6070
} ;
6072
- write_tlv_fields !
6073
- ( writer,
6074
- {
6075
- ( 0 , self . prev_hop, required) , ( 2 , self . value, required) ,
6076
- ( 4 , payment_data, option) , ( 6 , self . cltv_expiry, required) ,
6077
- ( 8 , keysend_preimage, option) ,
6078
- } ) ;
6071
+ write_tlv_fields ! ( writer, {
6072
+ ( 0 , self . prev_hop, required) ,
6073
+ ( 1 , self . total_msat, required) ,
6074
+ ( 2 , self . value, required) ,
6075
+ ( 4 , payment_data, option) ,
6076
+ ( 6 , self . cltv_expiry, required) ,
6077
+ ( 8 , keysend_preimage, option) ,
6078
+ } ) ;
6079
6079
Ok ( ( ) )
6080
6080
}
6081
6081
}
@@ -6086,32 +6086,41 @@ impl Readable for ClaimableHTLC {
6086
6086
let mut value = 0 ;
6087
6087
let mut payment_data: Option < msgs:: FinalOnionHopData > = None ;
6088
6088
let mut cltv_expiry = 0 ;
6089
+ let mut total_msat = None ;
6089
6090
let mut keysend_preimage: Option < PaymentPreimage > = None ;
6090
- read_tlv_fields !
6091
- ( reader,
6092
- {
6093
- ( 0 , prev_hop, required) , ( 2 , value, required) ,
6094
- ( 4 , payment_data, option) , ( 6 , cltv_expiry, required) ,
6095
- ( 8 , keysend_preimage, option)
6096
- } ) ;
6091
+ read_tlv_fields ! ( reader, {
6092
+ ( 0 , prev_hop, required) ,
6093
+ ( 1 , total_msat, option) ,
6094
+ ( 2 , value, required) ,
6095
+ ( 4 , payment_data, option) ,
6096
+ ( 6 , cltv_expiry, required) ,
6097
+ ( 8 , keysend_preimage, option)
6098
+ } ) ;
6097
6099
let onion_payload = match keysend_preimage {
6098
6100
Some ( p) => {
6099
6101
if payment_data. is_some ( ) {
6100
6102
return Err ( DecodeError :: InvalidValue )
6101
6103
}
6104
+ if total_msat. is_none ( ) {
6105
+ total_msat = Some ( value) ;
6106
+ }
6102
6107
OnionPayload :: Spontaneous ( p)
6103
6108
} ,
6104
6109
None => {
6105
6110
if payment_data. is_none ( ) {
6106
6111
return Err ( DecodeError :: InvalidValue )
6107
6112
}
6113
+ if total_msat. is_none ( ) {
6114
+ total_msat = Some ( payment_data. as_ref ( ) . unwrap ( ) . total_msat ) ;
6115
+ }
6108
6116
OnionPayload :: Invoice ( payment_data. unwrap ( ) )
6109
6117
} ,
6110
6118
} ;
6111
6119
Ok ( Self {
6112
6120
prev_hop : prev_hop. 0 . unwrap ( ) ,
6113
6121
timer_ticks : 0 ,
6114
6122
value,
6123
+ total_msat : total_msat. unwrap ( ) ,
6115
6124
onion_payload,
6116
6125
cltv_expiry,
6117
6126
} )
0 commit comments