Protocol Layer Overview
The protocol layer (blvm-protocol) abstracts Bitcoin protocol for multiple variants and protocol evolution. It sits between the pure mathematical consensus rules (blvm-consensus) and the Bitcoin node implementation (blvm-node), supporting mainnet, testnet, regtest, and future protocol variants.
Architecture Position
Stack layer 3 — protocol abstraction between blvm-consensus and blvm-node. Full stack: Introduction.
Protocol Variants
The protocol layer supports multiple Bitcoin network variants:
| Variant | Network Name | Default Port | Purpose |
|---|---|---|---|
| BitcoinV1 | mainnet | 8333 | Production Bitcoin network |
| Testnet3 | testnet | 18333 | Bitcoin test network |
| Regtest | regtest | 18444 | Regression testing network |
Network Parameters
Each variant has specific network parameters:
- Magic Bytes: P2P protocol identification (mainnet:
0xf9beb4d9, testnet:0x0b110907, regtest:0xfabfb5da) - Genesis Blocks: Network-specific genesis block hashes
- Difficulty Targets: Proof-of-work difficulty adjustment
- Halving Intervals: Block subsidy halving schedule (210,000 blocks)
- Feature Activation: SegWit, Taproot activation heights
Core Components
Protocol Engine
The BitcoinProtocolEngine is the main interface:
#![allow(unused)] fn main() { pub struct BitcoinProtocolEngine { version: ProtocolVersion, network_params: NetworkParams, config: ProtocolConfig, } }
Features:
- Protocol variant selection
- Network parameter access
- Feature flag management
- Validation rule enforcement
Network Messages
Supports Bitcoin P2P protocol messages:
Core Messages:
Version,VerAck- Connection handshakeAddr,GetAddr- Peer address managementInv,GetData,NotFound- Inventory managementBlock,Tx- Block and transaction relayGetHeaders,Headers,GetBlocks- Header synchronizationPing,Pong- Connection keepaliveMemPool,FeeFilter- Mempool synchronization
BIP152 (Compact Block Relay):
SendCmpct- Compact block negotiationCmpctBlock- Compact block transmissionGetBlockTxn,BlockTxn- Transaction reconstruction
FIBRE Protocol:
FIBREPacket- High-performance relay protocol- Packet format and serialization
- Performance optimizations
Governance Messages:
- Governance messages via P2P protocol
- Message format and routing
- Integration with governance system
Commons Extensions:
GetUTXOSet,UTXOSet- UTXO commitment protocolGetFilteredBlock,FilteredBlock- Spam-filtered blocksGetBanList,BanList- Distributed ban list sharing
Service Flags
Service flags indicate node capabilities:
Standard Flags:
NODE_NETWORK- Full node with all blocksNODE_WITNESS- SegWit supportNODE_COMPACT_FILTERS- BIP157/158 supportNODE_NETWORK_LIMITED- Pruned node
Commons Flags:
NODE_UTXO_COMMITMENTS- UTXO commitment supportNODE_BAN_LIST_SHARING- Ban list sharingNODE_FIBRE- FIBRE protocol supportNODE_DANDELION- Dandelion++ privacy relayNODE_PACKAGE_RELAY- BIP331 package relay
Validation Rules
Protocol-specific validation rules:
- Size Limits: Block (4MB), transaction (1MB), script (10KB)
- Feature Flags: SegWit, Taproot, RBF support
- Fee Rules: Minimum and maximum fee rates
- DoS Protection: Message size limits, address count limits
Commons-Specific Extensions
UTXO Commitments
Protocol messages for UTXO set synchronization:
GetUTXOSet- Request UTXO set at specific heightUTXOSet- UTXO set response with merkle proof
Filtered Blocks
Spam-filtered block relay for efficient syncing:
GetFilteredBlock- Request filtered blockFilteredBlock- Filtered block with spam transactions removed
Ban List Sharing
Distributed ban list management:
GetBanList- Request ban listBanList- Ban list response with signatures
BIP Support
Implemented Bitcoin Improvement Proposals:
- BIP152: Compact Block Relay
- BIP157: Client-side Block Filtering
- BIP158: Compact Block Filters
- BIP173/350/351: Bech32/Bech32m Address Encoding
- BIP70: Payment Protocol
Protocol Evolution
The protocol layer supports protocol evolution:
- Version Support: Multiple protocol versions
- Feature Management: Enable/disable features based on version
- Breaking Changes: Track and manage protocol evolution
- Backward Compatibility: Maintain compatibility with existing nodes
Usage Example
#![allow(unused)] fn main() { use blvm_protocol::{BitcoinProtocolEngine, ProtocolVersion}; // Create a mainnet protocol engine let engine = BitcoinProtocolEngine::new(ProtocolVersion::BitcoinV1)?; // Get network parameters let params = engine.get_network_params(); println!("Network: {}", params.network_name); println!("Port: {}", params.default_port); // Check feature support if engine.supports_feature("segwit") { println!("SegWit is supported"); } }
Source
- network_params.rs
- lib.rs
network.rs(NetworkMessage),wire/mod.rs(command names and serialization)- service_flags.rs
- validation.rs
- commons.rs (message structs); utxo_commitments/mod.rs (UTXO commitment protocol)
- commons.rs (
GetFilteredBlockMessage,FilteredBlockMessage) - commons.rs (
GetBanListMessage,BanListMessage) - bip157.rs
See Also
- Protocol Architecture - Protocol layer design and components
- Network Protocol - Transport abstraction and protocol details
- Message Formats - P2P message specifications
- Protocol Specifications - BIP implementations
- Node Configuration - Configuring protocol variants