@@ -3519,33 +3519,34 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3519
3519
}
3520
3520
3521
3521
let create_pending_htlc_status = |chan : & Channel < Signer > , pending_forward_info : PendingHTLCStatus , error_code : u16 | {
3522
- // Ensure error_code has the UPDATE flag set, since by default we send a
3523
- // channel update along as part of failing the HTLC.
3524
- assert ! ( ( error_code & 0x1000 ) != 0 ) ;
3525
3522
// If the update_add is completely bogus, the call will Err and we will close,
3526
3523
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
3527
3524
// want to reject the new HTLC and fail it backwards instead of forwarding.
3528
3525
match pending_forward_info {
3529
3526
PendingHTLCStatus :: Forward ( PendingHTLCInfo { ref incoming_shared_secret, .. } ) => {
3530
- let reason = if let Ok ( upd) = self . get_channel_update_for_unicast ( chan) {
3531
- onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, error_code, & {
3532
- let mut res = Vec :: with_capacity ( 8 + 128 ) ;
3533
- // TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
3534
- res. extend_from_slice ( & byte_utils:: be16_to_array ( 0 ) ) ;
3535
- res. extend_from_slice ( & upd. encode_with_len ( ) [ ..] ) ;
3536
- res
3537
- } [ ..] )
3527
+ let reason = if ( error_code & 0x1000 ) != 0 {
3528
+ if let Ok ( upd) = self . get_channel_update_for_unicast ( chan) {
3529
+ onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, error_code, & {
3530
+ let mut res = Vec :: with_capacity ( 8 + 128 ) ;
3531
+ // TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
3532
+ res. extend_from_slice ( & byte_utils:: be16_to_array ( 0 ) ) ;
3533
+ res. extend_from_slice ( & upd. encode_with_len ( ) [ ..] ) ;
3534
+ res
3535
+ } [ ..] )
3536
+ } else {
3537
+ // The only case where we'd be unable to
3538
+ // successfully get a channel update is if the
3539
+ // channel isn't in the fully-funded state yet,
3540
+ // implying our counterparty is trying to route
3541
+ // payments over the channel back to themselves
3542
+ // (because no one else should know the short_id
3543
+ // is a lightning channel yet). We should have
3544
+ // no problem just calling this
3545
+ // unknown_next_peer (0x4000|10).
3546
+ onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, 0x4000 |10 , & [ ] )
3547
+ }
3538
3548
} else {
3539
- // The only case where we'd be unable to
3540
- // successfully get a channel update is if the
3541
- // channel isn't in the fully-funded state yet,
3542
- // implying our counterparty is trying to route
3543
- // payments over the channel back to themselves
3544
- // (cause no one else should know the short_id
3545
- // is a lightning channel yet). We should have
3546
- // no problem just calling this
3547
- // unknown_next_peer (0x4000|10).
3548
- onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, 0x4000 |10 , & [ ] )
3549
+ onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, error_code, & [ ] )
3549
3550
} ;
3550
3551
let msg = msgs:: UpdateFailHTLC {
3551
3552
channel_id : msg. channel_id ,
0 commit comments