Skip to content

Capture mutated blocks from logs - #287

Merged
0xB10C merged 6 commits into
peer-observer:masterfrom
m4ycon:feat/mutated-blocks-log
Dec 12, 2025
Merged

0xB10C merged 6 commits into
peer-observer:masterfrom
m4ycon:feat/mutated-blocks-log

Conversation

@m4ycon

@m4ycon m4ycon commented Oct 31, 2025

Copy link
Copy Markdown
Collaborator
  • Add BlockChecked LogMatcher
  • Capture mutated blocks in metrics tool
  • Add an initial dashboard for logs in grafana

Here is what the dashboard looks like, the first chart shows 8/10 of it is the mainnet, the rest is regtest used to generate the mutated blocks logs.

Btw, the branch from this PR ClubeBitcoinUnB/btc-traffic#6 was used to generate these examples.

image

Maybe it could be useful, here are samples of what kind of content btc-core logs about these mutated blocks, I check for [validation] BlockChecked ones.

// bad-txnmrklroot
2025-10-28T02:18:37Z [validation] BlockChecked: block hash=3909cd2a5ff36b9a40368609f92945e5b7111bca3cb4d04b72c39964aeb5d156 state=bad-txnmrklroot, hashMerkleRoot mismatch
2025-10-28T02:18:37Z [error] ProcessNewBlock: AcceptBlock FAILED (bad-txnmrklroot, hashMerkleRoot mismatch)

// bad-txns-duplicate
2025-10-28T02:20:12Z [validation] BlockChecked: block hash=1811952798ccd2ad1264b064c3da6313fba7497159b999ee045afb046c7d0232 state=bad-txns-duplicate, duplicate transaction
2025-10-28T02:20:12Z [error] ProcessNewBlock: AcceptBlock FAILED (bad-txns-duplicate, duplicate transaction)

// bad-witness-nonce-size
2025-10-28T02:21:04Z [error] AcceptBlock: bad-witness-nonce-size, CheckWitnessMalleation : invalid witness reserved value size
2025-10-28T02:21:04Z [validation] BlockChecked: block hash=7e38f165598ceec2178db6f063e7745c2bdd4952d52bea44bfe069c686ea5a55 state=bad-witness-nonce-size, CheckWitnessMalleation : invalid witness reserved value size
2025-10-28T02:21:04Z [error] ProcessNewBlock: AcceptBlock FAILED (bad-witness-nonce-size, CheckWitnessMalleation : invalid witness reserved value size)

// bad-witness-merkle-match
2025-10-28T02:21:51Z [error] AcceptBlock: bad-witness-merkle-match, CheckWitnessMalleation : witness merkle commitment mismatch
2025-10-28T02:21:51Z [validation] BlockChecked: block hash=117dd69bd553742a13bd5fd094132c64b31dc33836711f72503bef22d714af02 state=bad-witness-merkle-match, CheckWitnessMalleation : witness merkle commitment mismatch
2025-10-28T02:21:51Z [error] ProcessNewBlock: AcceptBlock FAILED (bad-witness-merkle-match, CheckWitnessMalleation : witness merkle commitment mismatch)

// unexpected-witness
2025-10-28T02:22:28Z [error] AcceptBlock: unexpected-witness, CheckWitnessMalleation : unexpected witness data found
2025-10-28T02:22:28Z [validation] BlockChecked: block hash=0ffc0b771bce4405645c1b1584bf04bb3c1a084cd4950784df9bc560d7e75a3b state=unexpected-witness, CheckWitnessMalleation : unexpected witness data found
2025-10-28T02:22:28Z [error] ProcessNewBlock: AcceptBlock FAILED (unexpected-witness, CheckWitnessMalleation : unexpected witness data found)

@0xB10C

0xB10C commented Oct 31, 2025

Copy link
Copy Markdown
Collaborator

Concept ACK.

I'm not too sure about adding the dashboard in the tools/metrics/dashboards/playlist/ folder - maybe it can go into tools/metrics/dashboards/. Normally, the playlist dashboards only have one metric shown. See e.g. https://demo.peer.observer/monitoring/playlists

I'll probably need to play around myself with new metrics first to figure out what works best.

I think it would be good to have at least one logger integration test that produces a mutated block to catch the log changing in Bitcoin Core at some point. Given you authored ClubeBitcoinUnB/btc-traffic#6, you probably know best how to easily create a mutated block. I think a minimal mutated block could be constructed and submitted with something similar to this pseudocode:

