A method and system for optimizing the speed of blockchain transaction on-chain

By calculating transaction weights and constructing processing queues, the order of uploading blockchain transactions is optimized, which solves the problem of low transaction fees and long waiting time in the blockchain network, and improves the uploading speed and processing efficiency of transactions.

CN118055112BActive Publication Date: 2024-09-10ZHONGKE LIANAN (BEIJING) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410030650.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-08
Publication Date
2024-09-10
Estimated Expiration
2044-01-08

AI Technical Summary

Technical Problem

Transactions with lower handling fees in the blockchain network have low packaging efficiency and may have to wait for a long time to be uploaded to the chain, lacking optimization methods.

Method used

By calculating transaction waiting time and Gas usage, calculating transaction weight, building a processing queue, and optimizing the packaging order of checker nodes, we ensure that the weight of transactions with long waiting times gradually becomes larger, and avoid waiting for transactions with lower fees.

Benefits of technology

It improves the uploading speed of blockchain transactions, ensures that each transaction will not always be in a waiting state, and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118055112B
    Figure CN118055112B
Patent Text Reader

Abstract

The present invention provides a method and system for optimizing the speed of blockchain transaction upload, the steps of the method include: obtaining transactions to be packaged uploaded by users; determining the transaction waiting time based on the upload time of the transactions to be packaged, and calculating the time parameter based on the transaction waiting time of the transactions to be packaged; determining the Gas usage of the transactions to be packaged based on the transaction category of the transactions to be packaged, and calculating the Gas parameter based on the Gas usage of the transactions to be packaged; calculating the transaction weight of the transactions to be packaged based on the time parameter and the Gas parameter, constructing a processing queue of the transactions to be packaged based on the transaction weight, and the verifier node packages the transactions to be packaged on the chain based on the order of the processing queue. This solution solves the problem that the verifier node preferentially packages and uploads transactions with higher handling fees by constructing a processing queue.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain technology, and in particular to a method and system for optimizing the speed of blockchain transaction upload. Background Art

[0002] Blockchain is a distributed ledger technology, originally described as the underlying technology of Bitcoin. It is a decentralized database that verifies and records transactions through a consensus mechanism of multiple nodes. The core principle of blockchain is to store data in multiple nodes in the network, and each node has a complete copy of the ledger. When a new transaction occurs, the nodes in the network reach a consensus through a consensus algorithm and add the transaction to the block, forming an immutable blockchain.

[0003] Ethereum is an important milestone in blockchain technology. It expands the functionality of blockchain and introduces the concept of smart contracts, allowing developers to build and deploy decentralized applications (DApps) on the blockchain.

[0004] Generally, the speed at which a user sends a transaction to a blockchain network is directly related to the transaction fee provided by the user. In a blockchain network, verifier nodes usually prioritize transactions with higher fees for packaging and uploading them to the chain, and often wait for a long time for transactions with lower fees, or even wait forever due to the low fees, resulting in low packaging efficiency. Currently, there is a lack of a method to optimize packaging efficiency. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a method for optimizing the speed of blockchain transaction on-chain to eliminate or improve one or more defects existing in the prior art.

[0006] One aspect of the present invention provides a method for optimizing the speed of blockchain transaction on-chain, the method comprising the following steps:

[0007] Get the transactions to be packaged uploaded by the user;

[0008] Determine a transaction waiting time based on the upload time of the transaction to be packaged, and calculate a time parameter based on the transaction waiting time of the transaction to be packaged;

[0009] Determine the Gas usage of the transaction to be packaged based on the transaction category of the transaction to be packaged, and calculate the Gas parameter based on the Gas usage of the transaction to be packaged;

[0010] The transaction weight of the transaction to be packaged is calculated based on the time parameter and the Gas parameter, and a processing queue of the transaction to be packaged is constructed based on the transaction weight. The verifier node packages and uploads the transaction to be packaged to the chain based on the order of the processing queue.

[0011] By adopting the above scheme, the chain processing process of this scheme is different from the existing technology. This scheme first calculates the time parameter through the waiting time of each transaction, calculates the Gas parameter through the Gas usage, and then calculates the transaction weight through the time parameter and the Gas parameter. The processing queue is constructed through the transaction weight, and the chain processing is carried out in sequence based on the processing queue. On the one hand, this scheme solves the problem that the verifier node prioritizes the packaging and chaining of transactions with higher handling fees by constructing a processing queue. On the other hand, since the calculation of the transaction weight of this scheme takes the waiting time of the transaction into consideration, the transaction weight changes in real time, and the transaction weight of transactions with longer waiting time will gradually increase. No transaction will always be in a waiting state, which solves the problem that transactions with lower handling fees may always be waiting in the existing technology.

