Skip to content

Commit 5776c43

Browse files
committed
Use context logs in process_pending_htlc_forwards
Utilise `WithChannelContext` instead of using `self.logger` in `ChannelManager::process_pending_htlc_forwards`.
1 parent 232d6af commit 5776c43

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5415,6 +5415,23 @@ where
54155415
panic!("short_channel_id == 0 should imply any pending_forward entries are of type Receive");
54165416
}
54175417
};
5418+
5419+
let chan_info_opt = self.short_to_chan_info.read().unwrap().get(&short_chan_id).cloned();
5420+
let mut logger = LogContext::Module(&self.logger);
5421+
match chan_info_opt {
5422+
Some((counterparty_node_id, forward_chan_id)) => {
5423+
let per_peer_state = self.per_peer_state.read().unwrap();
5424+
if let Some(peer_state_mutex) = per_peer_state.get(&counterparty_node_id) {
5425+
if let Ok(mut peer_state_lock) = peer_state_mutex.lock() {
5426+
let peer_state = &mut *peer_state_lock;
5427+
if let Some(chan) = peer_state.channel_by_id.get_mut(&forward_chan_id) {
5428+
logger = LogContext::ChannelContext(WithChannelContext::from(&self.logger, chan.context(), Some(payment_hash)));
5429+
}
5430+
}
5431+
}
5432+
}
5433+
_ => {}
5434+
};
54185435
let claimable_htlc = ClaimableHTLC {
54195436
prev_hop: HTLCPreviousHopData {
54205437
short_channel_id: prev_short_channel_id,
@@ -5490,11 +5507,11 @@ where
54905507
});
54915508
if $purpose != claimable_payment.purpose {
54925509
let log_keysend = |keysend| if keysend { "keysend" } else { "non-keysend" };
5493-
log_trace!(self.logger, "Failing new {} HTLC with payment_hash {} as we already had an existing {} HTLC with the same payment hash", log_keysend(is_keysend), &payment_hash, log_keysend(!is_keysend));
5510+
log_trace!(logger, "Failing new {} HTLC with payment_hash {} as we already had an existing {} HTLC with the same payment hash", log_keysend(is_keysend), &payment_hash, log_keysend(!is_keysend));
54945511
fail_htlc!(claimable_htlc, payment_hash);
54955512
}
54965513
if !self.default_configuration.accept_mpp_keysend && is_keysend && !claimable_payment.htlcs.is_empty() {
5497-
log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} as we already had an existing keysend HTLC with the same payment hash and our config states we don't accept MPP keysend", &payment_hash);
5514+
log_trace!(logger, "Failing new keysend HTLC with payment_hash {} as we already had an existing keysend HTLC with the same payment hash and our config states we don't accept MPP keysend", &payment_hash);
54985515
fail_htlc!(claimable_htlc, payment_hash);
54995516
}
55005517
if let Some(earlier_fields) = &mut claimable_payment.onion_fields {
@@ -5511,7 +5528,7 @@ where
55115528
total_value += htlc.sender_intended_value;
55125529
earliest_expiry = cmp::min(earliest_expiry, htlc.cltv_expiry);
55135530
if htlc.total_msat != claimable_htlc.total_msat {
5514-
log_trace!(self.logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})",
5531+
log_trace!(logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})",
55155532
&payment_hash, claimable_htlc.total_msat, htlc.total_msat);
55165533
total_value = msgs::MAX_VALUE_MSAT;
55175534
}
@@ -5522,7 +5539,7 @@ where
55225539
if total_value >= msgs::MAX_VALUE_MSAT {
55235540
fail_htlc!(claimable_htlc, payment_hash);
55245541
} else if total_value - claimable_htlc.sender_intended_value >= claimable_htlc.total_msat {
5525-
log_trace!(self.logger, "Failing HTLC with payment_hash {} as payment is already claimable",
5542+
log_trace!(logger, "Failing HTLC with payment_hash {} as payment is already claimable",
55265543
&payment_hash);
55275544
fail_htlc!(claimable_htlc, payment_hash);
55285545
} else if total_value >= claimable_htlc.total_msat {
@@ -5573,17 +5590,17 @@ where
55735590
match claimable_htlc.onion_payload {
55745591
OnionPayload::Invoice { .. } => {
55755592
let payment_data = payment_data.unwrap();
5576-
let (payment_preimage, min_final_cltv_expiry_delta) = match inbound_payment::verify(payment_hash, &payment_data, self.highest_seen_timestamp.load(Ordering::Acquire) as u64, &self.inbound_payment_key, &self.logger) {
5593+
let (payment_preimage, min_final_cltv_expiry_delta) = match inbound_payment::verify(payment_hash, &payment_data, self.highest_seen_timestamp.load(Ordering::Acquire) as u64, &self.inbound_payment_key, logger.deref()) {
55775594
Ok(result) => result,
55785595
Err(()) => {
5579-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as payment verification failed", &payment_hash);
5596+
log_trace!(logger, "Failing new HTLC with payment_hash {} as payment verification failed", &payment_hash);
55805597
fail_htlc!(claimable_htlc, payment_hash);
55815598
}
55825599
};
55835600
if let Some(min_final_cltv_expiry_delta) = min_final_cltv_expiry_delta {
55845601
let expected_min_expiry_height = (self.current_best_block().height + min_final_cltv_expiry_delta as u32) as u64;
55855602
if (cltv_expiry as u64) < expected_min_expiry_height {
5586-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as its CLTV expiry was too soon (had {}, earliest expected {})",
5603+
log_trace!(logger, "Failing new HTLC with payment_hash {} as its CLTV expiry was too soon (had {}, earliest expected {})",
55875604
&payment_hash, cltv_expiry, expected_min_expiry_height);
55885605
fail_htlc!(claimable_htlc, payment_hash);
55895606
}
@@ -5603,15 +5620,15 @@ where
56035620
},
56045621
hash_map::Entry::Occupied(inbound_payment) => {
56055622
if let OnionPayload::Spontaneous(_) = claimable_htlc.onion_payload {
5606-
log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} because we already have an inbound payment with the same payment hash", &payment_hash);
5623+
log_trace!(logger, "Failing new keysend HTLC with payment_hash {} because we already have an inbound payment with the same payment hash", &payment_hash);
56075624
fail_htlc!(claimable_htlc, payment_hash);
56085625
}
56095626
let payment_data = payment_data.unwrap();
56105627
if inbound_payment.get().payment_secret != payment_data.payment_secret {
5611-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as it didn't match our expected payment secret.", &payment_hash);
5628+
log_trace!(logger, "Failing new HTLC with payment_hash {} as it didn't match our expected payment secret.", &payment_hash);
56125629
fail_htlc!(claimable_htlc, payment_hash);
56135630
} else if inbound_payment.get().min_value_msat.is_some() && payment_data.total_msat < inbound_payment.get().min_value_msat.unwrap() {
5614-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as it didn't match our minimum value (had {}, needed {}).",
5631+
log_trace!(logger, "Failing new HTLC with payment_hash {} as it didn't match our minimum value (had {}, needed {}).",
56155632
&payment_hash, payment_data.total_msat, inbound_payment.get().min_value_msat.unwrap());
56165633
fail_htlc!(claimable_htlc, payment_hash);
56175634
} else {

0 commit comments

Comments
 (0)