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