Privacy Relay Protocols
Overview
Bitcoin Commons implements multiple privacy-preserving and performance-optimized transaction relay protocols: Dandelion++, Fibre, and Package Relay. These protocols improve privacy, reduce bandwidth, and enable efficient transaction propagation.
Dandelion++
Overview
Dandelion++ provides privacy-preserving transaction relay with formal anonymity guarantees against transaction origin analysis. It operates in two phases: stem phase (obscures origin) and fluff phase (standard diffusion).
Code: dandelion.rs
Architecture
Dandelion++ operates in two phases:
- Stem Phase: Transaction relayed along a random path (obscures origin)
- Fluff Phase: Transaction broadcast to all peers (standard diffusion)
Stem Path Management
Each peer maintains a stem path to a randomly selected peer:
#![allow(unused)]
fn main() {
pub struct StemPath {
pub next_peer: String,
pub expiry: Instant,
pub hop_count: u8,
}
}
Code: dandelion.rs
Stem Phase Behavior
- Transactions relayed to next peer in stem path
- Random path selection obscures transaction origin
- Stem timeout: 10 seconds (default)
- Fluff probability: 10% per hop (default)
- Maximum stem hops: 2 (default)
Code: dandelion.rs
Fluff Phase Behavior
- Transaction broadcast to all peers
- Standard Bitcoin transaction diffusion
- Triggered by:
- Random probability at each hop
- Stem timeout expiration
- Maximum hop count reached
Code: dandelion.rs
Configuration
[network.dandelion]
enabled = true
stem_timeout_secs = 10
fluff_probability = 0.1 # 10%
max_stem_hops = 2
Code: dandelion.rs
Benefits
- Privacy: Obscures transaction origin
- Formal Guarantees: Anonymity guarantees against origin analysis
- Backward Compatible: Falls back to standard relay if disabled
- Configurable: Adjustable timeouts and probabilities
Fibre
Overview
Fibre (Fast Internet Bitcoin Relay Engine) provides high-performance block relay using UDP transport with Forward Error Correction (FEC) encoding for packet loss tolerance.
Code: fibre.rs
Architecture
Fibre uses:
- UDP Transport: Low-latency UDP for block relay
- FEC Encoding: Reed-Solomon erasure coding for packet loss tolerance
- Chunk-based Transmission: Blocks split into chunks with parity shards
- Automatic Recovery: Missing chunks recovered via FEC
FEC Encoding
Blocks are encoded using Reed-Solomon erasure coding:
- Data Shards: Original block data split into shards
- Parity Shards: Redundant shards for error recovery
- Shard Size: Configurable (default: 1024 bytes)
- Parity Ratio: Configurable (default: 0.2 = 20% parity)
Code: fibre.rs
Block Encoding Process
- Serialize block to bytes
- Split into data shards
- Generate parity shards via FEC
- Create FEC chunks for transmission
- Send chunks via UDP
Code: fibre.rs
Block Assembly Process
- Receive FEC chunks via UDP
- Track received chunks per block
- When enough chunks received (data shards), reconstruct block
- Verify block hash matches
Code: fibre.rs
UDP Transport
Fibre uses UDP for low-latency transmission:
- Connection Tracking: Per-peer connection state
- Retry Logic: Automatic retry for lost chunks
- Sequence Numbers: Duplicate detection
- Timeout Handling: Connection timeout management
Code: fibre.rs
Configuration
[network.fibre]
enabled = true
bind_addr = "0.0.0.0:8334"
chunk_timeout_secs = 5
max_retries = 3
fec_parity_ratio = 0.2 # 20% parity
max_assemblies = 100
Code: fibre.rs
Statistics
Fibre tracks comprehensive statistics:
- Blocks sent/received
- Chunks sent/received
- FEC recoveries
- UDP errors
- Average latency
- Success rate
Code: fibre.rs
Benefits
- Low Latency: UDP transport reduces latency
- Packet Loss Tolerance: FEC recovers from lost chunks
- High Throughput: Efficient chunk-based transmission
- Automatic Recovery: No manual retry needed
Package Relay (BIP331)
Overview
Package Relay (BIP331) allows nodes to relay and validate groups of transactions together, enabling efficient fee-bumping (RBF) and CPFP (Child Pays For Parent) scenarios.
Code: package_relay.rs
Package Structure
A transaction package contains:
- Transactions: Ordered list (parents before children)
- Package ID: Combined hash of all transactions
- Combined Fee: Sum of all transaction fees
- Combined Weight: Total weight for fee rate calculation
Code: package_relay.rs
Package Validation
Packages are validated for:
- Size Limits: Maximum 25 transactions (BIP331)
- Weight Limits: Maximum 404,000 WU (BIP331)
- Fee Rate: Minimum fee rate requirement
- Ordering: Parents must precede children
- No Duplicates: No duplicate transactions
Code: package_relay.rs
Use Cases
- Fee-Bumping (RBF): Parent + child transaction for fee increase
- CPFP: Child transaction pays for parent’s fees
- Atomic Sets: Multiple transactions that must be accepted together
Code: package_relay.rs
Package ID Calculation
Package ID is calculated as double SHA256 of all transaction IDs:
#![allow(unused)]
fn main() {
pub fn from_transactions(transactions: &[Transaction]) -> PackageId {
// Hash all txids, then double hash
}
}
Code: package_relay.rs
Configuration
[network.package_relay]
enabled = true
max_package_size = 25
max_package_weight = 404000 # 404k WU
min_fee_rate = 1000 # 1 sat/vB
Code: package_relay.rs
Benefits
- Efficient Fee-Bumping: Better fee rate calculation for packages
- Reduced Orphans: Reduces orphan transactions in mempool
- Atomic Validation: Package validated as unit
- DoS Resistance: Size and weight limits prevent abuse
Integration
Relay Manager
The RelayManager coordinates all relay protocols:
- Standard block/transaction relay
- Dandelion++ integration (optional)
- Fibre integration (optional)
- Package relay support
Code: relay.rs
Protocol Selection
Relay protocols are selected based on:
- Feature flags (
dandelion,fibre) - Peer capabilities
- Configuration settings
- Runtime preferences
Code: relay.rs
Components
The privacy relay system includes:
- Dandelion++ stem/fluff phase management
- Fibre UDP transport with FEC encoding
- Package Relay (BIP331) validation
- Relay manager coordination
- Statistics tracking
Location: blvm-node/src/network/dandelion.rs, blvm-node/src/network/fibre.rs, blvm-node/src/network/package_relay.rs, blvm-node/src/network/relay.rs