TON Blockchain 101
🎯 This document attempts to summarize key concepts of TON blockchain. Articulated during process of making TON Bridge by Oraichain Labs developers
Common terminology
Term | Definition |
---|---|
TON actor | Like “smart contract”. Even user wallets are contracts. Actor properties (including but not limited to): Unique address; Code; Data ; Balance |
Transaction | A set of steps to modify actor’s properties. Transactions are ordered. |
Chain | Sequence of transactions |
AccountChain | Sequence of transactions for a single address |
Blocks | Batch a set of transactions |
ShardChain | A set of blocks including transactions of a set of accounts. Can merge (aggregate) or split ShardChains. Allow up to 2^60 shard chains |
Blockchain (called Workchain) | An aggregation of ShardChains with common set of rules. Ton allows many blockchains with diff set of rules (2^32 blockchains) |
MasterChain | Chain for multichain state checkpoint. Masterchain blocks - blocks of the masterchain that include shard blocks of different workchains within a logical time (lt) range. A masterchain block does not include all shard blocks of a workchain, but only the highest-seqno shard block in that lt range. Masterchain is also a workchain with wc = -1 |
Key block | Key block is a masterchain block containing prev, cur, and next validator sets |
Quickly TON blockchain
Consensus algorithm
💡 Refer to The TON Blockchain is based on PoS consensus for detail
Ton uses BFT → each block should have > 2/3 voting power
Split consensus into multiple validation sessions
Each session lasts about 18 hours (config params #15 in base 10)
An election round is created to start a new session
Election process takes around 7 hours (also config params #15)
Send TON using special tx to election contract to participate
After an election, has 2 hours before the session starts (also config params #15) → refund TON if not elected & show list of next validators when querying config & keyblock
Number of validators (config params #16 in base 10)
Has a maximum global number of validators (current is 400 vals)
Has a maximum main number of validators for each session. Current is 100 main vals. Chosen from the pool of max validators (pseudorandom)
Main validators validate masterchain blocks
The rest validate shard blocks
Validators of each block is pseudorandom, but best effort to pick as many as possible.
Smart Contracts
Components
: <workchain_id (1 byte)><account_id (32 bytes)>Account ID
: sha256(compiled_code, initital_state)User friendly version (36 bytes)
: <flags (1 byte)><workchain_id><account_id><verification (2 bytes)>flag
- isBounceable (if cannot send to then “bounce” fund back to sender); isTestnetOnly, isUrlSafeverification
- CRC16-CCITT signature from the previous 34 bytesThen we base64(36 bytes) to get friendly address
Development concept
💡 On TON, everything consists of cells, including contract code, stored data, blocks, achieving streamline and robust flexibility in the process.
Cells
Cells are entities in Ton for data storage.
max = 1023 bits per cell
max 4 references to other cells
No circular ref with
Form DAG
5 types of cells
Bag of Cells (BoC)
Bag of Cells is a data format to
Serializing cells into bytes arrays
Contracts send
BoC
to others
TL-B (Type Language - Binary)
💡 Serves to describe the type system, constructors and existing functions. E.g TL-B schemes used to build binary structures associated with TON Blockchain
Language: TL-B
Type: TL-B Types
Ton FunC tutorials:
💡 A high-level language FunC is used to program smart contracts on TON: domain-specific, C-like, statically typed language.
FunC standard library
Best practices
References
Last updated