Skip to content

Commit 57a91f0

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 ad2cd84 commit 57a91f0

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
@@ -2213,6 +2213,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
22132213
for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
22142214
if htlc.htlc_id == htlc_id_arg {
22152215
assert_eq!(htlc.payment_hash, payment_hash_calc);
2216+
log_debug!(logger, "Claiming inbound HTLC id {} with payment hash {} with preimage {}",
2217+
htlc.htlc_id, htlc.payment_hash, payment_preimage_arg);
22162218
match htlc.state {
22172219
InboundHTLCState::Committed => {},
22182220
InboundHTLCState::LocalRemoved(ref reason) => {
@@ -5188,7 +5190,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
51885190
}
51895191

51905192
let need_holding_cell = (self.context.channel_state & (ChannelState::AwaitingRemoteRevoke as u32 | ChannelState::MonitorUpdateInProgress as u32)) != 0;
5191-
log_debug!(logger, "Pushing new outbound HTLC for {} msat {}", amount_msat,
5193+
log_debug!(logger, "Pushing new outbound HTLC with hash {} for {} msat {}",
5194+
payment_hash, amount_msat,
51925195
if force_holding_cell { "into holding cell" }
51935196
else if need_holding_cell { "into holding cell as we're awaiting an RAA or monitor" }
51945197
else { "to peer" });

lightning/src/ln/channelmanager.rs

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

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

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)