Block chain information acquisition method and device, electronic equipment and readable medium

By introducing information query cache and information update cache in blockchain nodes, the data acquisition process is optimized, the problems of low hit rate and high database call frequency caused by limited cache space are solved, and the data query efficiency of the blockchain system is improved.

CN120596520APending Publication Date: 2025-09-05TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410255090.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-05
Publication Date
2025-09-05

AI Technical Summary

Technical Problem

The cache space of blockchain nodes is limited, resulting in a low cache data hit rate and frequent calls to database interfaces, which affects data query efficiency and overall performance.

Method used

By introducing information query cache and information update cache in blockchain nodes, the target historical query record is first searched in the information query cache. If it does not hit, the historical update record is searched in the information update cache. Finally, the target information is obtained in the information database, reducing database interface calls.

Benefits of technology

The frequency of database interface calls during data acquisition is reduced, and the execution efficiency of data queries is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120596520A_ABST
    Figure CN120596520A_ABST
Patent Text Reader

Abstract

The invention provides a block chain information acquisition method and apparatus, an electronic device and a readable medium. The method comprises the steps of obtaining an information query request containing a target information identifier; according to the information query request, obtaining a target historical query record corresponding to the target information identifier from an information query cache of the block chain, the historical query record including a historical target information identifier of the historical information query request and corresponding historical target information; if the information query cache does not contain the target historical query record, obtaining a historical update record corresponding to the target information identifier from an information update cache of the block chain according to the information query request, the historical update record of the information update cache being generated according to a historical update operation of block chain information in the block chain; and if the historical update record indicates that the target information exists, obtaining the target information corresponding to the target information identifier from an information database of the block chain. According to the method, the database interface calling frequency in the data acquisition process can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device, and readable medium for obtaining blockchain information. Background Art

[0002] With the development of blockchain technology, more and more business systems are beginning to use blockchain. Blockchain data is typically stored in a database. When blockchain nodes retrieve block data or store block data as evidence, they need to call database interfaces to complete the operation. These database operations often have a significant impact on query performance.

[0003] In related technologies, a blockchain node will first try to query the block data to be obtained in the cached recently used block data, and if the query is found, the result will be obtained directly from the cache.

[0004] However, the cache space of blockchain nodes is usually not high, and the amount of cached data is usually lower than the proportion of blockchain data. When facing complex business in the blockchain system, the hit rate of the data to be queried in the cached data is low. A large number of data query operations that do not hit the cache require a large number of calls to the database interface, resulting in low execution efficiency of the data query process and affecting the overall performance of the blockchain. Summary of the Invention

[0005] Based on the above technical problems, the present application provides a method, device, electronic device and readable medium for obtaining blockchain information, so as to reduce the frequency of database interface calls and the overall time consumption of data acquisition during the data acquisition process and improve execution efficiency.

[0006] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by practice of the present application.

[0007] According to one aspect of an embodiment of the present application, a method for obtaining blockchain information is provided, comprising:

[0008] Obtaining an information query request containing a target information identifier;

[0009] According to the information query request, obtaining a target historical query record corresponding to the target information identifier from the information query cache of the blockchain, wherein the historical query record in the information query cache includes the historical target information identifier of the historical information query request and the corresponding historical target information;

[0010] If the target historical query record is not included in the information query cache, then according to the information query request, obtain the historical update record corresponding to the target information identifier from the information update cache of the blockchain, where the historical update record of the information update cache is generated according to the historical update operation of the blockchain information in the blockchain;

[0011] If the historical update record indicates that the target information corresponding to the target information identifier exists, the target information corresponding to the target information identifier is obtained from the information database of the blockchain.

[0012] According to one aspect of an embodiment of the present application, a device for obtaining blockchain information is provided, including:

[0013] a request acquisition module configured to acquire an information query request containing a target information identifier;

[0014] a query record acquisition module configured to acquire, based on the information query request, a target historical query record corresponding to the target information identifier from the information query cache of the blockchain, wherein the historical query record in the information query cache includes the historical target information identifier of the historical information query request and the corresponding historical target information;

[0015] an update record acquisition module, configured to, if the information query cache does not contain the target historical query record, acquire, based on the information query request, a historical update record corresponding to the target information identifier from the information update cache of the blockchain, where the historical update record of the information update cache is generated based on historical update operations of the blockchain information in the blockchain;

[0016] The information acquisition module is configured to obtain the target information corresponding to the target information identifier from the information database of the blockchain if the historical update record indicates that the target information corresponding to the target information identifier exists.

[0017] In some embodiments of the present application, based on the above technical solution, the information update cache includes a write cache and a delete cache; the update record acquisition module is specifically configured to: if the information query cache does not contain the target historical query record, obtain the target write record corresponding to the target information identifier from the write cache, and obtain the target deletion record corresponding to the target information identifier in the delete cache; if the target write record exists and the target deletion record does not exist, then use the target write record as the historical update record corresponding to the target information identifier; if the target write record does not exist, determine that the target information corresponding to the target information identifier does not exist; if the target write record exists and the target deletion record exists, then use the target deletion record as the historical update record corresponding to the target information identifier.

[0018] In some embodiments of the present application, based on the above technical solution, the update record acquisition module is specifically configured as follows: if the target write record exists and the target deletion record exists, then the deletion record data corresponding to the target deletion record is obtained in the deletion record database of the blockchain, and the deletion record database contains the historical information identifier deleted from the blockchain; if the deletion record data is included in the deletion record database of the blockchain, then it is determined that the target information corresponding to the target information identifier does not exist; if the deletion record data is not included in the deletion record database of the blockchain, then the target deletion record is used as the historical update record corresponding to the target information identifier.

[0019] In some embodiments of the present application, based on the above technical solution, the update record acquisition module is specifically configured as follows: when the blockchain node is started, the current block height of the blockchain and the record block height recorded in the deletion record database are obtained, and the record block height is the block height of the blockchain when the deletion record database was last updated; if the current block height is greater than the record block height, the blockchain information identifier deleted in the block between the current block height and the record block height is obtained; according to the deleted blockchain information identifier, the deletion record database and the record block height are updated.

[0020] In some embodiments of the present application, based on the above technical solution, the update record acquisition module is specifically configured to: obtain an information deletion request containing the target information identifier; delete the target information identifier and the corresponding target information from the information query cache according to the information query request; obtain the target write record corresponding to the target information identifier from the write cache, and if the target write record exists, delete the target information identifier and the corresponding target information from the information database; and update the deletion cache and deletion record database according to the target information identifier.

[0021] In some embodiments of the present application, based on the above technical solution, the information acquisition module is specifically configured to: serialize the historical update records in the information update cache to obtain serialized data; and update the local disk file corresponding to the information update cache according to the serialized data, so that when the blockchain node is started, the information update cache is loaded according to the local disk file.

[0022] In some embodiments of the present application, based on the above technical solution, the information acquisition module is specifically configured to: after the blockchain node completes the blockchain information operation in the current block, obtain the block height of the current block; if the block height is greater than or equal to the predetermined checkpoint height, obtain the historical update record in the information update cache; serialize the historical update record to obtain serialized data.

