Block chain transaction receipt storage method, query method and computer equipment

By separating transaction receipts in the blockchain system, using data hashing to store transaction receipts and storing transaction result data in the database, the storage pressure problem caused by transaction receipt data is solved, and more efficient storage and query processing is achieved.

CN119938668APending Publication Date: 2025-05-06HANGZHOU HIGH-TECH ZONE (BINJIANG) INSTITUTE OF BLOCKCHAIN & DATA SECURITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411956855.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-28
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

In blockchain systems, high-frequency query of transaction receipt data and large data volumes lead to an increase in input/output pressure and storage pressure of alliance chain nodes. The existing technology requires actively triggering data archives but still occupying a large amount of disk resources.

Method used

By separating the transaction result data and receipt metadata in the transaction receipt, the transaction receipt hash is used to store the transaction receipt, and the transaction result data is stored in the node's database, thereby reducing the need to store receipt data.

Benefits of technology

It reduces the storage pressure of blockchain nodes, reduces the storage resource requirement for transaction result data, and improves the processing efficiency of nodes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938668A_ABST
    Figure CN119938668A_ABST
Patent Text Reader

Abstract

The embodiment of the invention is suitable for the technical field of block chains and data processing, and provides a block chain transaction receipt storage method, a block chain transaction receipt query method and computer device.The storage method comprises the steps that a transaction request is received and executed, and the transaction request carries a transaction receipt strategy field; the transaction receipt strategy field is used for representing a storage mode of transaction result data; if the storage mode represented by the transaction receipt strategy field is a first storage mode, calculating data hash of transaction result data corresponding to the transaction; generating a first transaction receipt of the transaction based on the data hash of the transaction result data, and storing the first transaction receipt at a current node; and storing the transaction result data in a database corresponding to the current node. By adopting the method, the transaction result data and the receipt metadata in the transaction receipt can be separately stored, and the storage pressure of the block chain node is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application belong to the field of blockchain and data processing technology, and in particular, to a storage method, a query method, and a computer device for blockchain transaction receipts. Background Art

[0002] In the blockchain system, the application side can query data by calling smart contracts. These data are stored in the result field of the transaction receipt as the result of the smart contract call. After the application side calls the smart contract, it can obtain the expected business data by querying the transaction receipt. Taking the alliance chain as an example, the application side usually has the need to query the world state. This type of query is only for the world state. The returned results do not have actual storage value. Only the queryer cares about it, and other users do not care about the data queried by the queryer at this moment. However, the request frequency of this type of query is high and the data volume is large. The query process easily leads to a large amount of transaction receipt data in the alliance chain scenario, which increases the input / output (I / O) pressure and storage pressure of each node of the alliance chain.

[0003] In the prior art, data archiving can be adopted, and the blockchain provides a data archiving interface to archive data such as blocks, transactions, and transaction receipts within a specified block range. After archiving is completed, the archived data is moved to other storage media to reduce the storage pressure of each node. However, the above solution requires active triggering of data archiving operations, and data such as transaction receipts still need to be written to the disk first, which takes up a lot of disk resources. Summary of the invention

[0004] In view of this, the embodiments of the present application provide a storage method, a query method and a computer device for blockchain transaction receipts, which are used to separately store transaction result data and receipt metadata in transaction receipts, thereby reducing the storage pressure of blockchain nodes.

[0005] A first aspect of an embodiment of the present application provides a method for storing a blockchain transaction receipt, comprising:

[0006] receiving a transaction request and executing the transaction request, wherein the transaction request carries a transaction receipt policy field, and the transaction receipt policy field is used to characterize the storage method of transaction result data;

[0007] If the storage mode represented by the transaction receipt strategy field is the first storage mode, then calculating the data hash of the transaction result data corresponding to the current transaction;

[0008] Generate a first transaction receipt for the current transaction based on the data hash of the transaction result data, and store the first transaction receipt at the current node;

[0009] The transaction result data is stored in the database corresponding to the current node.

[0010] Optionally, generating the first transaction receipt of the transaction based on the data hash of the transaction result data includes:

[0011] Determine receipt metadata obtained by executing the transaction, where the receipt metadata at least includes a transaction hash of the transaction;

[0012] Generate a first transaction receipt for the transaction according to the data hash of the transaction result data corresponding to the transaction and the receipt metadata.

[0013] Optionally, storing the transaction result data in a database corresponding to the current node includes:

[0014] The transaction result data is stored in a cache database or a persistent database corresponding to the current node.

[0015] Optionally, it also includes:

[0016] If the storage method represented by the transaction receipt strategy field is the second storage method, a second transaction receipt for the transaction is generated based on the transaction result data corresponding to the transaction and the second transaction receipt is stored at the current node.

[0017] Optionally, it also includes:

[0018] After the execution of the block containing the transaction is completed, a block hash of the block is calculated, the block hash includes a transaction receipt root hash, the transaction receipt root hash is a hash value corresponding to the transaction receipt stored in the first storage method and the second storage method, and the transaction receipt includes a first transaction receipt and / or a second transaction receipt;

[0019] The data consistency of each node is verified based on the transaction receipt root hash.

[0020] A second aspect of an embodiment of the present application provides a method for querying a blockchain transaction receipt, comprising:

[0021] When receiving a transaction receipt query request, obtaining the transaction hash carried in the transaction receipt query request;

[0022] Determine the storage method of the transaction result data of the current transaction to be queried according to the transaction hash;

[0023] If the storage method of the transaction result data of the current transaction is the first storage method, obtaining the transaction result data corresponding to the current transaction in the database corresponding to the current node, and obtaining receipt metadata from the current node;

