Chaincraft Rust
A high-performance Rust-based platform for blockchain education and prototyping
Overview
A high-performance Rust-based platform for blockchain education and prototyping. Chaincraft Rust provides a clean, well-documented implementation of core blockchain concepts with a focus on performance, security, and educational value.
Features
- High Performance: Built with Rust for maximum performance and memory safety
- Educational Focus: Well-documented code with clear explanations of blockchain concepts
- Modular Design: Pluggable consensus mechanisms, storage backends, and network protocols
- Cryptographic Primitives: Support for multiple signature schemes (Ed25519, ECDSA/secp256k1)
- Network Protocol: P2P networking with peer discovery and message propagation
- Flexible Storage: Memory and persistent storage options with optional SQLite indexing
- CLI Interface: Easy-to-use command-line interface for node management
Quick Start
Installation
From Crates.io
From Source
Running a Node
Start a Chaincraft node with default settings:
Or with custom configuration:
Generate a Keypair
Usage as a Library
Add Chaincraft Rust to your Cargo.toml:
[]
= "0.2.1"
Basic Example
use ;
async
Advanced Configuration
use ;
use KeyType;
async
Architecture
Chaincraft Rust is built with a modular architecture:
- Core: Basic blockchain data structures and validation logic
- Consensus: Pluggable consensus mechanisms (Tendermint-style, randomness beacon)
- Network: P2P networking layer with peer discovery
- Storage: Flexible storage backends (memory, persistent, indexed)
- Crypto: Cryptographic primitives and utilities
- CLI: Command-line interface for node management
Network Architecture (Rust Version)
The Rust implementation uses raw UDP sockets (no libp2p) for simplicity and control:
- Bind: Each node binds a UDP socket to
host:port(port0= ephemeral). - Gossip Loop: A background task periodically rebroadcasts stored message hashes to all known peers.
- Receive Loop: Incoming datagrams are parsed as JSON
SharedMessage, deduplicated, stored, and rebroadcast. - Local Discovery: In-process nodes register in a static
LOCAL_NODESmap for automatic peer discovery within the same process. - Message Flow:
create_shared_message_with_data()stores a message, processes it throughApplicationObjects, and broadcasts to peers.
Running Multi-Node Demos
Start multiple nodes in separate terminals or use the multi-node script:
# Terminal 1
# Terminal 2
# Terminal 3
Or run the shared objects example (in-process multi-node):
Python vs Rust Feature Mapping
| Python (chaincraft) | Rust (chaincraft-rust) |
|---|---|
node.py |
src/node.rs |
SharedMessage |
shared::SharedMessage |
ApplicationObject |
shared_object::ApplicationObject |
SimpleSharedNumber |
shared_object::SimpleSharedNumber |
SimpleChainObject |
shared_object::MerkelizedChain |
| Message chain | shared_object::MessageChain |
| ECDSA ledger | examples::ecdsa_ledger::ECDSALedgerObject |
dbm / on-disk storage |
sled (feature persistent) |
local_discovery |
NodeConfig::local_discovery + LOCAL_NODES registry |
gossip loop |
Gossip task in start_networking() |
| UDP broadcast | broadcast_bytes() via UdpSocket |
Features
Default Features
compression: Enable message compression for network efficiency
Optional Features
persistent: Enable persistent storage using sledindexing: Enable SQLite-based transaction indexingvdf-crypto: Enable VDF (Verifiable Delay Function) support via vdf crate. Requires GMP:apt install libgmp-devorbrew install gmp
Enable features in your Cargo.toml:
[]
= { = "0.2.1", = ["persistent", "indexing"] }
Development
Prerequisites
- Rust 1.70 or later
- Git
Building
Running Tests
# Run all tests
# Run tests with all features enabled
# Run integration tests
Running Benchmarks
Code Coverage
API Documentation
Full API documentation is available on docs.rs.
To build documentation locally:
Examples
Check out the examples/ directory for more usage examples:
basic_node.rs: Simple node setup and operationkeypair_generation.rs: Cryptographic keypair generation and signingchatroom_example.rs: Decentralized chatroom protocol (create rooms, post messages)randomness_beacon_example.rs: Verifiable randomness beaconshared_objects_example.rs: Multi-node network with shared object propagationproof_of_work_example.rs: Proof of Work mining and verification
Run examples with:
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for your changes
- Ensure all tests pass (
cargo test --all-features) - Run clippy (
cargo clippy --all-features) - Format your code (
cargo fmt) - Commit your changes (
git commit -am 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Performance
Chaincraft Rust is designed for high performance:
- Zero-copy serialization where possible
- Efficient async networking with tokio
- Optimized cryptographic operations
- Configurable resource limits
Security
Security is a top priority:
- Memory-safe Rust implementation
- Cryptographic operations use well-audited libraries
- Network protocol includes message authentication
- Input validation and sanitization throughout
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with Tokio for async runtime
- Cryptography powered by RustCrypto
- Custom UDP-based P2P networking (no libp2p dependency)
Roadmap
- Advanced consensus mechanisms (PBFT)
- Smart contract support
- Enhanced monitoring and metrics
- WebAssembly runtime integration
For more information, visit our documentation or repository.