@@ -162,7 +162,11 @@ enum OnionPayload {
162
162
/// Contains a total_msat (which may differ from value if this is a Multi-Path Payment) and a
163
163
/// payment_secret which prevents path-probing attacks and can associate different HTLCs which
164
164
/// are part of the same payment.
165
- Invoice ( msgs:: FinalOnionHopData ) ,
165
+ Invoice {
166
+ /// This is only here for backwards-compatibility in serialization, in the future it can be
167
+ /// removed, breaking clients running 0.0.106 and earlier.
168
+ _legacy_hop_data : msgs:: FinalOnionHopData ,
169
+ } ,
166
170
/// Contains the payer-provided preimage.
167
171
Spontaneous ( PaymentPreimage ) ,
168
172
}
@@ -3100,11 +3104,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3100
3104
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3101
3105
routing, incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
3102
3106
prev_funding_outpoint } => {
3103
- let ( cltv_expiry, total_msat, onion_payload, phantom_shared_secret) = match routing {
3104
- PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } =>
3105
- ( incoming_cltv_expiry, payment_data. total_msat , OnionPayload :: Invoice ( payment_data) , phantom_shared_secret) ,
3107
+ let ( cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
3108
+ PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } => {
3109
+ let _legacy_hop_data = payment_data. clone ( ) ;
3110
+ ( incoming_cltv_expiry, OnionPayload :: Invoice { _legacy_hop_data } , Some ( payment_data) , phantom_shared_secret)
3111
+ } ,
3106
3112
PendingHTLCRouting :: ReceiveKeysend { payment_preimage, incoming_cltv_expiry } =>
3107
- ( incoming_cltv_expiry, amt_to_forward , OnionPayload :: Spontaneous ( payment_preimage) , None ) ,
3113
+ ( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) , None , None ) ,
3108
3114
_ => {
3109
3115
panic ! ( "short_channel_id == 0 should imply any pending_forward entries are of type Receive" ) ;
3110
3116
}
@@ -3119,7 +3125,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3119
3125
} ,
3120
3126
value : amt_to_forward,
3121
3127
timer_ticks : 0 ,
3122
- total_msat,
3128
+ total_msat : if let Some ( data ) = & payment_data { data . total_msat } else { amt_to_forward } ,
3123
3129
cltv_expiry,
3124
3130
onion_payload,
3125
3131
} ;
@@ -3143,7 +3149,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3143
3149
}
3144
3150
3145
3151
macro_rules! check_total_value {
3146
- ( $payment_data_total_msat : expr , $payment_secret : expr, $payment_preimage: expr) => { {
3152
+ ( $payment_data : expr, $payment_preimage: expr) => { {
3147
3153
let mut payment_received_generated = false ;
3148
3154
let htlcs = channel_state. claimable_htlcs. entry( payment_hash)
3149
3155
. or_insert( Vec :: new( ) ) ;
@@ -3159,27 +3165,27 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3159
3165
total_value += htlc. value;
3160
3166
match & htlc. onion_payload {
3161
3167
OnionPayload :: Invoice { .. } => {
3162
- if htlc. total_msat != $payment_data_total_msat {
3168
+ if htlc. total_msat != $payment_data . total_msat {
3163
3169
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})" ,
3164
- log_bytes!( payment_hash. 0 ) , $payment_data_total_msat , htlc. total_msat) ;
3170
+ log_bytes!( payment_hash. 0 ) , $payment_data . total_msat , htlc. total_msat) ;
3165
3171
total_value = msgs:: MAX_VALUE_MSAT ;
3166
3172
}
3167
3173
if total_value >= msgs:: MAX_VALUE_MSAT { break ; }
3168
3174
} ,
3169
3175
_ => unreachable!( ) ,
3170
3176
}
3171
3177
}
3172
- if total_value >= msgs:: MAX_VALUE_MSAT || total_value > $payment_data_total_msat {
3178
+ if total_value >= msgs:: MAX_VALUE_MSAT || total_value > $payment_data . total_msat {
3173
3179
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the total value {} ran over expected value {} (or HTLCs were inconsistent)" ,
3174
- log_bytes!( payment_hash. 0 ) , total_value, $payment_data_total_msat ) ;
3180
+ log_bytes!( payment_hash. 0 ) , total_value, $payment_data . total_msat ) ;
3175
3181
fail_htlc!( claimable_htlc) ;
3176
- } else if total_value == $payment_data_total_msat {
3182
+ } else if total_value == $payment_data . total_msat {
3177
3183
htlcs. push( claimable_htlc) ;
3178
3184
new_events. push( events:: Event :: PaymentReceived {
3179
3185
payment_hash,
3180
3186
purpose: events:: PaymentPurpose :: InvoicePayment {
3181
3187
payment_preimage: $payment_preimage,
3182
- payment_secret: $payment_secret,
3188
+ payment_secret: $payment_data . payment_secret,
3183
3189
} ,
3184
3190
amt: total_value,
3185
3191
} ) ;
@@ -3204,16 +3210,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3204
3210
match payment_secrets. entry ( payment_hash) {
3205
3211
hash_map:: Entry :: Vacant ( _) => {
3206
3212
match claimable_htlc. onion_payload {
3207
- OnionPayload :: Invoice ( ref payment_data) => {
3213
+ OnionPayload :: Invoice { .. } => {
3214
+ let payment_data = payment_data. unwrap ( ) ;
3208
3215
let payment_preimage = match inbound_payment:: verify ( payment_hash, & payment_data, self . highest_seen_timestamp . load ( Ordering :: Acquire ) as u64 , & self . inbound_payment_key , & self . logger ) {
3209
3216
Ok ( payment_preimage) => payment_preimage,
3210
3217
Err ( ( ) ) => {
3211
3218
fail_htlc ! ( claimable_htlc) ;
3212
3219
continue
3213
3220
}
3214
3221
} ;
3215
- let payment_secret = payment_data. payment_secret . clone ( ) ;
3216
- check_total_value ! ( payment_data. total_msat, payment_secret, payment_preimage) ;
3222
+ check_total_value ! ( payment_data, payment_preimage) ;
3217
3223
} ,
3218
3224
OnionPayload :: Spontaneous ( preimage) => {
3219
3225
match channel_state. claimable_htlcs . entry ( payment_hash) {
@@ -3234,14 +3240,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3234
3240
}
3235
3241
} ,
3236
3242
hash_map:: Entry :: Occupied ( inbound_payment) => {
3237
- let payment_data =
3238
- if let OnionPayload :: Invoice ( ref data) = claimable_htlc. onion_payload {
3239
- data. clone ( )
3240
- } else {
3241
- log_trace ! ( self . logger, "Failing new keysend HTLC with payment_hash {} because we already have an inbound payment with the same payment hash" , log_bytes!( payment_hash. 0 ) ) ;
3242
- fail_htlc ! ( claimable_htlc) ;
3243
- continue
3244
- } ;
3243
+ if payment_data. is_none ( ) {
3244
+ log_trace ! ( self . logger, "Failing new keysend HTLC with payment_hash {} because we already have an inbound payment with the same payment hash" , log_bytes!( payment_hash. 0 ) ) ;
3245
+ fail_htlc ! ( claimable_htlc) ;
3246
+ continue
3247
+ } ;
3248
+ let payment_data = payment_data. unwrap ( ) ;
3245
3249
if inbound_payment. get ( ) . payment_secret != payment_data. payment_secret {
3246
3250
log_trace ! ( self . logger, "Failing new HTLC with payment_hash {} as it didn't match our expected payment secret." , log_bytes!( payment_hash. 0 ) ) ;
3247
3251
fail_htlc ! ( claimable_htlc) ;
@@ -3250,7 +3254,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3250
3254
log_bytes!( payment_hash. 0 ) , payment_data. total_msat, inbound_payment. get( ) . min_value_msat. unwrap( ) ) ;
3251
3255
fail_htlc ! ( claimable_htlc) ;
3252
3256
} else {
3253
- let payment_received_generated = check_total_value ! ( payment_data. total_msat , payment_data . payment_secret , inbound_payment. get( ) . payment_preimage) ;
3257
+ let payment_received_generated = check_total_value ! ( payment_data, inbound_payment. get( ) . payment_preimage) ;
3254
3258
if payment_received_generated {
3255
3259
inbound_payment. remove_entry ( ) ;
3256
3260
}
@@ -3469,10 +3473,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3469
3473
debug_assert ! ( false ) ;
3470
3474
return false ;
3471
3475
}
3472
- if let OnionPayload :: Invoice ( ref final_hop_data ) = htlcs[ 0 ] . onion_payload {
3476
+ if let OnionPayload :: Invoice { .. } = htlcs[ 0 ] . onion_payload {
3473
3477
// Check if we've received all the parts we need for an MPP (the value of the parts adds to total_msat).
3474
3478
// In this case we're not going to handle any timeouts of the parts here.
3475
- if final_hop_data . total_msat == htlcs. iter ( ) . fold ( 0 , |total, htlc| total + htlc. value ) {
3479
+ if htlcs [ 0 ] . total_msat == htlcs. iter ( ) . fold ( 0 , |total, htlc| total + htlc. value ) {
3476
3480
return true ;
3477
3481
} else if htlcs. into_iter ( ) . any ( |htlc| {
3478
3482
htlc. timer_ticks += 1 ;
@@ -6073,11 +6077,11 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
6073
6077
impl Writeable for ClaimableHTLC {
6074
6078
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
6075
6079
let payment_data = match & self . onion_payload {
6076
- OnionPayload :: Invoice ( data ) => Some ( data . clone ( ) ) ,
6080
+ OnionPayload :: Invoice { _legacy_hop_data } => Some ( _legacy_hop_data ) ,
6077
6081
_ => None ,
6078
6082
} ;
6079
6083
let keysend_preimage = match self . onion_payload {
6080
- OnionPayload :: Invoice ( _ ) => None ,
6084
+ OnionPayload :: Invoice { .. } => None ,
6081
6085
OnionPayload :: Spontaneous ( preimage) => Some ( preimage. clone ( ) ) ,
6082
6086
} ;
6083
6087
write_tlv_fields ! ( writer, {
@@ -6125,7 +6129,7 @@ impl Readable for ClaimableHTLC {
6125
6129
if total_msat. is_none ( ) {
6126
6130
total_msat = Some ( payment_data. as_ref ( ) . unwrap ( ) . total_msat ) ;
6127
6131
}
6128
- OnionPayload :: Invoice ( payment_data. unwrap ( ) )
6132
+ OnionPayload :: Invoice { _legacy_hop_data : payment_data. unwrap ( ) }
6129
6133
} ,
6130
6134
} ;
6131
6135
Ok ( Self {
0 commit comments