Introduction to China Mobile Chain Transaction Module

The China Mobile Chain transaction module is one of the core modules of the China Mobile Chain blockchain system. Its main function is to process transaction requests initiated by users and package them into blocks and add them to the blockchain. The transaction module receives instructions from different contract executions, such as account creation, transfer, deployment and execution of smart contracts, and ensures that all transactions are valid and legal. Compared with other modules, the transaction module has a larger workload and needs to efficiently handle thousands of transaction requests per second.

01

Transaction components

China Mobile Chain's transactions mainly consist of the following components:

picture

Transactions are a whole in China Mobile Chain. Transactions have a unified transaction management mechanism (Transaction). Transactions either all execute successfully or all fail. Transactions in the transaction module are the basic units used to perform state transition operations on the blockchain. Chain accounts first initiate transactions through smart contracts, which must contain one or more Actions. After the smart contract is submitted by the chain account, the transaction will be created. The transaction processor will then verify and execute the transactions. By default, Actions in the same transaction will be in the same transaction. If one of the Actions fails to verify, all Actions in the current transaction will be rolled back.

Take the transaction of purchasing memory as an example:

{
    "expiration":"2023-06-21T12:00:00", #事务过期时间
    "ref_block_num":12345, #指示事务的参考区块编号,防止重放攻击
    "ref_block_prefix":67890, #指示事务的参考前缀,防止重放攻击
    "max_net_usage_words":0, #允许在事务中使用的最大网络资源单位,为0则无限制
    "max_cpu_usage_ms":0, #允许在事务中使用的最大CPU资源时间,为0则无限制
    "delay_sec":0, #事务的延迟执行时间(秒)
    "context_free_actions":[ #与上下文无关的操作
    ],
    "actions":[ #事务中的操作列表,这里包含了一个转账操作
        {
            "account":"eosio",
            "name":"buyrambytes",
            "authorization":[
                {
                    "actor":"accountadmin",
                    "permission":"active"
                }
            ],
            "data":{
                "payer":"accountadmin"
                "receiveruser":"receiveruser"
                "bytes":"1024"
            }
        }
    ],
    "transaction_extensions":[ #事务的扩展信息(一般为空)

    ]
}

In the above transaction:

actions contains all operations of the current transaction.

Account represents the target contract account to be called, and specifies which account's contract is to be executed.

name specifies the name of the operation to be performed. In this example, the method of purchasing memory in the system contract is called.

Authorization information list specifies the authorized users and permission levels that can perform this operation. In this example, only "accountadmin" with the "active" permission is authorized to perform this operation.

data contains specific operation data. In the contract to purchase memory, payer is the payer, receiver is the receiver, and bytes means purchasing 1024 bytes of memory.

When the above transaction is submitted, the transfer operation in the action will create a new transaction, and the transaction manager will verify the authorization (signature authorization) in the transfer. If the sender's permissions are wrong or insufficient, an authorization failure error will occur, the entire transaction and data will be rolled back, and the submitted transaction cannot be stored in the block's transaction list (delayed transactions will also be included in the block after failure) , and CPU resources will be charged). During this process, the transaction will go through a complex process to complete the confirmation and final execution. The next chapter will introduce the entire transaction life cycle.

02

Introduction to transaction life cycle

The entire life cycle of a China Mobile Chain transaction, including user creation of transaction objects, signature transactions, transaction broadcast, verification, checking transaction validity and resource adequacy, adding transactions to the pending transaction pool, block generation and confirmation, transaction execution and The lengthy process of updating the blockchain status, notifying the user that the transaction is complete, and adding the transaction to the relevant account’s transaction history. Note that the figure below is a simplified flow chart, and the actual processing also includes many complex details and links.

picture

The general process of the transaction is as follows:

1. Transaction transaction structure: Transaction transactions include a series of operations, which define the specific functions performed in the transaction, such as transfers, calling smart contracts, updating contracts, etc. Each operation requires specifying the type of operation, the permissions required to perform it, and the related parameters.

2. Signature: Transactions need to be effectively signed to prove that the transaction was initiated by an authorized account and ensure the integrity of the transaction. Each operation in a transaction needs to be added with one or more signatures to ensure the legitimacy of its origin.