[0012] In some embodiments of the present invention, in the step of calculating the transaction weight of the to-be-packaged transaction based on the time parameter and the Gas parameter, the transaction weight is calculated according to the following formula:

[0013]

[0014] Among them, w represents the transaction weight, g' represents the Gas parameter, t' represents the time parameter, m represents the preset weight coefficient, base represents the preset transaction classification weight, and e represents the Euler number.

[0015] The above scheme takes into account both the Gas usage and the waiting time. On the one hand, it ensures the transaction of Gas usage. On the other hand, since the waiting time is taken into account, the waiting time of each transaction is changing, so that each transaction will not be in a waiting state all the time.

[0016] In some embodiments of the present invention, in the step of calculating the time parameter based on the transaction waiting time of the to-be-packaged transaction, the time parameter is calculated based on the following formula:

[0017]

[0018] Among them, t' represents the time parameter, t represents the transaction waiting time of the currently calculated transaction to be packaged, and t max Indicates the maximum transaction waiting time of all transactions to be packaged, t min Indicates the minimum transaction waiting time of all transactions to be packaged.

[0019] In some embodiments of the present invention, in the step of calculating the Gas parameter based on the Gas usage of the transaction to be packaged, the Gas parameter is calculated based on the following formula:

[0020]

[0021] Among them, g' represents the Gas parameter, g represents the Gas usage of the currently calculated transaction to be packaged, and g max Indicates the maximum amount of Gas used by all transactions to be packaged.

[0022] In some embodiments of the present invention, the transactions to be packaged in the pending transactions are determined based on the selected instructions of Ethereum, a first quantity is determined based on the Gas usage threshold of the current block and the Gas usage of each transaction to be packaged, and the total number of transactions to be packaged in the processing queue is determined based on the first quantity.

[0023] In some embodiments of the present invention, the first number is n. In the step of determining the first number based on the Gas usage threshold of the current block and the Gas usage of each transaction to be packaged, the transactions to be packaged are sorted based on the transaction weights of the transactions to be packaged, and the total Gas usage of the first n transactions to be packaged in the sort is less than or equal to the Gas usage threshold of the current block, and the total Gas usage of the first n+1 transactions to be packaged in the sort is greater than the Gas usage threshold of the current block.

[0024] With the above solution, since the processing speed of the verifier node is usually faster in the actual processing process, if the total number of transactions to be packaged in the processing queue is set only according to the Gas usage threshold of the current block, it will easily lead to reduced processing efficiency. This solution is based on the Gas usage threshold of the current block to expand the total number of transactions to be packaged in the processing queue to ensure processing efficiency.

[0025] In some embodiments of the present invention, in the step of packaging and chaining the transactions to be packaged based on the order of the processing queue by the verifier node, if the verifier node completes the packaging and chaining of any transaction to be packaged in the processing queue, the transaction to be packaged is deleted from the processing queue.

[0026] In some embodiments of the present invention, the step of determining the Gas usage of the transaction to be packaged based on the transaction category of the transaction to be packaged includes:

[0027] Acquiring a transaction category of the transaction to be estimated, and determining whether the transaction to be estimated belongs to a first-category transaction or a second-category transaction based on the transaction category;

[0028] If the transaction category is a Class I transaction, the basic Gas usage and transaction data content are obtained, and the additional Gas usage is calculated based on the number of zero bytes and non-zero bytes in the transaction data content, and the Gas usage is calculated based on the basic Gas usage and the additional Gas usage;

[0029] If the transaction category is a Class II transaction, the basic Gas usage and transaction transaction message are obtained. The transaction transaction message includes the transaction amount. The user's disposable amount is determined based on the transaction amount and the account balance of the transaction initiator. The disposable amount is used as the upper limit of the cycle, and the basic Gas usage is used as the lower limit of the cycle. The Gas usage is determined by binary search.

[0030] In some embodiments of the present invention, the transaction category of the first type of transaction includes ordinary transfer transactions and smart contract deployment transactions;

[0031] If the transaction to be estimated belongs to an ordinary transfer transaction, then in the step of calculating the additional Gas usage based on the number of zero bytes and the number of non-zero bytes in the transaction data content, the remark data content in the transaction data content is obtained, the number of zero bytes and the number of non-zero bytes in the remark data content is calculated, the first Gas usage is calculated based on a preset zero byte unit price and the number of zero bytes in the remark data content, the second Gas usage is calculated based on the preset non-zero byte unit price and the number of non-zero bytes in the remark data content, and the additional Gas usage is calculated based on the first Gas usage and the second Gas usage;

