@@ -352,15 +352,32 @@ struct ReceiveError {
352
352
pub enum FailureCode {
353
353
/// We had a temporary error processing the payment. Useful if no other error codes fit
354
354
/// and you want to indicate that the payer may want to retry.
355
- TemporaryNodeFailure = 0x2000 | 2 ,
355
+ TemporaryNodeFailure ,
356
356
/// We have a required feature which was not in this onion. For example, you may require
357
357
/// some additional metadata that was not provided with this payment.
358
- RequiredNodeFeatureMissing = 0x4000 | 0x2000 | 3 ,
358
+ RequiredNodeFeatureMissing ,
359
359
/// You may wish to use this when a `payment_preimage` is unknown, or the CLTV expiry of
360
360
/// the HTLC is too close to the current block height for safe handling.
361
361
/// Using this failure code in [`ChannelManager::fail_htlc_backwards_with_reason`] is
362
362
/// equivalent to calling [`ChannelManager::fail_htlc_backwards`].
363
- IncorrectOrUnknownPaymentDetails = 0x4000 | 15 ,
363
+ IncorrectOrUnknownPaymentDetails ,
364
+ /// We failed to process the payload after the onion was decrypted. You may wish to
365
+ /// use this when receiving custom HTLC TLVs with even type numbers that you don't recognize.
366
+ ///
367
+ /// The tuple data should include the type number and byte offset in the decrypted byte stream
368
+ /// where the failure occurred.
369
+ InvalidOnionPayload ( Option < ( u64 , u16 ) > ) ,
370
+ }
371
+
372
+ impl Into < u16 > for FailureCode {
373
+ fn into ( self ) -> u16 {
374
+ match self {
375
+ FailureCode :: TemporaryNodeFailure => 0x2000 | 2 ,
376
+ FailureCode :: RequiredNodeFeatureMissing => 0x4000 | 0x2000 | 3 ,
377
+ FailureCode :: IncorrectOrUnknownPaymentDetails => 0x4000 | 15 ,
378
+ FailureCode :: InvalidOnionPayload ( _) => 0x4000 | 22 ,
379
+ }
380
+ }
364
381
}
365
382
366
383
/// Error type returned across the peer_state mutex boundary. When an Err is generated for a
@@ -4212,12 +4229,19 @@ where
4212
4229
/// Gets error data to form an [`HTLCFailReason`] given a [`FailureCode`] and [`ClaimableHTLC`].
4213
4230
fn get_htlc_fail_reason_from_failure_code ( & self , failure_code : FailureCode , htlc : & ClaimableHTLC ) -> HTLCFailReason {
4214
4231
match failure_code {
4215
- FailureCode :: TemporaryNodeFailure => HTLCFailReason :: from_failure_code ( failure_code as u16 ) ,
4216
- FailureCode :: RequiredNodeFeatureMissing => HTLCFailReason :: from_failure_code ( failure_code as u16 ) ,
4232
+ FailureCode :: TemporaryNodeFailure => HTLCFailReason :: from_failure_code ( failure_code. into ( ) ) ,
4233
+ FailureCode :: RequiredNodeFeatureMissing => HTLCFailReason :: from_failure_code ( failure_code. into ( ) ) ,
4217
4234
FailureCode :: IncorrectOrUnknownPaymentDetails => {
4218
4235
let mut htlc_msat_height_data = htlc. value . to_be_bytes ( ) . to_vec ( ) ;
4219
4236
htlc_msat_height_data. extend_from_slice ( & self . best_block . read ( ) . unwrap ( ) . height ( ) . to_be_bytes ( ) ) ;
4220
- HTLCFailReason :: reason ( failure_code as u16 , htlc_msat_height_data)
4237
+ HTLCFailReason :: reason ( failure_code. into ( ) , htlc_msat_height_data)
4238
+ } ,
4239
+ FailureCode :: InvalidOnionPayload ( data) => {
4240
+ let fail_data = match data {
4241
+ Some ( ( typ, offset) ) => [ BigSize ( typ) . encode ( ) , offset. encode ( ) ] . concat ( ) ,
4242
+ None => Vec :: new ( ) ,
4243
+ } ;
4244
+ HTLCFailReason :: reason ( failure_code. into ( ) , fail_data)
4221
4245
}
4222
4246
}
4223
4247
}
0 commit comments