Skip to content

Latest commit

Β 

History

History
241 lines (189 loc) Β· 10.1 KB

File metadata and controls

241 lines (189 loc) Β· 10.1 KB

🌐 CIRO Network P2P Architecture

Overview

This document outlines the peer-to-peer (P2P) networking architecture for CIRO Network, detailing the transition from a centralized coordinator model to a fully decentralized compute marketplace built on libp2p.


πŸ”„ Current Architecture (Centralized)

System Flow

Job Clients β†’ HTTP API β†’ Coordinator β†’ Database β†’ HTTP API β†’ Workers
     ↓                        ↓                        ↓
[REST API]            [In-Memory Pool]           [Registration]
                      [Task Queue]               [Capability Match]

Current Limitations

  • Single Point of Failure: Coordinator centralization
  • Limited Scalability: HTTP-based communication bottleneck
  • No Direct Worker Communication: Everything routes through coordinator
  • Static Discovery: Workers must know coordinator endpoints
  • No Fault Tolerance: If coordinator fails, entire network stops

🎯 Target P2P Architecture (Decentralized)

Network Topology

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    CIRO P2P Network                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚  Worker A   │◄──►│  Worker B   │◄──►│  Worker C   β”‚         β”‚
β”‚  β”‚  (libp2p)   β”‚    β”‚  (libp2p)   β”‚    β”‚  (libp2p)   β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚         β”‚                 β”‚                 β”‚                  β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                           β”‚                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚              Gossip Protocol                             β”‚  β”‚
β”‚  β”‚  β€’ Job Distribution    β”‚  β€’ Capability Broadcasting      β”‚  β”‚
β”‚  β”‚  β€’ Result Collection   β”‚  β€’ Reputation Updates           β”‚  β”‚
β”‚  β”‚  β€’ Network Health      β”‚  β€’ Blockchain State Sync       β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                           β”‚                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚                DHT-Based Discovery                       β”‚  β”‚
β”‚  β”‚  β€’ Peer Finding        β”‚  β€’ Capability Indexing         β”‚  β”‚
β”‚  β”‚  β€’ Bootstrap Nodes     β”‚  β€’ Network Topology            β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚                 Starknet Integration                       β”‚  β”‚
β”‚  β”‚  β€’ Job Contracts      β”‚  β€’ Payment Settlement           β”‚  β”‚
β”‚  β”‚  β€’ Worker Staking     β”‚  β€’ Reputation Storage           β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Advantages

  • Decentralized: No single point of failure
  • Scalable: Direct peer-to-peer communication
  • Fault Tolerant: Network continues operating with node failures
  • Efficient: Reduced latency through direct connections
  • Cost Effective: No need for centralized infrastructure

πŸ—οΈ P2P Network Components

1. Core P2P Layer (libp2p)

  • Transport: TCP, WebSocket, QUIC
  • Security: Noise protocol encryption
  • Multiplexing: Yamux for connection efficiency
  • Identity: Ed25519 keys for peer authentication

2. Peer Discovery (DHT)

  • Kademlia DHT: Distributed hash table for peer finding
  • Bootstrap Nodes: Initial network entry points
  • Capability Indexing: Find peers by specific capabilities
  • Network Topology: Maintain network structure view

3. Gossip Protocol

  • Job Distribution: Broadcast available jobs
  • Worker Capabilities: Announce worker specifications
  • Result Collection: Aggregate computation results
  • Network Health: Monitor peer status and reputation

4. Starknet Integration

  • Job Contracts: On-chain job registration and escrow
  • Payment Settlement: Automated payment distribution
  • Reputation Storage: Long-term reputation tracking
  • Dispute Resolution: Smart contract-based arbitration

πŸ“Š Network Protocol Flow

Job Execution Flow

1. Job Submission
   Client β†’ Network β†’ Gossip Broadcast

2. Worker Discovery
   Network β†’ DHT Lookup β†’ Capability Matching

3. Job Assignment
   Bidding Process β†’ Worker Selection β†’ Task Distribution

4. Execution
   Worker β†’ Compute β†’ Result Generation

5. Result Collection
   Result β†’ Gossip β†’ Aggregation β†’ Verification

6. Settlement
   Blockchain β†’ Payment β†’ Reputation Update

πŸ”§ Implementation Architecture

Core Modules

// rust-node/src/network/
β”œβ”€β”€ p2p.rs              // Core P2P networking layer
β”œβ”€β”€ discovery.rs        // DHT-based peer discovery
β”œβ”€β”€ gossip.rs          // Gossip protocol implementation
β”œβ”€β”€ worker_registry.rs  // Worker capability management
β”œβ”€β”€ job_distribution.rs // Decentralized job distribution
β”œβ”€β”€ result_collector.rs // Result aggregation system
└── reputation.rs       // Network health & reputation

Key Data Structures

pub struct P2PNetwork {
    swarm: libp2p::Swarm<CiroBehaviour>,
    local_peer_id: PeerId,
    bootstrap_peers: Vec<PeerId>,
    capability_index: HashMap<String, Vec<PeerId>>,
}

pub struct GossipMessage {
    JobAnnouncement(JobAnnouncement),
    WorkerCapabilities(WorkerCapabilities),
    JobResult(JobResult),
    ReputationUpdate(ReputationUpdate),
}

🎯 Migration Strategy

Phase 1: Hybrid Operation

  • Maintain existing centralized coordinator
  • Add P2P capabilities alongside current system
  • Allow gradual worker migration to P2P

Phase 2: P2P Primary

  • P2P becomes primary job distribution method
  • Centralized coordinator as fallback
  • Monitor network health and performance

Phase 3: Full Decentralization

  • Remove centralized coordinator dependency
  • Pure P2P operation
  • Enhanced fault tolerance and scalability

πŸ“ˆ Performance Targets

Network Metrics

  • Latency: <100ms for job distribution
  • Discovery: <5s to find suitable workers
  • Throughput: 100+ jobs/second network capacity
  • Uptime: >99.9% network availability

Scalability Metrics

  • Network Size: 1000+ concurrent workers
  • Concurrent Jobs: 500+ simultaneous executions
  • Data Efficiency: Minimal gossip overhead
  • Connection Stability: Resilient to network churn

πŸ”’ Security Considerations

Network Security

  • Peer Authentication: Ed25519 cryptographic identity
  • Transport Encryption: Noise protocol for all communications
  • Reputation System: Prevent malicious actor participation
  • Rate Limiting: Protect against DoS attacks

Economic Security

  • Stake Requirements: Workers must stake tokens to participate
  • Slashing Conditions: Penalize malicious or poor performance
  • Dispute Resolution: Smart contract arbitration system
  • Payment Security: Escrow-based payment protection

πŸš€ Future Enhancements

Advanced Features

  • Cross-Chain Support: Multi-blockchain job execution
  • Zero-Knowledge Proofs: Verifiable computation results
  • Dynamic Pricing: Market-based job pricing
  • Mobile Workers: Smartphone-based compute participation

Optimization Opportunities

  • Network Topology: Optimize peer connections for efficiency
  • Caching Strategies: Intelligent result and model caching
  • Load Balancing: Advanced job distribution algorithms
  • Edge Computing: Geographically distributed compute

πŸ“š References

Technical Documentation

Implementation Guidelines


This architecture document serves as the foundation for implementing CIRO Network's transition to a fully decentralized compute marketplace. Regular updates will be made as the implementation progresses.