@@ -2472,47 +2472,48 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2472
2472
//encrypted with the same key. It's not immediately obvious how to usefully exploit that,
2473
2473
//but we should prevent it anyway.
2474
2474
2475
- let ( mut pending_forward_info, mut channel_state_lock) = self . decode_update_add_htlc_onion ( msg) ;
2475
+ let ( pending_forward_info, mut channel_state_lock) = self . decode_update_add_htlc_onion ( msg) ;
2476
2476
let channel_state = & mut * channel_state_lock;
2477
2477
2478
2478
match channel_state. by_id . entry ( msg. channel_id ) {
2479
2479
hash_map:: Entry :: Occupied ( mut chan) => {
2480
2480
if chan. get ( ) . get_their_node_id ( ) != * their_node_id {
2481
2481
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" , msg. channel_id ) ) ;
2482
2482
}
2483
- if !chan. get ( ) . is_usable ( ) {
2483
+
2484
+ let create_pending_htlc_status = |chan : & Channel < ChanSigner > , pending_forward_info : PendingHTLCStatus , error_code : u16 | {
2484
2485
// If the update_add is completely bogus, the call will Err and we will close,
2485
2486
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
2486
2487
// want to reject the new HTLC and fail it backwards instead of forwarding.
2487
- if let PendingHTLCStatus :: Forward ( PendingHTLCInfo { incoming_shared_secret, .. } ) = pending_forward_info {
2488
- let chan_update = self . get_channel_update ( chan. get ( ) ) ;
2489
- pending_forward_info = PendingHTLCStatus :: Fail ( HTLCFailureMsg :: Relay ( msgs:: UpdateFailHTLC {
2490
- channel_id : msg. channel_id ,
2491
- htlc_id : msg. htlc_id ,
2492
- reason : if let Ok ( update) = chan_update {
2493
- // TODO: Note that |20 is defined as "channel FROM the processing
2494
- // node has been disabled" (emphasis mine), which seems to imply
2495
- // that we can't return |20 for an inbound channel being disabled.
2496
- // This probably needs a spec update but should definitely be
2497
- // allowed.
2498
- onion_utils:: build_first_hop_failure_packet ( & incoming_shared_secret, 0x1000 |20 , & {
2488
+ match pending_forward_info {
2489
+ PendingHTLCStatus :: Forward ( PendingHTLCInfo { ref incoming_shared_secret, .. } ) => {
2490
+ // The only case where we'd be unable to successfully get a channel
2491
+ // update here is if the channel isn't in the fully-funded
2492
+ // state yet, implying our counterparty is trying to route payments
2493
+ // over the channel back to themselves (cause no one else should
2494
+ // know the short_id is a lightning channel yet). We should have no
2495
+ // problem just calling this unknown_next_peer, as above (0x4000|10).
2496
+ let reason = if let Ok ( upd) = self . get_channel_update ( chan) {
2497
+ onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, error_code, & {
2499
2498
let mut res = Vec :: with_capacity ( 8 + 128 ) ;
2500
- res. extend_from_slice ( & byte_utils:: be16_to_array ( update . contents . flags ) ) ;
2501
- res. extend_from_slice ( & update . encode_with_len ( ) [ ..] ) ;
2499
+ res. extend_from_slice ( & byte_utils:: be16_to_array ( upd . contents . flags ) ) ;
2500
+ res. extend_from_slice ( & upd . encode_with_len ( ) [ ..] ) ;
2502
2501
res
2503
2502
} [ ..] )
2504
2503
} else {
2505
- // This can only happen if the channel isn't in the fully-funded
2506
- // state yet, implying our counterparty is trying to route payments
2507
- // over the channel back to themselves (cause no one else should
2508
- // know the short_id is a lightning channel yet). We should have no
2509
- // problem just calling this unknown_next_peer
2510
- onion_utils:: build_first_hop_failure_packet ( & incoming_shared_secret, 0x4000 |10 , & [ ] )
2511
- } ,
2512
- } ) ) ;
2504
+ onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, 0x4000 |10 , & [ ] )
2505
+ } ;
2506
+ let msg = msgs:: UpdateFailHTLC {
2507
+ channel_id : msg. channel_id ,
2508
+ htlc_id : msg. htlc_id ,
2509
+ reason
2510
+ } ;
2511
+ PendingHTLCStatus :: Fail ( HTLCFailureMsg :: Relay ( msg) )
2512
+ } ,
2513
+ _ => pending_forward_info
2513
2514
}
2514
- }
2515
- try_chan_entry ! ( self , chan. get_mut( ) . update_add_htlc( & msg, pending_forward_info) , channel_state, chan) ;
2515
+ } ;
2516
+ try_chan_entry ! ( self , chan. get_mut( ) . update_add_htlc( & msg, pending_forward_info, create_pending_htlc_status ) , channel_state, chan) ;
2516
2517
} ,
2517
2518
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" , msg. channel_id ) )
2518
2519
}
0 commit comments