[0032] If the transaction to be estimated belongs to a smart contract deployment transaction, the step of calculating the additional Gas usage based on the number of zero bytes and the number of non-zero bytes in the transaction data content includes: obtaining the length of the smart contract byte data in the transaction data content, and calculating the third Gas usage based on the length of the smart contract byte data; then based on the number of zero bytes and the number of non-zero bytes in the smart contract byte data in the transaction data content, calculating the fourth Gas usage based on the preset zero byte unit price and the number of zero bytes in the smart contract byte data, calculating the fifth Gas usage based on the preset non-zero byte unit price and the number of non-zero bytes in the smart contract byte data, and calculating the additional Gas usage based on the third Gas usage, the fourth Gas usage, and the fifth Gas usage;

[0033] The transaction category of the second type of transaction includes calling smart contract transactions, taking the disposable amount as the upper limit of the cycle, taking the basic Gas usage as the lower limit of the cycle, and using binary search to determine the total Gas usage includes:

[0034] Determine whether the upper limit of the loop is greater than the sum of the lower limit of the loop and the preset interval value;

[0035] If yes, then loop, calculate the middle value of the loop upper limit and the loop lower limit, input the middle value as the test Gas usage into the virtual machine to pre-execute the transaction, and receive the execution result of the virtual machine. If the virtual machine executes successfully, then use the middle value at this time as the loop upper limit, and judge again whether the loop upper limit is greater than the loop lower limit; if the virtual machine fails to execute, then use the middle value at this time as the loop lower limit, and judge again whether the loop upper limit is greater than the sum of the loop lower limit and the preset interval value;

[0036] If not, the loop is exited and the value of the loop upper limit at this time is used as the value of the total Gas usage.

[0037] The second aspect of the present invention also provides a blockchain transaction on-chain speed optimization system, which includes a computer device, the computer device includes a processor and a memory, the memory stores computer instructions, and the processor is used to execute the computer instructions stored in the memory. When the computer instructions are executed by the processor, the system implements the steps implemented by the method described above.

[0038] The third aspect of the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps implemented by the aforementioned blockchain transaction on-chain speed optimization method.

[0039] Additional advantages, purposes, and features of the present invention will be described in part in the following description, and will become apparent to those skilled in the art after studying the following, or may be learned from the practice of the present invention. The purposes and other advantages of the present invention can be specifically pointed out and obtained in the specification and the accompanying drawings.

[0040] Those skilled in the art will appreciate that the objectives and advantages that can be achieved with the present invention are not limited to the above specific description, and the above and other objectives that can be achieved by the present invention will be more clearly understood from the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] The drawings described herein are used to provide a further understanding of the present invention, constitute a part of this application, and do not constitute a limitation of the present invention.

[0042] Figure 1 A schematic diagram of an implementation method of the blockchain transaction on-chain speed optimization method of the present invention;

[0043] Figure 2 This is a schematic diagram of the mapping relationship between transaction weight and hash table;

[0044] Figure 3 It is a schematic diagram of the architecture of the present invention. DETAILED DESCRIPTION

[0045] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments and the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.

[0046] It should also be noted that, in order to avoid obscuring the present invention due to unnecessary details, only structures and / or processing steps closely related to the solutions according to the present invention are shown in the accompanying drawings, while other details that are not closely related to the present invention are omitted.

[0047] The steps of the present invention specifically include:

[0048] like Figure 1 and 3 As shown, the present invention proposes a method for optimizing the speed of blockchain transaction on-chain, and the steps of the method include:

[0049] Step S100, obtaining the transactions to be packaged uploaded by the user;

[0050] During the specific implementation process, the transactions to be packaged are added to the preset transaction pool.

[0051] Step S200, determining a transaction waiting time based on the upload time of the transaction to be packaged, and calculating a time parameter based on the transaction waiting time of the transaction to be packaged;

[0052] In a specific implementation process, in the step of determining the transaction waiting time based on the upload time of the transaction to be packaged, the difference between the current time and the upload time of the transaction to be packaged is calculated to obtain the transaction waiting time.

[0053] Step S300, determining the Gas usage of the transaction to be packaged based on the transaction category of the transaction to be packaged, and calculating the Gas parameter based on the Gas usage of the transaction to be packaged;

[0054] During the specific implementation process, in the step of determining the Gas usage of the transaction to be packaged based on the transaction category of the transaction to be packaged, the Gas usage of the transaction to be packaged is calculated based on the basic Gas usage preset for the transaction to be packaged, and the basic Gas usage preset for each transaction category is different.

