CN116957577A - Gas value estimation method, device, storage medium and equipment in transaction - Google Patents

Gas value estimation method, device, storage medium and equipment in transaction Download PDF

Info

Publication number
CN116957577A
CN116957577A CN202310924048.0A CN202310924048A CN116957577A CN 116957577 A CN116957577 A CN 116957577A CN 202310924048 A CN202310924048 A CN 202310924048A CN 116957577 A CN116957577 A CN 116957577A
Authority
CN
China
Prior art keywords
gas
transaction data
historical transaction
value
transaction
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310924048.0A
Other languages
Chinese (zh)
Inventor
张亚宁
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Rivtower Technology Co Ltd
Original Assignee
Hangzhou Rivtower Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Rivtower Technology Co Ltd filed Critical Hangzhou Rivtower Technology Co Ltd
Priority to CN202310924048.0A priority Critical patent/CN116957577A/en
Publication of CN116957577A publication Critical patent/CN116957577A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/389Keeping log of transactions for guaranteeing non-repudiation of a transaction
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/22Payment schemes or models
    • G06Q20/223Payment schemes or models based on the use of peer-to-peer networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof

Landscapes

  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Strategic Management (AREA)
  • Physics & Mathematics (AREA)
  • General Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Finance (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The application discloses a Gas value estimation method, a Gas value estimation device, a storage medium and Gas value estimation equipment in a transaction, and belongs to the technical field of blockchain. The method comprises the following steps: determining an intelligent contract corresponding to a transaction to be executed; querying contract states and contract logic of the smart contract; determining an execution path of the intelligent contract according to the contract state and the contract logic; estimating a first Gas forecast value according to an execution path and a historical transaction data set, wherein the historical transaction data set comprises at least one piece of historical transaction data, and the historical transaction data comprises a Gas value actually consumed by historical transaction and an execution path of an intelligent contract called when the historical transaction is executed; a second Gas forecast value for the transaction is calculated based on the first Gas forecast value. The method can avoid the problem that the number of transactions packed in the block is limited when the Gas value is set to be too large; the problem of transaction execution failure caused by too small Gas value setting can also be avoided.

Description

Gas value estimation method, device, storage medium and equipment in transaction
Technical Field
The present application relates to the field of blockchain technologies, and in particular, to a method, an apparatus, a storage medium, and a device for estimating Gas values in transactions.
Background
When executing a transaction in a blockchain, a Gas value needs to be set in the transaction, and the execution of the transaction is controlled by the Gas value.
When setting the Gas value, if the Gas value set by the user is too large, the number of transactions packed in the block may be limited; if the Gas value set by the user is too small, insufficient Gas value may be caused to cause failure of transaction execution.
Disclosure of Invention
The application provides a Gas value estimation method, a device, a storage medium and equipment in transaction, which are used for solving the problem that the Gas value of the transaction cannot be accurately set. The technical scheme is as follows:
in one aspect, a method for estimating Gas values in a transaction is provided, the method comprising:
determining an intelligent contract corresponding to a transaction to be executed;
querying a contract state and contract logic of the smart contract;
determining an execution path of the smart contract based on the contract state and the contract logic;
estimating a first Gas forecast value according to the execution path and a historical transaction data set, wherein the historical transaction data set comprises at least one piece of historical transaction data, and the historical transaction data comprises a Gas value actually consumed by historical transaction and an execution path of an intelligent contract called when the historical transaction is executed;
and calculating a second Gas predicted value of the transaction according to the first Gas predicted value.
In one possible implementation manner, the estimating the first Gas forecast value according to the execution path and the historical transaction data set includes:
searching historical transaction data matched with the execution path in the historical transaction data set;
when the execution paths in the searched historical transaction data are the same as the execution paths corresponding to the transactions, obtaining Gas values in the historical transaction data;
multiplying the Gas value by a safety coefficient to obtain the first Gas predicted value.
In one possible implementation manner, the execution path includes a plurality of branch paths that are sequentially executed, and after searching the historical transaction data set for the historical transaction data matching the execution path, the method further includes:
when the execution sequence of all branch paths in the searched historical transaction data is the same as that of all branch paths corresponding to the transaction, but the circulation times of the target branch paths are different, obtaining Gas values in the historical transaction data, and obtaining Gas values corresponding to the target branch paths in a single circulation;
and estimating the first Gas estimated value according to the Gas value in the historical transaction data and the Gas value corresponding to the branch path.
In one possible implementation manner, the obtaining the Gas value corresponding to the target branch path in a single cycle includes:
searching two historical transaction data with the same execution sequence of all branch paths and different circulation times of the target branch paths in the historical transaction data set;
subtracting Gas values in the two historical transaction data, and dividing the obtained Gas difference value by the cycle number difference value of the target branch path to obtain the Gas value corresponding to the target branch path in a single cycle.
In one possible implementation manner, the execution path includes a plurality of branch paths that are sequentially executed, and after searching the historical transaction data set for the historical transaction data matching the execution path, the method further includes:
when the execution paths in the searched historical transaction data are the same as the execution paths of the transaction after the preset operation, gas values in the historical transaction data are obtained;
and carrying out the preset operation on the Gas values in the plurality of pieces of historical transaction data, and determining an operation result as the first Gas predicted value.
In one possible implementation manner, a branch path marking event is arranged on a code branch of the intelligent contract, and the branch path marking event is used for recording a branch path selected when a transaction is executed;
and the code of the intelligent contract is provided with a cyclic processing marking event, and the cyclic processing marking event is used for recording the cyclic times of a single branch path when the transaction is executed.
In one possible implementation, the method further includes:
after the transaction is successfully executed, acquiring a transaction execution result from the blockchain;
obtaining the Gas value actually consumed by the transaction from the transaction execution result;
and adding the execution path of the transaction and the Gas value to the historical transaction data set correspondingly.
In one aspect, there is provided a Gas value estimation apparatus in a transaction, the apparatus comprising:
the contract determining module is used for determining intelligent contracts corresponding to transactions to be executed;
the contract inquiry module is used for inquiring the contract state and the contract logic of the intelligent contract;
a path determining module for determining an execution path of the smart contract according to the contract state and the contract logic;
the Gas value calculation module is used for estimating a first Gas estimated value according to the execution path and a historical transaction data set, wherein the historical transaction data set comprises at least one piece of historical transaction data, and the historical transaction data comprises a Gas value actually consumed by historical transaction and an execution path of an intelligent contract called when the historical transaction is executed;
the Gas value calculation module is further configured to calculate a second Gas predicted value of the transaction according to the first Gas predicted value.
In one aspect, a computer-readable storage medium having stored therein at least one instruction that is loaded and executed by a processor to implement a Gas value estimation method in a transaction as described above is provided.
In one aspect, a computer device is provided that includes a processor and a memory having at least one instruction stored therein that is loaded and executed by the processor to implement a Gas value estimation method in a transaction as described above.
The technical scheme provided by the application has the beneficial effects that at least:
by acquiring the execution path and the historical transaction data set of the intelligent contract corresponding to the transaction to be executed, the historical transaction data in the historical transaction data set comprises the Gas value actually consumed by the historical transaction and the execution path of the intelligent contract called when the historical transaction is executed, so that the first Gas predicted value can be estimated according to the execution path and the historical transaction data set, and the second Gas predicted value of the transaction is calculated according to the first Gas predicted value, thereby avoiding the problem that the number of the transactions packed in the block is limited when the Gas value is excessively set; the problem of transaction execution failure caused by too small Gas value setting can be avoided, so that the success rate of transaction execution can be improved, and the number of the transactions packaged in the block can be increased.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for estimating Gas value in a transaction according to one embodiment of the present application;
FIG. 2 is a flow chart of a method for estimating Gas value in a transaction according to another embodiment of the present application;
FIG. 3 is a block diagram illustrating a device for estimating Gas value in a transaction according to another embodiment of the present application;
fig. 4 is a block diagram of a device for estimating a Gas value in a transaction according to still another embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the following detailed description of the embodiments of the present application will be given with reference to the accompanying drawings.
When executing a transaction in a blockchain, a Gas value needs to be set in the transaction, and the execution of the transaction is controlled by the Gas value. When setting the Gas value, if the Gas value set by the user is too large, the number of transactions packed in the block may be limited; if the Gas value set by the user is too small, insufficient Gas value may be caused to cause failure of transaction execution.
When a transaction is executed by using a smart contract, since different branch paths are involved in the contract code of the smart contract and different transactions run to different branch paths in different contract states, even if the transaction is executed by the same smart contract, the actual consumed Gas value of the transaction may also be greatly different due to different contract states or different parameters when the transaction is called. Moreover, the contract code of the intelligent contract may have more complex cyclic processing events, and different cyclic times also can cause larger difference of Gas values actually consumed by transactions. Therefore, the order of the branch paths and the number of loops of the branch paths when a smart contract performs a transaction affect the Gas value actually consumed by the transaction.
In this embodiment, the plurality of branch paths form an execution path according to the execution order and the number of loops. For example, when the branch path of the smart contract executing in execution order includes A, B, C, D and there is no loop handling marker event, then the execution path may be A-B-C-D. For another example, when the branch path of the smart contract executed in execution order includes A, B, C, D and D needs to be executed 10 times in a loop, the execution path may be A-B-C- (DX 10).
After the execution path of the intelligent contract is obtained, the execution path can be utilized to estimate the Gas value of the transaction so as to improve the accuracy of Gas value estimation.
Referring to fig. 1, a flowchart of a method for estimating a Gas value in a transaction according to an embodiment of the application is shown, and the method for estimating a Gas value in a transaction can be applied to a computer device. The Gas value estimation method in the transaction can comprise the following steps:
step 101, determining an intelligent contract corresponding to a transaction to be executed.
The computer device may pre-obtain a contract address of the smart contract corresponding to the transaction and add the contract address to the transaction, such that, after the transaction is sent to the blockchain, the blockchain may invoke the smart contract deployed on the blockchain according to the contract address, and execute the transaction through the smart contract.
In this embodiment, the computer device may determine the smart contract corresponding to the transaction according to the contract address.
Step 102, querying the contract state and contract logic of the smart contract.
The computer device may determine that the smart contract provides a query interface through which to query the contract state and contract logic of the smart contract.
Step 103, determining the execution path of the intelligent contract according to the contract state and the contract logic.
The execution path comprises a plurality of branch paths which are sequentially executed and the circulation times of each branch path.
For example, when the branch path of the smart contract executing in execution order includes A, B, C, D and there is no loop handling marker event, then the execution path may be A-B-C-D. For another example, when the branch path of the smart contract executed in execution order includes A, B, C, D and D needs to be executed 10 times in a loop, the execution path may be A-B-C- (DX 10).
Step 104, estimating a first Gas forecast value according to the execution path and a historical transaction data set, wherein the historical transaction data set comprises at least one piece of historical transaction data, and the historical transaction data comprises a Gas value actually consumed by the historical transaction and an execution path of an intelligent contract called when the historical transaction is executed.
When executing a transaction in a blockchain, it is necessary to specify a Gas value in the transaction, and the execution of the transaction is controlled by the Gas value. The blockchain may record the Gas value actually consumed by each transaction after the transaction is completed.
In this embodiment, the computer device may obtain, from the blockchain, an execution path and a Gas value of the historical transaction, and generate a historical transaction data set according to the execution path and the Gas value of the historical transaction; the historical transaction data set may also be generated by the blockchain from the execution path and Gas values of the historical transaction, and the computer device obtains the historical transaction data set from the blockchain.
When generating the historical transaction data set, relevant historical transactions can be screened in executing completed historical transactions, and the execution paths of the historical transactions and the corresponding Gas values of the historical transactions are recorded into the historical transaction data set.
Wherein a time period (e.g., the last 5 days) may be set, and a historical transaction data set is generated based on historical transactions within the time period; alternatively, a historical transaction data set may be generated based on a quantity (e.g., the last 100) that is filtered from all historical transactions.
After the historical transaction data set is obtained, the computer device may search the historical transaction data set for matching historical transaction data according to the execution path of the transaction, and estimate the first Gas forecast value according to the Gas value in the searched historical transaction data, and a specific estimation algorithm is described in detail below.
Step 105, calculating a second Gas forecast value of the transaction according to the first Gas forecast value.
The computer device may multiply the first Gas estimate by the security factor to obtain a second Gas estimate, add the second Gas estimate to the transaction, and send the transaction to the blockchain, which, upon receipt of the transaction, performs the transaction based on the second Gas estimate.
Wherein the safety coefficient is a coefficient greater than 100%, so that the success rate of transaction execution can be ensured. However, considering the limitation of the Gas value of the block, the security coefficient should not be too large, so as to avoid the problem of limiting the number of transactions packed in the block when the security coefficient is too large. Specifically, the value of the security coefficient can be set according to the actual service requirement. For example, the safety factor may be set to 105%.
In summary, according to the Gas value estimation method in the transaction provided by the embodiment of the application, by acquiring the execution path and the historical transaction data set of the intelligent contract corresponding to the transaction to be executed, since the historical transaction data in the historical transaction data set comprises the Gas value actually consumed by the historical transaction and the execution path of the intelligent contract called when the historical transaction is executed, the first Gas estimated value can be estimated according to the execution path and the historical transaction data set, and the second Gas estimated value of the transaction can be calculated according to the first Gas estimated value, so that the problem that the number of packaged transactions in a block is limited when the Gas value is excessively set can be avoided; the problem of transaction execution failure caused by too small Gas value setting can be avoided, so that the success rate of transaction execution can be improved, and the number of the transactions packaged in the block can be increased.
Referring to fig. 2, a flowchart of a method for estimating a Gas value in a transaction according to an embodiment of the application is shown, and the method for estimating a Gas value in a transaction can be applied to a computer device. The Gas value estimation method in the transaction can comprise the following steps:
in step 201, a smart contract corresponding to a transaction to be executed is determined.
When writing a smart contract, we can set a branch path marking event on the code branch of the smart contract, by which the branch path selected at transaction execution is marked. When the contract code of the smart contract includes loop processing, we can set a loop processing flag event in the code of the smart contract by which the number of loops of a single branch path when a transaction is executed is recorded.
The computer device may pre-obtain a contract address of the smart contract corresponding to the transaction and add the contract address to the transaction, such that, after the transaction is sent to the blockchain, the blockchain may invoke the smart contract deployed on the blockchain according to the contract address, and execute the transaction through the smart contract.
In this embodiment, the computer device may determine the smart contract corresponding to the transaction according to the contract address.
Step 202, query the contract status and contract logic of the smart contract.
The computer device may determine that the smart contract provides a query interface through which to query the contract state and contract logic of the smart contract.
Step 203, determining an execution path of the intelligent contract according to the contract state and the contract logic.
The execution path comprises a plurality of branch paths which are sequentially executed and the circulation times of each branch path.
For example, when the branch path of the smart contract executing in execution order includes A, B, C, D and there is no loop handling marker event, then the execution path may be A-B-C-D. For another example, when the branch path of the smart contract executed in execution order includes A, B, C, D and D needs to be executed 10 times in a loop, the execution path may be A-B-C- (DX 10).
Step 204, estimating a first Gas forecast value according to the execution path and the historical transaction data set, wherein the historical transaction data set comprises at least one piece of historical transaction data, and the historical transaction data comprises the Gas value actually consumed by the historical transaction and the execution path of the intelligent contract called when the historical transaction is executed.
When executing a transaction in a blockchain, it is necessary to specify a Gas value in the transaction, and the execution of the transaction is controlled by the Gas value. The blockchain may record the Gas value actually consumed by each transaction after the transaction is completed.
In this embodiment, the computer device may obtain, from the blockchain, an execution path and a Gas value of the historical transaction, and generate a historical transaction data set according to the execution path and the Gas value of the historical transaction; the historical transaction data set may also be generated by the blockchain from the execution path and Gas values of the historical transaction, and the computer device obtains the historical transaction data set from the blockchain.
When generating the historical transaction data set, relevant historical transactions can be screened in executing completed historical transactions, and the execution paths of the historical transactions and the corresponding Gas values of the historical transactions are recorded into the historical transaction data set.
Wherein a time period (e.g., the last 5 days) may be set, and a historical transaction data set is generated based on historical transactions within the time period; alternatively, a historical transaction data set may be generated based on a quantity (e.g., the last 100) that is filtered from all historical transactions.
After the historical transaction data set is obtained, the computer equipment can search matched historical transaction data in the historical transaction data set according to the execution path of the transaction, and estimate the first Gas estimated value according to the Gas value in the searched historical transaction data.
Specifically, the computer device may search the historical transaction data set for historical transaction data matched with the execution path, and according to the search result, may divide the calculation process of the first Gas estimated value into three types:
(1) When the execution path in the searched historical transaction data is the same as the execution path of the transaction, acquiring the Gas value in the historical transaction data; the Gas value is multiplied by the safety coefficient to obtain a first Gas estimated value.
For example, the execution path of the historical transaction data is A-B-C-D, and no cycle times exist; the current transaction execution path is a-B-C-D and there is no cycle number, the computer device may determine that the execution path in the historical transaction data is the same as the transaction execution path.
For another example, the execution path of the historical transaction data is A-B- (C×3) -D, that is, the cycle number of C is 3; the current execution path of the transaction is a-B- (C x 3) -D, the computer device may determine that the execution path in the historical transaction data is the same as the execution path of the transaction.
The computer device may obtain the Gas value in the searched historical transaction data, obtain a preset safety coefficient, and multiply the Gas value by the safety coefficient to obtain a first Gas predicted value. Wherein the safety coefficient is a coefficient greater than 100%, so that the success rate of transaction execution can be ensured. However, considering the limitation of the Gas value of the block, the security coefficient should not be too large, so as to avoid the problem of limiting the number of transactions packed in the block when the security coefficient is too large. Specifically, the value of the security coefficient can be set according to the actual service requirement. For example, the safety factor may be set to 105%.
(2) When the execution sequence of all branch paths in the searched historical transaction data is the same as that of all branch paths corresponding to the transaction, but the circulation times of the target branch paths are different, obtaining Gas values in the historical transaction data, and obtaining Gas values corresponding to the target branch paths in a single circulation; and estimating a first Gas estimated value according to the Gas value in the historical transaction data and the Gas value corresponding to the branch path.
For example, the execution path of the historical transaction data is A-B- (C×10); the current transaction execution path is a-B- (C x 20), the computer device may determine that all branch paths in the historical transaction data are in the same order of execution as all branch paths corresponding to the transaction, but the number of loops of the target branch path is different.
The computer device may obtain the Gas value in the found historical transaction data, obtain the Gas value corresponding to the target branch path (C above) during a single cycle, calculate the cycle number difference between the historical transaction and the current transaction, multiply the cycle number difference by the Gas value corresponding to the target branch path, and then add the cycle number difference to the Gas value in the historical transaction data to obtain the first Gas predicted value.
For example, if the execution path of the historical transaction data is a-B- (c×10), the execution path of the current transaction is a-B- (c×20), the Gas value in the historical transaction data is a, and the Gas value corresponding to the branch path C is B, the first Gas predicted value= (20-10) ×b+a.
Specifically, the obtaining the Gas value corresponding to the target branch path during the single cycle may include: searching two historical transaction data which have the same execution sequence of all branch paths and different circulation times of the target branch paths in the historical transaction data set; subtracting the Gas values in the two historical transaction data, and dividing the obtained Gas difference value by the cycle number difference value of the target branch path to obtain the Gas value corresponding to the target branch path in a single cycle.
Assuming that the execution path of one found history transaction is a-B- (c×5) -D, the corresponding Gas value is p, and the execution path of the other history transaction is a-B- (c×10) -D, the corresponding Gas value is q, the Gas value corresponding to the target branch path c= (q-p)/5.
(3) When the execution paths in the searched historical transaction data are the same as the execution paths of the transaction after the preset operation, gas values in the historical transaction data are obtained; and carrying out preset operation on Gas values in the plurality of pieces of historical transaction data, and determining an operation result as a first Gas predicted value.
For example, the found execution path of the first historical transaction is A-B-C-D, the execution path of the second historical transaction is A-B-C-D1, the execution path of the third historical transaction is A-B-C1-D, and the execution path of the current transaction is A-B-C1-D1, and then the execution path of the first historical transaction is subtracted from the execution path of the second historical transaction plus the execution path of the third historical transaction, so that the execution path of the current transaction can be obtained.
Assuming that the Gas value in the first historical transaction data is x, the Gas value in the second historical transaction data is y, and the Gas value in the third historical transaction data is z, the first Gas predicted value=y+z-x.
Step 205, calculating a second Gas estimate for the transaction based on the first Gas estimate.
The computer device may multiply the first Gas estimate by the security factor to obtain a second Gas estimate, add the second Gas estimate to the transaction, and send the transaction to the blockchain, which, upon receipt of the transaction, performs the transaction based on the second Gas estimate.
If there is insufficient historical transaction data in the set of historical transaction data to analyze and estimate the Gas value for the current transaction, we can estimate the Gas value for the transaction in other ways.
Step 206, after the transaction execution is successful, obtaining the transaction execution result from the blockchain.
Step 207, obtaining the Gas value actually consumed by the transaction from the transaction execution result.
Step 208, adding the execution path of the transaction and the Gas value correspondence to the historical transaction data set.
The historical transaction data set may use an LRU (Least Recently Used ) queue, and the oldest data may be automatically eliminated during storage.
In summary, according to the Gas value estimation method in the transaction provided by the embodiment of the application, by acquiring the execution path and the historical transaction data set of the intelligent contract corresponding to the transaction to be executed, since the historical transaction data in the historical transaction data set comprises the Gas value actually consumed by the historical transaction and the execution path of the intelligent contract called when the historical transaction is executed, the first Gas estimated value can be estimated according to the execution path and the historical transaction data set, and the second Gas estimated value of the transaction can be calculated according to the first Gas estimated value, so that the problem that the number of packaged transactions in a block is limited when the Gas value is excessively set can be avoided; the problem of transaction execution failure caused by too small Gas value setting can be avoided, so that the success rate of transaction execution can be improved, and the number of the transactions packaged in the block can be increased.
Referring to fig. 3, a block diagram of a device for estimating a Gas value in a transaction according to an embodiment of the application is shown, where the device for estimating a Gas value in a transaction may be applied to a computer device. The Gas value estimation device in the transaction can comprise:
a contract determining module 310, configured to determine an intelligent contract corresponding to a transaction to be executed;
a contract query module 320 for querying contract states and contract logic of the smart contract;
a path determination module 330 for determining an execution path of the smart contract according to the contract status and the contract logic;
the Gas value calculation module 340 is configured to estimate a first Gas estimate value according to an execution path and a historical transaction data set, where the historical transaction data set includes at least one piece of historical transaction data, and the historical transaction data includes a Gas value actually consumed by a historical transaction and an execution path of an intelligent contract invoked when the historical transaction is executed;
the Gas value calculation module 340 is further configured to calculate a second Gas estimate for the transaction according to the first Gas estimate.
In an alternative embodiment, the Gas value calculation module 340 is further configured to:
searching historical transaction data matched with the execution path in the historical transaction data set;
when the execution paths in the searched historical transaction data are the same as the execution paths corresponding to the transactions, gas values in the historical transaction data are obtained;
the Gas value is multiplied by the safety coefficient to obtain a first Gas estimated value.
In an alternative embodiment, the execution path includes a plurality of branch paths that are sequentially executed, and the Gas value calculation module 340 is further configured to:
when the execution sequence of all branch paths in the searched historical transaction data is the same as that of all branch paths in the transaction, but the circulation times of the target branch paths are different, obtaining Gas values in the historical transaction data, and obtaining Gas values corresponding to the target branch paths in a single circulation;
and estimating a first Gas estimated value according to the Gas value in the historical transaction data and the Gas value corresponding to the branch path.
In an alternative embodiment, the Gas value calculation module 340 is further configured to:
searching two historical transaction data which have the same execution sequence of all branch paths and different circulation times of the target branch paths in the historical transaction data set;
subtracting the Gas values in the two historical transaction data, and dividing the obtained Gas difference value by the cycle number difference value of the target branch path to obtain the Gas value corresponding to the target branch path in a single cycle.
In an alternative embodiment, the execution path includes a plurality of branch paths that are sequentially executed, and the Gas value calculation module 340 is further configured to:
when the execution paths in the searched historical transaction data are the same as the execution paths of the transaction after the preset operation, gas values in the historical transaction data are obtained;
and carrying out preset operation on Gas values in the plurality of pieces of historical transaction data, and determining an operation result as a first Gas predicted value.
In an alternative embodiment, the code branches of the intelligent contract are provided with branch path marking events, and the branch path marking events are used for recording the branch paths selected when the transaction is executed;
the code of the intelligent contract is provided with a circulation processing marking event, and the circulation processing marking event is used for recording the circulation times of a single branch path when the transaction is executed.
In an alternative embodiment, as shown in fig. 4, the apparatus further comprises:
the result obtaining module 350 is configured to obtain a transaction execution result from the blockchain after the transaction execution is successful;
a Gas value obtaining module 360, configured to obtain a Gas value actually consumed by the transaction from a transaction execution result;
the data adding module 370 is configured to add the execution path of the transaction and the Gas value to the historical transaction data set.
In summary, by acquiring the execution path of the intelligent contract and the historical transaction data set corresponding to the transaction to be executed, the device for estimating the Gas value in the transaction provided by the embodiment of the application can estimate the first Gas estimated value according to the execution path and the historical transaction data set, and calculate the second Gas estimated value of the transaction according to the first Gas estimated value, so that the problem that the number of packaged transactions in a block is limited when the Gas value is excessively set can be avoided; the problem of transaction execution failure caused by too small Gas value setting can be avoided, so that the success rate of transaction execution can be improved, and the number of the transactions packaged in the block can be increased.
One embodiment of the present application provides a computer-readable storage medium having stored therein at least one instruction that is loaded and executed by a processor to implement a Gas value estimation method in a transaction as described above.
One embodiment of the present application provides a computer device including a processor and a memory having at least one instruction stored therein, the instruction being loaded and executed by the processor to implement a Gas value estimation method in a transaction as described above.
It should be noted that: the Gas value estimation device in the transaction provided in the above embodiment only uses the division of the above functional modules to illustrate when the Gas value estimation device in the transaction is performed, in practical application, the above functions may be allocated to different functional modules according to needs, that is, the internal structure of the Gas value estimation device in the transaction is divided into different functional modules, so as to complete all or part of the functions described above. In addition, the device for estimating the Gas value in the transaction provided in the above embodiment and the method embodiment for estimating the Gas value in the transaction belong to the same concept, and the detailed implementation process of the device is referred to the method embodiment and will not be described herein.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program for instructing relevant hardware, where the program may be stored in a computer readable storage medium, and the storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description should not be taken as limiting the embodiments of the application, but rather should be construed to cover all modifications, equivalents, improvements, etc. that may fall within the spirit and principles of the embodiments of the application.

Claims (10)

1. A method for predicting Gas values in a transaction, the method comprising:
determining an intelligent contract corresponding to a transaction to be executed;
querying a contract state and contract logic of the smart contract;
determining an execution path of the smart contract based on the contract state and the contract logic;
estimating a first Gas forecast value according to the execution path and a historical transaction data set, wherein the historical transaction data set comprises at least one piece of historical transaction data, and the historical transaction data comprises a Gas value actually consumed by historical transaction and an execution path of an intelligent contract called when the historical transaction is executed;
and calculating a second Gas predicted value of the transaction according to the first Gas predicted value.
2. The method of claim 1, wherein estimating the first Gas estimate based on the execution path and the historical transaction data set comprises:
searching historical transaction data matched with the execution path in the historical transaction data set;
when the execution paths in the searched historical transaction data are the same as the execution paths corresponding to the transactions, obtaining Gas values in the historical transaction data;
multiplying the Gas value by a safety coefficient to obtain the first Gas predicted value.
3. The method of claim 2, wherein the execution path includes a plurality of branch paths that are executed sequentially, the method further comprising, after searching the historical transaction data set for historical transaction data that matches the execution path:
when the execution sequence of all branch paths in the searched historical transaction data is the same as that of all branch paths corresponding to the transaction, but the circulation times of the target branch paths are different, obtaining Gas values in the historical transaction data, and obtaining Gas values corresponding to the target branch paths in a single circulation;
and estimating the first Gas estimated value according to the Gas value in the historical transaction data and the Gas value corresponding to the branch path.
4. The method for estimating a Gas value in a transaction according to claim 3, wherein the obtaining the Gas value corresponding to the target branch path in a single cycle includes:
searching two historical transaction data with the same execution sequence of all branch paths and different circulation times of the target branch paths in the historical transaction data set;
subtracting Gas values in the two historical transaction data, and dividing the obtained Gas difference value by the cycle number difference value of the target branch path to obtain the Gas value corresponding to the target branch path in a single cycle.
5. The method of claim 1, wherein the execution path includes a plurality of branch paths that are executed sequentially, and wherein after searching the historical transaction data set for historical transaction data that matches the execution path, the method further comprises:
when the execution paths in the searched historical transaction data are the same as the execution paths of the transaction after the preset operation, gas values in the historical transaction data are obtained;
and carrying out the preset operation on the Gas values in the plurality of pieces of historical transaction data, and determining an operation result as the first Gas predicted value.
6. The method of claim 1, wherein,
a branch path marking event is arranged on a code branch of the intelligent contract and is used for recording a branch path selected when the transaction is executed;
and the code of the intelligent contract is provided with a cyclic processing marking event, and the cyclic processing marking event is used for recording the cyclic times of a single branch path when the transaction is executed.
7. The method for estimating a Gas value in a transaction according to any one of claims 1 to 6, further comprising:
after the transaction is successfully executed, acquiring a transaction execution result from the blockchain;
obtaining the Gas value actually consumed by the transaction from the transaction execution result;
and adding the execution path of the transaction and the Gas value to the historical transaction data set correspondingly.
8. A Gas value estimation device in a transaction, the device comprising:
the contract determining module is used for determining intelligent contracts corresponding to transactions to be executed;
the contract inquiry module is used for inquiring the contract state and the contract logic of the intelligent contract;
a path determining module for determining an execution path of the smart contract according to the contract state and the contract logic;
the Gas value calculation module is used for estimating a first Gas estimated value according to the execution path and a historical transaction data set, wherein the historical transaction data set comprises at least one piece of historical transaction data, and the historical transaction data comprises a Gas value actually consumed by historical transaction and an execution path of an intelligent contract called when the historical transaction is executed;
the Gas value calculation module is further configured to calculate a second Gas predicted value of the transaction according to the first Gas predicted value.
9. A computer readable storage medium having stored therein at least one instruction that is loaded and executed by a processor to implement the method of Gas value estimation in a transaction according to any one of claims 1 to 7.
10. A computer device comprising a processor and a memory, the memory having stored therein at least one instruction that is loaded and executed by the processor to implement the method of Gas value estimation in a transaction according to any one of claims 1 to 7.
CN202310924048.0A 2023-07-26 2023-07-26 Gas value estimation method, device, storage medium and equipment in transaction Pending CN116957577A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310924048.0A CN116957577A (en) 2023-07-26 2023-07-26 Gas value estimation method, device, storage medium and equipment in transaction

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310924048.0A CN116957577A (en) 2023-07-26 2023-07-26 Gas value estimation method, device, storage medium and equipment in transaction

Publications (1)

Publication Number Publication Date
CN116957577A true CN116957577A (en) 2023-10-27

Family

ID=88450866

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310924048.0A Pending CN116957577A (en) 2023-07-26 2023-07-26 Gas value estimation method, device, storage medium and equipment in transaction

Country Status (1)

Country Link
CN (1) CN116957577A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117574320A (en) * 2024-01-15 2024-02-20 腾讯科技(深圳)有限公司 Data processing method, device, computer readable medium and electronic equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117574320A (en) * 2024-01-15 2024-02-20 腾讯科技(深圳)有限公司 Data processing method, device, computer readable medium and electronic equipment
CN117574320B (en) * 2024-01-15 2024-04-26 腾讯科技(深圳)有限公司 Data processing method, device, computer readable medium and electronic equipment

Similar Documents

Publication Publication Date Title
CA2428235A1 (en) System and method for building a time series model
KR102097953B1 (en) Failure risk index estimation device and failure risk index estimation method
CN109634819B (en) Alarm root cause positioning method and device and electronic equipment
CN116957577A (en) Gas value estimation method, device, storage medium and equipment in transaction
CN113268334A (en) Scheduling method, device, equipment and storage medium of RPA robot
CN116126346A (en) Code compiling method and device of AI model, computer equipment and storage medium
CN113535481B (en) Data backtracking method and device and non-volatile computer readable storage medium
US11734063B2 (en) Job management based on generated execution time prediction model and prediction accuracy
CN108509440A (en) A kind of data processing method and device
CN111694835B (en) Number section access method, system, equipment and storage medium of logistics electronic bill
CN109815118A (en) Data base management method and device, electronic equipment and computer readable storage medium
CN115858648A (en) Database generation method, data stream segmentation method, device, equipment and medium
CN115220404A (en) Intelligent diagnosis method, device, equipment and storage medium for processing equipment
CN115577491A (en) Parameter correction method and device, electronic equipment and storage medium
CN115599793A (en) Method, device and storage medium for updating data
Mohagheghi et al. Prioritizing methods to accelerate probabilistic model checking of discrete-time Markov models
CN115129432A (en) Transaction processing method and device, electronic equipment and medium
JP5650290B1 (en) Operational risk measurement method and apparatus
CN111767522A (en) Recursive algorithm implementation method and device and electronic equipment
CN116185940B (en) Atomic counter operation method, device, equipment and storage medium
CN117195568B (en) Simulation engine performance analysis method and device based on discrete event
CN117273115B (en) Static generation method, device, equipment and medium of reverse calculation graph
CN114092221A (en) Data processing method, device, equipment and computer storage medium
CN111913805B (en) CPU utilization rate calculation method and device
CN116521351B (en) Multithreading task scheduling method and device, storage medium and processor

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination