@@ -3525,25 +3525,29 @@ where
3525
3525
FailureCode :: TemporaryNodeFailure => HTLCFailReason :: from_failure_code ( * failure_code as u16 ) ,
3526
3526
FailureCode :: RequiredNodeFeatureMissing => HTLCFailReason :: from_failure_code ( * failure_code as u16 ) ,
3527
3527
FailureCode :: ExpiryTooSoon => {
3528
+ let mut expiry_fail_reason = None ;
3528
3529
let short_channel_id = htlc. prev_hop . short_channel_id ;
3529
- let ( counterparty_node_id, chan_id) = self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_channel_id) . cloned ( ) . unwrap ( ) ;
3530
- let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
3531
- let peer_state = per_peer_state. get ( & counterparty_node_id) ;
3532
- if peer_state. is_none ( ) {
3533
- return self . get_htlc_fail_reason_from_failure_code ( & FailureCode :: IncorrectOrUnknownPaymentDetails , htlc)
3530
+ let cp_node_chan_id = self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_channel_id) . cloned ( ) ;
3531
+ if let Some ( ( counterparty_node_id, chan_id) ) = cp_node_chan_id {
3532
+ let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
3533
+ if let Some ( peer_state) = per_peer_state. get ( & counterparty_node_id) {
3534
+ let peer_state = peer_state. lock ( ) . unwrap ( ) ;
3535
+ if let Some ( chan) = peer_state. channel_by_id . get ( & chan_id) {
3536
+ if let Ok ( channel_update) = self . get_channel_update_for_onion ( short_channel_id, chan) {
3537
+ let mut channel_update_data = Vec :: new ( ) ;
3538
+ ( channel_update. serialized_length ( ) as u16 + 2 ) . write ( & mut channel_update_data) . expect ( "Writes cannot fail" ) ;
3539
+ msgs:: ChannelUpdate :: TYPE . write ( & mut channel_update_data) . expect ( "Writes cannot fail" ) ;
3540
+ channel_update. write ( & mut channel_update_data) . expect ( "Writes cannot fail" ) ;
3541
+ expiry_fail_reason = Some ( HTLCFailReason :: reason ( * failure_code as u16 , channel_update_data) ) ;
3542
+ }
3543
+ }
3544
+ }
3534
3545
}
3535
- let peer_state = peer_state . unwrap ( ) . lock ( ) . unwrap ( ) ;
3536
- let chan = peer_state . channel_by_id . get ( & chan_id ) ;
3537
- if chan . is_none ( ) {
3538
- return self . get_htlc_fail_reason_from_failure_code ( & FailureCode :: IncorrectOrUnknownPaymentDetails , htlc)
3546
+ if let Some ( expiry_fail_reason ) = expiry_fail_reason {
3547
+ expiry_fail_reason
3548
+ } else {
3549
+ self . get_htlc_fail_reason_from_failure_code ( & FailureCode :: IncorrectOrUnknownPaymentDetails , htlc)
3539
3550
}
3540
- let chan = chan. unwrap ( ) ;
3541
- let channel_update = self . get_channel_update_for_onion ( short_channel_id, chan) . unwrap ( ) ;
3542
- let mut channel_update_data = Vec :: new ( ) ;
3543
- ( channel_update. serialized_length ( ) as u16 + 2 ) . write ( & mut channel_update_data) . expect ( "Writes cannot fail" ) ;
3544
- msgs:: ChannelUpdate :: TYPE . write ( & mut channel_update_data) . expect ( "Writes cannot fail" ) ;
3545
- channel_update. write ( & mut channel_update_data) . expect ( "Writes cannot fail" ) ;
3546
- HTLCFailReason :: reason ( * failure_code as u16 , channel_update_data)
3547
3551
} ,
3548
3552
FailureCode :: IncorrectOrUnknownPaymentDetails => {
3549
3553
let mut htlc_msat_height_data = htlc. value . to_be_bytes ( ) . to_vec ( ) ;
0 commit comments