Key Value Proposition
stdio_bus adds a complete observability layer to Bitcoin Core’s block processing pipeline with zero performance cost.
Benchmark results (Apple M1, 200 blocks regtest):
| Mode | Blocks/s | Total Time |
|---|---|---|
Baseline (-stdiobus=off) |
21.38 | 12.51s |
With observability (-stdiobus=shadow) |
23.24 | 11.77s |
This means:
- Full visibility into block processing pipeline
- No performance degradation
- Extensible foundation for future optimizations
- Can be enabled/disabled at runtime
Why This Matters
Bitcoin Core currently operates as a “black box” for block processing. When issues occur:
- Operators can’t identify which peer is slow
- Researchers can’t measure propagation latency
- Developers can’t pinpoint bottlenecks
stdio_bus solves this by emitting structured events at every critical point - without affecting the node’s performance.
What You Get
Real-Time Events
0sequenceDiagram
1 participant P as Peer
2 participant N as Node
3 participant O as Observability
4
5 P->>N: HEADERS/CMPCTBLOCK
6 N->>O: BlockAnnounce (peer, method, height)
7 N->>O: RequestDecision (why this peer)
8 N->>O: BlockInFlight (tracking)
9
10 alt Peer stalls
11 N->>O: StallerDetected (peer, duration)
12 end
13
14 P->>N: BLOCK
15 N->>O: BlockValidated (latency, result)
Event Types
| Event | What It Tells You |
|---|---|
BlockAnnounce |
Who announced block, via what method, when |
BlockRequestDecision |
Why we chose this peer, what’s already in-flight |
BlockInFlight |
Download progress tracking |
StallerDetected |
Which peer is blocking progress |
CompactBlockDecision |
BIP152 reconstruction success/failure |
BlockSourceResolved |
Final source attribution with timing |
Example Output (NDJSON)
0{"ts_us":1711180800000000,"event":"block_announce","hash":"00000...","peer_id":42,"via":"headers","height":800000}
1{"ts_us":1711180800100000,"event":"block_request","hash":"00000...","peer_id":42,"reason":"new_block"}
2{"ts_us":1711180802500000,"event":"staller_detected","hash":"00000...","staller_peer_id":42,"stall_duration_us":2400000}
3{"ts_us":1711180803000000,"event":"block_validated","hash":"00000...","latency_us":3000000,"accepted":true}
Architecture
0flowchart LR
1 subgraph BC[Bitcoin Core]
2 NP[net_processing.cpp]
3 VAL[validation.cpp]
4 end
5
6 subgraph OBS[Observability Layer]
7 HOOKS[StdioBusHooks<br/>Interface]
8 SDK[Async Queue<br/>+ Worker]
9 end
10
11 subgraph OUT[Output]
12 TCP[TCP Socket]
13 FILE[Log File]
14 PROM[Prometheus]
15 end
16
17 NP --> HOOKS
18 VAL --> HOOKS
19 HOOKS --> SDK
20 SDK --> TCP
21 SDK --> FILE
22 SDK --> PROM
Key design decisions:
- Lock-free bounded queue (4096 events)
- Background worker thread for I/O
- Fail-open on errors (never blocks main thread)
- <100μs callback latency budget
Zero Performance Cost - How?
- Async processing - Events pushed to queue, processed in background
- Lock-free queue - No mutex contention on hot path
- Bounded memory - Fixed 512KB max queue size
- Fail-open - If queue full, drop event (never block)
- No allocations - Fixed-size event structs
Extensibility
This is a foundation, not a final solution. The observability layer enables:
| Future Phase | What It Enables |
|---|---|
| RPC hooks | Measure RPC latency under P2P load |
| Mempool hooks | TX admission performance analysis |
| Active mode | Data-driven peer selection optimization |
| Security research | Controlled fault injection for testing |
Each extension uses the same infrastructure - add events, no new overhead.
Configuration
0# Enable observability (shadow mode - observe only)
1bitcoind -stdiobus=shadow -stdiobusaddr=127.0.0.1:9800
2
3# Disable (default)
4bitcoind -stdiobus=off
Consensus Safety
Strict guarantees:
- No consensus decisions through stdio_bus
- No modification of message content
- No blocking I/O on critical path
- Fail-open on any error
- All validation logic unchanged
Files
New:
src/node/stdio_bus_hooks.h- Event definitionssrc/node/stdio_bus_sdk_hooks.{h,cpp}- SDK implementationsrc/node/stdio_bus_observer.{h,cpp}- Validation observersrc/test/stdio_bus_hooks_tests.cpp- 32 unit testssrc/stdio_bus/{lib,include}- Pre-built SDK
Modified:
src/net_processing.cpp- Hook call sitessrc/init.cpp- Initialization
Benchmark
0python3 contrib/perf/stdio_bus_benchmark.py --blocks=200
1
2# Output:
3# Baseline: 21.38 blocks/s
4# Shadow: 23.24 blocks/s
5# Overhead: -5.95% (no degradation)
6# Result: PASS ✓
Summary
stdio_bus provides complete block processing observability at zero cost.
You gain visibility into every step of block propagation - which peers announce, who we request from, who stalls, how long validation takes - without sacrificing any performance.
This is the foundation for data-driven optimization of Bitcoin Core’s P2P layer.
Reference:
- stdio Bus: https://stdiobus.com