Description of a smart contract execution process
List of abbreviations
List of abbreviations:
TN - trusted node
WN - writing node
DB - database
Smart contract execution
Smart contract execution
The launch of smart contracts for execution is initiated by a special "Start" transaction that contains the sender's address (32-byte public key of the sender or his 4-byte index), the smart contract address (the 32-bit public key of the smart contract, or its 4-byte index), the sum of the transaction in "coins" (can be zero), and can also contain a list of called smart contract methods and a list of passed arguments.
The process of performing smart contracts on TN is as follows: At the beginning of the round, together with the round table TN receives the transaction packets and the new smart contract states packets. The new smart contract state packets come from TN of the previous rounds in which the smart contracts were completed. By the beginning of the current round, several batches of transactions may come to the entrance, as well as several packets of new states from different previous rounds.
The "new states" packet is similar to the "transaction packet" that is sent in the network, but the additional information is that it is signed by all TN of the round and contains the round number in which execution of the smart contracts began.
On the basis of the received data, and also on the basis of data of blockchain DB, TN form the queue of smart contracts execution for the current round, and then execute smart contracts sequentially, in order of priority.
When you run smart contracts, you can generate new transactions that transfer funds as well as start other smart contracts.
After all the smart contracts have been completed on all trusted hosts, an additional consensus is made on all new states of the smart contract, as well as on the new generated transactions. After the consensus is completed, a packet of new states is generated, and a list of the current trusted nodes (from the last rounds table) is requested.
During a consensus, the protocol defines a delegate that sends a packet of new states to the current trusted nodes to be added to the block.
Thus, the round ends with the release of a new block, and TN continue to execute smart contracts by the list according to the smart contracts execution queue. When smart contracts are completed, their new states must be sent to TN of the current round to be added to the blockchain.
In the processing of round input data TN perform the following activities:
- Actualize the smart contracts execution queue and execute smart contracts according to it;
- Release a new block, which in addition to transactions arrived for processing in the round also include information obtained from TN of the previous rounds in the form of new states packets.
Adding records on the launch of a smart contract in the "execution queue" ensures the correct sequential execution of the same smart contact in subsequent rounds. This ensures that smart contracts are executed in a strictly defined order, taking into account the previous states. Each subsequent start of the smart contract is performed strictly after the previous execution has finished and the changed state is fixed in the smart contract.
After a WN has formed a block, it sends the smart contracts execution queues to the next TN, along with the new round table.
Execution of a smart contract is not related to issuing block in a round, and continues upon full completion on all TN. After the smart contract is completed, the next procedure of consensus on the new states of smart contracts is conducted, after which the result is signed by the electronic signature of all the participating TN.