Data cleaning method and device of block chain, computer equipment and storage medium

By determining and dealing with expired transaction tasks during the consensus process of blockchain, the problem of manual intervention and single -point behavior in the existing technologies is solved, and automated, secure and efficient data cleanup is achieved. It is suitable for multi -business sharing The situation of the same chain.

CN119377196APending Publication Date: 2025-01-28TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310930289.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-07-26
Publication Date
2025-01-28

AI Technical Summary

Technical Problem

The existing blockchain data cleaning method requires manual intervention and is a single point of behavior, which may affect subsequent business processing processes and lead to inconsistent execution status, resulting in security problems.

Method used

By determining the expired transaction tasks in the transaction clearance tree during the consensus process, and grasping the target trading task, thereby generating new block proposals for carrying expired transaction tasks information, and broadcasting to the blockchain node for consensus and data cleaning.

Benefits of technology

The automated data cleaning in the process of consensus is achieved, the performance of the blockchain is improved, the security and retrospective of the data cleanup are ensured, and the cleaning level is controlled to the transaction level. It is suitable for the situation of multi -business sharing the same chain.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119377196A_ABST
    Figure CN119377196A_ABST
Patent Text Reader

Abstract

The invention relates to a block chain data cleaning method and device, computer equipment, a storage medium and a computer program product. The method comprises the following steps: determining an expired transaction task in a transaction cleaning tree maintained by itself; capturing a preset number of target transaction tasks from a transaction pool; generating a proposal message of the new block based on the expired transaction task and the target transaction task; the proposal message carries identification information of the expired transaction task; and broadcasting the proposal message to a first node in a block chain, so that the first node performs consensus on the new block based on the target transaction task, and performs data cleaning based on the identification information after the consensus is reached. By adopting the method, the expired data can be cleaned in the consensus process, and the performance of the whole block chain can be effectively improved while the security of the whole block chain is ensured. The technology can be applied to the field of intelligent transportation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a blockchain data cleaning method, device, computer equipment, storage medium and computer program product. Background Art

[0002] Blockchain is a new decentralized distributed ledger technology that can safely store transactions or other data. The characteristics are that the information stored on the blockchain cannot be forged or tampered with. The blockchain consensus algorithm drives each node on the blockchain to participate in the transaction verification process to ensure that transactions on the blockchain are confirmed and credible. Blockchain is essentially a distributed storage system. Each of its nodes stores data, and the storage of data by nodes is based on data. As the amount of data increases, more and more data needs to be stored. Naturally, for some non-distributed data, its performance will become lower and lower. Because blockchain itself is distributed storage, each node usually uses a non-distributed database, and the performance will be affected. Therefore, it is necessary to clean up expired data.

[0003] However, the current method of cleaning data in blockchain is usually to send a command to the entire blockchain node by the administrator of the blockchain system (the command will also be sent to the blockchain in the form of a transaction). The height of data archiving is usually specified in this command, and the blockchain node will archive (clean) all transaction data before the height of the data archiving, thereby achieving the effect of reducing the amount of data. However, this processing requires manual intervention, that is, when the amount of data stored in the blockchain is huge, the above data cleaning method requires manual participation, and the data cleaning method is a single-point behavior, that is, for the entire blockchain system, after the data in one of the nodes is manually cleaned, it may affect the subsequent processing flow of other businesses, and may also cause inconsistent execution status of each node, which in turn leads to security issues in the entire blockchain after data cleaning. Summary of the invention

[0004] Based on this, it is necessary to provide a blockchain data cleaning method, device, computer equipment, computer-readable storage medium and computer program product to address the above-mentioned technical problems, which can complete the cleaning of expired data during the consensus process, while ensuring the security of the entire blockchain and effectively improving the performance of the entire blockchain.

[0005] In the first aspect, the present application provides a method for data cleaning of a blockchain. The method includes: determining expired transaction tasks in a transaction cleaning tree maintained by the blockchain; grabbing a preset number of target transaction tasks from a transaction pool; generating a proposal message of the new block based on the expired transaction tasks and the target transaction tasks; the proposal message carries identification information of the expired transaction tasks; broadcasting the proposal message to a first node in the blockchain so that the first node reaches a consensus on the new block based on the target transaction tasks, and after reaching a consensus, performs data cleaning based on the identification information.

[0006] In the second aspect, the present application also provides a data cleaning device for blockchain. The device includes: a determination module for determining expired transaction tasks in a transaction cleaning tree maintained by itself; a capture module for capturing a preset number of target transaction tasks from a transaction pool; a generation module for generating a proposal message for the new block based on the expired transaction tasks and the target transaction tasks; the proposal message carries identification information of the expired transaction task; and a broadcast module for broadcasting the proposal message to a first node in the blockchain, so that the first node reaches a consensus on the new block based on the target transaction task, and performs data cleaning based on the identification information after reaching a consensus.

[0007] In a third aspect, the present application also provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program: determining expired transaction tasks in the transaction cleanup tree maintained by itself; grabbing a preset number of target transaction tasks from the transaction pool; generating a proposal message of the new block based on the expired transaction tasks and the target transaction tasks; the proposal message carries the identification information of the expired transaction task; broadcasting the proposal message to the first node in the blockchain, so that the first node reaches a consensus on the new block based on the target transaction task, and after reaching a consensus, performs data cleanup based on the identification information.

[0008] In a fourth aspect, the present application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented: determining expired transaction tasks in a transaction cleanup tree maintained by the processor; grabbing a preset number of target transaction tasks from a transaction pool; generating a proposal message for the new block based on the expired transaction tasks and the target transaction tasks; the proposal message carries identification information of the expired transaction task; broadcasting the proposal message to a first node in the blockchain, so that the first node reaches a consensus on the new block based on the target transaction task, and after reaching a consensus, performs data cleanup based on the identification information.

[0009] In a fifth aspect, the present application also provides a computer program product. The computer program product includes a computer program, which implements the following steps when executed by a processor: determining expired transaction tasks in a transaction cleanup tree maintained by itself; grabbing a preset number of target transaction tasks from a transaction pool; generating a proposal message for the new block based on the expired transaction tasks and the target transaction tasks; carrying identification information of the expired transaction tasks in the proposal message; broadcasting the proposal message to a first node in the blockchain, so that the first node reaches a consensus on the new block based on the target transaction tasks, and after reaching a consensus, performs data cleanup based on the identification information.

[0010] The data cleaning method, device, computer equipment, storage medium and computer program product of the above blockchain, by determining the expired transaction tasks in the transaction cleaning tree maintained by itself; grabbing a preset number of target transaction tasks from the transaction pool, and generating a proposal message of a new block based on the expired transaction tasks and the target transaction tasks; carrying the identification information of the expired transaction tasks in the proposal message; broadcasting the proposal message to the first node in the blockchain, so that the first node reaches a consensus on the new block based on the target transaction tasks, and after reaching a consensus, data cleaning is performed based on the identification information. Since the proposal message of the new block is generated based on the expired transaction tasks and the target transaction tasks, after reaching a consensus on the new block, data cleaning can be automatically performed based on the identification information of the expired transaction tasks carried in the proposal message. The entire data cleaning process is through consensus and will be written in the blockchain, which can realize the completion of the data cleaning process at the same time as the consensus, with high security and traceability, and at the same time, the level of data cleaning in the blockchain can be controlled to the transaction level, so that even if the same chain is shared between businesses, there is no problem, and it is achieved while ensuring the security of the entire blockchain and effectively improving the performance of the entire blockchain. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 This is an optional structural diagram of a distributed system 100 applied to a blockchain system in an embodiment;

[0012] Figure 2 An optional schematic diagram of a block structure in an embodiment;

[0013] Figure 3 A flowchart of a method for clearing data of a blockchain in one embodiment;

[0014] Figure 4 A schematic diagram of the structure of a transaction clearing tree in one embodiment;

[0015] Figure 5 A schematic diagram of a proposal process of a master node in one embodiment;

[0016] Figure 6 A schematic diagram of information carried by a transaction task in one embodiment;

[0017] Figure 7 A schematic diagram of a process of creating a transaction cleanup tree in one embodiment;

[0018] Figure 8 A schematic diagram of information carried in a proposal message in one embodiment;

[0019] Fig. 9 A schematic diagram of a verification process after a slave node receives a proposal message in one embodiment;

[0020] Fig.10 A schematic diagram of a consensus process based on a BFT consensus algorithm in one embodiment;

[0021] Fig.11 A flowchart of cleaning up expired data in one embodiment;

[0022] Fig.12 A schematic diagram of data cleaning in a traditional manner in one embodiment;

[0023] Fig.13 It is a structural block diagram of a data cleaning device for blockchain in one embodiment;

[0024] Fig.14 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0025] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0026] It should be noted that in the following description, the terms "first, second and third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first, second and third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.

[0027] The system involved in the embodiment of the present invention may be a distributed system formed by connecting a client and multiple nodes (computing devices of any form in an access network, such as a server and a user terminal) through network communication.

[0028] Take the distributed system as the blockchain system as an example, see Figure 1 , Figure 1It is an optional structural diagram of the distributed system 100 provided by the embodiment of the present invention applied to the blockchain system, which is formed by multiple nodes (any form of computing devices in the access network, such as servers, user terminals) and clients, and a peer-to-peer network is formed between the nodes. The Peer To Peer protocol is an application layer protocol running on the Transmission Control Protocol (TCP). In a distributed system, any machine such as a server or a terminal can join and become a node, and the node includes a hardware layer, an intermediate layer, an operating system layer, and an application layer.

[0029] See also Figure 1 The functions of each node in the blockchain system shown include:

[0030] 1) Routing: a basic function of a node, used to support communication between nodes.

[0031] In addition to the routing function, the node can also have the following functions:

[0032] 2) Applications are deployed in the blockchain to implement specific businesses based on actual business needs, record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system for other nodes to add the record data to a temporary block when they successfully verify the source and integrity of the record data.

[0033] For example, the services implemented by the application include:

[0034] 2.1) Wallet, used to provide the function of conducting electronic currency transactions, including initiating transactions (i.e., sending the transaction record of the current transaction to other nodes in the blockchain system. After the other nodes successfully verify the transaction, as a response to acknowledge the validity of the transaction, the transaction record data is stored in the temporary block of the blockchain; of course, the wallet also supports querying the remaining electronic currency in the electronic currency address;

[0035] 2.2) Shared ledger, which is used to provide functions such as storage, query and modification of account data. The record data of the operation on the account data is sent to other nodes in the blockchain system. After other nodes verify the validity, as a response to acknowledging the validity of the account data, the record data is stored in a temporary block, and a confirmation can also be sent to the node that initiated the operation.

[0036] 2.3) Smart contracts are computerized protocols that can execute the terms of a contract. They are implemented by deploying code on a shared ledger that is executed when certain conditions are met. The code is used to complete automated transactions based on actual business needs, such as querying the logistics status of the goods purchased by the buyer and transferring the buyer's electronic currency to the merchant's address after the buyer signs for the goods. Of course, smart contracts are not limited to executing contracts for transactions, but can also execute contracts for processing received information.

[0037] 3) Blockchain, including a series of blocks that are connected to each other in the order of their generation. Once a new block is added to the blockchain, it will not be removed. The block records the record data submitted by the nodes in the blockchain system.

[0038] See also Figure 2 , Figure 2 This is an optional schematic diagram of the block structure provided by an embodiment of the present invention. Each block includes the hash value of the transaction record stored in this block (the hash value of this block) and the hash value of the previous block. Each block is connected by the hash value to form a blockchain. In addition, the block can also include information such as the timestamp when the block was generated. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains relevant information for verifying the validity of its information (anti-counterfeiting) and generating the next block.

[0039] In one embodiment, Figure 3 As shown, a data cleaning method for blockchain is provided, and the method is applied to Figure 1 The node cluster in the blockchain system in the example is used to illustrate, including the following steps:

[0040] Step 302, determining the expired transaction tasks in the transaction clearing tree maintained by itself.

[0041] Among them, blockchain is a chain composed of blocks. Each block stores certain information, and they are connected into a chain in the order of their generation. This chain is stored in all servers. As long as there is a server in the entire system that can work, the entire blockchain is safe. These servers are called nodes in the blockchain system, and they provide storage space and computing power support for the entire blockchain system. If you want to modify the information in the blockchain, you must obtain the consent of more than half of the nodes and modify the information in all nodes. These nodes are usually in the hands of different entities, so it is extremely difficult to tamper with the information in the blockchain. Compared with traditional networks, blockchain has two core characteristics: one is that data is difficult to tamper with, and the other is decentralization. Based on these two characteristics, the information recorded in the blockchain is more authentic and reliable, which can help solve the problem of people's distrust of each other. The types of blockchains include public chains, joint chains, private chains, etc. The blockchain system in this application can be a consortium chain system.

[0042] After a newly created blockchain is started, when a new block is generated in the blockchain, the master node in the node cluster is responsible for generating a proposal message for the new block, and broadcasting the proposal message so that each slave node verifies the proposal message and confirms whether the new block in the proposal message can reach a consensus. When the new block reaches a consensus, each node in the node cluster can add the new block to the local ledger, that is, store the new block. The consensus environment of the blockchain in this application can be a blockchain underlying model based on BFT consensus. Under the blockchain underlying model based on BFT consensus, there are usually master nodes and slave nodes. The master node is responsible for generating proposals for new blocks, which are verified by the slave nodes to confirm whether the blocks in the proposal can reach a consensus. Among them, BFT (Byzantine Fault Tolerance), that is, Byzantine Fault Tolerance, is a consensus mechanism.

[0043] A new block refers to a newly generated block in the blockchain. For example, if blockchain 1 contains a genesis block and block 1, the new block may be block 1 in blockchain 1.

[0044] The transaction cleanup tree refers to a structure used to store identification information of expired transaction tasks that need to be cleaned up. For example, the transaction cleanup tree in this application can be a prefix tree structure, which is a multi-branch tree structure. Figure 4 As shown in FIG. 1 , it is a schematic diagram of the structure of a transaction clearing tree, that is, the transaction clearing tree in this application can be as follows: Figure 4 The structure shown in .

[0045] An expired transaction task refers to a transaction task that meets the preset expiration time. In some cases, the transaction task in this application can also be called a transaction, and an expired transaction task is called an expired transaction. For example, a user can set an expiration time for each transaction task (either an absolute time or a relative time). When the expiration time is reached, the transaction task is an expired transaction task. For example, the expiration time T set for transaction task A is 13:30 on July 16, 2023. When the time T is reached, for example, the current time is 13:31 on July 16, 2023, then the transaction task A is an expired transaction task.

[0046] Specifically, after a newly created blockchain is started, when a new block is generated in the blockchain and consensus is required, the master node in the node cluster can capture a preset number of transaction tasks from the transaction pool, and encapsulate the captured transaction tasks into a proposal message of the new block, and broadcast the proposal message to the slave nodes in the blockchain, so that the slave nodes can reach a consensus on the new block based on the transaction tasks in the proposal message. That is, the master node in the present application can package the captured preset number of transaction tasks into a proposal, and broadcast the proposal to all slave nodes in the blockchain in the form of a message. When each slave node receives the proposal message, each slave node can verify all the transaction tasks in the proposal message to obtain a verification result; when the verification result indicates that at least one of the transaction tasks in the proposal message is illegal, the slave node generates a voting message that does not agree with the consensus of the new block. At the same time, the slave node can receive voting messages broadcast by other nodes. When the number of voting messages in favor of the consensus of the new block in the voting message meets the preset conditions, the new block can reach a consensus, that is, the new block can be added to the blockchain, and each node can also add the new block to the local account book.

[0047] Among them, when the master node constructs a new block, the master node can first determine the expired transaction tasks in the transaction cleanup tree maintained by itself, that is, each node in the node cluster in this application maintains a transaction cleanup number, and the transaction cleanup tree stores the identification information of the expired transaction tasks to be cleaned. For example, when the master node constructs a new block, the master node can obtain the current time as t1, and based on time t1, search for expired transaction tasks that meet the time t1 from the transaction cleanup tree maintained by itself, that is, the master node can search for the identification information of the transaction tasks to be cleaned up to the time t1 from the transaction cleanup tree maintained by itself.

[0048] For example, in the underlying blockchain model based on BFT consensus, after a newly created blockchain is started, when a new block is generated in the newly created blockchain, each node in the node cluster can determine whether it is a master node. For example, each node in the node cluster can determine whether the block generation conditions are met based on the parameters in the block it maintains; when a node determines that it meets the block generation conditions, the node is the master node. The block generation condition refers to the condition used to trigger the block generation. For example, the block generation condition in this application can be set to a height value greater than a preset threshold, and the preset threshold can be 1. The node that generates the block is qualified to encapsulate the transaction task into a proposal message for the consensus block.

[0049] Furthermore, when a node (node ​​1) in the node cluster determines itself as the master node, the master node generates a block and starts a new round of consensus, that is, the master node is responsible for generating proposals for new blocks. Figure 4 As shown in the figure, it is a schematic diagram of the structure of the transaction cleanup tree. Assume that the transaction cleanup tree maintained by the master node (node ​​1) itself is as follows Figure 4 As shown in , when the master node (node ​​1) constructs a new block, the master node (node ​​1) can obtain the current time as t1: 12-01-01:01, and based on time t1, from the self-maintained Figure 4 The master node searches for expired transaction tasks that match the time t1 in the transaction cleanup tree shown in , that is, the master node can search for identification information of transaction tasks to be cleaned up by the time t1 from the transaction cleanup tree maintained by itself, and the identification information includes at least: Tx(1) and Tx(n).

[0050] Step 304: grab a preset number of target transaction tasks from the transaction pool.

[0051] Among them, the transaction pool is used to receive transaction tasks sent by nodes and transaction tasks sent by clients. The transaction pool has the function of verifying the validity of transaction tasks. In addition to the basic verification of whether the transaction tasks are expired and whether the format of the transaction task signature is correct, it is also necessary to verify whether there is double spending in the transaction tasks.

[0052] The preset number refers to the number of transaction tasks that need to be encapsulated in the new block. For example, the preset number may be 100.

[0053] The target transaction task refers to the transaction task selected by the master node from the transaction pool. For example, the target transaction task in this application can be the transaction task selected by the master node from the transaction pool in order from high to low processing priority corresponding to the contract of the transaction task.

[0054] Step 306, generating a proposal message of a new block based on the expired transaction task and the target transaction task; the proposal message carries the identification information of the expired transaction task.

[0055] Among them, a proposal message is a communication message used when communicating between nodes in a blockchain. For example, a communication message may also include a consensus message, a voting message, etc. A proposal message in this application refers to a message carrying a proposal. For example, a proposal message carries proposal 1, and proposal 1 is generated for the newly generated block 1.

[0056] The identification information refers to the identification information corresponding to the expired transaction task. The identification information corresponding to the mid-term transaction task of the present application may include at least two types of identification information. For example, the identification information corresponding to the mid-term transaction task of the present application may include an expired transaction identification set and an expired transaction hash value.

[0057] The expired transaction identification set refers to a set of transaction identifications of expired transaction tasks. For example, the expired transaction identification set in this application can be an expired transaction ID set. The expired transaction identification set can also be called ExpireTxIDs, which contains a list of transaction task IDs that need to be eliminated.

[0058] The expired transaction hash value refers to the MerkleRoot of the expired transaction identifier set. The expired transaction hash value can also be called ExpireTxRoot.

[0059] Step 308, broadcast the proposal message to the first node in the blockchain, so that the first node can reach a consensus on the new block based on the target transaction task, and clean up the data based on the identification information after reaching a consensus.

[0060] The first node refers to other nodes in the node cluster except the current node (master node). For example, the first node in the present application may be each slave node in the node cluster.

[0061] Consensus refers to the consensus on the newly generated new block. Only when the newly generated new block is verified by the nodes and consensus is reached, the new block can be uploaded to the blockchain, and each node can store the new block that has reached consensus in the local ledger.

[0062] Data cleaning refers to the operation of cleaning up expired data. For example, the data cleaning in this application is based on the granularity of transaction tasks, and the storage data related to expired transaction tasks is cleaned up. For example, for a certain expired transaction task, the state data of the expired transaction task is stored in the state database, and the block data of the expired transaction task is stored in the block database. In actual application scenarios, you can choose to clean up only the block data of the expired transaction task stored in the block database, or you can choose to clean up both the block data of the expired transaction task stored in the block database and the state data of the expired transaction task stored in the state database. It can be understood that the operation of cleaning up data in this application includes but is not limited to operations such as deletion, compression, archiving, and backup.

[0063] Specifically, when the master node in the node cluster constructs a new block, after the master node determines the expired transaction tasks in the transaction cleanup tree maintained by itself, the master node can grab a preset number of target transaction tasks from the transaction pool, and generate a proposal message for the new block based on the expired transaction tasks and the target transaction tasks. The proposal message carries the identification information of the expired transaction tasks, that is, the master node in the present application can package the captured preset number of target transaction tasks into a proposal, and the master node can add the identification information of the expired transaction tasks to the proposal, and broadcast the proposal to all slave nodes in the blockchain in the form of a message.

[0064] Furthermore, when each slave node receives the proposal message, each slave node can verify the identification information of the target transaction task and the expired transaction task in the proposal message to obtain a verification result. The slave node generates an approval message or a disapproval message based on the verification result. At the same time, the slave node can receive voting messages broadcast by other nodes. When the number of approval votes in the voting message meets the preset conditions, the new block can reach a consensus, that is, the new block can be added to the blockchain, and each node can also add the new block to the local ledger; after the new block reaches a consensus, each node can perform data cleaning steps based on the identification information of the expired transaction task carried in the proposal message.

[0065] For example, in the underlying blockchain model based on BFT consensus, Figure 5As shown, it is a schematic diagram of the proposal process of the master node. After a newly created blockchain is started, when a new block is generated in the newly created blockchain, each node in the node cluster can determine whether it is a master node. For example, each node in the node cluster can determine whether the block conditions are met based on the parameters in the block it maintains; when a node determines that it meets the block conditions, the node is the master node. The block condition refers to the condition used to trigger the block. For example, the block condition in this application can be set to a height value greater than a preset threshold, and the preset threshold can be 1. The node that generates the block is qualified to encapsulate the transaction task into a proposal message for the consensus block.

[0066] Furthermore, when a node (node ​​1) in the node cluster determines itself as the master node, the master node generates a block and starts a new round of consensus. The master node is responsible for generating proposals for new blocks. That is, when the master node in the node cluster constructs a new block, the master node can obtain the current time t1: 12-01-01:01, and based on time t1, it can generate a new block from the time it maintains. Figure 4 After searching for expired transaction tasks that meet the time t1 in the transaction cleanup tree shown in , the master node can grab a preset number of target transaction tasks from the transaction pool, and generate a proposal message for a new block based on the expired transaction tasks and the target transaction tasks. The proposal message carries the identification information of the expired transaction tasks, that is, the master node in this application can package the captured preset number of target transaction tasks into a proposal, and the master node can add the identification information of the expired transaction tasks to the proposal. For example, when generating a block, the master node will add an expired transaction hash value (ExpireTxRoot) to the block header of the new block. The expired transaction hash value (ExpireTxRoot) is the MerkleRoot calculated by the master node based on the expired transaction ID set, and the proposal will be broadcast to all slave nodes in the blockchain in the form of a message.

[0067] Furthermore, when a slave node receives a proposal message broadcast by the master node, the slave node can deserialize the proposal message to obtain the processed proposal structure information, and obtain the proposal time and identification information of the expired transaction task from the proposal structure information; the slave node can determine whether the proposal time is legal. When it is determined that the proposal time is legal, the slave node can obtain the local expired transaction task that meets the proposal time from the transaction cleanup tree maintained by itself, and compare the identification information of the local expired transaction task with the identification information of the expired transaction task carried in the proposal message to obtain a comparison result; further, when the comparison result indicates that the identification information of the local expired transaction task is consistent with the identification information of the expired transaction task carried in the proposal message, the slave node can further verify the target transaction task in the proposal message, that is, the slave node executes all target transaction tasks contained in the proposal message, obtains the execution result, and determines whether the execution result obtained by itself is consistent with the execution result of the target transaction task carried in the proposal message. When the slave node determines that the execution result obtained by itself is consistent with the execution result of the target transaction task carried in the proposal message, the slave node generates an affirmative vote and broadcasts the affirmative vote to other nodes in the form of a message; when the slave node determines that the execution result obtained by itself is inconsistent with the execution result of the target transaction task carried in the proposal message, the slave node generates a negative vote and broadcasts the negative vote to other nodes in the form of a message; at the same time, the slave node can receive voting messages broadcast by other nodes. When the number of affirmative votes in the voting message meets the preset conditions, the new block can reach a consensus, that is, the new block can be added to the blockchain, and each node can also add the new block to the local ledger; after the new block reaches a consensus, each node can perform a data cleaning step based on the identification information of the expired transaction task carried in the proposal message. For example, the step of performing data cleaning in the embodiment of the present application can be based on the identification information of the expired transaction task carried in the proposal message to perform a data deletion operation. The preset condition refers to the pre-set condition for a block to reach a consensus. For example, the preset condition can be set to 2f+1, where f refers to the maximum number of malicious nodes tolerated in the environment. In the Byzantine consensus, the model is 3f+1. For example, if there are 4 nodes in the entire environment (blockchain system), then f=1 node is allowed to be a malicious node, and no more. 2f+1 is the number of correct nodes, that is, when the number of affirmative votes in the voting message meets the number 2f+1, the block can reach a consensus.

[0068] In addition, when the number of affirmative votes in the voting message does not meet the preset condition (2f+1), the new block cannot reach a consensus, that is, when the new block does not reach a consensus, each slave node will not perform the data cleaning step. That is, the transaction tasks cleaned up in this application must be the transaction tasks in the account book. It can be understood that the transaction tasks for data cleaning in this application are the transaction tasks that have reached a consensus. Therefore, it can effectively avoid cleaning up the transaction tasks that have not reached a consensus, and can also effectively avoid the situation of inconsistent execution status.

[0069] In this embodiment, when constructing a new block, the expired transaction tasks in the transaction cleanup tree maintained by the self are determined; a preset number of target transaction tasks are captured from the transaction pool, and a proposal message of the new block is generated based on the expired transaction tasks and the target transaction tasks; the proposal message carries the identification information of the expired transaction tasks; the proposal message is broadcast to the first node in the blockchain, so that the first node reaches a consensus on the new block based on the target transaction tasks, and after reaching a consensus, data cleanup is performed based on the identification information. Since the proposal message of the new block is generated based on the expired transaction tasks and the target transaction tasks, after reaching a consensus in the new block, data cleanup can be automatically performed based on the identification information of the expired transaction tasks carried in the proposal message. The entire data cleanup process is through consensus and will be written in the blockchain, which can realize the completion of the data cleanup process at the same time as the consensus, with high security and traceability, and at the same time, the level of data cleanup in the blockchain can be controlled to the transaction level, so that even if the same chain is shared between businesses, there is no problem, which ensures the security of the entire blockchain while effectively improving the performance of the entire blockchain.

[0070] In one embodiment, the step of determining expired transaction tasks in the transaction expiration tree maintained by itself includes:

[0071] When constructing a new block, get the first time;

[0072] Based on the first time, determine the expired transaction tasks in the transaction cleanup tree maintained by itself.

[0073] Among them, the first time refers to the time when the block is generated, which can also be called the proposal time. For example, when the master node constructs a new block, the master node can obtain the current timestamp as t1, and t1 is the first time.

[0074] Specifically, in the underlying blockchain model based on BFT consensus, when a node (node ​​1) in the node cluster determines itself as the master node, the master node generates a block and starts a new round of consensus, that is, the master node is responsible for generating proposals for new blocks. Assume that the transaction cleanup tree maintained by the master node (node ​​1) is as follows: Figure 4As shown in , when the master node (node ​​1) constructs a new block, the master node (node ​​1) can obtain the current time stamp as t1: 12-01-01:01, and based on t1 from the self-maintained Figure 4 In the transaction cleanup tree shown in , the master node can search for expired transaction tasks that match the time t1, that is, the master node can search for the identification information of the transaction tasks to be cleaned up to the time t1 from the transaction cleanup tree maintained by itself, which at least includes: Tx(1) and Tx(n). In this way, the expired transaction tasks to be cleaned up can be determined according to the proposal time, and the level of blockchain data cleanup can be controlled to the transaction level, so that there is no problem even if the same chain is shared between businesses, which effectively improves the accuracy of data cleanup.

[0075] In one embodiment, the preset number is at least two; the method further comprises:

[0076] When the blockchain starts, a transaction cleanup tree is created;

[0077] When a consensus is reached on the new block, a root node, an intermediate node, and a leaf node are created in the transaction clearing tree based on the blockchain identifiers, identification information, and transaction expiration times carried by at least two target transaction tasks; wherein the leaf node contains the identification information of the target transaction task to be cleared;

[0078] When the transaction expiration times of at least two target transaction tasks are the same, the identification information of the at least two target transaction tasks is stored in the same leaf node.

[0079] Among them, the blockchain identifier is used to distinguish multiple chains, and can also be called a chain identifier (ChainID). For example, the chain identifier of blockchain 1 is Chain1.

[0080] The identification information refers to the transaction identification of the target transaction task, which may also be referred to as the transaction ID (TxID). For example, the transaction identification of a target transaction task is Tx1.

[0081] The transaction expiration time refers to the pre-set expiration time, which can be a relative time or an absolute time. If it is a relative time, the time when the transaction task is created is used as the starting time. For example, the expiration transaction time of a target transaction task is: 12-01-01:01 (absolute time).

[0082] The root node refers to the first-level node in the transaction cleanup tree. In the present application, the root node in the transaction cleanup tree may be created based on a time period. For example, a root node based on a period of days is created in the transaction cleanup tree.

[0083] An intermediate node refers to a node used to represent time information. The intermediate nodes in the present application may include second-level nodes and third-level nodes. For example, after creating a root node with a period of days in the transaction cleanup tree, a second-level node with a granularity of hours and a third-level node with a granularity of minutes are created in the transaction cleanup tree.

[0084] The leaf node is used to store the identification information of the transaction tasks to be cleared. For example, the third-level node in this application is the smallest level node, then each third-level node corresponds to a leaf node, and the leaf node contains the identification information of the transaction tasks to be cleared by the target time represented by the third-level node.

[0085] Specifically, Figure 6 As shown in Figure 1, it is a schematic diagram of the information carried by the transaction task. Figure 6 In the basic transaction configuration shown in , in order to allow the transaction task to be processed when it expires, it is necessary to define the expiration time in the basic configuration of the transaction task. This expiration time can be relative or absolute. If it is relative, the time when the transaction task is created is used as the starting time. Figure 6 The basic configuration of the transaction task shown in at least includes: chain identifier (ChainID), transaction ID (TxID), transaction timestamp (Timestamp), transaction expiration time (ExpirationTime) and contract information.

[0086] When the blockchain is started, a transaction cleanup tree is created. That is, after the blockchain is started, each node in the node cluster can create a transaction cleanup tree locally. Figure 4 As shown in the transaction cleanup tree, when a new block in the blockchain reaches a consensus, each node can create a root node, an intermediate node, and a leaf node in the transaction cleanup tree maintained by itself based on the blockchain identification, identification information, and transaction expiration time carried by at least two target transaction tasks contained in the new block. That is, the node can store the identification information of each transaction task in the transaction cleanup tree in the time sequence of the transaction expiration time based on the transaction expiration time of each transaction task. When the transaction expiration time of at least two transaction tasks is the same, the node can store the identification information of at least two transaction tasks in the same leaf node, that is, Figure 4 The leaf node of the transaction cleanup tree shown in contains a list of transaction IDs to be cleaned up by the target time corresponding to the leaf node.

[0087] It can be understood that the transaction clearing tree maintained by each node in this application is dynamically changing, that is, as long as a new block in the blockchain reaches a consensus, each node can create corresponding branch nodes in the transaction clearing tree maintained by itself based on the blockchain identification, identification information and transaction expiration time carried by the target transaction task contained in the new block. It should be noted that when there is no data to be cleared at a certain time, there is no need to create corresponding branch nodes, so as to save memory usage. As a result, the expired transaction tasks to be cleared can be determined according to the proposal time, and the identification information of the expired transaction tasks to be cleared can be stored using the prefix tree structure, so that the level of blockchain data clearing can be controlled to the transaction level, so that even if the same chain is shared between businesses, there is no problem, which effectively improves the accuracy of data clearing; and, by combining the prefix tree structure and the timestamp, the transaction expiration tree structure that each node needs to maintain dynamically is defined, so that the entire cleaning process does not require manual participation, and is automatically triggered and executed, thereby effectively improving the processing efficiency of the entire blockchain.

[0088] In one embodiment, the intermediate node includes a second-level node and a third-level node; when a consensus is reached on a new block, based on the blockchain identifier, identifier information and transaction expiration time carried by the target transaction task, the steps of creating a root node, a second-level node, a third-level node and a leaf node in the transaction cleanup tree include:

[0089] When a new block reaches consensus, based on the blockchain identifier, identifier information and transaction expiration time carried by the target transaction task, a root node with a period of days, a second-level node with a granularity of hours, a third-level node with a granularity of minutes and a leaf node corresponding to the target time represented by the third-level node are created in the transaction cleanup tree;

[0090] The leaf node contains identification information of the target transaction task to be cleared by the target time.

[0091] Specifically, Figure 7 As shown in the figure, it is a schematic diagram of the process of creating a transaction cleanup tree. When the new block 1 reaches a consensus, assuming that the target transaction task contained in the new block 1 is Figure 7 The transaction tasks shown on the left are: Tx(1):12-01:01:00:50, Tx(2):12-01:01:00:31, Tx(3):12-01:01:05:05, Tx(4):12-01:23:10:11, Tx(5):12-02:04:30:21. After consensus is reached on the new block 1, each node can construct the following according to the expiration time sequence of each transaction task contained in the new block 1: Figure 7Each transaction task shown in the transaction cleanup tree is a branch node, that is, each node in the node cluster can create a root node with a day period, a second-level node with an hour granularity, a third-level node with a minute granularity, and a leaf node corresponding to the target time (01:00:50) represented by the third-level node in the transaction cleanup tree based on the transaction expiration time carried by the first transaction task Tx(1):12-01:01:00:50, and store the identification information of the first transaction task Tx(1):12-01:01:00:50 in the leaf node, and the following can be obtained: Figure 7 Similarly, based on the transaction expiration times carried by Tx(2):12-01:01:00:31, Tx(3):12-01:01:05:05, Tx(4):12-01:23:10:11, and Tx(5):12-02:04:30:21, a root node with a period of days, a second-level node with a granularity of hours, a third-level node with a granularity of minutes, and leaf nodes corresponding to the target times (01:00:31, 01:05:05, 23:10:11, and 04:30:21) represented by the third-level nodes can be created in the transaction cleanup tree, and the identification information of each transaction task can be stored in the corresponding leaf node. Figure 7 It can be understood that in the branch nodes shown in 2, 3, and 4 Figure 7 In the structure of the transaction cleanup tree shown, the root node represents the day, the second-level node represents the hour, the third-level node represents the minute, and the last leaf node contains a list of transaction IDs to be cleaned up by the target time corresponding to the leaf node.

[0092] like Figure 4 As shown in , in order to improve processing performance, it is generally recommended to perform relationship maintenance of the transaction cleanup tree for the next day at the end of the day (for example, 1 hour before the end).

[0093] In addition, it should be noted that the expiration time of the transaction task sent by the user is not allowed to be a historical time, and it is best to reserve a certain time error range.

[0094] In this embodiment, the expired transaction tasks to be cleaned can be determined according to the proposal time, and the identification information of the expired transaction tasks to be cleaned can be stored using the prefix tree structure, so that the level of blockchain data cleaning can be controlled to the transaction level, so that there is no problem even if the same chain is shared between businesses, which effectively improves the accuracy of data cleaning; and, by combining the prefix tree structure and the timestamp, the transaction expiration tree structure that needs to be dynamically maintained for each node is defined, so that the entire cleaning process does not require human participation and is automatically triggered and executed, thereby effectively improving the processing efficiency of the entire blockchain.

[0095] In one embodiment, the step of generating a proposal message for a new block based on an expired transaction task and a target transaction task includes:

[0096] Determine the expired transaction hash value according to the expired transaction identifier set;

[0097] Add the expired transaction hash value to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block is the expired transaction hash value; or,

[0098] The expired transaction identification set is added to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block is the expired transaction identification set.

[0099] Specifically, when the master node in the node cluster constructs a new block, after the master node determines the expired transaction tasks in the transaction cleanup tree maintained by itself, the master node can grab a preset number of target transaction tasks from the transaction pool, and package the grabbed preset number of target transaction tasks into a proposal. At the same time, the master node can add the identification information of the expired transaction tasks to the proposal, and broadcast the proposal to all slave nodes in the blockchain in the form of a message. That is, the master node can store the identification information of the expired transaction tasks obtained from the transaction cleanup tree maintained by itself into the expired transaction identification set, and calculate the expired transaction hash value based on the expired transaction identification set; further, the master node can add the expired transaction hash value to the block header of the new block, so that the identification information of the expired transaction tasks carried in the proposal message of the new block is the expired transaction hash value; or,

[0100] The master node may also directly add the expired transaction identification set to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block is the expired transaction identification set.

[0101] For example, in the underlying blockchain model based on BFT consensus, when the master node in the node cluster constructs a new block, after the master node determines the expired transaction tasks in the transaction cleanup tree maintained by itself, the master node can grab a preset number of target transaction tasks from the transaction pool, and package the grabbed preset number of target transaction tasks into a proposal. At the same time, the master node can add the identification information of the expired transaction tasks to the proposal, and broadcast the proposal to all slave nodes in the blockchain in the form of a message.

[0102] like Figure 8 As shown in Figure 1, it is a schematic diagram of the information carried in the proposal message. Figure 8The identification information of the expired transaction task shown in may include: an expired transaction identification set (ExpireTxIDs) and an expired transaction hash value (ExpireTxRoot). Some proposal messages will carry an expired transaction identification set (ExpireTxIDs), while some proposal messages will not carry an expired transaction identification set (ExpireTxIDs). Therefore, when the master node in the node cluster constructs a new block, the master node can store the expired transaction task ID obtained from the transaction cleanup tree maintained by itself into the expired transaction identification set, calculate the MerkleRoot of the expired transaction identification set, and use the calculated MerkleRoot of the expired transaction identification set as the expired transaction hash value (ExpireTxRoot); further, the master node can add the expired transaction hash value (ExpireTxRoot) to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block is the expired transaction hash value (ExpireTxRoot); or,

[0103] The master node can also directly add the expired transaction identification set (ExpireTxIDs) to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block is the expired transaction identification set (ExpireTxIDs). That is, the master node in this application needs to add the cleaned (archived) transaction ID to the proposal when proposing. The proposal is generally a block + node signature, that is to say, the master node in this application needs to add the transaction ID set to be cleaned to the new block when constructing a new block. Among them, the expired transaction hash value (ExpireTxRoot) and the proposal time (ProposalTime) are two required fields. The former is the Merkle root calculated for the transaction ID set that needs to be cleaned, and the latter is mainly used to determine the time range of processing. As a result, by combining the transaction cleaning tree structure and the timestamp, the level of blockchain data cleaning can be controlled to the transaction level, so that even if the same chain is shared between businesses, it is no problem, which effectively improves the accuracy of data cleaning; and the entire cleaning process does not require manual participation, it is automatically triggered and executed, thereby effectively improving the processing efficiency of the entire blockchain.

[0104] In one embodiment, the step of generating a proposal message for a new block based on an expired transaction task and a target transaction task includes:

[0105] Determine the expired transaction hash value according to the expired transaction identifier set;

[0106] The expired transaction identification set and the expired transaction hash value are added to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block includes the expired transaction identification set and the expired transaction hash value.

[0107] Specifically, Figure 8 As shown in Figure 1, it is a schematic diagram of the information carried in the proposal message. Figure 8 The identification information of the expired transaction task shown in may include: an expired transaction identification set (ExpireTxIDs) and an expired transaction hash value (ExpireTxRoot). Some proposal messages may carry an expired transaction identification set (ExpireTxIDs) and an expired transaction hash value (ExpireTxRoot). Therefore, when the master node in the node cluster constructs a new block, the master node can store the expired transaction task ID obtained from the transaction cleanup tree maintained by itself into the expired transaction identification set (ExpireTxIDs), calculate the MerkleRoot of the expired transaction identification set, and use the calculated MerkleRoot of the expired transaction identification set as the expired transaction hash value (ExpireTxRoot); further, the master node can add both the expired transaction hash value (ExpireTxRoot) and the expired transaction identification set (ExpireTxIDs) to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block includes the expired transaction hash value (ExpireTxRoot) and the expired transaction identification set (ExpireTxIDs).

[0108] It should be noted that the proposal message in this application can carry ExpireTxIDs, which contains the list of transaction IDs to be removed after the consensus is reached. It can also not carry ExpireTxIDs. Generally, the TPS of the blockchain system that does not carry ExpireTxIDs is generally at the minute level, that is, each proposal is separated by more than a minute, so as to adapt to the transaction cleanup tree maintained by each node in this application. If the TPS of the blockchain system is relatively high, ExpireTxIDs must be carried so that the transaction ID set to be cleaned up can be clearly confirmed.

[0109] In this embodiment, by combining the transaction cleanup tree structure and the timestamp, the expired transaction tasks to be cleaned up can be determined according to the proposal time, so that the level of blockchain data cleanup can be controlled to the transaction level. In this way, there is no problem even if the same chain is shared between businesses, which effectively improves the accuracy of data cleanup; and the entire cleanup process does not require human participation, but is automatically triggered and executed, thereby effectively improving the processing efficiency of the entire blockchain.

[0110] In one embodiment, the proposal message carries the first time and the expired transaction hash value; the steps of reaching consensus on the new block based on the target transaction task include:

[0111] When the first node receives the proposal message, it deserializes the proposal message to obtain the processed proposal structure information;

[0112] Get the first-hand information from proposal structure;

[0113] When the first time is legal and the expired transaction identifier set is not obtained, a local expired transaction task that satisfies the first time is obtained from the transaction cleanup tree maintained by the first node;

[0114] Determine the hash value corresponding to the local expired transaction task;

[0115] Compare the hash value with the expired transaction hash value to obtain a comparison result;

[0116] When the comparison result indicates that the hash value is inconsistent with the expired transaction hash value, a negative vote message is generated and broadcast to other nodes.

[0117] Specifically, Fig. 9 The figure below is a schematic diagram of the verification process after the slave node receives the proposal message. After the master node broadcasts the proposal message carrying the first time (proposal time) and the expired transaction hash value to each slave node in the blockchain, when the slave node receives the proposal message, the process of the slave node verifying the proposal message is as follows: Fig. 9 As shown in , the slave node can deserialize the proposal message to obtain the processed proposal structure information, and obtain the first time and the expired transaction identification set from the proposal structure information, that is, the proposal structure contains a field for indicating the proposal time and a field for indicating the expired transaction identification set; further, the slave node can determine whether the first time (i.e., the proposal time) is legal. If the first time is legal, the slave node further determines whether the expired transaction identification set is an empty set. If the expired transaction identification set is an empty set, the slave node can obtain the local expired transaction task that meets the first time from the transaction cleanup tree maintained by itself, and calculate the hash value corresponding to the local expired transaction task; further, the slave node can compare the hash value calculated by itself with the expired transaction hash value carried in the proposal message to obtain a comparison result; when the comparison result indicates that the hash value calculated by itself is inconsistent with the expired transaction hash value carried in the proposal message, the slave node can generate a negative vote message and broadcast the negative vote message to other nodes. As a result, the entire data cleanup process is through consensus and will be written in the blockchain, with high security and traceability.

[0118] In one embodiment, after comparing the hash value with the expired transaction hash value and obtaining the comparison result, the method further includes:

[0119] When the comparison result indicates that the hash value is consistent with the expired transaction hash value, the target transaction task is obtained from the proposal structure information, and the target transaction task is executed to obtain the execution result corresponding to the target transaction task;

[0120] When the execution result is consistent with the execution result carried in the proposal message, an approval message is generated and broadcast to other nodes.

[0121] Specifically, Fig. 9 As shown in the figure, it is a schematic diagram of the verification process after the slave node receives the proposal message. After the master node broadcasts the proposal message carrying the first time (proposal time) and the expired transaction hash value to each slave node in the blockchain, when the slave node receives the proposal message, the process of the slave node verifying the proposal message is as follows: Fig. 9 As shown in , the slave node can deserialize the proposal message to obtain the processed proposal structure information, and obtain the first time and expired transaction identification set from the proposal structure information, that is, the proposal structure contains a field for indicating the proposal time and a field for indicating the expired transaction identification set; further, the slave node can determine whether the first time (i.e., the proposal time) is legal. If the first time is legal, the slave node further determines whether the expired transaction identification set is an empty set. If the expired transaction identification set is an empty set, the slave node can obtain the local expired transaction task that meets the first time from the transaction cleanup tree maintained by itself, and calculate the hash value corresponding to the local expired transaction task; further, the slave node can The hash value calculated by itself is compared with the expired transaction hash value carried in the proposal message to obtain the comparison result; when the comparison result indicates that the hash value calculated by itself is consistent with the expired transaction hash value carried in the proposal message, the slave node can continue to verify the target transaction task in the proposal message, that is, the slave node can obtain all the target transaction tasks contained in the proposal from the proposal structure information, and execute each target transaction task to obtain the execution result corresponding to each target transaction task; when the execution results of each target transaction task obtained by itself are consistent with the execution results of each target transaction task carried in the proposal message, a vote of approval message is generated and broadcast to other nodes. As a result, the entire data cleaning process is through consensus and will be written in the blockchain, which has high security and traceability.

[0122] In one embodiment, after obtaining the first time from the proposal structure information, the method further includes:

[0123] When the first time is legal and the expired transaction identifier set is obtained, a local expired transaction task that satisfies the first time is obtained from the transaction cleanup tree maintained by the first node;

[0124] Verify the expired transaction identifier set based on the local expired transaction task;

[0125] When the verification passes, the step of determining the hash value corresponding to the local expired transaction task is executed.

[0126] Specifically, Fig. 9 As shown in Figure 1, it is a schematic diagram of the verification process after the slave node receives the proposal message. After the master node broadcasts the proposal message carrying the first time and the expired transaction hash value to each slave node in the blockchain, when the slave node receives the proposal message, the process of the slave node verifying the proposal message is as follows: Fig. 9 As shown in , the slave node can deserialize the proposal message to obtain the processed proposal structure information, and obtain the first time and expired transaction identification set from the proposal structure information; further, the slave node can determine whether the first time (i.e., the proposal time) is legal. If the first time is legal, the slave node further determines whether the expired transaction identification set is an empty set. If the expired transaction identification set is not an empty set, the slave node can obtain the local expired transaction task that meets the first time from the transaction cleanup tree maintained by itself, and verify the expired transaction identification set based on the local expired transaction task, that is, the slave node can compare the transaction IDs of each expired transaction task in the expired transaction identification set according to the transaction ID of the local expired transaction task. When the comparison result is consistent, it means that the verification is passed, and the slave node can continue to execute the step of determining the hash value corresponding to the local expired transaction task. As a result, the entire data cleaning process is through consensus and will be written in the blockchain, which has high security and traceability.

[0127] In one embodiment, after obtaining the first time from the proposal structure, the method further includes:

[0128] When the first time does not meet the time threshold range, a negative vote message is generated;

[0129] Broadcast the negative vote message to other nodes.