[0055] In some embodiments of the present invention, different basic Gas usages are set for the ordinary transfer transaction and the smart contract deployment transaction. Specifically, the value of the basic Gas usage of the ordinary transfer transaction is set to 21000, and the value of the basic Gas usage of the smart contract deployment transaction is set to 53000.

[0056] Step S400: Calculate the transaction weight of the transaction to be packaged based on the time parameter and the Gas parameter, build a processing queue for the transaction to be packaged based on the transaction weight, and the verifier node packages the transaction to be packaged and processes it on the chain based on the order of the processing queue.

[0057] In the specific implementation process, the verifier node processes the transactions to be packaged with higher transaction weights toward the transactions to be packaged with lower transaction weights based on the order of the processing queue.

[0058] By adopting the above scheme, the chain processing process of this scheme is different from the existing technology. This scheme first calculates the time parameter through the waiting time of each transaction, calculates the Gas parameter through the Gas usage, and then calculates the transaction weight through the time parameter and the Gas parameter. The processing queue is constructed through the transaction weight, and the chain processing is carried out in sequence based on the processing queue. On the one hand, this scheme solves the problem that the verifier node prioritizes the packaging and chaining of transactions with higher handling fees by constructing a processing queue. On the other hand, since the calculation of the transaction weight of this scheme takes the waiting time of the transaction into consideration, the transaction weight changes in real time, and the transaction weight of transactions with longer waiting time will gradually increase. No transaction will always be in a waiting state, which solves the problem that transactions with lower handling fees may always be waiting in the existing technology.

[0059] In some embodiments of the present invention, in the step of calculating the transaction weight of the to-be-packaged transaction based on the time parameter and the Gas parameter, the transaction weight is calculated according to the following formula:

[0060]

[0061] Among them, w represents the transaction weight, g' represents the Gas parameter, t' represents the time parameter, m represents the preset weight coefficient, base represents the preset transaction classification weight, and e represents the Euler number.

[0062] Figure 3 The standardized g and t in are g' and t'.

[0063] In some embodiments of the present invention, the preset transaction classification weight for each transaction category is different. Specifically, the transaction classification weight is set to 1.5 for ordinary transfer transactions, the transaction classification weight is set to 1 for calling smart contract transactions, and the transaction classification weight is set to 0.5 for deploying smart contract transactions.

[0064] In some embodiments of the present invention, in the step of calculating the time parameter based on the transaction waiting time of the to-be-packaged transaction, the time parameter is calculated based on the following formula:

[0065]

[0066] Among them, t' represents the time parameter, t represents the transaction waiting time of the currently calculated transaction to be packaged, and t max Indicates the maximum transaction waiting time of all transactions to be packaged, t min Indicates the minimum transaction waiting time of all transactions to be packaged.

[0067] In some embodiments of the present invention, in the step of calculating the Gas parameter based on the Gas usage of the transaction to be packaged, the Gas parameter is calculated based on the following formula:

[0068]

[0069] Among them, g' represents the Gas parameter, g represents the Gas usage of the currently calculated transaction to be packaged, and g max Indicates the maximum amount of Gas used by all transactions to be packaged.

[0070] In some embodiments of the present invention, the transactions to be packaged in the pending transactions are determined based on the selected instructions of Ethereum, a first quantity is determined based on the Gas usage threshold of the current block and the Gas usage of each transaction to be packaged, and the total number of transactions to be packaged in the processing queue is determined based on the first quantity.

[0071] In some embodiments of the present invention, the first number is n. In the step of determining the first number based on the Gas usage threshold of the current block and the Gas usage of each transaction to be packaged, the transactions to be packaged are sorted based on the transaction weights of the transactions to be packaged, and the total Gas usage of the first n transactions to be packaged in the sort is less than or equal to the Gas usage threshold of the current block, and the total Gas usage of the first n+1 transactions to be packaged in the sort is greater than the Gas usage threshold of the current block.

[0072] During the specific implementation process, if the Gas usage threshold of the current block is 100, and the Gas usages of the transactions to be packaged in the current order of the transactions to be packaged are 42, 40, 35, 38, 26, 28 and 19 respectively, then 42+40<100, 42+40+35>100, then the first number n is determined to be 2.

[0073] During the specific implementation process, in the step of determining the total number of transactions to be packaged in the processing queue based on the first number, if the first number is n, the total number of transactions to be packaged is 3n. Specifically, if n is 2, 3n is 6, and the total number of transactions to be packaged in the processing queue is 6.

