Kinds of transactions in TON Blockchain

From TON Wiki (En)

A transaction in TON is a process that involves sending an incoming message to activate a smart contract, performing the corresponding actions within the contract, as well as sending outgoing messages to other network participants if stipulated by the contract.

General Components of a Transaction

Each transaction contains or indirectly refers to the following data:

  • The account to which the transaction belongs
  • The logical time of the transaction
  • One or zero inbound messages processed by the transaction
  • The number of generated outbound messages
  • The outbound messages
  • The initial state of the account (including its balance)
  • The final state of the account (including its balance)
  • The total fees collected by the validators
  • A detailed description of the transaction, containing all or some data needed to validate it, including the kind of the transaction and some of the intermediate steps performed
Transaction in TON
Transaction in TON

The logical time in TON Blockchain serves to accurately order events in the system, which is especially important in the asynchronous operation of smart contracts. It is assigned to each outgoing message and event created in the transaction, which allows for treating the creation of each outgoing message as an atomic event, dependent on previous messages and transactions in the same account. This ensures strictly increasing logical time for messages created by the same smart contract and helps validators efficiently order and process transactions.

The scheme illustrates the transaction process in TON Blockchain, showing the interaction of the smart contract with messages. The incoming message (in msg) arrives at the smart contract (marked with a circle labeled «A»). Upon receiving the message, the smart contract may perform certain actions and, depending on their result, generate one or several outgoing messages (out msg 1 and out msg 2), which are sent to other network participants. The number «0» is the exit code, indicating that the smart contract has completed its execution successfully and without errors. The transactions in the diagram are the arrows indicating data transfer from the incoming message to the smart contract and then to the outgoing messages.

Kinds of Transactions

  • Ordinary transactions
  • Storage transactions
  • Tick transactions
  • Tock transactions
  • Split transactions
  • Merge transactions

Ordinary Transactions

Belong to an account. They process one incoming message with a destination address, calculate the new state of the account, and generate several outgoing messages from the account source.

Phases of an Ordinary Transaction

A regular transaction is carried out in several phases, which can be considered as closely related «sub-transactions»:

  • Storage phase — Collects necessary payments for storing the account state at the current time.
  • Credit phase — The account is credited with the amount of the incoming message.
  • Computing phase — The smart contract code is called inside the TVM instance and completes with an exit code, new persistent data, and a list of actions.
  • Action phase — If the smart contract is successfully completed, actions from the list are executed.
  • Bounce phase — If the transaction was interrupted and the incoming message has a set bounce flag, it «bounces» back to its original sender.

Storage Transactions

These transactions can be inserted by validators under certain network conditions, for example, when an account has not been used for a long time or its balance is insufficient to pay for storage. They do not process any incoming messages and do not invoke any code. Their sole purpose is to collect payments for storing the account, affecting its storage statistics and balance. If the resulting balance of Toncoin on the account drops below a certain amount, the account can be frozen, and its code and data replaced with their combined hash. Storage transactions are very similar to a separate storage phase of a regular transaction.

Tick and Tock Transactions

Tick and tock transactions are reserved for special system smart contracts that must be automatically called in each block. Tick transactions are called at the beginning of each masterchain block, while tock transactions — at the end.

Split Transactions

Split transactions actually consist of two transactions. If an account ξ needs to be split into two accounts ξ and ξ' (for example, to optimize sharding, scalability of the network, or distribution of data and load):

  1. First, a splitting preparation transaction is executed, similar to a tock transaction for account ξ. This must be the last transaction for ξ in the shardchain block.
  2. Then a splitting setup transaction is added for account ξ' with a reference to the corresponding splitting preparation transaction.

Merge Transactions

Merge transactions also consist of two actions. If account ξ' needs to be merged with account ξ (for example, to optimize sharding, reduce network load, or combine data from different shardchains):

  1. First, a merging preparation transaction is executed for ξ', which converts all its permanent state and balance into a special constructor message with a destination address ξ.
  2. Then a merging setup transaction for ξ, referencing the corresponding merging preparation transaction, processes this constructor message.

Links

  1. https://docs.ton.org/tblkch.pdf
  2. https://docs.ton.org/develop/smart-contracts/guidelines/message-delivery-guarantees
  3. https://docs.ton.org/develop/data-formats/transaction-layout