[0024] Generate a first transaction receipt based on the transaction result data corresponding to the current transaction and the receipt metadata, and return the first transaction receipt to the requester;

[0025] Wherein, the transaction result data is stored using the method described in any one of the first aspects.

[0026] Optionally, acquiring transaction result data corresponding to the current transaction in a database corresponding to the current node includes:

[0027] Query and obtain the transaction result data corresponding to the current transaction in the cache database corresponding to the current node;

[0028] If the transaction result data corresponding to the current transaction does not exist in the cache database, the transaction result data is queried from the persistent database corresponding to the current node.

[0029] Optionally, it also includes:

[0030] If the storage method of the transaction result data of the transaction is the second storage method, the second transaction receipt corresponding to the transaction is obtained at the current node; wherein, when the second storage method is adopted, the second transaction receipt stored at the current node includes the transaction result data corresponding to the transaction and the receipt metadata.

[0031] A third aspect of an embodiment of the present application provides a storage device for a blockchain transaction receipt, including:

[0032] A transaction request execution module, used to receive a transaction request and execute the transaction request, wherein the transaction request carries a transaction receipt strategy field, and the transaction receipt strategy field is used to characterize the storage method of the transaction result data;

[0033] A data hash calculation module, configured to calculate a data hash of the transaction result data corresponding to the current transaction if the storage mode represented by the transaction receipt strategy field is the first storage mode;

[0034] A transaction receipt storage module, configured to generate a first transaction receipt for the current transaction based on a data hash of the transaction result data, and store the first transaction receipt at the current node;

[0035] The transaction result data storage module is used to store the transaction result data in the database corresponding to the current node.

[0036] A fourth aspect of an embodiment of the present application provides a blockchain transaction receipt query device, including:

[0037] A transaction hash acquisition module, configured to acquire the transaction hash carried in the transaction receipt query request upon receiving the transaction receipt query request;

[0038] A storage method determination module, used to determine the storage method of the transaction result data of the current transaction to be queried according to the transaction hash;

[0039] A transaction result data acquisition module, configured to acquire the transaction result data corresponding to the transaction in the database corresponding to the current node if the storage mode of the transaction result data of the current transaction is the first storage mode, and acquire receipt metadata from the current node;

[0040] A transaction receipt feedback module, configured to generate a first transaction receipt based on the transaction result data corresponding to the current transaction and the receipt metadata, and return the first transaction receipt to the requesting party;

[0041] Wherein, the transaction result data is stored using the device described in the third aspect.

[0042] A fifth aspect of an embodiment of the present application provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the computer device implements a method as described in any one of the first or second aspects above.

[0043] A sixth aspect of an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a computer, the method described in any one of the first aspect or the second aspect is implemented.

[0044] A seventh aspect of an embodiment of the present application provides a computer program product, including a computer program, which, when executed, enables the method described in any one of the first aspect or the second aspect to be executed.

[0045] Compared with the prior art, the embodiments of the present application have the following beneficial effects:

[0046] In an embodiment of the present application, after a blockchain node receives a transaction request and executes the transaction request, if the storage method of the transaction result data is determined to be the first storage method according to the transaction receipt policy field carried in the transaction request, the node can calculate the data hash of the transaction result data corresponding to this transaction, generate the transaction receipt of this transaction, i.e., the first transaction receipt, based on the data hash of the transaction result data, and store the first transaction receipt in the current node. When the first storage method is adopted, the transaction result data can be stored in the database corresponding to the current node. In this way, the first transaction receipt stored by the blockchain node may not include the transaction result data. By storing the transaction result data separately, the storage resources required for the node to store the transaction result data can be reduced, thereby reducing the storage pressure of the node. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or prior art descriptions. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0048] Figure 1 It is a schematic diagram of a method for storing a blockchain transaction receipt provided in an embodiment of the present application;

[0049] Figure 2 This is a schematic diagram comparing the storage methods of a transaction receipt provided in an embodiment of the present application;

[0050] Figure 3 It is a schematic diagram of a method for querying a blockchain transaction receipt provided in an embodiment of the present application;

[0051] Figure 4 It is a schematic diagram of a storage process of a blockchain transaction receipt provided by an embodiment of the present application;

[0052] Figure 5 It is a schematic diagram of a query process of a blockchain transaction receipt provided by an embodiment of the present application;

[0053] Figure 6 It is a schematic diagram of a storage device for a blockchain transaction receipt provided in an embodiment of the present application;

[0054] Figure 7 It is a schematic diagram of a blockchain transaction receipt query device provided in an embodiment of the present application;

[0055] Figure 8 It is a schematic diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0056] In the following description, specific details such as specific system structures, technologies, etc. are proposed for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from hindering the description of the present application.

[0057] The technical solution of the present application is described below through specific embodiments.

[0058] Reference Figure 1 , showing a schematic diagram of a method for storing a blockchain transaction receipt provided by an embodiment of the present application, which may specifically include the following steps:

[0059] S101. Receive a transaction request and execute the transaction request. The transaction request carries a transaction receipt policy field. The transaction receipt policy field is used to represent a storage method of transaction result data.

[0060] It should be noted that the method can be applied to blockchain, and each step of the method can be executed by each node in the blockchain. That is, the execution subject of the method can be a node in the blockchain, and each node can directly store the transaction receipt according to actual needs, or store the transaction result data and receipt metadata in the transaction receipt separately, thereby reducing the storage pressure of the blockchain node.

[0061] In the embodiment of the present application, the functions implemented by each node in the above blockchain can be implemented based on the carrier of the computer device, so the execution subject of the present method can also be a computer device. The embodiment of the present application does not limit the type of computer device.

