@@ -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.104 and earlier.
168
+ _legacy_hop_data : msgs:: FinalOnionHopData ,
169
+ } ,
166
170
/// Contains the payer-provided preimage.
167
171
Spontaneous ( PaymentPreimage ) ,
168
172
}
@@ -3095,11 +3099,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3095
3099
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3096
3100
routing, incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
3097
3101
prev_funding_outpoint } => {
3098
- let ( cltv_expiry, total_msat, onion_payload, phantom_shared_secret) = match routing {
3099
- PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } =>
3100
- ( incoming_cltv_expiry, payment_data. total_msat , OnionPayload :: Invoice ( payment_data) , phantom_shared_secret) ,
3102
+ let ( cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
3103
+ PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } => {
3104
+ let _legacy_hop_data = msgs:: FinalOnionHopData {
3105
+ payment_secret : payment_data. payment_secret ,
3106
+ total_msat : payment_data. total_msat
3107
+ } ;
3108
+ ( incoming_cltv_expiry, OnionPayload :: Invoice { _legacy_hop_data } , Some ( payment_data) , phantom_shared_secret)
3109
+ } ,
3101
3110
PendingHTLCRouting :: ReceiveKeysend { payment_preimage, incoming_cltv_expiry } =>
3102
- ( incoming_cltv_expiry, amt_to_forward , OnionPayload :: Spontaneous ( payment_preimage) , None ) ,
3111
+ ( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) , None , None ) ,
3103
3112
_ => {
3104
3113
panic ! ( "short_channel_id == 0 should imply any pending_forward entries are of type Receive" ) ;
3105
3114
}
@@ -3114,7 +3123,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3114
3123
} ,
3115
3124
value : amt_to_forward,
3116
3125
timer_ticks : 0 ,
3117
- total_msat,
3126
+ total_msat : if let Some ( data ) = & payment_data { data . total_msat } else { amt_to_forward } ,
3118
3127
cltv_expiry,
3119
3128
onion_payload,
3120
3129
} ;
@@ -3138,7 +3147,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3138
3147
}
3139
3148
3140
3149
macro_rules! check_total_value {
3141
- ( $payment_data_total_msat : expr , $payment_secret : expr, $payment_preimage: expr) => { {
3150
+ ( $payment_data : expr, $payment_preimage: expr) => { {
3142
3151
let mut payment_received_generated = false ;
3143
3152
let htlcs = channel_state. claimable_htlcs. entry( payment_hash)
3144
3153
. or_insert( Vec :: new( ) ) ;
@@ -3154,9 +3163,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3154
3163
total_value += htlc. value;
3155
3164
match & htlc. onion_payload {
3156
3165
OnionPayload :: Invoice { .. } => {
3157
- if htlc. total_msat != $payment_data_total_msat {
3166
+ if htlc. total_msat != $payment_data . total_msat {
3158
3167
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})" ,
3159
- log_bytes!( payment_hash. 0 ) , $payment_data_total_msat , htlc. total_msat) ;
3168
+ log_bytes!( payment_hash. 0 ) , $payment_data . total_msat , htlc. total_msat) ;
3160
3169
total_value = msgs:: MAX_VALUE_MSAT ;
3161
3170
}
3162
3171
if total_value >= msgs:: MAX_VALUE_MSAT { break ; }
@@ -3166,15 +3175,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3166
3175
}
3167
3176
if total_value >= msgs:: MAX_VALUE_MSAT || total_value > claimable_htlc. total_msat {
3168
3177
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the total value {} ran over expected value {} (or HTLCs were inconsistent)" ,
3169
- log_bytes!( payment_hash. 0 ) , total_value, $payment_data_total_msat ) ;
3178
+ log_bytes!( payment_hash. 0 ) , total_value, $payment_data . total_msat ) ;
3170
3179
fail_htlc!( claimable_htlc) ;
3171
- } else if total_value == $payment_data_total_msat {
3180
+ } else if total_value == $payment_data . total_msat {
3172
3181
htlcs. push( claimable_htlc) ;
3173
3182
new_events. push( events:: Event :: PaymentReceived {
3174
3183
payment_hash,
3175
3184
purpose: events:: PaymentPurpose :: InvoicePayment {
3176
3185
payment_preimage: $payment_preimage,
3177
- payment_secret: $payment_secret,
3186
+ payment_secret: $payment_data . payment_secret,
3178
3187
} ,
3179
3188
amt: total_value,
3180
3189
} ) ;
@@ -3199,16 +3208,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3199
3208
match payment_secrets. entry ( payment_hash) {
3200
3209
hash_map:: Entry :: Vacant ( _) => {
3201
3210
match claimable_htlc. onion_payload {
3202
- OnionPayload :: Invoice ( ref payment_data) => {
3211
+ OnionPayload :: Invoice { .. } => {
3212
+ let payment_data = payment_data. unwrap ( ) ;
3203
3213
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 ) {
3204
3214
Ok ( payment_preimage) => payment_preimage,
3205
3215
Err ( ( ) ) => {
3206
3216
fail_htlc ! ( claimable_htlc) ;
3207
3217
continue
3208
3218
}
3209
3219
} ;
3210
- let payment_secret = payment_data. payment_secret . clone ( ) ;
3211
- check_total_value ! ( payment_data. total_msat, payment_secret, payment_preimage) ;
3220
+ check_total_value ! ( payment_data, payment_preimage) ;
3212
3221
} ,
3213
3222
OnionPayload :: Spontaneous ( preimage) => {
3214
3223
match channel_state. claimable_htlcs . entry ( payment_hash) {
@@ -3229,14 +3238,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3229
3238
}
3230
3239
} ,
3231
3240
hash_map:: Entry :: Occupied ( inbound_payment) => {
3232
- let payment_data =
3233
- if let OnionPayload :: Invoice ( ref data) = claimable_htlc. onion_payload {
3234
- data. clone ( )
3235
- } else {
3236
- 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 ) ) ;
3237
- fail_htlc ! ( claimable_htlc) ;
3238
- continue
3239
- } ;
3241
+ if payment_data. is_none ( ) {
3242
+ 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 ) ) ;
3243
+ fail_htlc ! ( claimable_htlc) ;
3244
+ continue
3245
+ } ;
3246
+ let payment_data = payment_data. unwrap ( ) ;
3240
3247
if inbound_payment. get ( ) . payment_secret != payment_data. payment_secret {
3241
3248
log_trace ! ( self . logger, "Failing new HTLC with payment_hash {} as it didn't match our expected payment secret." , log_bytes!( payment_hash. 0 ) ) ;
3242
3249
fail_htlc ! ( claimable_htlc) ;
@@ -3245,7 +3252,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3245
3252
log_bytes!( payment_hash. 0 ) , payment_data. total_msat, inbound_payment. get( ) . min_value_msat. unwrap( ) ) ;
3246
3253
fail_htlc ! ( claimable_htlc) ;
3247
3254
} else {
3248
- let payment_received_generated = check_total_value ! ( payment_data. total_msat , payment_data . payment_secret , inbound_payment. get( ) . payment_preimage) ;
3255
+ let payment_received_generated = check_total_value ! ( payment_data, inbound_payment. get( ) . payment_preimage) ;
3249
3256
if payment_received_generated {
3250
3257
inbound_payment. remove_entry ( ) ;
3251
3258
}
@@ -3464,7 +3471,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3464
3471
debug_assert ! ( false ) ;
3465
3472
return false ;
3466
3473
}
3467
- if let OnionPayload :: Invoice ( ref final_hop_data) = htlcs[ 0 ] . onion_payload {
3474
+ if let OnionPayload :: Invoice { _legacy_hop_data : ref final_hop_data } = htlcs[ 0 ] . onion_payload {
3468
3475
// Check if we've received all the parts we need for an MPP (the value of the parts adds to total_msat).
3469
3476
// In this case we're not going to handle any timeouts of the parts here.
3470
3477
if final_hop_data. total_msat == htlcs. iter ( ) . fold ( 0 , |total, htlc| total + htlc. value ) {
@@ -6066,11 +6073,11 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
6066
6073
impl Writeable for ClaimableHTLC {
6067
6074
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
6068
6075
let payment_data = match & self . onion_payload {
6069
- OnionPayload :: Invoice ( data ) => Some ( data . clone ( ) ) ,
6076
+ OnionPayload :: Invoice { _legacy_hop_data } => Some ( _legacy_hop_data ) ,
6070
6077
_ => None ,
6071
6078
} ;
6072
6079
let keysend_preimage = match self . onion_payload {
6073
- OnionPayload :: Invoice ( _ ) => None ,
6080
+ OnionPayload :: Invoice { .. } => None ,
6074
6081
OnionPayload :: Spontaneous ( preimage) => Some ( preimage. clone ( ) ) ,
6075
6082
} ;
6076
6083
write_tlv_fields ! ( writer, {
@@ -6118,7 +6125,7 @@ impl Readable for ClaimableHTLC {
6118
6125
if total_msat. is_none ( ) {
6119
6126
total_msat = Some ( payment_data. as_ref ( ) . unwrap ( ) . total_msat ) ;
6120
6127
}
6121
- OnionPayload :: Invoice ( payment_data. unwrap ( ) )
6128
+ OnionPayload :: Invoice { _legacy_hop_data : payment_data. unwrap ( ) }
6122
6129
} ,
6123
6130
} ;
6124
6131
Ok ( Self {
0 commit comments