Skip to content

Commit bbe20c3

Browse files
authored
Merge pull request #2515 from TheBlueMatt/2023-08-earlier-payment-hash-log
Include payment hash in more early payment logs
2 parents 32d6e91 + 5a1f212 commit bbe20c3

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

lightning/src/ln/channel.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2206,8 +2206,6 @@ impl<SP: Deref> Channel<SP> where
22062206
}
22072207
assert_eq!(self.context.channel_state & ChannelState::ShutdownComplete as u32, 0);
22082208

2209-
let payment_hash_calc = PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).into_inner());
2210-
22112209
// ChannelManager may generate duplicate claims/fails due to HTLC update events from
22122210
// on-chain ChannelsMonitors during block rescan. Ideally we'd figure out a way to drop
22132211
// these, but for now we just have to treat them as normal.
@@ -2216,7 +2214,9 @@ impl<SP: Deref> Channel<SP> where
22162214
let mut htlc_value_msat = 0;
22172215
for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
22182216
if htlc.htlc_id == htlc_id_arg {
2219-
assert_eq!(htlc.payment_hash, payment_hash_calc);
2217+
debug_assert_eq!(htlc.payment_hash, PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).into_inner()));
2218+
log_debug!(logger, "Claiming inbound HTLC id {} with payment hash {} with preimage {}",
2219+
htlc.htlc_id, htlc.payment_hash, payment_preimage_arg);
22202220
match htlc.state {
22212221
InboundHTLCState::Committed => {},
22222222
InboundHTLCState::LocalRemoved(ref reason) => {
@@ -5216,7 +5216,8 @@ impl<SP: Deref> Channel<SP> where
52165216
}
52175217

52185218
let need_holding_cell = (self.context.channel_state & (ChannelState::AwaitingRemoteRevoke as u32 | ChannelState::MonitorUpdateInProgress as u32)) != 0;
5219-
log_debug!(logger, "Pushing new outbound HTLC for {} msat {}", amount_msat,
5219+
log_debug!(logger, "Pushing new outbound HTLC with hash {} for {} msat {}",
5220+
payment_hash, amount_msat,
52205221
if force_holding_cell { "into holding cell" }
52215222
else if need_holding_cell { "into holding cell as we're awaiting an RAA or monitor" }
52225223
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)