@@ -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
}
@@ -3092,11 +3096,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3092
3096
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
3093
3097
routing, incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
3094
3098
prev_funding_outpoint } => {
3095
- let ( cltv_expiry, total_msat, onion_payload, phantom_shared_secret) = match routing {
3096
- PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } =>
3097
- ( incoming_cltv_expiry, payment_data. total_msat , OnionPayload :: Invoice ( payment_data) , phantom_shared_secret) ,
3099
+ let ( cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
3100
+ PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } => {
3101
+ let _legacy_hop_data = msgs:: FinalOnionHopData {
3102
+ payment_secret : payment_data. payment_secret ,
3103
+ total_msat : payment_data. total_msat
3104
+ } ;
3105
+ ( incoming_cltv_expiry, OnionPayload :: Invoice { _legacy_hop_data } , Some ( payment_data) , phantom_shared_secret)
3106
+ } ,
3098
3107
PendingHTLCRouting :: ReceiveKeysend { payment_preimage, incoming_cltv_expiry } =>
3099
- ( incoming_cltv_expiry, amt_to_forward , OnionPayload :: Spontaneous ( payment_preimage) , None ) ,
3108
+ ( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) , None , None ) ,
3100
3109
_ => {
3101
3110
panic ! ( "short_channel_id == 0 should imply any pending_forward entries are of type Receive" ) ;
3102
3111
}
@@ -3111,7 +3120,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3111
3120
} ,
3112
3121
value : amt_to_forward,
3113
3122
timer_ticks : 0 ,
3114
- total_msat,
3123
+ total_msat : if let Some ( data ) = & payment_data { data . total_msat } else { amt_to_forward } ,
3115
3124
cltv_expiry,
3116
3125
onion_payload,
3117
3126
} ;
@@ -3135,7 +3144,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3135
3144
}
3136
3145
3137
3146
macro_rules! check_total_value {
3138
- ( $payment_data_total_msat : expr , $payment_secret : expr, $payment_preimage: expr) => { {
3147
+ ( $payment_data : expr, $payment_preimage: expr) => { {
3139
3148
let mut payment_received_generated = false ;
3140
3149
let htlcs = channel_state. claimable_htlcs. entry( payment_hash)
3141
3150
. or_insert( Vec :: new( ) ) ;
@@ -3150,7 +3159,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3150
3159
for htlc in htlcs. iter( ) {
3151
3160
total_value += htlc. value;
3152
3161
match & htlc. onion_payload {
3153
- OnionPayload :: Invoice ( _ ) => {
3162
+ OnionPayload :: Invoice { .. } => {
3154
3163
if htlc. total_msat != claimable_htlc. total_msat {
3155
3164
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})" ,
3156
3165
log_bytes!( payment_hash. 0 ) , claimable_htlc. total_msat, htlc. total_msat) ;
@@ -3169,7 +3178,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3169
3178
payment_hash,
3170
3179
purpose: events:: PaymentPurpose :: InvoicePayment {
3171
3180
payment_preimage: $payment_preimage,
3172
- payment_secret: $payment_secret,
3181
+ payment_secret: $payment_data . payment_secret,
3173
3182
} ,
3174
3183
amt: total_value,
3175
3184
} ) ;
@@ -3194,16 +3203,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3194
3203
match payment_secrets. entry ( payment_hash) {
3195
3204
hash_map:: Entry :: Vacant ( _) => {
3196
3205
match claimable_htlc. onion_payload {
3197
- OnionPayload :: Invoice ( ref payment_data) => {
3206
+ OnionPayload :: Invoice { .. } => {
3207
+ let payment_data = payment_data. unwrap ( ) ;
3198
3208
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 ) {
3199
3209
Ok ( payment_preimage) => payment_preimage,
3200
3210
Err ( ( ) ) => {
3201
3211
fail_htlc ! ( claimable_htlc) ;
3202
3212
continue
3203
3213
}
3204
3214
} ;
3205
- let payment_secret = payment_data. payment_secret . clone ( ) ;
3206
- check_total_value ! ( payment_data. total_msat, payment_secret, payment_preimage) ;
3215
+ check_total_value ! ( payment_data, payment_preimage) ;
3207
3216
} ,
3208
3217
OnionPayload :: Spontaneous ( preimage) => {
3209
3218
match channel_state. claimable_htlcs . entry ( payment_hash) {
@@ -3224,14 +3233,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3224
3233
}
3225
3234
} ,
3226
3235
hash_map:: Entry :: Occupied ( inbound_payment) => {
3227
- let payment_data =
3228
- if let OnionPayload :: Invoice ( ref data) = claimable_htlc. onion_payload {
3229
- data. clone ( )
3230
- } else {
3231
- 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 ) ) ;
3232
- fail_htlc ! ( claimable_htlc) ;
3233
- continue
3234
- } ;
3236
+ if payment_data. is_none ( ) {
3237
+ 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 ) ) ;
3238
+ fail_htlc ! ( claimable_htlc) ;
3239
+ continue
3240
+ } ;
3241
+ let payment_data = payment_data. unwrap ( ) ;
3235
3242
if inbound_payment. get ( ) . payment_secret != payment_data. payment_secret {
3236
3243
log_trace ! ( self . logger, "Failing new HTLC with payment_hash {} as it didn't match our expected payment secret." , log_bytes!( payment_hash. 0 ) ) ;
3237
3244
fail_htlc ! ( claimable_htlc) ;
@@ -3240,7 +3247,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3240
3247
log_bytes!( payment_hash. 0 ) , payment_data. total_msat, inbound_payment. get( ) . min_value_msat. unwrap( ) ) ;
3241
3248
fail_htlc ! ( claimable_htlc) ;
3242
3249
} else {
3243
- let payment_received_generated = check_total_value ! ( payment_data. total_msat , payment_data . payment_secret , inbound_payment. get( ) . payment_preimage) ;
3250
+ let payment_received_generated = check_total_value ! ( payment_data, inbound_payment. get( ) . payment_preimage) ;
3244
3251
if payment_received_generated {
3245
3252
inbound_payment. remove_entry ( ) ;
3246
3253
}
@@ -3459,7 +3466,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3459
3466
debug_assert ! ( false ) ;
3460
3467
return false ;
3461
3468
}
3462
- if let OnionPayload :: Invoice ( ref final_hop_data) = htlcs[ 0 ] . onion_payload {
3469
+ if let OnionPayload :: Invoice { _legacy_hop_data : ref final_hop_data } = htlcs[ 0 ] . onion_payload {
3463
3470
// Check if we've received all the parts we need for an MPP (the value of the parts adds to total_msat).
3464
3471
// In this case we're not going to handle any timeouts of the parts here.
3465
3472
if final_hop_data. total_msat == htlcs. iter ( ) . fold ( 0 , |total, htlc| total + htlc. value ) {
@@ -6061,11 +6068,11 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
6061
6068
impl Writeable for ClaimableHTLC {
6062
6069
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
6063
6070
let payment_data = match & self . onion_payload {
6064
- OnionPayload :: Invoice ( data ) => Some ( data . clone ( ) ) ,
6071
+ OnionPayload :: Invoice { _legacy_hop_data } => Some ( _legacy_hop_data ) ,
6065
6072
_ => None ,
6066
6073
} ;
6067
6074
let keysend_preimage = match self . onion_payload {
6068
- OnionPayload :: Invoice ( _ ) => None ,
6075
+ OnionPayload :: Invoice { .. } => None ,
6069
6076
OnionPayload :: Spontaneous ( preimage) => Some ( preimage. clone ( ) ) ,
6070
6077
} ;
6071
6078
write_tlv_fields ! ( writer, {
@@ -6113,7 +6120,7 @@ impl Readable for ClaimableHTLC {
6113
6120
if total_msat. is_none ( ) {
6114
6121
total_msat = Some ( payment_data. as_ref ( ) . unwrap ( ) . total_msat ) ;
6115
6122
}
6116
- OnionPayload :: Invoice ( payment_data. unwrap ( ) )
6123
+ OnionPayload :: Invoice { _legacy_hop_data : payment_data. unwrap ( ) }
6117
6124
} ,
6118
6125
} ;
6119
6126
Ok ( Self {
0 commit comments