Practical Byzantine Fault Tolerance in Rust
Castro and Liskov's pBFT provides Byzantine fault tolerance for state machine replication, tolerating up to f < n/3 faulty nodes through a three-phase protocol.
Three-Phase Consensus Protocol:
pub enum PbftMessage {
PrePrepare(PrePrepareMessage),
Prepare(PrepareMessage),
Commit(CommitMessage),
ViewChange(ViewChangeMessage),
NewView(NewViewMessage),
}Pre-prepare Phase: Primary orders requests and broadcasts pre-prepare messages
Prepare Phase: Replicas validate and broadcast prepare messages
Commit Phase: After 2f+1 matching prepares, replicas broadcast commits
View Change Protocol:
- Timeout-based primary failure detection
- View change messages with prepared request proofs
- New primary computes new view message with complete pre-prepare set
Async/Concurrent Architecture:
struct PbftConsensus {
state: Arc<RwLock<PbftNode>>,
network: NetworkManager,
service: Box<dyn Service>,
}Production Features:
- Tokio-based async networking
- Message authentication with HMAC-SHA256
- Efficient batching and pipelining
- Read-only request optimization
- Checkpoint and garbage collection
- Persistent state management
Performance Optimizations:
- Request batching reduces consensus overhead
- Parallel signature verification
- Memory pool management for frequent allocations
- Zero-copy message processing where possible