| Crates.io | chie-coordinator |
| lib.rs | chie-coordinator |
| version | 0.1.0 |
| created_at | 2026-01-18 14:01:38.22698+00 |
| updated_at | 2026-01-18 14:01:38.22698+00 |
| description | Central coordinator server for CHIE Protocol |
| homepage | |
| repository | https://github.com/cool-japan/chie |
| max_upload_size | |
| id | 2052390 |
| size | 1,587,204 |
Central Coordinator Server for the CHIE Protocol.
The coordinator is the central trust authority that:
┌─────────────────────────────────────────────────────────────┐
│ Coordinator Server │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ Axum Router │ │
│ │ POST /api/proofs → submit_proof() │ │
│ │ POST /api/content → register_content() │ │
│ │ GET /health → health_check() │ │
│ └───────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ Verification Engine │ │
│ │ 1. Nonce replay check │ │
│ │ 2. Timestamp validation (5-min window) │ │
│ │ 3. Signature verification (Ed25519) │ │
│ │ 4. Statistical anomaly detection (z-score) │ │
│ └───────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ Reward Engine │ │
│ │ Formula: base * demand_multiplier * quality_factor │ │
│ │ Distribution: provider + creator + referrers │ │
│ └───────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ PostgreSQL Database │ │
│ │ users, content, nodes, bandwidth_proofs, │ │
│ │ point_transactions, content_demand_hourly │ │
│ └───────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
// Submit bandwidth proof
POST /api/proofs
Body: BandwidthProof (JSON)
Response: { accepted: bool, reward: Option<u64>, message: String }
// Register new content
POST /api/content
Body: { cid, title, description, size_bytes, price, creator_id }
Response: { success: bool, content_id: Option<UUID>, message: String }
Multi-step verification pipeline:
let verifier = ProofVerifier::new(pool, VerificationConfig::default());
let result = verifier.verify(&proof).await?;
// VerificationResult
// - is_valid: bool
// - status: ProofStatus (Verified/Rejected)
// - rejection_reason: Option<String>
// - anomalies: Vec<AnomalyReport>
// - quality_score: f64 (0.0 to 1.0)
Verification Steps:
Dynamic pricing based on supply/demand:
let engine = RewardEngine::new(pool, RewardConfig::default());
let distribution = engine.calculate_and_distribute(
&proof,
proof_id,
quality_score,
provider_user_id,
content_creator_id,
).await?;
// RewardDistribution
// - provider_reward: Points
// - creator_reward: Points (10% of total)
// - referrer_rewards: Vec<(UUID, Points)> (5%, 2%, 1% tiers)
// - platform_fee: Points (10% of total)
Reward Formula:
reward = base_per_gb * demand_multiplier * latency_factor * quality_score
demand_multiplier = sqrt(demand/supply) // Capped at 3x
latency_factor = 1.0 if <100ms, 0.5 if >500ms
Models (models.rs):
User, Content, Node, ContentPinBandwidthProofRecord, PointTransaction, PurchaseContentDemandHourly, FraudReportRepositories (repository.rs):
UserRepository: User CRUD, points management, referral chainContentRepository: Content CRUD, trending queriesNodeRepository: Node registration, heartbeat, seeder lookupProofRepository: Proof storage, nonce checking, reward recordingTransactionRepository: Point transaction loggingAnalyticsRepository: Demand metrics, hourly aggregationVerificationConfig {
timestamp_tolerance_ms: 300_000, // 5 minutes
anomaly_z_threshold: 3.0,
min_latency_ms: 1,
high_latency_threshold_ms: 500,
}
RewardConfig {
base_reward_per_gb: 10, // Points per GB
max_demand_multiplier: 3.0,
min_demand_multiplier: 0.5,
optimal_latency_ms: 100,
penalty_latency_ms: 500,
max_latency_penalty: 0.5,
creator_share: 0.1, // 10%
platform_fee_share: 0.1, // 10%
referral_tiers: [0.05, 0.02, 0.01], // 5%, 2%, 1%
}
| Module | Purpose |
|---|---|
main.rs |
Server entry point |
api/mod.rs |
REST API endpoints |
verification/mod.rs |
Proof verification pipeline |
rewards/mod.rs |
Reward calculation engine |
db/mod.rs |
Database models and repositories |
nonce_cache.rs |
Redis nonce caching |
batch.rs |
Batch proof processing |
auth.rs |
JWT authentication |
validation.rs |
Request validation middleware |
fraud.rs |
Fraud detection and alerting |
metrics.rs |
Prometheus metrics export |
See migrations/001_initial_schema.sql for full schema.
Key tables:
users: User accounts with points balancecontent: Content registry with metadatanodes: Node registry with reputationbandwidth_proofs: Proof recordspoint_transactions: Audit trailused_nonces: Replay attack prevention# Set environment
export DATABASE_URL="postgresql://user:pass@localhost/chie"
export RUST_LOG="info"
# Run migrations
sqlx migrate run
# Start server
cargo run --release -p chie-coordinator
# Listening on 0.0.0.0:3000