[0062] The transaction request may be initiated by the requester, and the embodiment of the present application does not limit the requester who initiates the transaction request. After receiving the transaction request initiated by the requester, the blockchain node may execute the transaction request. Among them, the transaction request may carry multiple fields, and different fields may be used to record different information. For example, transaction hash, signature information of the requester, etc.

[0063] In an embodiment of the present application, the transaction request may carry a transaction receipt policy field, which can be used to characterize the storage method of the transaction result data. The above-mentioned transaction result data is the data obtained after the blockchain node executes the transaction request.

[0064] In a possible implementation of the embodiment of the present application, the storage method represented by the transaction receipt policy field may include a first storage method. The above-mentioned first storage method may be a separate storage method, that is, a blockchain node may store the data contained in the transaction receipt separately.

[0065] In the embodiment of the present application, the transaction receipt can be abstracted into two types of data, namely, receipt metadata and transaction result data. Among them, the receipt metadata can include data such as transaction hash, transaction type, transaction version number, etc.; the transaction result data can be the data output by the node after the transaction is executed, such as the return result after the smart contract call. The first storage method represented by the transaction receipt policy field in the embodiment of the present application is a storage method for storing the above-mentioned transaction result data and receipt metadata separately.

[0066] After the blockchain node executes this transaction, if the transaction receipt policy field carried in the transaction request shows that the transaction result data and receipt metadata need to be stored in the first storage method, that is, the transaction result data and receipt metadata are stored separately, then the blockchain node can execute S102 to calculate the data hash of the transaction result data corresponding to this transaction.

[0067] S102: If the storage method represented by the transaction receipt strategy field is the first storage method, calculate the data hash of the transaction result data corresponding to the current transaction.

[0068] In the embodiment of the present application, the first storage method may be separate storage, that is, a method of storing the transaction result data and the receipt metadata separately. When the storage method represented by the transaction receipt policy field is the first storage method, the blockchain node may only store the receipt metadata of this transaction and the data hash of the corresponding transaction result data. Therefore, when confirming that the storage method is the first storage method, the blockchain node may calculate the data hash of the transaction result data corresponding to this transaction.

[0069] S103: Generate a first transaction receipt for the current transaction based on the data hash of the transaction result data, and store the first transaction receipt at the current node.

[0070] In an embodiment of the present application, when the storage method is the first storage method, the transaction receipt stored by the blockchain node can be generated based on the data hash of the transaction result data, and the blockchain node may not store the corresponding transaction result data.

[0071] Therefore, after calculating the data hash of the transaction result data, the blockchain node can generate a transaction receipt based on the above data hash and store the transaction receipt at the current node.

[0072] In a possible implementation of the embodiment of the present application, the transaction receipt may include receipt metadata. Therefore, when storing the transaction receipt, the blockchain node may determine the receipt metadata obtained by executing this transaction, and then generate the transaction receipt of this transaction based on the data hash of the transaction result data corresponding to this transaction and the receipt metadata. That is, when the storage method is the first storage method, the transaction receipt stored by the blockchain node includes the receipt metadata and the data hash of the transaction result data. Among them, the receipt metadata may at least include the transaction hash of this transaction.

[0073] In a possible implementation of the embodiment of the present application, for the convenience of description, the transaction receipt stored in the first storage mode, that is, the separate storage mode, may be referred to as the first transaction receipt. Specifically, the first transaction receipt may only include the receipt metadata and the data hash of the transaction result data.

[0074] Therefore, in the aforementioned example, when the storage method is the first storage method, the blockchain node can generate the first transaction receipt of this transaction based on the data hash of the transaction result data and the receipt metadata, and store the first transaction receipt in the current node.

[0075] S104: Store the transaction result data in a database corresponding to the current node.

[0076] In the embodiment of the present application, when the first storage method is adopted, the transaction result data is not stored in the current node, but can be stored in the database corresponding to the current node. In this way, the storage resources required by the current node for storing the transaction result data can be reduced, and the storage pressure of the current node can be reduced.

[0077] In an embodiment of the present application, the database corresponding to the current node may include a cache database or a persistent database. That is, the blockchain node may store the transaction result data in the cache database or the persistent database corresponding to the current node.

[0078] Among them, the cache database can be used to cache the transaction result data. After executing a transaction, the blockchain node can first cache the transaction result data to the corresponding cache database. When the transaction result data needs to be persisted, the blockchain node can move the transaction result data cached in the cache database to the persistent database for storage. The embodiment of the present application does not limit the specific data structure used by the cache database and the persistent database.

[0079] In a possible implementation of the embodiment of the present application, the transaction result data cached in the cache database may not be persisted. That is, in some scenarios, if the transaction result data cached in the cache database has exceeded the corresponding cache time limit and there is no need to persist the transaction result data, the transaction result data in the cache database can be directly deleted without transferring it to the persistent database. In this way, the storage resources required for storing the transaction result data can be further reduced.

[0080] In a possible implementation of the embodiment of the present application, the transaction receipt may also be stored in a second storage method. The second storage method may be a method of directly storing the transaction receipt, that is, directly storing the completed transaction result data and the corresponding receipt metadata.

[0081] In the embodiment of the present application, corresponding to the first storage mode and the first transaction receipt, for the convenience of description, the transaction receipt stored in the second storage mode may be referred to as the second transaction receipt. Specifically, the second transaction receipt may include transaction result data and receipt metadata.

[0082] Therefore, if the storage method represented by the transaction receipt policy field is the second storage method, the blockchain node can generate the second transaction receipt of this transaction based on the transaction result data corresponding to this transaction and store the second transaction receipt in the current node. That is, when the storage method is the second storage method, the blockchain node can directly store the receipt metadata and the transaction result data in the current node.