[0023] In some embodiments of the present application, based on the above technical solution, the information acquisition module is specifically configured as follows: if the block height is greater than or equal to the predetermined checkpoint height, a write lock is applied to the information update cache; the historical update records in the information update cache are copied to obtain an update cache copy; and the write lock of the information update cache is released.

[0024] In some embodiments of the present application, based on the above technical solution, the information acquisition module is specifically configured to: create a replacement file for the information update cache based on the serialized data; rename the current cache file of the information update cache to the file to be deleted; rename the replacement file to the current cache file of the information update cache; and delete the file to be deleted.

[0025] In some embodiments of the present application, based on the above technical solution, the information acquisition module is specifically configured to: if the replacement file of the information update cache and the current cache file exist, check the integrity of the replacement file; if the replacement file is incomplete, obtain the update information of the blockchain information in the block higher than the first block height in the blockchain according to the first block height in the current cache file; update the information update cache and the current cache file according to the update information; and recreate the replacement file of the information update cache according to the serialized data.

[0026] In some embodiments of the present application, based on the above technical solution, the information acquisition module is specifically configured to: if the file to be deleted and the replacement file in the information update cache exist, check the integrity of the replacement file; if the replacement file is complete, obtain the update information of the blockchain information in the block higher than the second block height in the blockchain according to the second block height in the replacement file; update the information update cache and the current cache file according to the update information, and delete the file to be deleted; and recreate the replacement file in the information update cache according to the serialized data.

[0027] In some embodiments of the present application, based on the above technical solution, the information acquisition module is specifically configured as follows: if the file to be deleted and the current cache file of the information update cache exist, then according to the third block height in the current cache file, obtain the update information of the blockchain information in the block higher than the third block height in the blockchain; according to the update information, update the information update cache and the current cache file, and delete the file to be deleted; according to the serialized data, recreate the replacement file of the information update cache.

[0028] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute the method for obtaining blockchain information as in the above technical solution by executing the executable instructions.

[0029] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method for obtaining blockchain information in the above technical solution is implemented.

[0030] According to one aspect of an embodiment of the present application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the blockchain information acquisition method provided in the various optional implementations described above.

[0031] In an embodiment of the present application, after receiving an information query request, a blockchain node will first query the information query cache for historical query records based on the information query request. If no corresponding historical query record is found, the blockchain node will obtain the historical update record corresponding to the target information identifier from the information update cache of the blockchain based on the information query request. If the historical update record indicates that the target information corresponding to the target information identifier exists, the target information will be obtained from the information database. The information query cache is obtained based on the result records of historical information query requests, while the information update cache is generated based on the historical update operations of the blockchain information in the blockchain. When the data cannot be directly obtained through the previously recorded query results, the target information is first determined to still exist in the blockchain database through the historical update operation, and then the target information is obtained from the information database. In this way, the database interface can be called only for existing target data, and for non-existent data, it is directly determined through the information update cache without relying on database calls, thereby reducing the frequency of database interface calls during the data acquisition process, which is conducive to reducing the overall time consumption of data acquisition and improving execution efficiency.

[0032] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] The accompanying drawings are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and those skilled in the art can derive other drawings based on these drawings without inventive effort.

[0034] In the attached figure:

[0035] Figure 1 This is a system architecture for a key update solution applied to blockchain nodes according to an embodiment of the present application.

[0036] Figure 2 This is a schematic diagram of the blockchain network in an embodiment of the present application.

[0037] Figure 3 This is a schematic diagram of blocks in a blockchain network in an embodiment of the present application.

[0038] Figure 4 Flowchart of a method for obtaining blockchain information according to an embodiment of the present application.

[0039] Figure 5 Flowchart of a method for obtaining blockchain information according to an embodiment of the present application.

[0040] Figure 6 This is a schematic structural diagram of information update cache maintenance in an embodiment of the present application.

[0041] Figure 7 This is a schematic flowchart of the information deletion process in an embodiment of the present application.

[0042] Figure 8 Flowchart of a method for obtaining blockchain information according to an embodiment of the present application.

[0043] Figure 9 This is a schematic flowchart of the blockchain information query process in an embodiment of the present application.

[0044] Figure 10 This is a schematic diagram of the process of writing a Bloom filter from memory to disk in an embodiment of the present application.

[0045] Figure 11 This is a schematic flowchart of the process of writing a Bloom filter from memory to disk in an embodiment of the present application.

[0046] Figure 12This is a schematic flow chart of the Bloom filter loading process in an embodiment of the present application.

[0047] Figure 13 The block diagram schematically shows the composition of the device for obtaining blockchain information in an embodiment of the present application.

[0048] Figure 14 A schematic diagram of the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0049] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be thorough and complete and will fully convey the concepts of the example embodiments to those skilled in the art.

[0050] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner.In the following description, many specific details are provided so as to provide a full understanding of the embodiments of the present application. However, it will be appreciated by those skilled in the art that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps etc. can be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring the various aspects of the application.

[0051] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.

[0052] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0053] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, while others may be combined or partially combined. Therefore, the actual execution order may vary depending on the actual situation.

[0054] It should be understood that the solution of this application can be applied to accessing blockchain information, specifically in scenarios involving obtaining or verifying the existence of blockchain data. With the development of blockchain technology, more and more business systems are beginning to utilize blockchain technology. In blockchain systems, users can customize their own business logic, often referred to as smart contracts. Essentially, a transaction consists of two parts: the contract to be executed and the input parameters for executing that contract. Logic and various development languages ​​inherently encompass two components: computation and storage, and smart contracts are no different. In existing blockchain systems, storage often uses a key-value model, and corresponding smart contracts are typically written to support key-value operations such as get / query / set. Currently, contract set operations in blockchain systems are performed in memory and are only written to the database after consensus is reached. Retrieval and query operations require invoking database interfaces, making these operations often performance bottlenecks. Taking evidence storage as an example, a core business scenario in current blockchain systems, query operations are often used in most scenarios. This operation primarily determines whether a piece of evidence exists, executing different logic for whether it exists or not, regardless of the specific content of the evidence. Query operations in existing blockchain systems are very time-consuming. However, state data is not only continuously written but also subject to deletion. This application proposes a solution that combines two Bloom filters and a hash table to minimize the time required for retrieval and query operations, thereby improving the performance of blockchain contract execution. Related technologies utilize state data to improve performance during query or retrieval. State data acts as a cache, typically storing recently used keys. When querying data, if the corresponding data exists in the state data, the query is retrieved from the state data and the result is returned directly, eliminating the need to access the database. However, due to the diverse nature of blockchain services and the unpredictability of which contracts will be triggered, it is impossible to cache many keys in advance, resulting in a relatively low hit rate for query operations. In most cases, query operations require calling a database interface to perform the query. Since the cache will fail in most cases and performance improvement cannot be achieved, the number of database accesses in the data query process will be too high, the execution efficiency will be low, and the overall performance of the blockchain will be affected.