[0130] Specifically, Fig. 9 As shown in Figure 1, it is a schematic diagram of the verification process after the slave node receives the proposal message. After the master node broadcasts the proposal message carrying the first time and the expired transaction hash value to each slave node in the blockchain, when the slave node receives the proposal message, the process of the slave node verifying the proposal message is as follows: Fig. 9As shown in, the slave node can deserialize the proposal message to obtain the processed proposal structure information, and obtain the first time and expired transaction identifier set from the proposal structure information; further, the slave node can determine whether the first time (i.e. proposal time) is legal, that is, the slave node can determine whether the first time (i.e. proposal time) meets the preset time threshold range. If the first time (i.e. proposal time) is within the preset time threshold range, it indicates that the first time is legal; if the first time (i.e. proposal time) is not within the preset time threshold range, that is, the first time (i.e. proposal time) does not meet the preset time threshold range, it indicates that the first time is illegal, that is, when the first time is illegal, the slave node can generate a negative vote message and broadcast the negative vote message to other nodes. As a result, the entire data cleaning process is through consensus and will be written in the blockchain, which has high security and traceability.

[0131] In one embodiment, the steps of reaching consensus on a new block based on a target transaction task and cleaning up data based on identification information after reaching consensus include:

[0132] When the first node receives the second initial voting message broadcasted by other nodes, the first node determines the first voting message based on its own first initial voting message and the second initial voting message;

[0133] When the first node receives the second voting message broadcast by other nodes, it determines that a new block has reached consensus based on the first voting message and the second voting message, and writes the target transaction task and the execution result of the target transaction task into the local account book;

[0134] When the block header of the new block carries an expired transaction identifier set, the corresponding transaction task is obtained according to the expired transaction identifier set;

[0135] When the transaction task is in the state data deletion mode, the execution result corresponding to the transaction task is obtained from the block database, and the state data corresponding to the transaction task at the current moment is obtained from the state database;

[0136] Compare the execution result with the status data to obtain a comparison result;

[0137] When the comparison result indicates that the execution result is consistent with the status data, the status data corresponding to the transaction task is deleted from the status database, and the data corresponding to the transaction task in the block database is deleted.

[0138] Among them, the first initial voting message and the first voting message are only used to distinguish different rounds of voting messages of the current node. For example, the first initial voting message refers to the first round of voting messages of the current node, and the first voting message refers to the second round of voting messages of the current node.

[0139] The second initial voting message and the second voting message are only used to distinguish different rounds of voting messages of other nodes. For example, the second initial voting message refers to the first round of voting messages of other nodes, and the second voting message refers to the second round of voting messages of other nodes.

[0140] It can be understood that the first initial voting message, the second initial voting message, the first voting message, and the second voting message in the present application are only used to distinguish the voting messages broadcast by different nodes in different rounds.

[0141] Specifically, Fig.10 As shown in the figure, it is a schematic diagram of the consensus process based on the BFT consensus algorithm. Fig.10 In the underlying blockchain model based on BFT consensus shown in , when a node (Node1) in the node cluster determines itself as the leader, the leader generates a block and starts a new round of consensus. The leader can broadcast the proposal message to the slave nodes (Node2, Node3, Node4) in the blockchain so that the slave nodes (Node2, Node3, Node4) can reach consensus on the new block based on the transaction tasks in the proposal message; Fig.10 As shown in , when a slave node (Node4) in the node cluster receives the proposal message broadcast by the master node, the slave node (Node4) can execute the following Fig. 9 The verification process shown in generates a first initial voting message (Prevote vote); when the slave node receives the second initial voting message (Prevote vote) broadcasted by other nodes, the slave node can generate a first voting message (PreCommit vote) based on its own first initial voting message (Prevote vote) and the second initial voting message (Prevote vote); when the slave node receives the second voting message (PreCommit vote) broadcasted by other nodes, the slave node can determine whether the block corresponding to the block identifier in the proposal message can reach a consensus based on the first voting message (PreCommit vote) and the second voting message (PreCommit vote). For example, when the number of voting messages in favor of the consensus on the block in the first voting message and the second voting message meets the preset condition (the number of 2f+1), the slave node can determine that the new block has reached a consensus and submit the account book; or when the number of voting messages in favor of the consensus on the block in the first voting message and the second voting message does not meet the preset condition (the number of 2f+1), the slave node can determine that the new block has not reached a consensus, and then enter the next round of consensus processing.

[0142] Further, such as Fig.11 As shown in FIG. 1 , it is a flowchart for cleaning up expired data. Fig.11The i shown in the figure indicates the transaction number, and i++ means that after i participates in the operation, the value of i is increased by 1. Fig.11 The len(ETxIDs) in the ETxIDs represents the number of transaction IDs in the expired transaction ID set ETxIDs. When the slave node determines that the new block has reached consensus and submits the ledger, if there is an expired transaction ID in the expired transaction ID set (ExpireTxIDs) carried in the block header of the new block, the slave node needs to clean up the corresponding expired data. The processing flow is as follows: Fig.11 As shown in Fig.11 According to the processing flow shown in , when the block header of the new block carries an expired transaction identifier set and there is an expired transaction ID in the expired transaction identifier set (ExpireTxIDs), the slave node can obtain the corresponding transaction information according to the expired transaction ID in the expired transaction identifier set, and determine whether the transaction information is in the state data deletion mode (StateDB deletion mode); when the transaction information is in the state data deletion mode, the slave node can obtain the execution result (key-value pair information) corresponding to the transaction task from the block database (blockDB), and obtain the state data (key-value pair information) corresponding to the transaction task at the current moment from the state database (StateDB), and compare the execution result (key-value pair information) with the state data (key-value pair information) to obtain a comparison result; when the comparison result indicates that the execution result (key-value pair information) is consistent with the state data (key-value pair information), the slave node can delete the state data (key-value pair information) corresponding to the transaction task from the state database, and delete the transaction content corresponding to the transaction task in the block database. As a result, the entire data cleaning process is subject to consensus and will be written in the blockchain, which can complete the data cleaning process while achieving consensus, with high security and traceability. At the same time, the level of data cleaning in the blockchain can be controlled to the transaction level, so that there is no problem even if the same chain is shared between businesses. In addition, the state data in the state database can be cleaned up to a certain extent, and more data can be cleaned up than in traditional methods, ensuring the security of the entire blockchain while effectively improving the performance of the entire blockchain.

[0143] In one embodiment, after comparing the execution result with the state data and obtaining the comparison result, the method further includes:

[0144] When the comparison result indicates that the execution result is inconsistent with the status data, the data corresponding to the transaction task in the block database is deleted.

[0145] Specifically, Fig.11As shown in the figure, it is a flowchart for cleaning up expired data. When the slave node determines that the new block has reached consensus and submitted the ledger, if there is an expired transaction ID in the expired transaction identification set (ExpireTxIDs) carried in the block header of the new block, the slave node needs to clean up the corresponding expired data. The processing flow is as follows: Fig.11 As shown in Fig.11 According to the processing flow shown in , when the block header of the new block carries an expired transaction identifier set and there is an expired transaction ID in the expired transaction identifier set (ExpireTxIDs), the slave node can obtain the corresponding transaction information according to the expired transaction ID in the expired transaction identifier set, and determine whether the transaction information is in the state data deletion mode (StateDB deletion mode); when the transaction information is in the state data deletion mode, the slave node can obtain the execution result (key-value pair information) corresponding to the transaction task from the block database, and obtain the state data (key-value pair information) corresponding to the transaction task at the current moment from the state database, and compare the execution result (key-value pair information) with the state data (key-value pair information) to obtain a comparison result; when the comparison result indicates that the execution result (key-value pair information) is inconsistent with the state data (key-value pair information), the slave node can delete the transaction content corresponding to the transaction task in the block database. That is, when the comparison result indicates that the execution result (key-value pair information) is inconsistent with the state data (key-value pair information), the slave node will not delete the state data corresponding to the transaction task in the state database. That is, the blockchain system in this application can provide two modes of whether to delete StateDB. Because StateDB needs to be used in subsequent contract executions, if the data in StateDB is deleted without considering any other relationships, it may cause problems in the entire business. Therefore, it is not deleted by default. However, it can be deleted in some special scenarios, such as the evidence storage scenario where the keys do not conflict. Because the keys do not conflict, it will not affect subsequent business and can be deleted.

[0146] In this embodiment, in order to ensure security, in the deletable mode of StateDB, each node in the blockchain system also needs to determine whether the value corresponding to the current key is the value written at that time. If it is, it will be deleted. If not, the data in StateDB will not be deleted. This can ensure a certain degree of security, thereby achieving the goal of ensuring the security of the entire blockchain while effectively improving the performance of the entire blockchain.

[0147] In one embodiment, the present application further provides an application scenario, which applies the above-mentioned blockchain data cleaning method. Specifically, the application of the blockchain data cleaning method in the application scenario is as follows:

[0148] When you want to complete the cleaning of expired data at the same time as consensus, you can use the above-mentioned blockchain data cleaning method, that is, in the blockchain system, when the master node in the node cluster generates a block, when the master node constructs a new block, the master node determines the expired transaction tasks in the transaction cleaning tree maintained by itself, and grabs a preset number of target transaction tasks from the transaction pool. After that, the master node can generate a proposal message for a new block based on the expired transaction tasks and the target transaction tasks; the proposal message carries the identification information of the expired transaction tasks; the master node broadcasts the proposal message carrying the identification information of the expired transaction tasks to the slave nodes in the blockchain, so that the slave nodes reach a consensus on the new block based on the target transaction tasks, and after reaching a consensus, the data cleaning is performed based on the identification information of the expired transaction tasks carried in the proposal message. Since the entire data cleaning process is through consensus and will be written in the blockchain, the data cleaning process can be completed at the same time as consensus, which has high security and traceability. At the same time, the level of data cleaning in the blockchain can also be controlled to the transaction level, so that even if the same chain is shared between businesses, there is no problem, which ensures the security of the entire blockchain while effectively improving the performance of the entire blockchain.

[0149] The method provided in the embodiment of the present application can be applied to consensus scenarios of various blockchains. The following takes the blockchain consensus scenario in a BFT consensus environment as an example to illustrate the blockchain data cleaning method provided in the embodiment of the present application.

[0150] With the development of technology, blockchain technology has become more and more mature. Due to the open and transparent nature of blockchain itself, more and more systems are moving their businesses directly to blockchain.

[0151] Blockchain is essentially a distributed storage system. Each of its nodes stores data, and the storage of data by nodes is based on data. As the amount of data increases, more and more data needs to be stored. Naturally, for some non-distributed data, its storage performance will become lower and lower. Since blockchain itself is distributed storage, each node usually uses a non-distributed database, so the performance will naturally be affected.

[0152] In order to improve the overall processing performance, considering that not all data will be needed in the future, combined with the current solutions in the industry, this application proposes a timestamp-based data cleaning solution that can be accurate to the transaction level. This solution also effectively reduces storage, and most importantly, the cleaning process is automatically executed and agreed upon.

[0153] like Fig.12The figure shows a schematic diagram of data cleaning in the traditional way. The processing scheme adopted in the traditional way is generally called "data archiving". The so-called data archiving is that the administrator of the blockchain system sends a command to the entire blockchain node (the command will also be sent to the blockchain in the form of a transaction). In this command, the height of the archived block is usually specified. The blockchain node will archive all transaction data before the height, thereby achieving the effect of reducing the amount of data.

[0154] like Fig.12 The archiving method shown in the figure will only archive the data in blockDB, but not the data in stateDB. blockDB is the database that stores the original transaction information, and stateDB is the database that stores the status. The so-called status is the key-value pair operated during the transaction execution process. stateDB handles duplicate keys in an overwriting manner.

[0155] The reason why the data in StateDB is not archived is that there is no way to distinguish the information of the key in stateDB before the specified height (because its value is overwritten); secondly, the data in stateDB will be needed during the transaction execution process, so it cannot be archived arbitrarily.

[0156] The defects of the traditional method are as follows:

[0157] 1. Archiving cannot be done automatically and must be triggered manually by a person, usually an administrator, which is an action that affects the data;

[0158] 2. Archived content cannot be distinguished at the transaction level, but only at the block level. This is not friendly to partially available transactions that happen to be within the archive range. In addition, if multiple business systems are in a chain, archiving behavior may affect other businesses;

[0159] 3. Archiving is a single-point behavior, and consensus cannot be reached (or consensus needs to be reached manually). Failure to reach consensus may cause inconsistent execution status;

[0160] 4. Data in stateDB cannot be archived.

[0161] Therefore, in order to solve the above problems, the present application provides an optimization solution, that is, a method for blockchain data cleaning. In this optimization solution, the user can set an expiration time for each transaction. When the expiration time is reached, the blockchain system will delete the corresponding transaction (even including the data in StateDB) through consensus, so the granularity of its archiving is the transaction level, and because it is a consensus behavior, it is the result of reaching a consensus.

[0162] On the product side, the method provided in this application can be applied to the actual development of blockchain underlying software, and can also be used as a method of external publicity. It can also be implemented at the code level according to the solution of this application to optimize the corresponding blockchain underlying code.

[0163] On the technical side,

[0164] 1.1 Transaction Processing

[0165] In order for a transaction to be processed when it expires, it is necessary to define an expiration time in the transaction. This expiration time can be relative or absolute. If it is relative, it starts from the time the transaction was created, such as Figure 6 That is, the transactions archived in this application must be transactions in the ledger. In order to more efficiently handle the transaction archiving problem, this application combines the prefix tree structure with the timestamp and defines the following: Figure 4 The transaction maintenance structure shown in the transaction cleanup tree. Figure 4 In the structure shown in , the root node represents the day, the second-level node represents the hour, the third-level node represents the minute, and the last leaf node contains a list of transaction IDs that need to be cleared up to the time of the third-level node corresponding to the leaf node.

[0166] In order to improve processing performance, it is generally recommended to perform relationship maintenance of the transaction cleanup tree for the next day at the end of the day (for example, 1 hour before the end).

[0167] The process of creating a transaction cleanup tree in this application is as follows Figure 7 As shown in , it can be understood that branch nodes that do not have data are not created in order to save memory usage.

[0168] 1.2 Transaction Clearing Process

[0169] The consensus algorithm in the embodiments of this application refers to a BFT consensus algorithm. This type of consensus algorithm is generally as follows Fig.10 Several stages are shown in .

[0170] The core of the method provided by this application is that the master node needs to add the cleaned (archived) transaction ID to the proposal when proposing. The so-called proposal is generally a block + node signature, that is, the cleaned transaction ID set needs to be added to the block, such as Figure 8 The proposal message shown in the figure carries two required fields: ExpireTxRoot and ProposalTime. The former is the Merkle tree root calculated for the set of all transaction IDs that need to be cleaned up, and the latter is mainly used to determine the time range for processing.

[0171] It is understandable that Figure 8The information carried in the proposal message shown in can also include ExpireTxIDs, which contains the list of transaction IDs to be removed after the consensus is reached. The proposal message may not contain ExpireTxIDs. Generally, the TPS of the blockchain system that does not contain it is at the minute level, that is, each proposal is separated by more than minutes, so that it can adapt to the transaction cleanup tree created in this application. If the system's TPS is relatively high, ExpireTxIDs must be carried so that the transaction ID set that needs to be cleaned up can be clearly confirmed.

[0172] The proposal process of the master node is adjusted as follows Figure 5 As shown in Figure 5 The core of the process shown in is to add information such as ExpireTxRoot, ProposalTime, ExpireTxIDs, etc. to the blockchain.

[0173] When a slave node receives a proposal, its verification process is as follows: Fig. 9 As shown in Fig. 9 In the process shown in , the following points need to be specially explained:

[0174] 1) Because the clocks of each node are different, a certain time difference is allowed, but this time difference needs to be within a certain range, such as within 1 minute;

[0175] 2) If the block carries a set of expired transaction IDs, it is necessary to verify whether each expired transaction ID is legal, that is, whether it is confirmed to be a transaction to be cleaned up. If the block does not carry a set of expired transaction IDs, the proposal time is used as the benchmark, and each slave node calculates it based on the transaction cleanup tree maintained in its own memory.

[0176] In the third stage of BFT consensus, when the node receives enough PreCommit votes, it will operate on this consensus to confirm whether to abandon this operation or submit it. When it is confirmed that the new block has reached consensus and is submitted, if there is content in ExpireTxIDs, the node needs to clean up. The processing flow is as follows Fig.11 As shown in Fig.11 In the process shown in , a few points need to be explained:

[0177] 1) The blockchain system in this application can provide two modes: whether to delete StateDB or not. Because StateDB needs to be used in the subsequent contract execution, if StateDB is deleted without considering any other relationships, it will cause problems in the entire business. Therefore, it is not deleted by default, but it can be deleted in some special scenarios, such as the evidence storage scenario where the key does not conflict. Because the key does not conflict, it will not affect the subsequent business and can be deleted;

[0178] 2) To ensure security, even in the deletable mode of StateDB, the blockchain system needs to determine whether the value corresponding to the current key is the value written at the time. If it is, it will be deleted. This can ensure a certain degree of security, although ABA situations may still exist.

[0179] The beneficial effects of the technical solution of this application include:

[0180] 1. The level of blockchain data cleaning can be controlled to the transaction level, so there is no problem even if the same chain is shared between businesses;

[0181] 2. The entire data cleaning process is subject to consensus and will be written into the blockchain, which is highly secure and traceable;

[0182] 3. The cleaning process does not require manual participation, improving overall efficiency;

[0183] 4. It can clean up the data in StateDB to a certain extent, and clean up more data than the traditional method.

[0184] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0185] Based on the same inventive concept, the embodiment of the present application also provides a blockchain data cleaning device for implementing the blockchain data cleaning method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the one or more blockchain data cleaning devices provided below can refer to the limitations of the blockchain data cleaning method above, and will not be repeated here.

[0186] In one embodiment, Fig.13 As shown, a data cleaning device for a blockchain is provided, including: a determination module 1302, a capture module 1304, a generation module 1306 and a broadcast module 1308, wherein:

[0187] The determination module 1302 is used to determine the expired transaction tasks in the transaction clearing tree maintained by itself.

[0188] The capture module 1304 is used to capture a preset number of target transaction tasks from the transaction pool.

[0189] The generating module 1306 is used to generate a proposal message of the new block based on the expired transaction task and the target transaction task; the proposal message carries the identification information of the expired transaction task.

[0190] The broadcast module 1308 is used to broadcast the proposal message to the first node in the blockchain, so that the first node reaches a consensus on the new block based on the target transaction task, and performs data cleanup based on the identification information after reaching a consensus.

[0191] In one embodiment, the device further includes: an acquisition module, used to acquire a first time when constructing a new block; and the determination module is further used to determine, based on the first time, an expired transaction task in a transaction clearing tree maintained by itself.

[0192] In one embodiment, the preset number is at least two; the device also includes: a creation module and a storage module, the creation module is used to create the transaction cleanup tree when the blockchain is started; when the new block reaches a consensus, based on the blockchain identification, identification information and transaction expiration time carried by at least two of the target transaction tasks, a root node, an intermediate node and a leaf node are created in the transaction cleanup tree; wherein the leaf node contains the identification information of the target transaction task to be cleaned; the storage module is used to store the identification information of at least two target transaction tasks in the same leaf node when the transaction expiration time of at least two of the target transaction tasks is the same.

[0193] In one embodiment, the intermediate node includes a second-level node and a third-level node; the creation module is also used to create a root node with a period of days, a second-level node with a granularity of hours, a third-level node with a granularity of minutes, and a leaf node corresponding to the target time represented by the third-level node in the transaction clearing tree based on the blockchain identifier, identification information and transaction expiration time carried by the target transaction task after the new block reaches a consensus; wherein the leaf node contains the identification information of the target transaction task to be cleared by the target time.

