Skip to content

Commit 2709372

Browse files
committed
Improved shard article
1 parent 9499a6e commit 2709372

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

docs/develop/blockchain/shards.mdx

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,55 @@
44
Page is under development
55
:::
66

7-
Sharding is a mechanism in TON blockchain which allows to process a large number of transactions. The main idea of sharding in TON is that when account A sends a message to account B and account C sends a message to account D both of these operations can be performed asynchronously.
7+
Sharding is a mature concept originating in [database design](https://en.wikipedia.org/wiki/Shard_(database_architecture)). It involves splitting and distributing one logical data set across multiple databases that share nothing and can be deployed across multiple servers.
8+
Simply put, sharding allows horizontal scalability - splitting data to distinct, independent pieces that can be processed in parallel. This is a key concept in the world's transition from data to [big data](https://en.wikipedia.org/wiki/Big_data).
9+
When data sets are becoming too big to be handled by traditional means, there's no other way to scale other than to break them down into smaller pieces.
10+
11+
The Sharding mechanism in the TON blockchain, allows a large number of transactions to be processed.
12+
The TON Blockchain consists of one masterchain and up to 2<sup>32</sup> workchains. Each workchain is a separate chain with its rules. Each workchain can further split into 2<sup>60</sup> shardchains, or sub-shards, containing a fraction of the workchain's state. Currently, only one workchain is operating on TON - Basechain.
13+
The main idea of sharding in TON is that when account A sends a message to account B and account C sends a message to account D both of these operations can be performed asynchronously.
814

915
By default in the Basechain (`workchain=0`) there is only one shard with a shard number `0x8000000000000000` (or `1000000000000000000000000000000000000000000000000000000000000000` in binary representation). The masterchain (`workchain=-1`) always has one and only one shard.
1016

17+
## Masterchain
18+
19+
The Masterchain is the primary chain that stores the network configuration and the final state of all workchains. You can understand this as the masterchain being the core directory, a single source of truth for all the shards in the ecosystem.
20+
21+
It carries fundamental protocol information, including current settings, a list of active validators and their stakes, active workchains, and associated shardchains. Most importantly, it maintains a record of the latest block hashes for all workchains and shardchains, enforcing consensus across the network.
22+
23+
## Workchain
24+
25+
The Masterchain splits into individual chains called Workchains. Workchains are customized blockchains tailored to certain transactions or use cases, running parallel within the TON network.
26+
27+
## Uniqueness
28+
29+
In designing the TON blockchain, two key decisions were made that make it unique among other blockchains that utilize sharding.
30+
31+
First, TON provides for dynamic segmentation of the blockchain depending on the network load. When the number of transactions increases to a critical level, the blockchain is automatically split into two separate shardchains.
32+
If the load on one of the parts continues to grow, it is split in half again, and this process continues as needed. If the number of transactions decreases, the shards can merge again.
33+
This adaptive model allows for the creation of as many shards as needed at a given time.
34+
35+
The second solution that distinguishes TON is the principle of a non-fixed number of shards. Unlike systems like Ethereum 2.0, which supports a fixed number of shards (64 shards), TON allows adding more and more shards depending on the needs of the network, with a theoretical limit of 2<sup>60</sup> shards per worker chain.
36+
This number is so large as to be virtually limitless, and allows over 100 million shards to be provided to every person on Earth and still have a supply left over. This approach is the only way to meet dynamic scaling requirements that are difficult to predict in advance.
37+
38+
![](/img/docs/blockchain-fundamentals/scheme.png)
39+
1140
## Splitting
1241

13-
Each shard is responsible for some subset of accounts with some common binary prefix. This prefix appears in shard id which presented by a 64-bit integer and has the following structure: `<binary prefix>100000...`. For example, shard with id `1011100000...` contains all accounts started with prefix `1011`.
42+
In TON Blockchain, a sequence of transactions of a single account (e.g. `Tx1 -> Tx2 -> Tx3 -> ...`) is called an account transaction chain or <b>AccountChain</b>. This emphasizes that it is a sequence of transactions associated with a single account.
43+
Several such <b>AccountChains</b> combined within a single shard form a <b>ShardChain</b>. The <b>ShardChain</b> (hereinafter referred to as the shard) is responsible for storing and processing all transactions within a shard, where each transaction chain is defined by a specific account group.
44+
45+
These groups of accounts are denoted by a common binary prefix, which serves as a criterion for clustering them in the same shard.
46+
This prefix appears in shard id which presented by a 64-bit integer and has the following structure: `<binary prefix>100000...`. For example, shard with id `1011100000...` contains all accounts started with prefix `1011`.
1447

1548
When number of transactions in some shard growth, it splits into two shards. New shards obtaining the following ids: `<parent prefix>01000...` and `<parent prefix>11000...` and responsible for accounts starting with `<parent prefix>0` and `<parent prefix>1` correspondingly. The seqnos of blocks in shards goes continuously starting from parent last seqno plus 1. After split shards go independently and may have different seqnos.
1649

50+
A simple example:
51+
![](/img/docs/blockchain-fundamentals/shardchains-split.jpg)
52+
1753
Masterchain block contains information about shards in its header. After the block of shard appears in masterchain header it may be considered as finished (it cannot be rolled back).
1854

19-
Example:
55+
An actual example:
2056
* Masterchain block `seqno=34607821` has 2 shards: `(0,4000000000000000,40485798)` and `(0,c000000000000000,40485843)` (https://toncenter.com/api/v2/shards?seqno=34607821).
2157
* Shard `shard=4000000000000000` was splitted into `shard=2000000000000000` and `shard=6000000000000000` and masterchain block `seqno=34607822` already has 3 shards: `(0,2000000000000000,40485799)` and `(0,6000000000000000,40485799)`. Note, that both new shards has the same seqnos but different shard IDs (https://toncenter.com/api/v2/shards?seqno=34607822).
2258
* New shards go independently and after 100 masterchain blocks (in masterchain block `seqno=34607921`) one shard has last block `(0,2000000000000000,40485901)` and another one has `(0,6000000000000000,40485897)` (https://toncenter.com/api/v2/shards?seqno=34607921).
@@ -25,5 +61,8 @@ Example:
2561
When shards load goes down they can merge back as follow:
2662
* Two shards can merge if they have common parent and, therefore, their shard ids are `<parent prefix>010...` and `<parent prefix110...`. Merged shard will have shard id `<parent prefix>10...` (for example `10010...` + `10110...` = `1010...`). The first block of merged shard will have `seqno=max(seqno1, seqno2) + 1`.
2763

28-
Example:
64+
A simple example:
65+
![](/img/docs/blockchain-fundamentals/shardchains-merge.jpg)
66+
67+
An actual example:
2968
* In masterchain block `seqno=34626306` two of five shards with last blocks `(0,a000000000000000,40492030)` and `(0,e000000000000000,40492216)` merged into one with block `(0,c000000000000000,40492217)` (https://toncenter.com/api/v2/shards?seqno=34626306 and https://toncenter.com/api/v2/shards?seqno=34626307).
Loading
Loading
Loading

0 commit comments

Comments
 (0)