[0074] In some embodiments of the present invention, in the step of packaging and chaining the transactions to be packaged based on the order of the processing queue by the verifier node, if the verifier node completes the packaging and chaining of any transaction to be packaged in the processing queue, the transaction to be packaged is deleted from the processing queue.

[0075] like Figure 2 As shown, in the specific implementation process, the transactions to be packaged in the processing queue are set in a preset max heap, and a mapping relationship between the transaction weights of the transactions to be packaged in the max heap and the hash table is established. After the transactions to be packaged are packaged and uploaded to the chain, the verifier node determines the completed transactions to be packaged based on the mapping relationship between the hash table and the transaction weight, and deletes the transaction from the max heap and the processing queue.

[0076] In some embodiments of the present invention, the step of determining the Gas usage of the transaction to be packaged based on the transaction category of the transaction to be packaged includes:

[0077] Acquiring a transaction category of the transaction to be estimated, and determining whether the transaction to be estimated belongs to a first-category transaction or a second-category transaction based on the transaction category;

[0078] If the transaction category is a Class I transaction, the basic Gas usage and transaction data content are obtained, and the additional Gas usage is calculated based on the number of zero bytes and non-zero bytes in the transaction data content, and the Gas usage is calculated based on the basic Gas usage and the additional Gas usage;

[0079] If the transaction category is a Class II transaction, the basic Gas usage and transaction transaction message are obtained. The transaction transaction message includes the transaction amount. The user's disposable amount is determined based on the transaction amount and the account balance of the transaction initiator. The disposable amount is used as the upper limit of the cycle, and the basic Gas usage is used as the lower limit of the cycle. The Gas usage is determined by binary search.

[0080] In some embodiments of the present invention, the transaction categories include ordinary transfer transactions, smart contract deployment transactions and smart contract call transactions, among which ordinary transfer transactions and smart contract deployment transactions belong to the first category of transactions, and smart contract call transactions belong to the second category of transactions. The transaction category of the transaction to be estimated can be pre-set by the transaction initiator.

[0081] In some embodiments of the present invention, the transaction amount is the transaction amount initiated by the transaction initiator. In the step of determining the user's disposable amount based on the transaction amount and the account balance of the transaction initiator, the difference between the account balance of the transaction initiator and the transaction amount is calculated as the disposable amount, and the disposable amount is the upper limit of the transaction fee paid by the transaction initiator. Furthermore, if the difference is less than 0, it means that the account balance is not sufficient to pay the transaction amount, the account has no disposable amount, and the transaction cannot be initiated.

[0082] In the specific implementation process, if the transaction to be estimated belongs to the second category of transactions, a binary search is used to determine the Gas usage. This scheme gradually searches for the appropriate Gas usage and gradually accurately locates the Gas usage.

[0083] In some embodiments of the present invention, the transaction category of the first type of transaction includes ordinary transfer transactions and smart contract deployment transactions;

[0084] If the transaction to be estimated belongs to an ordinary transfer transaction, then in the step of calculating the additional Gas usage based on the number of zero bytes and the number of non-zero bytes in the transaction data content, the remark data content in the transaction data content is obtained, the number of zero bytes and the number of non-zero bytes in the remark data content is calculated, the first Gas usage is calculated based on a preset zero byte unit price and the number of zero bytes in the remark data content, the second Gas usage is calculated based on the preset non-zero byte unit price and the number of non-zero bytes in the remark data content, and the additional Gas usage is calculated based on the first Gas usage and the second Gas usage;

[0085] If the transaction to be estimated belongs to a smart contract deployment transaction, the step of calculating the additional Gas usage based on the number of zero bytes and the number of non-zero bytes in the transaction data content includes: obtaining the length of the smart contract byte data in the transaction data content, and calculating the third Gas usage based on the length of the smart contract byte data; then based on the number of zero bytes and the number of non-zero bytes in the smart contract byte data in the transaction data content, calculating the fourth Gas usage based on the preset zero byte unit price and the number of zero bytes in the smart contract byte data, calculating the fifth Gas usage based on the preset non-zero byte unit price and the number of non-zero bytes in the smart contract byte data, and calculating the additional Gas usage based on the third Gas usage, the fourth Gas usage, and the fifth Gas usage;

[0086] In some embodiments of the present invention, if the transaction data content of the transaction contains a recipient address and the input field of the transaction is empty, it means that the transaction is an ordinary transfer transaction. If the transaction contains a recipient address and the length of the input field data satisfies 4 bytes or a multiple of 4 bytes plus 32 bytes, the transaction is a smart contract call transaction. Otherwise, it is an ordinary transfer transaction and carries remark data. If the transaction does not contain a recipient address, it means that the transaction is a smart contract deployment transaction.

