Skip to content

log-extractor followups #285

Open
Open

Description

@0xB10C

In #272, @m4ycon implemented a basic log extractor that reads Bitcoin Core debug.logs and produces events for parsed log messages.

A few followups include:

from @0xB10C in #272 (comment)

  • add more matchers for different log messages
  • add support for multiline matching. e.g. the bench block connection logs
  • look into fuzzing the matcher input to see if it breaks somewhere
  • ideally, the matcher should return an error on e.g. invalid timestamps and not 0

from @m4ycon in #272 (comment)

  • 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.

Activity

  1. 0xB10C commented on Oct 29, 2025

    @0xB10C
    CollaboratorAuthor

    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.

    Example of a multi-line log with -debug=bench is:

    2025-10-29T17:04:43Z [bench] - Connect block: 273.88ms [0.66s (331.65ms/blk)]
    2025-10-29T17:04:43Z [bench]   - Using cached block
    2025-10-29T17:04:43Z [bench]   - Load block from disk: 0.02ms
    2025-10-29T17:04:43Z [bench]     - Sanity checks: 0.00ms [0.00s (0.00ms/blk)]
    2025-10-29T17:04:43Z [bench]     - Fork checks: 11.38ms [0.05s (15.74ms/blk)]
    2025-10-29T17:04:43Z [bench]       - Connect 991 transactions: 294.78ms (0.297ms/tx, 0.148ms/txin) [0.91s (304.52ms/blk)]
    2025-10-29T17:04:43Z [bench]     - Verify 1991 txins: 294.91ms (0.148ms/txin) [0.91s (304.66ms/blk)]
    2025-10-29T17:04:43Z [bench]     - Write undo data: 1.51ms [0.00s (1.58ms/blk)]
    2025-10-29T17:04:43Z [bench]     - Index writing: 0.01ms [0.00s (0.02ms/blk)]
    2025-10-29T17:04:43Z [bench]   - Connect total: 308.13ms [0.97s (322.29ms/blk)]
    2025-10-29T17:04:43Z [bench]   - Flush: 1.18ms [0.00s (1.30ms/blk)]
    2025-10-29T17:04:43Z [bench]   - Writing chainstate: 0.01ms [0.00s (0.03ms/blk)]
    2025-10-29T17:04:43Z UpdateTip: new best=00000012f127f0823149956467d0a1229f4ee51ae95f5025463b8d65e25b2e01 height=268959 version=0x20000000 log2_work=42.751443 tx=26640487 date='2025-09-10T08:59:44Z' progress=0.854412 cache=2.0MiB(12495txo)
    2025-10-29T17:04:43Z [bench]   - Connect postprocess: 0.18ms [0.00s (0.63ms/blk)]
    
  2. 0xB10C commented on Oct 29, 2025

    @0xB10C
    CollaboratorAuthor

    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.

  3. 0xB10C commented on Oct 31, 2025

    @0xB10C
    CollaboratorAuthor
  4. 0xB10C commented on Oct 31, 2025

    @0xB10C
    CollaboratorAuthor

    Also, missing docs for log-extractor. See #288

  5. 0xB10C commented on Nov 21, 2025

    @0xB10C
    CollaboratorAuthor

    Recently came across these logs:

    got inv: wtx 274b026f54264ade245c3391d950749cceffddb4498f6f359e91308249ba1aa8  have peer=50916
    got inv: wtx ec16e511b387a55c3f5dccecd0b8835a7559d1e0db56ac25cc5136dc4bf2f4a6  new peer=50916
    

    And figured it would be nice to have a metric how often we get an INV, but already "have" the transaction already.

  6. 0xB10C commented on Dec 4, 2025

    @0xB10C
    CollaboratorAuthor

    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.

  7. m4ycon commented on May 8, 2026

    @m4ycon
    Collaborator

    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.

    Any thoughts @0xB10C?

    Image
  8. 0xB10C commented on May 12, 2026

    @0xB10C
    CollaboratorAuthor

    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.

  9. m4ycon commented on May 12, 2026

    @m4ycon
    Collaborator

    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 🤔.

  10. m4ycon commented on May 12, 2026

    @m4ycon
    Collaborator

    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):

    1. 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;
    2. 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=cc41ca76260c4e66e8bf8090a4986f164a4c42b1cd6a260b04293825beda09f5

    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.

  11. 0xB10C commented on May 18, 2026

    @0xB10C
    CollaboratorAuthor

    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.

  12. 0xB10C commented on May 18, 2026

    @0xB10C
    CollaboratorAuthor

    Unrelated other metrics that I was thinking about that we can get from logs, that I want to note down here:

    • rate of attempted outbound connections. and rate of success in opening one
    • rate and success of feeler connections
  13. m4ycon commented on May 19, 2026

    @m4ycon
    Collaborator

    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.

  14. m4ycon commented on May 19, 2026

    @m4ycon
    Collaborator

    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.

    Image
    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 MultiLogMatcher
    for matcher in &static_matchers {
        match matcher(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?
  15. 0xB10C commented on May 20, 2026

    @0xB10C
    CollaboratorAuthor

    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.

  16. 0xB10C commented on May 20, 2026

    @0xB10C
    CollaboratorAuthor

    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.

  17. 0xB10C commented on May 20, 2026

    @0xB10C
    CollaboratorAuthor

    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?

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions