CN110555773B - Contract conflict detection method and device, readable storage medium and computer equipment - Google Patents

Contract conflict detection method and device, readable storage medium and computer equipment Download PDF

Info

Publication number
CN110555773B
CN110555773B CN201910853885.2A CN201910853885A CN110555773B CN 110555773 B CN110555773 B CN 110555773B CN 201910853885 A CN201910853885 A CN 201910853885A CN 110555773 B CN110555773 B CN 110555773B
Authority
CN
China
Prior art keywords
transaction
cache
processed
contract
current
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.)
Active
Application number
CN201910853885.2A
Other languages
Chinese (zh)
Other versions
CN110555773A (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201910853885.2A priority Critical patent/CN110555773B/en
Publication of CN110555773A publication Critical patent/CN110555773A/en
Application granted granted Critical
Publication of CN110555773B publication Critical patent/CN110555773B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • 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
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Abstract

The application relates to a contract conflict detection method, a contract conflict detection device, a computer readable storage medium and computer equipment, wherein the method comprises the following steps: the method comprises the steps of obtaining at least one intelligent contract method corresponding to a transaction to be processed, obtaining contract byte codes corresponding to the intelligent contract methods, obtaining preset detection contract byte codes, determining the intelligent contract methods without conflict from the intelligent contract methods according to the contract byte codes and the preset detection contract byte codes to obtain target intelligent contract methods, taking the corresponding transactions to be processed as target transactions to be processed, executing the target intelligent contract methods in parallel to obtain corresponding execution results, obtaining transaction sequences, combining the execution results with historical combined execution results in sequence according to the transaction sequences, and obtaining contract conflict results when intersection exists between the execution results to be combined corresponding to the current target transactions to be processed and the historical combined execution results. The scheme provided by the application can improve the diversity of contract conflict detection.

Description

Contract conflict detection method and device, readable storage medium and computer equipment
The application is a divisional application with the name of 'contract conflict detection method, device, readable storage medium and computer equipment', which is filed by the Chinese patent office at 09.08.2019 and has the application number of 2019107363437, and the whole content of the divisional application is incorporated into the application by reference.
Technical Field
The present application relates to the field of computer technologies, and in particular, to a contract conflict detection method and apparatus, a computer-readable storage medium, and a computer device.
Background
As computer technology has evolved, intelligent contracts are closely related to blockchains, an intelligent contract being a computer protocol intended to propagate, validate or execute contracts in an informational manner. Smart contracts allow trusted transactions to be conducted without third parties, which transactions are traceable and irreversible. However, the intelligent contract conflict detection in the current block chain must detect whether a conflict exists before the intelligent contract is executed, and cannot detect whether a conflict exists in the intelligent contracts corresponding to the respective transactions to be processed when the intelligent contracts are executed in parallel, and the detection mode is relatively single.
Disclosure of Invention
In view of the above, it is necessary to provide a contract conflict detection method, apparatus, computer-readable storage medium, and computer device capable of improving the diversity of contract conflict detections.
A contract conflict detection method, the method comprising:
receiving a transaction request, the transaction request including at least one pending transaction;
acquiring an intelligent contract method corresponding to each transaction to be processed according to the transaction request;
creating a block cache corresponding to a target block, and creating an initial transaction cache corresponding to each transaction to be processed;
executing corresponding intelligent contract methods in parallel in the initial transaction cache corresponding to each transaction to be processed to obtain an updated transaction cache corresponding to each transaction to be processed;
acquiring a transaction sequence of each transaction to be processed, and combining updated transaction caches corresponding to the transactions to be processed into a block cache according to the transaction sequence;
and obtaining a contract conflict result when the intersection exists between the transaction cache to be merged and updated corresponding to the current transaction to be processed and the historical merged transaction cache data in the block cache.
A contract conflict detection apparatus, the apparatus comprising:
the transaction request receiving module is used for receiving a transaction request, and the transaction request comprises at least one transaction to be processed;
the intelligent contract method acquisition module is used for acquiring the intelligent contract methods corresponding to the transactions to be processed according to the transaction requests;
the cache region creating module is used for creating a block cache corresponding to the target block and creating an initial transaction cache corresponding to each transaction to be processed;
the intelligent contract method execution module is used for executing the corresponding intelligent contract methods in parallel in the initial transaction cache corresponding to each transaction to be processed to obtain the updated transaction cache corresponding to each transaction to be processed;
the transaction result merging module is used for acquiring the transaction sequence of each transaction to be processed and sequentially merging the updated transaction cache corresponding to each transaction to be processed into the block cache according to the transaction sequence;
and the contract conflict result generation module is used for obtaining a contract conflict result when the transaction cache to be merged and updated corresponding to the current transaction to be processed is intersected with the historical merged transaction cache data in the block cache.
A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the program:
receiving a transaction request, the transaction request including at least one pending transaction;
acquiring an intelligent contract method corresponding to each transaction to be processed according to the transaction request;
creating a block cache corresponding to a target block, and creating an initial transaction cache corresponding to each transaction to be processed;
executing corresponding intelligent contract methods in parallel in the initial transaction cache corresponding to each transaction to be processed to obtain an updated transaction cache corresponding to each transaction to be processed;
acquiring a transaction sequence of each transaction to be processed, and combining updated transaction caches corresponding to the transactions to be processed into a block cache according to the transaction sequence;
and obtaining a contract conflict result when the intersection exists between the transaction cache to be merged and updated corresponding to the current transaction to be processed and the historical merged transaction cache data in the block cache.
A computer-readable storage medium having stored thereon a computer program which, when executed by a processor, causes the processor to perform the steps of:
receiving a transaction request, the transaction request including at least one pending transaction;
acquiring an intelligent contract method corresponding to each transaction to be processed according to the transaction request;
creating a block cache corresponding to a target block, and creating an initial transaction cache corresponding to each transaction to be processed;
executing corresponding intelligent contract methods in parallel in the initial transaction cache corresponding to each transaction to be processed to obtain an updated transaction cache corresponding to each transaction to be processed;
acquiring a transaction sequence of each transaction to be processed, and combining updated transaction caches corresponding to the transactions to be processed into a block cache according to the transaction sequence;
and obtaining a contract conflict result when the intersection exists between the transaction cache to be merged and updated corresponding to the current transaction to be processed and the historical merged transaction cache data in the block cache.
The contract conflict detection method, the contract conflict detection device, the computer-readable storage medium and the computer equipment acquire a corresponding intelligent contract method for at least one to-be-processed transaction through a transaction request, establish a block cache corresponding to a target block, then establish an initial transaction cache corresponding to each to-be-processed transaction, execute a corresponding intelligent contract method in parallel in the initial transaction cache corresponding to each to-be-processed transaction to obtain an updated transaction cache corresponding to each to-be-processed transaction, acquire a transaction sequence of each to-be-processed transaction, sequentially merge the updated transaction caches corresponding to each to-be-processed transaction to the block cache according to the transaction sequence, and acquire a contract conflict result when intersection exists between the updated transaction cache corresponding to the current to-be-processed transaction to be merged and historical merged transaction cache data in the block cache.
Therefore, when the intelligent contract methods corresponding to the transactions to be processed are parallel, whether the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the historical transaction to be processed is detected through whether the intersection exists between the transaction cache to be merged and updated corresponding to the current transaction to be processed and the historical merged transaction cache data in the block cache. Whether conflicts exist or not is detected without detecting before the intelligent contract method is executed, whether conflicts exist or not is detected in the process that the intelligent contract methods corresponding to the transactions to be processed are executed in parallel, and the diversity of contract conflict detection is improved. And further, whether contract conflict exists is detected in real time, the contract conflict is detected conveniently, if a problem occurs, the contract conflict can be timely repaired and is easy to maintain, and the comprehensiveness and accuracy of the contract conflict detection are improved.
Drawings
FIG. 1 is a diagram of an application environment for a contract conflict detection method in one embodiment;
FIG. 2 is a schematic flow chart diagram illustrating a contract conflict detection methodology in one embodiment;
FIG. 3 is a schematic diagram of a block cache and an initial transaction cache, in one embodiment;
FIG. 4 is a flowchart illustrating steps performed by the intelligent contract method in one embodiment;
FIG. 5 is a flow diagram illustrating the merge step of updating the transaction cache into the block cache in one embodiment;
FIG. 5A is a diagram illustrating merging of transaction results from updating a transaction cache into a block cache, according to an embodiment;
FIG. 6 is a flowchart illustrating the contract conflict result generation step in one embodiment;
FIG. 6A is a diagram that illustrates intelligent contract method conflict detection, in one embodiment;
FIG. 7 is a flowchart illustrating the steps of determining whether there is an intersection between the current update write cache and the historical merged transaction cache data in one embodiment;
FIG. 8 is a diagram of intelligent contract method conflict detection in another embodiment;
FIG. 9 is a flowchart illustrating the steps of determining whether there is an intersection between the current update read cache and the historical merged transaction cache data in one embodiment;
FIG. 9A is a schematic diagram illustrating an embodiment of a step of determining whether there is an intersection between a current update read cache and historical merged transaction cache data;
FIG. 10 is a schematic flow chart diagram illustrating a contract conflict detection methodology in accordance with another embodiment;
FIG. 11 is a block diagram of a contract conflict detection apparatus in one embodiment;
FIG. 12 is a block diagram that illustrates the structure of the intelligent contract method execution module in one embodiment;
FIG. 13 is a block diagram illustrating the structure of a transaction result merge module in one embodiment;
FIG. 14 is a block diagram showing a configuration of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
FIG. 1 is a diagram of an application environment of a contract conflict detection method in one embodiment. Referring to fig. 1, the contract conflict detection method is applied to a contract conflict detection system. The contract conflict detection system includes a terminal 110 and a server 120. The terminal 110 and the server 120 are connected through a network. The terminal 110 may specifically be a desktop terminal or a mobile terminal, and the mobile terminal may specifically be at least one of a mobile phone, a tablet computer, a notebook computer, and the like. The server 120 may be implemented as a stand-alone server or as a server cluster of at least one server. The server 120 is a node, and a complete block chain is stored in the node, where the block chain includes at least one block.
Specifically, the terminal 110 sends at least one pending transaction to the server 120 via a transaction request. The server 120 receives the transaction request, acquires the intelligent contract method corresponding to each transaction to be processed according to the transaction request, creates a block cache corresponding to a target block, creates an initial transaction cache corresponding to each transaction to be processed, executes the corresponding intelligent contract method in parallel in the initial transaction cache corresponding to each transaction to be processed, acquires an updated transaction cache corresponding to each transaction to be processed, acquires the transaction sequence of each transaction to be processed, sequentially merges the updated transaction caches corresponding to each transaction to be processed into the block cache according to the transaction sequence, and acquires a contract conflict result when the updated transaction caches corresponding to the current transaction to be processed intersect with the historical merged transaction cache data in the block cache.
As shown in FIG. 2, in one embodiment, a contract conflict detection method is provided. The contract conflict detection method may be performed by a computer device, which may be at least one of a server or a terminal. The embodiment is mainly illustrated by applying the method to the server 120 in fig. 1. Referring to fig. 2, the contract conflict detection method specifically includes the following steps:
at step 202, a transaction request is received, the transaction request including at least one pending transaction.
The transaction request is used for requesting to process the transaction to be processed, the transaction request is usually sent to the server by the terminal, and the server can process the corresponding transaction to be processed according to the transaction request after receiving the transaction request. The transaction request comprises at least one transaction to be processed, and the transaction to be processed is a transaction waiting to be processed. The to-be-processed transaction has the corresponding intelligent contract method, the to-be-processed transaction with the corresponding intelligent contract method can create the corresponding initial transaction cache, and the to-be-processed transaction without the corresponding intelligent contract method does not need to create the corresponding initial transaction cache.
Specifically, the terminal can trigger and generate a transaction request through a related application or control, carry transaction information corresponding to at least one transaction to be processed into the transaction request, and send the transaction information to the server through the network.
And 204, acquiring the intelligent contract method corresponding to each transaction to be processed according to the transaction request.
The intelligent contract is closely related to a block chain, the block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like, the block chain is essentially a decentralized database, the block chain is used as a bottom layer technology of the bitcoin, the blockchain is a series of data blocks which are produced by being related by a cryptography method, and each data block contains information of a batch of bitcoin network transactions and is used for verifying the validity (anti-counterfeiting) of the information and generating the next block. While smart contracts are a significant reason why blockchains are referred to as "decentralized," they allow for the execution of traceable, irreversible, and secure transactions without the need for third parties.
The intelligent contract is a computer protocol used in the block chain technology, contains all information of at least one transaction to be processed, and executes result operation only after meeting the requirement. The intelligent contract comprises at least one variable and a corresponding contract method, wherein the intelligent contract method refers to a contract method in the intelligent contract.
Specifically, after receiving the transaction request, the server obtains the intelligent contract method corresponding to each transaction to be processed according to the transaction request. Specifically, the corresponding variable is determined according to each transaction to be processed, the corresponding contract method is determined according to the variable, and the contract method corresponding to the variable is used as the intelligent contract method corresponding to the corresponding transaction to be processed.
And step 206, creating a block cache corresponding to the target block, and creating an initial transaction cache corresponding to each transaction to be processed.
The target block is used to create a block cache, and the target block may be determined from the chunks, for example, the target block may be a latest chunk, where the latest chunk refers to a highest-level chunk of the chunks stored by the server. The block cache is used for caching the transaction results corresponding to the to-be-processed transactions, and the initial transaction cache is used for caching the transaction results generated by executing the corresponding intelligent contract method on the to-be-processed transactions. When each transaction to be processed executes the corresponding intelligent contract method, the changes brought by the intelligent contract method are cached in the corresponding initial transaction cache, and the transaction results generated by the intelligent contract method corresponding to the execution of each transaction to be processed can be merged into the block cache. That is, the block cache temporarily stores the transaction results corresponding to all the transactions to be processed.
Specifically, the block cache may be created for a latest block based on the contract cache, where the latest block refers to a block with a highest degree among blocks stored by the server, and after the block cache is created, a corresponding initial transaction cache may be created for each to-be-processed transaction based on the block cache. The contract cache is used for storing the intelligent contract methods corresponding to the to-be-processed transactions, and after the to-be-processed transactions acquire the corresponding intelligent contract methods from the database, the acquired intelligent contract methods are uniformly put into the contract cache for storage. The contract cache comprises a contract read cache and a contract write cache, wherein the contract read cache is used for recording the read access condition of the intelligent contract method, and the contract write cache is used for recording the write access condition of the intelligent contract method.
In one embodiment, a read cache and a write cache corresponding to a block cache are created for the latest block based on the contract cache, and then a read cache and a write cache corresponding to an initial transaction cache are created for each transaction to be processed based on the read cache and the write cache of the block cache. The method comprises the steps that corresponding intelligent contract methods are respectively executed on a read cache and a write cache corresponding to an initial transaction cache of a transaction to be processed, a transaction result corresponding to the read cache of the initial transaction cache and a transaction result corresponding to the write cache of the initial transaction cache are respectively obtained, finally, the transaction results corresponding to the read cache of the initial transaction cache are merged into the read cache corresponding to a block cache, and the transaction results corresponding to the write cache of the initial transaction cache are merged into the write cache corresponding to the block cache.
And 208, executing the corresponding intelligent contract method in parallel in the initial transaction cache corresponding to each transaction to be processed to obtain the updated transaction cache corresponding to each transaction to be processed.
Specifically, after the block cache and the initial transaction caches corresponding to the respective transactions to be processed are created, the initial transaction caches are used for recording transaction information generated in the process of executing the intelligent contract method for the transactions to be processed, so that the corresponding intelligent contract method is executed in the initial transaction caches corresponding to the respective transactions to be processed, and the updated transaction caches corresponding to the respective transactions to be processed are obtained. That is, the intelligent contract is a set of commitments defined in a digital form, and after the intelligent contract method corresponding to each transaction to be processed is obtained, each transaction to be processed needs to be executed according to a protocol specified by the corresponding intelligent contract method, so that a transaction result corresponding to each transaction to be processed is obtained, the initial transaction cache is updated according to the transaction result, that is, the transaction result is stored in the updated transaction cache. The transaction result is that each transaction to be processed executes the corresponding intelligent contract method in the corresponding transaction cache, and the change result brought by the intelligent contract method can be used as the corresponding transaction result.
The intelligent contract method is executed in parallel, namely, the intelligent contract method is directly executed in parallel in the corresponding initial transaction cache by each transaction to be processed regardless of the transaction sequence of each transaction to be processed.
And step 210, acquiring the transaction sequence of each transaction to be processed, and combining the updated transaction caches corresponding to the transactions to be processed into the block cache according to the transaction sequence.
The transactions to be processed are arranged in sequence when being packed into the target block, and the transaction sequence corresponding to each transaction to be processed can be directly obtained without arranging the sequence. And when the to-be-processed transactions are not packed to the target block, determining the transaction sequence according to the transaction time of each to-be-processed transaction time, wherein the transaction time refers to the transaction time point corresponding to each to-be-processed transaction. The transaction sequence refers to a transaction sequence among the transactions to be processed, and the transaction sequence corresponding to each transaction to be processed can be determined according to the transaction time corresponding to each transaction to be processed. Specifically, the transaction sequence corresponding to each transaction to be processed can be directly obtained according to the transaction request.
Further, the updated transaction caches corresponding to the respective transactions to be processed are sequentially merged into the block cache according to the transaction sequence corresponding to the respective transactions to be processed, that is, after completion of the merging, the block cache includes the transaction results corresponding to all the transactions to be processed, that is, the block cache includes the transaction results corresponding to the respective transactions to be processed in the updated transaction cache.
In one embodiment, the block cache comprises a corresponding read cache and a corresponding write cache, the initial transaction cache corresponding to each transaction to be processed comprises a read cache and a write cache, and each transaction to be processed executes a corresponding intelligent contract method in the read cache and the write cache corresponding to the corresponding initial transaction cache to respectively obtain a transaction result corresponding to the read cache of the initial transaction cache and a transaction result corresponding to the write cache of the initial transaction cache, and then the initial transaction cache is updated according to the transaction result to obtain an updated transaction cache.
And finally, acquiring a transaction sequence among the transactions to be processed, sequentially merging the transaction results corresponding to the read cache of the initial transaction cache corresponding to the transactions to be processed into the read cache corresponding to the block cache according to the transaction sequence, merging the transaction results corresponding to the write cache of the initial transaction cache into the write cache corresponding to the block cache, namely sequentially merging the updated transaction caches corresponding to the transactions to be processed into the block caches according to the transaction sequence.
Step 212, when the intersection exists between the transaction cache to be merged and updated corresponding to the current transaction to be processed and the historical merged transaction cache data in the block cache, a contract conflict result is obtained.
In the merging process of sequentially merging the transaction results corresponding to the transactions to be processed into the block cache according to the transaction sequence, conflicts between the intelligent contract methods may exist, and the contract conflict result means that conflicts exist between the intelligent contract method corresponding to the current transaction to be processed and the intelligent contract method corresponding to the processed transaction in the merging process.
Wherein the transaction cache to be merged and updated temporarily stores the current transaction to be processed corresponding to the current transaction to be processed, the current pending transaction refers to the current pending transaction being processed, and the pending merged updated transaction cache where the current transaction result corresponding to the current pending transaction is obtained may be specifically the updated transaction cache corresponding to the current pending transaction is used as the pending merged updated transaction cache, since the updated transaction cache corresponding to each pending transaction temporarily holds the corresponding transaction result, the merging of the updated transaction cache into the block cache means that the transaction results corresponding to each transaction to be processed are merged into the block cache, and the transaction to be processed successfully merged into the block cache is updated into a processed transaction, that is, all transaction results of the processed transaction corresponding to the current transaction to be processed, that is, the merged transaction cache data, are temporarily stored in the block cache. The processed transaction refers to a processed transaction in which the update transaction cache corresponding to the transaction to be processed is successfully merged into the block cache after updating, that is, the corresponding update transaction cache is successfully merged into the block cache.
Specifically, a current updated transaction cache corresponding to a current transaction to be processed is obtained, the current updated transaction cache is used as an updated transaction cache to be merged, historical merged transaction cache data temporarily stored in a block cache is obtained, and when an intersection exists between the updated transaction cache to be merged and the historical merged transaction cache data in the block cache, a contract conflict result is obtained, namely, in the merging process, a conflict exists between an intelligent contract method corresponding to the current transaction to be processed and an intelligent contract method corresponding to the processed transaction. Otherwise, when the intersection of the transaction cache to be merged and updated and the historical merged transaction cache data in the block cache does not exist, determining that no conflict exists between the intelligent contract method corresponding to the current transaction to be processed and the intelligent contract method corresponding to the processed transaction.
When the intelligent contract method corresponding to the current to-be-processed transaction and the intelligent contract method corresponding to the processed transaction conflict, the current to-be-processed transaction and the processed transaction cannot be in parallel, and otherwise, when the intelligent contract method corresponding to the current to-be-processed transaction and the intelligent contract method corresponding to the processed transaction do not conflict, the current to-be-processed transaction and the processed transaction can be in parallel.
The contract conflict detection method comprises the steps of obtaining a corresponding intelligent contract method for at least one to-be-processed transaction through a transaction request, obtaining an updated transaction cache corresponding to each to-be-processed transaction by creating a block cache corresponding to a target block, then creating an initial transaction cache corresponding to each to-be-processed transaction, executing the corresponding intelligent contract method in parallel in the initial transaction cache corresponding to each to-be-processed transaction, obtaining a transaction sequence of each to-be-processed transaction, combining the updated transaction caches corresponding to the to-be-processed transactions to the block caches in sequence according to the transaction sequence, and obtaining a contract conflict result when the updated transaction caches corresponding to the current to-be-processed transactions to be combined intersect with historical combined transaction cache data in the block caches.
Therefore, when the intelligent contract methods corresponding to the transactions to be processed are parallel, whether the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the historical transaction to be processed is detected through whether the intersection exists between the transaction cache to be merged and updated corresponding to the current transaction to be processed and the historical merged transaction cache data in the block cache. Whether conflicts exist or not is detected without detecting before the intelligent contract method is executed, whether conflicts exist or not is detected in the process that the intelligent contract methods corresponding to the transactions to be processed are executed in parallel, and the diversity of contract conflict detection is improved. And further, whether contract conflict exists is detected in real time, the contract conflict is detected conveniently, if a problem occurs, the contract conflict can be timely repaired and is easy to maintain, and the comprehensiveness and accuracy of the contract conflict detection are improved.
In one embodiment, creating a block cache corresponding to the target block, and creating an initial transaction cache corresponding to each transaction to be processed includes: and acquiring a target block, establishing a corresponding block read cache and a corresponding block write cache for the target block based on the contract cache, and establishing a corresponding initial transaction read cache and an initial transaction write cache for each transaction to be processed based on the block read cache and the block write cache.
The contract cache is used for storing the intelligent contract methods corresponding to the to-be-processed transactions, and after the to-be-processed transactions acquire the corresponding intelligent contract methods from the database, the acquired intelligent contract methods are uniformly placed into the contract cache for storage. The block cache is used for caching the transaction results corresponding to the to-be-processed transactions, and the initial transaction cache is used for caching the transaction information generated by executing the corresponding intelligent contract method for each to-be-processed transaction. When each transaction to be processed executes the corresponding intelligent contract method, the changes brought by the intelligent contract method are cached in the corresponding initial transaction cache, so that the updated transaction cache is obtained, and the transaction results generated when each transaction to be processed executes the corresponding intelligent contract method can be merged into the block cache. That is, the block cache temporarily stores the transaction results corresponding to all the transactions to be processed.
Specifically, a block read cache and a block write cache corresponding to the block cache are created for the latest block based on the contract cache, and then an initial transaction read cache and an initial transaction write cache corresponding to the initial transaction cache are created for each transaction to be processed based on the block read cache and the block write cache. The method comprises the steps that corresponding intelligent contract methods are respectively executed on an initial transaction read cache and an initial transaction write cache corresponding to an initial transaction cache of a transaction to be processed, a transaction result corresponding to the initial transaction read cache of the initial transaction cache and a transaction result corresponding to the initial transaction write cache of the initial transaction cache are respectively obtained, the initial transaction read cache is updated according to the transaction result corresponding to the initial transaction read cache, an updated transaction read cache is obtained, and the initial transaction write cache is updated according to the transaction result corresponding to the initial transaction write cache to obtain an updated transaction write cache.
And finally, merging the transaction results corresponding to the updated transaction read cache of the updated transaction cache into the block read cache corresponding to the block cache, and merging the transaction results corresponding to the updated transaction write cache of the updated transaction cache into the block write cache corresponding to the block cache.
In an embodiment, as shown in fig. 3, fig. 3 is a schematic diagram of a block cache and an initial transaction cache in an embodiment, specifically, the server obtains a latest block, and creates a block read cache and a block write cache corresponding to the block cache for the latest block based on a contract cache, that is, the block cache includes the block read cache and the block write cache. Further, a corresponding initial transaction read cache and an initial transaction write cache are created for each transaction to be processed based on the block read cache and the block write cache, that is, each transaction to be processed has a corresponding initial transaction read cache and an initial transaction write cache.
In an embodiment, as shown in fig. 4, executing a corresponding intelligent contract method in parallel in an initial transaction cache corresponding to each transaction to be processed to obtain an updated transaction cache corresponding to each transaction to be processed includes:
step 402, executing a corresponding intelligent contract method in the initial transaction read cache corresponding to each transaction to be processed to obtain an updated transaction read cache corresponding to each transaction to be processed.
Step 404, executing a corresponding intelligent contract method in the initial transaction write cache corresponding to each transaction to be processed, and obtaining an updated transaction write cache corresponding to each transaction to be processed.
The updating transaction cache corresponding to each transaction to be processed comprises an updating transaction read cache and an updating transaction write cache, the updating transaction read cache is used for recording the read access condition of the transaction to be processed, the updating transaction write cache is used for recording the write access condition of the transaction to be processed, and each transaction to be processed can execute a corresponding intelligent contract method in the initial transaction cache so as to obtain the updating transaction cache.
Specifically, the corresponding intelligent contract method is executed in the transaction read cache corresponding to each transaction to be processed, changes caused by the intelligent contract method are all stored in the transaction read cache, a transaction read cache result corresponding to each transaction to be processed is obtained, and the transaction read cache result is stored in the updated transaction read cache. Similarly, executing the corresponding intelligent contract method in the transaction write cache corresponding to each transaction to be processed to obtain the transaction write cache result corresponding to each transaction to be processed, and storing the transaction write cache result in the updated transaction write cache. That is, both the transaction read cache and the transaction write cache are used to execute the corresponding execution contract and temporarily store the corresponding execution result.
In an embodiment, as shown in fig. 5, acquiring a transaction sequence of each to-be-processed transaction, and sequentially merging the updated transaction caches corresponding to each to-be-processed transaction into the block cache according to the transaction sequence includes:
step 502, obtaining a transaction sequence corresponding to each transaction to be processed.
The transactions to be processed are arranged in sequence when being packed into the target block, and the transaction sequence corresponding to each transaction to be processed can be directly obtained without arranging the sequence. And when the to-be-processed transactions are not packed to the target block, determining the transaction sequence according to the transaction time of each to-be-processed transaction time, wherein the transaction time refers to the transaction time point corresponding to each to-be-processed transaction. Specifically, the server (node) directly obtains the transaction sequence corresponding to each transaction to be processed.
And step 504, sequentially merging the updated transaction write cache corresponding to each transaction to be processed into the block write cache according to the transaction sequence.
Specifically, after the transaction sequence corresponding to each transaction to be processed is obtained, the updated transaction write cache corresponding to each transaction to be processed is sequentially merged into the block write cache. Namely, the transaction write cache result of the transaction write cache is submitted to the block write cache, namely the block write cache is the union of the transaction write cache results corresponding to all the transactions to be processed.
Whether conflicts exist among the intelligent contract methods corresponding to the transactions to be processed or not is identified by submitting the updated transaction write cache to the block write cache, and the explanations can be specifically given through the following embodiments, which are not repeated herein.
In the execution process of the intelligent contract method corresponding to each transaction to be processed, the data read from the database or the contract cache is stored in the block read cache.
In one embodiment, as shown in FIG. 5A, FIG. 5A illustrates a schematic diagram of updating the transaction results in a transaction cache to merge into a block cache in one embodiment. FIG. 5A shows a transaction 1 read cache, a transaction 1 write cache, and a transaction 2 read cache, a transaction 2 write cache. Specifically, transaction 1 read cache is submitted to block read cache and transaction 1 write cache is submitted to block write cache according to transaction sequence. And then submitting the transaction 2 read cache to the block read cache and submitting the transaction 2 write cache to the block write cache.
In one embodiment, as shown in fig. 6, the obtaining of the contract conflict result when the to-be-merged updated transaction cache corresponding to the current to-be-processed transaction intersects with the historical merged transaction cache data in the block cache includes:
step 602, when the transaction cache to be merged is the current update transaction write cache, obtaining historical merged transaction cache data in the block write cache, where the historical merged transaction cache data is the update transaction write cache corresponding to the processed transaction, and the update transaction cache corresponding to the transaction to be processed is merged into the block cache and then updated to the processed transaction.
The transaction cache to be merged and updated may be a current transaction write cache result or a current transaction read cache result, the transaction cache to be updated includes a transaction read cache to be updated and a transaction write cache to be updated, the current transaction write cache result is obtained by executing a corresponding intelligent contract method in the current transaction write cache to be processed, the current transaction read cache is obtained by executing a corresponding intelligent contract method in the current transaction read cache to be processed, the block cache includes a block read cache and a block write cache, the transaction read cache corresponding to each transaction to be processed is merged into the block read cache, and the transaction write cache corresponding to each transaction to be processed is merged into the block write cache.
Here, the update transaction cache to be merged may be a write cache of the current update transaction, or may be a read cache of the current update transaction. Specifically, when the transaction cache to be merged is the current update transaction write cache, it is described that the current update transaction write cache obtained by executing the corresponding intelligent contract method on the update transaction write cache for the current transaction to be processed is used as the transaction cache to be merged. And acquiring historical merged transaction cache data in the block write cache, wherein the historical merged transaction cache data is an updated transaction write cache corresponding to the processed transaction, and the updated transaction cache corresponding to the transaction to be processed is merged into the block cache and then updated into the processed transaction.
Wherein no conflict exists between the processed transactions corresponding to the historical merged transaction cache data in the block cache. That is, if there is a conflict for the pending transaction, the transaction write cache result will not be committed to the block write cache, and thus there is no conflict between the processed transactions in the block write cache.
Step 604, when the intersection exists between the current updated transaction write cache and at least one historical merged transaction cache data, it is determined that the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the processed transaction.
Specifically, when the intersection exists between the current updated transaction write cache and at least one history merged transaction cache data, it is indicated that the current to-be-processed transaction and the processed transaction are both changed in the same storage slot, so that in the execution process of the actual intelligent contract method, the current to-be-processed transaction must wait for the completion of the transactions corresponding to all the processed transactions before starting, that is, the current to-be-processed transaction and the processed transaction cannot be parallel, and it is determined that the intelligent contract method corresponding to the current to-be-processed transaction and the intelligent contract method corresponding to the processed transaction conflict.
In one embodiment, as shown in FIG. 6A, FIG. 6A illustrates a schematic diagram of intelligent contract method conflict detection in one embodiment. Fig. 6A shows a block write cache and a current transaction write cache result corresponding to a current transaction to be processed, where the current transaction to be processed is transaction 4, and the block write cache includes transaction write cache results corresponding to transactions 1, 2, and 3, and forms a historical transaction write cache result set in the block write cache. As shown in fig. 6A, if there is an intersection between the current transaction write cache result corresponding to the current transaction to be processed and at least one historical transaction write cache result in the block write cache, it is determined that there is a conflict between the intelligent contract method corresponding to the current transaction to be processed and the intelligent contract method corresponding to the processed transaction, that is, the current transaction to be processed must wait for the completion of all transactions corresponding to the processed transaction before the transaction can be started.
In one embodiment, as shown in FIG. 7, when there is an intersection between the current updated transaction write cache and at least one historical merged transaction cache data, the method includes:
step 702, obtaining a current transaction write key value pair corresponding to a current updated transaction write cache, where the current transaction write key value pair includes a current key and a corresponding current value.
Step 704, obtaining historical transaction write key value pairs corresponding to historical merged transaction cache data, where the historical transaction write key value pairs include historical keys and corresponding historical values.
The current updated transaction write cache temporarily stores the current transaction write cache result, which may be a key-value pair (key-value) string, which is often used in development, and each key is followed by a corresponding value, and when the corresponding key is pressed, the corresponding result is output. Therefore, whether conflicts exist between intelligent contract methods can be detected by updating the key-value pairs corresponding to the transaction write cache.
Specifically, a current transaction write key value pair corresponding to a current transaction write cache result in a current updated transaction write cache is obtained, the current transaction write key value pair comprises a current key and a corresponding current value, and a historical transaction write key value pair corresponding to historical merged transaction cache data is obtained at the same time, and the historical transaction write key value pair comprises a historical key and a corresponding historical value.
And step 706, when at least one target history key identical to the current key exists in each history key, determining that the intersection exists between the current updated transaction write cache and at least one history merged transaction cache data.
Specifically, a target history key which is the same as the current key is obtained from each history key, which indicates that the current transaction to be processed and the processed transaction are changed by the same storage slot, so that the current transaction to be processed can be started only after the transactions corresponding to all the processed transactions are completed in the execution process of the actual intelligent contract method, namely the current transaction to be processed and the processed transaction can not be parallel, and the intersection of the current updated transaction write cache and at least one history merged transaction cache data is determined.
In one embodiment, as shown in fig. 6A, the block write cache in fig. 6A includes a historical transaction write cache result corresponding to the processed transaction, such as the transaction write cache result of transaction 1: 1 is 1, the 1 on the left of the equal sign represents key, the 1 on the right of the equal sign represents value, and the transaction write cache result of transaction 2: 2 is equal to 2 and the transaction writing cache result 3 of the transaction 3 is equal to 3, and the current transaction to be processed is the transaction writing cache result corresponding to the transaction 4: if the key in the transaction write cache result of transaction 4 is 3 and the key in the historical transaction write cache result in the block cache is 3, it is determined that there is a conflict between the current transaction to be processed and the previous processed transaction, and the transaction can be started after the completion of all the transactions corresponding to the previous processed transaction.
In one embodiment, as shown in fig. 8, on the basis of fig. 6, when there is an intersection between the to-be-merged updated transaction cache corresponding to the current to-be-processed transaction and the historical merged transaction cache data in the block cache, obtaining a contract conflict result includes:
step 802, obtaining a current update transaction read cache corresponding to the current transaction to be processed, and using the current update transaction read cache as a to-be-merged update transaction cache.
Step 804, when the intersection exists between the current updated transaction read cache and at least one history merged transaction cache data, it is determined that the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the processed transaction.
The current updating transaction read cache comprises a result obtained by executing a corresponding intelligent contract method on the current transaction to be processed in the corresponding updating transaction read cache, historical merged transaction cache data is an updating transaction write cache result corresponding to all processed transactions in the block cache, and the updating transaction write cache result is obtained by executing the corresponding intelligent contract on the corresponding updating transaction write cache on the processed transactions.
Wherein, the processed transaction refers to all transactions to be processed whose transaction sequence is before the current transaction to be processed. There is no conflict between pending transactions corresponding to historical merged transaction cache data in the block cache. That is, if there is a conflict in the pending transaction, the transaction write cache result will not be committed to the block write cache, so there is no conflict between the forward pending transactions in the block write cache.
Specifically, a current update transaction read cache corresponding to the current transaction to be processed is obtained, the current update transaction read cache comprises a cache obtained by executing a corresponding intelligent contract method in the corresponding update transaction read cache for the current transaction to be processed, the current update transaction read cache is used as a to-be-merged update transaction cache, and when an intersection exists between the current update transaction read cache and at least one historical merged transaction cache data, it is determined that the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the processed transaction.
In one embodiment, as shown in FIG. 9, when there is an intersection between the current updated transaction read cache and at least one historical merged transaction cache data, it includes:
step 902, obtaining a current transaction key-reading value pair corresponding to a current updated transaction read cache, where the current transaction key-reading value pair includes a current key and a corresponding current value.
Step 904, obtaining historical transaction write key value pairs corresponding to historical merged transaction cache data, the historical transaction write key value pairs including historical keys and corresponding historical values.
The current updated transaction read cache temporarily stores the current transaction read cache result, where the transaction read cache result may be a key value pair, where a key value pair (value) character string is frequently used in development, each key is followed by a corresponding value, and when the corresponding key is pressed, the corresponding result is output. Therefore, whether conflicts exist between intelligent contract methods can be detected by updating the corresponding key-value pairs of the transaction read cache.
Specifically, a current transaction key-reading value pair corresponding to a current transaction read cache result in a current updated transaction read cache is obtained, the current transaction key-reading value pair comprises a current key and a corresponding current value, and a historical transaction key-writing value pair corresponding to historical merged transaction cache data is obtained at the same time, and the historical transaction key-writing value pair comprises a historical key and a corresponding historical value.
Step 906, when at least one target history key identical to the current key exists in each history key, determining that an intersection exists between the current updated transaction read cache and at least one history merged transaction cache data.
Specifically, when at least one target history key identical to the current key exists in each history key, it is indicated that under the parallel condition of the intelligent contract method corresponding to each transaction to be processed, values of the target history keys in different servers may have different conditions, and in order to maintain consistency among the servers, it is considered that the current transaction to be processed reads old data in a unified and pessimistic manner, that is, the current transaction to be processed must start after the transactions corresponding to all the processed transactions are completed, so that the current transaction to be processed and the processed transactions cannot be parallel, and it is determined that an intersection exists between the current updated transaction read cache and at least one history merged transaction cache data.
In one embodiment, as shown in fig. 9A, the block write cache in fig. 9A includes a historical transaction write cache result corresponding to the processed transaction, such as the transaction write cache result of transaction 1: 1 is 1, the 1 on the left of the equal sign represents key, the 1 on the right of the equal sign represents value, and the transaction write cache result of transaction 2: 2-2 and transaction write cache result 3-3 of transaction 3, and the transaction read cache result corresponding to the current transaction 3 to be processed: 3 is 0,4 is 4, so it can be seen that there is a target history key which is the same as the history key in the block cache in the transaction read cache result of transaction 4, i.e. key is 3, so whether the value corresponding to key is 3 is the same or not, it can be determined that the current transaction to be processed conflicts with the previous processed transaction, and it is necessary to wait for the completion of the transactions corresponding to all the previous processed transactions before starting.
In one embodiment, as shown in fig. 10, before obtaining the contract conflict result, the method further includes:
step 1002, receiving a contract deployment request, and obtaining contract bytecode corresponding to an intelligent contract method corresponding to each transaction to be processed according to the contract deployment request.
The contract deployment request is used for requesting to scan contract byte codes corresponding to the intelligent contract methods, and the contract byte codes refer to codes corresponding to the intelligent contract methods. Whether conflicts exist among the intelligent contract methods or not is detected, and the conflicts can be detected through contract byte codes corresponding to the intelligent contract methods.
Specifically, the terminal may send a contract deployment request to the server, and after receiving the contract deployment request, the server obtains, according to the contract deployment request, contract bytecode corresponding to an intelligent contract method corresponding to each transaction to be processed, and specifically, may scan, by using a contract virtual machine, the intelligent contract method corresponding to each transaction to be processed, so as to obtain the contract bytecode corresponding to the intelligent contract method corresponding to each transaction to be processed.
And 1004, acquiring a preset detection contract byte code, wherein the preset detection contract byte code is at least one of a pre-coding byte code and a custom contract byte code corresponding to the pre-coding contract.
Step 1006, when the contract bytecode matches the preset detection contract bytecode, determining that a conflict exists between the intelligent contract methods corresponding to the contract bytecode.
The preset contract byte code can be preset and used for detecting whether the contract byte code corresponding to the intelligent contract method has a conflict standard. The preset detection contract byte code is at least one of a pre-coding byte code corresponding to a pre-coding contract and a self-defined contract byte code, wherein the pre-coding contract refers to calling an external intelligent contract method, therefore, when the preset detection contract byte code is the pre-coding byte code corresponding to the pre-coding contract, the intelligent contract method corresponding to the scanned contract byte code is considered to possibly call the external intelligent contract method, and because a calling chain is possibly crossed, the analysis difficulty is high, and the intelligent contract method is determined to have conflict.
The self-defined contract byte code is used for detecting whether the intelligent contract method conflicts or not according to actual service needs or actual application scenes in a self-defined mode, and the self-defined contract byte code can also be used as a preset detection contract byte code.
Specifically, when the contract bytecode matches with the preset detection contract bytecode, it is determined that the intelligent contract method corresponding to the contract bytecode has conflict. Specifically, when a contract bytecode identical to a preset detection contract bytecode exists in the contract bytecode, it may be determined that a conflict exists in the intelligent contract method corresponding to the contract bytecode. Or, acquiring a function or an action corresponding to the preset detection contract bytecode, and determining that the intelligent contract method corresponding to the contract bytecode has a conflict when the contract bytecode has a contract bytecode the same as or similar to the preset detection contract bytecode in function or action.
In a specific embodiment, a contract conflict detection method is provided, which specifically includes the following steps:
1. a transaction request is received, the transaction request including at least one pending transaction.
2. And acquiring the intelligent contract method corresponding to each transaction to be processed according to the transaction request.
3. And creating a block cache corresponding to the target block, and creating an initial transaction cache corresponding to each transaction to be processed.
And 3-1, acquiring a target block, and establishing a corresponding block read cache and a corresponding block write cache for the target block based on contract cache.
And 3-2, establishing an initial transaction read cache and an initial transaction write cache corresponding to each transaction to be processed based on the block read cache and the block write cache.
4. And executing the corresponding intelligent contract method in parallel in the initial transaction cache corresponding to each transaction to be processed to obtain the updated transaction cache corresponding to each transaction to be processed.
4-1, executing a corresponding intelligent contract method in the initial transaction read cache corresponding to each transaction to be processed to obtain an updated transaction read cache corresponding to each transaction to be processed.
And 4-2, executing a corresponding intelligent contract method in the initial transaction write cache corresponding to each transaction to be processed to obtain an updated transaction write cache corresponding to each transaction to be processed.
5. And acquiring the transaction sequence of each transaction to be processed, and combining the updated transaction caches corresponding to the transactions to be processed into the block cache according to the transaction sequence.
And 5-1, acquiring a transaction sequence corresponding to each transaction to be processed.
And 5-2, sequentially merging the updated transaction write cache corresponding to each transaction to be processed into the block write cache according to the transaction sequence.
6. And obtaining a contract conflict result when the intersection exists between the transaction cache to be merged and updated corresponding to the current transaction to be processed and the historical merged transaction cache data in the block cache.
6-1, when the transaction cache to be merged and updated is the current transaction write cache, obtaining historical merged transaction cache data in the block write cache, wherein the historical merged transaction cache data is the updated transaction write cache corresponding to the processed transaction, the updated transaction cache corresponding to the processed transaction is merged into the block cache and then updated to the processed transaction, and when the intersection exists between the current updated transaction write cache and at least one piece of historical merged transaction cache data, determining that the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the processed transaction.
6-1-1, obtaining a current transaction write key value pair corresponding to the current updated transaction write cache, wherein the current transaction write key value pair comprises a current key and a corresponding current value.
6-1-2, obtaining historical transaction write key value pairs corresponding to historical merged transaction cache data, wherein the historical transaction write key value pairs comprise historical keys and corresponding historical values.
6-1-3, when at least one target history key identical to the current key exists in each history key, determining that the intersection exists between the current updated transaction write cache and at least one history merged transaction cache data.
And 6-2, acquiring a current updated transaction read cache corresponding to the current transaction to be processed, taking the current updated transaction read cache as a to-be-merged updated transaction cache, and determining that the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the processed transaction when intersection exists between the current updated transaction read cache and at least one history merged transaction cache data.
And 6-2-1, acquiring a current transaction key reading value pair corresponding to the current updated transaction read cache, wherein the current transaction key reading value pair comprises a current key and a corresponding current value.
6-2-2, obtaining historical transaction write key value pairs corresponding to historical merged transaction cache data, wherein the historical transaction write key value pairs comprise historical keys and corresponding historical values.
6-2-3, when at least one target history key which is the same as the current key exists in each history key, determining that the intersection exists between the current updated transaction read cache and at least one history merged transaction cache data.
7. And receiving a contract deployment request, and acquiring contract byte codes corresponding to the intelligent contract methods corresponding to the to-be-processed transactions according to the contract deployment request.
8. And acquiring a preset detection contract byte code, wherein the preset detection contract byte code is at least one of a pre-coding byte code and a self-defined contract byte code corresponding to the pre-coding contract.
9. And when the contract byte code is matched with the preset detection contract byte code, determining that the intelligent contract method corresponding to the contract byte code conflicts.
It should be understood that, although the steps in the above-described flowcharts are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in the above-described flowcharts may include multiple sub-steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of performing the sub-steps or the stages is not necessarily sequential, but may be performed alternately or alternatingly with other steps or at least a portion of the sub-steps or stages of other steps.
In one embodiment, as shown in FIG. 11, there is provided a contract conflict detection apparatus 1100, comprising:
a transaction request receiving module 1102 configured to receive a transaction request, where the transaction request includes at least one pending transaction.
And the intelligent contract method acquisition module 1104 is used for acquiring the intelligent contract methods corresponding to the to-be-processed transactions according to the transaction requests.
A cache region creating module 1106, configured to create a block cache corresponding to the target block, and create an initial transaction cache corresponding to each to-be-processed transaction.
The intelligent contract method execution module 1108 is configured to execute the corresponding intelligent contract method in parallel in the initial transaction cache corresponding to each to-be-processed transaction, so as to obtain an updated transaction cache corresponding to each to-be-processed transaction.
The transaction result merging module 1110 is configured to obtain a transaction sequence of each to-be-processed transaction, and sequentially merge the updated transaction caches corresponding to the to-be-processed transactions into the block cache according to the transaction sequence.
A contract conflict result generating module 1112, configured to obtain a contract conflict result when the to-be-merged updated transaction cache corresponding to the current to-be-processed transaction intersects with the historical merged transaction cache data in the block cache.
In one embodiment, the cache region creating module 1106 is further configured to obtain a target block, create a corresponding block read cache and a corresponding block write cache for the target block based on the contract cache, and create a corresponding initial transaction read cache and an initial transaction write cache for each to-be-processed transaction based on the block read cache and the block write cache.
In one embodiment, as shown in FIG. 12, the intelligent contract method execution module 1108 includes:
the transaction read cache execution unit 1108a is configured to execute a corresponding intelligent contract method in the initial transaction read cache corresponding to each to-be-processed transaction, so as to obtain an updated transaction read cache corresponding to each to-be-processed transaction.
The transaction write cache execution unit 1108b is configured to execute a corresponding intelligent contract method in the initial transaction write cache corresponding to each to-be-processed transaction, so as to obtain an updated transaction write cache corresponding to each to-be-processed transaction.
In one embodiment, as shown in FIG. 13, the transaction result merging module 1110 includes:
the transaction sequence determining unit 1110a is configured to obtain a transaction sequence corresponding to each transaction to be processed.
And the transaction write cache result merging unit 1110b is configured to sequentially merge the updated transaction write caches corresponding to the to-be-processed transactions into the block write cache according to the transaction sequence.
In one embodiment, the current transaction result is a current updated transaction write cache or a current updated transaction read cache, the initial transaction cache includes an initial transaction read cache and an initial transaction write cache, the current updated transaction write cache is obtained by the current pending transaction executing a corresponding intelligent contract method in the current initial transaction write cache, the current updated transaction read cache is obtained by the current pending transaction executing a corresponding intelligent contract method in the current initial transaction read cache, the block cache includes a block read cache and a block write cache, the contract conflict result generation module 1112 is further configured to obtain historical merged transaction cache data in the block write cache when the pending merged transaction cache is the current updated transaction write cache, the historical merged transaction cache data is an updated transaction write cache corresponding to the processed transaction, the updated transaction cache corresponding to the pending transaction is merged into the block cache and then updated into the processed transaction, and when the intersection exists between the current updated transaction write cache and at least one history merged transaction cache data, determining that the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the processed transaction.
In one embodiment, the contract conflict result generating module 1112 is further configured to obtain a current transaction write key-value pair corresponding to the current updated transaction write cache, where the current transaction write key-value pair includes a current key and a corresponding current value, obtain a historical transaction write key-value pair corresponding to the historical merged transaction cache data, where the historical transaction write key-value pair includes a historical key and a corresponding historical value, and determine that the current updated transaction write cache intersects with at least one historical merged transaction cache data when at least one target historical key identical to the current key exists in each historical key.
In one embodiment, the contract conflict result generating module 1112 is further configured to obtain a current updated transaction read cache corresponding to the current pending transaction, use the current updated transaction read cache as a pending merged updated transaction cache, and determine that an intelligent contract method corresponding to the current pending transaction conflicts with an intelligent contract method corresponding to the processed transaction when an intersection exists between the current updated transaction read cache and at least one historical merged transaction cache data.
In one embodiment, the contract conflict result generating module 1112 is further configured to obtain a current transaction read key value pair corresponding to the current updated transaction read cache, where the current transaction read key value pair includes a current key and a corresponding current value, obtain a historical transaction write key value pair corresponding to the historical merged transaction cache data, where the historical transaction write key value pair includes a historical key and a corresponding historical value, and determine that the current updated transaction read cache intersects with at least one historical merged transaction cache data when at least one target historical key identical to the current key exists in each historical key.
In one embodiment, the contract conflict detection apparatus 1100 is further configured to receive a contract deployment request, obtain a contract bytecode corresponding to an intelligent contract method corresponding to each transaction to be processed according to the contract deployment request, obtain a preset detection contract bytecode, where the preset detection contract bytecode is at least one of a pre-coding bytecode corresponding to a pre-coding contract and a custom contract bytecode, and determine that there is a conflict in the intelligent contract method corresponding to the contract bytecode when the contract bytecode matches the preset detection contract bytecode.
FIG. 14 is a diagram illustrating an internal structure of a computer device in one embodiment. The computer device may specifically be the server 120 in fig. 1. As shown in fig. 14, the computer apparatus includes a processor, a memory, a network interface, and an input device connected via a system bus. Wherein the memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program that, when executed by the processor, causes the processor to implement the contract conflict detection method. The internal memory may also have stored therein a computer program that, when executed by the processor, causes the processor to perform a contract conflict detection method. The input device of the computer equipment can be a touch layer covered on a display screen, a key, a track ball or a touch pad arranged on a shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 14 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, the contract conflict detection apparatus provided herein may be implemented in the form of a computer program that is executable on a computer device such as that shown in fig. 14. The memory of the computer device may store various program modules constituting the contract conflict detection apparatus, such as a transaction request receiving module, an intelligent contract method obtaining module, a cache region creating module, an intelligent contract method executing module, a transaction result merging module, and a contract conflict result generating module shown in fig. 11. The computer program constituted by the respective program modules causes the processor to execute the steps in the contract conflict detection method of the embodiments of the present application described in the present specification.
For example, the computer device shown in fig. 14 may perform receiving a transaction request including at least one pending transaction via a transaction request receiving module in a contract conflict detection apparatus as shown in fig. 11. The computer equipment can execute the intelligent contract method corresponding to each transaction to be processed according to the transaction request through the intelligent contract method acquisition module. The computer equipment can execute the block cache corresponding to the created target block through the cache region creating module, and create initial transaction caches corresponding to various to-be-processed transactions. The computer equipment can execute the corresponding intelligent contract method in parallel in the initial transaction cache corresponding to each transaction to be processed through the intelligent contract method execution module to obtain the updated transaction cache corresponding to each transaction to be processed. The computer equipment can execute and acquire the transaction sequence of each transaction to be processed through the transaction result merging module, and sequentially merge the updated transaction caches corresponding to the transactions to be processed into the block cache according to the transaction sequence. The computer equipment can execute the contract conflict result by the contract conflict result generating module when the transaction cache to be merged and updated corresponding to the current transaction to be processed is intersected with the historical merged transaction cache data in the block cache, and the contract conflict result is obtained.
In one embodiment, a computer device is provided, comprising a memory and a processor, the memory storing a computer program which, when executed by the processor, causes the processor to perform the steps of the contract conflict detection method described above. The steps of the contract conflict detection method herein may be steps in the contract conflict detection methods of the various embodiments described above.
In one embodiment, a computer readable storage medium is provided, storing a computer program that, when executed by a processor, causes the processor to perform the steps of the contract conflict detection method described above. The steps of the contract conflict detection method herein may be steps in the contract conflict detection methods of the various embodiments described above.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a non-volatile computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the program is executed. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present application. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (15)

1. A contract conflict detection method, comprising:
acquiring an intelligent contract method corresponding to at least one transaction to be processed;
executing each intelligent contract method in parallel to obtain an execution result corresponding to each transaction to be processed; the execution result is a transaction result;
acquiring a transaction sequence of each transaction to be processed, and sequentially combining an execution result corresponding to each transaction to be processed with a historical combined execution result according to the transaction sequence;
when intersection exists between the execution result to be merged corresponding to the current target transaction to be processed and the historical merged execution result, obtaining a first contract conflict result;
acquiring contract byte codes corresponding to the intelligent contract methods corresponding to the transactions to be processed;
acquiring a preset detection contract byte code, and determining that the intelligent contract method corresponding to the contract byte code conflicts when the contract byte code is matched with the preset detection contract byte code to obtain a second contract conflict result;
and obtaining a target contract conflict result according to the first contract conflict result and the second contract conflict result.
2. The method of claim 1, wherein prior to performing each intelligent contract method in parallel to obtain a corresponding execution result for each pending transaction, comprising:
acquiring a target block, and establishing a corresponding block read cache and a corresponding block write cache for the target block based on contract cache;
and establishing a corresponding initial transaction read cache and an initial transaction write cache for each transaction to be processed based on the block read cache and the block write cache.
3. The method of claim 2, wherein executing each intelligent contract method in parallel to obtain an execution result corresponding to each pending transaction comprises:
executing a corresponding intelligent contract method in the initial transaction read cache corresponding to each transaction to be processed to obtain an updated transaction read cache corresponding to each transaction to be processed;
and executing a corresponding intelligent contract method in the initial transaction write cache corresponding to each transaction to be processed to obtain an updated transaction write cache corresponding to each transaction to be processed.
4. The method according to claim 3, wherein the obtaining a transaction sequence of each of the transactions to be processed, and sequentially combining an execution result corresponding to each of the transactions to be processed with a historical combined execution result according to the transaction sequence comprises:
acquiring a transaction sequence corresponding to each transaction to be processed;
and sequentially merging the updated transaction write cache corresponding to each transaction to be processed into the block write cache according to the transaction sequence.
5. The method according to claim 2, wherein the execution result to be merged is a current update transaction write cache or a current update transaction read cache, the current update transaction write cache is obtained by the current transaction to be processed executing the corresponding intelligent contract method in a current initial transaction write cache, and the current update transaction read cache is obtained by the current transaction to be processed executing the corresponding intelligent contract method in a current initial transaction read cache;
when the to-be-merged execution result corresponding to the current to-be-processed transaction and the historical merged execution result have intersection, obtaining a first contract conflict result, including:
when the execution result to be merged is the current update transaction write cache, obtaining historical merged transaction cache data in the block write cache, wherein the historical merged transaction cache data is the update transaction write cache corresponding to the processed transaction, and the update transaction cache corresponding to the processed transaction is updated into the processed transaction after merging;
and when the intersection exists between the current updated transaction write cache and at least one history merged transaction cache data, determining that the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the processed transaction.
6. The method of claim 5, wherein when the current updated transaction write cache intersects at least one of the historical merged transaction cache data, comprising:
acquiring a current transaction write key value pair corresponding to the current updated transaction write cache, wherein the current transaction write key value pair comprises a current key and a corresponding current value;
acquiring historical transaction write key value pairs corresponding to the historical merged transaction cache data, wherein the historical transaction write key value pairs comprise historical keys and corresponding historical values;
and when at least one target history key which is the same as the current key exists in each history key, determining that the intersection exists between the current updated transaction write cache and at least one history merged transaction cache data.
7. The method of claim 5, further comprising:
acquiring a current updating transaction read cache corresponding to the current transaction to be processed, and taking the current updating transaction read cache as the execution result to be merged;
and when the intersection exists between the current updated transaction read cache and at least one history merged transaction cache data, determining that the intelligent contract method corresponding to the current transaction to be processed conflicts with the intelligent contract method corresponding to the processed transaction.
8. The method of claim 7, wherein when the current updated transactional read cache intersects at least one of the historical merged transactional cache data, comprising:
acquiring a current transaction key reading value pair corresponding to the current updated transaction read cache, wherein the current transaction key reading value pair comprises a current key and a corresponding current value;
acquiring historical transaction write key value pairs corresponding to the historical merged transaction cache data, wherein the historical transaction write key value pairs comprise historical keys and corresponding historical values;
and when at least one target history key which is the same as the current key exists in each history key, determining that the intersection exists between the current updated transaction read cache and at least one history merged transaction cache data.
9. The method of claim 1, wherein the predetermined detection contract bytecode is at least one of a pre-coding bytecode and a custom contract bytecode corresponding to a pre-coding contract.
10. A contract conflict detection apparatus, the apparatus comprising:
the intelligent contract method acquisition module is used for acquiring at least one intelligent contract method corresponding to the transaction to be processed;
the intelligent contract method execution module is used for executing corresponding intelligent contract methods in parallel to obtain execution results corresponding to the to-be-processed transactions; the execution result is a transaction result;
the transaction result merging module is used for acquiring the transaction sequence of each transaction to be processed and sequentially merging the execution result corresponding to each transaction to be processed with the historical merged execution result according to the transaction sequence;
the contract conflict result generating module is used for obtaining a first contract conflict result when the to-be-merged execution result corresponding to the current to-be-processed transaction and the historical merged execution result have intersection; acquiring contract byte codes corresponding to the intelligent contract methods corresponding to the transactions to be processed;
acquiring a preset detection contract byte code, and determining that the intelligent contract method corresponding to the contract byte code conflicts when the contract byte code is matched with the preset detection contract byte code to obtain a second contract conflict result; and obtaining a target contract conflict result according to the first contract conflict result and the second contract conflict result.
11. The apparatus of claim 10, further comprising: and the cache region creating module is used for acquiring a target block, creating a corresponding block read cache and a corresponding block write cache for the target block based on contract cache, and creating a corresponding initial transaction read cache and an initial transaction write cache for each transaction to be processed based on the block read cache and the block write cache.
12. The apparatus of claim 11, wherein the smart contract method execution module comprises:
a transaction read cache execution unit, configured to execute a corresponding intelligent contract method in an initial transaction read cache corresponding to each to-be-processed transaction, so as to obtain an updated transaction read cache corresponding to each to-be-processed transaction;
and the transaction write cache execution unit is used for executing the corresponding intelligent contract method in the initial transaction write cache corresponding to each transaction to be processed to obtain the updated transaction write cache corresponding to each transaction to be processed.
13. The apparatus of claim 12, wherein the transaction result merging module comprises:
the transaction sequence determining unit is used for acquiring the transaction sequence corresponding to each transaction to be processed;
and the transaction write cache result merging unit is used for sequentially merging the updated transaction write caches corresponding to the to-be-processed transactions into the block write cache according to the transaction sequence.
14. A computer-readable storage medium, storing a computer program which, when executed by a processor, causes the processor to carry out the steps of the method according to any one of claims 1 to 9.
15. A computer device comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method according to any one of claims 1 to 9.
CN201910853885.2A 2019-08-09 2019-08-09 Contract conflict detection method and device, readable storage medium and computer equipment Active CN110555773B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910853885.2A CN110555773B (en) 2019-08-09 2019-08-09 Contract conflict detection method and device, readable storage medium and computer equipment

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910853885.2A CN110555773B (en) 2019-08-09 2019-08-09 Contract conflict detection method and device, readable storage medium and computer equipment
CN201910736343.7A CN110443712B (en) 2019-08-09 2019-08-09 Contract conflict detection method and device, readable storage medium and computer equipment

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
CN201910736343.7A Division CN110443712B (en) 2019-08-09 2019-08-09 Contract conflict detection method and device, readable storage medium and computer equipment

Publications (2)

Publication Number Publication Date
CN110555773A CN110555773A (en) 2019-12-10
CN110555773B true CN110555773B (en) 2021-04-20

Family

ID=68434513

Family Applications (2)

Application Number Title Priority Date Filing Date
CN201910853885.2A Active CN110555773B (en) 2019-08-09 2019-08-09 Contract conflict detection method and device, readable storage medium and computer equipment
CN201910736343.7A Active CN110443712B (en) 2019-08-09 2019-08-09 Contract conflict detection method and device, readable storage medium and computer equipment

Family Applications After (1)

Application Number Title Priority Date Filing Date
CN201910736343.7A Active CN110443712B (en) 2019-08-09 2019-08-09 Contract conflict detection method and device, readable storage medium and computer equipment

Country Status (1)

Country Link
CN (2) CN110555773B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110866036B (en) * 2019-11-15 2023-02-10 腾讯科技(深圳)有限公司 Data processing method, system, device, terminal and readable storage medium
CN112214502B (en) * 2020-08-28 2023-07-07 迅鳐成都科技有限公司 User contract deployment method, device and system of alliance chain and storage medium
CN112559637B (en) * 2021-02-19 2021-06-18 腾讯科技(深圳)有限公司 Data processing method, device, equipment and medium based on distributed storage
CN115964389A (en) * 2021-10-09 2023-04-14 腾讯科技(深圳)有限公司 Data processing method, device and equipment based on block chain and readable storage medium
CN114022148B (en) * 2021-12-24 2022-04-22 杭州趣链科技有限公司 Transaction conflict detection method, device, equipment and storage medium based on block chain
CN114564412B (en) * 2022-04-27 2022-07-22 北京微芯感知科技有限公司 Method and system for deterministic transaction concurrent scheduling of block chains
CN115455457B (en) * 2022-11-11 2023-03-24 北京共识数信科技有限公司 Chain data management method, system and storage medium based on intelligent big data

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109040029A (en) * 2018-07-13 2018-12-18 上海点融信息科技有限责任公司 The method and apparatus of affairs are executed in block chain
CN109784930A (en) * 2019-02-18 2019-05-21 深圳市网心科技有限公司 A kind of processing method, device, electronic equipment and the medium of block chain transaction data
CN110019202A (en) * 2017-10-19 2019-07-16 深圳区块链金融服务有限公司 Method, computer system and medium for the transaction of concurrent processing block chain

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110019202A (en) * 2017-10-19 2019-07-16 深圳区块链金融服务有限公司 Method, computer system and medium for the transaction of concurrent processing block chain
CN109040029A (en) * 2018-07-13 2018-12-18 上海点融信息科技有限责任公司 The method and apparatus of affairs are executed in block chain
CN109784930A (en) * 2019-02-18 2019-05-21 深圳市网心科技有限公司 A kind of processing method, device, electronic equipment and the medium of block chain transaction data

Also Published As

Publication number Publication date
CN110555773A (en) 2019-12-10
CN110443712B (en) 2021-04-20
CN110443712A (en) 2019-11-12

Similar Documents

Publication Publication Date Title
CN110555773B (en) Contract conflict detection method and device, readable storage medium and computer equipment
CN110569264B (en) Contract data processing method and device, computer readable storage medium and computer equipment
CN110378694B (en) Block chain data processing method and device, computer equipment and storage medium
WO2020253061A1 (en) Page generating method and apparatus, computer device, and storage medium
CN111241061B (en) Writing method of state database, data processing device and storage medium
CN110866198A (en) Static resource caching method, system, device, computer equipment and storage medium
WO2021036253A1 (en) Method and device for executing transactions in parallel in blockchain
CN111563365B (en) Method and device for processing modification information of test standard worksheet and computer equipment
CN110224833B (en) Bill data processing method and system
CN113177225B (en) Block chain-based data storage certification method, device, equipment and storage medium
CN110768784B (en) Password transmission method, device, computer equipment and storage medium
CN110795171B (en) Service data processing method, device, computer equipment and storage medium
CN110609679A (en) Data processing method, data processing device, computer readable storage medium and computer equipment
CN113094076A (en) Version iteration method, device, equipment and medium based on version control
CN111177121A (en) Order data feedback method and device, computer equipment and storage medium
CN112860778A (en) Database management method, device, equipment and medium for desktop application program
EP4357883A1 (en) Data verification method and apparatus, device and storage medium
CN112069384A (en) Buried point data processing method, server and readable storage medium
CN110503432B (en) Method, device and computer readable storage medium for processing resource transfer request
CN114138734A (en) Web-based version management method facing database and file resource
CN115426106A (en) Identity authentication method, device, system, electronic equipment and storage medium
CN111124932B (en) Scheme verification method, system, device, computer equipment and storage medium
CN111061875B (en) Super parameter determination method, device, computer equipment and storage medium
CN112862454A (en) Test execution work order updating method and device, computer equipment and storage medium
CN113051008A (en) Interface request processing method and device, computer equipment and storage medium

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
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40015569

Country of ref document: HK

GR01 Patent grant
GR01 Patent grant