[0087] In the specific implementation process, if the transaction to be estimated is a normal transfer transaction, and the unit price of zero bytes is 4, and the unit price of non-zero bytes is 16, the additional Gas usage is calculated according to the following formula:

[0088] Additional Gas usage = 4*number of zero bytes in the remark data content + 16*number of non-zero bytes in the remark data content.

[0089] In the specific implementation process, the sum of the basic Gas usage and the additional Gas usage of the ordinary transfer transaction is calculated as the Gas usage.

[0090] In some embodiments of the present invention, if the transaction to be estimated belongs to a smart contract deployment transaction, the step of calculating the additional Gas usage based on the number of zero bytes and the number of non-zero bytes in the transaction data content includes:

[0091] Get the length of the smart contract byte data in the transaction data content, and calculate the third Gas usage based on the length of the smart contract byte data;

[0092] Then, based on the number of zero bytes and non-zero bytes in the smart contract byte data in the transaction data content, the fourth Gas usage is calculated based on the preset zero byte unit price and the number of zero bytes in the smart contract byte data, the fifth Gas usage is calculated based on the preset non-zero byte unit price and the number of non-zero bytes in the smart contract byte data, and the additional Gas usage is calculated based on the third Gas usage, the fourth Gas usage and the fifth Gas usage.

[0093] In the specific implementation process, the Ethereum Virtual Machine (EVM) is the core of the Ethereum chain and the operating environment for executing smart contracts on the blockchain. Developers can use Ethereum's programming language to write smart contracts, deploy them to the Ethereum network, and then execute them in the Ethereum virtual machine.

[0094] During the specific implementation process, the transaction initiator selects the smart contract based on its own needs.

[0095] In some embodiments of the present invention, in the step of calculating the third Gas usage based on the length of the smart contract byte data, the length of the smart contract word is calculated based on the length of the smart contract byte data, and the third Gas usage is calculated based on the unit price of the preset word and the length of the smart contract word.

[0096] In some embodiments of the present invention, in the step of calculating the length of the smart contract word based on the length of the smart contract byte data, the length of the smart contract word is calculated based on the following formula:

[0097] wordLen=(dataLen+31)÷32;

[0098] Among them, wordLen represents the length of the smart contract word, and dataLen represents the length of the smart contract byte data;

[0099] In the step of calculating the third Gas usage based on the unit price of the preset word and the length of the smart contract word, the third Gas usage is calculated based on the following formula:

[0100] β3 = wordLen × 2;

[0101] Among them, β3 represents the third Gas usage.

[0102] In some embodiments of the present invention, in the steps of calculating the fourth Gas usage based on the preset zero byte unit price and the number of zero bytes in the smart contract byte data, calculating the fifth Gas usage based on the preset non-zero byte unit price and the number of non-zero bytes in the smart contract byte data, and calculating the additional Gas usage based on the third Gas usage, the fourth Gas usage, and the fifth Gas usage, the fourth Gas usage is calculated based on the following formula:

[0103] β4=z1*α;

[0104] The fifth Gas usage is calculated based on the following formula:

[0105] β5=zn1*γ;

[0106] Among them, β4 represents the fourth Gas usage, β5 represents the fifth Gas usage, z1 represents the number of zero bytes in the smart contract byte data, α represents the preset zero byte unit price, zn1 represents the number of non-zero bytes in the smart contract byte data, and γ represents the preset non-zero byte unit price.

[0107] With the above solution, since the transaction for deploying a smart contract needs to carry the smart contract bytecode data, and the size of the smart contract is expressed in words, the Gas usage of the words needs to be accumulated on the basis of the accumulated calculation of the zero bytes and non-zero bytes of the smart contract bytecode data. This solution can accurately estimate the Gas usage.

[0108] The transaction category of the second type of transaction includes calling smart contract transactions, taking the disposable amount as the upper limit of the cycle, taking the basic Gas usage as the lower limit of the cycle, and using binary search to determine the total Gas usage includes:

[0109] Determine whether the upper limit of the loop is greater than the sum of the lower limit of the loop and the preset interval value;

[0110] If yes, then loop, calculate the middle value of the loop upper limit and the loop lower limit, input the middle value as the test Gas usage into the virtual machine to pre-execute the transaction, and receive the execution result of the virtual machine. If the virtual machine executes successfully, then use the middle value at this time as the loop upper limit, and judge again whether the loop upper limit is greater than the loop lower limit; if the virtual machine fails to execute, then use the middle value at this time as the loop lower limit, and judge again whether the loop upper limit is greater than the sum of the loop lower limit and the preset interval value;