[0055] Based on this, the technical solution of the embodiment of this application proposes a solution for obtaining blockchain information. Specifically, Figure 1As shown, the system architecture applied to the blockchain system according to an embodiment of the present application may include a blockchain network consisting of four blockchain nodes. Blockchain node devices may include smartphones, tablets, laptops, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, and the like. Blockchain node devices may also be servers that provide various services. They may be independent physical servers, server clusters or distributed systems consisting of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Communication links between blockchain nodes may use various types of connection media, such as wired communication links or wireless communication links.

[0056] Depending on implementation needs, the system architecture in the embodiments of the present application can have any number of terminal devices and servers. For example, server 130 can be a server group consisting of multiple server devices. In addition, the technical solutions provided in the embodiments of the present application can be applied to terminal device 110, server 130, or can be implemented jointly by terminal device 110 and server 130, and this application does not specifically limit this. In the embodiments of the present application, server 130 can be a server of a blockchain node, and terminal device 110 can be a blockchain node or a user terminal. Blockchain client software runs on terminal device 110, thereby communicating with server 130. When a user queries and browses information in the blockchain through terminal device 110, terminal device 110 will request the server 130 to obtain the information it wants to display. Server 130 then obtains the information requested by terminal device 110 according to the solution described in this application and provides feedback for terminal device 110 to display or subsequently process.

[0057] Both the server 130 and the terminal device 110 can be blockchain nodes in the blockchain. Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm. Blockchain is essentially a decentralized database, a string of data blocks (i.e. blocks) generated by cryptographic methods. Each data block contains information about a batch of network transactions, which is used to verify the validity of the information (anti-counterfeiting) and generate the next block. The blockchain is jointly maintained by the nodes in the blockchain network. For example, in Figure 2The blockchain network shown may include multiple nodes 201, which may be the individual clients that form the blockchain network. Each node 201 may receive input information during normal operation and, based on the received input information, maintain shared data within the blockchain network. To ensure information interoperability within the blockchain network, information connections may exist between each node in the blockchain network, allowing nodes to transmit information through these connections. For example, when any node in the blockchain network receives input information, the other nodes in the blockchain network obtain the input information according to a consensus algorithm and store it as shared data, ensuring that the data stored on all nodes in the blockchain network is consistent.

[0058] Each node in a blockchain network has a corresponding node identifier, and each node in the blockchain network can store the node identifiers of other nodes so that it can subsequently broadcast generated blocks to other nodes in the blockchain network based on the node identifiers of other nodes. Each node can maintain a node identifier list, storing the node name and node identifier in the node identifier list. The node identifier can be an IP (Internet Protocol, a protocol for interconnecting networks) address or any other information that can be used to identify the node.

[0059] Each node in the blockchain network stores the same blockchain. The blockchain consists of multiple blocks, see Figure 3 As shown in the figure, the blockchain consists of multiple blocks. The genesis block includes a block header and a block body. The block header stores the input information feature value, version number, timestamp, and difficulty value, etc., and the block body stores the input information. The next block of the genesis block uses the genesis block as its parent block. The next block also includes a block header and a block body. The block header stores the input information feature value of the current block, the block header feature value, version number, timestamp, and difficulty value of the parent block, etc., and so on. Therefore, the block data stored in each block in the blockchain is associated with the block data stored in the parent block, ensuring the security of the input information in the block.

[0060] The blockchain data obtained by the server 130 and the terminal device 110 can be Figure 3 In the embodiment of the present application, blockchain information can be stored in the form of blockchain transactions. Figure 3 In the block body of the blockchain structure shown in , consensus is reached between nodes along with the block and it is put on the blockchain.

[0061] The following is a detailed description of the implementation details of the technical solution of the embodiment of the present application: Figure 4The flowchart of the method for obtaining blockchain information according to one embodiment of the present application is shown. The method for obtaining blockchain information is applied to a blockchain system and can be specifically executed by a device with a computing and processing function, such as a server or terminal device where a blockchain node is located. Figure 4 As shown, the method for obtaining blockchain information includes at least steps S410 to S440, which are described in detail as follows:

[0062] Step S410: obtaining an information query request including a target information identifier.

[0063] An information query request is typically triggered by a client performing an operation such as browsing, querying, or updating specific blockchain information. The target information identifier refers to the blockchain identifier for the information being queried, such as a transaction identifier. It is understood that the target information being queried can be data added to the blockchain via a smart contract, and the data can be associated with a blockchain transaction or a blockchain address. The associated target information can be directly retrieved from the blockchain using the target information identifier. This information query request can be used to retrieve the target information from the blockchain, or simply to query whether the target information corresponding to the target information identifier exists without reading the specific content of the target information.

[0064] Step S420: According to the information query request, obtain the target historical query record corresponding to the target information identifier from the information query cache of the blockchain, and the historical query record in the information query cache includes the historical target information identifier of the historical information query request and the corresponding historical target information.

[0065] In response to an information query request, a blockchain node retrieves the target historical query record corresponding to the target information identifier from the blockchain's information query cache. The information query cache is data located in the blockchain node's cache or content, determined based on historical information query requests. The data in the information query cache can also be in the form of key-value pairs. When the blockchain executes a historical information query request, it enters the associated historical target information identifier and the retrieved historical target information into the information query cache, creating a historical query record. The blockchain node can directly use the target information identifier to check whether the corresponding target historical query record exists in the information query cache. If so, the blockchain node can directly obtain the query results of the information query request.

[0066] Step S430: If the information query cache does not contain the target historical query record, then according to the information query request, obtain the historical update record corresponding to the target information identifier from the information update cache of the blockchain, and the historical update record of the information update cache is generated according to the historical update operation of the blockchain information in the blockchain.

[0067] If the information query cache does not contain the target historical query record, it means that the corresponding target information needs to access the database to determine its existence or read its specific content. However, the blockchain node can first confirm whether the target information still exists in the blockchain based on the information update cache. If it no longer exists, there is no need to read the database content. Specifically, the historical update records in the information update cache are generated based on the historical update operations of the blockchain information. Update operations typically include addition, deletion, and modification. When a blockchain node performs such an operation on blockchain information, the identifier of the blockchain information on which the update operation was performed and the corresponding operation are recorded in the information update cache. Based on the target information identifier, the blockchain node can retrieve the corresponding historical update record of the target information and then determine whether the target information exists based on the historical update records. For example, if the most recent operation was a deletion of the target information, it can be determined that the target information no longer exists in the blockchain. However, if the most recent operation was an addition or update, it can be determined that the target information exists. In one embodiment, the historical update record corresponding to the target information identifier may not be available in the information update cache. At this time, if the information update cache is the complete set of data of the historical update operations of the blockchain information in the blockchain, it means that the target information has not been added to the blockchain, and it can be determined that the target information does not exist. If the information update cache is not the complete set of data of the historical update operations of the blockchain information in the blockchain, it is necessary to directly access the information database to finally confirm the situation of the target information.

[0068] Step S440: If the historical update record indicates that the target information corresponding to the target information identifier exists, the target information corresponding to the target information identifier is obtained from the information database of the blockchain.

[0069] If the historical update record indicates that the target information corresponding to the target information identifier exists, the blockchain node will retrieve the target information corresponding to the target information identifier from the blockchain's information database. The information database is a database that stores the actual blockchain data and contains the specific content of the target data. Depending on the specific purpose of the information query request, the information database may provide feedback as the target information: whether the data corresponding to the target information identifier exists (i.e., simply providing a "yes" or "no" response), or directly retrieve the target data itself as the target information.

