Infinity Sharding Paradigm
Understanding Split Merge in TON Blockchain
The TON (Telegram Open Network) Blockchain introduces innovative concepts for blockchain scalability and efficiency. One such concept is the Split Merge functionality, integral to its blockchain architecture. This short article explores the key aspects of Split Merge in the TON Blockchain, focusing on its role within the Infinite Sharding Paradigm (ISP).
Infinite Sharding Paradigm (ISP) and its Application
ISP underpins the TON Blockchain's design, treating each account as part of its separate "accountchain." These accountchains are then aggregated into shardchain blocks for efficiency. The state of a shardchain comprises the states of all its accountchains. Thus, a shardchain block essentially is a collection of virtual blocks of accounts assigned to it.
- ShardState: Approximated as Hashmap(n, AccountState), where n is the bit length of the account_id.
- ShardBlock: Approximated as Hashmap(n, AccountBlock).
Each shardchain, or more precisely, each shardchain block, is identified by a combination of workchain_id
and a binary prefix s
of the account_id.
Messages and Instant Hypercube Routing (Instant Hypercube Routing)
In the infinite sharding paradigm, each account (or smart-contract) is treated as if it were itself in a separate shardchain. Interaction between accounts occurs solely through the sending of messages, which is part of the actor model where accounts act as actors. An efficient messaging system between shardchains is critical to the operation of the TON blockchain. A feature of TON is Instant Hypercube Routing, which enables fast delivery and processing of messages between shardchains, ensuring that messages created in a block of one shardchain are processed in the next block of the target shardchain, regardless of their number in the system.
Sharding Example
In the provided graphic scheme:
- Shards of a workchain are divided by time and denoted in dashed line.
- Blocks 222, 223, and 224 relate to the masterchain block with seqno=102. Here, 222 is in one shard, while 223 and 224 are in another.
- If a split or merge event happens, the affected shards pause until the next masterchain block.
In summary, Split Merge in TON Blockchain is a complex yet efficient mechanism that enhances scalability and interaction within the blockchain network. It exemplifies TON's approach to resolving common blockchain challenges, emphasizing efficiency and global consistency.
Sharding Details
Split and Non-Split Parts of Shardchain
A shardchain block and state are divided into two parts:
- Split Part: Complies with the ISP form, containing account-specific data.
- Non-Split Part: Involves data pertaining to the block's interaction with other blocks and the outside world.
Interaction with Other Blocks
The non-split parts are crucial for ensuring global consistency, reduced to internal and external local consistency conditions. They are significant for:
- Message forwarding between shardchains.
- Transactions involving multiple shardchains.
- Delivery guarantees and validation of a block's initial state against its predecessor.
Inbound and Outbound Messages
Key components of the non-split part of a shardchain block include:
- InMsgDescr: Descriptions of all messages imported into the block (i.e., either processed by the transaction included in the block or forwarded to the output queue, in the case of a transient message traveling along a path dictated by
Hypercube Routing
). - OutMsgDescr: Descriptions of all messages exported or generated by the block (i.e. either messages generated by a transaction included in the block, or transit messages with a destination not belonging to the current shardchain, forwarded from
InMsgDescr
).
Block Header and Validator Signatures
The block header, another non-split component, contains essential information like workchain_id
, binary prefix of account_ids
, block sequence number (defined as the smallest non-negative integer greater than the sequence numbers of its predecessors), logical time, and unixtime generation. It also contains a hash of the immediate predecessor of the block (or its two immediate predecessors in the case of a preceding
shardchain merge event), hashes of its initial and final states (i.e., the states of the shardchain immediately before and immediately after the current block is processed), and a hash of the most recent masterchain block known at the time the shardchain block was generated. Validator signatures are appended to the unsigned block, forming the signed block.
Outbound Message Queue
OutMsgQueue
in the shardchain state is a critical non-split part. It contains undelivered messages included in OutMsgDescr
, either by the last shardchain block leading to this state or by one of its predecessors.
Initially, each outgoing message is included in the OutMsgQueue
and stored there, until they are processed or delivered to their destination.
Shard Split and Merge Mechanics
In the context of dynamic sharding, shard configurations may change due to split and merge events. These events are synchronized with the masterchain block. For instance, if a split or merge occurs, the affected shards wait for the next masterchain block before proceeding.