You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to organize a LogMatcher to support many implementations of a same log (e.g. diff btc-core versions), don't think that it'll be difficult but deciding on some pattern it's important.
"ideally, the matcher should return an error on e.g. invalid timestamps and not 0"
if you say this, I assume that an unexpected error on log-extractor parsing problably won't stop its loop, right? If so I'm ok with it.
Before I was thinking that in cases where we don't match the log (even common infos, e.g. timestamp) or get some error while parsing, we could still store the raw message (when Archiver tool - archive events for future analysis and processing #121 is implemented), maybe to debug later
From these, I think the multi-line and and error handling are the next big steps.
I agree with the idea of adding the raw log message to each LogEvent (next to log_timestamp and category). However, at the same time it's probably worth thinking about how to handle multi-line messages. This would mean each LogEvent get's a Vec of log messages attached to it. Also, figuring out how to parse a multi-line log is still open.
bitcoin/bitcoin#32604 implemented log rate-limiting in Bitcoin Core. It would be nice to detect "Excessive logging detected" messages and have a event for it. These only occur when reading from a debug.log file and not when reading from console.
About multiline matching, I've done some sketches. Log extractor could have a state of "pending matchers", LogMatcher trait would change to require two methods:
consume(line: String) -> bool: every incoming log must pass through this method on each LogMatcher implementation. If it returns true, it indicates that this log was succesfully consumed/matched.
get_event() -> Option<Event>: whenever consume(line) returns true, it should try to get the event. If None, it would store in a log extractor's state; otherwise, it would send to NATS.
I suppose multiline logs like bench ones don't get mixed up with something else, but even if it does, I think this structure would handle it fine.
Each LogMatcher would implement this trait in its own way, I will not enforce specific attributes, handling the inner state will be entirely the responsability of the implementation. This prevents unnecessary complexity in cases where it's just a single line.
And surelly, this also needs some state cleanup, I suppose it's hard to happen but it's always good to prevent stale data.
In addition, before sketching this idea, @edilmedeiros suggested to use a callback on LogMatcher that would send the event to NATS when it understands that it's the moment, or something similar. Adapting to my actual idea, I think it would remove get_event requirement and move more responsability to consume method, so before it returns true, it would check if it's "done" with the parsing then call something to send the event to NATS; Or maybe not... we wouldn't know when to remove this from state, it would require something to indicate this, and this could also send to NATS, well, idk; The thing that bothers me more on this, that's causing this "approximation" between LogMatcher and NATS. But if anyone have suggestions on this, please let me know.
I suppose multiline logs like bench ones don't get mixed up with something else, but even if it does, I think this structure would handle it fine.
Sometimes they do IIRC!
From your picture, I'm not sure what the orange and blue lines mean. Are these two possible implementation paths we could take?
More generally, it might be interesting to find out where and how many multiline logs we need to process from a Bitcoin Core node. If it's only the bench logs, we might be albe to do this without adding the complexity of multiline log matching...
The idea of keeping state for a while if we detect the first line of a multiline make sense to me. Fire the NATS event once we have all lines. However, what happens if we miss the first line or the last line (for some reason?). We should discard the state once we read the next "first" line I guess.
From your picture, I'm not sure what the orange and blue lines mean. Are these two possible implementation paths we could take?
I should've explained, my mistake... No, it was to represent an instance of LogMatcher, so the blue one is the same instance in all of this flow -- same for orange, but it isn't stored.
More generally, it might be interesting to find out where and how many multiline logs we need to process from a Bitcoin Core node. If it's only the bench logs, we might be albe to do this without adding the complexity of multiline log matching...
Great point, I can take a look at that.
However, what happens if we miss the first line or the last line (for some reason?). We should discard the state once we read the next "first" line I guess.
I think it wouldn't make sense to send an event partially filled, so I agree we should discard. About discarding at the next "first" line (new event) we see... I think it would be better to consider a "timeout", that way we wouldn't depend on another "new event" happening to cleanup our state 🤔.
More generally, it might be interesting to find out where and how many multiline logs we need to process from a Bitcoin Core node. If it's only the bench logs, we might be albe to do this without adding the complexity of multiline log matching...
I've identified some that maybe could be considered as a multiline but they are not relevant enough. Applying this regex heuristic of having indented logs LogDebug[^"]*" , we have (besides bench):
getblocks (ref code): A p2p message that it's just used by old nodes, so it very rare to see them, the ones starting with "getblocks" seems to be connected;
orphan (ref code): Those may be another one, but I didn't see too much correlation with similar logs; "accepted orphan tx" would be one of the targets.
With that said, I think there's only this "bench" multiline case. So probably "extending" the for loop where the log extractor try to match with many LogMatcher, with maybe another "extra" check for this specific case would be simplier -- it can also be a loop, but with just one case for now. Separating LogMatcher into a MultiLogMatcher seems good to not require more complexity to the other ones -- it would follow the logic from my diagram.
Neat, thanks for looking into it. I agree that these two aren't too relevant.
I think having a bench event for the multi-line bench log (#285 (comment)) could be nice, especially if we can get the block hash and height with it too from UpdateTip: new best=00000012f127f0823149956467d0a1229f4ee51ae95f5025463b8d65e25b2e01 height=268959.
If we can't get the block hash height easily, we can always emit the lines as individual events. This reduces the complexity a lot. For example, for the slow-blocks-on-signet a few weeks back, the Verify 1991 txins: 294.91ms line was very interesting. Plotting this over time or having alerting for a slow verification would already be a good thing to have.
If we can't get the block hash height easily, we can always emit the lines as individual events. This reduces the complexity a lot.
I agree. I see this data as a group, but at the same time, if we don't calculate something within those numbers, in a way that it MUST be connected and not mixed with other ones, it really doesn't need to be sent together (to NATS). Do you see a scenario where we want to, maybe like, do a diff between one measure and another (#285 (comment), e.g., connect total - connect block)?
Other way to look at this, as we in theory just receive this kind of log every 10 min, we don't really mix things up, maybe just for a brief moment between prometheus scrappings. So we could do this kind of calculations fine in grafana 🤔.
especially if we can get the block hash and height with it too
Arguing in favor of sending separate events, how can this be used? Using the already existent height metric as a "related" metric wouldn't be enough? Just curious.
And just a question @0xB10C, I want to help close this issue as it's part of the v1.0 milestone, but as you are incrementing it with some other metrics like rate of attempted outbound connections, however it may be simple, it makes me think if this issue is supposed to be closed or if it is like a "parent" issue for things related to log extractor. What are your thoughts on it? If it is supposed to be closed, it would be good to define a to-do list, set a finish line.
Also, an update on multiline diagram. I've refactored it to a much simpler way, which doesn't add complexity to simple cases (single line). Follow "log extractor" vertical line (time) top to bottom to understand the logic.
global_state.retain_mut(|m| {match m.parse_event(line){MatchResult::Matched(e) => {emit(e);false}MatchResult::Pending => true,MatchResult::NoMatch => false,}});// this part could follow the old logic,// but this would create a necessity for separate traits// e.g. LogMatcher and MultiLogMatcherfor matcher in&static_matchers {matchmatcher(line){MatchResult::Matched(e) => emit(e),MatchResult::Pending(m) => global_state.push(m),MatchResult::NoMatch => {}}}
Problems:
We need to create an instance for every matcher, even non-stateful ones. Could be solved with separate traits.
If we continue to consume only "line" (consume(line)), in multiline logs, we would set log_timestamp as the last event, is that a problem?
Other way to look at this, as we in theory just receive this kind of log every 10 min, we don't really mix things up, maybe just for a brief moment between prometheus scrappings. So we could do this kind of calculations fine in grafana 🤔.
This works in normal operation, but will break in IBD or when catching up blocks. Then these numbers will get mixed up.
And just a question @0xB10C, I want to help close this issue as it's part of the v1.0 milestone, but as you are incrementing it with some other metrics like rate of attempted outbound connections, however it may be simple, it makes me think if this issue is supposed to be closed or if it is like a "parent" issue for things related to log extractor. What are your thoughts on it? If it is supposed to be closed, it would be good to define a to-do list, set a finish line.
Good question. I posted these here to not forget about the idea, but don't think they are particulary pressing. I see this more as a general tracking issue for the log-extractor. Maybe we should have a seperate issue listing task (possibly log-extractor specific or maybe all tasks?) for the 1.0 milestone. A first objective would probably be to go through this and assign priorities and scratch ideas that we don't want to do.
If we continue to consume only "line" (consume(line)), in multiline logs, we would set log_timestamp as the last event, is that a problem?
For bench logs, we might see a parts of the message early, and then nothing for a while during slow-blocks. This would make the timestamp off by a bit, but that's probably not a big problem?
My understanding is that an "instance" is something that matches against one specific log type (e.g. a bench log), correct? Maybe it makes sense for us to sync up on this in a call. I'm feeling I'm missing a bit of context on how this would work.
Activity
0xB10C commentedon Oct 29, 2025
From these, I think the multi-line and and error handling are the next big steps.
I agree with the idea of adding the raw log message to each LogEvent (next to
log_timestampandcategory). However, at the same time it's probably worth thinking about how to handle multi-line messages. This would mean each LogEvent get's a Vec of log messages attached to it. Also, figuring out how to parse a multi-line log is still open.Example of a multi-line log with
-debug=benchis:0xB10C commentedon Oct 29, 2025
Also, add the log extractor to the https://github.com/0xB10C/nix NixOS module and then to and https://github.com/0xB10C/peer-observer-infra-library.
Could probably also use a cool websocket demo of log messages flying by in a web browser.
Before that, #276 might make sense.
0xB10C commentedon Oct 31, 2025
An interesting metric could also be the log size in bytes per category. This would be useful to know in relation to disk-filling attacks:
e.g.
https://bitcoincore.org/en/2025/10/24/disclose-cve-2025-54604/
https://bitcoincore.org/en/2025/10/24/disclose-cve-2025-54605/
0xB10C commentedon Oct 31, 2025
Also, missing docs for log-extractor. See #288
0xB10C commentedon Nov 21, 2025
Recently came across these logs:
And figured it would be nice to have a metric how often we get an INV, but already "have" the transaction already.
0xB10C commentedon Dec 4, 2025
bitcoin/bitcoin#32604 implemented log rate-limiting in Bitcoin Core. It would be nice to detect "Excessive logging detected" messages and have a event for it. These only occur when reading from a debug.log file and not when reading from console.
m4ycon commentedon May 8, 2026
About multiline matching, I've done some sketches. Log extractor could have a state of "pending matchers",
LogMatchertrait would change to require two methods:consume(line: String) -> bool: every incoming log must pass through this method on eachLogMatcherimplementation. If it returnstrue, it indicates that this log was succesfully consumed/matched.get_event() -> Option<Event>: wheneverconsume(line)returnstrue, it should try to get the event. IfNone, it would store in a log extractor's state; otherwise, it would send to NATS.I suppose multiline logs like
benchones don't get mixed up with something else, but even if it does, I think this structure would handle it fine.Each
LogMatcherwould implement this trait in its own way, I will not enforce specific attributes, handling the inner state will be entirely the responsability of the implementation. This prevents unnecessary complexity in cases where it's just a single line.And surelly, this also needs some state cleanup, I suppose it's hard to happen but it's always good to prevent stale data.
In addition, before sketching this idea, @edilmedeiros suggested to use a callback on
LogMatcherthat would send the event to NATS when it understands that it's the moment, or something similar. Adapting to my actual idea, I think it would removeget_eventrequirement and move more responsability toconsumemethod, so before it returnstrue, it would check if it's "done" with the parsing then call something to send the event to NATS; Or maybe not... we wouldn't know when to remove this from state, it would require something to indicate this, and this could also send to NATS, well, idk; The thing that bothers me more on this, that's causing this "approximation" betweenLogMatcherand NATS. But if anyone have suggestions on this, please let me know.Any thoughts @0xB10C?
0xB10C commentedon May 12, 2026
Sometimes they do IIRC!
From your picture, I'm not sure what the orange and blue lines mean. Are these two possible implementation paths we could take?
More generally, it might be interesting to find out where and how many multiline logs we need to process from a Bitcoin Core node. If it's only the bench logs, we might be albe to do this without adding the complexity of multiline log matching...
The idea of keeping state for a while if we detect the first line of a multiline make sense to me. Fire the NATS event once we have all lines. However, what happens if we miss the first line or the last line (for some reason?). We should discard the state once we read the next "first" line I guess.
m4ycon commentedon May 12, 2026
I should've explained, my mistake... No, it was to represent an instance of
LogMatcher, so the blue one is the same instance in all of this flow -- same for orange, but it isn't stored.Great point, I can take a look at that.
I think it wouldn't make sense to send an event partially filled, so I agree we should discard. About discarding at the next "first" line (new event) we see... I think it would be better to consider a "timeout", that way we wouldn't depend on another "new event" happening to cleanup our state 🤔.
m4ycon commentedon May 12, 2026
I've identified some that maybe could be considered as a multiline but they are not relevant enough. Applying this regex heuristic of having indented logs
LogDebug[^"]*", we have (besidesbench):getblocks(ref code): A p2p message that it's just used by old nodes, so it very rare to see them, the ones starting with "getblocks" seems to be connected;orphan(ref code): Those may be another one, but I didn't see too much correlation with similar logs; "accepted orphan tx" would be one of the targets.➜ cat debug.log-20260511-hal | grep 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce 2026-05-11T23:59:46.264116Z [msghand] [mempoolrej] 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5) from peer=34831 was not accepted: bad-txns-inputs-missingorspent 2026-05-11T23:59:46.264220Z [msghand] [txpackages] stored orphan tx 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5), weight: 606 (mapsz 1712 outsz 468) 2026-05-11T23:59:46.264262Z [msghand] [txpackages] added peer=439487 as announcer of orphan tx 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5) 2026-05-11T23:59:46.264302Z [msghand] [txpackages] added peer=5064029 as announcer of orphan tx 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5) 2026-05-11T23:59:46.264354Z [msghand] [txpackages] added peer=12511576 as announcer of orphan tx 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5) 2026-05-11T23:59:46.330594Z [msghand] [txpackages] added peer=10177227 as announcer of orphan tx 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5) 2026-05-11T23:59:46.776476Z [msghand] [txpackages] added 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5) to peer 12511576 workset 2026-05-11T23:59:46.780289Z [msghand] [validation] Enqueuing TransactionAddedToMempool: txid=5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5 2026-05-11T23:59:46.780361Z [msghand] [txpackages] accepted orphan tx 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5) 2026-05-11T23:59:46.780426Z [msghand] [txpackages] removed orphan tx 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5) (5 announcements) 2026-05-11T23:59:46.780456Z [msghand] [mempool] AcceptToMemoryPool: peer=12511576: accepted 5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce (wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5) (poolsz 103815 txn, 236439 kB) 2026-05-11T23:59:46.780475Z [scheduler] [validation] TransactionAddedToMempool: txid=5d41659ef6bd6d23aa70cb2b66250bf006fa8fe048819e90b38a86a8316a19ce wtxid=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5With that said, I think there's only this "bench" multiline case. So probably "extending" the for loop where the log extractor try to match with many
LogMatcher, with maybe another "extra" check for this specific case would be simplier -- it can also be a loop, but with just one case for now. SeparatingLogMatcherinto aMultiLogMatcherseems good to not require more complexity to the other ones -- it would follow the logic from my diagram.0xB10C commentedon May 18, 2026
Neat, thanks for looking into it. I agree that these two aren't too relevant.
I think having a
benchevent for the multi-line bench log (#285 (comment)) could be nice, especially if we can get the block hash and height with it too fromUpdateTip: new best=00000012f127f0823149956467d0a1229f4ee51ae95f5025463b8d65e25b2e01 height=268959.If we can't get the block hash height easily, we can always emit the lines as individual events. This reduces the complexity a lot. For example, for the slow-blocks-on-signet a few weeks back, the
Verify 1991 txins: 294.91msline was very interesting. Plotting this over time or having alerting for a slow verification would already be a good thing to have.0xB10C commentedon May 18, 2026
Unrelated other metrics that I was thinking about that we can get from logs, that I want to note down here:
feelerconnectionsm4ycon commentedon May 19, 2026
I agree. I see this data as a group, but at the same time, if we don't calculate something within those numbers, in a way that it MUST be connected and not mixed with other ones, it really doesn't need to be sent together (to NATS). Do you see a scenario where we want to, maybe like, do a diff between one measure and another (#285 (comment), e.g.,
connect total - connect block)?Other way to look at this, as we in theory just receive this kind of log every 10 min, we don't really mix things up, maybe just for a brief moment between prometheus scrappings. So we could do this kind of calculations fine in grafana 🤔.
Arguing in favor of sending separate events, how can this be used? Using the already existent height metric as a "related" metric wouldn't be enough? Just curious.
And just a question @0xB10C, I want to help close this issue as it's part of the v1.0 milestone, but as you are incrementing it with some other metrics like
rate of attempted outbound connections, however it may be simple, it makes me think if this issue is supposed to be closed or if it is like a "parent" issue for things related to log extractor. What are your thoughts on it? If it is supposed to be closed, it would be good to define a to-do list, set a finish line.m4ycon commentedon May 19, 2026
Also, an update on multiline diagram. I've refactored it to a much simpler way, which doesn't add complexity to simple cases (single line). Follow "log extractor" vertical line (time) top to bottom to understand the logic.
Problems:
consume(line)), in multiline logs, we would set log_timestamp as the last event, is that a problem?0xB10C commentedon May 20, 2026
This works in normal operation, but will break in IBD or when catching up blocks. Then these numbers will get mixed up.
0xB10C commentedon May 20, 2026
Good question. I posted these here to not forget about the idea, but don't think they are particulary pressing. I see this more as a general tracking issue for the log-extractor. Maybe we should have a seperate issue listing task (possibly log-extractor specific or maybe all tasks?) for the 1.0 milestone. A first objective would probably be to go through this and assign priorities and scratch ideas that we don't want to do.
0xB10C commentedon May 20, 2026
For bench logs, we might see a parts of the message early, and then nothing for a while during slow-blocks. This would make the timestamp off by a bit, but that's probably not a big problem?
regarding #285 (comment)
My understanding is that an "instance" is something that matches against one specific log type (e.g. a bench log), correct? Maybe it makes sense for us to sync up on this in a call. I'm feeling I'm missing a bit of context on how this would work.