@@ -346,19 +346,37 @@ struct ReceiveError {
346
346
/// using [`ChannelManager::fail_htlc_backwards_with_reason`].
347
347
///
348
348
/// For more info on failure codes, see <https://github.com/lightning/bolts/blob/master/04-onion-routing.md#failure-messages>.
349
+ #[ repr( u16 ) ]
349
350
#[ derive( Clone , Copy ) ]
350
351
pub enum FailureCode {
351
352
/// We had a temporary error processing the payment. Useful if no other error codes fit
352
353
/// and you want to indicate that the payer may want to retry.
353
- TemporaryNodeFailure = 0x2000 | 2 ,
354
+ TemporaryNodeFailure ,
354
355
/// We have a required feature which was not in this onion. For example, you may require
355
356
/// some additional metadata that was not provided with this payment.
356
- RequiredNodeFeatureMissing = 0x4000 | 0x2000 | 3 ,
357
+ RequiredNodeFeatureMissing ,
357
358
/// You may wish to use this when a `payment_preimage` is unknown, or the CLTV expiry of
358
359
/// the HTLC is too close to the current block height for safe handling.
359
360
/// Using this failure code in [`ChannelManager::fail_htlc_backwards_with_reason`] is
360
361
/// equivalent to calling [`ChannelManager::fail_htlc_backwards`].
361
- IncorrectOrUnknownPaymentDetails = 0x4000 | 15 ,
362
+ IncorrectOrUnknownPaymentDetails ,
363
+ /// We failed to process the payload after the onion was decrypted. You may wish to
364
+ /// use this when receiving custom HTLC TLVs with even type numbers that you don't recognize.
365
+ ///
366
+ /// The tuple data should include the type number and byte offset in the decrypted byte stream
367
+ /// where the failure occurred.
368
+ InvalidOnionPayload ( Option < ( u64 , u16 ) > ) ,
369
+ }
370
+
371
+ impl Into < u16 > for FailureCode {
372
+ fn into ( self ) -> u16 {
373
+ match self {
374
+ FailureCode :: TemporaryNodeFailure => 0x2000 | 2 ,
375
+ FailureCode :: RequiredNodeFeatureMissing => 0x4000 | 0x2000 | 3 ,
376
+ FailureCode :: IncorrectOrUnknownPaymentDetails => 0x4000 | 15 ,
377
+ FailureCode :: InvalidOnionPayload ( _) => 0x4000 | 22 ,
378
+ }
379
+ }
362
380
}
363
381
364
382
type ShutdownResult = ( Option < ( OutPoint , ChannelMonitorUpdate ) > , Vec < ( HTLCSource , PaymentHash , PublicKey , [ u8 ; 32 ] ) > ) ;
@@ -4049,12 +4067,19 @@ where
4049
4067
/// Gets error data to form an [`HTLCFailReason`] given a [`FailureCode`] and [`ClaimableHTLC`].
4050
4068
fn get_htlc_fail_reason_from_failure_code ( & self , failure_code : FailureCode , htlc : & ClaimableHTLC ) -> HTLCFailReason {
4051
4069
match failure_code {
4052
- FailureCode :: TemporaryNodeFailure => HTLCFailReason :: from_failure_code ( failure_code as u16 ) ,
4053
- FailureCode :: RequiredNodeFeatureMissing => HTLCFailReason :: from_failure_code ( failure_code as u16 ) ,
4070
+ FailureCode :: TemporaryNodeFailure => HTLCFailReason :: from_failure_code ( failure_code. into ( ) ) ,
4071
+ FailureCode :: RequiredNodeFeatureMissing => HTLCFailReason :: from_failure_code ( failure_code. into ( ) ) ,
4054
4072
FailureCode :: IncorrectOrUnknownPaymentDetails => {
4055
4073
let mut htlc_msat_height_data = htlc. value . to_be_bytes ( ) . to_vec ( ) ;
4056
4074
htlc_msat_height_data. extend_from_slice ( & self . best_block . read ( ) . unwrap ( ) . height ( ) . to_be_bytes ( ) ) ;
4057
- HTLCFailReason :: reason ( failure_code as u16 , htlc_msat_height_data)
4075
+ HTLCFailReason :: reason ( failure_code. into ( ) , htlc_msat_height_data)
4076
+ } ,
4077
+ FailureCode :: InvalidOnionPayload ( data) => {
4078
+ let fail_data = match data {
4079
+ Some ( ( typ, offset) ) => [ BigSize ( typ) . encode ( ) , offset. encode ( ) ] . concat ( ) ,
4080
+ None => Vec :: new ( ) ,
4081
+ } ;
4082
+ HTLCFailReason :: reason ( failure_code. into ( ) , fail_data)
4058
4083
}
4059
4084
}
4060
4085
}
0 commit comments