[0070] In an embodiment of the present application, after receiving an information query request, a blockchain node will first query the information query cache for historical query records based on the information query request. If no corresponding historical query record is found, the blockchain node will obtain the historical update record corresponding to the target information identifier from the information update cache of the blockchain based on the information query request. If the historical update record indicates that the target information corresponding to the target information identifier exists, the target information will be obtained from the information database. The information query cache is obtained based on the result records of historical information query requests, while the information update cache is generated based on the historical update operations of the blockchain information in the blockchain. When the data cannot be directly obtained through the previously recorded query results, the target information is first determined to still exist in the blockchain database through the historical update operation, and then the target information is obtained from the information database. In this way, the database interface can be called only for existing target data, and for non-existent data, it is directly determined through the information update cache without relying on database calls, thereby reducing the frequency of database interface calls during the data acquisition process, which is conducive to reducing the overall time consumption of data acquisition and improving execution efficiency.

[0071] In the embodiments of the present application, it is also proposed to Figure 4 Other embodiments that refine the technical solution of the embodiment shown are as follows Figure 5 As shown, in a method for obtaining blockchain information in one embodiment of the present application, the information update cache includes writing cache and deleting cache. The solution of the present application may include the following steps:

[0072] Step S510: obtaining an information query request including a target information identifier.

[0073] Optionally, the implementation details of step S510 are the same as Figure 4 The step S410 shown in FIG is the same as that in FIG, and will not be repeated here.

[0074] Step S520: According to the information query request, obtain the target historical query record corresponding to the target information identifier from the information query cache of the blockchain, and the historical query record in the information query cache contains the historical target information identifier of the historical information query request and the corresponding historical target information.

[0075] Optionally, the implementation details of step S520 are the same as Figure 4 The step S420 shown in FIG is the same as that in FIG, and will not be repeated here.

[0076] Step S530: If the information query cache does not contain the target historical query record, obtain the target write record corresponding to the target information identifier from the write cache, and obtain the target delete record corresponding to the target information identifier from the delete cache.

[0077] Optionally, the implementation details of step S530 are the same as Figure 4 The step S430 shown in FIG is the same as that in FIG, and will not be repeated here.

[0078] In this application, the blockchain node checks whether the target write record and the target delete record exist. If the target write record exists but the target delete record does not, step S540 is executed. If the target write record does not exist, step S550 is executed. If both the target write record and the target delete record exist, step S560 is executed.

[0079] Step S540: Write the target write record as a historical update record corresponding to the target information identifier.

[0080] The write cache contains records of the information identifiers of all blockchain information written to the blockchain, while the delete cache contains records of the information identifiers of all blockchain information deleted from the blockchain. If the target write record exists but the target delete record does not, it indicates that the target information was written to the blockchain and not deleted. Therefore, the blockchain node can directly use the target write record as the historical update record corresponding to the target information identifier. The target write record can contain both the information identifier and the information content. For requests to verify the existence of information, the blockchain node can directly confirm the existence of the target information based on the existence of the target write record and the absence of the target delete record. For requests to obtain data, the target write record can contain the written data, allowing the blockchain node to obtain the corresponding data from the target write record.

[0081] In the embodiment of the present application, the write cache, delete cache and information query cache include other caches that can generally be in the form of Bloom filters, for example, the write cache is specifically an ADD Bloom filter, and the delete cache is a DEL Bloom filter. For ease of introduction, please refer to Figure 6 . Figure 6 This is a schematic diagram of the information update cache maintenance in an embodiment of the present application. When information is written to or deleted from the blockchain, the information identifier is saved in the write cache and delete cache respectively. Specifically, the information identifier is converted into multiple hash values ​​according to a predetermined hash function, and these hash values ​​in the Bloom filter of the write cache are set to 1. If information is deleted, its information identifier is similarly set to 1.

[0082] Step S550: Determine that the target information corresponding to the target information identifier does not exist.

[0083] If the target write record does not exist, the blockchain node can directly determine that the target information corresponding to the target information identifier has not been written into the blockchain, and therefore directly determine that the target information corresponding to the target information identifier does not exist.

[0084] Step S560: taking the target deletion record as a historical update record corresponding to the target information identifier.

[0085] If both the target write record and the target delete record exist, it means that the corresponding target information has been deleted from the blockchain. Therefore, the blockchain node can use the target delete record as a historical update record corresponding to the target information identifier. It should be noted that when the delete cache uses a Bloom filter, the existence of the target delete record means that the target information is likely to be deleted, but there is still a small probability that the target information has not been deleted, but its corresponding hash value has been set to 1 by other data. In this case, it is possible to further confirm whether the target information has been confirmed to be deleted. In this embodiment, the write cache and the delete cache respectively record the write history and delete history of blockchain information, so that the specific situation of blockchain information in the blockchain can be specifically determined, thereby reducing the dependence of the blockchain information storage process on the underlying database and resource consumption, and improving the utilization efficiency of computing resources.

[0086] Step S570: If the historical update record indicates that the target information corresponding to the target information identifier exists, the target information corresponding to the target information identifier is obtained from the information database of the blockchain.

[0087] Optionally, the implementation details of step S570 are the same as Figure 4 The step S440 shown in FIG is the same as that in FIG, and will not be repeated here.

[0088] In an embodiment of the present application, after receiving an information query request, a blockchain node will first query the information query cache for historical query records based on the information query request. If no corresponding historical query record is found, the blockchain node will obtain the historical update record corresponding to the target information identifier from the information update cache of the blockchain based on the information query request. If the historical update record indicates that the target information corresponding to the target information identifier exists, the target information will be obtained from the information database. The information query cache is obtained based on the result records of historical information query requests, while the information update cache is generated based on the historical update operations of the blockchain information in the blockchain. When the data cannot be directly obtained through the previously recorded query results, the target information is first determined to still exist in the blockchain database through the historical update operation, and then the target information is obtained from the information database. In this way, the database interface can be called only for existing target data, and for non-existent data, it is directly determined through the information update cache without relying on database calls, thereby reducing the frequency of database interface calls during the data acquisition process, which is conducive to reducing the overall time consumption of data acquisition and improving execution efficiency.