[0083] like Figure 2 FIG. 1 is a schematic diagram showing a comparison of a storage method for a transaction receipt provided in an embodiment of the present application. Figure 2 The difference between the data stored on the blockchain node when the first storage method, i.e., separate storage, and the second storage method, i.e., direct storage, are respectively shown.

[0084] See also Figure 2 When the first storage method, i.e., separate storage, is used, the transaction receipt stored on the blockchain node, i.e., the first transaction receipt, includes the receipt metadata and the data hash corresponding to the transaction result data of this transaction; when the second storage method, i.e., direct storage, is used, the transaction receipt stored on the blockchain node, i.e., the second transaction receipt, includes the receipt metadata and the transaction result data of this transaction. The difference between the two is that, in separate storage, the transaction result data is not directly stored on the blockchain node. Figure 2 As shown, the transaction result data under separate storage can be stored in the cache database or persistent database corresponding to the node.

[0085] In a possible implementation of the embodiment of the present application, the blockchain node may execute the transaction in sequence according to the blocks. After the execution of the block containing the transaction is completed, the node may calculate the block hash of the block, and the block hash may include the transaction receipt root hash, which may be the hash value corresponding to the transaction receipt stored in the first storage method and the second storage method. Therefore, the transaction receipt may include the first transaction receipt and / or the second transaction receipt. The transaction receipt root hash can be used to verify the data consistency of each node.

[0086] In an embodiment of the present application, after a blockchain node receives a transaction request and completes the execution of the transaction request, if the storage method of the transaction result data is determined to be the first storage method according to the transaction receipt policy field carried in the transaction request, the node can calculate the data hash of the transaction result data corresponding to this transaction, generate the first transaction receipt of this transaction based on the data hash of the transaction result data, and store the first transaction receipt in the current node. When the first storage method is adopted, the transaction result data can be stored in the database corresponding to the current node. In this way, the transaction receipt stored by the blockchain node, that is, the first transaction receipt, may not include the transaction result data. By storing the transaction result data separately, the storage resources required for the node to store the transaction result data can be reduced, and the storage pressure of the node can be reduced.

[0087] Based on the storage method provided in the above embodiment, Figure 3 , showing a schematic diagram of a method for querying a blockchain transaction receipt provided by an embodiment of the present application, which may specifically include the following steps:

[0088] S301. When a transaction receipt query request is received, obtain the transaction hash carried in the transaction receipt query request.

[0089] It should be noted that the transaction receipts in the embodiments of the present application can be stored in the manner described in the various embodiments of the aforementioned blockchain transaction receipt storage method. That is, when the first storage method, i.e., separate storage, is adopted, the transaction receipt stored by the blockchain node includes the receipt metadata and the data hash corresponding to the transaction result data, and the transaction result data is stored in the cache database or persistent database of the current node; when the second storage method, i.e., direct storage, is adopted, the transaction receipt stored by the blockchain node includes the receipt metadata and the transaction result data. For the specific storage method of the transaction receipt, please refer to Figure 1 and Figure 2 The description of the corresponding embodiment part will not be repeated in the embodiments of this application.

[0090] The transaction receipt in the embodiment of the present application can be divided into a first transaction receipt and a second transaction receipt. The first transaction receipt only includes the receipt metadata and the data hash of the transaction result data, and does not directly include the transaction result data; the second transaction receipt includes the receipt metadata and the transaction result data. The difference between the first transaction receipt and the second transaction receipt can be found in Figure 2 As shown, no further details are given here.

[0091] Each step of the method can be executed by each node in the blockchain. That is, the execution subject of the method can be a node in the blockchain, and the functions implemented by each node in the blockchain can be implemented based on the carrier of the computer device, so the execution subject of the method can also be a computer device.

[0092] In an embodiment of the present application, a transaction receipt query request may be initiated by the requester of the transaction request. For example, after initiating a transaction, the requester may request to query the transaction receipt after the transaction is executed to determine the execution result of the transaction. The transaction receipt requested to be queried may include the first transaction receipt or the second transaction receipt.

[0093] Usually, a transaction hash can uniquely identify a transaction. Therefore, when a blockchain node receives a query request for a transaction receipt, it can first obtain the transaction hash carried in the transaction receipt query request to determine which transaction the requester is looking for.

[0094] S302: Determine a storage method for the transaction result data of the current transaction to be queried according to the transaction hash.

[0095] In the embodiment of the present application, the transaction to be queried by the requesting party can be determined based on the transaction hash. The blockchain node can further determine the storage method of the transaction receipt or transaction result data of the transaction.

[0096] In a possible implementation of the embodiment of the present application, the storage method of the transaction receipt or transaction result data may include a first storage method, and the first storage method may be the separate storage introduced in the aforementioned embodiment.

[0097] In another possible implementation of the embodiment of the present application, the storage method of the transaction receipt or transaction result data may also include a second storage method, and the second storage method may be the direct storage introduced in the aforementioned embodiment.

[0098] For the difference between the data stored on the blockchain node when the first storage method and the second storage method are used, please refer to Figure 2 As shown, the embodiments of the present application will not be described in detail.

[0099] If it is determined that the storage method of the result data of the transaction to be queried is the first storage method, the blockchain node executes S303 to obtain the transaction result data corresponding to this transaction in the corresponding database.

[0100] S303: If the storage method of the transaction result data of the current transaction is the first storage method, the transaction result data corresponding to the current transaction is obtained from the database corresponding to the current node, and receipt metadata is obtained from the current node.

