blockchain crate provides the core blockchain functionality with peer-to-peer networking capabilities for the Ubu-Block system.
Overview
This crate implements:- Blockchain data structure with P2P networking
- Peer discovery and connection management
- Block synchronization and propagation
- Message-based P2P protocol
Main Types
BlockChain
The main blockchain structure that manages both the database and P2P networking.Construction
P2P Networking Methods
Peer Management
Database Operations (via Deref)
TheBlockChain struct implements Deref and DerefMut for Database, so all database methods are directly available:
Helper Functions
P2P Protocol
The blockchain implements a message-based protocol for peer communication:- Handshake:
HelloandHelloResponsemessages for connection establishment - Block Sync:
BlockAnnouncement,GetBlocks,BlocksResponse - Chain Info:
ChainHeightRequest,ChainHeightResponse - Peer Discovery:
GetPeers,PeersResponse - Keep-Alive:
PingandPongmessages
Configuration
The blockchain usesP2PConfig for network configuration:
Error Handling
All async methods returnResult<T, ChainError> where ChainError can be:
DatabaseErrorSerializationErrorIoErrorPeerErrorTimeoutError
Thread Safety
TheBlockChain struct is Clone and uses Arc-based interior mutability for safe concurrent access across async tasks.