@@ -2524,6 +2524,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2524
2524
Some ( id) => id,
2525
2525
} ;
2526
2526
2527
+ self . get_channel_update_for_onion ( short_channel_id, chan)
2528
+ }
2529
+ fn get_channel_update_for_onion ( & self , short_channel_id : u64 , chan : & Channel < Signer > ) -> Result < msgs:: ChannelUpdate , LightningError > {
2530
+ log_trace ! ( self . logger, "Generating channel update for channel {}" , log_bytes!( chan. channel_id( ) ) ) ;
2527
2531
let were_node_one = PublicKey :: from_secret_key ( & self . secp_ctx , & self . our_network_key ) . serialize ( ) [ ..] < chan. get_counterparty_node_id ( ) . serialize ( ) [ ..] ;
2528
2532
2529
2533
let unsigned = msgs:: UnsignedChannelUpdate {
@@ -3213,7 +3217,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3213
3217
} else {
3214
3218
panic ! ( "Stated return value requirements in send_htlc() were not met" ) ;
3215
3219
}
3216
- let ( failure_code, data) = self . get_htlc_temp_fail_err_and_data ( 0x1000 |7 , chan. get ( ) ) ;
3220
+ let ( failure_code, data) = self . get_htlc_temp_fail_err_and_data ( 0x1000 |7 , short_chan_id , chan. get ( ) ) ;
3217
3221
failed_forwards. push ( ( htlc_source, payment_hash,
3218
3222
HTLCFailReason :: Reason { failure_code, data }
3219
3223
) ) ;
@@ -3713,9 +3717,32 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3713
3717
3714
3718
/// Gets an HTLC onion failure code and error data for an `UPDATE` error, given the error code
3715
3719
/// that we want to return and a channel.
3716
- fn get_htlc_temp_fail_err_and_data ( & self , desired_err_code : u16 , chan : & Channel < Signer > ) -> ( u16 , Vec < u8 > ) {
3720
+ ///
3721
+ /// This is for failures on the channel on which the HTLC was *received*, not failures
3722
+ /// forwarding
3723
+ fn get_htlc_inbound_temp_fail_err_and_data ( & self , desired_err_code : u16 , chan : & Channel < Signer > ) -> ( u16 , Vec < u8 > ) {
3724
+ // We can't be sure what SCID was used when relaying inbound towards us, so we have to
3725
+ // guess somewhat. If its a public channel, we figure best to just use the real SCID (as
3726
+ // we're not leaking that we have a channel with the counterparty), otherwise we try to use
3727
+ // an inbound SCID alias before the real SCID.
3728
+ let scid_pref = if chan. should_announce ( ) {
3729
+ chan. get_short_channel_id ( ) . or ( chan. latest_inbound_scid_alias ( ) )
3730
+ } else {
3731
+ chan. latest_inbound_scid_alias ( ) . or ( chan. get_short_channel_id ( ) )
3732
+ } ;
3733
+ if let Some ( scid) = scid_pref {
3734
+ self . get_htlc_temp_fail_err_and_data ( desired_err_code, scid, chan)
3735
+ } else {
3736
+ ( 0x4000 |10 , Vec :: new ( ) )
3737
+ }
3738
+ }
3739
+
3740
+
3741
+ /// Gets an HTLC onion failure code and error data for an `UPDATE` error, given the error code
3742
+ /// that we want to return and a channel.
3743
+ fn get_htlc_temp_fail_err_and_data ( & self , desired_err_code : u16 , scid : u64 , chan : & Channel < Signer > ) -> ( u16 , Vec < u8 > ) {
3717
3744
debug_assert_eq ! ( desired_err_code & 0x1000 , 0x1000 ) ;
3718
- if let Ok ( upd) = self . get_channel_update_for_unicast ( chan) {
3745
+ if let Ok ( upd) = self . get_channel_update_for_onion ( scid , chan) {
3719
3746
let enc = if desired_err_code == 0x1000 | 20 {
3720
3747
let mut res = Vec :: new ( ) ;
3721
3748
// TODO: underspecified, follow https://github.com/lightning/bolts/issues/791
@@ -3743,7 +3770,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3743
3770
let ( failure_code, onion_failure_data) =
3744
3771
match self . channel_state . lock ( ) . unwrap ( ) . by_id . entry ( channel_id) {
3745
3772
hash_map:: Entry :: Occupied ( chan_entry) => {
3746
- self . get_htlc_temp_fail_err_and_data ( 0x1000 |7 , & chan_entry. get ( ) )
3773
+ self . get_htlc_inbound_temp_fail_err_and_data ( 0x1000 |7 , & chan_entry. get ( ) )
3747
3774
} ,
3748
3775
hash_map:: Entry :: Vacant ( _) => ( 0x4000 |10 , Vec :: new ( ) )
3749
3776
} ;
@@ -4633,7 +4660,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4633
4660
match pending_forward_info {
4634
4661
PendingHTLCStatus :: Forward ( PendingHTLCInfo { ref incoming_shared_secret, .. } ) => {
4635
4662
let reason = if ( error_code & 0x1000 ) != 0 {
4636
- let ( real_code, error_data) = self . get_htlc_temp_fail_err_and_data ( error_code, chan) ;
4663
+ let ( real_code, error_data) = self . get_htlc_inbound_temp_fail_err_and_data ( error_code, chan) ;
4637
4664
onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, real_code, & error_data)
4638
4665
} else {
4639
4666
onion_utils:: build_first_hop_failure_packet ( incoming_shared_secret, error_code, & [ ] )
@@ -5626,8 +5653,8 @@ where
5626
5653
let res = f ( channel) ;
5627
5654
if let Ok ( ( funding_locked_opt, mut timed_out_pending_htlcs, announcement_sigs) ) = res {
5628
5655
for ( source, payment_hash) in timed_out_pending_htlcs. drain ( ..) {
5629
- let ( failure_code, data) = self . get_htlc_temp_fail_err_and_data ( 0x1000 |14 /* expiry_too_soon */ , & channel) ;
5630
- timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: Reason {
5656
+ let ( failure_code, data) = self . get_htlc_inbound_temp_fail_err_and_data ( 0x1000 |14 /* expiry_too_soon */ , & channel) ;
5657
+ timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: Reason {
5631
5658
failure_code, data,
5632
5659
} ) ) ;
5633
5660
}
0 commit comments