[0101] When the first storage method is used to store transaction receipts and transaction result data, the blockchain node can only store the receipt metadata of this transaction and the data hash of the transaction result data, without having to store the transaction result data in the current node. The transaction result data will be stored in a corresponding database, such as a cache database or a persistent database. Therefore, when the storage method is determined to be the first storage method, the blockchain node needs to obtain the result data of the transaction to be queried from the corresponding database and obtain the receipt metadata from the current node.

[0102] In a possible implementation of the embodiment of the present application, when the first storage method is adopted, the transaction result data can be first stored in the cache database. When the data stored in the cache database needs to be persisted, the transaction result data in the cache database will be moved to the persistent database. Therefore, when the blockchain node obtains the transaction result data in the corresponding database, it can first query and obtain the transaction result data corresponding to this transaction in the cache database corresponding to the current node. If the corresponding transaction result data can be queried in the cache database, the node can directly obtain the result data from the cache database. If the transaction result data corresponding to this transaction does not exist in the cache database, it means that the transaction result data may have been persisted, so the transaction result data can be queried from the persistent database corresponding to the current node.

[0103] If the transaction result data cannot be queried in both the cache database and the persistent database, it means that the transaction result data of this transaction cannot be queried, and the blockchain node can return a receipt that does not contain the transaction result data to the requester.

[0104] S304: Generate a first transaction receipt based on the transaction result data corresponding to the current transaction and the receipt metadata, and return the first transaction receipt to the requesting party.

[0105] In the embodiment of the present application, after the blockchain node obtains the transaction result data from the corresponding database, it can generate a transaction receipt, i.e., a first transaction receipt, based on the transaction result data and the receipt metadata obtained from the current node, and return the first transaction receipt to the requester. The first transaction receipt returned to the requester may include the queried transaction result data and the receipt metadata.

[0106] In a possible implementation of the embodiment of the present application, if the storage method of the transaction result data of this transaction is the second storage method, it means that the transaction receipt stored in the current node contains the transaction result data corresponding to this transaction. Therefore, the transaction receipt corresponding to this transaction, i.e., the second transaction receipt, can be directly obtained at the current node and the second transaction receipt is returned to the requesting party. The second transaction receipt returned to the requesting party includes the transaction result data and the receipt metadata.

[0107] In an embodiment of the present application, when a transaction receipt query request is received, by obtaining the transaction hash carried in the transaction receipt query request, the storage method of the transaction result data of the transaction to be queried can be determined according to the transaction hash. If the storage method of the transaction result data of this transaction is the first storage method, that is, separate storage, it means that the blockchain node only stores the receipt metadata and the data hash corresponding to the transaction result data, and does not directly store the transaction result data. Therefore, the transaction result data corresponding to this transaction can be obtained from the database corresponding to the current node and the receipt metadata can be obtained from the current node, and a transaction receipt, that is, a first transaction receipt, can be generated based on the result data and the receipt metadata and the first transaction receipt can be returned to the requesting party. By determining the storage method of the transaction receipt or transaction result data, the embodiment of the present application can obtain the transaction result data from the database corresponding to the node when it adopts separate storage, thereby reducing the data storage pressure of the blockchain node and reducing the pressure of performing I / O operations on the node in the process of obtaining the transaction result data.

[0108] It should be noted that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0109] For ease of understanding, the following is a complete example to introduce the storage method and query method of the blockchain transaction receipt provided in the embodiment of the present application. The storage method and query method for implementing the above-mentioned blockchain transaction receipt mainly include three parts: transaction receipt storage strategy, transaction receipt storage process and transaction receipt query process. They are introduced one by one below.

[0110] (1) Transaction Receipt Storage Strategy

[0111] In the embodiment of the present application, the transaction receipt can be abstracted into two types of data, namely, receipt metadata and transaction result data. Among them:

[0112] Receipt metadata: Contains data such as transaction hash, transaction type, and transaction version number.

[0113] Transaction result data: usually the output data after the transaction is executed. For example, the return result after the smart contract is called.

[0114] In the embodiment of the present application, for each transaction, a transaction receipt policy field may be added to the transaction request, and the field includes two optional values, namely, direct storage and separate storage.

[0115] Direct storage: Consistent with traditional blockchain, complete transaction result data is stored. This strategy is usually used for important contract transactions, and key business data is stored in the transaction receipt. The transaction receipt when directly stored can be called the second transaction receipt.

[0116] Separate storage: The original transaction result data is hashed, and the transaction receipt only stores the receipt metadata and the data hash of the transaction result data. The actual transaction result data is stored in the transaction result cache, such as the cache database and the optional persistence database. This strategy is usually used for contract query operations, that is, querying part of the status data. These query results do not need to be stored in the transaction receipt, but only need to be returned to the application or requester. The transaction receipt in separate storage can be called the first transaction receipt.

[0117] The transaction result cache can be used to cache actual transaction result data, which usually includes the transaction result data of the most recent multiple blocks of separated storage transactions, as well as the transaction result data of other earlier blocks of separated storage transactions.

[0118] In the embodiments of the present application, separate storage may be the first storage method in the aforementioned method embodiments, and direct storage may be the second storage method in the aforementioned method embodiments. The difference between the two can be seen in Figure 2 shown.

[0119] (2) Transaction receipt storage process

[0120] like Figure 4 , which is a schematic diagram of the storage process of the blockchain transaction receipt provided by the embodiment of the present application, Figure 4 The process shown is the transaction receipt storage process.

[0121] Reference Figure 4The storage process shown, for a blockchain node, after receiving a block, can execute each transaction in the block in series. In the process of the node executing each transaction, if the transaction is completed, the transaction result data can be obtained. According to the transaction receipt strategy of the transaction, whether it is direct storage or separate storage, the storage method of the transaction result data can be determined. If it is direct storage, the complete transaction result data can be stored in the node and the process ends; if the transaction receipt strategy of the transaction is separate storage, the node can calculate the data hash of the transaction result data, and the transaction receipt stored in the node, that is, the first transaction receipt, can only store the receipt metadata and the data hash of the transaction result data, and the transaction result data of the current transaction can be stored in the transaction result cache or an optional persistent database.

[0122] like Figure 4 As shown in the figure, after the block transaction is executed, the block hash needs to be calculated to verify the consistency of the node execution results in the consensus stage. This process includes calculating the transaction receipt root hash, that is, taking all directly stored transaction receipts and separately stored transaction receipts as input, and calculating the transaction receipt root hash of this block. For directly stored transaction receipts, the receipt metadata and transaction result data are consistent in different nodes. For separately stored transaction receipts, the data hash of the receipt metadata and transaction result data is also consistent in different nodes. Therefore, the transaction receipt root hash of the block must be consistent in different nodes, that is, after adopting separate storage, the consistency between nodes can still be verified through the transaction receipt root hash.

[0123] like Figure 4 As shown, after calculating the block hash, the transaction receipt can also be persistently stored, including the directly stored transaction receipt, i.e., the second transaction receipt (receipt metadata and transaction result data) and the separately stored transaction receipt, i.e., the first transaction receipt (receipt metadata and data hash of transaction result data).

[0124] According to the configuration of the node, if the blockchain node wants to store the complete transaction result data of the separately stored transaction receipt, the transaction result data of the separately stored transaction receipt can be persistently stored; the node can also not persistently store the transaction result data of the separately stored transaction receipt in the current node, thereby reducing the disk storage overhead.

[0125] (3) Transaction Receipt Query Process

[0126] like Figure 5 , which is a schematic diagram of the query process of blockchain transaction receipt provided by an embodiment of the present application, Figure 5 The process shown is the transaction receipt query process.

[0127] Reference Figure 5In the query process shown, for a blockchain node, after executing a transaction, the application or requester may have the need to query the receipt of the transaction. The transaction receipt to be queried may be the first transaction receipt or the second transaction receipt. The blockchain node can query the transaction receipt through the transaction hash of the transaction. Specifically, the corresponding transaction receipt can be queried in this node through the transaction hash. If the transaction receipt cannot be queried, the node can return the information that the transaction receipt does not exist to the application. If the transaction receipt is queried in this node, the node can determine the type of transaction receipt, that is, the storage method of the transaction receipt or transaction result data. If it is a direct storage type transaction receipt, the node can directly return the transaction receipt to the application because the transaction result data is stored on the node. If it is a separate storage type transaction receipt, since the separate storage type transaction receipt does not store the transaction result data on the node, it is necessary to try to query the transaction result data.

[0128] Specifically, the transaction result cache, such as a cache database, can be queried first. If the transaction result data of the transaction receipt exists in the cache, the transaction result data can be hashed to verify whether the data hash of the transaction result data is consistent with the data hash recorded in the separately stored transaction receipt. If the transaction result data of the transaction receipt does not exist in the cache, the node can determine whether there is persistent transaction result data. If so, the transaction result data can be queried from the persistent data, and the data consistency can be verified through the same hash calculation steps mentioned above. If the transaction result data cannot be queried, the node can return a receipt that does not contain the transaction result data to the application or requester.

[0129] Based on the storage method and query method of the transaction receipt introduced above, as a specific example of the embodiment of the present application, taking the Solidity contract as an example, assuming that a company's documents are stored on the blockchain, its data structure is represented as follows:

[0130] pragma solidity^0.8.19;

[0131] contract DocumentStorage{

[0132] / / Two-layer mapping: company name=>(document hash=>document data)

[0133] mapping(string=>mapping(string=>string))private documents;

[0134] }

[0135] In one example, the blockchain based on the above contract stores all the document data of the company, assuming that the size of a document is about 1KB. The following describes the difference in specific effects that can be achieved by using the storage and query method of the prior art and the storage and query method provided by the embodiment of the present application.

[0136] When the application system needs to periodically query the document data on the blockchain for offline auditing, it is necessary to divide the company's individual data into multiple transactions and query the document data from the chain.

[0137] Assuming that the company's audit includes 1,000,000 individual data, then considering the gas limit, it is usually processed in multiple transactions, for example, divided into 1,000 transactions for processing, and 1,000 data are queried each time.

[0138] If the solution in the prior art is followed, each query will write 1,000 document data in the transaction receipt to the transaction result, with a size of about 1MB. For a total of 1,000 transactions, each node occupies 1GB in total. Although the query service only processes the query operation, it brings 1GB of disk usage.

[0139] If the separate storage solution provided in the embodiment of the present application is used, each query will write the transaction results of 1,000 document data in the transaction receipt, cache them in the memory, and provide them to the application for query. The transaction result data size of a transaction is about 1MB. Assuming that the transaction result cache of the node only caches the transaction results of the most recent 100 blocks, and each block contains only one query request for document data during the query, then a maximum of 100MB of cache will be temporarily occupied to complete the query request. Compared with the direct storage solution in the prior art, each node reduces the storage overhead by 1GB, greatly reducing the storage pressure of the node.

[0140] Reference Figure 6 , shows a schematic diagram of a storage device for a blockchain transaction receipt provided in an embodiment of the present application, which may specifically include a transaction request execution module 601, a data hash calculation module 602, a transaction receipt storage module 603 and a transaction result data storage module 604, wherein:

[0141] The transaction request execution module 601 is used to receive a transaction request and execute the transaction request, wherein the transaction request carries a transaction receipt policy field, and the transaction receipt policy field is used to indicate the storage method of the transaction result data;

[0142] A data hash calculation module 602 is used to calculate the data hash of the transaction result data corresponding to the current transaction if the storage mode represented by the transaction receipt strategy field is the first storage mode;

[0143] The transaction receipt storage module 603 is used to generate the first transaction receipt of the current transaction based on the data hash of the transaction result data, and store the first transaction receipt at the current node;

[0144] The transaction result data storage module 604 is used to store the transaction result data in the database corresponding to the current node.

[0145] In the embodiment of the present application, the transaction receipt storage module 603 can be specifically used for:

[0146] Determine receipt metadata obtained by executing the transaction, where the receipt metadata at least includes a transaction hash of the transaction;

[0147] Generate a first transaction receipt for the transaction according to the data hash of the transaction result data corresponding to the transaction and the receipt metadata.

[0148] In the embodiment of the present application, the transaction result data storage module 604 can be specifically used for:

[0149] The transaction result data is stored in a cache database or a persistent database corresponding to the current node.

[0150] In a possible implementation of the embodiment of the present application, the transaction receipt storage module 603 may also be used to:

[0151] If the storage method represented by the transaction receipt strategy field is the second storage method, a second transaction receipt for the transaction is generated based on the transaction result data corresponding to the transaction and the second transaction receipt is stored at the current node.

[0152] In a possible implementation manner of the embodiment of the present application, the device may further include a consistency verification module, and the consistency verification module may be specifically used to:

[0153] After the execution of the block containing the transaction is completed, a block hash of the block is calculated, the block hash includes a transaction receipt root hash, the transaction receipt root hash is a hash value corresponding to the transaction receipt stored in the first storage method and the second storage method, and the transaction receipt includes a first transaction receipt and / or a second transaction receipt;

[0154] The data consistency of each node is verified based on the transaction receipt root hash.

[0155] An embodiment of the present application provides a storage device for a blockchain transaction receipt. By using this device, each step in the aforementioned storage method embodiments can be implemented.

[0156] Reference Figure 7, shows a schematic diagram of a blockchain transaction receipt query device provided in an embodiment of the present application, which may specifically include a transaction hash acquisition module 701, a storage method determination module 702, a transaction result data acquisition module 703 and a transaction receipt feedback module 704, wherein:

[0157] The transaction hash acquisition module 701 is used to acquire the transaction hash carried in the transaction receipt query request when receiving the transaction receipt query request;

[0158] A storage method determination module 702, used to determine the storage method of the transaction result data of the current transaction to be queried according to the transaction hash;

[0159] The transaction result data acquisition module 703 is used to acquire the transaction result data corresponding to the transaction in the database corresponding to the current node if the storage mode of the transaction result data of the current transaction is the first storage mode, and acquire receipt metadata from the current node;

[0160] A transaction receipt feedback module 704 is used to generate a first transaction receipt based on the transaction result data corresponding to the current transaction and the receipt metadata, and return the first transaction receipt to the requesting party;

[0161] Among them, the transaction result data is stored using a storage device such as the blockchain transaction receipt in the aforementioned embodiment.

[0162] In a possible implementation of the embodiment of the present application, the transaction result data acquisition module 703 may be specifically used to:

[0163] Query and obtain the transaction result data corresponding to the current transaction in the cache database corresponding to the current node;

[0164] If the transaction result data corresponding to the current transaction does not exist in the cache database, the transaction result data is queried from the persistent database corresponding to the current node.

[0165] In a possible implementation of the embodiment of the present application, the transaction receipt feedback module 704 may also be used to:

[0166] If the storage method of the transaction result data of the transaction is the second storage method, the second transaction receipt corresponding to the transaction is obtained at the current node; wherein, when the second storage method is adopted, the second transaction receipt stored at the current node includes the transaction result data corresponding to the transaction and the receipt metadata.

[0167] An embodiment of the present application provides a device for querying blockchain transaction receipts. By using this device, each step in the aforementioned query method embodiments can be implemented.

[0168] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment part.

[0169] Reference Figure 8 , shows a schematic diagram of a computer device provided by an embodiment of the present application. Figure 8 As shown, the computer device 800 in the embodiment of the present application includes: a processor 810, a memory 820, and a computer program 821 stored in the memory 820 and executable on the processor 810. When the processor 810 executes the computer program 821, the steps of each embodiment of the above-mentioned blockchain transaction receipt storage method or blockchain transaction receipt query method are implemented, such as Figure 1 Steps S101 to S104 shown or Figure 3 Alternatively, when the processor 810 executes the computer program 821, the functions of each module / unit in the above-mentioned device embodiments are realized, for example Figure 6 Modules 601 to 604 shown or Figure 7 Functions of modules 701 to 704 are shown.

[0170] Exemplarily, the computer program 821 may be divided into one or more modules / units, which are stored in the memory 820 and executed by the processor 810 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which may be used to describe the execution process of the computer program 821 in the computer device 800. For example, the computer program 821 may be divided into a transaction request execution module, a data hash calculation module, a transaction receipt storage module, and a transaction result data storage module, and the specific functions of each module are as follows:

[0171] A transaction request execution module, used to receive a transaction request and execute the transaction request, wherein the transaction request carries a transaction receipt strategy field, and the transaction receipt strategy field is used to characterize the storage method of the transaction result data;

[0172] A data hash calculation module, configured to calculate a data hash of the transaction result data corresponding to the current transaction if the storage mode represented by the transaction receipt strategy field is the first storage mode;

[0173] A transaction receipt storage module, configured to generate a first transaction receipt for the current transaction based on a data hash of the transaction result data, and store the first transaction receipt at the current node;

[0174] The transaction result data storage module is used to store the transaction result data in the database corresponding to the current node.

[0175] Alternatively, the computer program 821 may be divided into a transaction hash acquisition module, a storage method determination module, a transaction result data acquisition module, and a transaction receipt feedback module, and the specific functions of each module are as follows:

[0176] A transaction hash acquisition module, configured to acquire the transaction hash carried in the transaction receipt query request upon receiving the transaction receipt query request;

[0177] A storage method determination module, used to determine the storage method of the transaction result data of the current transaction to be queried according to the transaction hash;

[0178] A transaction result data acquisition module, configured to acquire the transaction result data corresponding to the transaction in the database corresponding to the current node if the storage mode of the transaction result data of the current transaction is the first storage mode, and acquire receipt metadata from the current node;

[0179] A transaction receipt feedback module, configured to generate a first transaction receipt based on the transaction result data corresponding to the current transaction and the receipt metadata, and return the first transaction receipt to the requesting party;

[0180] Among them, the transaction result data is stored using a storage device such as the blockchain transaction receipt in the aforementioned embodiments.

[0181] The computer device 800 may be an electronic device capable of implementing the functions related to each step in the above-mentioned method embodiments. The computer device 800 may be a desktop computer, a cloud server, etc. The computer device 800 may include, but is not limited to, a processor 810 and a memory 820. Those skilled in the art will understand that Figure 8 This is only an example of the computer device 800 and does not constitute a limitation of the computer device 800. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device 800 may also include input and output devices, network access devices, buses, etc.

[0182] The processor 810 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0183] The memory 820 may be an internal storage unit of the computer device 800, such as a hard disk or memory of the computer device 800. The memory 820 may also be an external storage device of the computer device 800, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device 800. Further, the memory 820 may also include both an internal storage unit of the computer device 800 and an external storage device. The memory 820 is used to store the computer program 821 and other programs and data required by the computer device 800. The memory 820 may also be used to temporarily store data that has been output or is to be output.

[0184] An embodiment of the present application further discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the methods described in the above embodiments are implemented.

[0185] The embodiments of the present application further disclose a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a computer, the methods described in the above embodiments are implemented.

[0186] The embodiments of the present application further disclose a computer program product, including a computer program. When the computer program is run on a computer, the computer is enabled to execute the methods described in the aforementioned embodiments.

[0187] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application is described in detail with reference to the above-mentioned embodiments, a person skilled in the art should understand that the technical solutions described in the above-mentioned embodiments can still be modified, or some of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.

Claims

1. A method for storing blockchain transaction receipts, characterized in that: include: receiving a transaction request and executing the transaction request, wherein the transaction request carries a transaction receipt strategy field, and the transaction receipt strategy field is used to characterize the storage method of transaction result data; If the storage mode represented by the transaction receipt strategy field is the first storage mode, then calculating the data hash of the transaction result data corresponding to the current transaction; Generate a first transaction receipt for the current transaction based on the data hash of the transaction result data, and store the first transaction receipt at the current node; The transaction result data is stored in the database corresponding to the current node.

2. The method according to claim 1, characterized in that The generating the first transaction receipt of the transaction based on the data hash of the transaction result data includes: Determine receipt metadata obtained by executing the transaction, where the receipt metadata at least includes a transaction hash of the transaction; Generate a first transaction receipt for the transaction according to the data hash of the transaction result data corresponding to the transaction and the receipt metadata.

3. The method according to claim 1, characterized in that The storing the transaction result data into a database corresponding to the current node includes: The transaction result data is stored in a cache database or a persistent database corresponding to the current node.

4. The method according to any one of claims 1 to 3, characterized in that: Also includes: If the storage method represented by the transaction receipt strategy field is the second storage method, a second transaction receipt for the transaction is generated based on the transaction result data corresponding to the transaction and the second transaction receipt is stored at the current node.

5. The method according to claim 4, characterized in that Also includes: After the execution of the block containing the transaction is completed, a block hash of the block is calculated, the block hash includes a transaction receipt root hash, the transaction receipt root hash is a hash value corresponding to the transaction receipt stored in the first storage method and the second storage method, and the transaction receipt includes a first transaction receipt and / or a second transaction receipt; The data consistency of each node is verified based on the transaction receipt root hash.

6. A method for querying blockchain transaction receipts, characterized in that: include: When receiving a transaction receipt query request, obtaining the transaction hash carried in the transaction receipt query request; Determine the storage method of the transaction result data of the current transaction to be queried according to the transaction hash; If the storage method of the transaction result data of the current transaction is the first storage method, obtaining the transaction result data corresponding to the current transaction in the database corresponding to the current node, and obtaining receipt metadata from the current node; Generate a first transaction receipt based on the transaction result data corresponding to the current transaction and the receipt metadata, and return the first transaction receipt to the requester; Wherein, the transaction result data is stored using the method described in any one of claims 1 to 5.

7. The method according to claim 6, characterized in that The acquiring the transaction result data corresponding to the current transaction in the database corresponding to the current node includes: Query and obtain the transaction result data corresponding to the current transaction in the cache database corresponding to the current node; If the transaction result data corresponding to the current transaction does not exist in the cache database, the transaction result data is queried from the persistent database corresponding to the current node.

8. The method according to claim 6 or 7, characterized in that: Also includes: If the storage method of the transaction result data of the transaction is the second storage method, the second transaction receipt corresponding to the transaction is obtained at the current node; wherein, when the second storage method is adopted, the second transaction receipt stored at the current node includes the transaction result data corresponding to the transaction and the receipt metadata.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the computer device is caused to implement the method according to any one of claims 1 to 8.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed, the method according to any one of claims 1 to 8 is executed.