-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add peer_id and channel_id explicitly to log records #2314
Conversation
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #2314 +/- ##
==========================================
- Coverage 88.64% 88.51% -0.13%
==========================================
Files 115 113 -2
Lines 90023 89550 -473
Branches 90023 89550 -473
==========================================
- Hits 79801 79266 -535
- Misses 7825 7904 +79
+ Partials 2397 2380 -17 ☔ View full report in Codecov by Sentry. |
bdf0de5
to
2c69caf
Compare
8bb0617
to
8748f91
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Sorry for the delay in getting back to you.
377116a
to
32eb894
Compare
8515d27
to
4f941bc
Compare
Probably a crude attempt right now, defining the mappings at the top of the files themselves. would prefer to do all the mapping up front in the mod.rs files or elsewhere and also have a sensible default. just putting it out there, not feeling too strongly abt this approach yet |
This patch works for me, so I think we should go this kind of direction (with different diff --git a/lightning/src/chain/package.rs b/lightning/src/chain/package.rs
index 4604a164c..6c2c9c706 100644
--- a/lightning/src/chain/package.rs
+++ b/lightning/src/chain/package.rs
@@ -44,4 +44,6 @@ use bitcoin::{PackedLockTime, Sequence, Witness};
use super::chaininterface::LowerBoundedFeeEstimator;
+use crate::util::macro_logger::log_warn;
+
const MAX_ALLOC_SIZE: usize = 64*1024;
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 99b3c1691..fc9439efa 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -53,4 +53,6 @@ use crate::sync::Mutex;
use bitcoin::hashes::hex::ToHex;
+use crate::util::macro_logger::log_warn;
+
#[cfg(test)]
pub struct ChannelValueStat {
diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs
index 235b1a148..56ebceefb 100644
--- a/lightning/src/routing/scoring.rs
+++ b/lightning/src/routing/scoring.rs
@@ -62,4 +62,5 @@ use crate::routing::router::Path;
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
use crate::util::logger::Logger;
+use crate::util::macro_logger::log_warn;
use crate::util::time::Time;
diff --git a/lightning/src/util/macro_logger.rs b/lightning/src/util/macro_logger.rs
index 8742e8e84..42d74767b 100644
--- a/lightning/src/util/macro_logger.rs
+++ b/lightning/src/util/macro_logger.rs
@@ -199,5 +199,5 @@ macro_rules! log_error {
/// Log at the `WARN` level.
#[macro_export]
-macro_rules! log_warn {
+macro_rules! _log_warn {
($logger: expr, $($arg:tt)*) => (
$crate::log_given_level!($logger, $crate::util::logger::Level::Warn, $($arg)*);
@@ -205,4 +205,6 @@ macro_rules! log_warn {
}
+pub use _log_warn as log_warn;
+
/// Log at the `INFO` level.
#[macro_export] |
062c703
to
da9f77c
Compare
Rebased on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just skimmed, but basically LGTM. We might as well land this.
lightning/src/chain/chainmonitor.rs
Outdated
@@ -799,12 +808,16 @@ where C::Target: chain::Filter, | |||
} | |||
}; | |||
if let ChannelMonitorUpdateStatus::UnrecoverableError = ret { | |||
let logger = WithChannelMonitor::from( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets move this code lock into the Some
match and drop the unwrap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, refactored the code slightly to allow for this.
@@ -1125,6 +1125,30 @@ macro_rules! _process_events_body { | |||
} | |||
pub(super) use _process_events_body as process_events_body; | |||
|
|||
pub(crate) struct WithChannelMonitor<'a, L: Deref> where L::Target: Logger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to move some of the pub(crate) methods on ChannelMonitor
to take a WithChannelMonitor
explicitly, rather than a generic Logger
, so that we enforce that its called correctly. It can happen later, though. Same in channel.rs, but the channel type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tend to agree that we should make this more enforceable. Ideally, we can just have those structs store a wrapped Logger
instead of passing one and relying on the caller to do the wrapping. Though, I think that may mean introducing a lifetime parameter.
But if instead we make the types explicit on pub(crate)
methods, then we may avoid some redundant wrapping. Let me take a look.
Pushed a few fixups and I think an amended commit that I hadn't pushed last week. |
Ugh, also a rebase apparently 😞 |
Just a bad push, actually. This should be the right diff: https://github.com/lightningdevkit/rust-lightning/compare/35b768825950c81bee510d2a80cd19c926b817a6..189ea78eca81e86e3be9d561eaf005e669a7d51e |
@TheBlueMatt Looks like I'll need to rebase this again. |
I'm kinda ready to land whenever you want to squash and rebase, will just take me an hour to go back over it and hit the button. |
Ugh, needs rebase again lol |
Instead of passing a reference to a Record, pass the Logger an owned Record so that it can be decorated with semantic context.
Include optional peer and channel ids to logger::Record. This will be used by wrappers around Logger in order to provide more context (e.g., the peer that sent a message, the channel an operation is pertaining to, etc.). Implementations of Logger can include this as metadata to aid in searching logs.
Using a decorator pattern, add peer_id and channel_id to Record stored on Logger.
Move the handling of ChannelMonitorUpdateStatus::UnrecoverableError to the point of error to avoid needing an unwrap later when re-wrapping the logger.
Rebased! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some followups, but we need to just land this so that we can move on.
&self, module: &str, peer_id: Option<PublicKey>, channel_id: Option<ChannelId>, count: usize | ||
) { | ||
let context_entries = self.context.lock().unwrap(); | ||
let l: usize = context_entries.iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a hashmap, we can look up, rather than iterate + count.
} | ||
} | ||
|
||
impl<'a, 'b, L: Deref> WithChannelContext<'a, L> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe 'b can be elided.
} | ||
} | ||
|
||
impl<'a, 'b, L: Deref> WithChannelMonitor<'a, L> where L::Target: Logger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe 'b can be elided.
ChannelMonitorUpdateStatus::UnrecoverableError => { | ||
// Take the monitors lock for writing so that we poison it and any future | ||
// operations going forward fail immediately. | ||
core::mem::drop(monitors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this no longer drops the lock itself, we'll just hang on the next line rather than actually panicking.
fixes #2292
This change adds explicit spots in the log Record struct for peer_id and channel_id
This makes the logs much more structured and ensure that they are not forgetten
during implementation