@@ -3461,33 +3461,34 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3461
3461
}
3462
3462
3463
3463
let create_pending_htlc_status = |chan : & Channel < Signer > , pending_forward_info : PendingHTLCStatus , error_code : u16 | {
3464
- // Ensure error_code has the UPDATE flag set, since by default we send a
3465
- // channel update along as part of failing the HTLC.
3466
- assert ! ( ( error_code & 0x1000 ) != 0 ) ;
3467
3464
// If the update_add is completely bogus, the call will Err and we will close,
3468
3465
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
3469
3466
// want to reject the new HTLC and fail it backwards instead of forwarding.
3470
3467
match pending_forward_info {
3471
3468
PendingHTLCStatus :: Forward ( PendingHTLCInfo { ref incoming_shared_secret, .. } ) => {
3472
- let reason = if let Ok ( upd) = self . get_channel_update_for_unicast ( chan) {
3473
- onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, error_code, & {
3474
- let mut res = Vec :: with_capacity ( 8 + 128 ) ;
3475
- // TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
3476
- res. extend_from_slice ( & byte_utils:: be16_to_array ( 0 ) ) ;
3477
- res. extend_from_slice ( & upd. encode_with_len ( ) [ ..] ) ;
3478
- res
3479
- } [ ..] )
3469
+ let reason = if ( error_code & 0x1000 ) != 0 {
3470
+ if let Ok ( upd) = self . get_channel_update_for_unicast ( chan) {
3471
+ onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, error_code, & {
3472
+ let mut res = Vec :: with_capacity ( 8 + 128 ) ;
3473
+ // TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
3474
+ res. extend_from_slice ( & byte_utils:: be16_to_array ( 0 ) ) ;
3475
+ res. extend_from_slice ( & upd. encode_with_len ( ) [ ..] ) ;
3476
+ res
3477
+ } [ ..] )
3478
+ } else {
3479
+ // The only case where we'd be unable to
3480
+ // successfully get a channel update is if the
3481
+ // channel isn't in the fully-funded state yet,
3482
+ // implying our counterparty is trying to route
3483
+ // payments over the channel back to themselves
3484
+ // (cause no one else should know the short_id
3485
+ // is a lightning channel yet). We should have
3486
+ // no problem just calling this
3487
+ // unknown_next_peer (0x4000|10).
3488
+ onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, 0x4000 |10 , & [ ] )
3489
+ }
3480
3490
} else {
3481
- // The only case where we'd be unable to
3482
- // successfully get a channel update is if the
3483
- // channel isn't in the fully-funded state yet,
3484
- // implying our counterparty is trying to route
3485
- // payments over the channel back to themselves
3486
- // (cause no one else should know the short_id
3487
- // is a lightning channel yet). We should have
3488
- // no problem just calling this
3489
- // unknown_next_peer (0x4000|10).
3490
- onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, 0x4000 |10 , & [ ] )
3491
+ onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, error_code, & [ ] )
3491
3492
} ;
3492
3493
let msg = msgs:: UpdateFailHTLC {
3493
3494
channel_id : msg. channel_id ,
0 commit comments