Skip to content

Commit ab5f8b8

Browse files
authored
Merge branch 'ton-community:main' into react-doc-wrappers
2 parents 5d0b2c5 + fe5179c commit ab5f8b8

File tree

102 files changed

+6767
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+6767
-336
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ Use Gitpod (a free, online VS code-like IDE) for contributing. It will launch a
7676
7777
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
7878
79+
## Contributors Wall
80+
<a href="https://github.com/ton-community/ton-docs/graphs/contributors">
81+
<img src="https://contrib.rocks/image?repo=ton-community/ton-docs&max=204" />
82+
</a>
83+
84+
<p align="right" style="font-size: 14px; color: #555; margin-top: 20px;">
85+
<a href="#readme-top" style="text-decoration: none; color: blue; font-weight: bold;">
86+
↑ Back to Top ↑
87+
</a>
88+
</p>
7989
## License
8090
8191
[GPL-3.0](https://choosealicense.com/licenses/gpl-3.0/)

docs/develop/dapps/ton-connect/tg-bot-integration-py.md renamed to docs/develop/archive/tg-bot-integration-py.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import Button from '@site/src/components/button'
22

33
# TON Connect for Telegram Bots - Python
44

5+
:::warning deprecated
6+
This tutorial describes an outdated approach to integrating TON Connect with Telegram bots. We strongly recommend using [Telegram Mini Apps](/develop/dapps/telegram-apps) for a more modern and secure integration.
7+
:::
8+
59
In this tutorial, we’ll create a sample telegram bot that supports TON Connect 2.0 authentication using Python TON Connect SDK [pytonconnect](https://github.com/XaBbl4/pytonconnect).
610
We will analyze connecting a wallet, sending a transaction, getting data about the connected wallet, and disconnecting a wallet.
711

docs/develop/dapps/ton-connect/tg-bot-integration.mdx renamed to docs/develop/archive/tg-bot-integration.mdx

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import Button from '@site/src/components/button'
22

33
# TON Connect for Telegram Bots
44

5+
:::warning deprecated
6+
This tutorial describes an outdated approach to integrating TON Connect with Telegram bots. We strongly recommend using [Telegram Mini Apps](/develop/dapps/telegram-apps) for a more modern and secure integration.
7+
:::
8+
59
In this tutorial, we’ll create a sample telegram bot that supports TON Connect 2.0 authentication using Javascript TON Connect SDK.
610
We will analyze connecting a wallet, sending a transaction, getting data about the connected wallet, and disconnecting a wallet.
711

@@ -206,7 +210,7 @@ import { IStorage } from '@tonconnect/sdk';
206210
const storage = new Map<string, string>(); // temporary storage implementation. We will replace it with the redis later
207211

208212
export class TonConnectStorage implements IStorage {
209-
constructor(private readonly chatId: number) {} // we need to have different stores for different users
213+
constructor(private readonly chatId: number) {} // we need to have different stores for different users
210214

211215
private getKey(key: string): string {
212216
return this.chatId.toString() + key; // we will simply have different keys prefixes for different users
@@ -269,7 +273,7 @@ Let's analyze what we are doing here. Firstly we fetch the wallets list and crea
269273
After that we subscribe to wallet change. When user connects a wallet, bot will send a message `${wallet.device.appName} wallet connected!`.
270274
Next we find the Tonkeeper wallet and create connection link. In the end we generate a QR code with the link and send it as a photo to the user.
271275

272-
Now you can run the bot (`npm run compile` and `npm run start` then) and send `/connect` message to the bot. Bot should reply with the QR. Scan it with the Tonkeeper wallet. You will see a message `Tonkeeper wallet connected!` in the chat.
276+
Now you can run the bot (`npm run compile` and `npm run start` then) and send `/connect` message to the bot. Bot should reply with the QR. Scan it with the Tonkeeper wallet. You will see a message `Tonkeeper wallet connected!` in the chat.
273277

274278

275279
We will use connector in many places, so let's move connector creating code to a separate file:
@@ -351,17 +355,17 @@ We will implement following UX for wallet connection:
351355
```text
352356
First screen:
353357
<Unified QR>
354-
<Open @wallet>, <Choose a wallet button (opens second screen)>, <Open wallet unified link>
358+
<Open @wallet>, <Choose a wallet button (opens second screen)>, <Open wallet unified link>
355359
356360
Second screen:
357361
<Unified QR>
358362
<Back (opens first screen)>
359-
<@wallet button (opens third screen)>, <Tonkeeper button (opens third screen)>, <Tonhub button (opens third screen)>, <...>
363+
<@wallet button (opens third screen)>, <Tonkeeper button (opens third screen)>, <Tonhub button (opens third screen)>, <...>
360364
361365
Third screen:
362366
<Selected wallet QR>
363367
<Back (opens second screen)>
364-
<Open selected wallet link>
368+
<Open selected wallet link>
365369
```
366370

367371
Let's start with adding inline keyboard to the `/connect` command handler in the `main.ts`
@@ -408,7 +412,7 @@ bot.onText(/\/connect/, async msg => {
408412
We need to wrap TonConnect deeplink as https://ton-connect.github.io/open-tc?connect=${encodeURIComponent(link)} because only `http` links are allowed in the Telegram inline keyboard.
409413
Website https://ton-connect.github.io/open-tc just redirects user to link passed in the `connect` query param, so it's only workaround to open `tc://` link in the Telegram.
410414

411-
Note that we replaced `connector.connect` call arguments. Now we are generating a unified link for all wallets.
415+
Note that we replaced `connector.connect` call arguments. Now we are generating a unified link for all wallets.
412416

413417
Next we tell Telegram to call `callback_query` handler with `{ "method": "chose_wallet" }` value when user clicks to the `Choose a Wallet` button.
414418

@@ -461,7 +465,7 @@ export const walletMenuCallbacks = { // Define buttons callbacks
461465
chose_wallet: onChooseWalletClick
462466
};
463467

464-
bot.on('callback_query', query => { // Parse callback data and execute corresponing function
468+
bot.on('callback_query', query => { // Parse callback data and execute corresponing function
465469
if (!query.data) {
466470
return;
467471
}
@@ -485,14 +489,14 @@ bot.on('callback_query', query => { // Parse callback data and execute correspon
485489
async function onChooseWalletClick ...
486490
```
487491

488-
Here we define buttons handlers list and `callback_query` parser. Unfortunately callback data is always string, so we have to pass JSON to the `callback_data` and parse it later in the `callback_query` handler.
492+
Here we define buttons handlers list and `callback_query` parser. Unfortunately callback data is always string, so we have to pass JSON to the `callback_data` and parse it later in the `callback_query` handler.
489493
Then we are looking for the requested method and call it with passed parameters.
490494

491495
Now we should add `conenct-wallet-menu.ts` import to the `main.ts`
492496
```ts
493497
// src/main.ts
494498
495-
// ... other imports
499+
// ... other imports
496500
497501
import './connect-wallet-menu';
498502
@@ -675,7 +679,7 @@ export const walletMenuCallbacks = {
675679
universal_qr: onOpenUniversalQRClick
676680
};
677681
678-
bot.on('callback_query', query => { // Parse callback data and execute corresponing function
682+
bot.on('callback_query', query => { // Parse callback data and execute corresponing function
679683
if (!query.data) {
680684
return;
681685
}
@@ -830,7 +834,7 @@ async function editQR(message: TelegramBot.Message, link: string): Promise<void>
830834
831835
Compile and run the bot to check how wallet connection works now.
832836
833-
You may note that we haven't considered QR code expiration and stopping connectors yet. We will handle it later.
837+
You may note that we haven't considered QR code expiration and stopping connectors yet. We will handle it later.
834838
835839
836840
At the moment we have the following files structure:
@@ -951,7 +955,7 @@ export const walletMenuCallbacks = {
951955
};
952956

953957
async function onChooseWalletClick(query: CallbackQuery, _: string): Promise<void> {
954-
958+
955959
// ... other code
956960
```
957961
@@ -1121,8 +1125,8 @@ bot.onText(/\/my_wallet/, handleShowMyWalletCommand);
11211125
Compile and run the bot to check that commands above works correctly.
11221126
11231127
## Optimisation
1124-
We've done all basic commands. But it is important to keep in mind that each connector keeps SSE connection opened until it is paused.
1125-
Also, we didn't handle case when user calls `/connect` multiple times, or calls `/connect` or `/send_tx` and doesn't scan the QR. We should set a timeout and close the connection to save server resources.
1128+
We've done all basic commands. But it is important to keep in mind that each connector keeps SSE connection opened until it is paused.
1129+
Also, we didn't handle case when user calls `/connect` multiple times, or calls `/connect` or `/send_tx` and doesn't scan the QR. We should set a timeout and close the connection to save server resources.
11261130
Then we should notify user that QR / transaction request is expired.
11271131
11281132
### Send transaction optimisation
@@ -1339,10 +1343,10 @@ export function getConnector(
13391343
13401344
</details>
13411345
1342-
This code may look a little tricky, but here we go.
1346+
This code may look a little tricky, but here we go.
13431347
Here we store a connector, it's cleaning timeout and list of callback that should be executed after the timeout for each user.
13441348
1345-
When `getConnector` is called we check if there is an existing connector for this `chatId` (user) it the cache. If it exists we reset the cleaning timeout and return the connector.
1349+
When `getConnector` is called we check if there is an existing connector for this `chatId` (user) it the cache. If it exists we reset the cleaning timeout and return the connector.
13461350
That allows keep active users connectors in cache. It there is no connector in the cache we create a new one, register a timeout clean function and return this connector.
13471351
13481352
To make it works we have to add a new parameter to the `.env`
@@ -1396,7 +1400,7 @@ export async function handleConnectCommand(msg: TelegramBot.Message): Promise<vo
13961400
const connectedName =
13971401
(await getWalletInfo(connector.wallet!.device.appName))?.name ||
13981402
connector.wallet!.device.appName;
1399-
1403+
14001404
await bot.sendMessage(
14011405
chatId,
14021406
`You have already connect ${connectedName} wallet\nYour address: ${toUserFriendlyAddress(
@@ -1465,9 +1469,9 @@ export async function handleConnectCommand(msg: TelegramBot.Message): Promise<vo
14651469
14661470
</details>
14671471
1468-
We defined `newConnectRequestListenersMap` to store cleanup callback for the last connect request for each user.
1469-
If user calls `/connect` multiple times, bot will delete previous message with QR.
1470-
Also, we subscribed to the connector expiration timeout to delete the QR-code message when it is expired.
1472+
We defined `newConnectRequestListenersMap` to store cleanup callback for the last connect request for each user.
1473+
If user calls `/connect` multiple times, bot will delete previous message with QR.
1474+
Also, we subscribed to the connector expiration timeout to delete the QR-code message when it is expired.
14711475
14721476
14731477
Now we should remove `connector.onStatusChange` subscription from the `connect-wallet-menu.ts` functions,
@@ -1641,7 +1645,7 @@ export async function buildUniversalKeyboard(
16411645
}
16421646
```
16431647
1644-
Here we are adding separate button for @wallet to the First screen (Universal QR screen). All that remains is to use this function in
1648+
Here we are adding separate button for @wallet to the First screen (Universal QR screen). All that remains is to use this function in
16451649
connect-wallet-menu and command-handlers:
16461650
16471651
@@ -1825,7 +1829,7 @@ async function onWalletClick(query: CallbackQuery, data: string): Promise<void>
18251829
18261830
</details>
18271831
1828-
Note that we place different links to the QR and button-link (`qrLink` and `buttonLink`),
1832+
Note that we place different links to the QR and button-link (`qrLink` and `buttonLink`),
18291833
because we don't need redirection when user scans QR by @wallet, and at the same time we need redirect back to the bot when user connects @wallet using button-link.
18301834
18311835
@@ -1917,7 +1921,7 @@ export async function handleSendTXCommand(msg: TelegramBot.Message): Promise<voi
19171921
19181922
</details>
19191923
1920-
That is it. Now user is able to connect @wallet using special button on the main screen, also we have provided proper return strategy for TG links.
1924+
That is it. Now user is able to connect @wallet using special button on the main screen, also we have provided proper return strategy for TG links.
19211925
19221926
## Add a permanent storage
19231927
At this moment we store TonConnect sessions in the Map object. But you may want to store it to the database or other permanent storage to save the sessions when you restart the server.

docs/develop/blockchain/sharding-lifecycle.mdx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,75 @@ ISP underpins the TON Blockchain's design, treating each account as part of its
1414

1515
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.
1616

17+
## Algorithm for deciding whether to split or merge
18+
19+
Validators decide whether to split or merge shards in the following way:
20+
1. For each block, block size, gas consumption and lt delta are calculated.
21+
2. Using these values, blocks can be considered overloaded or underloaded.
22+
3. Each shard keeps underload and overload history. If enough recent blocks were underloaded or overloaded, `want_merge` or `want_split` flag is set.
23+
4. Validators merge or split shards using these flags.
24+
25+
### 1. Assessment of the current state of the block
26+
27+
Each block has the following parameters. They are used to determine overload and underload.
28+
1. *Block size estimation* - not an actual block size, but an estimation calculated during collation.
29+
2. *Gas consumption* - total gas consumed in all transactions (excluding ticktock and mint/recover special transactions).
30+
3. *Lt delta* - difference between start and end lt of the block.
31+
32+
### 2. Block limits and classification
33+
34+
Block limits are loaded from the [configuration parameters 22 and 23](/develop/howto/blockchain-configs#param-22-and-23).
35+
Each of the three parameters has three limits: underload, soft, hard:
36+
1. *Block size*: `128/256/512 KiB`.
37+
2. *Gas consumption*: `2M/10M/20M` in basechain, `200K/1M/2.5M` in masterchain.
38+
3. *Lt delta*: `1000/5000/10000`.
39+
Also, there is a medium limit, which is equal to `(soft + hard) / 2`.
40+
41+
We classify the three parameters (size, gas, and lt delta) into categories:
42+
- `0` - underload limit is not reached.
43+
- `1` - underload limit is exceeded.
44+
- `2` - soft limit is exceeded.
45+
- `3` - medium limit is exceeded.
46+
- `4` - hard limit is exceeded.
47+
48+
Block classification is max(`Classification of size`, `Classification of gas`, `Classification of lt delta`). For example: if classification of size is 2, classification of gas is 3, classification of lt delta is 1, then the final block classification is 3.
49+
50+
- When classification of the block is 0 (underload), the block is inclined to merge with its sibling.
51+
- When classification of the block is 2 (soft limit reached), collator stops processing internal messages. The block is inclined to split.
52+
- When classification of the block is 3 (medium limit reached), collator stops processing external messages.
53+
54+
### 3. Determination of overload or underload
55+
56+
After classifying the block, collator checks overload and underload conditions.
57+
Size of the outbound message queue and status of dispatch queue processing is also taken into consideration.
58+
- If the block class is ≥ `2` (soft) and message queue size ≤ `SPLIT_MAX_QUEUE_SIZE = 100000` then the block is overloaded.
59+
- If limit for total processed messages from dispatch queue was reached and message queue size ≤ `SPLIT_MAX_QUEUE_SIZE = 100000` then the block is overloaded.
60+
- If the block class is `0` (underload) and message queue size ≤ `MERGE_MAX_QUEUE_SIZE = 2047` then the block is underloaded.
61+
- If message queue size is ≥ `FORCE_SPLIT_QUEUE_SIZE = 4096` and ≤ `SPLIT_MAX_QUEUE_SIZE = 100000` then the block is overloaded.
62+
63+
### 4. Deciding whether to split or merge
64+
65+
Each block keeps underload and overload history - it is a 64-bit mask of the underload/overload status of the last 64 blocks.
66+
It is used to decide whether to split or merge.
67+
68+
Underload and overload history has a weight, which is calculated as follows:
69+
`one_bits(mask & 0xffff) * 3 + one_bits(mask & 0xffff0000) * 2 + one_bits(mask & 0xffff00000000) - (3 + 2 + 1) * 16 * 2 / 3`
70+
(here `one_bits` is the number of `1`-bits in a mask, and the lower bits correspond to the most recent blocks).
71+
72+
When underload or overload history has a non-negative weight, the flag `want_merge` or `want_split` is set.
73+
74+
### 5. Final decision
75+
76+
Validators decide to split or merge shards using `want_split` and `want_merge` flags and [workchain configuration parameters](/develop/howto/blockchain-configs#param-12).
77+
78+
- If the shard has depth < `min_split` then it will split.
79+
- If the shard has depth > `max_split` then it will merge.
80+
- Shards with depth `min_split` cannot merge, shards with depth `max_split` cannot split.
81+
- If the block has `want_split` flag, the shard will split.
82+
- If the block and its sibling have `want_merge` flag, the shards will merge.
83+
84+
Shards split and merge in `split_merge_delay = 100` seconds after the decision is made.
85+
1786
## Messages and Instant Hypercube Routing (Instant Hypercube Routing)
1887

1988
In the infinite sharding paradigm, each account (or smart-contract) is treated as if it were itself in a separate shardchain.

docs/develop/companies/auditors.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ Test your software with the following quality assurance providers.
88

99
## Primary TON Blockchain SAP
1010

11+
* [certik.com](certik.com)
1112
* [quantstamp.com](https://quantstamp.com/)
13+
* [trailofbits.com](https://www.trailofbits.com/)
1214
* [zellic.io](https://www.zellic.io/)
1315

1416
## TON Ecosystem SAP
1517

18+
* [beosin.com](https://beosin.com/)
1619
* [hackenproof.com](https://hackenproof.com/)
1720
* [hexens.io](https://hexens.io/)
1821
* [scalebit](https://www.scalebit.xyz/)
19-
* [skynet.certik.com](https://skynet.certik.com/)
2022
* [slowmist.com](https://slowmist.com/)
2123
* [softstack.io formerly Chainsulting](https://softstack.io/)
22-
* [trailofbits.com](https://www.trailofbits.com/)
2324
* [vidma.io](https://vidma.io/)
2425

2526

docs/develop/dapps/apis/sdk.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ There are different ways to connect to blockchain:
2929

3030
### Python
3131

32-
<!-- tonsdk dropped due to invalid cells serialization -->
32+
<!-- tonsdk dropped due to invalid cells serialization, it is deprecated now -->
3333

3434
| Library | Blockchain connection | Description |
3535
|---------|------------------|--------------|

docs/develop/dapps/asset-processing/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Here you can find a **short overview** on [how TON transfers work](/develop/dapp
88

99
## Overview on messages and transactions
1010

11-
Embodying a fully asynchronous approach, TON Blockchain involves a few concepts which are uncommon to traditional blockchains. Particularly, each interaction of any actor with the blockchain consists of a graph of asynchronously transferred [messages](/develop/smart-contracts/guidelines/message-delivery-guarantees) between smart contracts and/or the external world. Each transaction consists of one incoming message and up to 512 outgoing messages.
11+
Embodying a fully asynchronous approach, TON Blockchain involves a few concepts which are uncommon to traditional blockchains. Particularly, each interaction of any actor with the blockchain consists of a graph of asynchronously transferred [messages](/develop/smart-contracts/guidelines/message-delivery-guarantees) between smart contracts and/or the external world. Each transaction consists of one incoming message and up to 255 outgoing messages.
1212

1313
There are 3 types of messages, that are fully described [here](/develop/smart-contracts/messages#types-of-messages). To put it briefly:
1414
* [external message](/develop/smart-contracts/guidelines/external-messages):

0 commit comments

Comments
 (0)