[0089] In some optional embodiments of the present application, based on other technical solutions of the present application, when a target write record exists and the target deletion record exists, the blockchain node, while treating the target deletion record as a historical update record corresponding to the target information identifier, retrieves deletion record data corresponding to the target deletion record from the deletion record database of the blockchain. The deletion record database contains the historical information identifier deleted from the blockchain. If the deletion record database of the blockchain contains the deletion record data, the blockchain node determines that the target information corresponding to the target information identifier does not exist. Otherwise, if the deletion record database of the blockchain does not contain the deletion record data, the blockchain node treats the target deletion record as a historical update record corresponding to the target information identifier. In the present application, after confirming the existence of the target deletion record, the blockchain node also verifies that the target data has indeed been deleted based on the deletion record database. Specifically, the deletion record database contains the historical information identifier deleted from the blockchain. If the deletion record database contains the deletion record data corresponding to the target deletion record, it indicates that the target data has indeed been deleted, and the blockchain node determines that the target information corresponding to the target information identifier does not exist. If the blockchain's deletion record database does not contain deletion record data, it indicates that the target deletion record contains a record error. This is because the hash values ​​calculated by the hash function based on different information identifiers may contain some duplication, and the hash values ​​calculated for multiple information identifiers may overwrite the hash value of another information identifier that has not yet been deleted. Therefore, if the blockchain's deletion record database does not contain deletion record data, the blockchain node will treat the target deletion record as a historical update record corresponding to the target information identifier. Based on this target deletion record, the blockchain node can determine that the target information identifier has not actually been deleted. In the case of confirmation of deletion, the blockchain will directly confirm that the target information does not exist without obtaining the target deletion record. In this embodiment, the deletion of information is verified and confirmed through the deletion record database, thereby avoiding errors in the deletion of data in the cache and improving the accuracy of the solution.

[0090] In some optional embodiments of the present application, based on other technical solutions of the present application, upon startup, a blockchain node obtains the current block height of the blockchain and the recorded block height recorded in the deletion record database. The recorded block height is the block height of the blockchain at the time the deletion record database was last updated. If the current block height is greater than the recorded block height, the blockchain node obtains the identifiers of the deleted blockchain information in blocks between the current block height and the recorded block height, and then updates the deletion record database and the recorded block height based on the deleted blockchain information identifiers. In this embodiment, the recorded block height recorded in the deletion record database is the block height of the blockchain at the time the deletion record database was last updated. The blockchain node determines whether the data in the deletion record database needs to be updated based on the comparison between the recorded block height and the current block height of the blockchain. If the current block height is greater than the recorded block height, the blockchain node updates the deletion record database with the deleted identifiers in the blocks corresponding to the height difference and updates the recorded block height to the current block height. By recording the processed block height in the deletion database, it is possible to avoid data inconsistency caused by an information identifier being deleted in the information database and a downtime before synchronization to the deletion record database, which is conducive to ensuring data consistency of the solution.

[0091] In some optional embodiments of the present application, based on other technical solutions of the present application, the blockchain node will obtain an information deletion request containing the target information identifier, and then delete the target information identifier and the corresponding target information from the information query cache according to the information query request, and obtain the target write record corresponding to the target information identifier from the write cache. If the target write record exists, the blockchain node will delete the target information identifier and the corresponding target information from the information database, and then update the deletion cache and deletion record database according to the target information identifier. In this embodiment, the blockchain node will delete the target information identifier from the database according to the information deletion request, and update the deletion cache and deletion record database. Please refer to Figure 7 , Figure 7 This is a schematic flow chart of the information deletion process in the embodiment of this application. Figure 7As shown, upon receiving an information deletion request (DelKey request), the blockchain node will first confirm whether the corresponding information identification Key exists in the information query cache, and if so, delete it. Subsequently, it checks whether the corresponding Key is contained in the write cache (ADD filter). If not, the deletion process ends directly. If it is contained, it checks whether the Key exists in the information database. If it exists, the Key is deleted from the information database, and then the deleted Key is added to the deletion cache and deletion record database. In this embodiment, the deletion information identifier is written to the deletion cache and the deletion record database, thereby ensuring that the deletion record database contains all deleted information identifiers for confirmation based on the deletion cache, and directly searches for deletion records from the deletion record database without relying on the information database for confirmation. The deletion record database only contains deletion records, and the amount of data is much lower than that of the information database, thereby reducing the information that needs to be processed in the confirmation process and improving access speed and efficiency.

[0092] In the embodiments of the present application, it is also proposed to Figure 4 Other embodiments that refine the technical solution of the embodiment shown are as follows Figure 8 As shown, in a method for obtaining blockchain information in one embodiment of the present application, the information update cache includes writing cache and deleting cache. The solution of the present application may include the following steps:

[0093] Step S810: Obtain an information query request including a target information identifier.

[0094] Optionally, the implementation details of step S810 are the same as Figure 4 The step S410 shown in FIG is the same as that in FIG, and will not be repeated here.

[0095] Step S820: According to the information query request, obtain the target historical query record corresponding to the target information identifier from the information query cache of the blockchain, and the historical query record in the information query cache includes the historical target information identifier of the historical information query request and the corresponding historical target information.

[0096] Optionally, the implementation details of step S820 are the same as Figure 4 The step S420 shown in FIG is the same as that in FIG, and will not be repeated here.

[0097] Step S830: If the information query cache does not contain the target historical query record, then according to the information query request, obtain the historical update record corresponding to the target information identifier from the information update cache of the blockchain, and the historical update record of the information update cache is generated according to the historical update operation of the blockchain information in the blockchain.

[0098] Optionally, the implementation details of step S830 are the same as Figure 4 The step S430 shown in FIG is the same as that in FIG, and will not be repeated here.

[0099] Step S840: If the historical update record indicates that the target information corresponding to the target information identifier exists, the target information corresponding to the target information identifier is obtained from the information database of the blockchain.

[0100] Optionally, the implementation details of step S840 are the same as Figure 4 The step S440 shown in FIG is the same as that in FIG, and will not be repeated here.

[0101] Step S850, serializing the historical update records in the information update cache to obtain serialized data;

[0102] Step S860: Update the local disk file corresponding to the information update cache according to the serialized data, so that when the blockchain node is started, the information update cache is loaded according to the local disk file.

[0103] In this embodiment, blockchain nodes periodically write data from their update cache to disk to rebuild the cache upon node restart. Specifically, the blockchain node serializes historical update records in the update cache to obtain serialized data. This serialized data is then used to update the local disk file corresponding to the update cache. Upon node startup, the update cache is loaded from the local disk file. Saving the update cache to a local disk file prevents data loss in the update cache and avoids the need to read large amounts of database data to rebuild the update cache upon node restart, which improves the stability of the solution.

[0104] In an embodiment of the present application, after receiving an information query request, a blockchain node will first query the information query cache for historical query records based on the information query request. If no corresponding historical query record is found, the blockchain node will obtain the historical update record corresponding to the target information identifier from the information update cache of the blockchain based on the information query request. If the historical update record indicates that the target information corresponding to the target information identifier exists, the target information will be obtained from the information database. The information query cache is obtained based on the result records of historical information query requests, while the information update cache is generated based on the historical update operations of the blockchain information in the blockchain. When the data cannot be directly obtained through the previously recorded query results, the target information is first determined to still exist in the blockchain database through the historical update operation, and then the target information is obtained from the information database. In this way, the database interface can be called only for existing target data, and for non-existent data, it is directly determined through the information update cache without relying on database calls, thereby reducing the frequency of database interface calls during the data acquisition process, which is conducive to reducing the overall time consumption of data acquisition and improving execution efficiency.

[0105] In some optional embodiments of the present application, based on other technical solutions of the present application, during the process of serializing the historical update records in the information update cache to obtain serialized data, after completing operations on the blockchain information in the current block, the blockchain node obtains the block height of the current block. If the block height is greater than or equal to a predetermined checkpoint height, the historical update records in the information update cache are serialized to obtain serialized data. The historical update records in the information update cache are obtained and then serialized to obtain serialized data. In this embodiment, the blockchain node uses the block height as a checkpoint for writing the information update cache to disk. Specifically, after the blockchain node completes operations on a block, if the block height reaches the predetermined checkpoint height, the blockchain node converts the information update cache into serialized data for writing to the local disk file. By using the block height as a checkpoint for saving the information update cache, the data in the local disk file is the data of the complete block, ensuring consistency between the information update cache loaded from the local disk file and the block data in the blockchain, and avoiding data mismatches that result in additional data reads.

[0106] In some optional embodiments of the present application, based on other technical solutions of the present application, if the block height is greater than or equal to a predetermined checkpoint height, the blockchain node will apply a write lock to the information update cache, then copy the historical update records in the information update cache to obtain an update cache copy, and then release the write lock on the information update cache. By applying a write lock to the information update cache before copying, the copied data is ensured to be consistent with the information update cache, avoiding data errors and improving data accuracy.

[0107] In some optional embodiments of the present application, based on other technical solutions of the present application, in the process of updating the local disk file corresponding to the information update cache according to the serialized data, the blockchain node will create a replacement file of the information update cache according to the serialized data, and then rename the current cache file of the information update cache to the file to be deleted, and rename the replacement file to the current cache file of the information update cache, and finally delete the file to be deleted. In this embodiment, the replacement file is used as an intermediate file, and the original file is deleted after the replacement is completed, thereby ensuring that the data in the original cache file exists consistently before the new current cache file takes effect, preventing accidental data loss, and helping to improve the data security of the system.

[0108] In some optional embodiments of the present application, based on other technical solutions of the present application, during the process of creating a replacement file for the information update cache based on the serialized data, if the replacement file for the information update cache and the current cache file exist, the blockchain node will check the integrity of the replacement file. If the replacement file is incomplete, the blockchain node will obtain updated blockchain information in blocks in the blockchain that are higher than the first block height in the current cache file, then update the information update cache and the current cache file based on the updated information. Finally, based on the serialized data, the replacement file for the information update cache will be recreated. In this embodiment, the existence of the replacement file and the current cache file indicates that the blockchain node may have crashed while updating the local cache file. The blockchain node can check the integrity of the replacement file and, if incomplete, rebuild the current cache file. If complete, the replacement file can be directly used. Rebuilding the current cache file restores the file to the current blockchain state, which helps improve the efficiency of the solution in handling crashes.

[0109] In some optional embodiments of the present application, based on other technical solutions of the present application, during the process of creating a replacement file for the information update cache based on the serialized data, if the to-be-deleted file and the replacement file in the information update cache exist, the blockchain node will check the integrity of the replacement file. If the replacement file is complete, the blockchain node will obtain updated blockchain information in blocks in the blockchain that are higher than the second block height based on the second block height in the replacement file. Based on the updated information, the blockchain node will update the information update cache and the current cache file, delete the to-be-deleted file, and finally recreate the replacement file for the information update cache based on the serialized data. If the to-be-deleted file and the replacement file exist, it means that the original cache file has been renamed to the to-be-deleted file during the downtime, but the replacement file has not been updated to the new current cache file. The replacement file can be directly used to construct the new current cache file. In this embodiment, when both the to-be-deleted file and the replacement file exist, the replacement file is directly used. The replacement file has more complete data than the to-be-deleted file, which helps reduce the amount of data required to rebuild the current cache file and improve the processing efficiency of the solution.

[0110] In some optional embodiments of the present application, based on other technical solutions of the present application, in the process of creating a replacement file for the information update cache according to the serialized data, if the file to be deleted and the current cache file in the information update cache exist, the blockchain node will obtain the update information of the blockchain information in the block higher than the third block height in the blockchain according to the third block height in the current cache file, and then update the information update cache and the current cache file according to the update information, delete the file to be deleted, and then recreate the replacement file for the information update cache according to the serialized data. If the file to be deleted and the current cache file exist, it means that the current cache file is the updated file, and the file to be deleted is the file that will not be deleted in the future. The blockchain node can directly update based on the difference between the current cache file and the current blockchain to obtain the latest current cache file without having to retrieve all data from the database, which is conducive to improving the update efficiency of the current cache file.

[0111] The following is an example of the implementation details of the technical solution of the embodiment of the present application: Figure 9 , Figure 9 This is a schematic flow chart of the blockchain information query process in the embodiment of this application. Figure 9As shown, the blockchain's virtual machine generates a HasKey request for information existence verification of the information identification key. The blockchain node will first verify whether the information identification key exists based on the state cache. If it exists, it is directly determined that the result is that the data exists. Otherwise, the query component of the blockchain node checks whether the information identification key has been added to the database based on the ADD Bloom filter. If it has not been added, it is directly determined that the data does not exist. Otherwise, it is further verified based on the DEL Bloom filter to see whether the information identification key has been deleted. If so, it is verified based on the DEL database to see whether the information identification key has been deleted. If so, it is confirmed that the information identification key does not exist. If the DEL Bloom filter or the DEL database feedback information that the information identification key has not been deleted, the blockchain node finally confirms whether the information identification key exists based on the database, and confirms the final query result based on the result fed back by the domestic database. Both the ADD Bloom filter and the DEL Bloom filter can be written to disk files. For details, please refer to Figure 10 and Figure 11 , Figure 10 This is a schematic diagram of the process of writing a Bloom filter from memory to disk in an embodiment of the present application. Figure 11 This is a schematic flow chart of the process of writing a Bloom filter from memory to disk in an embodiment of the present application. As shown in the figure, after all the key operations in a block are completed, the blockchain node will use the block height as the checkpoint judgment basis to confirm whether the checkpoint has been reached. If not, the process result. If it has been reached, a write lock is added to the current Bloom filter so that it can only be read but not edited. Subsequently, the Bloom filter in the memory is copied to the new memory space, and the lock on the original Bloom filter is released. According to the creation of file f2 and the serialization of the data in the new memory space to generate binary content, the binary content and the corresponding cyclic redundancy check code and block height are written to file f2. Subsequently, the file f0 of the currently saved Bloom filter is named f1, f2 is named f0, and then the file f1 is deleted, thereby completing the process of saving the content of the Bloom filter to the file.

[0112] The data saved to the file can be used to load the bloom filter when the node starts. For details, see Figure 12 . Figure 12 FIG. 1 is a schematic flow chart of the Bloom filter loading process in the embodiment of the present application. Figure 12As shown in the figure, after the node starts, it will first read the DEL database and then obtain the height value corresponding to the block height MaxHeight stored therein. This height value is compared with the current highest height H of the blockchain. If H-Value = 0, the DEL database is consistent with the blockchain database. However, if H-Value > 0, the DEL database and the blockchain database may also be consistent because not every block performs the deletion operation. When H-Value > 0, the node obtains the deleted keys between Value+1 and H in the blockchain data and adds them to the DEL database to update the DEL database to be consistent with the blockchain database. Finally, the node can obtain the local file list corresponding to the Bloom filter and load it according to the corresponding situation.

[0113] It should be noted that although the steps of the method of the present application are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all steps must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.

[0114] The following introduces the device implementation of the present application, which can be used to execute the method for obtaining blockchain information in the above embodiments of the present application. Figure 13 The block diagram of the device for obtaining blockchain information in the embodiment of the present application is schematically shown. Figure 13 As shown, the blockchain information acquisition device 1300 may mainly include:

[0115] The request acquisition module 1310 is configured to acquire an information query request including a target information identifier;

[0116] A query record acquisition module 1320 is configured to acquire, based on the information query request, a target historical query record corresponding to the target information identifier from the information query cache of the blockchain, wherein the historical query record in the information query cache includes the historical target information identifier of the historical information query request and the corresponding historical target information;

[0117] An update record acquisition module 1330 is configured to, if the information query cache does not contain the target historical query record, acquire, based on the information query request, a historical update record corresponding to the target information identifier from the information update cache of the blockchain, where the historical update record of the information update cache is generated based on historical update operations of the blockchain information in the blockchain;

[0118] The information acquisition module 1340 is configured to obtain the target information corresponding to the target information identifier from the information database of the blockchain if the historical update record indicates that the target information corresponding to the target information identifier exists.

[0119] In some embodiments of the present application, based on the above technical solution, the information update cache includes a write cache and a delete cache; the update record acquisition module 1330 is specifically configured as: if the information query cache does not contain the target historical query record, obtain the target write record corresponding to the target information identifier from the write cache, and obtain the target deletion record corresponding to the target information identifier in the delete cache; if the target write record exists and the target deletion record does not exist, then the target write record is used as the historical update record corresponding to the target information identifier; if the target write record does not exist, it is determined that the target information corresponding to the target information identifier does not exist; if the target write record exists and the target deletion record exists, then the target deletion record is used as the historical update record corresponding to the target information identifier.

[0120] In some embodiments of the present application, based on the above technical solution, the update record acquisition module 1330 is specifically configured as follows: if the target write record exists and the target deletion record exists, then the deletion record data corresponding to the target deletion record is obtained in the deletion record database of the blockchain, and the deletion record database contains the historical information identifier deleted from the blockchain; if the deletion record data is included in the deletion record database of the blockchain, then it is determined that the target information corresponding to the target information identifier does not exist; if the deletion record data is not included in the deletion record database of the blockchain, then the target deletion record is used as the historical update record corresponding to the target information identifier.

[0121] In some embodiments of the present application, based on the above technical solution, the update record acquisition module 1330 is specifically configured as follows: when the blockchain node is started, the current block height of the blockchain and the record block height recorded in the deletion record database are obtained, and the record block height is the block height of the blockchain when the deletion record database was last updated; if the current block height is greater than the record block height, the blockchain information identifier deleted in the block between the current block height and the record block height is obtained; according to the deleted blockchain information identifier, the deletion record database and the record block height are updated.

[0122] In some embodiments of the present application, based on the above technical solution, the update record acquisition module 1330 is specifically configured to: obtain an information deletion request containing the target information identifier; delete the target information identifier and the corresponding target information from the information query cache according to the information query request; obtain the target write record corresponding to the target information identifier from the write cache, and if the target write record exists, delete the target information identifier and the corresponding target information from the information database; and update the deletion cache and deletion record database according to the target information identifier.

[0123] In some embodiments of the present application, based on the above technical solution, the information acquisition module 1340 is specifically configured to: serialize the historical update records in the information update cache to obtain serialized data; and update the local disk file corresponding to the information update cache according to the serialized data, so that when the blockchain node is started, the information update cache is loaded according to the local disk file.

[0124] In some embodiments of the present application, based on the above technical solution, the information acquisition module 1340 is specifically configured to: after the blockchain node completes the blockchain information operation in the current block, obtain the block height of the current block; if the block height is greater than or equal to the predetermined checkpoint height, obtain the historical update record in the information update cache; serialize the historical update record to obtain serialized data.

[0125] In some embodiments of the present application, based on the above technical solution, the information acquisition module 1340 is specifically configured as follows: if the block height is greater than or equal to the predetermined checkpoint height, a write lock is applied to the information update cache; the historical update records in the information update cache are copied to obtain an update cache copy; and the write lock of the information update cache is released.

[0126] In some embodiments of the present application, based on the above technical solution, the information acquisition module 1340 is specifically configured to: create a replacement file for the information update cache based on the serialized data; rename the current cache file of the information update cache to the file to be deleted; rename the replacement file to the current cache file of the information update cache; and delete the file to be deleted.

[0127] In some embodiments of the present application, based on the above technical solution, the information acquisition module 1340 is specifically configured to: if the replacement file of the information update cache and the current cache file exist, check the integrity of the replacement file; if the replacement file is incomplete, obtain the update information of the blockchain information in the block higher than the first block height in the blockchain according to the first block height in the current cache file; update the information update cache and the current cache file according to the update information; and recreate the replacement file of the information update cache according to the serialized data.

[0128] In some embodiments of the present application, based on the above technical solution, the information acquisition module 1340 is specifically configured to: if the file to be deleted and the replacement file in the information update cache exist, check the integrity of the replacement file; if the replacement file is complete, obtain the update information of the blockchain information in the block higher than the second block height in the blockchain according to the second block height in the replacement file; update the information update cache and the current cache file according to the update information, and delete the file to be deleted; and recreate the replacement file in the information update cache according to the serialized data.

[0129] In some embodiments of the present application, based on the above technical solution, the information acquisition module 1340 is specifically configured as follows: if the file to be deleted and the current cache file of the information update cache exist, then according to the third block height in the current cache file, obtain the update information of the blockchain information in the block higher than the third block height in the blockchain; according to the update information, update the information update cache and the current cache file, and delete the file to be deleted; according to the serialized data, recreate the replacement file of the information update cache.

[0130] It should be noted that the apparatus provided in the above embodiment and the method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module performs the operation has been described in detail in the method embodiment and will not be repeated here.

[0131] Figure 14 A schematic diagram of the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present application is shown.

[0132] It should be noted that Figure 14 The computer system 1400 of the electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present application.

[0133] like Figure 14As shown, computer system 1400 includes a central processing unit (CPU) 1401, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 1402 or programs loaded from storage 1408 into random access memory (RAM) 1403. RAM 1403 also stores various programs and data required for system operation. CPU 1401, ROM 1402, and RAM 1403 are connected to each other via bus 1404. An input / output (I / O) interface 1405 is also connected to bus 1404.

[0134] The following components are connected to the I / O interface 1405: an input section 1406 including a keyboard, a mouse, and the like; an output section 1407 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 1408 including a hard disk; and a communication section 1409 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 1409 performs communication processing via a network such as the Internet. A drive 1410 is also connected to the I / O interface 1405 as needed. Removable media 1411, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 1410 as needed, so that computer programs read from the removable media can be installed in the storage section 1408 as needed.

[0135] In particular, according to an embodiment of the present application, the processes described in the various method flow charts can be implemented as computer software programs. For example, an embodiment of the present application includes a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the methods shown in the flow charts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1409, and / or installed from a removable medium 1411. When the computer program is executed by the central processing unit (CPU) 1401, the various functions defined in the system of the present application are executed.

[0136] It should be noted that the computer-readable medium shown in the embodiments of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-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 computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, or any suitable combination thereof.

[0137] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of the boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0138] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiment of the application, the features and functions of two or more modules or units described above can be concretized in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be concretized.

[0139] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.

[0140] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present invention that follow the general principles of this application and include common knowledge or customary techniques in the art that are not disclosed herein.

[0141] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A method for obtaining blockchain information, characterized in that: include: Obtaining an information query request containing a target information identifier; According to the information query request, obtaining a target historical query record corresponding to the target information identifier from the information query cache of the blockchain, wherein the historical query record in the information query cache includes the historical target information identifier of the historical information query request and the corresponding historical target information; If the target historical query record is not included in the information query cache, then according to the information query request, obtain the historical update record corresponding to the target information identifier from the information update cache of the blockchain, where the historical update record of the information update cache is generated according to the historical update operation of the blockchain information in the blockchain; If the historical update record indicates that the target information corresponding to the target information identifier exists, the target information corresponding to the target information identifier is obtained from the information database of the blockchain.

2. The acquisition method according to claim 1, characterized in that The information update cache includes a write cache and a delete cache; if the information query cache does not contain the target historical query record, then according to the information query request, obtaining the historical update record corresponding to the target information identifier from the information update cache of the blockchain, including: If the information query cache does not contain the target historical query record, obtaining a target write record corresponding to the target information identifier from the write cache, and obtaining a target delete record corresponding to the target information identifier from the delete cache; If the target write record exists and the target delete record does not exist, taking the target write record as a historical update record corresponding to the target information identifier; If the target write record does not exist, determining that the target information corresponding to the target information identifier does not exist; If the target write record exists and the target delete record exists, the target delete record is used as a historical update record corresponding to the target information identifier.

3. The acquisition method according to claim 2, characterized in that If the target write record exists and the target delete record exists, then the target delete record is used as a historical update record corresponding to the target information identifier, including: If the target write record exists and the target deletion record exists, obtaining deletion record data corresponding to the target deletion record from the deletion record database of the blockchain, wherein the deletion record database includes an identifier of historical information deleted from the blockchain; If the deletion record database of the blockchain contains the deletion record data, determining that the target information corresponding to the target information identifier does not exist; If the deletion record data is not included in the deletion record database of the blockchain, the target deletion record is used as a historical update record corresponding to the target information identifier.

4. The acquisition method according to claim 3, characterized in that The method further comprises: When the blockchain node is started, the current block height of the blockchain and the record block height recorded in the deletion record database are obtained, where the record block height is the block height of the blockchain when the deletion record database was last updated; If the current block height is greater than the recorded block height, then obtaining the blockchain information identifier deleted in the blocks between the current block height and the recorded block height; According to the deleted blockchain information identifier, the deletion record database and the record block height are updated.

5. The acquisition method according to claim 2, characterized in that: The method further comprises: Obtaining an information deletion request including the target information identifier; Deleting the target information identifier and the corresponding target information from the information query cache according to the information query request; Obtaining a target write record corresponding to the target information identifier from the write cache, If the target write record exists, deleting the target information identifier and the corresponding target information from the information database; The deletion cache and the deletion record database are updated according to the target information identifier.

6. The method according to claim 1, wherein The method further comprises: Serializing the historical update records in the information update cache to obtain serialized data; According to the serialized data, a local disk file corresponding to the information update cache is updated, so that when the blockchain node is started, the information update cache is loaded according to the local disk file.

7. The method according to claim 6, characterized in that The serializing the historical update records in the information update cache to obtain serialized data includes: After the blockchain node completes the operation on the blockchain information in the current block, the block height of the current block is obtained; If the block height is greater than or equal to a predetermined checkpoint height, obtaining a historical update record in the information update cache; The historical update records are serialized to obtain serialized data.

8. The method according to claim 7, characterized in that If the block height is greater than or equal to a predetermined checkpoint height, obtaining historical update records in the information update cache includes: If the block height is greater than or equal to a predetermined checkpoint height, applying a write lock to the information update cache; Copying the historical update records in the information update cache to obtain an update cache copy; Release the write lock of the information update cache.

9. The method according to claim 6, characterized in that Updating the local disk file corresponding to the information update cache according to the serialized data includes: Creating a replacement file for the information update cache based on the serialized data; Rename the current cache file of the information update cache to a file to be deleted; Rename the replacement file to the current cache file of the information update cache; Delete the file to be deleted.

10. The method according to claim 9, characterized in that The step of creating a replacement file for the information update cache according to the serialized data includes: If the replacement file of the information update cache and the current cache file exist, checking the integrity of the replacement file; If the replacement file is incomplete, obtaining updated information of blockchain information in blocks in the blockchain that are higher than the first block height according to the first block height in the current cache file; updating the information update cache and the current cache file according to the update information; Recreate the replacement file of the information update cache based on the serialized data.

11. The method according to claim 9, characterized in that The step of creating a replacement file for the information update cache according to the serialized data includes: If the file to be deleted and the replacement file exist in the information update cache, checking the integrity of the replacement file; If the replacement file is complete, obtaining updated information of blockchain information in blocks in the blockchain that are higher than the second block height according to the second block height in the replacement file; According to the update information, update the information update cache and the current cache file, and delete the to-be-deleted file; Recreate the replacement file of the information update cache based on the serialized data.

12. The method according to claim 9, characterized in that The step of creating a replacement file for the information update cache according to the serialized data includes: If the to-be-deleted file in the information update cache and the current cache file exist, obtaining updated information of the blockchain information in a block higher than the third block height in the blockchain according to the third block height in the current cache file; According to the update information, update the information update cache and the current cache file, and delete the to-be-deleted file; Recreate the replacement file of the information update cache based on the serialized data.

13. A device for obtaining blockchain information, characterized in that: include: a request acquisition module configured to acquire an information query request containing a target information identifier; a query record acquisition module configured to acquire, based on the information query request, a target historical query record corresponding to the target information identifier from the information query cache of the blockchain, wherein the historical query record in the information query cache includes the historical target information identifier of the historical information query request and the corresponding historical target information; an update record acquisition module, configured to, if the information query cache does not contain the target historical query record, acquire, based on the information query request, a historical update record corresponding to the target information identifier from the information update cache of the blockchain, where the historical update record of the information update cache is generated based on historical update operations of the blockchain information in the blockchain; The information acquisition module is configured to obtain the target information corresponding to the target information identifier from the information database of the blockchain if the historical update record indicates that the target information corresponding to the target information identifier exists.

14. An electronic device, characterized in that: include: processor; a memory for storing executable instructions of the processor; Wherein, the processor is configured to execute the method for obtaining blockchain information as described in any one of claims 1 to 12 by executing the executable instructions.

15. A computer-readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for obtaining blockchain information according to any one of claims 1 to 12 is implemented.

16. A computer program product, characterized in that The computer program product includes a computer program, which is stored in a computer-readable storage medium. The processor of the electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device performs the method for obtaining blockchain information as described in any one of claims 1 to 12.