Shard Chain
A processing thread, also known as a shard chain, is an independent block thread within the workchain. By default, workchain 0 has only one thread and one chain. The validators of this thread receive external messages and process them, as well as handle internal messages sent by themselves or from other workchains. If a thread becomes overloaded in the recent N blocks, it will be split: one thread is divided into two, and transactions are processed in parallel.
Accounts with addresses starting from 0:00.. - 0:88.. are now located in thread 1, while accounts 0:88.. - 0:FF.. are located in thread 2. Since all smart contracts communicate asynchronously with each other, there are no failures, and the throughput is doubled. When the load decreases, the threads will merge back after a period of time. If the load continues to increase, the two threads can be split repeatedly, and so on. The main chain has only one thread.
In TON, blocks are not just a list of transactions needed to achieve state changes. Instead, a block is:
A list of messages executing transactions, removing them from the incoming queue. New messages resulting from message processing entering the outgoing queue, and then message processing causing changes in the smart contract state. In other words, for validators of shard X to maintain the current state of shard Y, they do not need to execute all transactions in shard Y's block. They only need to download the block and summarize the changes that have occurred. This occurs in the message queue and smart contract state.
Fundamentally changing the blockchain world is not possible without a cost. To utilize this radical approach, TON smart contract developers must design their contracts in a different way. The basic atomic unit of the TON blockchain is the smart contract. Smart contracts have an address, code, and data unit (persistent state). This unit is called an atomic unit because smart contracts always have atomic synchronous access to all their persistent states.
Hypercube Network Routing
TON has pioneered an intelligent routing mechanism to ensure that transactions between any two blockchains can always be processed quickly, regardless of the system's size. The time required to send messages between TON blockchains increases logarithmically with the number of chains, allowing them to communicate at the fastest speed even when scaled to millions of chains.
In the TON blockchain, fast routing (Instant Hypercube Routing) and slow routing are two routing mechanisms used to process cross-chain transactions.
Fast Routing (Instant Hypercube Routing): The idea proposed by TON to speed up message routing, allowing cross-chain transactions to be completed in a very short time. In the traditional slow hypercube routing process, a message is routed from one shard chain to the destination shard chain along the hypercube network. However, during the message routing process, the validators of the destination shard chain can choose to process the message early and include it in a block, then provide a Merkle proof (receipt) to send a receipt to destroy the message being transmitted. This allows cross-chain transactions to be completed in a very short time. Fast routing achieves efficient cross-chain interaction by constructing a high-dimensional hypercube routing structure. In this structure, each chain is mapped to a vertex of the hypercube, and the distance between chains is represented by the number of hops between vertices. Through this method, transactions can be quickly routed on the shortest path, achieving efficient cross-chain interaction. Fast routing can complete cross-chain transactions in seconds without waiting for block confirmation.
Slow Routing: Slow routing is a relatively traditional method for processing cross-chain transactions, achieved by gradually transferring transactions from the source chain to the target chain. In this method, transactions are first packaged into a block on the source chain, then transferred to the target chain through a relayer. The validators of the target chain verify the validity of the transaction and then package it into a block on the target chain. The advantage of slow routing over fast routing is that it provides higher security and decentralization, as cross-chain transactions require a complete block confirmation process. Similar to the TCP/IP network, messages are addressed and sent to the destination by the destination IP address, ensuring that messages are reliably propagated to the destination chain in order. For a sharded chain hypercube network with a scale of N, the number of intermediate sharded chains (hop) required is log16(N)-1. Therefore, only 4 routing nodes (intermediate sharded chains) are needed to support millions of sharded chains.
Why Design It This Way?
Distributed validation nodes are needed. If the system is very large and has tens of thousands of nodes, the burden is too heavy to expand. After sharding, each shard has a set, shard0, shard1, etc., and cross-shard communication is required. Communication can cross shards, from one to another, meaning there needs to be a routing mechanism between shards. Connections form a route, passing through certain intermediate nodes. Each time a message passes through a route, the transmission time increases by one block time.
As the total number of shard chains grows, this will require a large amount of computing power and network bandwidth, limiting the system's scalability. Therefore, it is not possible to directly transmit messages from any one shard to all other shards. Instead, each shard is only "connected" to a different shard on a hexadecimal number in its (w, s) shard identifier. In this way, all shard chains form a "hypercube" graph, and messages are passed along the edges of this hypercube.
If a message is sent to a shard different from the current one, the current shard identifier's hexadecimal number (deterministically chosen) will be replaced by the corresponding number of the target shard, and the resulting identifier will serve as the approximate target, becoming the recipient of the forwarded message.
The main advantage of hypercube routing lies in the block validity condition. Validators creating blocks for shard chains must collect and process messages from the "adjacent" shard chains' output queues, or they will lose their staking. In this way, it can be expected that any message will eventually reach its final destination; messages will neither be lost nor duplicated during transmission.
Hypercube routing introduces some additional delay and cost, as messages need to be forwarded through several intermediate shard chains. However, the number of these intermediate shard chains grows very slowly, related to the logarithm of the total number of shard chains N.
Asynchronous Communication
Smart contracts on TON implement asynchronous communication, analogous to microservices on the internet. Each microservice only has atomic synchronous access to its local data. Communication between two microservices involves sending asynchronous messages over the network.
In system architecture, larger systems often require microservice architecture. This distributed approach requires some trade-offs but can bring benefits to user experience. Modern system management relies on sequencers like Kubernetes to obtain a set of containerized microservices, automatically start new instances on demand (auto-scaling), and effectively partition them between machines.
Analogous to using Kubernetes (a large-scale cluster management system), this is exactly what TON does. As the load on a specific shard chain increases, it is split into two parts. Since smart contracts are atomic, they will never be split in half. This means that some smart contracts that were once on the same shard chain may one day find themselves on different shard chains.
TON's virtual machine (TVM) is applying the concept of distributed microservices to the overall architecture, benchmarking against Ethereum's EVM.
Decentralized State
This is the most complex and challenging sharding mechanism in the sharding field. The entire database is separated and placed on different shards. Each shard stores all its own data, rather than the state of the entire blockchain.
In the TON blockchain sharding, all services are implemented as smart contracts, and the state data of smart contracts is only stored in the corresponding shard network, achieving state sharding.
Furthermore, in TON, contracts have implemented a unique implementation path, where each user can manage token state in their own contract, truly achieving decentralization at the blockchain state level. I will explore the principles of this design in detail through a case study.
First, it is necessary to understand the Wallet contract and Jetton wallet contract. The Wallet contract is a user-specific smart contract used to manage a user's tokens on the TON blockchain. The Jetton wallet contract is a special type of Wallet contract specifically used to manage a user's Jetton tokens. These tokens can be used to pay network fees and execute smart contracts. Each user has their own Wallet contract and Jetton wallet contract. These contracts act as the user's digital wallet for storing and managing tokens. At the same time, these contracts can interact with the contracts of other users, enabling decentralized asset transfers and transactions.
Suppose user A and user B each have their own Wallet contract. User A wants to transfer a certain amount of tokens to user B. In this case, user A's Wallet contract will interact with user B's Wallet contract to facilitate the token transfer. The entire process does not rely on a centralized contract, but rather is achieved through two decentralized contracts.
Users on the TON blockchain have their own contracts to manage asset states, meaning there is no risk of a single centralized contract managing all assets. This increases the decentralization of the system and reduces the risk of single points of failure. The asset states of all users are managed by a dedicated contract, preventing attackers from affecting the entire system by attacking a single centralized contract. Asset transactions between users can also be automatically executed through smart contracts, avoiding the risk of human error. Users can also customize their own Wallet contract and Jetton wallet contract according to their needs, enabling more functionality and use cases. This provides users with greater flexibility and autonomy. Each person manages asset states in their own contract, improving the system's scalability. As the number of users increases, the number of contracts will also increase accordingly, but this will not put excessive pressure on the entire system, as each contract operates independently.
The above is my analysis of the scalability and technical architecture concepts in the TON blockchain whitepaper. I would like to thank Dr. Awesome Doge for editing the first draft. I also want to express my gratitude to the development teams in Russia and Ukraine for their persistent efforts, and finally, I would like to thank Mr. Nikolai Durov, the founder of Telegram, for his great design many years ago, all for the glory of the human mind.
免责声明:本文章仅代表作者个人观点,不代表本平台的立场和观点。本文章仅供信息分享,不构成对任何人的任何投资建议。用户与作者之间的任何争议,与本平台无关。如网页中刊载的文章或图片涉及侵权,请提供相关的权利证明和身份证明发送邮件到support@aicoin.com,本平台相关工作人员将会进行核查。