How blinddoggy/tronapi works
To accurately represent the architecture of the chia-blockchain project, follow these tailored guidelines. Your goal is to decompose the system into logical components, show their relationships, and highlight the technologies and design patterns in use.
Project type and purpose
• This is a full-stack cryptocurrency implementation, written primarily in Python, with a small Node.js-based REST API layer under server.js + src/.
• Core functionality: run a full Chia node (consensus, block storage, mempool, networking), farming/harvesting, wallet services, timelords (VDF), and seeding (peer discovery).
Main components
a. Client layer
• CLI (chia commands under chia/cmds/), built with Click and Python.
• Optional Web UI / REST API server (server.js + src/controllers/*.js) written in Node.js/Express.
b. RPC/Gateway layer
• The Chia Daemon (chia/daemon/server.py) exposes JSON-RPC endpoints over HTTP on localhost.
• Node.js controllers and CLI tools communicate over these RPC endpoints.
c. Service layer (each process is usually spawned by the daemon)
• Full Node (chia/full_node/full_node.py + full_node_api.py): block and mempool management, network syncing.
• Farmer (chia/farmer/farmer.py + farmer_api.py): block creation coordinator.
• Harvester (chia/harvester/harvester.py + harvester_api.py): reads polynomial proofs from disk.
• Wallet (chia/wallet/wallet.py + wallet_node_api.py): UTXO management, transaction creation.
• Timelord (chia/timelord/timelord.py + timelord_api.py): VDF orchestration.
• Introducer & Seeder (chia/introducer/introducer.py, chia/seeder/crawler.py): peer discovery & DNS seeder.
• Data Layer (chia/data_layer/data_layer_server.py + plugins): off-chain data storage via S3 or local store.
d. Persistence layer
• Block store, coin store, mempool caches, SQLite / RocksDB wrappers under chia/util/db_* and chia/full_node/*_store.py.
• File-based “plots” and log files on disk.
e. P2P network
• Protocol definitions (chia/protocols/*.py) and server (chia/server/server.py) implement gossip/flood-style messaging on TCP port 8444.
• UPnP support for NAT traversal.
Relationships & Data flows
1. CLI / Web UI → HTTP RPC → Daemon
2. Daemon → spawns/internal dispatch → each sub-service
3. Full Node ↔ P2P Network ← other peers
4. Farmer requests proofs from Harvester → proposes blocks to Full Node
5. Wallet submits transactions to Full Node → broadcast to network
6. Timelord ↔ Full Node chain snapshots for VDF proofs
7. Data Layer plugin ↔ external S3 service or local object store
8. Introducer/Seeder maintain peer lists and feed Full Node
Architectural patterns & principles
• Modular microservices: each daemon sub-service has its own RPC API.
• Hexagonal architecture: clear ports/adapters (CLI & Web UI are adapters, RPC is the port, services are the core).
• Event-driven & async: Python asyncio for networking and RPC.
• Domain separation: consensus (chia/consensus/), networking (chia/server/), storage (chia/full_node/*_store.py), CLI (chia/cmds/), puzzles (chia/wallet/puzzles, chia/consensus/puzzles).
Technologies & frameworks
• Python 3.8+ with asyncio, Click (CLI), JSON-RPC, uvicorn-like server for RPC.
• Node.js/Express for REST layer (if used).
• SQLite / RocksDB via Python wrappers.
• Jinja2 for build scripts (packaging).
• CLVM puzzles (.clsp/.clib) for smart‐contract logic.
• BLS signatures, Proof-of-Space & VDF cryptography.
Final checklist
• Component labels (e.g., Full Node, Farmer, Harvester)