3. Permission verification: Before executing the transaction, China Mobile Chain will verify the authority of the transaction. This means that the transaction must be initiated by an account authorized with the corresponding permissions, and the transaction needs to meet the permission requirements of the authorized account, such as weight, key, etc.

4. Broadcast transaction: After executing all operations contained in the transaction, the transaction enters the end phase. In this step, a corresponding operation receipt is generated for each operation. Transaction receipts summarize the results of a transaction (executed, not executed, failed, delayed, expired, etc.), including actual CPU usage in microseconds, as well as total NET and RAM used and broadcast over the P2P network to enable Other nodes can receive the transaction and verify its validity.

5. Propagation and verification: After the transaction is broadcast to other nodes in the network, each node will verify the legality and validity of the transaction. During the verification process, the node will check whether the signature, authority, transaction hash and related data of the transaction are correct.

6. Block packaging and confirmation: After passing the verification, the transaction transaction will enter the candidate transaction pool of the block. When a new block is generated, China Mobile Chain will generate a new block approximately every 0.5 seconds, which will be generated from the candidate transaction pool. A number of transactions are selected from the pool to form the block. Once a new block is generated and confirmed by consensus, the transactions contained in it are confirmed and permanently recorded on the blockchain.

7. Status update: According to the operations in the transaction, the status of the blockchain will be updated, including smart contract storage, data changes, etc. Updates to these states affect the integrity and consistency of the blockchain state.

It should be noted that during the transaction execution process, the signature and authority verification will be verified after the transaction is created to ensure that all states will be rolled back, thus ensuring the data consistency of the entire blockchain. Throughout the life cycle, the transaction settings of the chain can be set through some global configurations, such as transaction timeout, maximum number of transaction delay blocks, number of transaction processor threads and other parameters to flexibly control transaction execution rules to meet the needs of different environments. Different needs.

03

Summarize

The transaction module is an important part of China Mobile Chain. The transaction module of China Mobile Chain has the following attributes:

  • Efficiency: China Mobile Chain's trading system has independent threads. After all transactions are initiated, they will be suspended in the thread pool. The thread pool can quickly process a large number of transactions and support parallel processing.

  • Stability: China Mobile Chain’s transaction module adopts a highly reliable algorithm and system design. By using the DPoS consensus algorithm to select block producers and verify transactions, it reduces the computing cost and energy consumption of the consensus algorithm and ensures the consistency of transactions. and correctness.

  • Scalability: China Mobile Chain’s transaction module adopts a distributed architecture and optimization algorithm, and all nodes are connected using P2P, which can be easily expanded to a larger network scale.

  • Security: China Mobile Chain’s transaction module uses advanced encryption technology and security mechanisms to protect the integrity of transactions through digital signatures and hash functions. The hash function converts transaction data into a fixed-length hash value, and any pair of Modifications to the data will result in different hash values. By comparing hash values, it can be verified whether the transaction data has been tampered with, ensuring the security and confidentiality of the transaction.

  • Customizability: China Mobile Chain’s trading module can be customized and adjusted as needed. Various parameters of the trading system can be configured through system contracts to meet the needs of different environments.

04

References

[1]BSN open alliance chain:

https://opb.bsnbase.com/main/index

[2] Official EOSIO account and permission introduction:

https://developers.eos.io/welcome/latest/protocol-guides/accounts_and_permissions

[3] Official EOSIO transaction introduction:

https://developers.eos.io/welcome/latest/protocol-guides/transactions_protocol

[4] Official EOSIO smart contract introduction:

https://developers.eos.io/welcome/latest/smart-contract-guides/index

[5] Official EOSIO resource module introduction:

https://developers.eos.io/welcome/latest/resources/index

[6] Official EOSIO code base transaction rollback fee answer:

https://developers.eos.io/welcome/latest/resources/index

[7] The official EOS forum’s answer to transaction parameters preventing replay attacks:

https://developers.eos.io/welcome/latest/resources/index

[8] The official EOSIO white paper explains context-free-actions:

https://developers.eos.io/welcome/latest/resources/index

Computer access to DDC web portal

ddc.bsnbase.com

END

Guess you like

Origin blog.csdn.net/BSN_yanxishe/article/details/133128438