How ton-blockchain/ton works
Project Type and Purpose
• This is the TON monorepo: a reference implementation of a full blockchain node and tooling suite, including the full-node/validator, lite-client, tonlib library, FunC compiler (tolk), Fift assembler, emulators, storage daemon, and various utilities.
• It’s a distributed peer-to-peer system with multiple protocols (ADNL, DHT, Overlay, RLDP) and components for consensus (Catchain), storage (TonDb, cell storage, archive DB), execution (TVM), and client APIs (lite-client, HTTP/RPC).
High-Level Components
a. Network Layer
• ADNL (abstract datagram layer)
• DHT (peer discovery)
• Overlay network & FEC broadcast
• RLDP / RLDP2 (reliable packet delivery)
• HTTP server (microhttpd) for RPC endpoints
b. Consensus Layer
• Catchain module (block proposal, confirmation)
c. Storage Layer
• TonDb (RocksDB-based persistent cell store)
• Archive-DB, State-DB, StaticFilesDB
• Optional external “storage-daemon” process (smart-contract storage provider)
d. Execution Layer
• TVM (virtual machine): crypto/vm modules, cell parsing, dispatch, stack, op-code tables
• FunC compiler (tolk) & Fift assembler libraries/tools
e. API & Client Layer
• lite-client (CLI & library)
• tonlib (C++ library + JSON wrapper)
• validator-engine-console & validator-engine
• third-party clients (Android, C++ examples)
f. Build & Deployment
• Assembly scripts (Linux/MacOS/AppImage/Android/WebAssembly)
• Docker manifests
• CMake build system
Relationships and Data Flows
• Peer Discovery: HTTP/UDP → ADNL ←→ DHT
• P2P Messaging: ADNL → Overlay → RLDP → Catchain messages
• Consensus: Catchain feeds validated blocks into Validator
• Storage: Validator writes blocks/cells into TonDb and ArchiveDB
• Execution: Validator invokes TVM to run smart contracts in blocks
• Client Queries: lite-client/tonlib → HTTP RPC → Validator → TVM/Storage → JSON response
• Smart-Contract Compilation: FunC (tolk) / Fift produce BOC code deployed on chain
• Optional Storage Daemon: storage-daemon ↔ Validator via internal API for off-chain storage
Architectural Patterns & Principles
• Layered modular architecture with clear protocol separation
• Actor-model concurrency (tdactor) for internal scheduling and I/O
• Event-driven P2P networking with reliable packet protocols
• Separation of persistent storage (TonDb) from in-memory execution (TVM)
• Extensibility via plugin-style smart contract languages (FunC, Fift, Wasm)