You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/develop/archive/tg-bot-integration-py.md
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,10 @@ import Button from '@site/src/components/button'
2
2
3
3
# TON Connect for Telegram Bots - Python
4
4
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
+
5
9
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).
6
10
We will analyze connecting a wallet, sending a transaction, getting data about the connected wallet, and disconnecting a wallet.
Copy file name to clipboardExpand all lines: docs/develop/archive/tg-bot-integration.mdx
+27-23Lines changed: 27 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,10 @@ import Button from '@site/src/components/button'
2
2
3
3
# TON Connect for Telegram Bots
4
4
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
+
5
9
In this tutorial, we’ll create a sample telegram bot that supports TON Connect 2.0 authentication using Javascript TON Connect SDK.
6
10
We will analyze connecting a wallet, sending a transaction, getting data about the connected wallet, and disconnecting a wallet.
7
11
@@ -206,7 +210,7 @@ import { IStorage } from '@tonconnect/sdk';
206
210
const storage =newMap<string, string>(); // temporary storage implementation. We will replace it with the redis later
207
211
208
212
exportclassTonConnectStorageimplementsIStorage {
209
-
constructor(privatereadonlychatId:number) {} // we need to have different stores for different users
213
+
constructor(privatereadonlychatId:number) {} // we need to have different stores for different users
210
214
211
215
private getKey(key:string):string {
212
216
returnthis.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
269
273
After that we subscribe to wallet change. When user connects a wallet, bot will send a message `${wallet.device.appName} wallet connected!`.
270
274
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.
271
275
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.
273
277
274
278
275
279
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:
351
355
```text
352
356
First screen:
353
357
<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>
355
359
356
360
Second screen:
357
361
<Unified QR>
358
362
<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)>, <...>
360
364
361
365
Third screen:
362
366
<Selected wallet QR>
363
367
<Back (opens second screen)>
364
-
<Open selected wallet link>
368
+
<Open selected wallet link>
365
369
```
366
370
367
371
Let's start with adding inline keyboard to the `/connect` command handler in the `main.ts`
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.
409
413
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.
410
414
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.
412
416
413
417
Next we tell Telegram to call `callback_query` handler with `{ "method": "chose_wallet" }` value when user clicks to the `Choose a Wallet` button.
Compile and run the bot to check that commands above works correctly.
1122
1126
1123
1127
## 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.
1126
1130
Then we should notify user that QR / transaction request is expired.
1127
1131
1128
1132
### Send transaction optimisation
@@ -1339,10 +1343,10 @@ export function getConnector(
1339
1343
1340
1344
</details>
1341
1345
1342
-
This code may look a little tricky, but here we go.
1346
+
This code may look a little tricky, but here we go.
1343
1347
Here we store a connector, it's cleaning timeout and list of callback that should be executed after the timeout for each user.
1344
1348
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.
1346
1350
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.
1347
1351
1348
1352
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
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`),
1829
1833
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.
1830
1834
1831
1835
@@ -1917,7 +1921,7 @@ export async function handleSendTXCommand(msg: TelegramBot.Message): Promise<voi
1917
1921
1918
1922
</details>
1919
1923
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.
1921
1925
1922
1926
## Add a permanent storage
1923
1927
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.
Copy file name to clipboardExpand all lines: docs/develop/blockchain/sharding-lifecycle.mdx
+69Lines changed: 69 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,75 @@ ISP underpins the TON Blockchain's design, treating each account as part of its
14
14
15
15
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.
16
16
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:
(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
+
17
86
## Messages and Instant Hypercube Routing (Instant Hypercube Routing)
18
87
19
88
In the infinite sharding paradigm, each account (or smart-contract) is treated as if it were itself in a separate shardchain.
Copy file name to clipboardExpand all lines: docs/develop/dapps/asset-processing/overview.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Here you can find a **short overview** on [how TON transfers work](/develop/dapp
8
8
9
9
## Overview on messages and transactions
10
10
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.
12
12
13
13
There are 3 types of messages, that are fully described [here](/develop/smart-contracts/messages#types-of-messages). To put it briefly:
0 commit comments