1 stable release
| new 1.1.19 | Jan 7, 2026 |
|---|
#21 in #swarm
94KB
2K
SLoC
Hanzo Compute - BitTorrent-style Decentralized Compute Protocol
This crate implements a BitTorrent-inspired protocol for distributing AI compute tasks across a decentralized network of peers. Key features:
- Swarm Management: Peer discovery, connection management, and reputation tracking
- Piece Distribution: Task decomposition into verifiable pieces
- Rarest-First Scheduling: Prioritize pieces that are least available in the swarm
- Result Verification: Multi-peer consensus and TEE attestation support
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ ComputeSwarm │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Peers │ │ Tasks │ │ Scheduler │ │
│ │ (DashMap) │ │ (DashMap) │ │ (rarest-1st)│ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────────────────────────────────────┐ │
│ │ PieceManager │ │
│ │ - Split tasks into pieces │ │
│ │ - Track piece availability │ │
│ │ - Manage piece completion │ │
│ └─────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────┐ │
│ │ ResultVerifier │ │
│ │ - Hash verification │ │
│ │ - Multi-peer consensus │ │
│ │ - TEE attestation (optional) │ │
│ └─────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Example
use hanzo_compute::{ComputeSwarm, SwarmConfig, ComputeTask, TaskType};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a swarm with default config
let config = SwarmConfig::default();
let swarm = ComputeSwarm::new(config).await?;
// Submit a compute task
let task = ComputeTask::new(
TaskType::Inference {
model: "llama-3.1-8b".to_string(),
prompt: "Hello, world!".to_string(),
max_tokens: 100,
},
1.0, // reward in AI coins
);
let task_id = swarm.submit_task(task).await?;
// Wait for result
let result = swarm.await_result(&task_id).await?;
println!("Result: {:?}", result);
Ok(())
}
Dependencies
~12–53MB
~735K SLoC