[0111] If not, the loop is exited and the value of the loop upper limit at this time is used as the value of the total Gas usage.

[0112] The above scheme is different from ordinary transfer transactions and smart contract deployment transactions in that, in the actual execution of transactions, calling smart contracts is also affected by the smart contract instruction set Gas pricing mechanism. Different operation instructions in the smart contract instruction set have different Gas prices. If the method of presetting the instruction set Gas cost is used to calculate the Gas usage required to execute the smart contract function, there are too many uncertain factors, such as the depth of the function call chain cannot be predicted, the termination condition of the loop logic in the function depends on dynamic variables, and some operation instructions have dynamic Gas cost overheads. Therefore, this scheme uses a custom Ethereum virtual machine to pre-execute the call smart contract transaction to obtain accurate Gas usage. Specifically, the precise Gas usage can be located by adding a transaction pre-execution function in the Ethereum virtual machine source code and using a binary search algorithm in the function to continuously modify the upper and lower limits of Gas.

[0113] In some embodiments of the present invention, if the transaction to be estimated belongs to a category of transactions, in the step of calculating the Gas usage based on the basic Gas usage and the additional Gas usage, the sum of the basic Gas usage and the additional Gas usage is calculated to obtain the Gas usage.

[0114] In the specific implementation process, this solution connects to the Ethereum network through the Ethereum virtual machine node and synchronizes block data from the network. At the same time, the Ethereum virtual machine node continuously monitors the transaction pre-execution message and returns the result after the transaction pre-execution. Furthermore, this solution deploys the Ethereum transaction fee determination service, which runs continuously on the server and continuously receives transactions with pending fees by providing an interface to the client. The basic Gas usage, zero byte unit price, non-zero byte unit price and word unit price are preset in the fee determination service.

[0115] An embodiment of the present invention also provides a blockchain transaction on-chain speed optimization system, which includes a computer device, wherein the computer device includes a processor and a memory, wherein the memory stores computer instructions, and the processor is used to execute the computer instructions stored in the memory. When the computer instructions are executed by the processor, the system implements the steps implemented by the method described above.

[0116] The embodiment of the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps implemented by the aforementioned blockchain transaction on-chain speed optimization method. The computer-readable storage medium may be a tangible storage medium, such as a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a floppy disk, a hard disk, a removable storage disk, a CD-ROM, or any other form of storage medium known in the technical field.

[0117] It should be understood by those skilled in the art that the exemplary components, systems and methods described in conjunction with the embodiments disclosed herein can be implemented in hardware, software or a combination of the two. Whether it is performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present invention are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link via a data signal carried in a carrier.

[0118] It should be clear that the present invention is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present invention.

[0119] In the present invention, features described and / or illustrated for one embodiment may be used in the same or similar manner in one or more other embodiments, and / or combined with or replace features of other embodiments.

[0120] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for optimizing the speed of blockchain transaction on-chain, characterized in that: The steps of the method include: Get the transactions to be packaged uploaded by the user; Determine a transaction waiting time based on the upload time of the transaction to be packaged, and calculate a time parameter based on the transaction waiting time of the transaction to be packaged; Determine the Gas usage of the transaction to be packaged based on the transaction category of the transaction to be packaged, and calculate the Gas parameter based on the Gas usage of the transaction to be packaged; The transaction weight of the transaction to be packaged is calculated based on the time parameter and the Gas parameter, and the transaction weight is calculated according to the following formula: Wherein, w represents the transaction weight, g' represents the Gas parameter, t' represents the time parameter, m represents the preset weight coefficient, base represents the preset transaction classification weight, and e represents the Euler number; The time parameters are calculated based on the following formula: Among them, t' represents the time parameter, t represents the transaction waiting time of the currently calculated transaction to be packaged, and t max Indicates the maximum transaction waiting time of all transactions to be packaged, t min Indicates the minimum transaction waiting time of all transactions to be packaged; The Gas parameter is calculated based on the following formula: Among them, g' represents the Gas parameter, g represents the Gas usage of the currently calculated transaction to be packaged, and g max Indicates the maximum amount of Gas used by all transactions to be packaged; A processing queue for the transactions to be packaged is constructed based on the transaction weights, and the verifier node packages the transactions to be packaged and processes them on the chain based on the order of the processing queues.

2. The method for optimizing the speed of blockchain transaction on-chain according to claim 1, characterized in that: Determine the transactions to be packaged in the pending transactions based on the selected instructions of Ethereum, determine a first quantity based on the Gas usage threshold of the current block and the Gas usage of each transaction to be packaged, and determine the total number of transactions to be packaged in the processing queue based on the first quantity.

