Block chain data processing method and device, electronic equipment and storage medium
By selecting target data units in the blockchain for compression processing and hash snapshot generation, the problems of blockchain data storage pressure and low recovery efficiency are solved, hardware costs are reduced, and data recovery speed is improved.
Patent Information
- Application Number
- CN202310184186.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-22
- Publication Date
- 2024-08-23
AI Technical Summary
With the development of blockchain applications, the storage resources occupied by data and consensus signatures gradually increase, resulting in rising hardware costs and low data recovery efficiency.
By detecting the number of data units in the blockchain, when it reaches a certain threshold, the target data unit is automatically selected for compression processing, hash processing is used to generate a local hash snapshot for consistency verification, and a global hash snapshot is generated and the blockchain is trimmed. Data unit, reducing storage and processing pressure.
During the consensus process, only the transaction hash value is stored and verified, eliminating the consensus signature in the target data unit, reducing the amount of data that needs to be stored, reducing data storage pressure, and reducing the hardware cost of blockchain technology applications. And achieve rapid data recovery.
Smart Images

Figure CN118537121A
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a method, device, electronic device and storage medium for processing blockchain data. Background Art
[0002] Nowadays, with the development of computer technology, more and more related applications have been developed, which have brought many conveniences to people's work and study. Among them, blockchain technology is a new application model that includes computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Due to its decentralized, open, and tamper-proof characteristics, it has very broad application prospects in many fields such as finance, digital services, and the Internet of Things.
[0003] In related technologies, when using blockchain, it is necessary to store corresponding transaction data, status data and consensus node consensus signatures on data in order to trace, verify and recover data. As the requirements for high throughput and low latency of blockchain continue to increase, the structural growth rate of blockchain and the storage pressure of related data have increased significantly, resulting in data and consensus signatures occupying a large amount of storage resources, increasing the hardware cost of blockchain technology applications. Summary of the invention
[0004] The embodiments of the present application provide a method, device, electronic device and storage medium for processing blockchain data, which can periodically compress data and blockchain structure, reduce data storage pressure, and help reduce the hardware cost of blockchain technology applications.
[0005] On the one hand, an embodiment of the present application provides a method for processing blockchain data, the method comprising:
[0006] Detecting the number of data units in the current blockchain; wherein the data unit is used to store a transaction certificate, and the transaction certificate includes a transaction hash value;
[0007] When the number of the data units is greater than or equal to the first number, selecting a second number of target data units from the blockchain, and obtaining a target transaction hash value in the target data unit; wherein the second number is less than the first number;
[0008] According to the target transaction hash value, obtaining target status data of the transaction item corresponding to the target data unit;
[0009] Performing hash processing on the target transaction hash value and the target state data to obtain a first hash value, and establishing a local hash snapshot according to the first hash value;
[0010] Sending the local hash snapshot to a consensus node for consistency verification, receiving a first consensus signature returned by the consensus node, and generating a global hash snapshot based on the first consensus signature and the local hash snapshot;
[0011] The global hash snapshot is sent to the consensus node for storage, and the target data unit in the blockchain is pruned.
[0012] On the other hand, the embodiment of the present application also provides a blockchain data processing device, including:
[0013] A detection unit, used to detect the number of data units in the current blockchain; wherein the data unit is used to store a transaction certificate, and the transaction certificate includes a transaction hash value;
[0014] a selection unit, configured to select a second number of target data units from the blockchain when the number of the data units is greater than or equal to the first number, and obtain a target transaction hash value in the target data units; wherein the second number is less than the first number;
[0015] An acquisition unit, configured to acquire target status data of the transaction item corresponding to the target data unit according to the target transaction hash value;
[0016] a processing unit, configured to perform hash processing on the target transaction hash value and the target state data to obtain a first hash value, and to establish a local hash snapshot according to the first hash value;
[0017] A verification unit, configured to send the local hash snapshot to a consensus node for consistency verification, receive a first consensus signature returned by the consensus node, and generate a global hash snapshot based on the first consensus signature and the local hash snapshot;
[0018] A pruning unit is used to send the global hash snapshot to the consensus node for storage and prune the target data unit in the blockchain.
[0019] Furthermore, the blockchain data processing device further includes a construction unit, which is specifically used to:
[0020] Obtain transaction data of transaction items;
[0021] Performing hash processing on the transaction data to obtain the transaction hash value;
[0022] Sending the transaction data and the transaction hash value to a consensus node for consistency verification, and receiving a second consensus signature returned by the consensus node;
[0023] The transaction hash value and the second consensus signature are packaged into a transaction certificate, and a data unit corresponding to the transaction certificate is established.
[0024] Furthermore, the processing device further includes a sorting unit, which is specifically configured to:
[0025] Detecting the depth level of each data unit in the blockchain;
[0026] The data units are sorted according to the depth layer number to obtain a first sequence number corresponding to each of the data units.
[0027] Furthermore, the above-mentioned selection unit is specifically used for:
[0028] Sort the data units in ascending order according to the corresponding first sequence numbers, and select the second several data units with the highest order as target data units;
[0029] Alternatively, the data units are sorted in descending order according to the corresponding first sequence numbers, and the second few data units with the lowest sorting order are selected as the target data units.
[0030] Furthermore, the blockchain data processing device further includes a number determination unit, which is specifically used to:
[0031] Detecting the data throughput of the blockchain in a preset time period;
[0032] Determining the second number according to the data throughput;
[0033] The data throughput is positively correlated with the size of the second number.
[0034] Furthermore, the acquisition unit is specifically used for:
[0035] According to the target transaction hash value, determine the target transaction item corresponding to the target data unit by matching the transaction data of each transaction item;
[0036] According to the target transaction item, the target status data is obtained.
[0037] Furthermore, the above processing unit is specifically used for:
[0038] Sort the target transaction hash values according to the first sequence numbers corresponding to the target data units to obtain a transaction metadata sequence;
[0039] Sorting the target state data according to the first sequence number corresponding to the target data unit to obtain a state change sequence;
[0040] The transaction metadata sequence and the state change sequence are integrated, and the integrated data are hashed to obtain the first hash value.
[0041] Furthermore, the above processing unit is specifically used for:
[0042] Determine a second sequence number corresponding to the local hash snapshot according to the first sequence number corresponding to the target data unit and the second number;
[0043] Determine the depth field information corresponding to the local hash snapshot according to the depth layer number of each target data unit;
[0044] Performing hash processing on the second serial number, the depth field information, and the first hash value to obtain a second hash value, and obtaining a local signature according to the second hash value;
[0045] The second serial number, the depth field information, the first hash value, and the local signature are packaged to obtain the local hash snapshot.
[0046] Furthermore, the verification unit is specifically used for:
[0047] Sending the local hash snapshot to a consensus node, performing hash processing on the second sequence number, the depth field information and the first hash value through the consensus node to obtain a third hash value; verifying whether the third hash value is consistent with the second hash value through the consensus node, and passing consistency verification if the third hash value is consistent with the second hash value;
[0048] Alternatively, the local hash snapshot is sent to a consensus node, the target transaction hash value and the target status data are obtained by the consensus node according to the second serial number, and the target transaction hash value and the target status data are hashed to obtain a fourth hash value; the consensus node verifies whether the first hash value and the fourth hash value are consistent, and if the first hash value and the fourth hash value are consistent, the consistency verification is passed.
[0049] Furthermore, the verification unit is specifically used for:
[0050] Receive and accumulate the third number of the first consensus signature returned by the consensus node;
[0051] When the third number is greater than or equal to a preset threshold, each of the first consensus signatures is added to the local hash snapshot to generate the global hash snapshot.
[0052] Furthermore, the blockchain data processing device further includes a recovery unit, which is used to:
[0053] Sending a data recovery request to the consensus node, and receiving the global hash snapshot returned by the consensus node;
[0054] Obtaining original transaction data and original status data of transaction items;
[0055] Performing consistency check on the original transaction data and the original status data according to the global hash snapshot;
[0056] When the original transaction data and the original status data pass verification, the target data unit is restored according to the target transaction data.
[0057] Furthermore, the above recovery unit is specifically used for:
[0058] Performing hash processing on the original transaction data to obtain a fifth hash value;
[0059] Performing hash processing on the fifth hash value and the original state data to obtain a sixth hash value;
[0060] Verify whether the first Hash value and the sixth Hash value are consistent. If the first Hash value and the sixth Hash value are consistent, the consistency verification is passed.
[0061] On the other hand, an embodiment of the present application further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-mentioned blockchain data processing method when executing the computer program.
[0062] On the other hand, an embodiment of the present application also provides a computer-readable storage medium, which stores a program, and the program is executed by a processor to implement the above-mentioned blockchain data processing method.
[0063] On the other hand, the embodiment of the present application further provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of the computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the above-mentioned blockchain data processing method.
[0064] The embodiments of the present application at least include the following beneficial effects: the present application provides a method, device, electronic device and storage medium for processing blockchain data, detects the number of data units in the current blockchain, and when it is greater than or equal to the first number, automatically selects the target data unit of the second number from the blockchain for compression processing, so that the structure of the blockchain can be periodically compressed to reduce its structural redundancy; in the data compression process, the corresponding target state data is found according to the target transaction hash value in the target data unit, and then the target transaction hash value and the target state data are hashed to establish a local hash snapshot, save the business data of the corresponding target data unit, and transmit the local hash snapshot to the consensus node for verification, and generate a global hash snapshot after consensus. In the scheme of the embodiment of the present application, in the consensus process, only the transaction hash value needs to be stored and verified, and the transaction data does not need to be processed, which can reduce the amount of data processing; in the global hash snapshot, the information of the original transaction hash value is retained, and the consensus signature in each target data unit is omitted. On the basis of achieving data consensus, the amount of data that needs to be stored can be reduced, reducing the pressure of data storage, which is conducive to reducing the hardware cost of blockchain technology applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] The accompanying drawings are used to provide further understanding of the technical solution of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the technical solution of the present application and do not constitute a limitation on the technical solution of the present application.
[0066] Figure 1 A schematic diagram of an implementation environment of a blockchain data processing method provided in an embodiment of the present application;
[0067] Figure 2 A flowchart of a method for processing blockchain data provided in an embodiment of the present application;
[0068] Figure 3 A schematic diagram of the principle of generating a data unit provided in an embodiment of the present application;
[0069] Figure 4 A schematic diagram of a consensus process between nodes provided in an embodiment of the present application;
[0070] Figure 5 A schematic diagram of data unit sorting of a blockchain with a single chain structure provided in an embodiment of the present application;
[0071] Figure 6 A schematic diagram of data unit sorting of a blockchain with a DAG structure provided in an embodiment of the present application;
[0072] Figure 7 A schematic diagram of the data content of a local hash snapshot provided in an embodiment of the present application;
[0073] Figure 8 A schematic diagram of data content of a global hash snapshot provided in an embodiment of the present application;
[0074] Fig. 9 A flowchart of another method for processing blockchain data provided in an embodiment of the present application;
[0075] Fig.10 A schematic diagram of a specific implementation flow of a method for processing blockchain data provided in an embodiment of the present application;
[0076] Fig.11 A structural block diagram of a blockchain data processing device provided in an embodiment of the present application;
[0077] Fig.12 A structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0078] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and are not to be construed as limitations on the present application. For the step numbers in the following embodiments, they are only provided for the convenience of explanation, and the order between the steps is not limited in any way, and the execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.
[0079] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0080] Before describing the embodiments of the present application in detail, some nouns and terms involved in the embodiments of the present application are first described. The nouns and terms involved in the embodiments of the present application are subject to the following explanations.
[0081] 1) Blockchain: Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0082] The underlying blockchain platform can include processing modules such as object management, basic services, smart contracts, and operation management. Among them, the object management module is responsible for the identity information management of all blockchain participants, including maintaining public and private key generation (account management), key management, and maintaining the correspondence between the object's real identity and blockchain address (authority management), etc., and in the case of authorization, it identifies the transaction status of certain real identities and provides risk control rule configuration (risk control audit); the basic service module is deployed on all blockchain node devices to verify the validity of business requests, and records valid requests to storage after consensus is reached. For a new business request, the basic service first performs interface adaptation analysis and authentication processing (interface adaptation), and then encrypts the business information through the consensus algorithm (consensus management) , after encryption, it is completely and consistently transmitted to the shared ledger (network communication) and recorded and stored; the smart contract module is responsible for the registration and issuance of contracts, as well as contract triggering and contract execution. Developers can define the contract logic in a programming language and publish it to the blockchain (contract registration). According to the logic of the contract terms, the key or other event trigger execution is called to complete the contract logic. At the same time, it also provides the function of contract upgrade and cancellation; the operation management module is mainly responsible for the deployment, configuration modification, contract setting, cloud adaptation and real-time status visualization output of the product during the product release process, such as alarm, query network status, query node equipment health status, etc.
[0083] The platform product service layer provides the basic capabilities and implementation framework of typical applications. Developers can superimpose business features based on these basic capabilities to complete the blockchain implementation of business logic. The application service layer provides application services based on blockchain solutions for business participants to use.
[0084] 2) The consensus mechanism is to solve the trust problem caused by the core concept of decentralization on the basis of blockchain. Because in the blockchain, nodes are unknown and unreliable by default, and each node cannot know whether other nodes are down or betrayed, so the accuracy and security of recorded information can be guaranteed as much as possible. At the same time, the more dispersed the nodes are, the lower the efficiency is, and the higher the network's satisfaction with information is, the safer it is.
[0085] 3) Directed Acyclic Graph (DAG). From the perspective of computers, DAG is a graph. Like arrays, queues, and linked lists, graphs are data structures. Graphs are data structures composed of vertices and edges connecting vertices. In computer science, graphs are one of the most flexible data structures, and many problems can be modeled and solved using graph models. For example, social networks between people, analyzing the topology of computer networks to determine whether two computers can communicate, finding the shortest path between two locations in a logistics system, and so on.
[0086] The blockchain data processing method provided in the embodiments of the present application can be executed in scenarios involving the use of blockchain technology such as financial services, data analysis, and public services, and can specifically involve applications such as insurance business, asset securitization, digital bills, shopping payments, credit management, digital copyright, and identity (qualification) authentication.
[0087] For example, in the application scenario of insurance business, information about personal health status, accident records, etc. can be uploaded to the blockchain, so that insurance companies can obtain risk information more timely and accurately when customers take out insurance, thereby reducing underwriting costs and improving business efficiency. The sharing and transparency of blockchain technology can reduce the risk of information asymmetry; its historical traceability is conducive to reducing the difficulty and cost of insurance management.
[0088] For example, in the application scenario of credit management, the lack of data sharing often leads to information asymmetry between credit reporting agencies and limited collection channels, which makes the battle for data sources consume a lot of unnecessary costs; moreover, with the prominence of data privacy protection issues, traditional technical architectures are difficult to meet new requirements. Blockchain technology has the characteristics of decentralization, trustlessness, timestamps, asymmetric encryption and smart contracts. On the technical level, it can achieve limited and controllable credit data sharing and verification on the basis of effectively protecting data privacy.
[0089] For example, in the application scenarios of public services, such as education, charity, and public welfare, the public trust problem of information is objective. The traditional way is to rely on a credible third party for credit endorsement, but data fraud and lack of credit still exist. Blockchain technology can ensure the integrity, permanence, and immutability of data, and thus can effectively solve the difficulties and pain points of these industries in terms of evidence storage, traceability, association, and backtracking.
[0090] Of course, it should be noted that the above application scenarios are only exemplary and do not limit the actual application of the method in the embodiment of the present application. Those skilled in the art can understand that in different application scenarios, the method provided in the embodiment of the present application can be used to perform the specified task.
[0091] Furthermore, it should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on the target object's information, the target object's behavioral data, the target object's historical data, and the target object's location information and other data related to the target object's identity or characteristics, the target object's permission or consent will be obtained first, and the collection, use and processing of these data will comply with the relevant laws, regulations and standards of the relevant countries and regions. In addition, when the embodiment of the present application needs to obtain sensitive information of the target object, the target object's separate permission or separate consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the target object's separate permission or separate consent, the necessary target object-related data used to enable the normal operation of the embodiment of the present application will be obtained.
[0092] Nowadays, with the development of computer technology, more and more related applications have been developed, which have brought many conveniences to people's work and study. Among them, blockchain technology is a new application model that includes computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Due to its decentralized, open, and tamper-proof characteristics, it has very broad application prospects in many fields such as finance, digital services, and the Internet of Things.
[0093] Traditional blockchain systems generally include data layer, network layer, consensus layer, incentive layer, contract layer and application layer. The data layer encapsulates the underlying data blocks and related basic data and basic algorithms such as data encryption and timestamp; the network layer includes distributed networking mechanism, data transmission mechanism and data verification mechanism; the consensus layer mainly encapsulates various consensus algorithms of network nodes; the incentive layer integrates economic factors into the blockchain technology system, mainly including the issuance mechanism and distribution mechanism of economic incentives; the contract layer mainly encapsulates various scripts, algorithms and smart contracts, which is the basis of the programmable characteristics of blockchain; the application layer encapsulates various application scenarios and cases of blockchain.
[0094] In related technologies, when using blockchain, it is necessary to store corresponding transaction data, status data, and consensus signatures of consensus nodes on data in order to trace, verify, and recover data. With the increasing requirements for high throughput and low latency in various blockchain application scenarios with large data volumes and complex data structures, the DAG structure has gradually become a consensus solution to replace the traditional chain structure. However, due to the characteristics of the DAG structure such as high throughput and low latency, its structure grows very fast, and the storage pressure of related data increases significantly, resulting in data and consensus signatures occupying a large amount of storage resources, which increases the hardware cost of blockchain technology applications. At the same time, during the data recovery process, new nodes need to constantly catch up to the latest depth of the DAG, and the recovery efficiency is low.
[0095] Based on this, the embodiment of the present application provides a method, device, electronic device and storage medium for processing blockchain data, which detects the number of data units in the current blockchain. When it is greater than or equal to the first number, the target data unit of the second number is automatically selected from the blockchain for compression processing, so that the structure of the blockchain can be periodically compressed to reduce its structural redundancy; in the data compression process, the corresponding target state data is found according to the target transaction hash value in the target data unit, and then the target transaction hash value and the target state data are hashed to establish a local hash snapshot, save the business data of the corresponding target data unit, and transmit the local hash snapshot to the consensus node for verification, and generate a global hash snapshot after consensus. The scheme of the embodiment of the present application only needs to store and verify the transaction hash value during the consensus process, and does not need to process the transaction data, which can reduce the amount of data processing; in the global hash snapshot, the information of the original transaction hash value is retained, and the consensus signature in each target data unit is omitted. On the basis of achieving data consensus, the amount of data that needs to be stored can be reduced, reducing the pressure of data storage, which is conducive to reducing the hardware cost of blockchain technology applications.
[0096] The specific implementation of the embodiment of the present application is described in detail below in conjunction with the accompanying drawings.
[0097] Reference Figure 1 , Figure 1 The following is a schematic diagram showing an implementation environment of the method for processing blockchain data provided in the embodiment of the present application. In this implementation environment, a blockchain system is mainly involved, and the blockchain system includes multiple nodes, such as Figure 1 In the example, there are a first node, a second node, a third node, and ... an Nth node (N is a positive integer). These nodes can be terminal devices or servers, and can participate in consensus voting, transaction execution, data verification, data unit generation, and other tasks in the blockchain system. At each node, blockchain data 110 can be stored. The blockchain data stored in each node is the data that has been agreed upon by the blockchain system, which can ensure the integrity, permanence, and immutability of the data. In the same blockchain system, each node communicates with each other.
[0098] Specifically, in Figure 1In the illustrated implementation environment, the method for processing blockchain data provided in the embodiments of the present application can be executed at any node. For example, taking the first node as an example, when the first node detects that there are a large number of data units in the current blockchain, the target data units of the second number can be selected therefrom, their target transaction hash values and corresponding target status data can be obtained, hash processing can be performed to obtain the first hash value, and a local hash snapshot can be established. Then, the first node can send the local hash snapshot to the consensus node for consistency verification. After the verification is passed, a global hash snapshot is generated based on the local hash snapshot and the first consensus signature returned by other consensus nodes, and then the global hash snapshot is sent to other nodes for storage, and the target data units in the blockchain stored locally by the first node are cropped, thereby achieving compression of the blockchain structure and data.
[0099] The terminal devices in the above embodiments may include smart phones, tablet computers, laptop computers, desktop computers, smart speakers, smart watches, and vehicle-mounted terminals, but are not limited thereto. The server may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides 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.
[0100] The nodes in the blockchain system can establish a communication connection through a wireless network or a wired network. The wireless network or wired network uses standard communication technology and / or protocols. The network can be set to the Internet or any other network, such as but not limited to a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a mobile, wired or wireless network, a private network or any combination of a virtual private network. Moreover, the above-mentioned software and hardware entities can use the same communication connection method or different communication connection methods, and this application does not impose specific restrictions on this.
[0101] Of course, it is understandable that Figure 1 The implementation environment in the present application is only some optional application scenarios of the blockchain data processing method provided in the embodiments of the present application. The actual application is not fixed. Figure 1The method provided in the embodiment of the present application can be applied to various technical fields, such as shopping, games, social networking, cloud technology, artificial intelligence, smart transportation, assisted driving and other fields, and the present application does not make specific restrictions on this.
[0102] Reference Figure 2 , Figure 2 A flowchart of a method for processing blockchain data provided in an embodiment of the present application is provided. The method for processing blockchain data can be executed by a terminal device or by a server. The method for processing blockchain data includes but is not limited to the following steps 210 to 260.
[0103] Step 210: Detect the number of data units in the current blockchain.
[0104] The data unit is mainly used to store the transaction certificate, and the transaction certificate in the embodiment mainly stores the transaction hash.
[0105] In the embodiment of the present application, the data unit is mainly a data carrier or a data structure formed after partial integration of data; the data unit may have different commands and specific data structures in different application scenarios; for example, in the most common blockchain application scenario using the Proof of Work (PoW) mechanism, the data unit may refer to a single block in the blockchain; when the data unit is a block, its data structure mainly includes a block header and a block body, wherein the block header is used to record the characteristic value of the block, and the block body is used to store the data content, i.e., the transaction certificate. For another example, in a blockchain application scenario using a DAG structure (or other decentralized distributed data systems), the data unit may refer to a vertex in the blockchain of the DAG structure, in which the transaction certificate used to describe the transaction record is mainly stored. In addition to transaction certificates, the vertices of the DAG blockchain can also store digital signatures used to describe vertex features or for verification. The digital signature can be a unique and unforgeable string generated during the vertex generation process, and this string is also a valid proof of the formality of the data content stored in the vertex; and the implementation method of the digital signature can be generated through hash operations, or through a digital signature generated based on an asymmetric key encryption mechanism.
[0106] More specifically, when the embodiment adopts the DAG blockchain, the vertices of the DAG store transaction certificates corresponding to the consumption records or consumption data, and the transaction certificates mainly include transaction hash values and consensus node signatures; wherein the transaction hash value is the data value obtained after the hash operation is performed according to the specific transaction data; the consensus node signature is the signature information generated when more than half of the nodes authenticate the data content in the newly generated DAG vertex under the DAG consensus mechanism. In some embodiments, the authentication process is as follows: the nodes of the DAG blockchain perform a hash operation on the acquired transaction data through the transaction data in the database or other storage space, which corresponds to the transaction data represented by the transaction hash value recorded in the transaction certificate of the new vertex in the directed acyclic graph, and compare the result of the hash operation with the result of the transaction hash value broadcasted by the new vertex to other nodes. If the comparison results are consistent, the vertex is considered to be an honest vertex (that is, the node that uploads the original transaction data and the transaction hash value recorded in the new vertex added in the directed acyclic graph at the node are credible), otherwise other nodes consider the new vertex to be a malicious vertex, and the node that uploads the original transaction data will also be marked as a malicious node. The proportion of new vertices recognized as honest vertices by statistical nodes is counted. If the proportion exceeds half (50%), a DAG-type consensus mechanism is used to generate a consensus node signature and store it in the transaction certificate of the new node. Furthermore, the terminal device that uploads this original transaction data can also be added to the DAG blockchain as a new consensus node.
[0107] In the embodiment of the present application, the data storage method of the transaction certificate is essentially a compression processing of the transaction data. By storing the transaction hash value, the amount of data in the directed acyclic graph can be reduced, reducing the storage pressure; further, in certain scenarios, after the node consensus vote, the consensus node signature generation process can be omitted, further reducing the amount of data storage.
[0108] It should be noted that the data content represented by the transaction certificate can be determined according to the specific application scenario, and this application does not impose any restrictions on this.
[0109] Step 220: When the number of data units is greater than or equal to the first number, select the target data unit of the second number from the blockchain and obtain the target transaction hash value in the target data unit.
[0110] In the embodiments of the present application, the first number refers to the preset threshold value of the number of data units. For example, in a blockchain scenario with a DAG structure, the first number may refer to the preset threshold value of the number of vertices in a directed acyclic graph. The second number refers to the number of data units that need to be truncated and data compressed; in similar scenarios, the second number may refer to the number of vertices that are truncated in a directed acyclic graph and packaged and snapshotted after truncation; therefore, the second number in the embodiments needs to be smaller than the first number. The target data unit in the embodiments is the data unit that needs to be truncated and data compressed; and the target transaction hash value is the transaction hash value recorded in the transaction certificate of the target data unit.
[0111] Exemplarily, under the DAG consensus mechanism, in response to the completion of the transaction behavior, the original transaction data generated by the transaction behavior and the status data (orders or transactions) generated during the transaction process will be continuously obtained in the application layer of a certain software background. According to the data structure characteristics of the directed acyclic graph, the embodiment needs to package the data generated in the application layer and perform corresponding hash operations to obtain the transaction certificate corresponding to the transaction record, and generate a new vertex in the directed acyclic graph according to the generated transaction certificate. It should be noted that in the embodiment, when a new vertex is generated, it is necessary to determine the association characteristics between the new vertex and other vertices according to other characteristic information stored in the transaction certificate in the new vertex; for example, in the embodiment, the hash value of the previous vertex of the current vertex and the hash value of the current vertex can be recorded in the transaction certificate; further, in the embodiment, the association relationship between the new vertex and other vertices in the directed acyclic graph can be determined according to the hash value recorded in the transaction certificate in the new vertex, and the connection path between the vertices can be constructed. With the continuous addition of new vertices, the structure of the directed acyclic graph gradually becomes complex and bloated, and the response speed may be reduced, and data query and recovery may be difficult. To this end, in the embodiment, after there are 10 vertices in the directed acyclic graph, the first generated vertex will be pruned. The number of pruned vertices in the embodiment is set to 5, that is, the first 5 vertices generated in the directed acyclic graph and other vertices are truncated, the truncated vertices are compressed and packaged, and a corresponding snapshot is generated for subsequent data recovery.
[0112] It should be noted that, in the embodiments, the packaged vertices or other data units need to be hot-backed up by means of snapshots, and the generated snapshots only contain the core data content of the packaged vertices. For example, the snapshots generated in the embodiments are fragments of a globally consistent ordered transaction hash sequence; based on the core data content described by the snapshots, the snapshots generated in the embodiments can provide necessary data support when performing data recovery.
[0113] Step 230: Obtain target status data of the transaction item corresponding to the target data unit according to the target transaction hash value.
[0114] In the embodiments of the present application, transaction items may include record data generated when transaction behavior occurs; the record data may include but is not limited to transaction creation, transaction completion, transaction cancellation, and transaction termination; correspondingly, the target status data in the embodiments refers to information used to describe changes or changes in the aforementioned transaction items, including but not limited to status data such as creation, completion, cancellation, termination, and modification. More specifically, in the transaction scenario, each transaction data generated in the embodiments generates a read and write operation on the status data; in some feasible implementation scenarios, the data of such read and write operations can be separately integrated to form a read-write set; therefore, in the embodiments, the corresponding field attributes can be formed through the read-write set to record the transaction creation, modification, or deletion structure of the transaction, so that it can be directly annotated when the transaction data is subsequently generated.
[0115] It should be noted that in some feasible embodiments, an independent database (Database, DB) can be set up in the software background, and the original transaction data of the transaction items (or the transaction hash value obtained after hash operation) and the status information (data) associated therewith can be locally backed up or offline backed up through the database.
[0116] Exemplarily, in the process of associating state information (data) with original transaction data, the embodiment can associate multiple state data with a certain original transaction data through key field matching, and construct new vertices of the DAG blockchain and generate transaction certificates of the vertices through hash operations. When the number of vertices in the directed acyclic graph continues to increase, that is, the number of vertices meets the conditions in step 220, it is necessary to perform compression processing of the transaction data, that is, a certain number of vertices need to be truncated, packaged and compressed, and corresponding snapshots need to be generated. Among the truncated vertices, the target state data associated with the transaction hash value in the transaction certificate in the independent storage space is obtained, and the obtained target state data can be used as the core data source for subsequent generation of snapshots. For example, for a truncated vertex, the transaction data (or the corresponding original transaction record) described by the transaction hash value in its transaction certificate is a transfer of 1,000 yuan from A to B; the transaction items determined based on the transaction data include: "A created a transfer transaction with B as the target", "A modified the transfer amount to 1,000", "B received the transfer and the transaction was completed"; therefore, in this embodiment, the status data that can be determined based on the transaction items include "create", "modify" and "complete".
[0117] Step 240: Hash the target transaction hash value and the target state data to obtain a first hash value, and create a local hash snapshot based on the first hash value.
[0118] In the embodiment of the present application, hash processing may refer to calculating the input data through a hash algorithm (Hash), also known as a digest algorithm (Digest), to obtain an output digest of a fixed length. In most implementation scenarios, this data digest may be called a hash value. More specifically, the first hash value in the embodiment is the hash value obtained by inputting the transaction hash value of the vertex and the state data into the hash algorithm together. It can be understood that the hash algorithm used in the embodiment belongs to the technical means or algorithm function known to those skilled in the art. Therefore, the specific hash operation process and the principle of hash operation in the embodiment are not repeated here. The hash algorithm or hash operation has the following characteristics: First, the same input must get the same output; second, different inputs are likely to get different outputs. Therefore, in the embodiment, the hash value obtained after the transaction hash value and the state data are hashed can be used as the unique identification information of the original transaction data. By comparing and verifying this hash value, it can be determined whether the original transaction data in the vertex has been tampered with. Based on the above characteristics, in the embodiment, the hash value obtained after hashing the transaction hash value and the status data is used as the core data of the local hash snapshot. On the one hand, it can reduce the data redundancy of the DAG blockchain through the snapshot method, and on the other hand, it can ensure the security and trustworthiness of the snapshot.
[0119] It should be noted that the local hash snapshot in the embodiment refers to the snapshot information generated for the pruned vertices during the vertex pruning and compression process of the directed acyclic graph. The core data of this snapshot information is the globally consistent transaction hash fragment of the DAG blockchain, and this transaction hash fragment is the data fragment obtained by integrating the hash value obtained by hashing the transaction hash value and status data of all pruned vertices (under the current pruning action).
[0120] Exemplarily, the core technical idea of blockchain is applied in a trading system, and a DAG consensus mechanism is adopted to store all transaction records generated in the system. The system replaces the transaction data sent by the application layer with the transaction hash value, and constructs a new vertex according to the transaction hash value and adds it to the directed acyclic graph. As the number of vertices in the directed acyclic graph becomes larger and larger, the embodiment is based on the core concept of consensus data compression, and when the number of vertices in the directed acyclic graph exceeds 8, the vertices are compressed and pruned, and the set pruned length is 4 vertices. When the 9th new vertex is generated in the embodiment, the first 4 vertices generated will be pruned, packaged, and the corresponding snapshots will be generated. Specifically, in the snapshot generation process, it is necessary to obtain the transaction hash values stored in the transaction certificates of the four pruned vertices respectively, and synchronously obtain the status data of their transaction hash values, and synchronously input the two parts of the data content into the hash operation function. The hash value obtained by the hash operation is further used as the core data of the snapshot, and the local hash snapshot after pruned is constructed based on this core data. This local hash snapshot is broadcasted on the nodes of the DAG blockchain. After obtaining more than half of the votes of the consensus nodes, this local hash snapshot can be considered honest and credible, and will be subsequently integrated into the global hash snapshot.
[0121] It should be further explained that the concept of "local" mentioned in the local hash snapshot in the embodiment is a "global" description relative to the DAG blockchain, and is not simply equivalent to the "local" concept of the terminal node.
[0122] Step 250: Send the local hash snapshot to the consensus node for consistency verification, receive the first consensus signature returned by the consensus node, and generate a global hash snapshot based on the first consensus signature and the local hash snapshot.
[0123] In the embodiment of the present application, the consensus node refers to other nodes in the DAG blockchain except the current newly generated vertex, and the other nodes are also honest nodes that have obtained more than half of the votes (verification) of the nodes in the directed acyclic graph before they are added to the directed acyclic graph. The consistency verification process can be a process in which the consensus nodes other than the new nodes compare and verify the core fields in the snapshot with the original transaction data that is independently stored or backed up after obtaining the local hash snapshot.
[0124] It should be noted that in the consistency verification process, the embodiment can not only verify whether the local hash snapshot comes from an honest node, but also verify the legitimacy of the snapshot generation in necessary scenarios, for example, whether the generation of the local hash snapshot conflicts with the number of vertices in the directed acyclic graph of the current DAG blockchain. In the embodiment, the first consensus signature is the identification information carrying the consensus node information assigned to the snapshot by the consensus node after the local hash snapshot has passed the verification of the consensus node. The generation method of the consensus signature includes but is not limited to the method of using the digital signature of the consensus node, for example, the digital signature obtained by hashing the transaction certificate of the consensus node itself is used as the consensus signature of the consensus node for the local hash snapshot after the consistency verification. In the embodiment, the global hash snapshot may refer to a collection of multiple local hash snapshots after the consistency verification, and the collection may contain the transaction hash values of all vertices after the current directed acyclic graph is pruned and compressed.
[0125] For example, in a data storage scenario of a trading system, a directed acyclic graph for transaction data storage is constructed based on a DAG consensus mechanism, and some vertices in the directed acyclic graph are pruned and compressed to obtain a local hash snapshot containing a more core and simpler data structure. This local hash snapshot will be transmitted to the consensus node of the DAG blockchain by broadcasting. After receiving this local hash snapshot, the consensus node can first verify the legitimacy of the snapshot. For example, the global information that the consensus node can currently obtain is that there are 10 vertices in the directed acyclic graph in addition to the newly generated vertex. The addition of new vertices will inevitably trigger the pruning and compression of the vertex. Then the consensus node can determine that the generation of this local hash snapshot is legal. After passing the snapshot legitimacy verification, the consensus node will verify the content in the snapshot to determine that the transaction certificate is not a malicious tampering of data and that the node that uploaded the data is not a Byzantine node; for example, the consensus node can perform a hash operation on the new transaction data stored in the application layer of the embodiment to obtain a hash value, and compare this hash value with the field describing the transaction hash value in the local hash snapshot. When the comparison result determines that the two are the same, it is determined that the local hash snapshot is legal and credible. Since there can be several consensus nodes in the DAG consensus mechanism, after broadcasting the local hash snapshot, the embodiment votes, that is, more than half of the consensus nodes believe that the local hash snapshot is legal and credible, and forms a consensus signature in the local hash snapshot by assigning an electronic signature. When the embodiment determines that the consensus signature is legal and meets the half principle, the local hash snapshot is integrated into the global hash snapshot.
[0126] Step 260: Send the global hash snapshot to the consensus node for storage, and trim the target data unit in the blockchain.
[0127] In the embodiment of the present application, before the newly generated local hash snapshot passes the consistency verification of the consensus node and is integrated into the global hash snapshot, operations such as vertex pruning and compression of the directed acyclic graph of the DAG blockchain are all expected behaviors; furthermore, when the aforementioned local hash snapshot does not pass the consistency verification, the embodiment believes that this pruning action may be malicious tampering or attack behavior to a certain extent, and the vertex will be processed based on the snapshot. When the aforementioned local hash snapshot passes the consistency verification, the local hash snapshot will be integrated into the global hash snapshot, and the global hash snapshot will be updated; based on the implementation principle of the DAG consensus mechanism, the updated global hash snapshot will also be sent to all consensus nodes in a broadcast manner for storage, and the global hash snapshot stored locally at the node will be updated. During the update process, the missing snapshots can be completed; after the consensus node completes the global hash snapshot update, the directed acyclic graph prunes its vertices according to the expected behavior corresponding to the snapshot, removes redundant information such as digital signatures in the transaction certificate, and completes data compression. At this point, the processing method of blockchain data in the embodiment is completed. The method of the embodiment periodically compresses transaction data, signature data and DAG structure by means of hash snapshots, effectively alleviating the consensus data expansion problem caused by the DAG structure. In addition, when restoring data, hash snapshot information can be used for restoration, which not only ensures the effectiveness of data compression but also realizes rapid data recovery.
[0128] Specifically, in a possible implementation, the data unit is established through the following steps:
[0129] Obtain transaction data of transaction items;
[0130] Hash the transaction data to obtain the transaction hash value;
[0131] Send the transaction data and transaction hash value to the consensus node for consistency verification, and receive the second consensus signature returned by the consensus node;
[0132] The transaction hash value and the second consensus signature are packaged into a transaction certificate, and a data unit corresponding to the transaction certificate is established.
[0133] In the embodiments of the present application, when the transaction data is packaged into a data unit and uploaded to the chain, in some cases, the transaction data can be packaged in the order in which the transaction items are generated. For example, the transaction data of the transaction items generated within a certain period of time before can be packaged at regular intervals to form a data unit and added to the blockchain; here, the time interval for each specific packaging of transaction data is not limited, and it can be flexibly adjusted as needed. The transaction data contained in each data unit can be either a single one or multiple ones. In other embodiments, the transaction data can be packaged in strips according to the transaction items, that is, each time a transaction item occurs, the transaction data generated by the transaction item is packaged into a data unit and then added to the blockchain.
[0134] Specifically, in an embodiment of the present application, the process of packaging transaction data to form a data unit can be executed by any node, and the node is recorded as the target node. For the target node, other nodes in the blockchain system can be recorded as consensus nodes of the target node, and the consensus node can subsequently participate in the consensus process of the data unit generated by the target node. In the process of forming a data unit, first, the target node can obtain the transaction data of the transaction item, and then hash the transaction data, and the obtained hash value can be recorded as the transaction hash value. Here, based on the foregoing description, it can be understood that the target node can obtain either a single transaction data or multiple transaction data, and the transaction items covered can be the same or different.
[0135] In the embodiments of the present application, when hashing transaction data, the type of hash algorithm used and the length of the hash value obtained are not limited, and can be flexibly adjusted according to actual needs. In addition, it is understood that each hash value appearing in the subsequent embodiments is applicable to the description here.
[0136] After calculating the transaction hash value, the target node can send the transaction data and the transaction hash value to the consensus node for consistency verification. The consensus node verifies the consistency of the transaction data and the transaction hash value. If the verification passes, a consensus signature can be returned to the target node, which is recorded as the second consensus signature in the embodiment of the present application. If the verification fails, the target node cannot obtain the second consensus signature from the consensus node. The target node receives and accumulates the number of second consensus signatures returned by each consensus node. When the total number reaches a certain amount, it can be considered that the blockchain has reached a consensus on the authenticity and accuracy of the transaction data and the transaction hash value. At this time, the transaction hash value and the received second consensus signature can be packaged together to form a transaction certificate, and then a data unit can be established, and the transaction certificate can be stored in the data unit. The data unit can then be uploaded to the chain and added to the blockchain for storage. For example, referring to Figure 3 , Figure 3A schematic diagram of the principle of data unit generation is shown in Figure 3 The blockchain system shown includes M nodes (M is a positive integer greater than 1), each of which can generate a data unit and add it to the blockchain. When a node generates a data unit, the node is regarded as the target node, and the other M-1 nodes are regarded as consensus nodes. Figure 3 In the example, the target node is the first node. At a certain moment, the first node receives a transaction data and needs to establish a data unit corresponding to the transaction data in the blockchain. At this time, the first node will calculate the transaction hash value of the transaction data, and then send the transaction data and transaction hash value to other consensus nodes for consistency verification. After verification, each consensus node returns the second consensus signature to the first node. The first node can package the transaction hash value and the second consensus signature into a transaction certificate, establish a data unit corresponding to the transaction certificate, and add it to the blockchain.
[0137] It should be noted that in the embodiment of the present application, each data unit in the blockchain stores the transaction hash value of the transaction data rather than the transaction data itself, that is, the transaction data does not need to be stored on the chain, but can be stored in the public transaction database off the chain. Since the transaction hash value can compress the original transaction data into a summary, the amount of data becomes smaller. Therefore, storing the transaction hash value in the data unit can reduce the amount of data that the blockchain needs to store and reduce the application cost of the blockchain.
[0138] Specifically, in some embodiments, the consensus process of the target node and the consensus node on the transaction data and the transaction hash value can be implemented based on an asymmetric encryption algorithm. For example, in a blockchain, a pair of keys can be configured for each node, and the key includes a public key and a private key corresponding to the node, wherein the private key is saved by the corresponding node, the public key is publicly released, the private key can be used for encryption and signing, and the public key can be used for decryption. When the target node obtains the transaction hash value, it can use its own corresponding private key to encrypt the transaction hash value, and record the encrypted transaction hash value as the encrypted hash value. It should be noted that since the private key used for encryption at this time is unique to the target node, the encrypted hash value can also be regarded as the signature information of the target node. Similarly, for other nodes, the transaction hash value can also be encrypted using its own corresponding private key to obtain the signature information.
[0139] Then, the target node can send the transaction data and the encrypted transaction hash value to other consensus nodes. After receiving these data, the consensus node can, on the one hand, use the same hash algorithm to hash the transaction data to obtain a hash value for consistency verification; on the other hand, the encrypted hash value can be decrypted using the public key corresponding to the target node to restore the transaction hash value. In the embodiment of the present application, the decrypted transaction hash value is recorded as the decrypted hash value. Then, the consensus node can match and verify the hash value obtained by hashing the transaction data and the decrypted hash value obtained by restoring to determine whether the two are completely consistent. If they are consistent, it means that the transaction hash value is correct and the consistency verification is passed.
[0140] Please refer to Figure 4 , Figure 4 by Figure 3 Taking the consensus process between the first node and the second node in as an example, a schematic diagram of related data processing and transmission is given. Specifically, Figure 4 The first node in is the target node, and the second node is the consensus node participating in the consensus process. For the first node, after hashing the transaction data, it obtains the transaction hash value, and uses the private key it carries to encrypt the transaction hash value to obtain the encrypted hash value. Then, the first node sends the transaction data and the encrypted hash value to the second node for consensus. After receiving the transaction data, the second node also hashes it to obtain a transaction hash value. In addition, the second node also uses the public key corresponding to the first node to decrypt the encrypted hash value to obtain a decrypted hash value. Then, the second node determines whether the first hash value transmitted by the first node is accurate and whether there is any tampering based on whether the decrypted hash value and the transaction hash value are consistent. If they are consistent, the verification is passed. The second node uses the private key it carries to encrypt the transaction hash value and returns it to the first node as the second consensus signature.
[0141] It should be noted that in the embodiments of the present application, when consensus is reached on the transaction hash value, it is generally necessary for multiple consensus nodes to verify and pass before the transaction hash value is considered correct and the corresponding data unit can be generated. Here, the majority principle can be adopted, that is, when more than half of the consensus nodes in the blockchain system pass the verification, the consensus is considered to be completed. Of course, the number of consensus nodes required for the specific consistency verification can be flexibly adjusted as needed, and this application does not limit this.
[0142] It should be noted that when selecting target data units for data compression, in order to ensure good integrity of the blockchain structure after compression, data units with connection relationships in the blockchain should be selected as target data units as much as possible, that is, when selecting target data units, it is hoped that their positions in the blockchain are as close as possible, so as to facilitate the removal of the substructure composed of them from the blockchain and have less impact on the remaining blockchain structure. To this end, in some embodiments, the various data units in the blockchain can be sorted based on the structural principle of the blockchain, and the target data unit can be selected and determined according to the sequence number obtained by the sorting.
[0143] Specifically, in a possible implementation manner, the method further includes the following steps:
[0144] Detect the depth of each data unit in the blockchain;
[0145] The data units are sorted according to the depth layer number to obtain the first sequence number corresponding to each data unit.
[0146] For the blockchain, it includes multiple interconnected data units. In the embodiment of the present application, a unique serial number can be arranged and set for each data unit, and the serial number is recorded as the first serial number.
[0147] In some embodiments, for example, referring to Figure 5 For a traditional single-chain blockchain, the data unit is generally called a block. Each block is connected in the order of creation. The earliest created block can be recorded as the genesis block, such as Figure 5 The first block 510 in the diagram is the genesis block. After the genesis block, there are other blocks connected. Figure 5 The blockchain in includes 5 data units, namely, the first block 510, the second block 520, the third block 530, the fourth block 540 and the fifth block 550. In the embodiment of the present application, the first serial number corresponding to the genesis block, that is, the first block 510, can be recorded as 0, and then the first serial numbers corresponding to the blocks connected after the genesis block are increased in sequence, that is, they can be 1, 2, 3..., until the last block of the current blockchain is arranged. In this way, for Figure 5 For the blockchain shown, the first sequence number corresponding to the second block 520 is 2, the first sequence number corresponding to the third block 530 is 3, the first sequence number corresponding to the fourth block 540 is 4, and the first sequence number corresponding to the fifth block 550 is 5.
[0148] In addition to the traditional single-chain blockchain, the more common blockchains currently include DAG-structured blockchains, which are relatively more complex in structure. When sorting the data units in the DAG-structured blockchain, you can number them according to the depth level of each data unit. For example, please refer to Figure 6 , Figure 6 A blockchain with a DAG structure is shown. In the blockchain, first, at least one genesis unit can be found, that is, a data unit that is not linked to other data units. The genesis unit is the deepest level in the blockchain. Next, the data units linked to the genesis unit are detected. The depth of these data units is one level shallower than that of the genesis unit. By executing in this way in a loop, the relationship between the depth levels of each data unit in the current blockchain can be determined. It can be understood that by determining the depth level of the data unit farthest from the genesis unit in the blockchain as the first level, the depth levels corresponding to other data can be determined in turn. For example, for Figure 6 For example, the blockchain includes two genesis units, which can be recorded as the first genesis unit and the second genesis unit respectively. By determining the shortest path between other data and the two genesis units, each data unit can be layered. Figure 6 In the example, each data unit is divided into 5 layers in total, so the depth layer of the creation unit can be determined as 5, and then in sequence: the depth layer of the data unit that has a direct link relationship with the creation unit is determined to be 4; the depth layer of the data unit that has a direct link relationship with the data unit at the depth layer 4 (except the data unit whose depth layer has been determined) is determined to be 3, until the depth layers of all data units are determined.
[0149] After determining the depth level of each data unit, the data units can be sorted according to the depth level. It is understandable that, generally speaking, the deeper the depth level of a data unit, the earlier it may be generated, and the earlier the corresponding historical transaction. Therefore, the data units with larger depth levels can be numbered first, and then the data units with smaller depth levels can be numbered in sequence. For data units at the same depth level, the order of their first serial numbers can be unlimited. For example, for Figure 6In the blockchain shown, there are two data units with a depth of 5, and the first and second genesis units may correspond to two first serial numbers 1 and 2. Specifically, the first serial number of the first genesis unit may be 1, and the first serial number of the second genesis unit may be 2; or the first serial number of the first genesis unit may be 2, and the first serial number of the second genesis unit may be 1. There are three data units with a depth of 4, and their corresponding first serial numbers may be 3, 4, and 5 respectively; there are three data units with a depth of 3, and their corresponding first serial numbers may be 6, 7, and 8 respectively; there are two data units with a depth of 2, and their corresponding first serial numbers may be 9 and 10 respectively; there is one data unit with a depth of 1, and its corresponding first serial number may be 11.
[0150] Of course, it is understandable that Figure 5 and Figure 6 The blockchain structure shown is only used to illustrate a numbering method of blockchain data units in the embodiments of the present application, and does not mean to limit the specific blockchain structure applied to the blockchain data processing method provided in the embodiments of the present application.
[0151] Specifically, in a possible implementation, selecting a target data unit of a second number from the blockchain includes:
[0152] Sort each data unit in ascending order according to the corresponding first sequence number, and select the second several data units with the highest order as the target data units;
[0153] Alternatively, the data units are sorted in descending order according to the corresponding first sequence numbers, and the second few data units with the lowest sorting order are selected as the target data units.
[0154] In the embodiment of the present application, as mentioned above, the various data units in the blockchain can be sorted based on the structural principle of the blockchain, and the target data unit can be selected and determined according to the sequence number obtained by the sorting.
[0155] Specifically, for each data unit in the current blockchain, it can be understood that the smaller the corresponding first sequence number is, the deeper the position in the blockchain is, the earlier the corresponding historical transaction occurs, and the lower the probability of subsequent use. Therefore, in the embodiment of the present application, the data unit with a smaller first sequence number can be selected as the target data unit, and these target data units can be compressed, which can reduce the data storage pressure and the impact on the efficiency of blockchain data use.
[0156] In the embodiment of the present application, when selecting the target data unit, the data units in the current blockchain can be sorted according to the size of the first sequence number. For example, the data units can be sorted in the order from small to large according to the first sequence number. At this time, the data units with smaller first sequence numbers are ranked first, so the second several data units ranked first can be selected and used as the target data units. For another example, the data units can be sorted in the order from large to small according to the first sequence number. At this time, the data units with smaller first sequence numbers are ranked last, and relatively, the second several data units ranked last can be selected and used as the target data units.
[0157] Specifically, in a possible implementation, the second number is determined by the following steps:
[0158] Detect the data throughput of the blockchain in a preset time period;
[0159] Based on the data throughput, determine the second number;
[0160] Among them, the data throughput is positively correlated with the size of the second number.
[0161] It should be noted that in the embodiments of the present application, the number of target data units compressed each time, that is, the size of the second number, can be flexibly set. In some embodiments, the size of the second number can be fixed to a specific value according to demand, for example, it can be set to 10 or 20. In other embodiments, the size of the second number can be determined according to the throughput requirements of specific blockchain data. For example, it can be understood that, in general, when the blockchain data throughput is large, its data storage and processing pressure is relatively large. At this time, more data should be compressed at one time as much as possible to reduce the data storage pressure. Therefore, in this case, the size of the second number can be set relatively large, which can reduce the number of data compressions and the amount of data processing; it can also increase the amount of data compressed at one time and release more storage space in time.
[0162] Specifically, in the embodiment of the present application, when determining the second number, the data throughput of the blockchain within a certain time period can be detected, and the length of the time period can be preset, for example, it can be 1 hour, 1 day, etc. Then, the second number can be determined according to the size of the data throughput: the larger the data throughput, the larger the second number, and vice versa, the smaller the data throughput, the smaller the second number, that is, the data throughput and the size of the second number are positively correlated, and the present application does not limit the specific functional relationship between the two.
[0163] Specifically, in a possible implementation, obtaining target status data of a transaction item corresponding to a target data unit according to a target transaction hash value includes:
[0164] According to the target transaction hash value, the target transaction item corresponding to the target data unit is determined by matching the transaction data of each transaction item;
[0165] According to the target transaction items, the target status data is obtained.
[0166] In the embodiment of the present application, it can be understood that for each transaction item, the corresponding transaction data and status data can be recorded, and the transaction data and status data have a corresponding relationship, and both are stored in the data corresponding to the same transaction item. Since the data unit in the blockchain in the embodiment of the present application stores the transaction hash value, and the status data is stored off-chain, when compressing the data, it is necessary to consider the associated processing of the status data, that is, it is necessary to determine the status data corresponding to each transaction hash value.
[0167] Specifically, in the embodiment of the present application, for the target transaction hash value, it is calculated based on the transaction data corresponding to the target data unit. When determining the target status data corresponding to the target transaction hash value, first, the transaction item corresponding to the target data unit can be determined based on the target transaction hash value, and in the embodiment of the present application, it is recorded as the target transaction item. For example, the transaction data in each transaction item can be hashed, and the obtained hash value can be compared with the target transaction hash value. When a consistency is found, the transaction item can be determined as the target transaction item. Then, the corresponding status data is obtained according to the target transaction item query to obtain the target status data.
[0168] Specifically, in a possible implementation, performing hash processing on the target transaction hash value and the target state data to obtain a first hash value includes:
[0169] Sort the target transaction hash values according to the first sequence number corresponding to the target data unit to obtain a transaction metadata sequence;
[0170] Sort the target state data according to the first sequence number corresponding to the target data unit to obtain a state change sequence;
[0171] The transaction metadata sequence and the state change sequence are integrated, and the integrated data is hashed to obtain a first hash value.
[0172] In an embodiment of the present application, when calculating the first hash value, the target transaction hash value and the target state data can be sorted and bound according to the first sequence number, and then hashed to retain the corresponding data sequence information. Specifically, for example, the target transaction hash value can be sorted according to the size of the corresponding first sequence number to obtain a transaction metadata sequence; then, the target state data can be sorted according to the size of the corresponding first sequence number to obtain a state change sequence. Then, the two sequences can be integrated, for example, the state change sequence can be spliced to the back of the transaction metadata sequence. The integrated data is hashed to obtain the first hash value.
[0173] It can be understood that in the embodiment of the present application, the transaction metadata sequence and the state change sequence are bound and integrated through the first serial number, which realizes the transfer of transaction sequence consistency to state change sequence consistency, can retain regular and clear data content, and facilitate subsequent data recovery and verification work.
[0174] Specifically, in a possible implementation, establishing a local hash snapshot according to the first hash value includes:
[0175] Determine the second serial number corresponding to the local hash snapshot according to the first serial number and the second number corresponding to the target data unit;
[0176] Determine the depth field information corresponding to the local hash snapshot according to the depth layer number of each target data unit;
[0177] Performing hash processing on the second serial number, the depth field information, and the first hash value to obtain a second hash value, and obtaining a local signature according to the second hash value;
[0178] The second serial number, depth field information, first hash value and local signature are packaged to obtain a local hash snapshot.
[0179] In the embodiments of the present application, for the same blockchain, it may undergo multiple data compression processes, and there are multiple local hash snapshots. For the local hash snapshots generated at different stages, they can be sorted and numbered, and the serial number corresponding to each local hash snapshot can be recorded as the second serial number. It can be understood that for the same blockchain, the second serial numbers corresponding to the local hash snapshots generated are different, which is convenient for subsequent distinction and use. Specifically, in some embodiments, each local hash snapshot can be numbered in the order of its generation time. For example, an earlier generated local hash snapshot can correspond to a smaller second serial number. In other embodiments, the second serial number corresponding to the local hash snapshot can be associated with the first serial number corresponding to the corresponding compressed data unit to facilitate subsequent rapid query and recovery of a data unit.
[0180] For example, for a group of target data units that need to be compressed, the second sequence number corresponding to the generated local hash snapshot can be determined based on their corresponding first sequence numbers. For example, assuming that the second number is 10, that is, the number of data units compressed each time is 10, if the first sequence number and the second sequence number are both numbered from 0, then the second sequence number corresponding to the local hash snapshot generated when the target data units with first sequence numbers from 0 to 9 are compressed is 0; the second sequence number corresponding to the local hash snapshot generated when the target data units with first sequence numbers from 10 to 19 are compressed is 1. If the first sequence numbers corresponding to the current batch of target data units that need to be compressed are 120 to 129, then the second sequence number corresponding to the generated local hash snapshot is 12. In other words, the second sequence number corresponding to the local hash snapshot can be determined based on the first sequence number and the second number corresponding to the target data unit.
[0181] In an embodiment of the present application, the local hash snapshot may also store the depth layer information of the target data unit. Specifically, as mentioned above, each data unit in the blockchain has a corresponding depth layer, and the data units with similar first serial numbers have similar corresponding depth layers, and are likely to be at the same or similar depth layers. In an embodiment of the present application, a batch of depth layer ranges of target depth units can be retained through a local hash snapshot, so that their positions in the blockchain can be quickly located during subsequent data recovery, thereby improving the efficiency of data recovery. In an embodiment of the present application, the depth layer range corresponding to the target depth unit of the second number is recorded as depth field information.
[0182] When generating a local hash snapshot, the second serial number, the depth field information, and the first hash value corresponding to the local hash snapshot may be hashed to obtain a second hash value. The second hash value may then be encrypted to obtain a local signature, and the second serial number, the depth field information, the first hash value, and the local signature may be packaged to obtain a local hash snapshot.
[0183] For details, please refer to Figure 7 , Figure 7 A schematic diagram of the data content of a local hash snapshot is shown. In the embodiment of the present application, the transaction metadata sequence and the state change sequence are integrated, and the integrated data is hashed to obtain a first hash value. When generating a local hash snapshot, the first serial number of the target data unit is bound to the second serial number corresponding to the local hash snapshot. The second serial number is represented as in, is the rounding down symbol; m is the smallest first serial number corresponding to the target data unit in the local hash snapshot; and n is the second number.
[0184] and, Figure 7The depth information of the target data unit (h1…hn) is also bound to the depth field information of the local hash snapshot, where h1 is the depth layer corresponding to the first target depth unit in the local hash snapshot, and hn is the depth layer corresponding to the last target depth unit in the local hash snapshot. The depth field information of the local hash snapshot is the minimum depth layer and maximum depth layer of the target data unit corresponding to all transaction hash values, that is, the depth field information of the local hash snapshot can be expressed as (MIN(h1…hn), MAX(h1…hn)), and the minimum depth hmin and maximum depth hmax are obtained, which are recorded in the local hash snapshot.
[0185] Finally, the second serial number is used as the snapshot serial number seq, the minimum depth hmin, the maximum depth hmax, and the first hash value are integrated, and the local signature obtained by hashing the second serial number, the depth field information, and the first hash value is added to obtain a local hash snapshot. The transaction metadata sequence information contained in it is used to quickly restore consensus data, and the state change sequence is used to quickly restore state data.
[0186] Specifically, in one possible implementation, sending the local hash snapshot to the consensus node for consistency verification includes at least one of the following steps:
[0187] Send the local hash snapshot to the consensus node, and use the consensus node to hash the second sequence number, the depth field information, and the first hash value to obtain a third hash value; and use the consensus node to verify whether the third hash value and the second hash value are consistent. If the third hash value and the second hash value are consistent, the consistency verification is passed;
[0188] Alternatively, the local hash snapshot is sent to the consensus node, the target transaction hash value and the target status data are obtained according to the second serial number by the consensus node, and the target transaction hash value and the target status data are hashed to obtain a fourth hash value; the consensus node verifies whether the first hash value and the fourth hash value are consistent, and if the first hash value and the fourth hash value are consistent, the consistency verification is passed.
[0189] In the embodiment of the present application, the consensus process of the local hash snapshot may include at least two aspects.
[0190] First, in some embodiments, the process may include verifying the authenticity of the second serial number, the depth field information, and the first hash value as a whole. Specifically, at this time, for the corresponding consensus node, it needs to hash the second serial number, the depth field information, and the first hash value, and the obtained hash value is recorded as the third hash value. Based on the third hash value and the second hash value obtained by decrypting the local signature in the local hash snapshot, the third hash value and the second hash value can be compared and verified to be consistent. If the two are consistent, it means that the overall second serial number, the depth field information, and the first hash value content authenticity can be guaranteed and have not been tampered with. If the third hash value and the second hash value are inconsistent, it means that the authenticity of the second serial number, the depth field information, and the first hash value content is in doubt. At this time, at the consensus node, the verification fails.
[0191] In other embodiments, the consensus process for the local hash snapshot may also include verifying the authenticity of the first hash value. Specifically, at this time, for the corresponding consensus node, it needs to obtain the relevant target transaction hash value and target status data according to the second sequence number, and hash the target transaction hash value and target status data. The obtained hash value is recorded as the fourth hash value. Here, similarly, before the target transaction hash value and target status data are hashed, the two can be sequenced and integrated to ensure data format consistency. The specific implementation process refers to the description of the aforementioned embodiment and will not be repeated here. Based on the first hash value and the first hash value in the local hash snapshot, it is possible to compare and verify whether the fourth hash value and the first hash value are consistent. If the two are consistent, it means that the content authenticity of the first hash value can be guaranteed and has not been tampered with. If the fourth hash value and the first hash value are inconsistent, it means that the content authenticity of the first hash value is in doubt. At this time, at the consensus node, the verification fails.
[0192] It should be noted that in the embodiments of the present application, when consensus is reached on the local hash snapshot, it is generally necessary for multiple consensus nodes to verify and pass before the local hash snapshot is considered correct and the corresponding first consensus signature can be fed back. The number of first consensus signatures is accumulated and recorded as the third number. When the third number is greater than or equal to the preset threshold, a global hash snapshot can be generated. Here, the majority principle can be specifically adopted, that is, when more than half of the consensus nodes in the blockchain system have passed the verification, the consensus is considered to be completed, and the size of the preset threshold is set to half of the number of nodes in the blockchain system. Of course, the number of consensus nodes required for the specific consistency verification can be flexibly adjusted as needed, and this application does not limit this. Reference Figure 8 , Figure 8A schematic diagram of the data content of a global hash snapshot is shown, which also includes the original second serial number, depth field information and first hash value of the local hash snapshot. After the local hash snapshot is verified, the first consensus signature of other consensus nodes can be added to the local hash snapshot, and the original local signature plus the first consensus signature become a signature set, thereby obtaining a global hash snapshot.
[0193] In some feasible implementations or in some possible implementation scenarios, after a new node joins the DAG consensus mechanism, it is necessary to restore the transaction data of all vertices in the directed acyclic graph based on the current global hash snapshot. Therefore, refer to Fig. 9 The method for processing blockchain data provided in the embodiment of the present application may also include but is not limited to steps 910 to 940:
[0194] Step 910: Send a data recovery request to the consensus node, and receive a global hash snapshot returned by the consensus node;
[0195] In an embodiment, a data recovery request may be a request message triggered after a new node joins a DAG-type consensus mechanism. The request message is mainly used to obtain a global hash snapshot from an existing consensus node in the DAG blockchain, and to restore the pruned vertices in the directed acyclic graph based on several core data fragments in the global hash snapshot, thereby obtaining other more detailed data content in the transaction certificate of the vertex, including but not limited to digital signatures attached by other consensus nodes during the vertex generation process.
[0196] Exemplarily, in a trading system, a newly added node is a terminal device with a certain data processing capability. The data storage method adopted by the trading system is decentralized distributed storage, and the transaction certificate storing the transaction data is a node in a directed acyclic graph. Due to the huge amount of transaction data in the trading system, the throughput of read and write operations for transactions is also extremely large. In the embodiment, it is necessary to use the data compression capability of the DAG blockchain to perform corresponding clipping and packaging compression processing on the vertices in the directed acyclic graph, and to independently store the transaction hash values in the clipped nodes by means of a global hash snapshot. Therefore, when a new terminal node is added to the trading system, it is not possible to obtain the data content of the transaction certificates or transaction hash values of all vertices in the directed acyclic graph by a simple broadcast method. Then, when a new node is added, a data recovery request can be triggered. Based on this request, the consensus node in the trading system can return the global hash snapshot stored in the node to the local of the newly added node by broadcasting, and the new node can further obtain the data content of the transaction certificates in all vertices of the directed acyclic graph through subsequent verification processing.
[0197] Step 920: Obtain original transaction data and original status data of the transaction item.
[0198] Specifically in the embodiment, when adding a new vertex to the directed acyclic graph of the DAG blockchain, the transaction hash value in the vertex transaction certificate is associated with the read and write operations, that is, the matter-related information corresponding to the original transaction data of the transaction hash value is associated with the transaction hash value as status data. The specific association implementation process is as described in the aforementioned embodiment and will not be repeated here. In some feasible implementations, the embodiment may also directly associate the transaction hash value with the status data, and the response rate is higher when querying the target transaction item. It should be further explained that the original transaction data and original status data obtained in the embodiment should be distinguished from the data content directly obtained from the global hash snapshot or the local hash snapshot; the original transaction data and original status data in the embodiment can be stored in the database of the application layer in an independent storage or backup manner.
[0199] For example, when a new terminal node successfully joins the distributed transaction system built on the DAG blockchain, after the node successfully passes the authentication of other consensus nodes and obtains the global hash snapshot stored in other consensus nodes by broadcasting, before storing the transaction hash value in this global hash snapshot locally on the node, the new node also needs to verify the broadcast content of other consensus nodes to avoid malicious data tampering and Byzantine attacks. Therefore, after obtaining the global hash snapshot, the new node can directly obtain the original transaction data and the status data associated with the transaction data from the database set up by the application layer of the transaction system, and perform consistency verification based on the original records obtained and the global hash snapshot obtained by broadcasting, etc., to improve the security of data storage.
[0200] Step 930: Perform consistency check on the original transaction data and the original status data according to the global hash snapshot.
[0201] In an embodiment, the method of security verification through consistency verification can be bidirectional, that is, when a new node is added to the distributed system, it needs to be verified to avoid the addition of malicious nodes. At the same time, after the new node joins the distributed system, it is also necessary to perform necessary verification on the consensus nodes already in the system to avoid malicious attacks when restoring the historical data of the system. The one-time verification process in the embodiment is to compare and verify the original transaction data and original status data obtained in step 920 with the global hash snapshot obtained by broadcasting. It should be supplemented that since the core data in the global hash snapshot (or the data segment used to describe the transaction certificate) is the data content obtained after multiple hash operations, therefore, in the embodiment, when performing consistency verification, the original transaction data and the original change data obtained need to be processed by the same round of hash operations to obtain the same data structure as the core data in the global hash snapshot, so that a direct comparison can be performed to determine whether the two are the same.
[0202] Step 940: When the original transaction data and the original status data pass verification, the target data unit is restored according to the target transaction data.
[0203] In an embodiment, when the hash value obtained by performing necessary hash operations on the original transaction data and the original change data is compared with the core data in the global hash snapshot, and it is determined that the two are the same, the consistency check is considered to have passed. The new node that successfully joins the DAG blockchain can store the global hash snapshot locally in the node, and restore the pruned vertices according to the corresponding original transaction data used to describe the directed acyclic graph vertex transaction certificate in the snapshot and other attribute information of the node in the directed acyclic graph; wherein other attribute information may include but is not limited to the depth information of the vertex in the directed acyclic graph, or the path information between the vertex and other vertices. It should be noted that the vertex restored in the embodiment can be used as the genesis vertex of the new node to participate in the subsequent consensus process in the embodiment.
[0204] As mentioned above, since the core data in the global hash snapshot (or the data segment used to describe the transaction certificate) is the data content obtained after multiple hash operations, in the embodiment, when performing consistency verification, the obtained original transaction data and the original change data need to be processed by the same round of hash operations. In some feasible implementations, the blockchain data processing method provided in the embodiment, step 930, can further include steps 9301 to 9303:
[0205] Step 9301: Perform hash processing on the original transaction data to obtain a fifth hash value.
[0206] Specifically in the embodiments, especially in the process of generating new vertices of the directed acyclic graph of the DAG blockchain, it is first necessary to perform a hash operation on the original transaction data to obtain the corresponding hash value to achieve compression of redundant data. Based on this hash operation process, in order to make the compared data content have the same data attributes and the same data structure during the consistency verification process, correspondingly, at the node where the vertex of the directed acyclic graph is recovered, the embodiment needs to perform the same hash processing on the obtained original transaction data, so as to be consistent with the rounds of hash processing performed during the vertex generation process. Obviously, in the data recovery stage, the hash function for hashing the original transaction should be consistent with the hash function in the vertex construction stage, and the specific hash operation process will not be repeated here. In addition, it should be noted that the original transaction data input by the hash operation in the process of adding new vertices to the directed acyclic graph is not strictly the same data as the original transaction data obtained in the (vertex) data recovery stage, because after several rounds of data reading and writing, there is a possibility of tampering with the original transaction data, but it is extremely difficult to tamper with the data processed by the hash operation, so the embodiment adopts a consistency verification method at the data recovery node to ensure that the independently stored original transaction data has not been tampered with.
[0207] Step 9302: Perform hash processing on the fifth hash value and the original state data to obtain a sixth hash value.
[0208] Similarly, in the process of new vertex clipping of the directed acyclic graph, the state data input by the hash operation is not strictly the same as the original state data obtained in the (vertex) data recovery stage, because after several times of data reading and writing, there may be a possibility of tampering with the original transaction data, but the difficulty of tampering with the data processed by the hash operation is extremely high, so the embodiment adopts a consistency verification method at the data recovery node to ensure that the independently stored original data has not been tampered with. Specifically in the embodiment, based on the DAG consensus mechanism, the number of vertices in the directed acyclic graph storing transaction certificates gradually increases, and the embodiment triggers the node clipping process, and saves the transaction hash value in the vertex by snapshot. In the process of generating the snapshot, the embodiment performs a hash operation on the transaction hash value in the clipped vertex and its associated state data to obtain a hash value, and uses this hash value as the core data of the local hash snapshot. Correspondingly, at the node where the vertex of the directed acyclic graph is restored, the embodiment needs to perform the same hash processing on the obtained original state data, so as to keep consistent with the round of hash processing performed during the vertex generation process. Therefore, the embodiment performs another round of hash operation on the hash value obtained by hash operation in step 9301 and the original state data to obtain a new hash value, that is, the sixth hash value. The obtained hash value is verified for consistency with the global hash snapshot to determine whether the independently stored original data has been tampered with.
[0209] Step 9303: Verify whether the first Hash value and the sixth Hash value are consistent. If the first Hash value and the sixth Hash value are consistent, the consistency verification is passed.
[0210] Specifically in the embodiment, the consistency verification process is to compare the hash value obtained by the operation processing of step 9302 with the specific data fragment in the global hash snapshot to determine whether the two are the same; wherein, since the global hash snapshot is obtained by continuously integrating the local hash snapshot, therefore, when performing consistency verification, the specific data fragment in the global hash snapshot is determined according to the vertex of the directed acyclic graph to be restored as needed, and therefore, the specific data fragment refers to the fragment containing the vertex transaction hash value to be restored, that is, the first hash value. The two hash values are compared, and if the two are the same, it is determined that the consistency verification has passed, and the nodes of the directed acyclic graph can be restored according to the original transaction data and the original state change data obtained; otherwise, if the consistency verification fails, it is considered that the original transaction data and the original state change data may be maliciously tampered with, and the data recovery process is terminated. It should be noted that in the embodiment, the specific node or all nodes in the directed acyclic graph that need to be restored can be determined according to specific needs. When a specific node needs to be restored, the specific data fragment is the specific data fragment of the specific node in the global hash snapshot; when all nodes need to be restored, the specific data fragment is all the transaction hash data content in the global hash snapshot.
[0211] Below, in combination with some more specific embodiments, the blockchain data processing method provided in this application is described in detail.
[0212] Reference Fig.10 , Fig.10 A schematic diagram of the principle of data compression of a blockchain in a DAG-structured blockchain is shown. In this embodiment, the DAG structure is used to sort the various data units in the blockchain, wherein each vertex is a data unit for storing a transaction certificate, and the transaction certificate mainly includes a transaction hash value and a second consensus signature of more than half of the consensus nodes. After a specific consensus protocol process, the blockchain system can generate a global ordered certificate list. When compressing the blockchain, the original transaction hash values of some fragments in the list are taken out and signed to form a local hash snapshot; the local hash snapshot is broadcast to other consensus nodes for consistency verification, and the global hash snapshot is stored after successful verification, and the sub-DAG structure in the blockchain is deleted, thus completing the data compression operation.
[0213] Specifically, the implementation process of the data compression operation in the embodiment of the present application is described in detail below. First, in the embodiment of the present application, the transaction data in the blockchain system is stored in the transaction database, and each transaction item includes transaction data and corresponding status data.
[0214] Step (1): When a new transaction is generated, the memory obtains the transaction data, replaces the transaction data with the transaction hash value and stores it in the blockchain on the disk.
[0215] Step (2): Truncate the global ordered certificate list. After the blockchain consensus protocol process for the transaction hash value is completed, obtain the current global ordered certificate list. When the list reaches a certain length, truncate the first n certificates to generate a global ordered certificate fragment, where n is the number of transactions contained in a single hash snapshot.
[0216] Step (3): Bind transaction status data. Take out the original transaction hash value (referred to as transaction metadata) and the depth layer number h contained in each transaction certificate from the certificate fragment, and generate a transaction metadata sequence according to the order of data unit sorting. According to the transaction hash value, take out the status data of the corresponding transaction item from the application layer and generate a state change sequence in the same order. The binding of the transaction metadata sequence and the state change sequence realizes the transfer from transaction order consistency to state change order consistency.
[0217] Step (4): Generate a local hash snapshot. Integrate the transaction metadata sequence generated in step (3) with the state change sequence, and calculate the corresponding first hash value; determine the snapshot number (i.e., the second serial number) through the first serial number corresponding to the data unit of the current batch. This process can be implemented with reference to the aforementioned embodiment and will not be described in detail here. In addition, determine the depth field information of the snapshot based on the depth layer number corresponding to the data unit, associate the snapshot serial number, depth field information, and the first hash value, and finally add a local signature to form a local hash snapshot.
[0218] Step (5): Generate a global hash snapshot. Broadcast the local hash snapshot to other consensus nodes for consistency verification. The verification method is as follows: 1) Check the legitimacy of the local signature. 2) Determine whether n*(seq+1)-1≤i holds, where seq is the snapshot sequence number and i is the latest sequence number of the current global ordered certificate list. 3) Obtain the global ordered certificate fragments from n*seq to n*(seq+1)-1, and then generate the corresponding hash value in the local hash snapshot in a similar manner to steps (3) and (4). 4) Determine whether the generated hash value is consistent with the received hash value. If they are consistent, return the local hash snapshot (including its own first consensus signature). If the first consensus signatures of more than half of the consensus nodes are collected, the first consensus signatures are aggregated to form a global hash snapshot and broadcast again to other consensus nodes.
[0219] Step (6): Store the global hash snapshot and trim the sub-DAG structure in the blockchain. Store the global hash snapshot in the corresponding database and delete the global ordered certificate fragment intercepted in step (2). At this point, the compression of the consensus data is completed. The technical solution in the embodiment of the present application, the generated global hash snapshot effectively compresses the transaction data, signature data and DAG structure, which can greatly reduce the application cost of the blockchain.
[0220] Furthermore, in the embodiment of the present application, the nodes of the blockchain can use the above-mentioned global hash snapshot to recover data, and the specific steps are as follows:
[0221] Step (7): The new node obtains the missing global hash snapshot from the remaining nodes.
[0222] Step (8): The remaining nodes return the global hash snapshot and its corresponding complete transaction data and status data.
[0223] Step (9): The new node receives and checks the global hash snapshots in order. The new node calculates the hash value of the transaction data and status data in each global hash snapshot and verifies whether the hash value is consistent with the hash value in the global hash snapshot.
[0224] Step (10): Update state data and consensus data. After the new node is successfully verified, the application layer applies the state data to the local state database and saves the transaction data; the consensus layer saves the transaction metadata sequence and restores the blockchain of the specified depth based on the depth field information of the global hash snapshot. The new node can participate in the subsequent consensus process based on the restored data.
[0225] Reference Fig.11 , Fig.11 A schematic diagram of the structure of a blockchain data processing device provided in an embodiment of the present application, wherein the blockchain data processing device includes:
[0226] A detection unit 1110 is used to detect the number of data units in the current blockchain; wherein the data unit is used to store a transaction certificate, and the transaction certificate includes a transaction hash value;
[0227] A selection unit 1120 is used to select a second number of target data units from the blockchain when the number of data units is greater than or equal to the first number, and obtain a target transaction hash value in the target data unit; wherein the second number is less than the first number;
[0228] An acquisition unit 1130 is used to acquire target status data of a transaction item corresponding to a target data unit according to a target transaction hash value;
[0229] The processing unit 1140 is configured to perform hash processing on the target transaction hash value and the target state data to obtain a first hash value, and to establish a local hash snapshot according to the first hash value;
[0230] A verification unit 1150 is used to send the local hash snapshot to the consensus node for consistency verification, receive the first consensus signature returned by the consensus node, and generate a global hash snapshot based on the first consensus signature and the local hash snapshot;
[0231] The pruning unit 1160 is used to send the global hash snapshot to the consensus node for storage and prune the target data unit in the blockchain.
[0232] Furthermore, the blockchain data processing device also includes a construction unit, which is specifically used to:
[0233] Obtain transaction data of transaction items;
[0234] Hash the transaction data to obtain the transaction hash value;
[0235] Send the transaction data and transaction hash value to the consensus node for consistency verification, and receive the second consensus signature returned by the consensus node;
[0236] The transaction hash value and the second consensus signature are packaged into a transaction certificate, and a data unit corresponding to the transaction certificate is established.
[0237] Furthermore, the processing device further includes a sorting unit, which is specifically configured to:
[0238] Detect the depth of each data unit in the blockchain;
[0239] The data units are sorted according to the depth layer number to obtain the first sequence number corresponding to each data unit.
[0240] Furthermore, the above-mentioned selection unit is specifically used for:
[0241] Sort each data unit in ascending order according to the corresponding first sequence number, and select the second several data units with the highest order as the target data units;
[0242] Alternatively, the data units are sorted in descending order according to the corresponding first sequence numbers, and the second few data units with the lowest sorting order are selected as the target data units.
[0243] Furthermore, the blockchain data processing device further includes a number determination unit, which is specifically used to:
[0244] Detect the data throughput of the blockchain in a preset time period;
[0245] Based on the data throughput, determine the second number;
[0246] Among them, the data throughput is positively correlated with the size of the second number.
[0247] Furthermore, the acquisition unit is specifically used for:
[0248] According to the target transaction hash value, the target transaction item corresponding to the target data unit is determined by matching the transaction data of each transaction item;
[0249] According to the target transaction items, the target status data is obtained.
[0250] Furthermore, the above processing unit is specifically used for:
[0251] Sort the target transaction hash values according to the first sequence number corresponding to the target data unit to obtain a transaction metadata sequence;
[0252] Sort the target state data according to the first sequence number corresponding to the target data unit to obtain a state change sequence;
[0253] The transaction metadata sequence and the state change sequence are integrated, and the integrated data is hashed to obtain a first hash value.
[0254] Furthermore, the above processing unit is specifically used for:
[0255] Determine the second serial number corresponding to the local hash snapshot according to the first serial number and the second number corresponding to the target data unit;
[0256] Determine the depth field information corresponding to the local hash snapshot according to the depth layer number of each target data unit;
[0257] Performing hash processing on the second serial number, the depth field information, and the first hash value to obtain a second hash value, and obtaining a local signature according to the second hash value;
[0258] The second serial number, depth field information, first hash value and local signature are packaged to obtain a local hash snapshot.
[0259] Furthermore, the verification unit is specifically used for:
[0260] Send the local hash snapshot to the consensus node, and use the consensus node to hash the second sequence number, the depth field information, and the first hash value to obtain a third hash value; and use the consensus node to verify whether the third hash value and the second hash value are consistent. If the third hash value and the second hash value are consistent, the consistency verification is passed;
[0261] Alternatively, the local hash snapshot is sent to the consensus node, the target transaction hash value and the target status data are obtained according to the second serial number by the consensus node, and the target transaction hash value and the target status data are hashed to obtain a fourth hash value; the consensus node verifies whether the first hash value and the fourth hash value are consistent, and if the first hash value and the fourth hash value are consistent, the consistency verification is passed.
[0262] Furthermore, the verification unit is specifically used for:
[0263] Receive and accumulate the third number of the first consensus signature returned by the consensus node;
[0264] When the third number is greater than or equal to the preset threshold, each first consensus signature is added to the local hash snapshot to generate a global hash snapshot.
[0265] Furthermore, the blockchain data processing device further includes a recovery unit, which is used to:
[0266] Send a data recovery request to the consensus node and receive the global hash snapshot returned by the consensus node;
[0267] Obtaining original transaction data and original status data of transaction items;
[0268] Based on the global hash snapshot, the original transaction data and the original status data are checked for consistency;
[0269] When the original transaction data and the original status data are verified, the target data unit is restored according to the target transaction data.
[0270] Furthermore, the above recovery unit is specifically used for:
[0271] Perform hash processing on the original transaction data to obtain a fifth hash value;
[0272] Performing hash processing on the fifth hash value and the original state data to obtain a sixth hash value;
[0273] Verify whether the first Hash value and the sixth Hash value are consistent. If the first Hash value and the sixth Hash value are consistent, the consistency verification is passed.
[0274] It is understandable that if Figure 2 The contents of the blockchain data processing method embodiment shown in the figure are applicable to the blockchain data processing device embodiment. The functions specifically implemented by the blockchain data processing device embodiment are similar to those in the embodiment shown in the figure. Figure 2 The processing embodiment of blockchain data shown is the same as that shown in FIG. Figure 2 The beneficial effects achieved by the blockchain data processing embodiment shown are also the same.
[0275] Reference Fig.12 The present application also discloses an electronic device, including:
[0276] at least one processor 1210;
[0277] At least one memory 1220, used to store at least one program;
[0278] When at least one program is executed by at least one processor 1210, the at least one processor 1210 implements the following Figure 2 An embodiment of a method for processing blockchain data is shown.
[0279] It is understandable that if Figure 2 The contents of the blockchain data processing method embodiment shown in the figure are all applicable to the electronic device embodiment. The functions specifically implemented by the electronic device embodiment are similar to those in the embodiment shown in the figure. Figure 2 The processing method of blockchain data shown in the embodiment is the same as that in the embodiment of the present invention, and the beneficial effects achieved are the same as those in the embodiment of the present invention. Figure 2 The beneficial effects achieved by the blockchain data processing method embodiment shown are also the same.
[0280] The present application also discloses a computer-readable storage medium in which a program executable by a processor is stored. When the program executable by the processor is executed by the processor, it is used to implement the following Figure 2 An embodiment of a method for processing blockchain data is shown.
[0281] Understandably, Figure 2 The contents of the blockchain data processing method embodiment shown in the figure are all applicable to the computer-readable storage medium embodiment. The functions specifically implemented by the computer-readable storage medium embodiment are the same as those in the embodiment of the present invention. Figure 2 The processing method of blockchain data shown in the embodiment is the same as that of Figure 2 The beneficial effects achieved by the blockchain data processing method embodiment shown are also the same.
[0282] The embodiment of the present application further discloses a computer program product or a computer program, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in the above-mentioned computer-readable storage medium; Fig.12 The processor of the electronic device shown can read the computer instruction from the above-mentioned computer readable storage medium, and the processor executes the computer instruction so that the electronic device executes Figure 2 An embodiment of a method for processing blockchain data is shown.
[0283] Understandably, Figure 2 The contents of the blockchain data processing method embodiment shown in the figure are applicable to the computer program product or computer program embodiment, and the functions specifically implemented by the computer program product or computer program embodiment are the same as those in the embodiment of the present invention. Figure 2 The processing method of blockchain data shown in the embodiment is the same as that of Figure 2 The beneficial effects achieved by the blockchain data processing method embodiment shown are also the same.
[0284] In some selectable embodiments, the function / operation mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the function / operation involved, the two boxes shown in succession can actually be executed substantially simultaneously or the boxes can sometimes be executed in reverse order. In addition, the embodiment presented and described in the flow chart of the application is provided by way of example, for the purpose of providing a more comprehensive understanding of technology. The disclosed method is not limited to the operation and logic flow presented herein. Selectable embodiments are expected, wherein the order of various operations is changed and the sub-operation of a part described as a larger operation is performed independently.
[0285] In addition, although the present application is described in the context of functional modules, it should be understood that, unless otherwise specified, one or more of the functions and / or features can be integrated into a single physical device and / or software module, or one or more functions and / or features can be implemented in a separate physical device or software module. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding the present application. More specifically, in view of the properties, functions, and internal relationships of the various functional modules in the device disclosed herein, the actual implementation of the module will be understood within the conventional techniques of the engineer. Therefore, those skilled in the art can implement the present application set forth in the claims without excessive experimentation using ordinary techniques. It is also understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present application, which is determined by the full scope of the attached claims and their equivalents.
[0286] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.
[0287] The logic and / or steps represented in the flowchart or otherwise described herein, for example, may be considered as an ordered list of executable instructions for implementing logical functions, and may be embodied in any computer-readable storage medium for use by an instruction execution system, apparatus, or device (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, apparatus, or device and execute instructions), or in conjunction with such instruction execution system, apparatus, or device. For purposes of this specification, a "computer-readable storage medium" may be any device that can contain, store, communicate, propagate, or transmit a program for use by an instruction execution system, apparatus, or device, or in conjunction with such instruction execution system, apparatus, or device.
[0288] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0289] In the above description of this specification, the description with reference to the terms "one embodiment / example", "another embodiment / example" or "certain embodiments / examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0290] Although the embodiments of the present application have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present application, and that the scope of the present application is defined by the claims and their equivalents.
[0291] The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the embodiments. Technical personnel familiar with the field can make various equivalent modifications or substitutions without violating the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present application.
Claims
1. A method for processing blockchain data, characterized in that: The method comprises: Detecting the number of data units in the current blockchain; wherein the data unit is used to store a transaction certificate, and the transaction certificate includes a transaction hash value; When the number of the data units is greater than or equal to the first number, selecting a second number of target data units from the blockchain, and obtaining a target transaction hash value in the target data unit; wherein the second number is less than the first number; According to the target transaction hash value, obtaining target status data of the transaction item corresponding to the target data unit; Performing hash processing on the target transaction hash value and the target state data to obtain a first hash value, and establishing a local hash snapshot according to the first hash value; Sending the local hash snapshot to a consensus node for consistency verification, receiving a first consensus signature returned by the consensus node, and generating a global hash snapshot based on the first consensus signature and the local hash snapshot; The global hash snapshot is sent to the consensus node for storage, and the target data unit in the blockchain is pruned.
2. The method for processing blockchain data according to claim 1, characterized in that: The data unit is established by the following steps: Obtain transaction data of transaction items; Performing hash processing on the transaction data to obtain the transaction hash value; Sending the transaction data and the transaction hash value to a consensus node for consistency verification, and receiving a second consensus signature returned by the consensus node; The transaction hash value and the second consensus signature are packaged into a transaction certificate, and a data unit corresponding to the transaction certificate is established.
3. The method for processing blockchain data according to claim 1, characterized in that: The method further comprises the following steps: Detecting the depth level of each data unit in the blockchain; The data units are sorted according to the depth layer number to obtain a first sequence number corresponding to each of the data units.
4. The method for processing blockchain data according to claim 3, characterized in that: The selecting a target data unit of a second number from the blockchain includes: Sort the data units in ascending order according to the corresponding first sequence numbers, and select the second several data units with the highest order as target data units; Alternatively, the data units are sorted in descending order according to the corresponding first sequence numbers, and the second few data units with the lowest sorting order are selected as the target data units.
5. The method for processing blockchain data according to any one of claims 1 to 4, characterized in that: The second number is determined by the following steps: Detecting the data throughput of the blockchain in a preset time period; Determining the second number according to the data throughput; The data throughput is positively correlated with the size of the second number.
6. The method for processing blockchain data according to claim 1, characterized in that: The step of obtaining target status data of the transaction item corresponding to the target data unit according to the target transaction hash value includes: According to the target transaction hash value, determine the target transaction item corresponding to the target data unit by matching the transaction data of each transaction item; According to the target transaction item, the target status data is obtained.
7. The method for processing blockchain data according to claim 4, characterized in that: The step of performing hash processing on the target transaction hash value and the target state data to obtain a first hash value includes: Sort the target transaction hash values according to the first sequence numbers corresponding to the target data units to obtain a transaction metadata sequence; Sorting the target state data according to the first sequence number corresponding to the target data unit to obtain a state change sequence; The transaction metadata sequence and the state change sequence are integrated, and the integrated data are hashed to obtain the first hash value.
8. The method for processing blockchain data according to claim 7, characterized in that: The step of establishing a local hash snapshot according to the first hash value includes: Determine a second sequence number corresponding to the local hash snapshot according to the first sequence number corresponding to the target data unit and the second number; Determine the depth field information corresponding to the local hash snapshot according to the depth layer number of each target data unit; Performing hash processing on the second sequence number, the depth field information, and the first hash value to obtain a second hash value, and obtaining a local signature according to the second hash value; The second serial number, the depth field information, the first hash value, and the local signature are packaged to obtain the local hash snapshot.
9. The method for processing blockchain data according to claim 8, characterized in that: The sending the local hash snapshot to the consensus node for consistency verification includes at least one of the following steps: Sending the local hash snapshot to a consensus node, and performing hash processing on the second sequence number, the depth field information, and the first hash value by the consensus node to obtain a third hash value; Verify, by the consensus node, whether the third Hash value is consistent with the second Hash value, and if the third Hash value is consistent with the second Hash value, pass the consistency verification; Alternatively, the local hash snapshot is sent to a consensus node, the target transaction hash value and the target state data are obtained by the consensus node according to the second sequence number, and the target transaction hash value and the target state data are hashed to obtain a fourth hash value; The consensus node verifies whether the first hash value and the fourth hash value are consistent. If the first hash value and the fourth hash value are consistent, the consistency verification is passed.
10. The method for processing blockchain data according to claim 1, characterized in that: The receiving the first consensus signature returned by the consensus node, and generating a global hash snapshot based on the first consensus signature and the local hash snapshot, includes: Receive and accumulate the third number of the first consensus signature returned by the consensus node; When the third number is greater than or equal to a preset threshold, each of the first consensus signatures is added to the local hash snapshot to generate the global hash snapshot.
11. The method for processing blockchain data according to claim 1, characterized in that: The method further comprises the following steps: Sending a data recovery request to the consensus node, and receiving the global hash snapshot returned by the consensus node; Obtaining original transaction data and original status data of transaction items; Performing a consistency check on the original transaction data and the original status data according to the global hash snapshot; When the original transaction data and the original status data pass verification, the target data unit is restored according to the target transaction data.
12. The method for processing blockchain data according to claim 11, characterized in that: The performing consistency check on the original transaction data and the original status data according to the global hash snapshot includes: Performing hash processing on the original transaction data to obtain a fifth hash value; Performing hash processing on the fifth hash value and the original state data to obtain a sixth hash value; Verify whether the first Hash value and the sixth Hash value are consistent. If the first Hash value and the sixth Hash value are consistent, the consistency verification is passed.
13. A blockchain data processing device, characterized in that: The device comprises: A detection unit, used to detect the number of data units in the current blockchain; wherein the data unit is used to store a transaction certificate, and the transaction certificate includes a transaction hash value; a selection unit, configured to select a second number of target data units from the blockchain when the number of the data units is greater than or equal to the first number, and obtain a target transaction hash value in the target data units; wherein the second number is less than the first number; An acquisition unit, configured to acquire target status data of the transaction item corresponding to the target data unit according to the target transaction hash value; a processing unit, configured to perform hash processing on the target transaction hash value and the target state data to obtain a first hash value, and to establish a local hash snapshot according to the first hash value; A verification unit, configured to send the local hash snapshot to a consensus node for consistency verification, receive a first consensus signature returned by the consensus node, and generate a global hash snapshot based on the first consensus signature and the local hash snapshot; A pruning unit is used to send the global hash snapshot to the consensus node for storage and prune the target data unit in the blockchain.
14. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the method for processing blockchain data according to any one of claims 1 to 12 is implemented.
15. A computer-readable storage medium storing a program, characterized in that: When the program is executed by a processor, the method for processing blockchain data according to any one of claims 1 to 12 is implemented.
Citation Information
Cited By
Byzantine fault-tolerant consensus method based on directed acyclic graph and computer equipment
CN119324931A
Smart traffic data storage method, system and device based on Internet of Things, and medium
CN120336431A
