From d101dc51d9b4f605a2366636d6f442591ec970de Mon Sep 17 00:00:00 2001 From: AlexG <39581753+Reveloper@users.noreply.github.com> Date: Fri, 8 Dec 2023 22:42:04 +0900 Subject: [PATCH] shards_page_added --- docs/develop/blockchain/shards.mdx | 25 +++++++++++++++++++++++++ sidebars.js | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 docs/develop/blockchain/shards.mdx diff --git a/docs/develop/blockchain/shards.mdx b/docs/develop/blockchain/shards.mdx new file mode 100644 index 0000000000..8dfa3b7149 --- /dev/null +++ b/docs/develop/blockchain/shards.mdx @@ -0,0 +1,25 @@ +# TON Shards + +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. + +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. + +## Splitting + +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: `100000...`. For example, shard with id `1011100000...` contains all accounts started with prefix `1011`. + +When number of transactions in some shard growth, it splits into two shards. New shards obtaining the following ids: `01000...` and `11000...` and responsible for accounts starting with `0` and `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. + +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). + +Example: +* Masterchain block `seqno=34607821` has 2 shards: `(0,4000000000000000,40485798)` and `(0,c000000000000000,40485843)` (https://toncenter.com/api/v2/shards?seqno=34607821). +* 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). +* 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). + +## Merging +When shards load goes down they can merge back as follow: +* Two shards can merge if they have common parent and, therefore, their shard ids are `010...` and `10...` (for example `10010...` + `10110...` = `1010...`). The first block of merged shard will have `seqno=max(seqno1, seqno2) + 1`. + +Example: +* 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). diff --git a/sidebars.js b/sidebars.js index f951062e29..a39082a5e0 100644 --- a/sidebars.js +++ b/sidebars.js @@ -554,8 +554,8 @@ const sidebars = { type: 'category', label: 'Blockchain Fundamentals', items: [ - - 'develop/blockchain/sharding-lifecycle', + 'develop/blockchain/shards', + 'develop/blockchain/sharding-lifecycle', ], }, {