@@ -2808,7 +2808,10 @@ where
2808
2808
debug_assert_ne!(peer.held_by_thread(), LockHeldState::HeldByThread);
2809
2809
}
2810
2810
2811
- log_debug!(self.logger, "Finishing closure of channel with {} HTLCs to fail", shutdown_res.dropped_outbound_htlcs.len());
2811
+ let logger = WithContext::from(
2812
+ &self.logger, Some(shutdown_res.counterparty_node_id), Some(shutdown_res.channel_id),
2813
+ );
2814
+ log_debug!(logger, "Finishing closure of channel with {} HTLCs to fail", shutdown_res.dropped_outbound_htlcs.len());
2812
2815
for htlc_source in shutdown_res.dropped_outbound_htlcs.drain(..) {
2813
2816
let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
2814
2817
let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
@@ -2967,7 +2970,7 @@ where
2967
2970
}
2968
2971
2969
2972
fn decode_update_add_htlc_onion(
2970
- &self, msg: &msgs::UpdateAddHTLC
2973
+ &self, msg: &msgs::UpdateAddHTLC, counterparty_node_id: &PublicKey,
2971
2974
) -> Result<
2972
2975
(onion_utils::Hop, [u8; 32], Option<Result<PublicKey, secp256k1::Error>>), HTLCFailureMsg
2973
2976
> {
@@ -2986,7 +2989,7 @@ where
2986
2989
($msg: expr, $err_code: expr, $data: expr) => {
2987
2990
{
2988
2991
log_info!(
2989
- WithContext::from(&self.logger, None , Some(msg.channel_id)),
2992
+ WithContext::from(&self.logger, Some(*counterparty_node_id) , Some(msg.channel_id)),
2990
2993
"Failed to accept/forward incoming HTLC: {}", $msg
2991
2994
);
2992
2995
let (err_code, err_data) = if is_blinded {
@@ -3133,13 +3136,15 @@ where
3133
3136
}
3134
3137
3135
3138
fn construct_pending_htlc_status<'a>(
3136
- &self, msg: &msgs::UpdateAddHTLC, shared_secret: [u8; 32], decoded_hop: onion_utils::Hop,
3137
- allow_underpay: bool, next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>
3139
+ &self, msg: &msgs::UpdateAddHTLC, counterparty_node_id: &PublicKey, shared_secret: [u8; 32],
3140
+ decoded_hop: onion_utils::Hop, allow_underpay: bool,
3141
+ next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>,
3138
3142
) -> PendingHTLCStatus {
3139
3143
macro_rules! return_err {
3140
3144
($msg: expr, $err_code: expr, $data: expr) => {
3141
3145
{
3142
- log_info!(WithContext::from(&self.logger, None, Some(msg.channel_id)), "Failed to accept/forward incoming HTLC: {}", $msg);
3146
+ let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(msg.channel_id));
3147
+ log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
3143
3148
return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
3144
3149
channel_id: msg.channel_id,
3145
3150
htlc_id: msg.htlc_id,
@@ -3276,23 +3281,33 @@ where
3276
3281
} = args;
3277
3282
// The top-level caller should hold the total_consistency_lock read lock.
3278
3283
debug_assert!(self.total_consistency_lock.try_write().is_err());
3279
- log_trace!(WithContext::from(&self.logger, Some(path.hops.first().unwrap().pubkey), None),
3280
- "Attempting to send payment with payment hash {} along path with next hop {}",
3281
- payment_hash, path.hops.first().unwrap().short_channel_id);
3282
3284
let prng_seed = self.entropy_source.get_secure_random_bytes();
3283
3285
let session_priv = SecretKey::from_slice(&session_priv_bytes[..]).expect("RNG is busted");
3284
3286
3285
3287
let (onion_packet, htlc_msat, htlc_cltv) = onion_utils::create_payment_onion(
3286
3288
&self.secp_ctx, &path, &session_priv, total_value, recipient_onion, cur_height,
3287
3289
payment_hash, keysend_preimage, prng_seed
3288
- )?;
3290
+ ).map_err(|e| {
3291
+ let logger = WithContext::from(&self.logger, Some(path.hops.first().unwrap().pubkey), None);
3292
+ log_error!(logger, "Failed to build an onion for path for payment hash {}", payment_hash);
3293
+ e
3294
+ })?;
3289
3295
3290
3296
let err: Result<(), _> = loop {
3291
3297
let (counterparty_node_id, id) = match self.short_to_chan_info.read().unwrap().get(&path.hops.first().unwrap().short_channel_id) {
3292
- None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!".to_owned()}),
3298
+ None => {
3299
+ let logger = WithContext::from(&self.logger, Some(path.hops.first().unwrap().pubkey), None);
3300
+ log_error!(logger, "Failed to find first-hop for payment hash {}", payment_hash);
3301
+ return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!".to_owned()})
3302
+ },
3293
3303
Some((cp_id, chan_id)) => (cp_id.clone(), chan_id.clone()),
3294
3304
};
3295
3305
3306
+ let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(id));
3307
+ log_trace!(logger,
3308
+ "Attempting to send payment with payment hash {} along path with next hop {}",
3309
+ payment_hash, path.hops.first().unwrap().short_channel_id);
3310
+
3296
3311
let per_peer_state = self.per_peer_state.read().unwrap();
3297
3312
let peer_state_mutex = per_peer_state.get(&counterparty_node_id)
3298
3313
.ok_or_else(|| APIError::ChannelUnavailable{err: "No peer matching the path's first hop found!".to_owned() })?;
@@ -4044,7 +4059,8 @@ where
4044
4059
None => {
4045
4060
let error = format!("Channel with id {} not found for the passed counterparty node_id {}",
4046
4061
next_hop_channel_id, next_node_id);
4047
- log_error!(self.logger, "{} when attempting to forward intercepted HTLC", error);
4062
+ let logger = WithContext::from(&self.logger, Some(next_node_id), Some(*next_hop_channel_id));
4063
+ log_error!(logger, "{} when attempting to forward intercepted HTLC", error);
4048
4064
return Err(APIError::ChannelUnavailable {
4049
4065
err: error
4050
4066
})
@@ -4132,6 +4148,7 @@ where
4132
4148
4133
4149
for (short_chan_id, mut pending_forwards) in forward_htlcs {
4134
4150
if short_chan_id != 0 {
4151
+ let mut forwarding_counterparty = None;
4135
4152
macro_rules! forwarding_channel_not_found {
4136
4153
() => {
4137
4154
for forward_info in pending_forwards.drain(..) {
@@ -4145,7 +4162,8 @@ where
4145
4162
}) => {
4146
4163
macro_rules! failure_handler {
4147
4164
($msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr, $next_hop_unknown: expr) => {
4148
- log_info!(self.logger, "Failed to accept/forward incoming HTLC: {}", $msg);
4165
+ let logger = WithContext::from(&self.logger, forwarding_counterparty, Some(prev_funding_outpoint.to_channel_id()));
4166
+ log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
4149
4167
4150
4168
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
4151
4169
short_channel_id: prev_short_channel_id,
@@ -4244,6 +4262,7 @@ where
4244
4262
continue;
4245
4263
}
4246
4264
};
4265
+ forwarding_counterparty = Some(counterparty_node_id);
4247
4266
let per_peer_state = self.per_peer_state.read().unwrap();
4248
4267
let peer_state_mutex_opt = per_peer_state.get(&counterparty_node_id);
4249
4268
if peer_state_mutex_opt.is_none() {
@@ -5347,6 +5366,7 @@ where
5347
5366
}
5348
5367
if valid_mpp {
5349
5368
for htlc in sources.drain(..) {
5369
+ let prev_hop_chan_id = htlc.prev_hop.outpoint.to_channel_id();
5350
5370
if let Err((pk, err)) = self.claim_funds_from_hop(
5351
5371
htlc.prev_hop, payment_preimage,
5352
5372
|_, definitely_duplicate| {
@@ -5357,6 +5377,7 @@ where
5357
5377
if let msgs::ErrorAction::IgnoreError = err.err.action {
5358
5378
// We got a temporary failure updating monitor, but will claim the
5359
5379
// HTLC when the monitor updating is restored (or on chain).
5380
+ let logger = WithContext::from(&self.logger, None, Some(prev_hop_chan_id));
5360
5381
log_error!(self.logger, "Temporary failure claiming HTLC, treating as success: {}", err.err.err);
5361
5382
} else { errs.push((pk, err)); }
5362
5383
}
@@ -6455,7 +6476,7 @@ where
6455
6476
// Note that the ChannelManager is NOT re-persisted on disk after this (unless we error
6456
6477
// closing a channel), so any changes are likely to be lost on restart!
6457
6478
6458
- let decoded_hop_res = self.decode_update_add_htlc_onion(msg);
6479
+ let decoded_hop_res = self.decode_update_add_htlc_onion(msg, counterparty_node_id );
6459
6480
let per_peer_state = self.per_peer_state.read().unwrap();
6460
6481
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
6461
6482
.ok_or_else(|| {
@@ -6469,8 +6490,10 @@ where
6469
6490
if let ChannelPhase::Funded(chan) = chan_phase_entry.get_mut() {
6470
6491
let pending_forward_info = match decoded_hop_res {
6471
6492
Ok((next_hop, shared_secret, next_packet_pk_opt)) =>
6472
- self.construct_pending_htlc_status(msg, shared_secret, next_hop,
6473
- chan.context.config().accept_underpaying_htlcs, next_packet_pk_opt),
6493
+ self.construct_pending_htlc_status(
6494
+ msg, counterparty_node_id, shared_secret, next_hop,
6495
+ chan.context.config().accept_underpaying_htlcs, next_packet_pk_opt,
6496
+ ),
6474
6497
Err(e) => PendingHTLCStatus::Fail(e)
6475
6498
};
6476
6499
let create_pending_htlc_status = |chan: &Channel<SP>, pending_forward_info: PendingHTLCStatus, error_code: u16| {
@@ -10014,7 +10037,7 @@ where
10014
10037
log_error!(logger, "A ChannelManager is stale compared to the current ChannelMonitor!");
10015
10038
log_error!(logger, " The channel will be force-closed and the latest commitment transaction from the ChannelMonitor broadcast.");
10016
10039
if channel.context.get_latest_monitor_update_id() < monitor.get_latest_update_id() {
10017
- log_error!(args. logger, " The ChannelMonitor for channel {} is at update_id {} but the ChannelManager is at update_id {}.",
10040
+ log_error!(logger, " The ChannelMonitor for channel {} is at update_id {} but the ChannelManager is at update_id {}.",
10018
10041
&channel.context.channel_id(), monitor.get_latest_update_id(), channel.context.get_latest_monitor_update_id());
10019
10042
}
10020
10043
if channel.get_cur_holder_commitment_transaction_number() > monitor.get_cur_holder_commitment_number() {
@@ -10410,7 +10433,7 @@ where
10410
10433
let counterparty_opt = id_to_peer.get(&monitor.get_funding_txo().0.to_channel_id());
10411
10434
let chan_id = monitor.get_funding_txo().0.to_channel_id();
10412
10435
if counterparty_opt.is_none() {
10413
- let logger = WithContext ::from(&args.logger, None, Some(chan_id) );
10436
+ let logger = WithChannelMonitor ::from(&args.logger, monitor );
10414
10437
for (htlc_source, (htlc, _)) in monitor.get_pending_or_resolved_outbound_htlcs() {
10415
10438
if let HTLCSource::OutboundRoute { payment_id, session_priv, path, .. } = htlc_source {
10416
10439
if path.hops.is_empty() {
0 commit comments