Block chain data query method and device, electronic equipment and storage medium
By setting a local cache area on the client and detecting data identification, the problem of excessive interactions between the client and the blockchain network is solved, and the effect of reducing system pressure and improving data query speed is achieved.
Patent Information
- Application Number
- CN202311484904.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-08
- Publication Date
- 2025-05-09
AI Technical Summary
In the existing blockchain data query methods, the number of interactions between the client and the blockchain network is too high, resulting in increased system pressure and reduced data query speed.
Set a local cache area on the client, and detect whether there is a data identifier for the data to be queried. If it exists, data will be obtained from the cache. If it does not exist, a query request will be sent to the blockchain network and the received data content will be stored in the cache area.
It reduces the number of interactions between clients and blockchain networks, alleviates system pressure, and improves data query speed.
Smart Images

Figure CN119961315A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of blockchain data management, and specifically discloses a blockchain data query method, device, electronic device and storage medium. Background Art
[0002] Blockchain technology is also known as distributed shared ledger technology. It uses a specific consensus algorithm to perform distributed accounting in the entire blockchain network. It has the characteristics of decentralization, immutability, data transparency, and traceability.
[0003] As the number of functional modules in business systems built on blockchain technology increases, clients are increasingly querying on-chain data. The industry mostly uses software development kits (SDKs) to query on-chain data. Currently, the mainstream query methods include active requests and passive reception:
[0004] In the query process of active requests, each time the client executes a data query, it needs to call the SDK to send a query request to the blockchain network. Large batches of queries generated by different clients will increase system pressure and reduce the system's data processing capabilities.
[0005] In the passive query process, the client does not request data query from the blockchain network, but establishes a long link between the SDK and the blockchain network. When the data on the chain changes, the blockchain network pushes the specific changed data content. This method cannot obtain data on demand, and will cause the client to passively receive a large amount of data that is irrelevant to business needs, which will cause a waste of network resources.
[0006] Furthermore, both of the above query processes require the blockchain network to send data, and the data query speed is seriously affected by the network environment. When the network delay is high, the query speed will be reduced, which will in turn affect the processing efficiency of the business. Summary of the invention
[0007] The embodiments of the present application provide a blockchain data query method, device, electronic device and storage medium to reduce the number of interactions between a client and a blockchain network, alleviate system pressure, and increase data query speed.
[0008] In a first aspect, an embodiment of the present application provides a blockchain data query method, the method comprising:
[0009] In response to a query instruction for obtaining blockchain data, obtaining a first data identifier of the data to be queried;
[0010] Detecting whether the first data identifier is stored in the local cache area;
[0011] When the first data identifier is not stored, a query request carrying the first data identifier is sent to the blockchain network, and the first data content sent by the blockchain network is received, and the first data content is associated with the first data identifier and stored in the local cache area; wherein the first data content is: the data content corresponding to the data to be queried recorded in the blockchain network;
[0012] When the first data identifier is stored, second data content associated with the first data identifier is obtained from the local cache area.
[0013] In some possible implementations, each data identifier stored in the local cache area is set with a corresponding storage duration; after the first data content is associated with the first data identifier and stored in the local cache area, the method further includes:
[0014] A storage duration set for the first data identifier in the local cache area;
[0015] The method further comprises:
[0016] Periodically updating the storage duration of each data identifier in the local cache area, and obtaining expired data identifiers in the local cache area whose remaining storage duration is less than a first time threshold;
[0017] The expired data identifier and the data content associated with the expired data identifier are deleted from the local cache area.
[0018] In some possible implementations, before storing the first data content in association with the first data identifier in the local cache area, the method further includes:
[0019] Detecting whether the free capacity of the local cache area is greater than the capacity to be occupied; wherein the capacity to be occupied is determined according to the data volume of the first data content;
[0020] When the free capacity is not greater than the to-be-occupied capacity, obtaining the remaining storage duration of each data identifier in the local cache area;
[0021] According to the order of the remaining storage duration from small to large, each data identifier and the data content associated with each data identifier are deleted in sequence until the free capacity is greater than the to-be-occupied capacity.
[0022] In some possible implementations, after acquiring the second data content associated with the first data identifier from the local cache area, the method further includes:
[0023] The remaining storage duration of the first data identifier is increased to the storage duration set when the first data identifier is stored in the local cache.
[0024] In some possible implementations, the storage duration set for the first data content in the local cache area includes:
[0025] The number of queries for the to-be-queried data by the client within a preset time period is obtained, and the storage duration is set according to the number of queries.
[0026] In some possible implementations, the method further includes:
[0027] For multiple smart contracts deployed by the client, establish a first subscription event with the blockchain network; wherein the first subscription event is used to obtain data update content based on the status data generated by the multiple smart contracts from the blockchain network;
[0028] In response to a first subscription notification triggered by the blockchain network based on the first subscription event, obtaining first updated content of target state data and a second data identifier of the target state data; wherein the target state data includes: state data of a data update event generated when a transaction operation is executed based on at least one smart contract among the multiple smart contracts;
[0029] When the second data identifier is stored in the local cache area, the data content associated with the second data identifier in the local cache area is replaced with the first updated content.
[0030] In some possible implementations, after associating the first data content with the first data identifier and storing it in the local cache area, the method further includes:
[0031] When the data to be queried is status data of a smart contract, a second subscription event is established with the blockchain network for the data to be queried; wherein the second subscription event is used to obtain data update content of the data to be queried from the blockchain network;
[0032] In response to a second subscription notification triggered by the blockchain network based on the second subscription event, obtaining second updated content of the data to be queried from the blockchain network;
[0033] The data content associated with the first data identifier of the data to be queried in the local cache area is replaced with the second updated content.
[0034] In some possible implementations, the method further includes:
[0035] After deleting the data to be queried from the local cache area, canceling the second subscription event established with the blockchain network.
[0036] In a second aspect, the embodiment of the present application further provides a blockchain data query device, the device comprising:
[0037] An information acquisition unit, configured to execute, in response to a query instruction for acquiring blockchain data, acquiring a first data identifier of the data to be queried;
[0038] A cache detection unit, configured to detect whether the first data identifier is stored in the local cache area;
[0039] The data cache unit is configured to execute, when the first data identifier is not stored, sending a query request carrying the first data identifier to the blockchain network, receiving the first data content issued by the blockchain network, and associating the first data content with the first data identifier and storing it in the local cache area; wherein the first data content is: the data content corresponding to the data to be queried recorded in the blockchain network;
[0040] The data processing unit is configured to execute, when the first data identifier is stored, obtaining second data content associated with the first data identifier from the local cache area.
[0041] In some possible implementations, each data identifier stored in the local cache area is set with a corresponding storage duration; after performing the step of associating the first data content with the first data identifier and storing it in the local cache area, the data cache unit is further configured to:
[0042] A storage duration set for the first data identifier in the local cache area;
[0043] The data cache unit is further configured to: periodically update the storage duration of each data identifier in the local cache area, and obtain expired data identifiers in the local cache area whose remaining storage duration is less than a first time threshold;
[0044] The expired data identifier and the data content associated with the expired data identifier are deleted from the local cache area.
[0045] In some possible implementations, before performing the step of associating the first data content with the first data identifier and storing it in the local cache area, the data cache unit is further configured to:
[0046] Detecting whether the free capacity of the local cache area is greater than the capacity to be occupied; wherein the capacity to be occupied is determined according to the data volume of the first data content;
[0047] When the free capacity is not greater than the to-be-occupied capacity, obtaining the remaining storage duration of each data identifier in the local cache area;
[0048] According to the order of the remaining storage duration from small to large, each data identifier and the data content associated with each data identifier are deleted in sequence until the free capacity is greater than the to-be-occupied capacity.
[0049] In some possible implementations, after executing the step of acquiring the second data content associated with the first data identifier from the local cache area, the data processing unit is further configured to:
[0050] The remaining storage duration of the first data identifier is increased to the storage duration set when the first data identifier is stored in the local cache.
[0051] In some possible implementations, to perform the step of setting a storage duration for the first data content in the local cache area, the data cache unit is configured as follows:
[0052] The number of queries for the to-be-queried data by the client within a preset time period is obtained, and the storage duration is set according to the number of queries.
[0053] In some possible implementations, the data cache unit is further configured to:
[0054] For multiple smart contracts deployed by the client, establish a first subscription event with the blockchain network; wherein the first subscription event is used to obtain data update content based on the status data generated by the multiple smart contracts from the blockchain network;
[0055] In response to a first subscription notification triggered by the blockchain network based on the first subscription event, obtaining first updated content of target state data and a second data identifier of the target state data; wherein the target state data includes: state data of a data update event generated when a transaction operation is executed based on at least one smart contract among the multiple smart contracts;
[0056] When the second data identifier is stored in the local cache area, the data content associated with the second data identifier in the local cache area is replaced with the first updated content.
[0057] In some possible implementations, after performing the step of associating the first data content with the first data identifier and storing it in the local cache area, the data cache unit is further configured to:
[0058] When the data to be queried is status data of a smart contract, a second subscription event is established with the blockchain network for the data to be queried; wherein the second subscription event is used to obtain data update content of the data to be queried from the blockchain network;
[0059] In response to a second subscription notification triggered by the blockchain network based on the second subscription event, obtaining second updated content of the data to be queried from the blockchain network;
[0060] The data content associated with the first data identifier of the data to be queried in the local cache area is replaced with the second updated content.
[0061] In some possible implementations, the data cache unit is further configured to:
[0062] After deleting the data to be queried from the local cache area, canceling the second subscription event established with the blockchain network.
[0063] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a processor, a memory and a display, wherein the display provides a command line interface for receiving triggered operations, and the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of any of the above-mentioned blockchain data query methods.
[0064] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium on which computer-executable instructions are stored. When the computer-executable instructions are executed by a computer device, the steps of any of the above-mentioned blockchain data query methods are implemented.
[0065] In a fifth aspect, an embodiment of the present application also provides a computer program product, comprising a computer program, which implements the steps of any of the above-mentioned blockchain data query methods when executed by a computer device.
[0066] The beneficial effects of this application are as follows:
[0067] The embodiment of the present application provides a blockchain data query method, device, electronic device and storage medium. In the method, when a business system has a query demand for blockchain data, the client responds to a query instruction for obtaining blockchain data and obtains a first data identifier of the data to be queried. Then, it is preferentially detected whether the first data identifier is stored in the local cache area.
[0068] When the first data identifier is not stored in the local cache area, a query request carrying the first data identifier is sent to the blockchain network to actively request the blockchain network to send the data content of the data to be queried recorded in the blockchain network to the client. After receiving the first data content sent by the blockchain network, the client associates the first data content with the first data identifier and stores it in the local cache area. In this way, when the client queries the data to be queried again, the corresponding data content can be extracted from the local cache area without interacting with the blockchain network.
[0069] Correspondingly, when the first data identifier is stored in the local cache area, the second data content associated with the first data identifier can be directly obtained from the local cache area without interacting with the blockchain network. This reduces the number of interactions between the client and the blockchain network, relieves system pressure, and improves data query speed.
[0070] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0072] Figure 1 A schematic diagram of a business system based on blockchain technology provided in an embodiment of the present application;
[0073] Figure 2 A schematic diagram of a query process for an active request provided in an embodiment of the present application;
[0074] Figure 3 A schematic diagram of a query process for passive reception provided in an embodiment of the present application;
[0075] Figure 4 An overall flow chart of a blockchain data query method provided in an embodiment of the present application;
[0076] Figure 5 A schematic diagram of the cache configuration of blockchain data provided in an embodiment of the present application;
[0077] Figure 6 A schematic diagram of the composition of a smart contract provided in an embodiment of the present application;
[0078] Figure 7 A schematic diagram of executing a transaction operation based on a smart contract provided in an embodiment of the present application;
[0079] Figure 8 A schematic diagram of obtaining data to be queried from a blockchain network provided in an embodiment of the present application;
[0080] Fig. 9 A schematic diagram of an expired cache record provided in an embodiment of the present application;
[0081] Fig.10 A schematic diagram of another expired cache record provided in an embodiment of the present application;
[0082] Fig.11 A schematic diagram of periodically clearing cache provided in an embodiment of the present application;
[0083] Fig.12 A schematic diagram of clearing expiring data from a local cache area provided in an embodiment of the present application;
[0084] Fig.13 A schematic diagram of increasing storage duration provided in an embodiment of the present application;
[0085] Fig.14 A processing flow chart of a first subscription event provided in an embodiment of the present application;
[0086] Fig.15 A processing flow chart of a second subscription event provided in an embodiment of the present application;
[0087] Fig.16 A structural diagram of a blockchain data query device provided in an embodiment of the present application;
[0088] Fig.17 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0089] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the technical solution of the present application, rather than all of the embodiments. Based on the embodiments recorded in the application documents, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the technical solution of the present application.
[0090] The following is an introduction to some concepts involved in the embodiments of the present application.
[0091] Software Development Kit (SDK): It is a set of development tools for building application software using specific software packages, software frameworks, hardware platforms, operating systems, etc. In the blockchain data query scenario, SDK is used to build an interactive bridge between the client and the blockchain network. The client can use SDK to query and modify the data on the chain.
[0092] Remote Procedure Call (RPC): is a protocol for requesting services from a remote computer program over a network without having to understand the underlying network technology. The main functional goal of the RPC service is to make it easier to build distributed computing (applications) while providing powerful remote calling capabilities without losing the semantic simplicity of local calls.
[0093] Cache: A hardware or software component embedded in the memory of an application or device that automatically and temporarily stores data used by the user to reduce the data retrieval time the next time the application or device is accessed. Compared with data stored in a server or hard disk, cached data can be modified and read very quickly.
[0094] The following is a brief introduction to the design concept of the embodiment of the present application:
[0095] With the continuous development and application of blockchain technology, building business systems based on blockchain technology has gradually become an important part of enterprise digital transformation. More and more companies are beginning to adopt blockchain technology in their business process environments to improve the efficiency and security of their business processes.
[0096] Figure 1 An example of a distributed business system based on blockchain technology is shown. The distributed system 100 is composed of multiple nodes 200 (any form of computing devices in the access network, such as servers and user terminals), and each node 200 forms a peer-to-peer network. Peer-to-peer is an application layer protocol running on the Transmission Control Protocol (TCP).
[0097] It should be noted that any machine (such as a server or a terminal) can be added to the distributed system and become a node. The node 200 in the aforementioned distributed system 100 may include a hardware layer, an intermediate layer, an operating system layer, and an application layer. Figure 1 The functions of each node 200 shown are introduced, and the node 200 may include the following functions:
[0098] 1) Routing: a basic function of a node, used to support communication between nodes.
[0099] In addition to the routing function, the node can also have the following functions:
[0100] 2) Applications are deployed in the blockchain to implement specific businesses based on actual business needs, record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system for other nodes to add the record data to a temporary block when they successfully verify the source and integrity of the record data.
[0101] For example, the services implemented by the application include:
[0102] 2.1) Wallet, used to provide the function of conducting electronic currency transactions, including initiating transactions (i.e., sending the transaction record of the current transaction to other nodes in the blockchain system. After the other nodes successfully verify the transaction, as a response to acknowledge the validity of the transaction, the transaction record data is stored in the temporary block of the blockchain; of course, the wallet also supports querying the remaining electronic currency in the electronic currency address;
[0103] 2.2) Shared ledger, which is used to provide functions such as storage, query and modification of account data. The record data of the operation on the account data is sent to other nodes in the blockchain system. After other nodes verify the validity, as a response to acknowledging the validity of the account data, the record data is stored in a temporary block, and a confirmation can also be sent to the node that initiated the operation.
[0104] 2.3) Smart contracts are computerized protocols that can execute the terms of a contract. They are implemented by deploying code on a shared ledger that is executed when certain conditions are met. The code is used to complete automated transactions based on actual business needs, such as querying the logistics status of the goods purchased by the buyer and transferring the buyer's electronic currency to the merchant's address after the buyer signs for the goods. Of course, smart contracts are not limited to executing contracts for transactions, but can also execute contracts for processing received information.
[0105] 3) Blockchain, including a series of blocks that are connected to each other in the order of their generation. Once a new block is added to the blockchain, it will not be removed. The block records the record data submitted by the nodes in the blockchain system.
[0106] In actual applications, the client 300 can interact with the blockchain network through a preset software development kit SDK to query the data on the chain. The mainstream query methods in the industry include active request and passive reception, as follows: Figure 2 and Figure 3 As shown:
[0107] The query process for active requests is as follows: Figure 2As shown in the figure, when the client has a data query demand, it actively sends a query request to the blockchain network by calling the SDK. After receiving the request, the blockchain network will obtain the data from the on-chain storage space by executing the query contract, and send the requested query data content to the client based on the RPC protocol.
[0108] pass Figure 2 As can be seen from the process shown, in the active query process, each time the client executes a data query, it needs to call the SDK to send a query request to the blockchain network. Large batches of queries generated by different clients will increase system pressure and reduce the system's data processing capacity.
[0109] The query process for passive reception is as follows: Figure 3 As shown, the client pre-establishes a long link with the blockchain network through the SDK. When the data on the chain changes (for example, new data is uploaded to the chain, or the data content changes), the blockchain network notifies the client by pushing the specific changed data content to the SDK.
[0110] pass Figure 3 As can be seen from the process shown, in the passive receiving query process, the blockchain network pushes the specific changed data content to the client. This method cannot obtain data on demand, and will cause the client to passively receive a large amount of data that is irrelevant to business needs, which will cause a waste of network resources.
[0111] Furthermore, both of the above query processes require the blockchain network to send data, and the data query speed is seriously affected by the network environment. When the network delay is high, the data query speed will be significantly reduced, which will in turn affect the business processing efficiency of the system.
[0112] In view of this, the embodiments of the present application provide a blockchain data query method, device, electronic device and storage medium. In the method, a local cache area pre-established on the client, when the business system has a query demand for blockchain data, responds to a query instruction for obtaining blockchain data, and obtains a first data identifier of the data to be queried. Next, it is detected whether the first data identifier is stored in the local cache area.
[0113] If the first data identifier is not stored in the local cache area, a query request carrying the first data identifier is sent to the blockchain network to actively request the blockchain network to send the data content recorded in the blockchain network of the data to be queried to the client.
[0114] After receiving the first data content sent by the blockchain network, the first data content is associated with the first data identifier and stored in the local cache area. In this way, when the client queries the data to be queried again, the corresponding data content can be extracted from the local cache area without interacting with the blockchain network. Correspondingly, if the first data identifier is stored in the local cache area, the second data content associated with the first data identifier can be directly obtained from the local cache area.
[0115] In the above process, by caching the data content of the blockchain data that the client has queried, when the client queries data, the data content of the data to be queried is obtained from the local cache area first, and when the data to be queried is not stored in the local cache area, the data is obtained from the blockchain network. In this way, the number of interactions between the client and the blockchain network can be effectively reduced, the system pressure can be relieved, and the data query speed can be improved.
[0116] Next, the preferred embodiments of the present application are described in conjunction with the drawings in the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application, and are not used to limit the technical solutions of the present application. In addition, the embodiments of the present application and the features therein may be combined with each other if there is no conflict.
[0117] See also Figure 4 , Figure 4 The overall process of a blockchain data query method provided by an embodiment of the present application is shown, including the following steps:
[0118] Step 401: In response to a query instruction for obtaining blockchain data, obtain a first data identifier of the data to be queried;
[0119] In actual applications, business systems often use Key-Value data structures to record on-chain data generated by the business. When there is a need to query a certain blockchain data, the blockchain data is used as the data to be queried, and by triggering a query instruction for the data to be queried, the first data identifier of the data to be queried (i.e., the Key of the data to be queried) is notified to the client, so that the client can obtain the data content corresponding to the first data identifier.
[0120] Step 402: Detect whether the first data identifier is stored in the local cache area;
[0121] In the embodiment of the present application, a local cache area is generated by establishing a Key-Value cache structure in the client's memory. The Key in the cache structure represents the name of the cached blockchain data, and the Value represents the data content of the blockchain data corresponding to the cache Key.
[0122] In practical applications, blockchain data includes block data and transaction data that cannot be tampered with after being uploaded to the chain, as well as status data whose data content can be changed according to the preset rules of the smart contract. The embodiment of the present application sets corresponding Key-Value cache structures for the above-mentioned different types of blockchain data. The cache configuration of the above-mentioned types of blockchain data can be as follows: Figure 5 As shown:
[0123] In the cache structure for block data, the Key is defined as "block_[block height]". For example, if a cache for a block is established, the block height is 10, and the data content blockValue is 123. Then the storage content of the block data in the cache is "block_
[10] :123".
[0124] In the cache structure for transaction data, the Key is defined as "tx_[transaction ID]". For example, the client generates a transaction through the blockchain network, the transaction ID is 1765fe50354, and the specific transaction data content txValue is 1234. Then, the storage content of the transaction data in the cache is "tx_[1765fe50354]:1234".
[0125] In the cache structure for state data, the key is defined as "statu_[contract name]_[state data name]". To facilitate understanding of the above expression for state data, we first briefly explain the relationship between state data and smart contracts. Figure 6 As shown, the smart contract is deployed with trigger conditions, preset response rules and status data based on the contract content. When external data or events meet the trigger conditions of the smart contract, the data content of each status data is updated by executing the preset response rules.
[0126] Figure 7 The example shows a smart contract Contract 1 for flight delay compensation. The triggering conditions of the smart contract are: the flight departure time is input, and the deposit is deposited in the smart contract. The preset response rule is: if the flight is delayed for 2 hours, the deposit will be transferred to the customer account, otherwise, the deposit will be transferred to the company account.
[0127] Among them, the status data of the smart contract Contract1 may include: whether the plane takes off (testKey1), whether the deposit is paid (testKey2), etc.
[0128] When customer A purchases the insurance, the insurance company will deposit the insurance money into the smart contract, and trigger condition 1 in the smart contract is triggered. Assuming that the plane takes off at 8:00, after the departure time is entered at 8:00, trigger condition 2 in the smart contract is triggered. After all the trigger conditions of the smart contract are triggered, the smart contract begins to execute the preset response rules: when the plane takes off, the data content testValue of the status data testKey1 will change from the original value 0, which indicates that the plane has not taken off, to the value 1, which indicates that the plane has taken off.
[0129] Assuming that the take-off time of the plane is delayed by 2 hours, the deposit will be transferred to the account of customer A according to the contract. After the deposit is transferred to customer A's account, the data content testValue of the aforementioned status data testKey2 will change from the value 0 indicating that the deposit has not been paid to the value 1 indicating that the deposit has been paid.
[0130] Taking the above-mentioned state data testKey1 as an example, after the aircraft takes off, the storage content of the state data in the local cache area is the above-mentioned Figure 5 "statu_[Contract1]_[testKey1]:1" is shown.
[0131] After the local cache area is established through the above process, when the first data identifier of the above step 401 is obtained, it is pre-detected whether the local cache area has the first data identifier. If the first data identifier is stored in the local cache area, jump to the following step 403. Correspondingly, if the first data identifier is not stored in the local cache area, jump to the following step 404.
[0132] Step 403: When the first data identifier is not stored, a query request carrying the first data identifier is sent to the blockchain network, and the first data content sent by the blockchain network is received, and the first data content is associated with the first data identifier and stored in the local cache area; wherein the first data content is: the data content corresponding to the data to be queried recorded in the blockchain network;
[0133] When implementing Figure 8 As shown, assuming that the data to be queried is blockchain data of transaction type, its first data identifier is "tx_[1765fe50354]". Then, when the first data identifier "tx_[1765fe50354]" of the data to be queried is not stored in the local cache area, the client will send a query request carrying the first data identifier "tx_[1765fe50354]" to the blockchain network. After receiving the query request, the blockchain network will send the blockchain data corresponding to the first data identifier tx_[1765fe50354] (that is, the aforementioned data to be queried) and the first data content "1234" recorded in the blockchain network to the client through the SDK.
[0134] After the client receives the first data content "1234", it will generate a local cache record carrying the first data content "1234" and the first data identifier "tx_[1765fe50354]" in the local cache area using the cache structure of transaction data. That is, Figure 8 The local cache record of the data to be queried is shown in “tx_[1765fe50354]:1234”.
[0135] It should be noted that the storage capacity of the local cache area should not be set too large, otherwise it will occupy too much memory resources of the client and cause the client's data processing speed to decrease. Based on this, the embodiment of the present application is provided with a corresponding storage duration for each data identifier stored in the local cache area.
[0136] During implementation, an expired cache record corresponding to the aforementioned cache structure may be set. The expired cache record is also composed of a Key-Value data structure. The Key of the expired cache record is the same as the cache structure, both representing the blockchain data in the cache. The difference is that the Value of the cache structure represents the data content recorded by the blockchain data in the blockchain network, while the Value of the expired cache record represents the remaining storage time of the blockchain data in the local cache area.
[0137] After the first data content is associated with the first data identifier and stored in the local cache area, a storage duration in the local cache area is set for the first data identifier.
[0138] During implementation, a fixed storage duration adding logic may be set, for example, whenever new data is added to the local cache area, a fixed storage duration (for example, 10 minutes) is added to the data. Figure 8 The following example illustrates the Fig. 9 As shown. Figure 8 In the process shown, after adding the local cache record "tx_[1765fe50354]:1234" of the data to be queried in the local cache area, an expired cache record "tx_[1765fe50354]_10:00" that satisfies the above-mentioned expired cache structure is generated based on the first data identifier of the data to be queried. Thus, a storage duration of 10 minutes is added to the local cache record "tx_[1765fe50354]:1234".
[0139] It should be noted that the Value (storage duration) in the aforementioned expired cache record is equivalent to a timer. After the expired cache record corresponding to the local cache record is generated, the timer starts. When the remaining time of the timer is 0 (that is, the aforementioned expired cache record is changed from "tx_[1765fe50354]_10:00" to "tx_[1765fe50354]_00:00", indicating that the remaining storage duration of the local cache record "tx_[1765fe50354]:1234" is 0), the local cache record "tx_[1765fe50354]:1234" is deleted from the local cache area to achieve the purpose of clearing the cache.
[0140] In some possible implementations, the Value of the expired cache structure can be set to the expiration time. Figure 8 The following example illustrates the Fig.10 As shown. Figure 8 The first data identifier and the first data content of the data to be queried are stored in the local cache area, and a local cache record "tx_[1765fe50354]:1234" is obtained.
[0141] Next, the generation time of the local cache record is read: 2023 / 1 / 1-0:00:15 (year / month / day-hour / minute / second), and a fixed storage duration (10 minutes) is added to the generation time "2023 / 1 / 1-0:00:15" to obtain the corresponding expiration time "2023 / 1 / 1-0:10:15". At this time, the expired cache record of the data to be queried can be expressed as "tx_[1765fe50354]:2023 / 1 / 1-0:00:15", which means that when the current time reaches "2023 / 1 / 1-0:10:15", the local cache record "tx_[1765fe50354]:1234" needs to be deleted from the local cache area.
[0142] In addition, when new data is added to the local cache area, the number of queries the client makes for the data within a preset period (e.g., 3 hours) can be obtained, and the storage duration of the data in the local cache area can be calculated based on the number of queries for the data.
[0143] In some possible implementations, a fixed unit storage duration (e.g., 3 minutes) is preset. When the client performs 5 query operations on the data within the last 3 hours, the storage duration set for the data is 5×3=15 minutes. Correspondingly, when the client performs 6 query operations on the data within the last 3 hours, the storage duration set for the data is 6×3=18 minutes.
[0144] The number of queries a client makes for data within a period of time can indicate the importance of the data in the business process. Through the above process, you can set a longer storage period for data that is frequently queried by the client to prevent the data from being cleared from the cache prematurely due to expiration of the storage period.
[0145] In the embodiment of the present application, the storage duration of each data identifier in the local cache area is periodically updated. In specific implementation, the storage duration of each data identifier in the local cache area can be periodically obtained to obtain the expired data identifiers in the local cache area whose remaining storage duration is less than the first time threshold. Then, the obtained expired data identifiers and the data content associated with the expired data identifiers are deleted from the local cache area.
[0146] With the aforementioned Fig. 9 The example is as follows. Fig.11 As shown. The client reads the expired cache records stored in the local cache area every 1 second to obtain the remaining storage time of each data identifier in the local cache area. Then, the data identifier with a remaining storage time of 0 is used as the expired data identifier.
[0147] For example Fig.11 As shown, the local cache record "tx_[1765fe50354]:1234" corresponds to the expired cache record tx_[1765fe50354]_00:00. At this time, the data identifier "tx_[1765fe50354]" of the local cache record is used as the expired data identifier, and the expired data identifier and the data content associated with the expired data identifier (i.e., the local cache record "tx_[1765fe50354]_00:00") are deleted from the local cache area. Along with the deletion of the local cache record, the expired cache record "tx_[1765fe50354]_00:00" generated based on the data identifier "tx_[1765fe50354]" of the local cache record will also be deleted. In this way, all records related to the expired data identifier "tx_[1765fe50354]" (local cache records and expired cache records) are deleted from the local cache area.
[0148] In some possible implementations, before storing new data in the local cache area (ie, storing the first data content in association with the first data identifier as described above), it is necessary to pre-detect whether the free capacity of the local cache area is greater than the capacity to be occupied.
[0149] The capacity to be occupied is determined according to the newly stored data content. Specifically, the cache capacity occupied by the first data content may be multiplied by a preset weight (eg, 1.25) to obtain the capacity to be occupied required for storing the first data content in association with the first data identifier.
[0150] When the free capacity is not greater than the capacity to be occupied, it means that the local cache area does not have enough space to store new data. At this time, the expiring data in the local cache area is deleted to clear enough space for storing the first data content and the first data identifier.
[0151] For example Fig.12 As shown in , the storage duration of each expired cache record in the local cache area (i.e., the remaining storage duration of each data identifier) can be read in advance during implementation. Then, each data identifier and the data content associated with each data identifier are deleted in order from small to large according to the remaining storage duration (i.e., the local cache record and expired cache record composed of each data identifier are deleted synchronously), until the free capacity of the local cache area is greater than the capacity to be occupied, and the new data to be cached (i.e., the first data content and the first data identifier mentioned above) are stored in the local cache area.
[0152] Step 404: when the first data identifier is stored, obtain the second data content associated with the first data identifier from the local cache area.
[0153] As mentioned above, the more frequently the client queries data, the more important the data is in the business process. Based on this, the embodiment of the present application needs to increase the remaining storage time of the data in the local cache area after obtaining the local cache record of the data to be queried from the local cache area according to the query instruction issued by the client each time.
[0154] In specific implementation, after obtaining the second data content associated with the first data identifier in step 404, the remaining storage duration of the first data identifier may be increased to the storage duration set when storing it in the local cache. Fig. 9 The following example illustrates the Fig.13 shown.
[0155] Assume that the first data identifier of the data to be queried is Fig. 9 The local cache area is queried through the first data identifier tx_[1765fe50354] to obtain the local cache record "tx_[1765fe50354]:1234" corresponding to the first data identifier tx_[1765fe50354] and the expired cache record "tx_[1765fe50354]:01:17".
[0156] After obtaining the first data identifier and the first data content (i.e., the local cache record "tx_[1765fe50354]:1234"), the remaining storage duration "1:17" in the expired cache record "tx_[1765fe50354]:01:17" corresponding to the first data identifier is increased to the duration when the expired cache record corresponding to the first data identifier was just generated (i.e., ten minutes). At this time, in the local cache area, the expired cache record corresponding to the first data identifier is updated to "tx_[1765fe50354]:10:00".
[0157] As mentioned above, there is a special kind of data (state data) in blockchain data, and the data content recorded on the blockchain can be updated according to the response strategy preset by the smart contract. Based on this, the embodiment of the present application establishes a subscription event between the client and the blockchain network to ensure the consistency of the data content stored in the local cache area with the records on the chain. Fig.14 As shown, the following steps are included:
[0158] Step 1401: Establish a first subscription event with the blockchain network for multiple smart contracts deployed by the client; wherein the first subscription event is used to obtain data update content based on status data generated by the multiple smart contracts from the blockchain network.
[0159] During implementation, the cache configuration of the state data can be read in advance to obtain the name of the state data contained in each smart contract deployed by the client. Then, based on the state data name, the first subscription event for obtaining the on-chain changes of the state data is established. That is, assuming that the client has deployed 200 smart contracts, each of which has 10 state data, then there are a total of 2,000 state data under all deployed smart contracts. Then, the first subscription event established by the client and the blockchain network is used to obtain the data content changes recorded on the chain for each of the 2,000 state data.
[0160] Step 1402: receiving a first subscription notification, obtaining first update content of the target state data, and a second data identifier of the target state data;
[0161] When the data content recorded in the chain of any state data is updated, the blockchain network will send a first subscription notification triggered by the first subscription event to SKD. The first subscription notification carries the first updated content of the target state data and the second data identifier of the target state data.
[0162] The target state data is the state data of the data update event generated when executing a transaction operation based on at least one of the multiple smart contracts deployed above (i.e., the state data of any change in the content on the chain). The first update content is the latest data content recorded on the chain of the target state data. The second data identifier is the cache key of the target state data, which is the same as the cache key of the target state data. Figure 5 Taking the status data testKey1 shown as an example, when the data content recorded in the blockchain network of the status data changes, the first subscription event issued by the blockchain network includes the second data identifier "testKey1" of the status data and the first update content recorded in the blockchain network of the status data.
[0163] Step 1403: Detect whether the second data identifier is stored in the local cache area;
[0164] Step 1404: If the second data identifier is not stored, the first subscription notification received this time is ignored;
[0165] If the second data identifier is not stored in the local cache area, there is no need to perform any processing on the local cache area, and the first subscription notification received this time can be ignored.
[0166] Step 1405: If the second data identifier is stored, then detecting whether there is enough space in the local cache area to store the first update content;
[0167] During implementation, the data content associated with the second data identifier stored in the local cache area can be obtained, and then the data volume of the first updated content is subtracted from the data volume of the associated data content to obtain the storage capacity required for the local cache area to replace the data content associated with the second data identifier stored with the first updated content.
[0168] When the storage capacity required by the first update content is greater than the current free capacity of the local cache area, it means that the local cache area has enough space to store the first update content. At this time, the process can jump to the following step 1407 to update the local cache record of the target state data.
[0169] Correspondingly, when the storage capacity required for the first update content is not greater than the free capacity, it means that the current remaining storage space in the local cache is insufficient to support the storage of the first update content. At this time, it is necessary to jump to the following step 1406 to clean up the local cache.
[0170] Step 1406: If there is not enough space, clear out enough storage space from the cache that is about to expire;
[0171] When implementing it specifically, the above-mentioned Fig.12The cache clearing process shown in the figure reads the remaining storage time of each data identifier in the local cache area. Then, according to the order of the remaining storage time from small to large, delete each data identifier and the data content associated with each data identifier in turn until the free capacity of the local cache area is sufficient to store the first updated content.
[0172] Step 1407: If there is enough space, the data content associated with the second data identifier in the local cache area is replaced with the first updated content.
[0173] When the second data identifier is stored in the local cache area, the data content associated with the second data identifier in the local cache area needs to be replaced with the first updated content. In this way, the local cache record update of the target state data is completed. The above process can ensure that the data content obtained by the client from the local cache area is consistent with the record on the chain.
[0174] In addition, considering that the above process is to subscribe to the on-chain changes of all status data in the business system, the blockchain network will notify the client of the data update content of the status data that is not stored in the local cache. The client needs to share some resources to check whether the target status data with updated content is stored in the local cache.
[0175] In order to reduce the resource usage of the client, a second subscription event can be established to obtain the on-chain data content changes of the state data when the state data is stored in the local cache. For example, after the first data content in the above step 403 is associated with the first data identifier and stored in the local cache, Fig.15 The process shown establishes a subscription event between the client and the blockchain network, including the following steps:
[0176] Step 1501: associate and store first data content and a first data identifier;
[0177] Step 1502: Detect whether the data type of the data to be queried is status data;
[0178] Step 1503: If it is status data, a second subscription event is established with the blockchain network for the data to be queried; otherwise, it means that the on-chain content of the blockchain data stored this time is fixed and unchanged, and there will be no inconsistency between the cache and the chain, and the processing can be terminated at this time.
[0179] During implementation, the cache configuration of the data to be queried can be read in advance to obtain the state data name of the data to be queried. Figure 5 Taking the cache configuration of the status data shown as an example, a second subscription event is established between the SDK and the blockchain network for the status data statue_[Contract1]_[testKey1].
[0180] The second subscription event can be represented by the following code: sdk.Instance.EmitEvent("testEvent",[]string{testKey1,testValue1}. That is, the second subscription event is used to obtain the data update content (testValue1) recorded in the blockchain network for the data to be queried (testKey1).
[0181] Step 1504: In response to a second subscription notification triggered by the blockchain network based on the second subscription event, obtaining second updated content of the to-be-queried data from the blockchain network;
[0182] Step 1505: Detect whether there is enough space in the local cache area to store the second update content;
[0183] During implementation, the data content associated with the data to be queried in the local cache area can be obtained, and then the data volume of the second updated content is subtracted from the data volume of the data content in the local cache area to obtain the storage capacity required for the local cache area to replace the data content of the stored data to be queried with the second updated content.
[0184] When the storage capacity required for the second update content is greater than the current free capacity of the local cache area, it means that the local cache area has enough space to store the second update content. At this time, the process can jump to the following step 1507 to update the local cache record of the data to be queried.
[0185] Correspondingly, when the storage capacity required for the second updated content is not greater than the free capacity, it means that the current remaining storage space in the local cache is insufficient to support the storage of the second updated content. At this time, it is necessary to jump to the following step 1506 to clear the local cache.
[0186] Step 1506: If there is not enough space, clear out enough storage space from the cache that is about to expire;
[0187] When implementing, the above Fig.12 The clear cache process shown reads the remaining storage time of each data identifier in the local cache area, and then deletes each data identifier and the data content associated with each data identifier in order from small to large remaining storage time, until the free capacity of the local cache area is sufficient to store the first updated content.
[0188] Step 1507: If there is enough space, the data content associated with the first data identifier of the data to be queried in the local cache area is replaced with the second updated content.
[0189] In the above steps 1501 to 1507, subscription events are only established for the state data stored in the local cache. When a state data is deleted from the local cache, the second subscription event for the state data established with the blockchain network will be canceled synchronously. Fig.14 In the process shown, the client does not need to share resources to check whether there is updated content data in the local cache area, which reduces the resource usage of the client.
[0190] The technical solution provided by the embodiment of the present application pre-builds a local cache area to cache the data content of the blockchain data that has been queried by the client. When the client queries data, the data content of the data to be queried is obtained from the local cache area first, and when the data to be queried is not stored in the local cache area, the data is obtained from the blockchain network. In this way, the number of interactions between the client and the blockchain network can be effectively reduced, the system pressure can be relieved, and the data query speed can be improved.
[0191] Based on the same inventive concept, the present application embodiment also provides a blockchain data query device 160, specifically as follows Fig.16 As shown, including:
[0192] The information acquisition unit 161 is configured to execute, in response to a query instruction for acquiring blockchain data, acquiring a first data identifier of the data to be queried;
[0193] The cache detection unit 162 is configured to detect whether the first data identifier is stored in the local cache area;
[0194] The data cache unit 163 is configured to execute, when the first data identifier is not stored, sending a query request carrying the first data identifier to the blockchain network, receiving the first data content issued by the blockchain network, and associating the first data content with the first data identifier and storing it in a local cache area; wherein the first data content is: the data content corresponding to the data to be queried recorded in the blockchain network;
[0195] The data processing unit 164 is configured to execute, when the first data identifier is stored, obtaining the second data content associated with the first data identifier from the local cache area.
[0196] In some possible implementations, each data identifier stored in the local cache area is set with a corresponding storage duration; after the first data content is associated with the first data identifier and stored in the local cache area, the data cache unit 163 is further configured to:
[0197] A storage duration set for the first data identifier in the local cache area;
[0198] The data cache unit 163 is further configured to: periodically update the storage duration of each data identifier in the local cache area, and obtain expired data identifiers in the local cache area whose remaining storage duration is less than the first time threshold;
[0199] The expired data identifier and the data content associated with the expired data identifier are deleted from the local cache area.
[0200] In some possible implementations, before storing the first data content in association with the first data identifier in the local cache area, the data cache unit 163 is further configured to:
[0201] Detecting whether the free capacity of the local cache area is greater than the capacity to be occupied; wherein the capacity to be occupied is determined according to the data volume of the first data content;
[0202] When the free capacity is not greater than the capacity to be occupied, the remaining storage time of each data identifier in the local cache area is obtained;
[0203] According to the order of the remaining storage time from small to large, each data identifier and the data content associated with each data identifier are deleted in sequence until the free capacity is larger than the capacity to be occupied.
[0204] In some possible implementations, after obtaining the second data content associated with the first data identifier from the local cache area, the data processing unit 164 is further configured to:
[0205] The remaining storage duration of the second data content is increased to the storage duration set when the second data content is stored in the local cache.
[0206] In some possible implementations, the storage duration in the local cache area is set for the first data content, and the data cache unit 163 is configured as follows:
[0207] The number of queries for the data to be queried by the client within a preset time period is obtained, and the storage duration is set according to the number of queries.
[0208] In some possible implementations, the data cache unit 163 is further configured to:
[0209] For multiple smart contracts deployed by the client, establish a first subscription event with the blockchain network; wherein the first subscription event is used to obtain data update content based on the status data generated by the multiple smart contracts from the blockchain network;
[0210] In response to a first subscription notification triggered by the blockchain network based on the first subscription event, obtaining first updated content of the target state data and a second data identifier of the target state data; wherein the target state data includes: state data of a data update event generated when a transaction operation is executed based on at least one smart contract among the multiple smart contracts;
[0211] When the second data identifier is stored in the local cache area, the data content associated with the second data identifier in the local cache area is replaced with the first updated content.
[0212] In some possible implementations, after the first data content is associated with the first data identifier and stored in the local cache area, the data cache unit 163 is further configured to:
[0213] When the data to be queried is status data of a smart contract, a second subscription event is established with the blockchain network for the data to be queried; wherein the second subscription event is used to obtain data update content of the data to be queried from the blockchain network;
[0214] In response to a second subscription notification triggered by the blockchain network based on the second subscription event, obtaining second updated content of the to-be-queried data from the blockchain network;
[0215] The data content associated with the first data identifier of the data to be queried in the local cache area is replaced with the second updated content.
[0216] In some possible implementations, the data cache unit 163 is further configured to:
[0217] After deleting the data to be queried from the local cache area, the second subscription event established with the blockchain network is canceled.
[0218] Based on the same inventive concept as the above method embodiment, an electronic device is also provided in the embodiment of the present application. In one embodiment, the electronic device can be a single server, a distributed cluster including multiple servers, or a terminal device. In this embodiment, the structure of the electronic device can be as follows: Fig.17 As shown, it includes a memory 171 , a communication module 173 and one or more processors 172 .
[0219] The memory 171 is used to store computer programs executed by the processor 172. The memory 171 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and an operating instruction set.
[0220] The memory 171 may be a volatile memory, such as a random-access memory (RAM); the memory 171 may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); or the memory 171 may be any other medium that can be used to carry or store a desired computer program in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 171 may be a combination of the above memories.
[0221] The processor 172 may include one or more central processing units (CPU) or a digital processing unit, etc. The processor 172 is used to implement the above rendering abnormality detection method when calling the computer program stored in the memory 171.
[0222] The communication module 173 is used to communicate with terminal devices and other servers.
[0223] The specific connection medium between the memory 171, the communication module 173 and the processor 172 is not limited in the embodiment of the present application. Fig.17 The memory 171 and the processor 172 are connected via a bus 174. Fig.17 The connections between the other components are only for illustration and are not intended to be limiting. The bus 174 can be divided into an address bus, a data bus, a control bus, etc. For ease of description, Fig.17 The diagram shows that only one thick line is used, but this does not mean that there is only one bus or only one type of bus.
[0224] The memory 171 stores a computer storage medium, and the computer storage medium stores computer executable instructions, and the computer executable instructions are used to implement the rendering anomaly detection method of the embodiment of the present application. The processor 172 is used to execute the steps of the above rendering anomaly detection method.
[0225] In some possible implementations, various aspects of the data classification method provided by the present application may also be implemented in the form of a program product, which includes a computer program. When the program product is run on an electronic device, the computer program is used to enable the electronic device to execute the steps of the rendering anomaly detection method according to various exemplary implementations of the present application described above in this specification.
[0226] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical fiber, a portable compact disk read-only memory, an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0227] The program product of the embodiment of the present application may adopt a portable compact disk read-only memory and include a computer program, and can be run on an electronic device. However, the program product of the present application is not limited thereto, and in this document, a readable storage medium may be any tangible medium containing or storing a program, which can be used by or in combination with a command execution system, apparatus, or device.
[0228] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein a readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A readable signal medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with a command execution system, apparatus, or device.
[0229] The computer program embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0230] The computer program for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The computer program may be executed entirely on the user computing device, partially on the user computing device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device via any type of network, including a local area network or a wide area network, or may be connected to an external computing device.
[0231] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain a computer-usable computer program.
[0232] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
Claims
1. A blockchain data query method, characterized in that: The method comprises: In response to a query instruction for obtaining blockchain data, obtaining a first data identifier of the data to be queried; Detecting whether the first data identifier is stored in the local cache area; When the first data identifier is not stored, a query request carrying the first data identifier is sent to the blockchain network, and the first data content sent by the blockchain network is received, and the first data content is associated with the first data identifier and stored in the local cache area; wherein the first data content is: the data content corresponding to the data to be queried recorded in the blockchain network; When the first data identifier is stored, second data content associated with the first data identifier is obtained from the local cache area.
2. The method according to claim 1, characterized in that Each data identifier stored in the local cache area is provided with a corresponding storage duration; after the first data content is associated with the first data identifier and stored in the local cache area, the method further includes: A storage duration set for the first data identifier in the local cache area; The method further comprises: Periodically updating the storage duration of each data identifier in the local cache area, and obtaining expired data identifiers in the local cache area whose remaining storage duration is less than a first time threshold; The expired data identifier and the data content associated with the expired data identifier are deleted from the local cache area.
3. The method according to claim 2, characterized in that Before storing the first data content in association with the first data identifier in the local cache area, the method further includes: Detecting whether the free capacity of the local cache area is greater than the capacity to be occupied; wherein the capacity to be occupied is determined according to the data volume of the first data content; When the free capacity is not greater than the to-be-occupied capacity, obtaining the remaining storage duration of each data identifier in the local cache area; According to the order of the remaining storage duration from small to large, each data identifier and the data content associated with each data identifier are deleted in sequence until the free capacity is greater than the to-be-occupied capacity.
4. The method according to claim 2, characterized in that: After acquiring the second data content associated with the first data identifier from the local cache area, the method further includes: The remaining storage duration of the first data identifier is increased to the storage duration set when the first data identifier is stored in the local cache.
5. The method according to claims 2-4, characterized in that The storage duration set for the first data content in the local cache area includes: The number of queries for the to-be-queried data by the client within a preset time period is obtained, and the storage duration is set according to the number of queries.
6. The method according to claims 1-4, characterized in that The method further comprises: For multiple smart contracts deployed by the client, establish a first subscription event with the blockchain network; wherein the first subscription event is used to obtain data update content based on the status data generated by the multiple smart contracts from the blockchain network; In response to a first subscription notification triggered by the blockchain network based on the first subscription event, obtaining first updated content of target state data and a second data identifier of the target state data; wherein the target state data includes: state data of a data update event generated when a transaction operation is executed based on at least one smart contract among the multiple smart contracts; When the second data identifier is stored in the local cache area, the data content associated with the second data identifier in the local cache area is replaced with the first updated content.
7. The method according to claims 1-4, characterized in that After the first data content is associated with the first data identifier and stored in the local cache area, the method further includes: When the data to be queried is status data of a smart contract, a second subscription event is established with the blockchain network for the data to be queried; wherein the second subscription event is used to obtain data update content of the data to be queried from the blockchain network; In response to a second subscription notification triggered by the blockchain network based on the second subscription event, obtaining second updated content of the data to be queried from the blockchain network; The data content associated with the first data identifier of the data to be queried in the local cache area is replaced with the second updated content.
8. The method according to claim 7, characterized in that The method further comprises: After deleting the data to be queried from the local cache area, canceling the second subscription event established with the blockchain network.
9. A blockchain data query device, characterized in that: The device comprises: An information acquisition unit, configured to execute, in response to a query instruction for acquiring blockchain data, acquiring a first data identifier of the data to be queried; A cache detection unit, configured to detect whether the first data identifier is stored in the local cache area; The data cache unit is configured to execute, when the first data identifier is not stored, sending a query request carrying the first data identifier to the blockchain network, receiving the first data content issued by the blockchain network, and associating the first data content with the first data identifier and storing it in the local cache area; wherein the first data content is: the data content corresponding to the data to be queried recorded in the blockchain network; The data processing unit is configured to execute, when the first data identifier is stored, obtaining second data content associated with the first data identifier from the local cache area.
10. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of any one of the methods of claims 1-8.
11. A computer-readable storage medium, characterized in that: It comprises a computer program. When the computer program is run on an electronic device, the computer program is used to make the electronic device execute the steps of any one of the methods of claims 1-8.