Page MenuHomePhabricator

Per-Peer Message Capture
ClosedPublic

Authored by PiRK on Nov 18 2022, 11:14.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCcfcf6bb92f46: Per-Peer Message Capture
Summary

The purpose and scope of this feature is intentionally limited. It answers a question anyone new to Bitcoin's P2P protocol has had: "Can I see what messages my node is sending and receiving?".

When a new debug-only command line argument capturemessages is set, any message that the node receives or sends is captured. The capture occurs in the MessageHandler thread. When receiving a message, it is captured as soon as the MessageHandler thread takes the message off of the vProcessMsg queue. When sending, the message is captured just before the message is pushed onto the vSendMsg queue.

The message capture is as minimal as possible to reduce the performance impact on the node. Messages are captured to a new message_capture folder in the datadir. Each node has their own subfolder named with their IP address and port. Inside, received and sent messages are captured into two binary files, msgs_recv.dat and msgs_sent.dat, like so:

message_capture/203.0.113.7:56072/msgs_recv.dat
message_capture/203.0.113.7:56072/msgs_sent.dat

Because the messages are raw binary dumps, included in this PR is a Python parsing tool to convert the binary files into human-readable JSON. This script has been placed on its own and out of the way in the new contrib/message-capture folder. Its usage is simple and easily discovered by the autogenerated -h option.

This is a backport of core#19509

Test Plan

ninja all check-all
src/bitcoind -capturemessages
./contrib/message-capture/message-capture-parser.py -o out.json /bitcoinddata/message_capture/**/*.dat

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Nov 18 2022, 11:14
PiRK edited the summary of this revision. (Show Details)
Fabien added a subscriber: Fabien.
Fabien added inline comments.
contrib/message-capture/message-capture-parser.py
209 ↗(On Diff #36389)

Can't use typing ?

This revision is now accepted and ready to land.Nov 18 2022, 14:34
PiRK edited the summary of this revision. (Show Details)

use modern PEP 526 typehints (possible as of python 3.6), add limited_proofid to list of integer variables that should be decoded as hex uint256 hashes

This revision was automatically updated to reflect the committed changes.