Skip to content

Commit 5e64c40

Browse files
committed
Require WithContext log wrappers on OutboundPayments calls
In much of LDK we pass around `Logger` objects both to avoid having to `Clone` `Logger` `Deref`s (soon to only be `Logger`s) and to allow us to set context with a wrapper such that any log calls on that wrapper get additional useful metadata in them. Sadly, when we added a `Logger` type to `OutboundPayments` we broke the ability to do the second thing - payment information logged directly or indirectly via logic in the `OutboundPayments` has no context making log-searching rather challenging. Here we fix this by retunring to passing loggers explicitly to `OutboundPayments` methods that need them, specifically requiring `WithContext` wrappers to ensure the callsite sets appropriate context on the logger. Fixes #4307
1 parent 0f253c0 commit 5e64c40

2 files changed

Lines changed: 175 additions & 129 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ pub struct ChannelManager<
26722672
/// after reloading from disk while replaying blocks against ChannelMonitors.
26732673
///
26742674
/// See `PendingOutboundPayment` documentation for more info.
2675-
pending_outbound_payments: OutboundPayments<L>,
2675+
pending_outbound_payments: OutboundPayments,
26762676

26772677
/// SCID/SCID Alias -> forward infos. Key of 0 means payments received.
26782678
///
@@ -3485,7 +3485,7 @@ where
34853485
best_block: RwLock::new(params.best_block),
34863486

34873487
outbound_scid_aliases: Mutex::new(new_hash_set()),
3488-
pending_outbound_payments: OutboundPayments::new(new_hash_map(), logger.clone()),
3488+
pending_outbound_payments: OutboundPayments::new(new_hash_map()),
34893489
forward_htlcs: Mutex::new(new_hash_map()),
34903490
decode_update_add_htlcs: Mutex::new(new_hash_map()),
34913491
claimable_payments: Mutex::new(ClaimablePayments { claimable_payments: new_hash_map(), pending_claiming_payments: new_hash_map() }),
@@ -5354,11 +5354,12 @@ where
53545354
});
53555355
if route.route_params.is_none() { route.route_params = Some(route_params.clone()); }
53565356
let router = FixedRouter::new(route);
5357+
let logger = WithContext::from(&self.logger, None, None, Some(payment_hash));
53575358
self.pending_outbound_payments
53585359
.send_payment(payment_hash, recipient_onion, payment_id, Retry::Attempts(0),
53595360
route_params, &&router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
53605361
&self.entropy_source, &self.node_signer, best_block_height,
5361-
&self.pending_events, |args| self.send_payment_along_path(args))
5362+
&self.pending_events, |args| self.send_payment_along_path(args), &logger)
53625363
}
53635364

53645365
/// Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
@@ -5418,6 +5419,7 @@ where
54185419
best_block_height,
54195420
&self.pending_events,
54205421
|args| self.send_payment_along_path(args),
5422+
&WithContext::from(&self.logger, None, None, Some(payment_hash)),
54215423
)
54225424
}
54235425

@@ -5516,6 +5518,7 @@ where
55165518
best_block_height,
55175519
&self.pending_events,
55185520
|args| self.send_payment_along_path(args),
5521+
&WithContext::from(&self.logger, None, None, Some(invoice.payment_hash())),
55195522
)
55205523
}
55215524

@@ -5568,6 +5571,7 @@ where
55685571
best_block_height,
55695572
&self.pending_events,
55705573
|args| self.send_payment_along_path(args),
5574+
&WithContext::from(&self.logger, None, None, None),
55715575
)
55725576
}
55735577

@@ -5748,6 +5752,7 @@ where
57485752
best_block_height,
57495753
&self.pending_events,
57505754
|args| self.send_payment_along_path(args),
5755+
&WithContext::from(&self.logger, None, None, None),
57515756
)
57525757
}
57535758

@@ -5826,6 +5831,7 @@ where
58265831
) -> Result<PaymentHash, RetryableSendFailure> {
58275832
let best_block_height = self.best_block.read().unwrap().height;
58285833
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
5834+
let payment_hash = payment_preimage.map(|preimage| preimage.into());
58295835
self.pending_outbound_payments.send_spontaneous_payment(
58305836
payment_preimage,
58315837
recipient_onion,
@@ -5840,6 +5846,7 @@ where
58405846
best_block_height,
58415847
&self.pending_events,
58425848
|args| self.send_payment_along_path(args),
5849+
&WithContext::from(&self.logger, None, None, payment_hash),
58435850
)
58445851
}
58455852

@@ -7252,6 +7259,7 @@ where
72527259
best_block_height,
72537260
&self.pending_events,
72547261
|args| self.send_payment_along_path(args),
7262+
&WithContext::from(&self.logger, None, None, None),
72557263
);
72567264
if needs_persist {
72577265
should_persist = NotifyOption::DoPersist;
@@ -8644,6 +8652,7 @@ where
86448652
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
86458653
match source {
86468654
HTLCSource::OutboundRoute { ref path, ref session_priv, ref payment_id, .. } => {
8655+
let logger = WithContext::from(&self.logger, None, None, Some(*payment_hash));
86478656
self.pending_outbound_payments.fail_htlc(
86488657
source,
86498658
payment_hash,
@@ -8655,6 +8664,7 @@ where
86558664
&self.secp_ctx,
86568665
&self.pending_events,
86578666
&mut from_monitor_update_completion,
8667+
&logger,
86588668
);
86598669
if let Some(update) = from_monitor_update_completion {
86608670
// If `fail_htlc` didn't `take` the post-event action, we should go ahead and
@@ -9345,6 +9355,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
93459355
from_onchain,
93469356
&mut ev_completion_action,
93479357
&self.pending_events,
9358+
&WithContext::from(&self.logger, None, None, Some(payment_preimage.into())),
93489359
);
93499360
// If an event was generated, `claim_htlc` set `ev_completion_action` to None, if
93509361
// not, we should go ahead and run it now (as the claim was duplicative), at least
@@ -18064,8 +18075,7 @@ where
1806418075
}
1806518076
pending_outbound_payments = Some(outbounds);
1806618077
}
18067-
let pending_outbounds =
18068-
OutboundPayments::new(pending_outbound_payments.unwrap(), args.logger.clone());
18078+
let pending_outbounds = OutboundPayments::new(pending_outbound_payments.unwrap());
1806918079

1807018080
for (peer_pubkey, peer_storage) in peer_storage_dir {
1807118081
if let Some(peer_state) = per_peer_state.get_mut(&peer_pubkey) {
@@ -18418,6 +18428,7 @@ where
1841818428
session_priv_bytes,
1841918429
&path,
1842018430
best_block_height,
18431+
&logger,
1842118432
);
1842218433
}
1842318434
}
@@ -18452,7 +18463,7 @@ where
1845218463
&mut decode_update_add_htlcs,
1845318464
&prev_hop_data,
1845418465
"HTLC already forwarded to the outbound edge",
18455-
&args.logger,
18466+
&&logger,
1845618467
);
1845718468
}
1845818469

@@ -18469,7 +18480,7 @@ where
1846918480
&mut decode_update_add_htlcs_legacy,
1847018481
&prev_hop_data,
1847118482
"HTLC was forwarded to the closed channel",
18472-
&args.logger,
18483+
&&logger,
1847318484
);
1847418485
forward_htlcs_legacy.retain(|_, forwards| {
1847518486
forwards.retain(|forward| {
@@ -18526,6 +18537,7 @@ where
1852618537
true,
1852718538
&mut compl_action,
1852818539
&pending_events,
18540+
&logger,
1852918541
);
1853018542
// If the completion action was not consumed, then there was no
1853118543
// payment to claim, and we need to tell the `ChannelMonitor`
@@ -18579,8 +18591,10 @@ where
1857918591
}
1858018592
}
1858118593
for (htlc_source, payment_hash) in monitor.get_onchain_failed_outbound_htlcs() {
18594+
let logger =
18595+
WithChannelMonitor::from(&args.logger, monitor, Some(payment_hash));
1858218596
log_info!(
18583-
args.logger,
18597+
logger,
1858418598
"Failing HTLC with payment hash {} as it was resolved on-chain.",
1858518599
payment_hash
1858618600
);
@@ -18648,6 +18662,11 @@ where
1864818662
// inbound edge of the payment's monitor has already claimed
1864918663
// the HTLC) we skip trying to replay the claim.
1865018664
let htlc_payment_hash: PaymentHash = payment_preimage.into();
18665+
let logger = WithChannelMonitor::from(
18666+
&args.logger,
18667+
monitor,
18668+
Some(htlc_payment_hash),
18669+
);
1865118670
let balance_could_incl_htlc = |bal| match bal {
1865218671
&Balance::ClaimableOnChannelClose { .. } => {
1865318672
// The channel is still open, assume we can still
@@ -18670,7 +18689,7 @@ where
1867018689
// edge monitor but the channel is closed (and thus we'll
1867118690
// immediately panic if we call claim_funds_from_hop).
1867218691
if short_to_chan_info.get(&prev_hop.prev_outbound_scid_alias).is_none() {
18673-
log_error!(args.logger,
18692+
log_error!(logger,
1867418693
"We need to replay the HTLC claim for payment_hash {} (preimage {}) but cannot do so as the HTLC was forwarded prior to LDK 0.0.124.\
1867518694
All HTLCs that were forwarded by LDK 0.0.123 and prior must be resolved prior to upgrading to LDK 0.1",
1867618695
htlc_payment_hash,
@@ -18685,7 +18704,7 @@ where
1868518704
// of panicking at runtime. The user ideally should have read
1868618705
// the release notes and we wouldn't be here, but we go ahead
1868718706
// and let things run in the hope that it'll all just work out.
18688-
log_error!(args.logger,
18707+
log_error!(logger,
1868918708
"We need to replay the HTLC claim for payment_hash {} (preimage {}) but don't have all the required information to do so reliably.\
1869018709
As long as the channel for the inbound edge of the forward remains open, this may work okay, but we may panic at runtime!\
1869118710
All HTLCs that were forwarded by LDK 0.0.123 and prior must be resolved prior to upgrading to LDK 0.1\

0 commit comments

Comments
 (0)