[0194] In one embodiment, the device also includes: an adding module, the determining module is also used to determine the expired transaction hash value according to the expired transaction identification set; the adding module is used to add the expired transaction hash value to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block is the expired transaction hash value; or, the expired transaction identification set is added to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block is the expired transaction identification set.

[0195] In one embodiment, the determination module is further used to determine the expired transaction hash value based on the expired transaction identification set; the adding module is further used to add the expired transaction identification set and the expired transaction hash value to the block header of the new block, so that the proposal message of the new block carries the identification information of the expired transaction task including the expired transaction identification set and the expired transaction hash value.

[0196] In one embodiment, the proposal message carries a first time and an expired transaction hash value; the device also includes: a processing module and a comparison module, the processing module is used to deserialize the proposal message when the first node receives the proposal message to obtain the processed proposal structure information; the acquisition module is also used to obtain the first time from the proposal structure information; when the first time is legal and the expired transaction identifier set is not obtained, the local expired transaction task that meets the first time is obtained from the transaction cleanup tree maintained by the first node; the determination module is also used to determine the hash value corresponding to the local expired transaction task; the comparison module is used to compare the hash value with the expired transaction hash value to obtain a comparison result; the generation module is also used to generate negative vote information when the comparison result indicates that the hash value is inconsistent with the expired transaction hash value, and broadcast the negative vote information to other nodes.

[0197] In one embodiment, the acquisition module is also used to obtain the target transaction task from the proposal structure information and execute the target transaction task to obtain the execution result corresponding to the target transaction task when the comparison result indicates that the hash value is consistent with the expired transaction hash value; the generation module is also used to generate an approval message when the execution result is consistent with the execution result carried in the proposal message, and broadcast the approval message to the other nodes.

[0198] In one embodiment, the device further includes: a verification module and an execution module, the acquisition module is further used to obtain a local expired transaction task that meets the first time from a transaction cleanup tree maintained by the first node when the first time is legal and the expired transaction identifier set is acquired; the verification module is used to verify the expired transaction identifier set based on the local expired transaction task; the execution module is used to execute the step of determining the hash value corresponding to the local expired transaction task when the verification passes.

[0199] In one embodiment, the generating module is further used to generate a negative vote message when the first time does not meet the time threshold range; the broadcasting module is further used to broadcast the negative vote message to other nodes.

[0200] In one embodiment, the device further includes: a deletion module, a determination module further configured to, when the first node receives a second initial voting message broadcast by other nodes, determine the first voting message based on the first initial voting message and the second initial voting message of the first node; when the first node receives the second voting message broadcast by the other nodes, determine that the new block reaches a consensus based on the first voting message and the second voting message, and write the target transaction task and the execution result of the target transaction task into the local account book; the acquisition module further configured to, when the block header of the new block carries an expired transaction identifier set, acquire the corresponding transaction task according to the expired transaction identifier set; when the transaction task is in a state data deletion mode, acquire the execution result corresponding to the transaction task from the block database, and acquire the state data corresponding to the transaction task at the current moment from the state database; the comparison module further configured to compare the execution result with the state data to obtain a comparison result; the deletion module configured to, when the comparison result indicates that the execution result is consistent with the state data, delete the state data corresponding to the transaction task from the state database, and delete the data corresponding to the transaction task in the block database.

[0201] In one embodiment, the deletion module is further used to delete the data corresponding to the transaction task in the block database when the comparison result indicates that the execution result is inconsistent with the status data.

[0202] Each module in the above-mentioned blockchain data cleaning device can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0203] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.14 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store block data and status data of the blockchain. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a data cleaning method of a blockchain is implemented.

[0204] Those skilled in the art will understand that Fig.14 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0205] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.

[0206] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0207] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0208] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0209] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited thereto.

[0210] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0211] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for cleaning blockchain data, characterized in that: The method comprises: Determine the expired transaction tasks in the transaction cleanup tree maintained by itself; Grab a preset number of target trading tasks from the trading pool; Generate a proposal message of the new block based on the expired transaction task and the target transaction task; the proposal message carries identification information of the expired transaction task; The proposal message is broadcast to the first node in the blockchain, so that the first node reaches a consensus on the new block based on the target transaction task, and performs data cleanup based on the identification information after reaching a consensus.

2. The method according to claim 1, characterized in that The determining of expired transaction tasks in the transaction expiration tree maintained by itself includes: When constructing a new block, get the first time; Based on the first time, an expired transaction task in a transaction clearing tree maintained by itself is determined.

3. The method according to claim 1, characterized in that: The preset number is at least two; and the method further comprises: When the blockchain is started, creating the transaction cleanup tree; When the new block reaches a consensus, a root node, an intermediate node and a leaf node are created in the transaction clearing tree based on the blockchain identifiers, identification information and transaction expiration time carried by at least two of the target transaction tasks; wherein the leaf node contains the identification information of the target transaction task to be cleared; When the transaction expiration times of at least two target transaction tasks are the same, the identification information of the at least two target transaction tasks is stored in the same leaf node.

4. The method according to claim 3, characterized in that: The intermediate nodes include second-level nodes and third-level nodes; When the new block reaches a consensus, based on the blockchain identifier, identification information and transaction expiration time carried by the target transaction task, a root node, a second-level node, a third-level node and a leaf node are created in the transaction clearing tree, including: When the new block reaches a consensus, based on the blockchain identifier, identification information and transaction expiration time carried by the target transaction task, a root node with a period of days, a second-level node with a granularity of hours, a third-level node with a granularity of minutes and a leaf node corresponding to the target time represented by the third-level node are created in the transaction cleanup tree; The leaf node contains identification information of the target transaction task to be cleared by the target time.

5. The method according to claim 1, characterized in that The proposal message for generating the new block based on the expired transaction task and the target transaction task includes: Determine the expired transaction hash value according to the expired transaction identifier set; Add the expired transaction hash value to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block is the expired transaction hash value; or, The expired transaction identification set is added to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block is the expired transaction identification set.

6. The method according to claim 1, characterized in that The proposal message for generating the new block based on the expired transaction task and the target transaction task includes: Determine the expired transaction hash value according to the expired transaction identifier set; The expired transaction identification set and the expired transaction hash value are added to the block header of the new block, so that the identification information of the expired transaction task carried in the proposal message of the new block includes the expired transaction identification set and the expired transaction hash value.

7. The method according to claim 1, characterized in that The proposal message carries the first time and the expired transaction hash value; and the consensus on the new block based on the target transaction task includes: When the first node receives the proposal message, deserializes the proposal message to obtain processed proposal structure information; Acquire the first time from the proposal structure information; When the first time is legal and the expired transaction identifier set is not obtained, obtaining a local expired transaction task that meets the first time from the transaction cleanup tree maintained by the first node; Determine the hash value corresponding to the local expired transaction task; Compare the hash value with the expired transaction hash value to obtain a comparison result; When the comparison result indicates that the hash value is inconsistent with the expired transaction hash value, negative vote information is generated and broadcast to other nodes.

8. The method according to claim 7, characterized in that After comparing the hash value with the expired transaction hash value to obtain a comparison result, the method further includes: When the comparison result indicates that the hash value is consistent with the expired transaction hash value, the target transaction task is obtained from the proposal structure information, and the target transaction task is executed to obtain an execution result corresponding to the target transaction task; When the execution result is consistent with the execution result carried in the proposal message, an approval message is generated and the approval message is broadcast to the other nodes.

9. The method according to claim 7, characterized in that: After obtaining the first time from the proposal structure information, the method further includes: When the first time is legal and the expired transaction identifier set is obtained, obtaining a local expired transaction task that meets the first time from the transaction cleanup tree maintained by the first node; Verifying the expired transaction identifier set based on the local expired transaction task; When the verification passes, the step of determining the hash value corresponding to the local expired transaction task is performed.

10. The method according to claim 7, characterized in that After obtaining the first time from the proposal structure, the method further includes: When the first time does not meet the time threshold range, generating a negative vote message; The negative vote message is broadcasted to other nodes.

11. The method according to claim 1, characterized in that The reaching a consensus on the new block based on the target transaction task, and performing data cleaning based on the identification information after reaching a consensus, includes: When the first node receives the second initial voting message broadcasted by other nodes, the first node determines the first voting message based on its own first initial voting message and the second initial voting message; When the first node receives the second voting message broadcast by the other nodes, based on the first voting message and the second voting message, it is determined that the new block reaches a consensus, and the target transaction task and the execution result of the target transaction task are written into the local account book; When the block header of the new block carries an expired transaction identifier set, obtaining a corresponding transaction task according to the expired transaction identifier set; When the transaction task is in the state data deletion mode, the execution result corresponding to the transaction task is obtained from the block database, and the state data corresponding to the transaction task at the current moment is obtained from the state database; Comparing the execution result with the status data to obtain a comparison result; When the comparison result indicates that the execution result is consistent with the state data, the state data corresponding to the transaction task is deleted from the state database, and the data corresponding to the transaction task in the block database is deleted.

12. The method according to claim 11, characterized in that After comparing the execution result with the status data to obtain a comparison result, the method further includes: When the comparison result indicates that the execution result is inconsistent with the status data, the data corresponding to the transaction task in the block database is deleted.

13. A data cleaning device for blockchain, characterized in that: The device comprises: A determination module, used to determine expired transaction tasks in the transaction cleanup tree maintained by itself; The capture module is used to capture a preset number of target transaction tasks from the transaction pool; A generating module, configured to generate a proposal message of the new block based on the expired transaction task and the target transaction task; the proposal message carries identification information of the expired transaction task; The broadcast module is used to broadcast the proposal message to the first node in the blockchain, so that the first node reaches a consensus on the new block based on the target transaction task, and performs data cleanup based on the identification information after reaching a consensus.

14. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 12 are implemented.

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

16. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.