Author: Kiwi from PKU blockchain Association
作者:北大区块链协会 Kiwi
https://twitter.com/KiwiCryptoBig
Keytakeaways
TON possesses a core technological logic centered around high-speed applications: TON originated from Telegram, with transactions directly recorded on the chain based on messages, supporting peer-to-peer communication.
-
Asynchronous message delivery: FunC, chosen as the development language, facilitates communication among TON nodes through the exchange of “messages.” However, as TON operates as an asynchronous chain, introducing the concept of logical time (It) is crucial for correctly synchronizing messages across chains. This is achieved by ensuring that the logical time (lt) of messages is strictly executed in chronological order, guaranteeing the accurate execution of information.
-
Hypercube message routing mechanism: TON employs a combination of regular routing and fast routing. Regular routing passes messages between shards through a hypercube structure involving adjacent nodes. Fast routing incorporates Merkle proofs that can relay messages along the edges of the hypercube, enhancing speed.
-
PoS + BFT consensus for ecosystem development: POS avoids extensive computations during the block generation process, resulting in higher efficiency, lower costs, and improved network performance, making it conducive to the practical implementation of DAPP applications. While DPOS is faster, its trust speed is slower than BFT systems. Therefore, TON opts for the BFT consensus mechanism.
TON’s dynamic multi-shard architecture facilitates application scalability: TON enhances speed through parallel queries, improves query accuracy with dynamic sharding, and boosts extensibility through a bag of cells structure.
-
Dynamic multi-shard architecture: TON comprises three layers – a single masterchain, multiple Workchains, and shardchains that can dynamically increase, decrease, and split. Each shardchain is a collection of various account chains, and DAPPs can autonomously activate specific shardchains.
-
Rapidly updatable global state: Updating the global state involves a structure similar to DAG called “bag of cells.” It swiftly updates by combining a new and old set of cells, removing the old root. Simultaneously, it adopts a vertical block repair mechanism for updating blocks.
TON will continue optimizing its technical framework in the future: Through parallel expansion, the introduction of chain sharding tools, and the reinforcement of node inspections, TON aims to sustain its advantages in speed and scalability.
Blockchain Scaling Challenges
Blockchain scalability is a crucial technical challenge and a key driver for the development of blockchain technology: As blockchain applications grow and user numbers increase, existing blockchain networks often face issues of insufficient throughput and long transaction confirmation times. Traditional blockchain designs limit their ability to handle large-scale transactions and user demands, leading to network congestion, high transaction costs, and inefficiency.
The challenges of blockchain scalability primarily stem from the distributed architecture and consensus mechanisms: The consensus mechanism and distributed nature of blockchain require every node in the network to verify and record all transactions, limiting the throughput of the network. Additionally, blockchain’s security and decentralized features demand that all nodes maintain complete blockchain copies, increasing the burden on storage and transmission.
To address the challenge of blockchain scalability, researchers have proposed various scaling solutions such as Sharding, Sidechains, and Layer 2 solutions: These approaches aim to enhance network throughput and performance by dividing the network into smaller segments, introducing independent blockchains, or constructing additional structures on the main chain. However, these solutions bring about new technical challenges and security issues, such as inter-shard communication, cross-shard asset transfers, and consensus mechanism design.
-
Sharding, for example, involves dividing the entire blockchain network into smaller fragments or shards, with each shard independently processing a portion of transactions and data. While this mechanism can improve the overall network throughput and performance, it still faces challenges related to the security and consistency of inter-shard communication and cross-shard transactions. Additionally, sharding mechanisms must address the design and implementation of consensus mechanisms to ensure the overall network’s consistency and security.
-
Sidechain technology involves creating and running independent blockchains connected to the main chain within a blockchain network. Sidechains facilitate two-way asset transfers with the main chain while having their own rules and functionality. The basic principle of sidechain technology is to process some transactions on the sidechain, relieving the main chain’s burden and providing higher scalability and flexibility. However, sidechains require secure mechanisms and protocols to ensure asset safety and consistency in two-way asset transfers. Additionally, the design and implementation of sidechains must consider compatibility and interoperability with the main chain.
-
Rollup, on the other hand, stores a large volume of transaction data off-chain in a sidechain and submits summary information of these transactions to the main chain for verification. Its advantage lies in significantly improving the scalability and performance of the blockchain network by storing transaction data off-chain and using the main chain for verification. However, concerns about centralization and security exist with the Rollup approach.
-
New consensus mechanisms, such as Solana’s Proof of History (POH), associate timestamps with each transaction, providing a verifiable time sequence for the blockchain. This time sequence can be used to verify transaction order and time, reducing communication costs and delays in the consensus process. While Solana claims a TPS of up to 65,000, the actual data throughput, considering node-to-node communication, is around 6-8k TPS (daily around 4-5k).
TON blockchain , originating from Telegram , was conceived with the idea of serving a massive user base: Telegram is one of the world’s most popular social platforms, boasting over 800 million monthly active users and transmitting billions of messages within the software every day. TON, as Telegram’s foray into web3, was designed from the outset to cater to billions of users rather than just a small user base.
TON’s Technical Architecture
Adaptive Infinite Split Multi-Chain Design
TON’s sharding is bottom-up: While conventional blockchain sharding schemes typically adopt a top-down approach, establishing a single blockchain first and then breaking it down into interactive blockchains to enhance performance, TON’s sharding takes a bottom-up approach. It organizes these account chains into shardchains, forming a Shardchain, where Workchains exist purely in virtual or logical forms. TON achieves parallel transaction processing across multiple chains, referred to as a “blockchain of blockchains.” This approach effectively boosts system performance.
TON features a dynamic sharding architecture, consisting of masterchain, workchain, and shardchain: The masterchain coordinates, while actual transaction processing occurs within various workchains and shardchains. Additionally, TON’s sharding is dynamic, with each account functioning as a shardchain. These can adaptively combine into larger shardchains based on the interactions among accounts to address dynamic expansion needs.
- Masterchain: There is only one, encompassing protocol parameters, validator sets, corresponding shares, and recording current active workchains and their subordinate shardchains. Lower chains submit the latest block hash to the masterchain to ensure determining the latest state when cross-chain message retrieval is necessary.
If sharding reaches its limit, each shardchain will store only one account or smart contract. This results in numerous “account-chains” describing the state and transitions of individual accounts, with these chains mutually transmitting information, forming Workchain through Shardchains.
-
Workchain: It’s a virtual concept existing as a collection of Shardchains, with the system supporting up to 2^32 Workchains. Each Workchain can flexibly customize rules, such as transaction types, token types, smart contracts, and address formats, as long as interoperability standards are met. However, Workchains must share the same message queue format for efficient message exchange, implying similar security guarantees for all Workchains.
-
Shardchain: To enhance processing efficiency, Shardchains automatically split during high loads and merge during decreased loads. Each Workchain further divides into Shardchains (up to 2^60). Shardchains distribute work across all Shardchains, with each serving only a portion of the account collection.
Information Transfer Mechanisms
Message: Since TON uses FunC’s send_raw_message function to develop its language, the messages passed by TON nodes are called “messages”. A transaction in TON consists of an inbound message that initially triggers it and a set of outbound messages that are sent to other contracts;
Hypercube Routing: A three-dimensional structured messaging mechanism that enables messages created in one block of a sharded chain to be rapidly delivered and processed to the next block of the target sharded chain.
Asynchronous message delivery
Asynchronous calls pose synchronization challenges: In synchronous blockchains, transactions can include multiple smart contract calls. In asynchronous systems, users cannot promptly receive responses from the target smart contract in the same transaction. This delay is because contract calls may take several blocks to process, and the routing distance between source and destination blocks affects this process.
To achieve infinite sharding, it is essential to ensure complete parallelization of messages, leading to the introduction of the concept of logical time: In TON, each transaction executes solely on a single smart contract and communicates between contracts using messages. This introduces the concept of logical time in asynchronous chains, enabling synchronization of messages between chains. Each message has its logical time or Lamport time (hereafter referred to as lt). This time is used to track the relationships between events and determine which events validators need to process first.
The execution logic is guaranteed by strictly following the execution order of message lt: Messages sent from an account and transactions occurring on an account are strictly ordered, with the lt of generated transactions greater than the lt of messages. Additionally, the lt of messages sent in a transaction is strictly greater than the lt of the transaction that triggers the messages. In the case of multiple messages, those with lower lt are processed earlier.
Message Hypercube routing mechanism
TON employs parallel execution with Fast Routing + Slow Routing:
Slow Routing: A more stable and traditional cross-chain information processing method, where information is packaged into a block on the source chain and then relayed from one shard chain to another through a relayer. Multiple intermediary shard chains can also be used for transmission. All shard chains form a “hypercube” graph, and messages propagate along the edges of this hypercube. After validation by validators, the information is packaged into another block.
The advantage of Slow Routing lies in higher security and decentralization, as all information needs to go through a complete block confirmation process. For a hypercube network of shard chains with a scale of N, the number of routes hop = log16(N). Therefore, only 4 routing nodes are needed to support a million shard chains.
Fast Routing: In Slow Routing, messages propagate along the edges of the hypercube. To speed up, Fast Routing allows the validators of the destination shard chain to process the message in advance, provide a Merkle proof, and send a receipt to destroy the transmitting message.
Fast Routing is faster (nodes can find the optimal path) and prevents double delivery. However, it cannot replace Slow Routing because validators are not penalized for losing receipts, posing a certain security risk.
Global state of a sharded blockchain
“Bag of cells”: A set of cells updated in a manner similar to a Directed Acyclic Graph (DAG). This involves representing the new state as another “bag of cells” with its own root, and then combining the new and old sets of cells while simultaneously removing the old root.
Vertical block repair: In TON shard chains, each block is not just a single block but a chain. When it is necessary to fix a block in an erroneous shard chain, a new block will be submitted to the “vertical block chain” for the replacement of the block.
Consensus
POS network consists of three roles:
-
Validator Nodes: Participants in maintaining network security by staking 300,000 TON upon meeting hardware requirements. Blocks are created by 100 to 1000 selected nodes, elected monthly. During their tenure, elected nodes are divided into multiple working groups to create new blocks. Each new block requires signatures from over 2/3 of the staked nodes in the working group to be considered successfully created. Malicious behavior may lead to slashing and disqualification.
-
Fisherman: Acts as a supervisor by sending invalid proof to check if validator nodes have diligently completed their verification tasks.
-
Nominator: Suggests new shard chain candidate blocks to validator nodes. If the block is elected, the curator profits. They are responsible for verifying the state of the shard chain and neighboring shard chain data and sending it to validator nodes.
BFT (Byzantine Fault Tolerance ): TON, after weighing options, chooses BFT over DPOS for its higher trust level and speed, despite DPOS being faster.
TON’s new framework can support TG’s high-speed information transfer
TON achieves high transaction speed and finality through a dynamic multi-shard architecture: Each user wallet in TON can have its own chain, and the theoretical basis for high TPS includes parallel computation of shards, support for instant cross-shard communication, and TVM supporting asynchronous computation.
TON brings higher scalability through an information-passing mechanism: In TON blockchain, calls between smart contracts are asynchronous rather than atomic. This means that when one smart contract calls another, the call is not executed immediately but is processed in some future block after the transaction ends. This design allows for higher scalability as it doesn’t require completing all transaction processing in a single block.
TON will continue to optimize the technical framework in the future…
TON’s technical roadmap will continuously advance the speed and scalability advantages of TON:
-
Separation of Sorters and Validators.
-
Scalability and Speed Improvement: Enabling TON to achieve parallel expansion in handling a large number of transactions.
-
Chain Sharding Guides and Tools: Organizing guides and code examples for handling high loads of TON work in exchanges, payment systems, and TON services.
-
Enhancing Coordination Among Validator Nodes: Strengthening and improving the detection and punishment of underperforming validators.
Reference not listed because of newuser limitation of ton community
Keytakeaways
TON 拥有以高速应用为核心的技术逻辑:TON 诞生于 telegram ,交易基于 message 直接上链,支持 点对点 ;
-
异步 message 传递:由于选用 FunC 作为函数开发语言,TON 中各节点传递通过传递“message”通讯,但 TON 是异步链,因此为了正确同步链间 message 引入了逻辑时间(It)的概念,通过保证 message lt 严格按照先后顺序执行来保障信息的正确执行;
-
超立方体的 message 路由机制:TON 采用普通路由+快路由的方式,普通路由通过立方体结构通过相邻节点传递分片间message,快路由加入了可以沿超立方体边缘传递的 Merkle 证明来中继 message 提升速度;
-
PoS +BFT 共识便于生态发展:POS 避免了出块过程中的大量计算,效率更高成本更低,网络性能更好,利于DAPP应用落地;同时虽然 DPOS 更快,但是信任速度比 BFT 系统慢,因此 TON 选用 BFT。
TON 的动态多分片架构便于应用的Scalability:TON 通过 并行 查询提升速度,通过动态分片提升查询准确度,通过 bag of cells提升拓展性;
-
动态多分片架构:TON 有三层,单条masterchain+ 多个Workchain+可动态增减和拆分的shardchain,每个分片链是各种账户链的集合,DAPP 可以自主激活某条分片链;
-
可快速更新的全局状态:通过类似 DAG 的“bag of cells”结构更新全局状态,通过联立新旧两组 cells 并删除旧 root 快速更新。同时采用垂直区块修复更新区块。
**TON 未来将继续优化技术框架:**通过并行拓展、推出链分片工具、加强节点检查等机制持续推进 TON 的速度和可拓展性优势。
区块链扩容难题
区块链扩容是重要的技术难题,是推动 区块链技术 发展的关键之一:随着区块链应用的不断增长和用户数量的增加,现有的区块链网络往往面临着吞吐量不足和交易确认时间长的问题。传统的区块链设计限制了其在处理大规模交易和用户需求方面的能力,这导致了网络拥堵、高交易费用和低效率的情况;
区块链扩容的挑战主要源于 分布式架构 **和共识机制:**首先区块链的共识机制和分布式性质使得在网络中的每个节点都需要对所有交易进行验证和记录,这导致了网络的吞吐量受限。其次区块链的安全性和去中心化特性要求所有节点都要保持完整的区块链副本,这增加了存储和传输的负担;
**为了解决区块链扩容难题,研究者们提出了各种扩容方案:**如分片(Sharding)、侧链(Sidechains)、二层方案(Layer 2 solutions)等,这些方案试图通过将网络分割成多个较小的部分、引入独立的区块链或在主链上构建额外的结构来提高网络的吞吐量和性能。然而,这些方案也带来了新的技术挑战和安全性问题,如分片间通信、跨链资产转移和共识机制设计等。
-
分片:基本思想是将整个区块链网络分割成多个较小的片段(或称为分片),每个分片可以独立地处理一部分交易和数据。通过将交易和数据分散到不同的分片中,分片机制可以提高整个网络的吞吐量和性能。但仍面临着分片间通信和跨分片交易的安全性和一致性问题,此外,分片机制还需要解决共识机制的设计和实现,以确保整个网络的一致性和安全性;
-
侧链:侧链技术是一种在区块链网络中创建并运行与主链(主要区块链)相互连接的独立区块链的方法。侧链可以与主链进行双向的资产转移,同时具有自己的独立规则和功能。侧链技术的基本原理是通过将一些交易从主链转移到侧链上进行处理,从而减轻主链的负担,并提供更高的扩展性和灵活性。但侧链需要与主链进行双向的资产转移,这需要一定的安全机制和协议来确保资产的安全性和一致性。此外,侧链的设计和实现需要考虑与主链的兼容性和互操作性;
-
Rollup:基本原理是将大量的交易数据存储在链下的侧链中,然后将这些交易的摘要信息提交到主链上进行验证。其优势在于它可以显著提高区块链网络的扩展性和性能,通过将交易数据存储在侧链上,并使用主链进行验证,Rollup技术可以大大减少主链上的存储和计算负担。但也有中心化和安全性的顾虑;
-
新共识机制:如 Solana 的 POH,通过将时间戳与每个交易相关联,为区块链提供了一种可验证的时间序列。这种时间序列可以用来验证交易的顺序和时间,从而减少了共识过程中的通信成本和延迟。虽然Solana称其TPS可以达到65,000,但实际上大部分TPS是作为节点间的通信,真正数据上限只有6-8k(日常4-5k)。
TON 区块链源于 Telegram **,初始设立理念就是服务大量用户:**Telegram 是全球最受欢迎的社交平台之一,月活用户超过8亿,每天软件内传输数百亿条消息。TON 作为 telegram 的 web3 转型,其设计理念从一开始就基于服务数十亿用户而不仅仅只满足于少量用户。
TON 的技术架构
自适应无限分片多链设计
**TON 的分片是自下而上的:**区块链分片方案普遍采用自上而下的方式,即先建立单一的区块链,然后将其分解为若干交互式的区块链,以提升性能。然而,TON 分片方案采取了一种自下而上的方式:将这些账户链组织成碎片链(Shardchain),使得账户链(Workchain)在分片链中仅存在纯粹的虚拟或逻辑形式。TON 实现了多条链并行处理交易,被称为“blockchain of blockchains”。通过这种方式,可以有效提高系统性能;
TON的是动态分片架构:分为masterchain、workchain和shardchain。masterchain负责协调,各个workchain和shardchain进行实际的交易处理。此外,TON的分片是动态的,每个账户作为一条Shardchain,可根据账户间的交互关系自适应组合成更大的 Shardchain 来应对动态扩展的需求。
- Masterchain:仅有唯一一条,包含协议的参数、Validators集合以及对应的share,记录当前工作的Workchains及下属Shardchains。下层链将最新区块哈希提交至Masterchain,以确保在需要发生跨链消息读取时能确定最新状态。
如果分片已达到极限,那么最后每个分片链会仅保存一个账户或智能合约。这将导致大量描述单一账户状态和状态转换的“账户链(account-chains)”,这些账户链相互进行信息传输,即由Shardchain构成Workchain。 - Workchain:是作为 Shardchains 集合存在的一个虚拟概念,系统最高可容纳2^32条Workchains。每条Workchain在满足互操作性标准的前提下,可灵活自定义规则,如交易类型、代币类型、智能合约、地址形式等。但 Workchain 必须有相同的消息队列格式,便于其交换消息,当然这也意味着所有 Workchain 必须具有大致相同的安全保证;
- Shardchain:为提升处理效率,能在负载变高时自动分裂、在负载下降时合并链,每个Workchain会进一步分割为分片Shardchains(最高2^60)。Shardchain 将工作分摊到所有的Shardchains中,每条Shardchain 仅服务部分账户集合。
图片见上文
信息传递机制
**Message:**由于 TON 使用 FunC 的 send_raw_message函数开发语言,因此 TON 各节点传递的称为“message”。在TON中的交易由最初触发它的入站消息和一组发送到其他合约的出站消息组成;
**Hypercube Routing:**立体结构的信息传递机制,能使一个分片链区块中创建的消息迅速传递和处理至目标分片链的下一个区块中。
异步的 message 传递
异步调用 **有同步问题:**在同步区块链中,交易可包含多个智能合约调用。而在异步系统中,用户无法在同一交易中即时获取目标智能合约的响应,因为合约调用可能需要数个块的时间来处理,源块和目的块之间的路由长度将会影响这一进程;
为了实现无限分片,必须确保 message 完全 并行 **化,进而引出逻辑时间:**在TON中,每笔交易仅在单个智能合约上执行并通过 message 进行智能合约间通信。因此引出在异步链中使用的逻辑时间概念,以实现链间消息同步,即每条消息都有其逻辑时间或Lamport时间(以下简称为lt)。此时间用于追踪事件之间的关系,以及验证器需要首先处理的事件;
**message lt 将严格按照先后顺序执行来确保操作逻辑:**从一个帐户发送的消息和在一个帐户上发生的交易会被严格排序,产生的事务的lt大于消息的lt,在某个事务中发送的消息的lt严格大于引发该消息的事务的lt。此外,如果存在多条消息,那么将会更早处理lt较低的消息。
Message 超立方体路由机制:
TON 采用快路由 + 慢路由 并行 运行:
**慢路由:**更稳定且传统的跨链信息处理方法,信息在源链上被打包到一个区块中,再通过中继器(relayer)从一个分片链传递到另一个分片链,也可使用多个中间分片链进行传输。让所有的分片链构成一个 “hypercube” 图形,消息将沿着这个超立方体的边缘传播,信息经过验证者验证后打包到另一个区块中;
慢速路由优势在于更高的安全性和去中心化程度,因为所有信息需要经过完整的区块确认过程。对于一个规模为 N 的分片链超立方体网络,需要经过的路由条数 hop = log16(N)。因此,只需要 4 个路由节点,就能支持百万级的分片链。
**快路由:**慢路由中消息沿着超立方体的边缘传播,为了提速,快路由可以让消息的目的分片链所属的的验证器提前处理这条消息,再提供一个 merkel 证明,并发送回执来销毁掉这条正在传输的消息;
快路由速度更快(节点可找到最优路径),也能防止双重传递,但并不能取代慢速路由,因为验证人不会因为丢失 receipt 受到惩罚,因此有一定安全性风险
分片链的全局状态
“bag of cells” :通过类似 DAG 的形式更新的一组 cells。通过将新状态表示为具有其自身根的另一个 “bag of cells”,然后联立新旧两组 cells,同时删除旧的根;
**垂直区块修复:**TON 分片链中的每个区块实际不只有一个区块,而是一条链,当需要修复错误分片链的区块时,一个新的区块将会提交到“垂直区块链”并对它进行区块的替换。
共识机制
POS 网络中存在 3 个角色:
- 验证节点:满足硬件条件后质押 300 000 TON 即可参与维护网络安全;
所有区块由 100 ~ 1000 个选定的节点创建,节点每月选举一次,并需要在选举时封存质押的 TON Coin。任职期间选定的节点将被划分成多个工作组来创建新区块,每个新区块拿到工作组超过 2/3 的质押节点的签名即算创建成功,若作恶则会 slash 并剥夺资格;
-
Fisherman:通过发送无效证明检测验证节点是否尽职完成验证任务,可看作是监督者的角色;
-
校对人:它向验证人建议新的分片链候选区块,若区块当选则校对人获利。它负责校对该分片链的状态和邻近分片链的数据并发送给验证节点。
**BFT:**TON 经过权衡,发现虽然 DPOS 更快,但是它的信任级别和速度都比 BFT 系统慢,因此最终选择BFT(Byzantine fault tolerance)。
TON 的新框架可以支撑起 TG 的高速信息传递
**TON 通过动态多分片架构实现高速交易速度和 finality:**TON 可以为每个用户钱包创建一条链,分片的并行计算、支持瞬间跨分片交流和 TVM 支持异步计算构成了其高 TPS 的理论基础;
**TON 通过信息传递机制带来更高的可扩展性:**在 TON 区块链中,智能合约之间的调用是异步的,而不是原子的。这意味着当一个智能合约调用另一个智能合约时,该调用不会立即执行,而是在交易结束后的某个未来区块上被处理,这种设计允许更高的可扩展性,因为它不需要在一个区块中完成所有的交易处理。
TON 未来将继续优化技术框架…
TON roadmap 技术部分将持续推进 TON 的速度和可拓展性优势
-
排序器和验证者分离;
-
可拓展性和速度提升:让 TON 在处理大量事务的情况下实现并行扩展;
-
链分片指南和工具:在交易所、支付系统和TON服务中组织高负载TON工作的指南和代码示例;
-
加强验证者节点间的协调性:加强并改进对表现不佳的验证者的检测和惩罚;