CN117390117A - Block chain-based data processing method, device, equipment and readable storage medium - Google Patents
Block chain-based data processing method, device, equipment and readable storage medium Download PDFInfo
- Publication number
- CN117390117A CN117390117A CN202311374981.1A CN202311374981A CN117390117A CN 117390117 A CN117390117 A CN 117390117A CN 202311374981 A CN202311374981 A CN 202311374981A CN 117390117 A CN117390117 A CN 117390117A
- Authority
- CN
- China
- Prior art keywords
- node
- pruning
- block
- height
- target
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000003672 processing method Methods 0.000 title claims abstract description 20
- 238000013138 pruning Methods 0.000 claims abstract description 547
- 238000013507 mapping Methods 0.000 claims abstract description 216
- 238000000034 method Methods 0.000 claims abstract description 41
- 238000012545 processing Methods 0.000 claims description 44
- 238000004590 computer program Methods 0.000 claims description 20
- 230000006870 function Effects 0.000 claims description 16
- 238000004891 communication Methods 0.000 claims description 8
- 238000010586 diagram Methods 0.000 description 8
- 230000008569 process Effects 0.000 description 8
- 238000012546 transfer Methods 0.000 description 8
- 238000012790 confirmation Methods 0.000 description 5
- 238000012217 deletion Methods 0.000 description 5
- 230000037430 deletion Effects 0.000 description 5
- 238000005516 engineering process Methods 0.000 description 5
- 230000007246 mechanism Effects 0.000 description 4
- 238000004422 calculation algorithm Methods 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- VLFZHMWZMNJMTK-UHFFFAOYSA-N CCC.CCC.CCC.CCC Chemical compound CCC.CCC.CCC.CCC VLFZHMWZMNJMTK-UHFFFAOYSA-N 0.000 description 1
- 238000007792 addition Methods 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 230000006835 compression Effects 0.000 description 1
- 238000007906 compression Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000000977 initiatory effect Effects 0.000 description 1
- 230000002045 lasting effect Effects 0.000 description 1
- 230000014759 maintenance of location Effects 0.000 description 1
- 230000008520 organization Effects 0.000 description 1
- 238000005096 rolling process Methods 0.000 description 1
- 230000002123 temporal effect Effects 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/08—Learning methods
- G06N3/082—Learning methods modifying the architecture, e.g. adding, deleting or silencing nodes or connections
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Artificial Intelligence (AREA)
- Life Sciences & Earth Sciences (AREA)
- Health & Medical Sciences (AREA)
- Biomedical Technology (AREA)
- Biophysics (AREA)
- Computational Linguistics (AREA)
- Evolutionary Computation (AREA)
- General Health & Medical Sciences (AREA)
- Molecular Biology (AREA)
- Mathematical Physics (AREA)
- Software Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application discloses a data processing method, device and equipment based on a blockchain and a readable storage medium, wherein the method comprises the following steps: determining the height of a target pruning block in M service blocks; determining a service block with the block height belonging to the target pruning block height as a target mapping block, determining a state tree node associated with the target mapping block as a comparison node, and generating a pruning mapping relation table through the mapping relation between node hash contained in the comparison node and the node height of the comparison node; generating a target pruning range based on the target pruning block height, determining a state tree node associated with the business block with the block height belonging to the target pruning range as a node to be judged, determining the target pruning node in the node to be judged according to the node height of the node to be judged and the pruning mapping relation table, and deleting the state data stored in the target pruning node. By adopting the method and the device, the consumption of the block chain state data to the storage resource and the network resource can be reduced.
Description
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a data processing method, apparatus, device and readable storage medium based on a blockchain.
Background
In the blockchain, each block contains a part of transaction and corresponding state data, at present, a blockchain archiving node or a state tree needs to store a full amount of historical state data, a large amount of storage space is occupied, the data amount of the historical state data can continuously rise along with the increase of the height of the blocks of the blockchain, huge storage resources and network resources can be consumed for storing all the state data, the synchronization speed between blockchain networks can be influenced, and the availability of the blockchain is reduced.
Disclosure of Invention
The embodiment of the application provides a data processing method, device and equipment based on a blockchain and a readable storage medium, which can reduce consumption of storage resources and network resources by blockchain state data.
An aspect of an embodiment of the present application provides a data processing method based on a blockchain, including:
according to the block heights corresponding to the M service blocks in the block chain, determining the node heights of the state tree nodes of M state trees respectively associated with the M service blocks; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs;
Determining the height of a target pruning block in M service blocks;
determining a service block with the block height belonging to the target pruning block height as a target mapping block, determining a state tree node associated with the target mapping block as a comparison node, and generating a pruning mapping relation table through the mapping relation between node hash contained in the comparison node and the node height of the comparison node;
generating a target pruning range based on the target pruning block height, determining a state tree node associated with the business block with the block height belonging to the target pruning range as a node to be judged, determining the target pruning node in the node to be judged according to the node height of the node to be judged and the pruning mapping relation table, and deleting the state data stored in the target pruning node.
Wherein determining the target pruning block height in the M service blocks comprises:
acquiring a block height error threshold, and determining a difference value between the highest block height in the M business blocks and the block height error threshold as a tolerance block height;
and determining the height of the target pruning block according to the height of the tolerance block.
Wherein determining the target pruning block height according to the tolerance block height comprises:
Acquiring rollback times of M service blocks in a rollback statistical period respectively, and if the service blocks with the rollback times being greater than a time threshold exist, determining the minimum block height in the service blocks with the rollback times being greater than the time threshold as the rollback block height;
if the rollback block height is greater than or equal to the tolerance block height, determining the tolerance block height as a target pruning block height;
if the rollback block height is less than the tolerance block height, the rollback block height is determined to be the target pruning block height.
Wherein determining the target pruning block height in the M service blocks comprises:
gradually traversing M business blocks from an originating block; the creation block is the service block with the lowest block height in the M service blocks;
when traversing to the business block with rollback, stopping traversing the business block, determining the traversed business block with rollback as a stable block, and determining the block height of the stable block as a target pruning block height.
According to the node height and pruning mapping relation table contained in the node to be determined, determining the target pruning node in the node to be determined comprises the following steps:
Traversing to obtain node hash and node height of each state tree node in the pruning mapping relation table;
if the node hash of the node to be judged is determined to be not in the pruning mapping relation table based on the traversed node hash, determining the node to be judged which is not in the pruning mapping relation table as a target pruning node;
if the node hash of the node to be judged is determined to exist in the pruning mapping relation table based on the traversed node hash, determining the node to be judged existing in the pruning mapping relation table as a height judgment node, and acquiring the node height of the height judgment node;
if the node height of the height judging node is smaller than the node height corresponding to the node hash in the pruning mapping relation table, determining the node height as the target pruning node.
According to the node height and pruning mapping relation table contained in the node to be determined, determining the target pruning node in the node to be determined comprises the following steps:
traversing to obtain node hash and node height of each state tree node in the pruning mapping relation table;
if the state tree nodes in the pruning mapping relation table have shared nodes, determining the child nodes of the shared nodes as reserved nodes; the shared node refers to a state tree node shared by state trees respectively corresponding to at least two business blocks in the M business blocks;
And determining the node to be determined which does not belong to the reserved node in the nodes to be determined as the target pruning node.
Wherein, still include:
when N updating blocks are newly added in the block chain, determining the block heights corresponding to the N updating blocks as the node heights of the state tree nodes of the state tree respectively associated with the N updating blocks; n is a positive integer;
determining the height of an updated pruning block in the N updating blocks;
determining an update block with the block height belonging to the update pruning height as an update mapping block, determining a state tree node associated with the update mapping block as an update comparison node, and generating an update pruning mapping relation table through a mapping relation between node hash contained in the update comparison node and the node height of the update comparison node;
generating an updated pruning range based on the target pruning block height and the updated pruning block height, determining a service block with the block height belonging to the updated pruning range and a state tree node associated with the updated block as an updated node to be determined, determining the updated pruning node in the updated node to be determined according to the node height of the updated node to be determined and the updated pruning mapping relation table, and deleting the state data stored in the updated pruning node.
Wherein generating an updated pruning scope based on the target pruning block height and the updated pruning block height, comprises:
and determining the target pruning block height as a first interval value, determining the updated pruning block height as a second interval value, and generating an updated pruning range based on the first interval value and the second interval value.
Wherein, prior to the step of deleting the state data stored in the target pruning node, the method further comprises:
generating a data snapshot from the state data stored in the target pruning node; the data snapshot is used for querying historical state data of the target pruning node.
Wherein deleting the state data stored in the target pruning node comprises:
determining a state tree node connected with the target pruning node as an associated state node; the state data of the target pruning node and the state data of the associated state node comprise target data, the state data of the target pruning node also comprises associated data, the target data of the target pruning node is data required by the target pruning node to participate in the consensus, the target data of the associated state node is data required by the associated state node to participate in the consensus, and the associated data is data stored by the target pruning node for maintaining the associated state node;
And deleting the associated data stored by the target pruning node and the target data stored by the associated state node.
An aspect of an embodiment of the present application provides a data processing apparatus based on a blockchain, including:
the node height determining module is used for determining node heights of state tree nodes of M state trees respectively associated with the M service blocks according to block heights respectively corresponding to the M service blocks in the block chain; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs;
the pruning height processing module is used for determining the height of a target pruning block in M business blocks;
the mapping table generation module is used for determining a service block with the block height belonging to the target pruning block height as a target mapping block, determining a state tree node associated with the target mapping block as a comparison node, and generating a pruning mapping relation table through the mapping relation between node hash contained in the comparison node and the node height of the comparison node;
the judging processing module is used for generating a target pruning range based on the height of the target pruning block, determining the state tree node associated with the business block with the block height belonging to the target pruning range as a node to be judged, determining the target pruning node in the node to be judged according to the node height of the node to be judged and the pruning mapping relation table, and deleting the state data stored in the target pruning node.
Wherein, pruning height processing module includes:
the fault-tolerant height determining unit is used for obtaining a block height error threshold value and determining the difference value between the highest block height in the M business blocks and the block height error threshold value as a tolerance block height;
and the pruning height determining unit is used for determining the target pruning block height according to the tolerance block height.
Wherein, pruning height determination unit includes:
a rollback height determining subunit, configured to obtain rollback times of the M service blocks in the rollback statistics period, and determine, if there are service blocks with rollback times greater than the time threshold, a minimum block height in the service blocks with rollback times greater than the time threshold as a rollback block height;
a height selection subunit, configured to determine the tolerance block height as the target pruning block height if the rollback block height is greater than or equal to the tolerance block height;
the height selection subunit is further configured to determine the rollback block height as the target pruning block height if the rollback block height is less than the tolerance block height.
Wherein, pruning height processing module includes:
the rollback traversing unit is used for traversing the M business blocks step by step from the creation block; the creation block is the service block with the lowest block height in the M service blocks;
And the stable block processing unit is used for stopping traversing the business blocks when traversing to the business blocks with rollback, determining the traversed business blocks with rollback as stable blocks, and determining the block height of the stable blocks as the target pruning block height.
Wherein, judge processing module includes:
the first judging traversing unit is used for traversing and acquiring node hash and node height of each state tree node in the pruning mapping relation table;
a first decision selecting unit, configured to determine, if it is determined based on the traversed node hash that the node hash of the node to be determined does not exist in the pruning mapping relationship table, the node to be determined that does not exist in the pruning mapping relationship table as a target pruning node;
the first judging and selecting unit is further used for determining the node to be judged in the pruning mapping relation table as the height judging node and acquiring the node height of the height judging node if the node hash of the node to be judged is determined to exist in the pruning mapping relation table based on the traversed node hash;
the first decision selecting unit is further configured to determine, as the target pruning node, a height decision node whose node height is smaller than the node height in the pruning mapping relationship table if the node height of the height decision node is smaller than the node height corresponding to the node hash in the pruning mapping relationship table.
Wherein, judge processing module includes:
the second judging traversing unit is used for traversing and acquiring node hash and node height of each state tree node in the pruning mapping relation table;
the second judging and selecting unit is used for determining the child node of the shared node as a reserved node if the shared node exists in the state tree nodes in the pruning mapping relation table; the shared node refers to a state tree node shared by state trees respectively corresponding to at least two business blocks in the M business blocks;
and the second judging and selecting unit is used for determining the node to be judged which does not belong to the reserved node in the nodes to be judged as the target pruning node.
Wherein, still include:
the updating height determining module is used for determining the block heights corresponding to the N updating blocks respectively as the node heights of the state tree nodes of the state tree respectively associated with the N updating blocks when N updating blocks are newly added in the block chain; n is a positive integer;
the updating height processing module is used for determining the updating pruning block height in the N updating blocks;
the updating mapping generation module is used for determining an updating block with the block height belonging to the updating pruning height as an updating mapping block, determining a state tree node associated with the updating mapping block as an updating comparison node, and generating an updating pruning mapping relation table through the mapping relation between node hash contained in the updating comparison node and the node height of the updating comparison node;
The updating judgment processing module is used for generating an updating pruning range based on the target pruning block height and the updating pruning block height, determining a business block with the block height belonging to the updating pruning range and a state tree node associated with the updating block as a node to be judged, determining the updating pruning node in the node to be judged according to the node height of the node to be judged and the updating pruning mapping relation table, and deleting the state data stored in the updating pruning node.
The updating judgment processing module is specifically configured to determine the target pruning block height as a first interval value, determine the updating pruning block height as a second interval value, and generate an updating pruning range based on the first interval value and the second interval value.
Wherein, still include:
the data snapshot module is used for generating a data snapshot through the state data stored in the target pruning node; the data snapshot is used for querying historical state data of the target pruning node.
Wherein the update determination processing module includes:
the data confirmation unit is used for determining the state tree node connected with the target pruning node as an associated state node; the state data of the target pruning node and the state data of the associated state node comprise target data, the state data of the target pruning node also comprises associated data, the target data of the target pruning node is data required by the target pruning node to participate in the consensus, the target data of the associated state node is data required by the associated state node to participate in the consensus, and the associated data is data stored by the target pruning node for maintaining the associated state node;
And the data deleting unit is used for deleting the associated data stored by the target pruning node and the target data stored by the associated state node.
In one aspect, a computer device is provided, including: a processor, a memory, and a network interface;
the processor is connected with the memory and the network interface, wherein the network interface is used for providing a data communication function, the memory is used for storing a computer program, and when the computer program is executed by the processor, the computer device is caused to execute the method provided by the embodiment of the application.
In one aspect, the present application provides a computer readable storage medium storing a computer program adapted to be loaded and executed by a processor, so that a computer device having the processor performs the method provided in the embodiments of the present application.
In one aspect, the present application provides a computer program product comprising a computer program stored on a computer readable storage medium. The processor of the computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the method provided in the embodiment of the present application.
According to the embodiment of the application, the corresponding node heights are distributed for the state tree nodes of the state tree associated with the business block, the pruning mapping relation table is generated through the node hash and the node heights contained in the state tree nodes associated with the target pruning block, the target pruning range is generated based on the target pruning block heights, all the state tree nodes associated with the business block in the target pruning range are determined to be the nodes to be judged, the pruning mapping relation table is traversed, and the target pruning nodes needing pruning are determined through the comparison of the node hash and the node heights in the nodes to be judged and the node hash and the node heights of the pruning mapping relation table, so that range pruning is possible. Pruning of the blockchain state tree may remove invalid or attacked state tree nodes, thereby reducing potential security risks. Only valid and valuable nodes are reserved, and the security of the whole blockchain system can be enhanced. Pruning of the blockchain state tree may remove invalid or outdated state nodes, thereby reducing memory space usage. Redundant nodes in the state tree are removed, thereby reducing the time and resource overhead of querying and validating. The pruned state tree is more compact, so that related operations are more efficient, and consumption of the blockchain state data on storage resources and network resources can be reduced.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of a blockchain network according to an embodiment of the present disclosure;
FIG. 2 is a schematic diagram of a data processing scenario based on a blockchain according to an embodiment of the present application;
FIG. 3 is a flowchart illustrating a block chain based data processing method according to an embodiment of the present application;
FIG. 4 is a second flow chart of a block chain based data processing method according to an embodiment of the present application;
FIG. 5 is a schematic diagram of a block chain based data processing apparatus according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, are intended to be within the scope of the present application.
Blockchains are the carrier and organization of the way the blockchain technology is run. The blockchain technique (Blockchain technology, BT), also known as the distributed ledger technique, is an internet database technique that features decentralization, transparent disclosure, and allows everyone to participate in database records. Blockchain technology is a distributed infrastructure and computing method that uses a blockchain data structure to verify and store data, a distributed node consensus algorithm to generate and update data, cryptography to secure data transmission and access, and intelligent contracts composed of automated script code to program and manipulate data.
For ease of understanding, the blockchain and its related concepts will be described as follows:
1. blockchain (Block chain): in a narrow sense, the blockchain is a chain data structure taking a block as a basic unit, and the block uses a digital abstract to verify the transaction history acquired before, so that the blockchain is suitable for the requirements of tamper resistance and expandability in a distributed accounting scene; in a broad sense, blockchain also refers to distributed accounting techniques implemented by blockchain structures, including distributed consensus, privacy and security protection, point-to-point communication techniques, network protocols, smart contracts, and the like.
The goal of the blockchain is to implement a distributed data logging ledger that allows only additions and not deletions. The basic structure of the ledger floor is a linear linked list. The linked list is formed by serially connecting blocks, the Hash value of the preceding block is recorded in the following blocks, and whether each block (and the transaction in the block) is legal or not can be rapidly checked by calculating the Hash value. If a node in the network proposes to add a new block, a consensus acknowledgement must be made for the block via a consensus mechanism.
2. Block (block): the data packet carrying transaction data on the blockchain network is a data structure marked with a timestamp and a hash value corresponding to a preceding block, and the block verifies and confirms the transaction in the block through a consensus mechanism of the network. The Block includes a Block Header (Block Header) and a Block Body (Block Body), where the Block Header can record meta information of the current Block and includes data such as a current version number, a hash value corresponding to a previous Block, a timestamp, a random number, a hash value of a Merkle Root (Merkle Root), and the like. The block may record detailed data generated over a period of time, including all transaction records or other information generated during the creation of the block for which the current block is verified, and may be understood as a representation of the ledger. In addition, the detailed data of the block may include generating a unique Merkle Root record in the block header through a hash process of a Merkle Tree (Merkle Tree).
The successor Block, also called Parent Block (Parent Block), is a Block chain that performs temporal ordering by recording the hash value corresponding to the Block and the hash value corresponding to the Parent Block in the Block header.
3. Hash value (hash): also called information characteristic value or eigenvalue, hash value is generated by converting input data of arbitrary length into a password by hash algorithm and performing fixed output, and original input data cannot be retrieved by decrypting the hash value, which is a one-way encryption function. In a blockchain, each block (except the initial block) contains a hash value of the successor block, which is the potential core foundation and most important aspect in blockchain technology, which preserves the authenticity of the recorded and viewed data, as well as the integrity of the blockchain as a whole.
4. Smart Contract: the concept of intelligent contracts has three major elements of commitment, agreement and digital form, so that the application range of the blockchain can be expanded to all links of transaction, payment, settlement and clearing in the financial industry. Intelligent contracts refer to the immediate execution of corresponding contract terms when a pre-programmed condition is triggered, the working principle of which is similar to the if-then statement of a computer program.
Referring to fig. 1, fig. 1 is a schematic structural diagram of a blockchain network according to an embodiment of the present application. The blockchain network as shown in fig. 1 may include, but is not limited to, a blockchain network to which the federated chain corresponds. The blockchain network may include a plurality of blockchain nodes, and the plurality of blockchain nodes may include a blockchain node 10a, a blockchain node 10b, a blockchain node 10c, a blockchain node 10d, …, and a blockchain node 10n. Each blockchain node can receive data sent by the outside during normal operation, perform blockchain uplink processing based on the received data, and also can send the data to the outside. To ensure data interworking between the various blockchain nodes, a data connection may exist between each blockchain node, such as between blockchain node 10a and blockchain node 10b, between blockchain node 10a and blockchain node 10c, and between blockchain node 10b and blockchain node 10 c.
It will be appreciated that data or block transfer may be performed between the blockchain nodes via the data connections described above. The blockchain network can realize data connection among the blockchain nodes based on the node identifiers, each blockchain node in the blockchain network has the corresponding node identifier, and each blockchain node can store the node identifiers of other blockchain nodes connected with the blockchain network so as to broadcast acquired data or generated blocks to other blockchain nodes according to the node identifiers of other blockchain nodes.
For example, the blockchain node 10a may maintain a node identifier list as shown in table 1, where the node identifier list stores node names and node identifiers of other nodes:
TABLE 1
Node name | Node identification |
Node 10a | AAA.AAA.AAA.AAA |
Node 10b | BBB.BBB.BBB.BBB |
Node 10c | CCC.CCC.CCC.CCC |
Node 10d | DDD.DDD.DDD.DDD |
… | … |
Node 10n | EEE.EEE.EEE.EEE |
The node identifier may be any of a protocol (Internet Protocol, IP) address for interconnection between networks, and any other information that can be used to identify a node in a blockchain network, and the IP address is only illustrated in table 1. For example, the blockchain node 10a may send information (e.g., a block) to the blockchain node 10b through the node identification bbb.bbb.bbb.bbb.bbb, and the blockchain node 10b may determine that the information was sent by the blockchain node 10a through the node identification aaa.aaa.aaa.
In a blockchain, a block must be consensus-passed through consensus nodes in the blockchain network before the block is uplink, and the block can be added to the blockchain after the consensus passes. It will be appreciated that when a blockchain is used in some contexts of a government or commercial establishment, not all participating nodes in the blockchain (i.e., blockchain nodes in the blockchain network described above) have sufficient resources and necessity to become consensus nodes of the blockchain. For example, in the blockchain network shown in fig. 1, blockchain node 10a, blockchain node 10b, blockchain node 10c, and blockchain node 10d may be considered as consensus nodes in the blockchain network. The consensus nodes in the blockchain network participate in consensus, namely, consensus is carried out on the blocks (comprising a batch of transactions), namely, voting is carried out on the blocks; while non-consensus nodes do not participate in consensus, but will help propagate block and vote messages, and synchronize status with each other, etc.
It will be appreciated that when the blockchain network employs a bayer consensus mechanism to achieve the consensus of the blocks, the assembly of the blocks and initiation of the consensus is typically done by the master node (also referred to as the out-block node). In this embodiment of the present application, the blockchain network as shown in fig. 1 may implement block consensus using a bayer consensus mechanism, and at this time, the blockchain node with the consensus function, for example, the blockchain node 10a, needs to determine the master node corresponding to the block corresponding to the next block height after determining that the block uplink of the current block height is successful, so as to complete the consensus operation for the block of the next block height.
Specifically, the blockchain node 10a may determine the block height corresponding to the service block in the blockchain as the node height of the state tree node in the state tree of the service block. For example, the block height of traffic block 1 is 500, then the node height of each state tree node in the state tree associated with traffic block 1 is 500.
Wherein the state tree may be a merck prefix tree (Merkle Patricia Tree, MPT), and the blockchain node may store state data (e.g., transaction information, transfer data, etc.) through state tree nodes of the merck prefix tree. The state tree nodes in each state tree contain node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs.
State data of a blockchain state tree may refer to state information of all accounts in the blockchain, including balances of the accounts, contract codes, stored data, and the like. The state data is organized into a tree structure, each node representing an account or contract, and the nodes are connected by parent-child relationships. The root node of the state tree may store global state information for the current blockchain.
The blockchain node 10a may determine the target pruning block height in the blockchain, where the target pruning block height may be determined by a difference between a highest block height in the blockchain and a block height error threshold (which may be a statistically derived error value), or may be determined by a number of rollbacks in a rollback statistical period, which embodiments of the present application are not limited herein.
The rollback in the blockchain (also referred to as soft bifurcation, blockchain reconstruction) refers to that the consistency of the blockchain storage records is affected by the generation of new blocks or new chains on the old chains due to the modification of data (such as transaction information, transfer records, etc.) in the blockchain.
The blockchain node 10a may determine a service block whose block height belongs to the target pruning block height as a target mapping block, determine a state tree node associated with the target mapping block as a comparison node, and generate a pruning mapping relationship table by comparing a mapping relationship between node hashes and node heights included in the nodes.
The blockchain node 10a may generate a target pruning range by using the target pruning block height, and determine a state tree node associated with a service block whose block height belongs to the target pruning range as a node to be determined.
The blockchain node 10a may traverse the pruning mapping relationship table, determine the target pruning node from the nodes to be determined through the node hash and the node height in the pruning mapping relationship table, and the blockchain node 10a may delete the state data stored in the target pruning node.
According to the embodiment of the application, the corresponding node heights are distributed for the state tree nodes of the state tree associated with the business block, the pruning mapping relation table is generated through the node hash and the node heights contained in the state tree nodes associated with the target pruning block, the target pruning range is generated based on the target pruning block heights, all the state tree nodes associated with the business block in the target pruning range are determined to be the nodes to be judged, the pruning mapping relation table is traversed, and the target pruning nodes needing pruning are determined through the comparison of the node hash and the node heights in the nodes to be judged and the node hash and the node heights of the pruning mapping relation table, so that range pruning is possible. Pruning of the blockchain state tree may remove invalid or attacked state tree nodes, thereby reducing potential security risks. Only valid and valuable nodes are reserved, and the security of the whole blockchain system can be enhanced. Pruning of the blockchain state tree may remove invalid or outdated state nodes, thereby reducing memory space usage. Redundant nodes in the state tree are removed, thereby reducing the time and resource overhead of querying and validating. The pruned state tree is more compact, so that related operations are more efficient, and consumption of the blockchain state data on storage resources and network resources can be reduced.
Fig. 2 is a schematic diagram of a data processing method based on a blockchain according to an embodiment of the present application.
As shown in fig. 2, the blockchain node 10a may determine the block height corresponding to a service block in the blockchain as the node height of the state tree node in the state tree of the service block.
Wherein, the state tree may be a merck prefix tree, and the block link points may store state data (such as transaction information, transfer data, etc.) through state tree nodes of the merck prefix tree. The state tree nodes in each state tree contain node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs.
State data of a blockchain state tree may refer to state information of all accounts in the blockchain, including balances of the accounts, contract codes, stored data, and the like. The state data is organized into a tree structure, each node representing an account or contract, and the nodes are connected by parent-child relationships. The root node of the state tree may store global state information for the current blockchain.
For example, the block height of traffic block 1 is 500, then the node height of each state tree node (which may include state tree node 1, state tree node 2, state tree node 3, state tree node 4, state tree node 5, state tree node 6, and state tree node 7) in the state tree associated with traffic block 1 is 500.
The blockchain node 10a may determine the target pruning block height in the blockchain, where the target pruning block height may be determined by a difference between a highest block height in the blockchain and a block height error threshold (which may be a statistically derived error value), or may be determined by a number of rollbacks in a rollback statistical period, which embodiments of the present application are not limited herein.
The rollback in the blockchain (also referred to as soft bifurcation, blockchain reconstruction) refers to that the consistency of the blockchain storage records is affected by the generation of new blocks or new chains on the old chains due to the modification of data (such as transaction information, transfer records, etc.) in the blockchain.
For example, the blockchain node 10a may obtain the number of rollbacks of the traffic blocks in the rollback statistics period, gradually traverse the traffic blocks from the originating block, if the number of rollbacks of the subsequent blocks is 0, continue to gradually traverse the traffic blocks, stop traversing the traffic blocks when traversing to the traffic block having rollbacks, determine the traversed traffic block having rollbacks as a stable block, and determine the block height of the stable block as the target pruning block height.
The creation block refers to the block with the lowest block height in the service block.
The blockchain node 10a may determine a traffic block with a block height that belongs to the target prune block height as the target map block, e.g., traffic block 2, and the block height of traffic block 2 may be 505.
The blockchain node 10a may determine the state tree node associated with the target mapping block as an alignment node, and the state tree nodes associated with the traffic block 2 may include state tree node 2, state tree node 3, state tree node 4, state tree node 8, state tree node 9, state tree node 10, and state tree node 11
The blockchain node 10a may generate a pruning mapping table by comparing the mapping between the node hash and the node height contained in the node. The pruning mapping relationship table may be as shown in table 2:
TABLE 2
The node hash of the state tree node 2 is the node hash 2, the node hash of the state tree node 3 is the node hash 3, the node hash of the state tree node 4 is the node hash 4, the node hash of the state tree node 8 is the node hash 8, the node hash of the state tree node 9 is the node hash 9, the node hash of the state tree node 10 is the node hash 10, and the node hash of the state tree node 11 is the node hash 11. Node height 2, node height 3, node height 4, node height 8, node height 9, node height 10 and node height 11 may be the same as the block height of traffic block 2, and state tree node 2, state tree node 3 and state tree node 4 may be state tree nodes common to traffic block 1 and traffic block 2.
The blockchain node 10a may generate a target pruning range through the target pruning block height, e.g., the target pruning range may be represented as a section 0,505, i.e., the target pruning range may not include the state tree nodes of the state tree associated with traffic block 2.
The blockchain node 10a may determine a state tree node associated with a traffic block whose blockheight falls within the target pruning range as the node to be determined. For example, traffic block 1 of block height data 500 is in the target pruning range, then blockchain node 10a may determine each state tree node (which may include state tree node 1, state tree node 2, state tree node 3, state tree node 4, state tree node 5, state tree node 6, and state tree node 7) in the state tree associated with traffic block 1 as a node to be determined.
The blockchain node 10a may traverse the node hash and the node height of each state tree node in the pruning mapping relationship table, and if the state tree node in the pruning mapping relationship table has a shared node, the blockchain node 10a may determine a child node of the shared node as a reserved node.
The shared node refers to a state tree node shared by state trees corresponding to a plurality of service blocks respectively. The shared node may be determined by calling information, and embodiments of the present application are not limited herein.
For example, the blockchain node 10a may determine that the state tree node 2 in the pruning mapping table is a shared node by calling the information, and then the blockchain node 10a may determine the child nodes (state tree node 3 and state tree node 4) of the state tree node 2 as reserved nodes.
The blockchain node 10a may determine a node to be determined, which does not belong to the reserved node, among the nodes to be determined as the target pruning node.
The blockchain node 10a may further determine the node to be determined after determining the reserved node, and if the node hash of the node to be determined does not exist in the node hash traversed by the pruning mapping table, that is, the node hash of the node to be determined does not exist in the pruning mapping table, the blockchain node 10a may determine the node to be determined that does not exist in the pruning mapping table as the target pruning node. For example, the node hash 5 of the state tree node 5 is not present in the pruning mapping table, the blockchain node 10a may determine that the state tree node 5 is the target pruning node.
If the node hash of the node to be determined exists in the node hash traversed by the pruning mapping relation table, the blockchain node 10a may determine the node to be determined existing in the pruning mapping relation table as the height determination node, and acquire the node height of the height determination node;
If the node height of the height determination node is less than the node height corresponding to the node hash in the pruning mapping relationship table, the blockchain node 10a may determine the node height as the target pruning node as the height determination node having the node height less than the node height in the pruning mapping relationship table.
For example, the node hash 9 of the state tree node 5 may be the same as the node hash 9 of the state tree node 9, then the blockchain node 10a may determine that the node height 5 of the state tree node 5 is 505, where the node height 5 is 500 less than the node height 9, and the blockchain node 10a may determine the state tree node 5 as the target pruning node.
It can be understood that when determining the target pruning node, the embodiment of the application determines the sharing node in the pruning mapping table, determines the child node of the sharing node as the reserved node, avoids deleting the child node of the sharing node, determines the node hash and the node height of the node to be determined, and avoids the possibility that the node hash may have the same as the node hash and the node height in the pruning mapping table, thereby causing the wrong node to be determined to be reserved and improving the accuracy and feasibility of range pruning.
The blockchain node 10a may delete the state data stored in the target pruning node.
According to the embodiment of the application, the corresponding node heights are distributed for the state tree nodes of the state tree associated with the business block, the pruning mapping relation table is generated through the node hash and the node heights contained in the state tree nodes associated with the target pruning block, the target pruning range is generated based on the target pruning block heights, all the state tree nodes associated with the business block in the target pruning range are determined to be the nodes to be judged, the pruning mapping relation table is traversed, and the target pruning nodes needing pruning are determined through the comparison of the node hash and the node heights in the nodes to be judged and the node hash and the node heights of the pruning mapping relation table, so that range pruning is possible. Pruning of the blockchain state tree may remove invalid or attacked state tree nodes, thereby reducing potential security risks. Only valid and valuable nodes are reserved, and the security of the whole blockchain system can be enhanced. Pruning of the blockchain state tree may remove invalid or outdated state nodes, thereby reducing memory space usage. Redundant nodes in the state tree are removed, thereby reducing the time and resource overhead of querying and validating. The pruned state tree is more compact, so that related operations are more efficient, and consumption of the blockchain state data on storage resources and network resources can be reduced.
Referring to fig. 3, fig. 3 is a flowchart illustrating a blockchain-based data processing method according to an embodiment of the present application, where the blockchain-based data processing method may be performed by a blockchain node, and the blockchain node may be the blockchain node 10a shown in fig. 1. The present data processing method will be described below by taking the block link point execution as an example. The data processing method based on the blockchain at least comprises the following steps of S101 to S104:
step S101, determining node heights of state tree nodes of M state trees respectively associated with M service blocks according to block heights respectively corresponding to M service blocks in a block chain; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs;
specifically, the blockchain node may determine the block height corresponding to the service block in the blockchain as the node height of the state tree node in the state tree of the service block.
The state tree may be a merck prefix tree, which is a compression dictionary tree combining the advantages of the prefix tree and the merck tree, and may efficiently and safely verify the content of the data structure. The blockchain node may store status data (e.g., transaction information, transfer data, etc.) through a status tree node of the merck prefix tree. The state tree nodes in each state tree contain node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs.
State data of a blockchain state tree may refer to state information of all accounts in the blockchain, including balances of the accounts, contract codes, stored data, and the like. The state data is organized into a tree structure, each node representing an account or contract, and the nodes are connected by parent-child relationships. The root node of the state tree may store global state information for the current blockchain.
For example, the block height of traffic block 1 is 500, then the node height of each state tree node in the state tree associated with traffic block 1 is 500.
Step S102, determining the height of a target pruning block in M business blocks;
specifically, the blockchain node may determine a target pruning block height in the blockchain. The target pruning block height may be determined by the highest block height in the blockchain and the block height error threshold, and the process may be: acquiring a block height error threshold, and determining a difference value between the highest block height in the M business blocks and the block height error threshold as a tolerance block height; and determining the height of the target pruning block according to the height of the tolerance block.
Specifically, the blockchain node may obtain a blockheight error threshold, where the blockheight error threshold may be an error value obtained through statistical data, that is, in a certain blockheight period (for example, blockheight 1000), a service block generated recently at the blockheight error threshold (which may be 50) may roll back.
The rollback in the blockchain (also referred to as soft bifurcation, blockchain reconstruction) refers to that the consistency of the blockchain storage records is affected by the generation of new blocks or new chains on the old chains due to the modification of data (such as transaction information, transfer records, etc.) in the blockchain.
The blockchain node may determine the difference between the highest block height (e.g., 1000) in the traffic block and the block height error threshold (e.g., 50) as the tolerance block height, i.e., the tolerance block height is 950.
The block link point can determine the target pruning block height by the tolerance block height, which can be as follows: acquiring rollback times of M service blocks in a rollback statistical period respectively, and if the service blocks with the rollback times being greater than a time threshold exist, determining the minimum block height in the service blocks with the rollback times being greater than the time threshold as the rollback block height; if the rollback block height is greater than or equal to the tolerance block height, determining the tolerance block height as a target pruning block height; if the rollback block height is less than the tolerance block height, the rollback block height is determined to be the target pruning block height.
Specifically, the blockchain node may obtain the rollback times of the service blocks in the blockchain in the rollback statistics period, where the rollback statistics period may be a time period (for example, every three months), or may be a block height period (for example, every 1000 newly added service blocks in the blockchain).
If the service blocks with the rollback times larger than the times threshold exist, the minimum block height in the service blocks with the rollback times larger than the times threshold is determined as the rollback block height.
The number threshold, that is, the number of rollbacks allowed in the blockchain in the rollback statistics period, may be, for example, 2 times.
The block link points may determine the target pruning block height by rolling back the block height and the tolerance block height.
If the rollback block height is greater than or equal to the tolerance block height, determining the tolerance block height as a target pruning block height;
if the rollback block height is less than the tolerance block height, the rollback block height is determined to be the target pruning block height.
That is, the blockchain node may determine the lesser of the rollback block height and the tolerance block height as the target pruning block height, improving the fault tolerance of the target pruning block height determination, and improving the feasibility of range pruning of the blockchain state tree.
Optionally, the blockchain node may further determine the target pruning block height by using the number of rollbacks in the rollback statistics period, and the process may be: gradually traversing M business blocks from an originating block; the creation block is the service block with the lowest block height in the M service blocks; when traversing to the business block with rollback, stopping traversing the business block, determining the traversed business block with rollback as a stable block, and determining the block height of the stable block as a target pruning block height.
Specifically, the blockchain node may acquire the rollback times of the service blocks in the rollback statistics period, gradually traverse the service blocks from the originating block, if the rollback times of the subsequent blocks are 0, continue to gradually traverse the service blocks, stop traversing the service blocks when traversing the rollback service blocks, determine the traversed rollback service blocks as stable blocks, and determine the block heights of the stable blocks as target pruning block heights.
The creation block refers to the block with the lowest block height in the service block.
Step S103, determining a service block with the block height belonging to the target pruning block height as a target mapping block, determining a state tree node associated with the target mapping block as a comparison node, and generating a pruning mapping relation table through the mapping relation between node hash contained in the comparison node and the node height of the comparison node;
specifically, the blockchain node may determine a service block whose block height belongs to the target pruning block height as a target mapping block, determine a state tree node associated with the target mapping block as a comparison node, and generate a pruning mapping relationship table through a mapping relationship between node hashes and node heights included in the comparison node.
Step S104, a target pruning range is generated based on the target pruning block height, the state tree nodes associated with the business blocks with the block height belonging to the target pruning range are determined as nodes to be judged, the target pruning nodes are determined in the nodes to be judged according to the node heights of the nodes to be judged and the pruning mapping relation table, and the state data stored in the target pruning nodes are deleted.
Specifically, the block link points may generate a target pruning range through a target pruning block height, which may be expressed as a bin. The base may be a pruning block height determined at the time of pruning last time, and the base may be 0 at the time of pruning first time. target is the target pruning block height.
The blockchain node may determine a state tree node associated with the traffic block whose blockheight belongs to the target pruning range as the node to be determined.
The blockchain node may traverse the pruning mapping relationship table, determine the target pruning node in the nodes to be determined through the node hash and the node height in the pruning mapping relationship table, and the blockchain node 10a may delete the state data stored in the target pruning node.
According to the embodiment of the application, the node heights of the state tree nodes of M state trees respectively associated with the M service blocks are determined according to the block heights respectively corresponding to the M service blocks in the block chain; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs; determining the height of a target pruning block in M service blocks; determining a service block with the block height belonging to the target pruning block height as a target mapping block, determining a state tree node associated with the target mapping block as a comparison node, and generating a pruning mapping relation table through the mapping relation between node hash contained in the comparison node and the node height of the comparison node; generating a target pruning range based on the target pruning block height, determining a state tree node associated with the business block with the block height belonging to the target pruning range as a node to be judged, determining the target pruning node in the node to be judged according to the node height of the node to be judged and the pruning mapping relation table, and deleting the state data stored in the target pruning node. It can be seen that, in the embodiment of the present application, by allocating the corresponding node heights to the state tree nodes of the state tree associated with the service block, generating the pruning mapping relation table by using the node hash and the node height included in the state tree node associated with the target pruning block height, generating the target pruning range based on the target pruning block height, determining all the state tree nodes associated with the service block in the target pruning range as the nodes to be determined, traversing the pruning mapping relation table, and comparing the node hash and the node height in the node to be determined with the node hash and the node height of the pruning mapping relation table, to determine the target pruning node needing pruning, so that range pruning becomes possible. Pruning of the blockchain state tree may remove invalid or attacked state tree nodes, thereby reducing potential security risks. Only valid and valuable nodes are reserved, and the security of the whole blockchain system can be enhanced. Pruning of the blockchain state tree may remove invalid or outdated state nodes, thereby reducing memory space usage. Redundant nodes in the state tree are removed, thereby reducing the time and resource overhead of querying and validating. The pruned state tree is more compact, so that related operations are more efficient, and consumption of the blockchain state data on storage resources and network resources can be reduced.
Referring to fig. 4, fig. 4 is a second flowchart of a blockchain-based data processing method according to an embodiment of the present application, where the blockchain-based data processing method may be performed by a resource client, and the resource client may be the terminal device 200 shown in fig. 1. The present data processing method will be described below as an example of execution by a resource client. The data processing method based on the blockchain at least comprises the following steps of S201 to S208:
step S201, determining node heights of state tree nodes of M state trees respectively associated with M service blocks according to block heights respectively corresponding to M service blocks in a block chain; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs;
specifically, reference may be made to the corresponding specific description of step S101 in the embodiment of fig. 3.
Step S202, determining the height of a target pruning block in M business blocks;
specifically, reference may be made to the specific description corresponding to step S102 in the embodiment of fig. 3.
Step S203, a business block with the block height belonging to the target pruning block height is determined as a target mapping block, a state tree node associated with the target mapping block is determined as a comparison node, and a pruning mapping relation table is generated through the mapping relation between node hash contained in the comparison node and the node height of the comparison node;
Specifically, the blockchain node may determine a traffic block whose block height belongs to the target pruning block height as the target mapping block. The target pruning block height may also be referred to as target.
For example, for the target mapping block to be traffic block a, the target pruning block height may be 950. Traffic block a may include state tree node 1, state tree node 2, state tree node 3, state tree node 4, and state tree node 5, then the node heights of state tree node 1, state tree node 2, state tree node 3, state tree node 4, and state tree node 5 may all be 950.
The blockchain node can generate a pruning mapping relation table by comparing the mapping relation between node hash and node height contained in the node, and the pruning mapping relation table can be called as map. The pruning mapping relation table may include node heights and node hashes corresponding to the state tree nodes respectively, for example, the state tree node 1 includes the node hash 1 and the node height 1, and the state tree node 2 includes the node hash 2 and the node height 2.
The pruning mapping relation table of the service block a may be as shown in table 3:
TABLE 3 Table 3
The node hash of the state tree node 1 is the node hash 1, the node hash of the state tree node 2 is the node hash 2, the node hash of the state tree node 3 is the node hash 3, the node hash of the state tree node 4 is the node hash 4, and the node hash of the state tree node 5 is the node hash 5. Node height 1, node height 2, node height 3, node height 4, and node height 5 may be the same as the block height of traffic block a. The state tree node 1 in the pruning mapping relation table may be a shared node, and the child nodes of the state tree node 1 include a state tree node 6 and a state tree node 7.
The storage and traversal of the pruning mapping relation table can be realized by using a Level database (Level Data Base), wherein the Level database is a sustainable key value database, and the random writing of a disk is converted into sequential writing by utilizing the characteristic that the sequential writing performance of the disk is far greater than that of random writing and adopting an LSM-Tree (Log Structured-Merge Tree) structure, so that the writing speed is greatly improved. Keys (keywords) in the level db may also be a character string obtained by combining node hash and node height, which is not limited in this embodiment of the present application. The LevelDB can store state data in a lasting mode, meanwhile, the state data can be cached in a memory, quick reading is achieved, and the range pruning efficiency of the blockchain state data can be improved.
Step S204, a target pruning range is generated based on the target pruning block height, the state tree nodes associated with the business blocks with the block height belonging to the target pruning range are determined as nodes to be judged, the target pruning nodes are determined in the nodes to be judged according to the node heights of the nodes to be judged and the pruning mapping relation table, and the state data stored in the target pruning nodes are deleted.
Specifically, the block link points may generate a target pruning range through a target pruning block height, which may be expressed as a bin. The base may be a pruning block height determined at the time of pruning last time, and the base may be 0 at the time of pruning first time. target is the target pruning block height.
For example, the target pruning scope may be represented as a section [0,950 ], i.e. the target pruning scope may not include the state tree nodes of the state tree associated with traffic block a.
The blockchain node may determine a state tree node associated with the traffic block whose blockheight belongs to the target pruning range as the node to be determined.
For example, traffic block B of block height data 900 is in target pruning range 0,950), then the blockchain node may determine each state tree node (which may include state tree node 6, state tree node 7, state tree node 8, and state tree node 9) in the state tree associated with traffic block B as a node to be determined.
The blockchain may determine the shared node in the pruning mapping table first, and then determine the target pruning node, and the process may be: traversing to obtain node hash and node height of each state tree node in the pruning mapping relation table; if the state tree nodes in the pruning mapping relation table have shared nodes, determining the child nodes of the shared nodes as reserved nodes; the shared node refers to a state tree node shared by state trees respectively corresponding to at least two business blocks in the M business blocks; and determining the node to be determined which does not belong to the reserved node in the nodes to be determined as the target pruning node.
Specifically, the blockchain node may traverse the node hash and the node height of each state tree node in the pruning mapping table.
If the state tree node in the pruning mapping relation table has a shared node, the blockchain node can determine the child node of the shared node as a reserved node.
The shared node refers to a state tree node shared by state trees corresponding to a plurality of service blocks respectively. The shared node may be determined by calling information, and embodiments of the present application are not limited herein.
For example, the blockchain node may determine that the state tree node 1 in the pruning mapping relationship table is a shared node by invoking the information, and the child nodes of the state tree node 1 include the state tree node 6 and the state tree node 7, and then the blockchain node may determine the state tree node 6 and the state tree node 7 as reserved nodes.
The blockchain node may determine a node to be determined, which does not belong to the reserved node, among the nodes to be determined as a target pruning node.
Optionally, the block link point may determine the target pruning node through a node hash and a node height included in the node to be determined and a node hash and a node height in the pruning mapping table, and the block link node may further determine the target pruning node by further determining the node to be determined after determining the reserved node, where the process may be: traversing to obtain node hash and node height of each state tree node in the pruning mapping relation table; if the node hash of the node to be judged is determined to be not in the pruning mapping relation table based on the traversed node hash, determining the node to be judged which is not in the pruning mapping relation table as a target pruning node; if the node hash of the node to be judged is determined to exist in the pruning mapping relation table based on the traversed node hash, determining the node to be judged existing in the pruning mapping relation table as a height judgment node, and acquiring the node height of the height judgment node; if the node height of the height judging node is smaller than the node height corresponding to the node hash in the pruning mapping relation table, determining the node height as the target pruning node.
Specifically, the blockchain node may traverse the node hash and the node height of each state tree node in the pruning mapping table.
If the node hash of the node to be determined does not exist in the node hash traversed by the pruning mapping relation table, that is, the node hash of the node to be determined does not exist in the pruning mapping table, the blockchain node can determine the node to be determined which does not exist in the pruning mapping relation table as the target pruning node. For example, the node hash 8 of the state tree node 8 is not present in the pruning mapping table, the blockchain node may determine that the state tree node 8 is the target pruning node.
If the node hash of the node to be judged exists in the node hash traversed by the pruning mapping relation table, the blockchain node can determine the node to be judged existing in the pruning mapping relation table as a height judgment node, and acquire the node height of the height judgment node;
if the node height of the height determination node is smaller than the node height corresponding to the node hash in the pruning mapping relation table, the blockchain node can determine the height determination node with the node height smaller than the node height in the pruning mapping relation table as the target pruning node.
For example, the node hash 9 of the state tree node 9 may be the same as the node hash 3 of the state tree node 3, then the blockchain node may determine that the node height 9 of the state tree node 9 is 950, the node height 9 being 900 less than the node height 3, and the blockchain node may determine the state tree node 9 as the target pruning node.
Alternatively, the blockchain link point may generate a data snapshot through the state data (may be transaction information, transfer incentives, etc.) stored by the target pruning node, and store the data snapshot as an independent file, which may reduce the storage space of the blockchain. The blockchain may hold the latest data snapshot and later state data, and the previous block data may be deleted. When historical state data needs to be queried, the latest data snapshot may be used to recover the historical state data.
It can be appreciated that the manner of creating the data snapshot in the embodiments of the present application may create the data memory snapshot through the level db, which is not limited herein.
The blockchain node may delete the state data stored in the target pruning node.
Optionally, the target pruning node may include target data and associated data, and the blockchain node may delete the associated data stored in the target pruning node, which may be: determining a state tree node connected with the target pruning node as an associated state node; the state data of the target pruning node and the state data of the associated state node comprise target data, the state data of the target pruning node also comprises associated data, the target data of the target pruning node is data required by the target pruning node to participate in the consensus, the target data of the associated state node is data required by the associated state node to participate in the consensus, and the associated data is data stored by the target pruning node for maintaining the associated state node; and deleting the associated data stored by the target pruning node and the target data stored by the associated state node.
Specifically, the blockchain node may determine the state tree node connected with the target pruning node as an associated state node, the state data stored in the state tree node of the state tree associated with the service block may be divided into target data and associated data, that is, the state data of the target node may include target data required for the target node to participate in the consensus, and associated data required for the associated state node to participate in the consensus, the associated data stored in the target node may be target data required for the associated node to verify, and the associated data stored in the associated node may be target data required for the target node to verify.
The blockchain node can delete the associated data of each target pruning node, only the target data of the target pruning node is reserved, but the data of the associated state node is not reserved, and the blockchain node can verify the nodes through the target data of the target pruning node and the associated state node, so that whether the target data participating in consensus is correct or not is confirmed, and the consumption of the state data to the storage space can be reduced.
Step S205, when N update blocks are newly added in the block chain, determining the block heights corresponding to the N update blocks as the node heights of the state tree nodes of the state tree associated with the N update blocks respectively; n is a positive integer;
Specifically, when a service block is newly added in the blockchain, the newly added service block may be referred to as an update block, and the blockchain node may determine the block heights corresponding to the update blocks respectively as the node heights of the state tree nodes of the state tree associated with the update blocks respectively. The state tree nodes in each state tree contain node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the associated update block (newly added service block).
Step S206, determining the height of the updated pruning block in the N updated blocks;
specifically, the blockchain node may determine the updated pruning height in the updated block, where the manner of determining the updated pruning height may be the same as the manner of determining the target pruning block height, may be determined by a difference between a highest block height in the blockchain and a block height error threshold (may be a statistically obtained error value), or may be determined by a number of rollbacks in a rollback statistical period, and the manner of determining the target pruning block height may be described in detail in step S103 in the embodiment of fig. 3, which is not limited herein.
Step S207, determining an update block with the block height belonging to the update pruning height as an update mapping block, determining a state tree node associated with the update mapping block as an update comparison node, and generating an update pruning mapping relation table through a mapping relation between node hash contained in the update comparison node and node height of the update comparison node;
specifically, the blockchain node may determine that the block height belongs to an update block of the update pruning height as an update mapping block, determine a state tree node associated with the update mapping block as an update comparison node, and generate an update pruning mapping relationship table through a mapping relationship between a node hash included in the update comparison node and the node height of the update comparison node.
Step S208, generating an updated pruning range based on the target pruning block height and the updated pruning block height, determining the service blocks with the block heights belonging to the updated pruning range and the state tree nodes associated with the updated blocks as updated nodes to be determined, determining the updated pruning nodes in the updated nodes to be determined according to the node heights of the updated nodes to be determined and the updated pruning mapping relation table, and deleting the state data stored in the updated pruning nodes.
Specifically, the blockchain node may determine the target pruning block height target as the first section value target1, determine the updated pruning block height as the second section value target2, generate an updated pruning range based on the first section value and the second section value, and the updated pruning range may be represented as a section [ target1, target2 ], i.e. the target pruning range of the first pruning [ base, target1 ], since there is no previous pruning yet, the base may be 0, i.e. the range of the first pruning is [0, target1 ], the second pruning range may be [ target1, target 2), the third pruning range may be [ target2, target 3), and so on.
The blockchain node may determine that the traffic blocks whose block heights fall within the update pruning range and the state tree nodes associated with the update blocks are update pending nodes.
The blockchain node may traverse the node hash and node height of each state tree node in the pruning map.
If the state tree node in the pruning mapping relation table has a shared node, the blockchain node can determine the child node of the shared node as a reserved node.
The shared node refers to a state tree node shared by state trees corresponding to a plurality of service blocks respectively. The shared node may be determined by calling information, and embodiments of the present application are not limited herein.
The blockchain node may determine an update pending node of the update pending nodes that does not belong to the retention node as the target pruning node.
The blockchain node may determine to update the pruning node by updating the node hash and the node height included in the node to be determined and the node hash and the node height in the pruning mapping table, or may further determine to update the node to be determined to determine to update the pruning node after determining the reserved node.
If the node hash of the node to be determined does not exist in the node hash traversed by the pruning mapping relation table, that is, the node hash of the node to be determined does not exist in the pruning mapping table, the blockchain node may determine the node to be determined, which does not exist in the pruning mapping relation table, as the updated pruning node.
If the node hash of the node to be judged is in the node hash traversed by the pruning mapping relation table, the block chain node can determine the node to be judged updated in the pruning mapping relation table as the height judgment node, and acquire the node height of the height judgment node;
if the node height of the height determination node is smaller than the node height corresponding to the node hash in the pruning mapping relation table, the blockchain node can determine the node height as the updated pruning node.
The method for updating the pruning node may be the same as the method for determining the target pruning node, and the process thereof may refer to the specific description of step S204, which is not repeated herein.
The blockchain node may delete the state data stored in the updated pruning node.
According to the embodiment of the application, the node heights of the state tree nodes of M state trees respectively associated with the M service blocks are determined according to the block heights respectively corresponding to the M service blocks in the block chain; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs; determining the height of a target pruning block in M service blocks; determining a service block with the block height belonging to the target pruning block height as a target mapping block, determining a state tree node associated with the target mapping block as a comparison node, and generating a pruning mapping relation table through the mapping relation between node hash contained in the comparison node and the node height of the comparison node; generating a target pruning range based on the target pruning block height, determining a state tree node associated with the business block with the block height belonging to the target pruning range as a node to be judged, determining the target pruning node in the node to be judged according to the node height of the node to be judged and the pruning mapping relation table, and deleting the state data stored in the target pruning node. When N updating blocks are newly added in the block chain, determining the block heights corresponding to the N updating blocks as the node heights of the state tree nodes of the state tree respectively associated with the N updating blocks; n is a positive integer; determining the height of an updated pruning block in the N updating blocks; determining an update block with the block height belonging to the update pruning height as an update mapping block, determining a state tree node associated with the update mapping block as an update comparison node, and generating an update pruning mapping relation table through a mapping relation between node hash contained in the update comparison node and the node height of the update comparison node; generating an updated pruning range based on the target pruning block height and the updated pruning block height, determining a service block with the block height belonging to the updated pruning range and a state tree node associated with the updated block as an updated node to be determined, determining the updated pruning node in the updated node to be determined according to the node height of the updated node to be determined and the updated pruning mapping relation table, and deleting the state data stored in the updated pruning node. It can be seen that, in the embodiment of the present application, corresponding node heights are allocated to the service blocks and the state tree nodes of the state tree associated with the update blocks, an updated pruning mapping relationship table is generated by updating the node hashes and the node heights included in the state tree nodes associated with the pruning block heights, an updated pruning range is generated based on the updated pruning block heights, all the state tree nodes associated with the service blocks and the update blocks in the updated pruning range are determined as the nodes to be determined, the pruning mapping relationship table is traversed, and the updated pruning nodes requiring pruning are determined by comparing the node hashes and the node heights in the nodes to be determined with the node hashes and the node heights of the updated pruning mapping relationship table, so that range pruning is possible. Pruning of the blockchain state tree may remove invalid or attacked state tree nodes, thereby reducing potential security risks. Only valid and valuable nodes are reserved, and the security of the whole blockchain system can be enhanced. Pruning of the blockchain state tree may remove invalid or outdated state nodes, thereby reducing memory space usage. Redundant nodes in the state tree are removed, thereby reducing the time and resource overhead of querying and validating. The pruned state tree is more compact, so that related operations are more efficient, and consumption of the blockchain state data on storage resources and network resources can be reduced.
On the other hand, when the target pruning node is determined, the shared node in the pruning mapping table is determined, the child node of the shared node is determined to be the reserved node, deletion of the child node of the shared node is avoided, then the node hash and the node height of the node to be determined are determined to be the same as the node hash and the node height in the pruning mapping table, and the possibility that the node hash may exist is avoided, so that the wrong node to be determined is reserved, and accuracy and feasibility of range pruning are improved.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a data processing apparatus based on a blockchain according to an embodiment of the present application. As shown in fig. 5, the data processing apparatus 1 includes a node height determining module 500, a pruning height processing module 510, a mapping table generating module 520, a decision processing module 530, a data snapshot module 540, an update height determining module 550, an update height processing module 560, an update mapping generating module 570, and an update decision processing module 580. The pruning height processing module 510 includes a fault-tolerant height determining unit 511, a pruning height determining unit 512, a rollback traversing unit 513, and a stable block processing unit 514. The decision processing module 530 includes a first decision traversing unit 531, a first decision selecting unit 532, a second decision traversing unit 533, and a second decision selecting unit 534. The update determination processing module 580 includes a data confirmation unit 581 and a data deletion unit 582. The pruning height determination unit 512 includes a roll-back height determination subunit 512a and a height selection subunit 512b.
The node height determining module 500 is configured to determine node heights of state tree nodes of M state trees respectively associated with the M service blocks according to block heights respectively corresponding to the M service blocks in the blockchain; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs; the specific function of the node height determining module 500 may be referred to the above description of step S101 in the corresponding embodiment of fig. 3, and will not be repeated here.
A pruning height processing module 510, configured to determine a target pruning block height among the M service blocks; the specific function of the pruning height processing module 510 may be referred to the above description of step S102 in the corresponding embodiment of fig. 3, and will not be repeated here.
The pruning height processing module 510 includes a fault-tolerant height determining unit 511, a pruning height determining unit 512, a rollback traversing unit 513, and a stable block processing unit 514.
A fault-tolerant height determining unit 511, configured to obtain a block height error threshold, and determine a difference between a highest block height of the M service blocks and the block height error threshold as a tolerance block height;
The pruning height determining unit 512 determines the target pruning block height according to the tolerance block height.
The pruning height determination unit 512 includes a roll-back height determination subunit 512a and a height selection subunit 512b.
A rollback height determining subunit 512a, configured to obtain rollback times of the M service blocks in the rollback statistics period, and determine, if there are service blocks with rollback times greater than the time threshold, a minimum block height in the service blocks with rollback times greater than the time threshold as a rollback block height;
a height selection subunit 512b, configured to determine the tolerance block height as the target pruning block height if the rollback block height is greater than or equal to the tolerance block height;
the height selection subunit 512b is further configured to determine the rollback block height as the target pruning block height if the rollback block height is less than the tolerance block height.
A rollback traversing unit 513, configured to gradually traverse the M service blocks from the creation block; the creation block is the service block with the lowest block height in the M service blocks;
the stable block processing unit 514 is configured to stop traversing the traffic block when traversing to the traffic block with rollback, determine the traversed traffic block with rollback as a stable block, and determine the block height of the stable block as the target pruning block height.
The specific functions of the fault-tolerant height determining unit 511, the pruning height determining unit 512, the rollback height determining subunit 512a, the height selecting subunit 512b, the rollback traversing unit 513 and the stable block processing unit 514 may be referred to the specific description of step S102 in the corresponding embodiment of fig. 3, and are not repeated herein.
The mapping table generating module 520 is configured to determine a service block whose block height belongs to a target pruning block height as a target mapping block, determine a state tree node associated with the target mapping block as a comparison node, and generate a pruning mapping relationship table by comparing a node hash included in the comparison node with a mapping relationship of the node height of the comparison node; the specific function of the mapping table generating module 520 may be referred to the above specific description of step S103 in the corresponding embodiment of fig. 3, and will not be repeated here.
The decision processing module 530 is configured to generate a target pruning range based on the target pruning block height, determine a state tree node associated with a service block whose block height belongs to the target pruning range as a node to be decided, determine a target pruning node in the node to be decided according to the node height of the node to be decided and the pruning mapping relationship table, and delete the state data stored in the target pruning node. The specific function of the decision processing module 530 may be referred to the above description of step S104 in the corresponding embodiment of fig. 3, and will not be repeated here.
The decision processing module 530 includes a first decision traversing unit 531, a first decision selecting unit 532, a second decision traversing unit 533, and a second decision selecting unit 534.
A first decision traversing unit 531, configured to traverse and obtain node hash and node height of each state tree node in the pruning mapping relationship table;
a first decision selecting unit 532, configured to determine, if it is determined based on the traversed node hash that the node hash of the node to be determined does not exist in the pruning mapping relationship table, the node to be determined that does not exist in the pruning mapping relationship table as the target pruning node;
the first decision selecting unit 532 is further configured to determine, if it is determined that the node hash of the node to be determined exists in the pruning mapping relationship table based on the traversed node hash, the node to be determined that exists in the pruning mapping relationship table as the height determining node, and obtain the node height of the height determining node;
the first decision selecting unit 532 is further configured to determine, as the target pruning node, a height decision node whose node height is smaller than the node height in the pruning mapping relationship table if the node height of the height decision node is smaller than the node height corresponding to the node hash in the pruning mapping relationship table.
A second decision traversing unit 533 configured to traverse and obtain a node hash and a node height of each state tree node in the pruning mapping relationship table;
a second decision selecting unit 534, configured to determine a child node of the shared node as a reserved node if the shared node exists in the state tree nodes in the pruning mapping relationship table; the shared node refers to a state tree node shared by state trees respectively corresponding to at least two business blocks in the M business blocks;
and a second decision selecting unit 534, configured to determine, as the target pruning node, a node to be decided that does not belong to the reserved node among the nodes to be decided.
Specific functions of the first decision traversing unit 531, the first decision selecting unit 532, the second decision traversing unit 533, and the second decision selecting unit 534 may be referred to the specific description of step S204 in the corresponding embodiment of fig. 4, and are not repeated herein.
A data snapshot module 540 for generating a data snapshot from the state data stored in the target pruning node; the data snapshot is used for querying historical state data of the target pruning node. The specific function of the data snapshot module 540 may be referred to the above description of step S204 in the corresponding embodiment of fig. 4, and will not be repeated here.
An update height determining module 550, configured to determine, when N update blocks are newly added in the blockchain, the block heights corresponding to the N update blocks respectively as node heights of the state tree nodes of the state tree associated with the N update blocks respectively; n is a positive integer; the specific function of the update height determining module 550 may be referred to the above description of step S205 in the corresponding embodiment of fig. 4, and will not be repeated here.
An update height processing module 560, configured to determine an update pruning block height among the N update blocks; the specific function of the update height processing module 560 may be referred to the above description of step S206 in the corresponding embodiment of fig. 4, and will not be described herein.
The update map generation module 570 is configured to determine an update block whose block height belongs to an update pruning height as an update map block, determine a state tree node associated with the update map block as an update comparison node, and generate an update pruning map table according to a mapping relationship between a node hash included in the update comparison node and a node height of the update comparison node; the specific function of the update map generation module 570 may be referred to the above description of step S207 in the corresponding embodiment of fig. 4, and will not be repeated here.
The update determination processing module 580 is configured to generate an update pruning range based on the target pruning block height and the update pruning block height, determine a service block with a block height belonging to the update pruning range and a state tree node associated with the update block as an update node to be determined, determine an update pruning node in the update node to be determined according to the node height of the update node to be determined and the update pruning mapping relation table, and delete the state data stored in the update pruning node. The specific function of the update determination processing module 580 may be referred to the above description of step S205 in the corresponding embodiment of fig. 4, and will not be repeated here.
The update determination processing module 580 is specifically configured to determine the target pruning block height as a first interval value, determine the updated pruning block height as a second interval value, and generate an updated pruning range based on the first interval value and the second interval value.
The update determination processing module 580 includes a data confirmation unit 581 and a data deletion unit 582.
The data confirmation unit 581 is configured to determine, as an associated state node, a state tree node to which the target pruning node is connected; the state data of the target pruning node and the state data of the associated state node comprise target data, the state data of the target pruning node also comprises associated data, the target data of the target pruning node is data required by the target pruning node to participate in the consensus, the target data of the associated state node is data required by the associated state node to participate in the consensus, and the associated data is data stored by the target pruning node for maintaining the associated state node;
And a data deleting unit 582 configured to delete the association data stored in the target pruning node and the target data stored in the association status node.
The specific functions of the data confirmation unit 581 and the data deletion unit 582 may be referred to the above-described specific description of step S205 of the corresponding embodiment of fig. 4, and will not be repeated here.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a computer device according to an embodiment of the present application. As shown in fig. 6, the computer device 1000 may include: processor 1001, network interface 1004, and memory 1005, and in addition, the above-described computer device 1000 may further include: a user interface 1003, and at least one communication bus 1002. Wherein the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display (Display), a Keyboard (Keyboard), and the optional user interface 1003 may further include a standard wired interface, a wireless interface, among others. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (non-volatile memory), such as at least one disk memory. The memory 1005 may also optionally be at least one storage device located remotely from the processor 1001. As shown in fig. 6, an operating system, a network communication module, a user interface module, and a device control application may be included in the memory 1005, which is a type of computer-readable storage medium.
In the computer device 1000 shown in fig. 6, the network interface 1004 may provide a network communication network element; while user interface 1003 is primarily used as an interface for providing input to a user; and the processor 1001 may be used to invoke a device control application stored in the memory 1005 to implement:
determining node heights of state tree nodes of M state trees respectively associated with M service blocks according to block heights respectively corresponding to the M service blocks in a block chain; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs;
determining a target pruning block height in the M service blocks;
determining a service block with the block height belonging to the target pruning block height as a target mapping block, determining a state tree node associated with the target mapping block as a comparison node, and generating a pruning mapping relation table through a mapping relation between node hash contained in the comparison node and the node height of the comparison node;
generating a target pruning range based on the target pruning block height, determining a state tree node associated with a service block with the block height belonging to the target pruning range as a node to be judged, determining a target pruning node in the node to be judged according to the node height of the node to be judged and the pruning mapping relation table, and deleting the state data stored in the target pruning node.
It should be understood that the computer device 1000 described in the embodiments of the present application may perform the description of the data processing method in any of the foregoing embodiments corresponding to fig. 3 and fig. 4, which is not repeated herein. In addition, the description of the beneficial effects of the same method is omitted.
Furthermore, it should be noted here that: the embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program, when the processor executes the computer program, the description of the data processing method in any one of the corresponding embodiments of fig. 3 and fig. 4 can be executed, and therefore, a detailed description will not be given here. In addition, the description of the beneficial effects of the same method is omitted. For technical details not disclosed in the embodiments of the computer-readable storage medium according to the present application, please refer to the description of the method embodiments of the present application.
The computer readable storage medium may be the data processing apparatus provided in any one of the foregoing embodiments or an internal storage unit of the computer device, for example, a hard disk or a memory of the computer device. The computer readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash card (flash card) or the like, which are provided on the computer device. Further, the computer-readable storage medium may also include both internal storage units and external storage devices of the computer device. The computer-readable storage medium is used to store the computer program and other programs and data required by the computer device. The computer readable storage medium may also be used to temporarily store data that has been or is to be displayed.
Furthermore, it should be noted here that: embodiments of the present application also provide a computer program product comprising a computer program stored in a computer readable storage medium. The processor of the computer device reads the computer program from the computer readable storage medium and executes the computer program to cause the computer device to perform the method provided by the corresponding embodiment of any of the previous figures 3 and 4.
The terms first, second and the like in the description and in the claims and drawings of the embodiments of the present application are used for distinguishing between different objects and not for describing a particular sequential order. Furthermore, the term "include" and any variations thereof is intended to cover a non-exclusive inclusion. For example, a process, method, apparatus, article, or device that comprises a list of steps or elements is not limited to the list of steps or modules but may, in the alternative, include other steps or modules not listed or inherent to such process, method, apparatus, article, or device.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps described in connection with the embodiments disclosed herein may be embodied as electronic hardware, as a computer software, or in a combination of the two, and that the elements and steps of the examples have been generally described in terms of network elements in the foregoing description to clearly illustrate the interchangeability of hardware and software. Whether these network elements are implemented in hardware or software depends on the specific application and design constraints of the solution. The skilled person may use different methods for implementing the described network elements for each specific application, but such implementation should not be considered beyond the scope of the present application.
The foregoing disclosure is only illustrative of the preferred embodiments of the present application and is not intended to limit the scope of the claims herein, as the equivalent of the claims herein shall be construed to fall within the scope of the claims herein.
Claims (14)
1. A blockchain-based data processing method, comprising:
determining node heights of state tree nodes of M state trees respectively associated with M service blocks according to block heights respectively corresponding to the M service blocks in a block chain; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs;
determining a target pruning block height in the M service blocks;
determining a service block with the block height belonging to the target pruning block height as a target mapping block, determining a state tree node associated with the target mapping block as a comparison node, and generating a pruning mapping relation table through a mapping relation between node hash contained in the comparison node and the node height of the comparison node;
generating a target pruning range based on the target pruning block height, determining a state tree node associated with a service block with the block height belonging to the target pruning range as a node to be judged, determining a target pruning node in the node to be judged according to the node height of the node to be judged and the pruning mapping relation table, and deleting the state data stored in the target pruning node.
2. The method of claim 1, wherein said determining a target pruning block height among said M traffic blocks comprises:
acquiring a block height error threshold, and determining a difference value between the highest block height in the M service blocks and the block height error threshold as a tolerance block height;
and determining the height of the target pruning block according to the height of the tolerance block.
3. The method of claim 2, wherein the determining a target pruning block height from the tolerance block height comprises:
acquiring the rollback times of the M service blocks in the rollback statistical period respectively, and if the service blocks with the rollback times larger than the time threshold exist, determining the minimum block height in the service blocks with the rollback times larger than the time threshold as the rollback block height;
if the rollback block height is greater than or equal to the tolerance block height, determining the tolerance block height as a target pruning block height;
and if the rollback block height is smaller than the tolerance block height, determining the rollback block height as a target pruning block height.
4. The method of claim 1, wherein said determining a target pruning block height among said M traffic blocks comprises:
Gradually traversing the M business blocks from the creation block; the created block is the service block with the lowest block height in the M service blocks;
and stopping traversing the business blocks when traversing to the business blocks after rollback, determining the traversed business blocks after rollback as stable blocks, and determining the block height of the stable blocks as the target pruning block height.
5. The method according to claim 1, wherein the determining a target pruning node in the nodes to be determined according to the node heights contained in the nodes to be determined and the pruning mapping table includes:
traversing to obtain node hash and node height of each state tree node in the pruning mapping relation table;
if the node hash of the node to be judged is determined to be not in the pruning mapping relation table based on the traversed node hash, determining the node to be judged which is not in the pruning mapping relation table as a target pruning node;
if the node hash of the node to be judged exists in the pruning mapping relation table based on the traversed node hash, determining the node to be judged existing in the pruning mapping relation table as a height judgment node, and acquiring the node height of the height judgment node;
And if the node height of the height judging node is smaller than the node height corresponding to the node hash in the pruning mapping relation table, determining the node height as a target pruning node.
6. The method according to claim 1, wherein the determining a target pruning node in the nodes to be determined according to the node heights contained in the nodes to be determined and the pruning mapping table includes:
traversing to obtain node hash and node height of each state tree node in the pruning mapping relation table;
if the state tree nodes in the pruning mapping relation table have shared nodes, determining child nodes of the shared nodes as reserved nodes; the shared node refers to a state tree node shared by state trees respectively corresponding to at least two business blocks in the M business blocks;
and determining the node to be determined which does not belong to the reserved node in the nodes to be determined as a target pruning node.
7. The method as recited in claim 1, further comprising:
when N updating blocks are newly added in the block chain, determining the block heights corresponding to the N updating blocks as the node heights of the state tree nodes of the state tree respectively associated with the N updating blocks; n is a positive integer;
Determining the height of an updated pruning block in the N updating blocks;
determining an update block with the block height belonging to the update pruning height as an update mapping block, determining a state tree node associated with the update mapping block as an update comparison node, and generating an update pruning mapping relation table through a mapping relation between node hash contained in the update comparison node and the node height of the update comparison node;
generating an update pruning range based on the target pruning block height and the update pruning block height, determining a service block with the block height belonging to the update pruning range and a state tree node associated with the update block as an update to-be-determined node, determining an update pruning node in the update to-be-determined node according to the node height of the update to-be-determined node and the update pruning mapping relation table, and deleting the state data stored in the update pruning node.
8. The method of claim 7, wherein the generating an updated pruning range based on the target pruning block height and the updated pruning block height comprises:
and determining the target pruning block height as a first interval value, determining the updated pruning block height as a second interval value, and generating an updated pruning range based on the first interval value and the second interval value.
9. The method of claim 1, wherein prior to the step of deleting the state data stored in the target pruning node, the method further comprises:
generating a data snapshot from the state data stored in the target pruning node; the data snapshot is used for inquiring historical state data of the target pruning node.
10. The method of claim 1, wherein the deleting the state data stored in the target pruning node comprises:
determining a state tree node connected with the target pruning node as an associated state node; the state data of the target pruning node and the state data of the associated state node comprise target data, the state data of the target pruning node also comprises associated data, the target data of the target pruning node is data required by the target pruning node to participate in consensus, the target data of the associated state node is data required by the associated state node to participate in consensus, and the associated data is data stored by the target pruning node for maintaining the associated state node;
and deleting the associated data stored by the target pruning node and the target data stored by the associated state node.
11. A blockchain-based data processing device, comprising:
the node height determining module is used for determining node heights of state tree nodes of M state trees respectively associated with the M service blocks according to block heights respectively corresponding to the M service blocks in the block chain; m is a positive integer; the state tree nodes of each state tree comprise node hashes, and the node height of each state tree node in a single state tree is the same as the block height of the service block to which the state tree node belongs;
the pruning height processing module is used for determining the height of a target pruning block in the M business blocks;
the mapping table generation module is used for determining a service block with the block height belonging to the target pruning block height as a target mapping block, determining a state tree node associated with the target mapping block as a comparison node, and generating a pruning mapping relation table through the mapping relation between node hash contained in the comparison node and the node height of the comparison node;
the judging and processing module is used for generating a target pruning range based on the target pruning block height, determining a state tree node associated with a service block with the block height belonging to the target pruning range as a node to be judged, determining the target pruning node in the node to be judged according to the node height of the node to be judged and the pruning mapping relation table, and deleting the state data stored in the target pruning node.
12. A computer device, comprising: a processor, a memory, and a network interface;
the processor is connected to the memory, the network interface for providing data communication functions, the memory for storing a computer program, the processor for invoking the program code to cause the computer device to perform the method of any of claims 1-10.
13. A computer readable storage medium, characterized in that the computer readable storage medium has stored therein a computer program adapted to be loaded and executed by a processor to cause a computer device having the processor to perform the method of any of claims 1-10.
14. A computer program product, characterized in that the computer program product comprises a computer program stored in a computer readable storage medium and adapted to be read and executed by a processor to cause a computer device with the processor to perform the method of any of claims 1-10.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311374981.1A CN117390117A (en) | 2023-10-19 | 2023-10-19 | Block chain-based data processing method, device, equipment and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311374981.1A CN117390117A (en) | 2023-10-19 | 2023-10-19 | Block chain-based data processing method, device, equipment and readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117390117A true CN117390117A (en) | 2024-01-12 |
Family
ID=89466248
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311374981.1A Pending CN117390117A (en) | 2023-10-19 | 2023-10-19 | Block chain-based data processing method, device, equipment and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117390117A (en) |
-
2023
- 2023-10-19 CN CN202311374981.1A patent/CN117390117A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN113329031B (en) | Method and device for generating state tree of block | |
CN107193490B (en) | Distributed data storage system and method based on block chain | |
CN111061769B (en) | Consensus method of block chain system and related equipment | |
CN110597825B (en) | Data processing method and device based on block chain and node equipment | |
CN113326165B (en) | Data processing method and device based on block chain and computer readable storage medium | |
JP7157348B2 (en) | Blockchain system, approval terminal, smart contract registration method, and smart contract registration program | |
CN101009516A (en) | A method and system for data synchronization | |
CN110941676B (en) | Configuration method, device, equipment and medium | |
CN112862490A (en) | Output consensus method under asynchronous network | |
CN115988001A (en) | Consensus voting processing method, device, equipment and medium for block chain system | |
US20230353393A1 (en) | Blockchain-based methods and apparatuses for processing data, devices and readable storage mediums | |
US12032557B2 (en) | Method, device, and computer program product for data management | |
CN116977067A (en) | Block chain-based data processing method, device, equipment and readable storage medium | |
WO2023142605A1 (en) | Blockchain-based data processing method and related apparatus | |
CN117390117A (en) | Block chain-based data processing method, device, equipment and readable storage medium | |
US11568399B2 (en) | Distributed ledger management system, distributed ledger management method, and node | |
CN115730933A (en) | Data processing method, device and equipment based on block chain and storage medium | |
CN117421369A (en) | Block chain-based data processing method, device, equipment and readable storage medium | |
CN112883038B (en) | Data management method based on block chain, computer and readable storage medium | |
WO2024037117A1 (en) | Blockchain-based data processing method and device, medium, and program product | |
CN116700628B (en) | Block chain data processing method, device, computer equipment and storage medium | |
CN114691686B (en) | Method for generating block status commitment | |
CN117375810A (en) | Block chain-based data processing method, device, equipment and readable storage medium | |
CN116661674A (en) | Data compression method, block synchronization method and related equipment | |
CN117255130A (en) | Data processing method, device, equipment and medium based on block chain |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication |