Skip to content

Commit 9e69922

Browse files
committed
Include payment hash in more early payment logs
If a user has issues with a payment, the most obvious thing they'll do is check logs for the payment hash. Thus, we should ensure our logs that show a payment's lifecycle include the payment hash and are emitted (a) as soon as LDK learns of the payment, (b) once the payment goes out to the peer (which is already reasonably covered in the commitment transaction building logs) and (c) when the payment ultimately is fulfilled or fails. Here we improve our logs for both (a) and (c).
1 parent 0c25046 commit 9e69922

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

lightning/src/ln/channel.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,8 @@ impl<SP: Deref> Channel<SP> where
22172217
for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
22182218
if htlc.htlc_id == htlc_id_arg {
22192219
assert_eq!(htlc.payment_hash, payment_hash_calc);
2220+
log_debug!(logger, "Claiming inbound HTLC id {} with payment hash {} with preimage {}",
2221+
htlc.htlc_id, htlc.payment_hash, payment_preimage_arg);
22202222
match htlc.state {
22212223
InboundHTLCState::Committed => {},
22222224
InboundHTLCState::LocalRemoved(ref reason) => {
@@ -5210,7 +5212,8 @@ impl<SP: Deref> Channel<SP> where
52105212
}
52115213

52125214
let need_holding_cell = (self.context.channel_state & (ChannelState::AwaitingRemoteRevoke as u32 | ChannelState::MonitorUpdateInProgress as u32)) != 0;
5213-
log_debug!(logger, "Pushing new outbound HTLC for {} msat {}", amount_msat,
5215+
log_debug!(logger, "Pushing new outbound HTLC with hash {} for {} msat {}",
5216+
payment_hash, amount_msat,
52145217
if force_holding_cell { "into holding cell" }
52155218
else if need_holding_cell { "into holding cell as we're awaiting an RAA or monitor" }
52165219
else { "to peer" });

lightning/src/ln/channelmanager.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3210,7 +3210,9 @@ where
32103210
// The top-level caller should hold the total_consistency_lock read lock.
32113211
debug_assert!(self.total_consistency_lock.try_write().is_err());
32123212

3213-
log_trace!(self.logger, "Attempting to send payment for path with next hop {}", path.hops.first().unwrap().short_channel_id);
3213+
log_trace!(self.logger,
3214+
"Attempting to send payment with payment hash {} along path with next hop {}",
3215+
payment_hash, path.hops.first().unwrap().short_channel_id);
32143216
let prng_seed = self.entropy_source.get_secure_random_bytes();
32153217
let session_priv = SecretKey::from_slice(&session_priv_bytes[..]).expect("RNG is busted");
32163218

lightning/src/ln/outbound_payment.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,8 @@ impl OutboundPayments {
722722
{
723723
#[cfg(feature = "std")] {
724724
if has_expired(&route_params) {
725+
log_error!(logger, "Payment with id {} and hash {} had expired before we started paying",
726+
payment_id, payment_hash);
725727
return Err(RetryableSendFailure::PaymentExpired)
726728
}
727729
}
@@ -730,16 +732,25 @@ impl OutboundPayments {
730732
&node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
731733
Some(&first_hops.iter().collect::<Vec<_>>()), inflight_htlcs(),
732734
payment_hash, payment_id,
733-
).map_err(|_| RetryableSendFailure::RouteNotFound)?;
735+
).map_err(|_| {
736+
log_error!(logger, "Failed to find route for payment with id {} and hash {}",
737+
payment_id, payment_hash);
738+
RetryableSendFailure::RouteNotFound
739+
})?;
734740

735741
let onion_session_privs = self.add_new_pending_payment(payment_hash,
736742
recipient_onion.clone(), payment_id, keysend_preimage, &route, Some(retry_strategy),
737743
Some(route_params.payment_params.clone()), entropy_source, best_block_height)
738-
.map_err(|_| RetryableSendFailure::DuplicatePayment)?;
744+
.map_err(|_| {
745+
log_error!(logger, "Payment with id {} is already pending. New payment had payment hash {}",
746+
payment_id, payment_hash);
747+
RetryableSendFailure::DuplicatePayment
748+
})?;
739749

740750
let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage, payment_id, None,
741751
onion_session_privs, node_signer, best_block_height, &send_payment_along_path);
742-
log_info!(logger, "Result sending payment with id {}: {:?}", &payment_id, res);
752+
log_info!(logger, "Sending payment with id {} and hash {} returned {:?}",
753+
payment_id, payment_hash, res);
743754
if let Err(e) = res {
744755
self.handle_pay_route_err(e, payment_id, payment_hash, route, route_params, router, first_hops, &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path);
745756
}
@@ -1188,6 +1199,7 @@ impl OutboundPayments {
11881199
if let hash_map::Entry::Occupied(mut payment) = outbounds.entry(payment_id) {
11891200
if !payment.get().is_fulfilled() {
11901201
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
1202+
log_info!(logger, "Payment with id {} and hash {} sent!", payment_id, payment_hash);
11911203
let fee_paid_msat = payment.get().get_pending_fee_msat();
11921204
pending_events.push_back((events::Event::PaymentSent {
11931205
payment_id: Some(payment_id),

0 commit comments

Comments
 (0)