Skip to content

Fix/log level filter and state guards - #369

Merged
0xB10C merged 2 commits into
peer-observer:masterfrom
deadmanoz:fix/log-level-filter-and-state-guards
Mar 6, 2026
Merged

0xB10C merged 2 commits into
peer-observer:masterfrom
deadmanoz:fix/log-level-filter-and-state-guards

Conversation

@deadmanoz

Copy link
Copy Markdown
Collaborator

Summary

The log line parser in shared/src/log_matchers.rs treats all [bracketed] metadata tokens as either thread names or debug categories. This breaks when Bitcoin Core emits log level markers via LogError() and LogWarning(), which produce lines like:

2025-10-02T02:31:14Z [error] AcceptBlock: bad-witness-nonce-size, ...
2025-10-02T02:31:14Z [msghand] [error] ConnectBlock: ...

The parser would interpret [error] as a thread name (in the first case) or a debug category (in the second). This is incorrect - it's a severity level emitted by GetLogPrefix() in Bitcoin Core's logging.cpp.

When -logthreadnames=1 is enabled, the thread name bracket and the level bracket appear as two separate tokens (e.g. [msghand] [error] as above), so both cases need handling.

This is the root cause behind the flaky BlockCheckedLog test failures reported in #366. The nix-coverage CI job captured logs showing threadname: "error", with [error] having been misinterpreted as a thread name! I also hit this locally while working on #338.

This PR adds an is_standalone_log_level() filter that strips [error] and [warning] from the parsed metadata items before thread name/category assignment. The function is scoped to only these two levels because they are the only ones that appear as standalone bracket tokens under default Bitcoin Core configuration (see the linked logging.cpp):

  • LogInfo() produces no bracket at all (GetLogPrefix returns empty for uncategorised info-level messages)
  • LogDebug()/LogTrace() both require a category argument so they produce [category] or [category:trace] as single bracket tokens, never standalone [debug] or [trace]

In a separate commit, the integration tests for BlockCheckedLog events are tightened using the same pattern as #354: the state value check (e.g. "Valid", "bad-witness-nonce-size", "bad-txnmrklroot") is moved from an assert_eq! inside the match body into an if-let guard condition. This prevents the callback from panicking on a legitimate but unexpected state value arriving first (it skips non-matching events and waits for the correct one).

Fixes #366 🥳

Testing

Four new tests in shared/src/log_matchers.rs:

  • test_log_matcher_error_level_not_treated_as_threadname - standalone [error] is filtered, not assigned as thread name
  • test_log_matcher_error_level_with_threadname - [msghand] [error] preserves the real thread name and filters the level
  • test_log_matcher_warning_level_filtered - standalone [warning] is filtered
  • test_is_standalone_log_level - exercises the filter against known levels, non-standalone levels (info, debug, trace), and known non-levels (categories and thread names like net, validation, msghand)

Existing integration tests (test_integration_logextractor_block_checked, test_integration_logextractor_mutated_block_bad_witness_nonce_size, test_integration_logextractor_mutated_block_bad_txnmrklroot) continue to pass with the guard-style predicates.

Full pre-push quality gate (fmt, clippy, unit tests, NATS integration tests) passes.

See green CI via PR opened against my fork: https://github.com/deadmanoz/peer-observer/actions/runs/22381839058

@deadmanoz

Copy link
Copy Markdown
Collaborator Author

NOTE: there is still some flakiness with tests that I will address in my next PR (which will resolve the underlying/fundamental cause of some test flakiness)

@m4ycon m4ycon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@0xB10C

0xB10C commented Mar 5, 2026 •

Copy link
Copy Markdown
Collaborator

Code looks good to me. Going to rebase this on #360 and if it passes (ignoring unrelated failures), merging this tomorrow.

Move block_checked.state assertions from inside the match body into
if-let guard conditions so the callback skips non-matching events
instead of panicking on a legitimate but unexpected state value.
Bitcoin Core's LogError() and LogWarning() emit [error] and [warning]
bracket tokens. The log parser was misidentifying these as threadnames
or debug categories. Strip known log level markers from metadata items
before threadname/category assignment.
@0xB10C
0xB10C force-pushed the fix/log-level-filter-and-state-guards branch from 5bea68f to 0e35bdb Compare March 5, 2026 16:54
@0xB10C

0xB10C commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator

Update - We are observing delays in queuing Actions workflow runs. We’re still investigating the causes of these delays. https://www.githubstatus.com/incidents/g5gnt5l5hf56

@0xB10C

0xB10C commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

Re-triggering CI (which didn't run due to yesterdays outage)

@0xB10C 0xB10C closed this Mar 6, 2026
@0xB10C 0xB10C reopened this Mar 6, 2026
@0xB10C

0xB10C commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

Thank you! Another intermittent failure squashed!

@0xB10C
0xB10C merged commit 4bfe701 into peer-observer:master Mar 6, 2026
12 checks passed
@deadmanoz
deadmanoz deleted the fix/log-level-filter-and-state-guards branch May 28, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test flakiness uncovered by nix-coverage job

3 participants