+ Detailed Flow Sequence
+
+ 1. CLI Wrapper Execution
+ User Command:
+ ./scripts/aitbc-cli.sh submit inference --prompt "What is machine learning?" --model llama3.2:latest
+
+ Internal Process:
+
+ - Bash script (aitbc-cli.sh) parses arguments
+ - Sets environment variables:
+
+ - AITBC_URL=http://127.0.0.1:18000
+ - CLIENT_KEY=REDACTED_CLIENT_KEY
+
+
+ - Calls Python client: python3 cli/client.py --url $AITBC_URL --api-key $CLIENT_KEY submit inference --prompt "..."
+
+
+ 2. Python Client Processing
+ File: /cli/client.py
+
+ Steps:
+
+ - Parse command-line arguments
+ - Prepare job submission payload:
+
{
+ "type": "inference",
+ "prompt": "What is machine learning?",
+ "model": "llama3.2:latest",
+ "client_key": "REDACTED_CLIENT_KEY",
+ "timestamp": "2025-01-29T14:50:00Z"
+}
+
+
+
+ 3. Coordinator API Call
+
+
HTTP Request:
+
POST /v1/jobs
+Host: 127.0.0.1:18000
+Content-Type: application/json
+X-Api-Key: REDACTED_CLIENT_KEY
+
+{
+ "type": "inference",
+ "prompt": "What is machine learning?",
+ "model": "llama3.2:latest"
+}
+
+
+ Coordinator Service (Port 18000):
+
+ - Receives HTTP request
+ - Validates API key and job parameters
+ - Generates unique job ID: job_123456
+ - Creates job record in database
+ - Returns initial response:
+
{
+ "job_id": "job_123456",
+ "status": "pending",
+ "submitted_at": "2025-01-29T14:50:01Z"
+}
+
+
+
+ 4. Blockchain Transaction
+ Coordinator → Blockchain Node (RPC Port 26657):
+
+
+ - Coordinator creates blockchain transaction:
+
{
+ "type": "submit_job",
+ "job_id": "job_123456",
+ "client": "REDACTED_CLIENT_KEY",
+ "payload_hash": "abc123...",
+ "reward": "100aitbc"
+}
+
+ - RPC Call to blockchain node:
+
curl -X POST http://127.0.0.1:26657 \
+ -d '{
+ "jsonrpc": "2.0",
+ "method": "broadcast_tx_sync",
+ "params": {"tx": "base64_encoded_transaction"}
+ }'
+
+ - Blockchain validates and includes transaction in next block
+ - Transaction hash returned: 0xdef456...
+
+
+ 5. Job Queue and Miner Assignment
+ Coordinator Internal Processing:
+
+ - Job added to pending queue (Redis/Database)
+ - Miner selection algorithm runs:
+
+ - Check available miners
+ - Select based on stake, reputation, capacity
+
+
+ - Selected miner: REDACTED_MINER_KEY
+
+
+
+
Coordinator → Miner Daemon (Port 18001):
+
POST /v1/jobs/assign
+Host: 127.0.0.1:18001
+Content-Type: application/json
+X-Api-Key: REDACTED_ADMIN_KEY
+
+{
+ "job_id": "job_123456",
+ "job_data": {
+ "type": "inference",
+ "prompt": "What is machine learning?",
+ "model": "llama3.2:latest"
+ },
+ "reward": "100aitbc"
+}
+
+
+ 6. Miner Processing
+ Miner Daemon (Port 18001):
+
+ - Receives job assignment
+ - Updates job status to running
+ - Notifies coordinator:
+
POST /v1/jobs/job_123456/status
+{"status": "running", "started_at": "2025-01-29T14:50:05Z"}
+
+
+
+ 7. Ollama Inference Request
+
+
Miner → Ollama Server (Port 11434):
+
POST /api/generate
+Host: 127.0.0.1:11434
+Content-Type: application/json
+
+{
+ "model": "llama3.2:latest",
+ "prompt": "What is machine learning?",
+ "stream": false,
+ "options": {
+ "temperature": 0.7,
+ "num_predict": 500
+ }
+}
+
+
+ Ollama Processing:
+
+ - Loads model into GPU memory
+ - Processes prompt through neural network
+ - Generates response text
+ - Returns result:
+
{
+ "model": "llama3.2:latest",
+ "response": "Machine learning is a subset of artificial intelligence...",
+ "done": true,
+ "total_duration": 12500000000,
+ "prompt_eval_count": 15,
+ "eval_count": 150
+}
+
+
+
+ 8. Result Submission to Coordinator
+
+
Miner → Coordinator (Port 18000):
+
POST /v1/jobs/job_123456/complete
+Host: 127.0.0.1:18000
+Content-Type: application/json
+X-Miner-Key: REDACTED_MINER_KEY
+
+{
+ "job_id": "job_123456",
+ "result": "Machine learning is a subset of artificial intelligence...",
+ "metrics": {
+ "compute_time": 12.5,
+ "tokens_generated": 150,
+ "gpu_utilization": 0.85
+ },
+ "proof": {
+ "hash": "hash_of_result",
+ "signature": "miner_signature"
+ }
+}
+
+
+ 9. Receipt Generation
+ Coordinator Processing:
+
+ - Verifies miner's proof
+ - Calculates payment: 12.5 seconds × 0.02 AITBC/second = 0.25 AITBC
+ - Creates receipt:
+
{
+ "receipt_id": "receipt_789",
+ "job_id": "job_123456",
+ "client": "REDACTED_CLIENT_KEY",
+ "miner": "REDACTED_MINER_KEY",
+ "amount_paid": "0.25aitbc",
+ "result_hash": "hash_of_result",
+ "block_height": 12345,
+ "timestamp": "2025-01-29T14:50:18Z"
+}
+
+
+
+ 10. Blockchain Receipt Recording
+ Coordinator → Blockchain (RPC Port 26657):
+{
+ "type": "record_receipt",
+ "receipt": {
+ "receipt_id": "receipt_789",
+ "job_id": "job_123456",
+ "payment": "0.25aitbc"
+ }
+}
+
+ 11. Client Polling for Result
+ CLI Client Status Check:
+ ./scripts/aitbc-cli.sh status job_123456
+
+
+
HTTP Request:
+
GET /v1/jobs/job_123456
+Host: 127.0.0.1:18000
+X-Api-Key: REDACTED_CLIENT_KEY
+
+
Response:
+
{
+ "job_id": "job_123456",
+ "status": "completed",
+ "result": "Machine learning is a subset of artificial intelligence...",
+ "receipt_id": "receipt_789",
+ "completed_at": "2025-01-29T14:50:18Z"
+}
+
+
+ 12. Final Output to User
+ CLI displays:
+ Job ID: job_123456
+Status: completed
+Result: Machine learning is a subset of artificial intelligence...
+Receipt: receipt_789
+Completed in: 17 seconds
+Cost: 0.25 AITBC
+
+ Message Flow Timeline
+ 0s: User submits CLI command
+└─> 0.1s: Python client called
+ └─> 0.2s: HTTP POST to Coordinator (port 18000)
+ └─> 0.3s: Coordinator validates and creates job
+ └─> 0.4s: RPC to Blockchain (port 26657)
+ └─> 0.5s: Transaction in mempool
+ └─> 1.0s: Job queued for miner
+ └─> 2.0s: Miner assigned (port 18001)
+ └─> 2.1s: Miner accepts job
+ └─> 2.2s: Ollama request (port 11434)
+ └─> 14.7s: Inference complete (12.5s processing)
+ └─> 14.8s: Result to Coordinator
+ └─> 15.0s: Receipt generated
+ └─> 15.1s: Receipt on Blockchain
+ └─> 17.0s: Client polls and gets result
+