Witnet Wire Protocol
Witnet is a lightweight, high-performance HTTP-like TCP server framework built explicitly for ultra-fast transfers of "Execution Witnesses" between Execution Clients and Provers.
It strips away all unnecessary application-layer overhead (like HTTP/2, gRPC, or QUIC framing) in favor of a zero-buffering, strictly 9-byte framed socket connection. It achieves blazing fast throughput (>13.4 GB/s) on local loopback, crushing standard Unix Domain Socket (IPC) latency limitations.
Core Features
- HTTP-Like Developer Experience: You structure your applications using
Router,Request, andResponseparadigms common in frameworks likeActixorAxum. - Zero-Buffering Pipelines: The
Request::into_body_stream()returns aBodystruct mapped directly to the activetokio::net::TcpStream. NoBytesMutstring-buffering takes place behind the scenes. - Protection Limits: Hard-coded
MAX_PAYLOAD_SIZEdrops connections immediately if payload allocations exceed 5GB, avoiding Node DoS vulnerabilities. - Massive Throughput Enhancements: Implements
TCP_NODELAYandtokio_util::io::ReaderStream64KB capacities under the hood to completely eliminate kernel allocation thrashing, beating manual loop-scripts.
Installation
Add witnet to your Cargo.toml:
[]
= "0.1.0"
The Protocol Specification
A single message frame consists of:
- 1-byte Message Type identifier
- 8-byte Length Prefix (Big-Endian
u64) - Raw Payload bytes
As soon as the 9-byte header is parsed, the socket halts, yielding control to your Router handler logic exactly before payload ingress.
Standard Usage
Server Configuration
use ;
use StreamExt;
use Duration;
const WITNESS_BY_NUMBER: u8 = 0x01;
async
async
State Extraction (Axum-style)
Witnet provides a State extractor wrapper heavily inspired by Axum, allowing you to pass Arc/shared state objects directly into your handler functions!
use ;
use Arc;
async
// Extract state gracefully using `State(state)`
async
Client Configuration
use ;
async
Benchmarks
Benchmarked against an Apple Silicon M3 Max running on the 127.0.0.1 macOS loopback layer. Because of the ReaderStream 64KB scaling, witnet averages speeds drastically higher than manual socket polling scripts.
| Payload Size | Throughput |
|---|---|
| 8 MB | 2538 MB/s |
| 20 MB | 3481 MB/s |
| 100 MB | 4195 MB/s |
| 300 MB | 8774 MB/s |
| 500 MB | 13.4 GB/s |
Note: You can replicate the testing parameters yourself by running cargo run --release --example dummy_witness.