block = RPC generateblock [address] ["txid", ..] submit=false
mutated_coinbase = block.coinbase.witness_commitment.mutate() // e.g. set to something random
mutated_block = block
mutated_block.coinbase = mutated_coinbase
RPC submitblock mutated_block

@0xB10C

0xB10C commented Oct 31, 2025

Copy link
Copy Markdown
Collaborator

Also, CI is failing as the integration test metric now outputs peerobserver_log_events{category="unknown"} 2 instead of peerobserver_log_events 2. Should be an easy fix to update the expected output.

@m4ycon

m4ycon commented Nov 1, 2025 •

Copy link
Copy Markdown
Collaborator Author

I'm not too sure about adding the dashboard in the tools/metrics/dashboards/playlist/ folder - maybe it can go into tools/metrics/dashboards/. Normally, the playlist dashboards only have one metric shown. See e.g. https://demo.peer.observer/monitoring/playlists

Oh I didn't know about this concept, but ok.

I think it would be good to have at least one logger integration test that produces a mutated block to catch the log changing in Bitcoin Core at some point. Given you authored ClubeBitcoinUnB/btc-traffic#6, you probably know best how to easily create a mutated block. I think a minimal mutated block could be constructed and submitted with something similar to this pseudocode:

Done for 2 out of 5 cases, except from bad-txns-duplicate which is bit more complicated to accomplish, the rest were giving valid blocks when it wasn't supposed to, I didn't understand why and they are quite simple to build. These two "false-positives" are bad-witness-merkle-match and unexpected-witness. If you wanna check what needs to be done for them, here it is bad-witness-merkle-match and unexpected-witness.

@0xB10C
0xB10C force-pushed the feat/mutated-blocks-log branch from 772a928 to ec1f8b0 Compare November 8, 2025 18:08
@0xB10C

0xB10C commented Nov 8, 2025

Copy link
Copy Markdown
Collaborator

squashed your fixups with their original commits. Code-wise this looks good, but I want to run it a bit first. Plan to do this next week.

0xB10C added a commit to 0xB10C/nix that referenced this pull request Dec 9, 2025
0xB10C added a commit to 0xB10C/nix that referenced this pull request Dec 9, 2025
0xB10C added a commit to 0xB10C/nix that referenced this pull request Dec 9, 2025
@0xB10C

0xB10C commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator

Finially getting back to this: I've started testing this and integration the log-extractor into my Nix infrastructure in 0xB10C/nix#247

@0xB10C

0xB10C commented Dec 10, 2025

Copy link
Copy Markdown
Collaborator

Hm, that might be due to running with logthreadnames=1 which isn't supported by the current log-extractor.

https://github.com/peer-observer/infra-library/blob/e24262ed5e8731a8a81dfaf37402736385d09f8f/modules/node/node.nix#L177C9-L177C25

This adds e.g. [msghand] and [scheduler] in-front of the category:

2025-12-10T14:16:06.964097Z [msghand] [net] got inv: wtx abcdef  have peer=56452
2025-12-10T14:16:52.361894Z [msghand] [txpackages] added peer=52648 as announcer of orphan tx abcd (wtxid=abcd)
2025-12-10T14:17:12.966258Z [scheduler] [validation] TransactionAddedToMempool: txid=abcdef wtxid=abcdef

@m4ycon

m4ycon commented Dec 10, 2025

Copy link
Copy Markdown
Collaborator Author

Hm, that might be due to running with logthreadnames=1 which isn't supported by the current log-extractor.

Oh didn't know about this one... I could work on that, but do you think it fits into this PR?

@0xB10C

0xB10C commented Dec 10, 2025

Copy link
Copy Markdown
Collaborator

Hm, that might be due to running with logthreadnames=1 which isn't supported by the current log-extractor.

Oh didn't know about this one... I could work on that, but do you think it fits into this PR?

No, feel free to pick this up in a separate PR :) Thank you!

@0xB10C

0xB10C commented Dec 12, 2025 •

Copy link
Copy Markdown
Collaborator

I think this is ready to merge. We can add more metrics to the Logs dashboard a bit later.

Thank you @m4ycon!

@0xB10C
0xB10C merged commit 56e5521 into peer-observer:master Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants