Data processing method, device and server-side equipment based on blockchain
By clearing the block data in the cache in the order of block height from low to high in the blockchain, the problem of block production performance degradation caused by blockchain data query is solved, and the block production performance is achieved without affecting the block production performance , improve the efficiency of block data query.
Patent Information
- Application Number
- CN202011178426.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-28
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2040-10-28
AI Technical Summary
Blockchain data query leads to a degradation of block output performance. The existing technology causes read requests to directly reach the underlying storage engine by clearing caches regularly, affecting the performance of writing data and block consensus.
In the blockchain, each block corresponds to a block height, and the block data is stored in the cache and cleared from the cache in the order of the block height from low to high. After obtaining the query request for the target block, query the target block data of the target block from the cache.
Through this cache clearing order, block data with higher query frequency can be kept in the cache as much as possible, reducing read requests to the underlying storage engine, so as not to affect block production performance.
Smart Images

Figure CN112182114B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a blockchain-based data processing method, apparatus, and server-side device. Background Art
[0002] Currently, the method for querying blockchain data is to first query the corresponding block data in the cache. If the block data cannot be found in the cache, a read request is made to the underlying storage engine to query from the underlying storage engine.
[0003] Of course, in order to prevent the cache from growing infinitely, all caches will be cleared regularly through scheduled tasks, causing read requests to reach the underlying storage engine directly. In the case of a large amount of data queries, read requests to the underlying storage engine will reduce its data writing performance, which will in turn slow down its block consensus and reduce block performance. Summary of the invention
[0004] The purpose of this application is to provide a blockchain-based data processing method, device and server-side equipment to alleviate the technical problem of reduced block performance caused by block data query.
[0005] In a first aspect, an embodiment of the present application provides a data processing method based on a blockchain, wherein each block in the blockchain corresponds to a block height; the block data of the block is stored in a cache and is cleared from the cache in order of the block height from low to high; the method comprises:
[0006] Get the query request of the target block;
[0007] The target block data of the target block is queried from the cache based on the query request.
[0008] In a possible implementation, the block data stored in the cache is the block data when the block is completely flushed to the disk.
[0009] In a possible implementation, when the highest block height stored in the cache is higher than a preset height, the block data stored in the cache is cleared from the cache in order of the block heights from low to high until the highest block height stored in the cache is lower than or equal to the preset height.
[0010] In a possible implementation, when the highest block height stored in the cache is lower than or equal to the preset height, the block data of the block that has completed disk flushing is stored in the cache.
[0011] In a possible implementation, the block data of the plurality of blocks are stored in the cache in an ascending order of the block heights.
[0012] In a possible implementation, there is a corresponding relationship between the block index information and the block height of the same block; the step of querying the target block data of the target block from the cache based on the query request includes:
[0013] Based on the query request, determining target block index information corresponding to the target block height of the target block from the corresponding relationship;
[0014] The target block data of the target block is queried from the cache using the target block index information.
[0015] In a possible implementation, the block index information includes a block hash of the block; the block data includes block content; and the step of querying the target block data of the target block from the cache using the target block index information includes:
[0016] The target block content of the target block is queried from the cache using the target block hash in the target block index information.
[0017] In a possible implementation, the block index information includes a transaction hash of a transaction included in the block; the block data includes transaction content of the transaction included in the block; and the step of querying the target block data of the target block from the cache using the target block index information includes:
[0018] The target transaction content of the target transaction included in the target block is queried from the cache using the target transaction hash in the target block index information.
[0019] In a possible implementation, the multiple transaction hashes in the block index information are in the form of a list.
[0020] In a possible implementation, the transaction content includes a transaction process and a transaction result; the step of using the target transaction hash in the target block index information to query the target transaction content of the target transaction included in the target block from the cache includes:
[0021] The target transaction hash in the target block index information is used to query the target transaction process and target transaction result of the target transaction contained in the target block from the cache.
[0022] In a possible implementation, the corresponding relationship and the block index information are stored in the cache.
[0023] In a possible implementation, when the highest block height stored in the cache is higher than a preset height, the block data, the corresponding relationship, and the block index information stored in the cache are all cleared from the cache in order of the block heights from low to high until the highest block height stored in the cache is lower than or equal to the preset height.
[0024] In a second aspect, a data processing device based on a blockchain is provided, wherein each block in the blockchain corresponds to a block height; the block data of the block is stored in a cache and is cleared from the cache in the order of the block height from low to high; the device comprises:
[0025] The acquisition module is used to obtain the query request of the target block;
[0026] A query module is used to query the target block data of the target block from the cache based on the query request.
[0027] In a third aspect, an embodiment of the present application further provides a server-side device, including a memory and a processor, wherein the memory stores a computer program that can be executed on the processor, and when the processor executes the computer program, the method described in the first aspect is implemented.
[0028] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to execute the method described in the first aspect above.
[0029] The embodiments of the present application bring the following beneficial effects:
[0030] The embodiments of the present application provide a data processing method, apparatus and server-side device based on blockchain, wherein each block in the blockchain corresponds to a block height, and the order of multiple block heights from low to high represents the order of multiple block consensus successes from first to last, and the block data of the block is stored in a cache and cleared from the cache in order from low to high. After obtaining a query request for a target block, the target block data of the target block can be queried from the cache based on the query request. In this solution, the order of clearing the block data in the cache is in order from low to high block heights, that is, Block data is cleared in the order of first to last block consensus success. Since the newer the consensus success, the higher the query frequency of block data, the cache clearing order of this solution can ensure that the block data in the cache will not increase infinitely, and the block data with a higher query frequency can be retained in the cache as much as possible, instead of clearing the cache regularly in the prior art. Therefore, it is beneficial for the target block data to be queried to be successfully queried from the cache without having to query from the underlying storage engine. In this way, even if the amount of block data increases, it will not affect the block performance of the underlying storage engine.
[0031] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the specific implementation methods of the present application or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0033] Figure 1 A schematic diagram of the existing data query process is shown;
[0034] Figure 2 A schematic diagram of an application scenario provided by an embodiment of the present application is shown;
[0035] Figure 3 A schematic diagram of the structure of a server device provided in an embodiment of the present application is shown;
[0036] Figure 4 A flowchart of a blockchain-based data processing method provided in an embodiment of the present application;
[0037] Figure 5 A schematic diagram of the structure of a blockchain-based data processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution of the present application will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present application.
[0039] The terms "including" and "having" and any variations thereof mentioned in the embodiments of the present application are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device including a series of steps or units is not limited to the listed steps or units, but may optionally include other steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.
[0040] At present, in the public chain, alliance chain and private chain based on the Ethereum architecture, the query method for any data is to query from the underlying storage engine when it cannot be queried from the cache. For example, to obtain block details based on block hash, and to query transaction details based on transaction hash, the corresponding cache is queried first. If it cannot be queried in the cache, it is queried through the underlying storage engine level db. The original Ethereum cache implementation method is that when the client or Ethereum node itself needs to query a certain type of data, such as querying block information through block hash, it first passes through the block cache (m_BlockCache), at which time the key is the block hash and the value is the block information (Block info). For another example, for the transaction memory cache (m_Transaction), the key is the transaction hash and the value is the transaction information (tranaction_info). If the corresponding data can be obtained directly from the m_Block Cache, it is returned directly, otherwise it is queried from the level db based on the block hash. If the data exists in the level db, the Block info is written to the m_BlockCache. Of course, in order to prevent the cache from growing infinitely, Ethereum will clear all caches regularly through scheduled tasks.
[0041] For example, Figure 1As shown, in the current construction of the cache structure in Ethereum, the client needs to query Block_info through Block_hash. According to the query type and query key (i.e. Block_hash), first query from the cache (Cache) of the block information (m_Blocks). If it exists in the cache, it is returned directly. If it cannot be found through the cache, it is directly obtained from the db. If it does not exist in the db, it is directly returned empty. If the query from the db is successful, the query content is written to the cached block information (m_Blocks), and then the query result is returned. Finally, there is a scheduled task, which is to clear the above cache regularly.
[0042] In actual applications, both inside the Ethereum node and in the Ethereum client, a large number of tasks are required to query the recent relevant block information. For example, before the block with a block height (referred to as block height) of n is produced, it is necessary to verify and query the parent block (block with a block height of n-1) and the grandparent block (block with n-2). At this time, it is necessary to obtain the corresponding block information, so it is necessary to rely on the cache of the above-mentioned parent block and grandparent block. For another example, when the client initiates a transaction to the eth node, the transaction initiated by the client is considered successful only when it is packaged into the specified block and the packaged block is successfully recognized by consensus, and the client queries the corresponding transaction result through the transaction hash.
[0043] It can be seen that there are a large number of query requirements in the nodes of Ethereum, and most of the queries are for the most recently relevant block information. Here, "most recently relevant" means that the higher the block height, the higher the query frequency. Since the existing Ethereum solution will clear the cache regularly, the query request will be directly hit on the underlying storage engine level db. On the other hand, in the case of large data volumes (such as tens of billions, hundreds of billions of data volumes), a large number of read requests to level db will cause a linear decrease in the performance of level db writing data, and the decrease in level db writing data performance will cause its consensus to slow down, especially in the alliance chain of the Ethereum architecture, the impact is greater. Therefore, the existing Ethereum cache solution will lead to a decrease in block performance after the amount of block data increases.
[0044] Based on this, the embodiments of the present application provide a blockchain-based data processing method, apparatus, and server-side device, through which the technical problem of decreased block performance caused by block data query can be alleviated.
[0045] The blockchain-based data processing method in the embodiment of the present application can be applied to a server-side device, wherein the server-side device includes a memory and a processor.
[0046] In some embodiments, when querying the block data in the cache through the server device, the query request can be a query request issued locally by the server device, or a query request issued by the peer client.
[0047] For example, Figure 2 As shown, Figure 2 Schematic diagram of an application scenario provided for an embodiment of the present application. The application scenario may include a server device (e.g., server 201) and a client (e.g., mobile phone 202), and the server device may communicate with the client via a wired network or a wireless network. Among them, server 201 is used to respond to a query request for block data, which may be a query request issued locally by server 201 or a query request issued by mobile phone 202.
[0048] The server device of this embodiment is described by taking server 201 as an example. Server 201 includes a memory 2011 and a processor 2012. The memory stores a computer program that can be run on the processor. When the processor executes the computer program, the steps of the method provided in the embodiment of the present application are implemented. Those skilled in the art can understand that Figure 3 The server structure shown in the figure does not constitute a limitation on the server, and may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently.
[0049] See also Figure 3 The server 201 further includes: a bus 2013 and a communication interface 2014, the processor 2012, the communication interface 2014 and the memory 2011 are connected via the bus 2013; the processor 2012 is used to execute executable modules stored in the memory 2011, such as computer programs.
[0050] The memory 2011 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 2014 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0051] The bus 2013 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0052] Among them, the memory 2011 is used to store programs, and the processor 2012 executes the program after receiving the execution instruction. The method executed by the device defined by the process disclosed in any embodiment of the present application below can be applied to the processor 2012 or implemented by the processor 2012.
[0053] The processor 2012 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the following method can be completed by the hardware integrated logic circuit or software instructions in the processor 2012. The processor 2012 described below can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 2011, and the processor 2012 reads the information in the memory 2011 and completes the steps of the method provided in the embodiment of the present application in combination with its hardware.
[0054] The embodiments of the present application are further introduced below.
[0055] Figure 4 A flowchart of a data processing method based on blockchain provided by an embodiment of the present application. Each block in the blockchain corresponds to a block height, and the order of multiple block heights from low to high can represent the order of multiple block consensus successes from first to last; the block data of the block is stored in the cache and is cleared from the cache in the order of block heights from low to high. Figure 4 As shown, the method includes:
[0056] Step S410, obtaining a query request for a target block.
[0057] The query request may be a query request sent locally by the server device, or a query request sent by the client.
[0058] For the cache structure in the embodiment of the present application, the task of clearing the block data therein at a regular interval is no longer performed. Instead, the block data is cleared from the cache in order from low to high block heights, that is, the corresponding block data in the cache is cleared in order from first to last according to the successful block consensus.
[0059] Step S420 , querying the target block data of the target block from the cache based on the query request.
[0060] In the embodiment of the present application, the order of clearing the block data in the cache is in the order from low to high according to the block height, that is, clearing the block data in the order from first to last according to the success of the block consensus. Since the newer the consensus is, the higher the query frequency of the block data is, through this cache clearing order of the present solution, on the basis of ensuring that the amount of block data in the cache will not increase indefinitely, the block data with a higher query frequency can be retained in the cache as much as possible, instead of the timed clearing of the cache in the prior art. Therefore, it is beneficial for the target block data to be queried to be smoothly queried from the cache without having to query from the underlying storage engine. In this way, even if the amount of block data increases, it will not affect the block performance of the underlying storage engine. The method provided in the embodiment of the present application can also be used in the blockchain cache query mechanism of the Ethereum and other architectures.
[0061] The above steps are described in detail below.
[0062] In some embodiments, the block data of the block can be written into the cache when the block is completed. Based on this, the block data stored in the cache is the block data when the block is completed.
[0063] In practical applications, the time to write block data into the cache can be the stage where the block is dropped to disk. When a block with a block height of n is successfully agreed upon, the block will be dropped to disk, and the block data of the block can be written to the cache during the stage where the block is dropped to disk. The time when a block is dropped to disk is visible to the outside world. Therefore, choosing to write the block to the cache synchronously when the block is dropped to disk can maintain the consistency of the block data in the cache and ensure that the block with successful consensus can be written to the cache.
[0064] In some embodiments, the trigger condition for clearing the block data in the cache may be a situation where the amount of blocks in the cache exceeds a certain threshold. As an example, when the highest block height stored in the cache is higher than a preset height, the block data stored in the cache is cleared from the cache in order of block height from low to high until the highest block height stored in the cache is lower than or equal to the preset height.
[0065] For example, if the amount of blocks in the cache structure (m_blcokCacheStructs) is full, such as greater than the preset value N, the block structure with the smallest block height in m_blcokCacheStructs is removed until the size of m_blcokCacheStructs is equal to or less than N.
[0066] By clearing blocks in descending order when the preset value is exceeded, the logic of scheduled cache clearing can be removed. While ensuring that the amount of block data in the cache does not exceed the limit, block data with a higher query frequency can be retained in the cache as much as possible.
[0067] Based on this, the block data that has been written to the disk can be written into the cache when the cache is not full. As an example, when the highest block height stored in the cache is lower than or equal to the preset height, the block data of the block that has been written to the disk is stored in the cache.
[0068] Exemplarily, when the size of the cache structure (m_blcokCacheStructs) does not exceed the preset value, when the block with a block height of a is completed, the relevant information of the block corresponding to the block height of a is written into the cache.
[0069] For example, after the consensus of the block with block height a succeeds, the following information can be persisted: block details [Block(block)_hash->Block(block)_info(information)]; transaction list contained in the current block [thash1->Transaction1, thash2->Transaction2, thash3->Transaction3]; transaction result list contained in the current block [thash1->receipt1, thash2->receipt 2, thash3->receipt 3]. After the above information is persisted, the write cache information can be constructed to implement a mechanism for block cache query based on block height.
[0070] In some embodiments, the storage order of the blocks in the cache may also be in the order of block height from low to high. As an example, the block data of multiple blocks are stored in the cache in the order of block height from low to high.
[0071] In practical applications, blockchain can generate blocks in a way that the block height increases by one, that is, the block height starts from 0, the first block height is 0, then the second block height is 1, the third block height is 2, the fourth block height is 3... and so on.
[0072] By storing the corresponding block data in the cache in order from low to high block heights, the data query process in the cache can be facilitated.
[0073] Based on this, the block index information to be queried can be obtained from the correspondence between the block index information and the block height, and then the block index information is used to query the target block data from the cache. As an example, there is a correspondence between the block index information and the block height of the same block; the above step S420 may include the following steps:
[0074] Step a), based on the query request, determining the target block index information corresponding to the target block height of the target block from the corresponding relationship;
[0075] Step b), using the target block index information to query the target block data of the target block from the cache.
[0076] For example, in the mechanism of implementing block cache query based on block height, the block cache index structure (BlockCacheStruct) can contain block index information such as block height (Block Num), block hash (Block Hash), and transaction hash (TransactionHashes) contained in the block. And m_blcokCacheStructs is the key to implementing the block cache query mechanism based on block height, where the query key is the block height and the query value is a BlockCache Struct.
[0077] By obtaining the target block index information corresponding to the target block height from the correspondence between the block index information and the block height, the target block data can be quickly and efficiently queried from the cache using the target block index information.
[0078] In some embodiments, when a block is successfully agreed upon, the memory for storing the block may include various information related to the block, such as block information, transaction details, and transaction results (receipt), etc. Based on this, the above step b) may include multiple implementation methods.
[0079] As an example, block information can be queried from the cache through block hash. For example, the block index information includes the block hash of the block; the block data includes the block content; the above step b) may include the following steps:
[0080] Step c), using the target block hash in the target block index information, query the target block content of the target block from the cache.
[0081] In actual applications, Block_info can be queried through Block_hash. By using block hash to query block information from the cache, block information can be queried quickly, accurately and efficiently.
[0082] As another example, transaction related information can be queried from the cache through the transaction hash. For example, the block index information includes the transaction hash of the block containing the transaction; the block data includes the transaction content of the block containing the transaction; the block data includes the block content; the above step b) may include the following steps:
[0083] Step d), using the target transaction hash in the target block index information, query the target transaction content of the target transaction contained in the target block from the cache.
[0084] By using the transaction hash to query transaction-related information from the cache, the query process can be made faster, more accurate, and more efficient.
[0085] Based on the above step d), if the number of transaction hashes is large, multiple transaction hashes can be in a list form that is easy to query. As an example, multiple transaction hashes in the block index information are in a list form.
[0086] For example, in a mechanism for implementing block cache query based on block height, the block cache index structure (BlockCache Struc) can include a list of transaction hashes of transactions contained in the block. Through the form of a transaction hash list, the transaction query speed can be improved.
[0087] Based on the above step d), the transaction-related information may be various information related to the transaction. As an example, the transaction content includes the transaction process and the transaction result; the above step d) may include the following steps:
[0088] Step e), using the target transaction hash in the target block index information, query the target transaction process and target transaction result of the target transaction contained in the target block from the cache.
[0089] For example, you can use the transaction hash to query the transaction process, that is, [thash1->Transaction1, thash2->Transaction2, thash3->Transaction3]; you can also use the transaction hash to query the transaction result, that is, [thash1->receipt1, thash2->receipt 2, thash3->receipt 3]. Through the transaction hash, you can query various information related to the transaction, such as the transaction process and transaction results.
[0090] Based on the above steps a) and b), the corresponding relationship and block index information can be stored in the cache. For the process of storing the corresponding relationship and block index information in the cache, exemplarily, the cache index structure temp can be first constructed, including: a (block height), Block (block)_hash, [thash1, thash2, thash3], and then "a->temp" is written into m_blcokCacheStructs; then, [Block_hash->Block_info (information)] is written into m_Blocks; [thash1->Transaction1, thash2->Transaction2, thash3->Transaction3] is written into m_Transactions Address; [thash1->receipt1, thash2->receipt 2, thash3->receipt 3] is written into m_receipts.
[0091] By storing the corresponding relationship and block index information in the cache, the target block index information can be queried more quickly, and then the target block data can be queried quickly.
[0092] Based on this, the corresponding relationship and block index information in the cache can also be removed along with the clearing of the corresponding block data. For example, when the highest block height stored in the cache is higher than the preset height, the block data, corresponding relationship and block index information stored in the cache are cleared from the cache in the order of block height from low to high until the highest block height stored in the cache is lower than or equal to the preset height.
[0093] In actual applications, if the amount of blocks in the cache structure (m_blcokCacheStructs) is full, such as greater than the preset value N, the block structure with the smallest block height in m_blcokCacheStructs is removed, and the corresponding relationship and block index information corresponding to the block structure with the smallest block height are also removed from m_Blocks, m_TransactionsAddress, m_receipts, etc., until the size of m_blcokCacheStructs is equal to or less than the preset value N.
[0094] By removing the corresponding relationship and block index information in the cache along with the clearing of the corresponding block data, the use space of the cache can be increased and the use efficiency of the cache can be improved.
[0095] Figure 5A schematic diagram of a data processing device based on blockchain is provided. Each block in the blockchain corresponds to a block height; the block data of the block is stored in a cache and is cleared from the cache in the order of the block height from low to high. Figure 5 As shown, the blockchain-based data processing device 500 includes:
[0096] An acquisition module 501 is used to acquire a query request for a target block;
[0097] The query module 502 is configured to query the target block data of the target block from the cache based on the query request.
[0098] In some embodiments, the block data stored in the cache is the block data when the block is completely flushed to the disk.
[0099] In some embodiments, when the highest block height stored in the cache is higher than a preset height, the block data stored in the cache is cleared from the cache in order of the block heights from low to high until the highest block height stored in the cache is lower than or equal to the preset height.
[0100] In some embodiments, when the highest block height stored in the cache is lower than or equal to the preset height, the block data of the block that has completed disk flushing is stored in the cache.
[0101] In some embodiments, the block data of the plurality of blocks are stored in the cache in an ascending order of the block heights.
[0102] In some embodiments, there is a corresponding relationship between the block index information and the block height of the same block; the query module 502 is specifically used to:
[0103] Based on the query request, determining target block index information corresponding to the target block height of the target block from the corresponding relationship;
[0104] The target block data of the target block is queried from the cache using the target block index information.
[0105] In some embodiments, the block index information includes the block hash of the block; the block data includes the block content; the query module 502 is further used to:
[0106] The target block content of the target block is queried from the cache using the target block hash in the target block index information.
[0107] In some embodiments, the block index information includes a transaction hash of a transaction included in the block; the block data includes a transaction content of the transaction included in the block; the query module 502 is further used to:
[0108] The target transaction content of the target transaction included in the target block is queried from the cache using the target transaction hash in the target block index information.
[0109] In some embodiments, the multiple transaction hashes in the block index information are in the form of a list.
[0110] In some embodiments, the transaction content includes the transaction process and transaction results; the query module 502 is specifically used to:
[0111] The target transaction hash in the target block index information is used to query the target transaction process and target transaction result of the target transaction contained in the target block from the cache.
[0112] In some embodiments, the corresponding relationship and the block index information are stored in the cache.
[0113] In some embodiments, when the highest block height stored in the cache is higher than a preset height, the block data, the corresponding relationship, and the block index information stored in the cache are all cleared from the cache in order of the block heights from low to high until the highest block height stored in the cache is lower than or equal to the preset height.
[0114] The blockchain-based data processing device provided in the embodiment of the present application has the same technical features as the blockchain-based data processing method provided in the above embodiment, so it can also solve the same technical problems and achieve the same technical effects.
[0115] Corresponding to the above-mentioned blockchain-based data processing method, an embodiment of the present application also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to execute the steps of the above-mentioned blockchain-based data processing method.
[0116] The blockchain-based data processing device provided in the embodiment of the present application can be specific hardware on the device or software or firmware installed on the device. The device provided in the embodiment of the present application has the same implementation principle and technical effects as the aforementioned method embodiment. For the sake of brief description, the parts not mentioned in the device embodiment can refer to the corresponding contents in the aforementioned method embodiment. It can be clearly understood by technicians in the relevant field that for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above can all refer to the corresponding processes in the aforementioned method embodiment, and will not be repeated here.
[0117] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0118] For another example, the flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the device, method and computer program product according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the 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 a different order from the order marked in the accompanying drawings. For example, two consecutive boxes 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 and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0119] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0120] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0121] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the blockchain-based data processing method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., and other media that can store program codes.
[0122] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and are not to be understood as indicating or implying relative importance.
[0123] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solution of the present application, rather than to limit it. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the aforementioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solution recorded in the aforementioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solution deviate from the scope of the technical solution of the embodiment of the present application. They should all be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A data processing method based on blockchain, characterized in that: Each block in the blockchain corresponds to a block height; the block data of the block is stored in a cache and is cleared from the cache in order of the block height from low to high; The method comprises: A query request for obtaining a target block; the block data of the plurality of blocks are stored in the cache in the order of the block height from low to high; there is a corresponding relationship between the block index information and the block height of the same block; the block index information includes the block hash of the block; the block data includes the block content; Based on the query request, determining target block index information corresponding to the target block height of the target block from the corresponding relationship; The target block content of the target block is queried from the cache using the target block hash in the target block index information.
2. The method according to claim 1, characterized in that: The block data stored in the cache is the block data when the block is completely written to the disk.
3. The method according to claim 1, characterized in that When the highest block height stored in the cache is higher than a preset height, the block data stored in the cache is cleared from the cache in order of the block heights from low to high until the highest block height stored in the cache is lower than or equal to the preset height.
4. The method according to claim 3, characterized in that In a case where the highest block height stored in the cache is lower than or equal to the preset height, the block data of the block that has completed disk placement is stored in the cache.
5. The method according to claim 1, characterized in that The block index information includes a transaction hash of a transaction included in the block; the block data includes transaction content of the transaction included in the block; and the step of querying the target block data of the target block from the cache using the target block index information includes: The target transaction content of the target transaction included in the target block is queried from the cache using the target transaction hash in the target block index information.
6. The method according to claim 5, characterized in that The multiple transaction hashes in the block index information are in the form of a list.
7. The method according to claim 5, characterized in that The transaction content includes a transaction process and a transaction result; the step of using the target transaction hash in the target block index information to query the target transaction content of the target transaction included in the target block from the cache includes: The target transaction hash in the target block index information is used to query the target transaction process and target transaction result of the target transaction contained in the target block from the cache.
8. The method according to claim 1, characterized in that The corresponding relationship and the block index information are stored in the cache.
9. The method according to claim 8, characterized in that When the highest block height stored in the cache is higher than a preset height, the block data, the corresponding relationship and the block index information stored in the cache are all cleared from the cache in order of the block heights from low to high until the highest block height stored in the cache is lower than or equal to the preset height.
10. A data processing device based on blockchain, characterized in that: Each block in the blockchain corresponds to a block height; the block data of the block is stored in a cache and is cleared from the cache in order of the block height from low to high; The device comprises: The acquisition module is used to obtain the query request of the target block; A query module, configured to query the target block data of the target block from the cache based on the query request; The block data of the plurality of blocks are stored in the cache in the order of the block height from low to high; there is a corresponding relationship between the block index information and the block height of the same block; the query module is specifically used to: determine the target block index information corresponding to the target block height of the target block from the corresponding relationship based on the query request; and query the target block data of the target block from the cache using the target block index information; The block index information includes the block hash of the block; the block data includes block content; the query module is also used to: use the target block hash in the target block index information to query the target block content of the target block from the cache.
11. A server device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 9 are implemented.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Block-link data shrinking method and device and storage medium
CN109324757A
Transaction data storage control method and device and storage medium
CN110222116A
Method for improving response speed of block chain, block chain application system and related equipment
CN110830581A