A simple yet functional blockchain implementation written in Rust, featuring a modular architecture with separate components for core blockchain logic, node operations, and mining.
Hyperion is built with a modular design consisting of three main components:
hyperion-core: Core blockchain primitives and consensus algorithmshyperion-node: Full node implementation with RPC server and networkinghyperion-miner: Dedicated mining client with multi-threaded PoW mining
- Proof of Work (PoW) consensus mechanism
- Dynamic difficulty adjustment based on block time
- Merkle tree transaction verification
- Block validation with proper chain linking
- Serialization support for persistence
- JSON-RPC API server for mining and blockchain queries
- Mempool transaction management
- Blockchain persistence to disk
- Network listener for peer communication (basic)
- Real-time block validation and acceptance
- Multi-threaded mining with configurable worker count
- Work distribution across mining threads
- Automatic work restart when blocks are found
- Mining statistics and hashrate reporting
- Race condition prevention with atomic solution detection
- Configurable mining via CLI and config files
- Rust 1.89.0 or later
- Cargo package manager
- Clone the repository:
git clone https://github.com/Ashintosh/hyperion.git
cd hyperion- Build all components:
cargo build --releaseStart a Hyperion node with RPC server:
cargo run --bin hyperion-nodeThe node will:
- Listen for RPC requests on
http://127.0.0.1:6001 - Start a network listener on
127.0.0.1:6000 - Create a genesis block and initialize the blockchain
- Add test transactions to the mempool
In a separate terminal, start the miner:
cargo run --bin hyperion-minerThe miner will:
- Connect to the node's RPC server
- Request block templates
- Mine blocks using multiple threads
- Submit found blocks back to the node
Create a config.toml file in the hyperion-miner directory:
node_url = "http://127.0.0.1:6001"
threads = 4
reconnect_delay = 5
work_update_interval = 1000
stats_interval = 30
log_level = "info"NOTE: The miner is in a very basic form, and may not be fully configurable.
The node exposes a JSON-RPC 2.0 API on port 6001:
Get a block template for mining.
curl -X POST http://127.0.0.1:6001/rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"getblocktemplate","params":null}'Submit a mined block.
curl -X POST http://127.0.0.1:6001/rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":2,"method":"submitblock","params":{"block_hex":"..."}}'Get mining information and statistics.
curl -X POST http://127.0.0.1:6001/rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":3,"method":"getmininginfo","params":null}'Get blockchain information.
curl -X POST http://127.0.0.1:6001/rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":4,"method":"getblockchaininfo","params":null}'Get the current block height.
curl -X POST http://127.0.0.1:6001/rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":5,"method":"getblockcount","params":null}'Run the comprehensive test suite:
cargo testThe tests cover:
- Block validation and merkle tree computation
- Blockchain operations and validation
- Transaction handling
- Serialization/deserialization
- Proof of Work validation
- Difficulty adjustment algorithms
When running, the miner displays real-time statistics:
Mining Stats - Hashrate: 1234.56 H/s, Blocks: 5, Uptime: 2m 30s
- Target block time: 600 seconds (10 minutes)
- Difficulty adjustment: Every 3 blocks
- Proof of Work: SHA-256 double hashing
- Difficulty format: Compact representation (similar to Bitcoin)
- Version: Block format version
- Previous hash: Hash of the previous block
- Merkle root: Root hash of transaction merkle tree
- Timestamp: Block creation time
- Difficulty: Target difficulty for PoW
- Nonce: Proof of Work nonce
- Transactions: List of transactions in the block
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass:
cargo test - Submit a pull request
- The current implementation uses a very low difficulty for demonstration purposes
- In production, difficulty would be much higher and blocks would take longer to mine
- The miner uses atomic operations to prevent race conditions between workers
- Block validation includes full merkle tree verification and PoW checking
- Peer-to-peer networking with block propagation
- Transaction fees and UTXO model
- Digital signatures for transactions
- Wallet functionality for key management
- Mining pool support
- REST API alongside JSON-RPC
- Blockchain explorer interface
- Performance optimizations for high-difficulty mining
- Network synchronization and consensus
- Configuration for different network modes (testnet/mainnet)
- Significant code cleanup/refactoring
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
- Inspired by Bitcoin's blockchain architecture
- Built with the excellent Rust async ecosystem (Tokio, Axum)
- Thanks to the Rust community for outstanding documentation and tools
Note: This is an educational blockchain implementation. It is not suitable for production use in its current form and lacks many security features required for a real cryptocurrency.