3. The method for optimizing the speed of blockchain transaction on-chain according to claim 2, characterized in that: The first number is n. In the step of determining the first number based on the Gas usage threshold of the current block and the Gas usage of each transaction to be packaged, the transactions to be packaged are sorted based on the transaction weights of the transactions to be packaged, and the total Gas usage of the first n transactions to be packaged in the sort is less than or equal to the Gas usage threshold of the current block, and the total Gas usage of the first n+1 transactions to be packaged in the sort is greater than the Gas usage threshold of the current block.

4. The method for optimizing the speed of blockchain transaction on-chain according to claim 1, characterized in that: In the step where the verifier node packages and uploads the transactions to be packaged onto the chain based on the order of the processing queue, if the verifier node completes the packaging and uploads the transactions to be packaged onto the chain for any transaction to be packaged in the processing queue, the transaction to be packaged is deleted from the processing queue.

5. The method for optimizing the speed of blockchain transaction on-chain according to claim 1, characterized in that: The step of determining the Gas usage of the transaction to be packaged based on the transaction category of the transaction to be packaged includes: Acquiring a transaction category of the transaction to be estimated, and determining whether the transaction to be estimated belongs to a first-category transaction or a second-category transaction based on the transaction category; If the transaction category is a Class I transaction, the basic Gas usage and transaction data content are obtained, and the additional Gas usage is calculated based on the number of zero bytes and non-zero bytes in the transaction data content, and the Gas usage is calculated based on the basic Gas usage and the additional Gas usage; If the transaction category is a Class II transaction, the basic Gas usage and transaction transaction message are obtained. The transaction transaction message includes the transaction amount. The user's disposable amount is determined based on the transaction amount and the account balance of the transaction initiator. The disposable amount is used as the upper limit of the cycle, and the basic Gas usage is used as the lower limit of the cycle. The Gas usage is determined by binary search.

6. The method for optimizing the speed of blockchain transaction on-chain according to claim 5, characterized in that: The transaction categories of the first type of transactions include ordinary transfer transactions and smart contract deployment transactions; If the transaction to be estimated belongs to an ordinary transfer transaction, then in the step of calculating the additional Gas usage based on the number of zero bytes and the number of non-zero bytes in the transaction data content, the remark data content in the transaction data content is obtained, the number of zero bytes and the number of non-zero bytes in the remark data content is calculated, the first Gas usage is calculated based on a preset zero byte unit price and the number of zero bytes in the remark data content, the second Gas usage is calculated based on the preset non-zero byte unit price and the number of non-zero bytes in the remark data content, and the additional Gas usage is calculated based on the first Gas usage and the second Gas usage; If the transaction to be estimated belongs to a smart contract deployment transaction, the step of calculating the additional Gas usage based on the number of zero bytes and the number of non-zero bytes in the transaction data content includes: obtaining the length of the smart contract byte data in the transaction data content, and calculating the third Gas usage based on the length of the smart contract byte data; then based on the number of zero bytes and the number of non-zero bytes in the smart contract byte data in the transaction data content, calculating the fourth Gas usage based on the preset zero byte unit price and the number of zero bytes in the smart contract byte data, calculating the fifth Gas usage based on the preset non-zero byte unit price and the number of non-zero bytes in the smart contract byte data, and calculating the additional Gas usage based on the third Gas usage, the fourth Gas usage, and the fifth Gas usage; The transaction category of the second type of transaction includes calling smart contract transactions, taking the disposable amount as the upper limit of the cycle, taking the basic Gas usage as the lower limit of the cycle, and using binary search to determine the total Gas usage includes: Determine whether the upper limit of the loop is greater than the sum of the lower limit of the loop and the preset interval value; If yes, then loop, calculate the middle value of the loop upper limit and the loop lower limit, input the middle value as the test Gas usage into the virtual machine to pre-execute the transaction, and receive the execution result of the virtual machine. If the virtual machine executes successfully, then use the middle value at this time as the loop upper limit, and judge again whether the loop upper limit is greater than the loop lower limit; if the virtual machine fails to execute, then use the middle value at this time as the loop lower limit, and judge again whether the loop upper limit is greater than the sum of the loop lower limit and the preset interval value; If not, the loop is exited and the value of the loop upper limit at this time is used as the value of the total Gas usage.

7. A blockchain transaction on-chain speed optimization system, characterized in that: The system includes a computer device, which includes a processor and a memory. The memory stores computer instructions. The processor is used to execute the computer instructions stored in the memory. When the computer instructions are executed by the processor, the system implements the steps implemented by the method as described in any one of claims 1 to 6.