chie-core
Core protocol logic for the CHIE Protocol.
Overview
This crate provides the main business logic for CHIE nodes, including:
- Content node management
- Bandwidth proof protocol implementation
- Content management and storage
- Coordinator communication
Architecture
┌────────────────────────────────────────────────────────────┐
│ ContentNode │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ KeyPair (Ed25519) │ NodeConfig │ │
│ │ - Sign chunk responses │ - max_storage_bytes │ │
│ │ - Generate proofs │ - max_bandwidth_bps │ │
│ │ │ - coordinator_url │ │
│ └──────────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ PinnedContents │ │
│ │ HashMap<CID, PinnedContent> │ │
│ │ - cid, size_bytes, encryption_key │ │
│ │ - predicted_revenue_per_gb │ │
│ └──────────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────────┘
Modules
node/mod.rs - Content Node
Main node implementation for content providers.
use ;
let config = NodeConfig ;
let mut node = new;
// Pin content for distribution
node.pin_content;
// Handle incoming chunk request
let response = node.handle_chunk_request.await?;
// Submit proof to coordinator
node.submit_proof.await?;
protocol/mod.rs - Bandwidth Proof Protocol
Protocol helpers for creating requests and proofs.
use ;
// Create a request with random challenge
let request = create_chunk_request;
// After receiving response and verifying, create proof
let proof = create_bandwidth_proof;
content/mod.rs - Content Management
Content storage and metadata caching.
use ContentManager;
let manager = new;
// Cache metadata for quick access
manager.cache_metadata;
// Query cached metadata
if let Some = manager.get_metadata
// Check total storage used
let used = manager.total_storage_used;
Bandwidth Proof Flow
1. Requester 2. Provider
│ │
│ create_chunk_request() │
│ - Generate nonce │
│ - Set timestamp │
│ - Include public key │
│ │
│ ────── ChunkRequest ────────► │
│ │ handle_chunk_request()
│ │ - Read chunk from storage
│ │ - Hash chunk (BLAKE3)
│ │ - Sign (nonce||hash||req_pk)
│ │ - Encrypt chunk
│ ◄───── ChunkResponse ──────── │
│ │
│ Verify provider signature │
│ Decrypt chunk │
│ Verify hash │
│ Sign receipt │
│ │
│ create_bandwidth_proof() │
│ │
│ ────── BandwidthProof ──────────────► Coordinator
Investment Caching Strategy
Nodes can strategically choose which content to pin based on expected returns:
// High demand / Low supply = High returns
// Predicted revenue = base_reward * sqrt(demand/supply)
PinnedContent
PinnedContent
Modules
| Module | Purpose |
|---|---|
node/mod.rs |
Content node management |
protocol/mod.rs |
Bandwidth proof protocol helpers |
content/mod.rs |
Content management and metadata |
storage/mod.rs |
Chunk storage and retrieval |
chunk_encryption.rs |
Per-chunk encryption with nonces |
integrity.rs |
Content integrity verification |
pinning.rs |
Selective pinning optimizer |
popularity.rs |
Content popularity tracking |
prefetch.rs |
Chunk prefetching |
dedup.rs |
Content deduplication |
ratelimit.rs |
Bandwidth rate limiting |
proof_submit.rs |
Proof submission with retry |
Configuration
| Parameter | Default | Description |
|---|---|---|
max_storage_bytes |
50 GB | Maximum storage allocation |
max_bandwidth_bps |
100 Mbps | Maximum bandwidth provision |
coordinator_url |
https://coordinator.chie.network | Coordinator API endpoint |