Blockchain node status data processing method, electronic device and storage medium
By scanning monitoring parameters in blockchain nodes and performing persistence operations, the dynamic pruning mechanism solves the impact of state pruning on business performance, achieves rational pruning timing, and improves the stability and stability of the blockchain system. efficiency.
Patent Information
- Application Number
- CN202410519478.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-28
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-04-28
AI Technical Summary
Blockchain state pruning will affect normal business performance, and existing technologies lack effective solutions.
By scanning the status change set of the blockchain node, multiple monitoring parameters are obtained to determine whether the trigger condition is hit, and the status data of the blockchain node is persisted based on the status change set to implement a dynamic pruning mechanism and rationalize pruning. Branch timing to reduce the impact on business performance.
Through the dynamic pruning mechanism, we can identify the pruning time and rationalize the pruning operation, which improves the impact of blockchain state pruning on normal business performance and improves the stability and efficiency of the system.
Smart Images

Figure CN118093557B
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a blockchain node status data processing method, electronic device and storage medium. Background Art
[0002] Blockchain is a distributed database or ledger, which is composed of a series of ordered blocks linked by hash pointers to form an immutable chain structure. Each block contains multiple transactions, which record events such as asset transfers and smart contract calls in the system. When a blockchain node executes a transaction, state change information is generated. The collection of state change information is called the state change collection. The state tree is a data structure used to store the current global state in the blockchain system. It is mainly used to record all accounts and their related state information.
[0003] State expansion is one of the factors that affect the performance of blockchain systems, and the state tree accounts for the vast majority of it. When blockchain nodes execute transactions, they need to access the data in the state tree. For blockchain systems with high TPS (Transactions Per Second), this will bring greater disk load pressure.
[0004] To address the problem of state expansion, blockchain has introduced state pruning technology. State pruning is essentially the deletion of historical data in the blockchain state tree, so that blockchain nodes can only hold state data within a certain range in the recent period, thereby reducing the hardware resource requirements for some types of blockchain nodes. When pruning the state tree of a blockchain node, if the pruning timing is not appropriate, it will affect the business performance of the blockchain node.
[0005] There is currently no effective solution to the problem that blockchain state pruning in related technologies will affect the performance of normal business. Summary of the invention
[0006] In this embodiment, a blockchain node status data processing method, an electronic device, and a storage medium are provided to solve the problem in the related art that blockchain status pruning may affect the performance of normal business.
[0007] In the first aspect, a blockchain node status data processing method is provided in this embodiment, including:
[0008] Scan the state change set of blockchain nodes to obtain multiple monitoring parameters;
[0009] Determine whether any of the multiple monitoring parameters meets the trigger condition;
[0010] When it is determined that any one of the monitoring parameters meets the trigger condition, the state data of the blockchain node is persisted according to the state change set.
[0011] In one embodiment, the monitoring parameters include at least one of the following:
[0012] A time-driven parameter, which is used to represent the time interval between the current time and the last time a persistence operation was performed on the state data of the blockchain node;
[0013] A transaction accumulation parameter, which is used to represent the number of blocks added since the last persistence operation was performed on the state data of the blockchain node;
[0014] A data capacity parameter, which is used to characterize the amount of state data to be persisted for the blockchain node at the current time.
[0015] In one of the embodiments, the state data of the blockchain node is stored in a persistent storage space in a tree structure to form a state tree, and each child node in the state tree has only one unique parent node.
[0016] In one embodiment, the state change set includes a write set and a pruning set of state tree nodes generated when the blockchain node executes a block transaction; when it is determined that any monitoring parameter hits the trigger condition, a persistence operation is performed on the state data of the blockchain node according to the state change set, including:
[0017] The data in the pruned set is deleted in the state tree, and the data in the write set is inserted in the state tree.
[0018] In one embodiment, before performing a persistence operation on the state data of the blockchain node according to the state change set, the method further includes:
[0019] Writing the state change set into a pruning log;
[0020] The pruning log is persistently stored and cached respectively, and an index is set for the pruning log according to the block number of the execution block.
[0021] In one embodiment, after persisting the state data of the blockchain node according to the state change set, the method further includes:
[0022] Delete the pruning log corresponding to the state change set of the current blockchain node.
[0023] In one embodiment, the method further comprises:
[0024] When the blockchain node executes a block transaction, the cached pruning log is accessed according to the index, and a state value required to execute the transaction is found from the cached pruning log;
[0025] If the state value does not exist in the cache, the state value required to execute the transaction is searched from the state tree.
[0026] In one embodiment, the method further comprises:
[0027] When it is determined that none of the multiple monitoring parameters meets the trigger condition, after a preset time interval, the state change set of the blockchain node is scanned to obtain multiple new monitoring parameters.
[0028] In a second aspect, an electronic device is provided in this embodiment, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the blockchain node status data processing method described in the first aspect.
[0029] In a third aspect, a computer-readable storage medium is provided in this embodiment, on which a computer program is stored. When the computer program is executed by a processor, the steps of the blockchain node status data processing method described in the first aspect are performed.
[0030] The above-mentioned blockchain node status data processing method, electronic device and storage medium, during the blockchain node status change process, quantitatively monitor the key parameters therein based on multiple dimensions to obtain multiple monitoring parameters, and when any monitoring parameter hits the trigger condition, the status data of the blockchain node is persisted according to the state change set, thereby realizing the dynamic pruning mechanism, facilitating the accurate pruning timing, making pruning more rational, and improving the impact of blockchain status pruning on normal business performance.
[0031] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0033] Figure 1 The hardware structure block diagram of a terminal of a blockchain node status data processing method in one embodiment;
[0034] Figure 2 It is a flowchart of a method for processing blockchain node status data in one embodiment;
[0035] Figure 3 This is a schematic diagram of the architecture of a blockchain system in one embodiment;
[0036] Figure 4 It is an operation flow chart of a blockchain system in one embodiment;
[0037] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0038] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0039] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with general skills in the technical field to which this application belongs. The words "one", "a", "the", "these" and the like in this application do not indicate a quantitative limitation, and they may be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone. Generally, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0040] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. For example, running on a terminal, Figure 1 1 is a hardware structure diagram of a terminal of a blockchain node status data processing method according to an embodiment of the present application. Figure 1 As shown, the terminal may include one or more ( Figure 1Only one is shown in the figure) processor 101 and memory 102 for storing data, wherein processor 101 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 103 and an input and output device 104 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0041] The memory 102 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the blockchain node state data processing method in this embodiment. The processor 101 executes various functional applications and data processing by running the computer program stored in the memory 102, that is, to implement the above method. The memory 102 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 102 may further include a memory remotely arranged relative to the processor 101, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0042] The transmission device 103 is used to receive or send data via a network. The above network includes a wireless network provided by a communication provider of the terminal. In one example, the transmission device 103 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 103 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0043] In one embodiment, Figure 2 As shown, a flowchart of a method for processing blockchain node status data is provided, and the method is applied to Figure 1 The terminal in is used as an example to illustrate the process, including the following steps:
[0044] Step S201, scan the state change set of the blockchain node to obtain multiple monitoring parameters.
[0045] One of the core tasks of blockchain runtime is to continuously execute transactions in new blocks, apply the transaction execution results to the world state of the current ledger, and obtain a new world state. The state change set generated by each block can be recorded with the block as the dimension, and pruned according to these sets. Whenever a blockchain node executes a transaction, the blockchain node will change its state, generate state change information, write the state change information into a set, and obtain a state change set. The state data of the blockchain node is stored in a tree structure in a persistent storage space to form a state tree, and each child node in the state tree has only one unique parent node. Among them, the state change can include creating, deleting or adjusting several Merkle paths from the root node to the leaf node. The state tree can store the data of the current global state in the blockchain to record all accounts in the blockchain and their related state information.
[0046] In some embodiments, the state change set includes the write set (Write Set) and prune set (Prune Set) of the state tree node generated when the blockchain node executes the block transaction. Among them, the write set and the prune set respectively represent different types of operation records performed by the blockchain node on the state tree node when executing a new block. The write set contains the addition or update operations made to the state tree node during the execution of the current block, and the prune set contains the state tree nodes identified as no longer needed to be retained or can be safely deleted during the execution of the current block. The write set and the prune set are two components of the state change set, corresponding to the addition / update operation and the deletion / discard operation of the state tree node, respectively. These two parts are used to describe the specific changes in the state of the ledger world relative to the previous state after the execution of the new block. In actual applications, the write set and the prune set will be packaged into a state change set, and will be persistently stored as a pruning log and recorded in the memory cache, respectively, to facilitate subsequent state recovery, state search, and pruning optimization operations.
[0047] Step S202: determine whether any monitoring parameter among the multiple monitoring parameters meets the trigger condition.
[0048] Monitoring parameters are parameters obtained by quantitatively monitoring key parameters in the process of blockchain node state change from multiple dimensions. For example, monitoring parameters can be determined from any two or three dimensions of time drive, transaction accumulation and data capacity. Specifically, the time drive dimension can include the time interval, the transaction accumulation dimension can include the accumulated number of blocks, and the data capacity dimension can include the size of the accumulated state data to be refreshed. Monitoring parameters can be regarded as "pruning trigger conditions" or "persistence trigger indicators". Multiple monitoring parameters together constitute a set of quantitative standards for determining when to start the persistence operation, which are used to guide the pruning thread to perform pruning (i.e. persistence) tasks at the appropriate time point. Among them, the pruning thread is a thread started in the blockchain system, which is used to perform state pruning. The blockchain system also includes a transaction thread, which is used to execute transactions in the block.
[0049] A corresponding threshold range may be set for each monitoring parameter to determine whether the monitoring parameter falls within the corresponding threshold range.
[0050] Step S203, when it is determined that any monitoring parameter meets the trigger condition, the state data of the blockchain node is persisted according to the state change set.
[0051] In this embodiment, if any of the monitoring parameters falls within the corresponding threshold range, it is determined that the trigger condition is hit, and the state change set persistence operation can be started at this time. The persistence operation refers to the operation of the state data based on the state change set, such as deleting the data of the trimmed set in the state change set on the physical ledger, and inserting the data of the write set in the state change set on the physical ledger, which is reflected in the state tree as pruning to reduce the physical storage space.
[0052] In some cases, it is the time-driven parameter that hits the trigger condition; in some cases, it is the transaction accumulation parameter that hits the trigger condition; in some cases, it is the data capacity parameter that hits the trigger condition; in some cases, the time-driven parameter and the transaction accumulation parameter jointly hit the trigger condition; in some cases, the transaction accumulation parameter and the data capacity parameter jointly hit the trigger condition, and so on, which will not be repeated here. In other words, for the entire blockchain, the monitoring parameters that hit the trigger conditions at different times are not fixed and may change, so the pruning mechanism is also dynamically changed. Compared with the traditional fixed pruning mechanism, this embodiment can start from multiple dimensions and hit the trigger conditions within a reasonable range, so that the pruning timing is reasonable.
[0053] Based on the above pruning mechanism, each block will generate a state change set, and the pruning thread needs to apply these state change sets to the physical ledger at the right time to achieve the effect of reducing physical storage space. In the above steps S201 to S203, during the blockchain node state change process, the key parameters are quantitatively monitored based on multiple dimensions to obtain multiple monitoring parameters. When any monitoring parameter hits the trigger condition, the state data of the blockchain node is persisted according to the state change set, which realizes the dynamic pruning mechanism, so as to find the right pruning time, make pruning reasonable, and improve the impact of blockchain state pruning on normal business performance.
[0054] In one embodiment, comparing each monitoring parameter with a corresponding threshold value may be achieved in the following manner:
[0055] When any of the monitoring parameters is not lower than the corresponding threshold, the trigger condition is determined to be hit. The monitoring parameters may include any two or three of the time-driven parameters, transaction accumulation parameters, and data capacity parameters. Among them, the time-driven parameter is used to characterize the time interval between the current time and the last persistence operation on the state data of the blockchain node; the transaction accumulation parameter is used to characterize the number of blocks added since the last persistence operation on the state data of the blockchain node; the data capacity parameter is used to characterize the amount of state data to be persisted at the current blockchain node. Accordingly, the threshold of the time-driven parameter may be a time threshold; the threshold of the transaction accumulation parameter may be a block number threshold; and the threshold of the data capacity parameter may be a data volume threshold.
[0056] In this embodiment, the considerations for the above three dimensional parameters are as follows:
[0057] Time-driven parameter: By monitoring this parameter, the time interval between the last time the blockchain node persisted the ledger and the current time can be kept within a certain range, which is convenient for ledger operations. It is conducive to regular operations such as checking the operation status of blockchain nodes, version upgrades, snapshot generation and verification, etc.
[0058] Transaction accumulation parameter: By monitoring this parameter, the distance between the block height of the last persistent ledger of the blockchain node and the current block height can be kept within a certain range, which is convenient for ledger operations. It is conducive to regularly checking the operation status of the chain node, upgrading the version, generating snapshots and verifying operations every certain number of blocks.
[0059] Data capacity parameter: Due to the characteristics of the key-value storage engine (KV), when the total size of the data flushed to the disk exceeds a certain threshold, it will cause an instantaneous performance degradation. By monitoring this parameter, the size of the state data to be persisted each time can be controlled within a certain range to ensure the instantaneous performance of the blockchain system.
[0060] Optionally, when comparing each monitoring parameter with the corresponding threshold, when the time-driven parameter is not less than the preset time threshold, it means that the time interval between the current time and the last persistence operation on the status data of the blockchain node is not less than the time threshold, then it can be determined that the trigger condition is hit.
[0061] Optionally, when comparing each monitoring parameter with the corresponding threshold, when the transaction accumulation parameter is not less than the preset block number threshold, it means that the number of newly added blocks since the last persistence operation on the status data of the blockchain node is not less than the block number threshold, then it can be determined that the trigger condition is hit.
[0062] Optionally, when comparing each monitoring parameter with the corresponding threshold, when the data capacity parameter is not less than the preset data volume threshold, it means that the data volume of the status data to be persisted at the blockchain node at the current time is not less than the data volume threshold, and it can be determined that the trigger condition is hit.
[0063] In some embodiments, when comparing each monitoring parameter with a corresponding threshold, when multiple monitoring parameters are not lower than the corresponding threshold, it can be determined that the trigger condition is hit. It can be understood that the situation of hitting the trigger condition is not unique and will not be repeated here.
[0064] The relevant technology uses Ethereum to build a state tree. At present, the common pruning mechanism is an offline pruning mechanism. When pruning, the Ethereum node needs to stop the service of the current node and restart the service after the pruning is completed. This will cause the blockchain node to be unable to provide normal business services to the outside world for a period of time. Because for the MPT (MerklePatricia Tree) tree used by Ethereum, it is impossible to accurately generate a pruning set after executing a block, because in the same MPT tree, there may be multiple paths that share a leaf node on the physical disk. Even if the reference to a leaf node is cancelled on a certain path, it is impossible to determine whether it can be actually deleted at the physical level. This is also the main reason why Ethereum cannot perform pruning at runtime. Specifically, in the MPT tree of Ethereum, a node may have multiple parent nodes. When the state is updated after each block is executed, when MPT is used as the state tree, to determine whether an old node can be pruned, a reference count is required to confirm that the node is not referenced by any other parent node before it can be deleted. However, in an ever-expanding blockchain system, it is impossible to maintain reference counts for each tree node in memory, and naturally it is impossible to prune at runtime.
[0065] In order to solve this problem, in one embodiment, the state data of the blockchain node is stored in a persistent storage space in a tree structure to form a state tree, and each child node in the state tree has only one unique parent node. The persistent storage space is a physical disk, that is, in the same state tree, there will not be multiple paths sharing a leaf node on the physical disk. Since each node has only one unique parent node, when updating the Merkle path where the node is located, all nodes on the old path can be directly deleted. Therefore, after executing the current block, those leaf nodes that have been dereferenced can be recorded in the pruning set. Exemplarily, this embodiment can use a JMT (JellyfishMerkle Tree) tree. Since there will not be multiple paths sharing a leaf node on the physical disk in the same JMT tree, the pruning mechanism used by Ethereum requires shutdown and reference counting, while the pruning mechanism of this embodiment can occur in the running state of the blockchain node, and does not require reference counting. Therefore, the JMT tree can also be applied to the dynamic pruning mechanism proposed in the above embodiment.
[0066] In one embodiment, before persisting the state data of the blockchain node according to the state change set, the method also includes: writing the state change set into a pruning log; persistently storing and caching the pruning logs respectively, and setting an index for the pruning log according to the block number of the execution block. For example, when a blockchain node executes a block transaction, the write set and pruning set of the state tree node generated by the current block are recorded to form a state change set for the current block. One copy of the state change set is packaged into a pruning log for persistent storage, and one copy is recorded in the memory cache, and can be accessed with the block number as the index. The pruning log can cope with the situation where the node process recovers after an abnormal crash, and the index facilitates the search for data.
[0067] In one embodiment, when a blockchain node executes a block transaction, it accesses the cached pruning log according to the index, and searches for the state value required to execute the transaction from the cached pruning log; if the state value does not exist in the cache, it searches for the state value required to execute the transaction from the state tree. For example, when a blockchain node executes the next block, if the execution layer finds that there is a state change set in the cache, it will first index back from the largest to the smallest block number, and try to find the state value required to execute the transaction from the cached state change set in sequence. If the required state value cannot be found in all the cached state change sets, it means that the state value has not changed in these blocks, so it will be searched in the state tree.
[0068] In one embodiment, when it is determined that any one of the monitoring parameters hits the trigger condition, when the state data of the blockchain node is persisted according to the state change set, the data in the pruning set is deleted from the state tree, and the data in the write set is inserted into the state tree. For example, when the blockchain node is started, a pruning thread is started in the background. According to the pruning mechanism of the above embodiment, the pruning thread can be indexed from small to large according to the block number, and the state data of the blockchain node can be refreshed based on the state change set in sequence, that is, the data in the pruning set is deleted from the state tree, and the data in the write set is inserted into the state tree.
[0069] In one embodiment, after the state data of the blockchain node is persisted according to the state change set, the pruning log corresponding to the state change set of the current blockchain node is deleted. This configuration can reduce the total capacity of the state change set accumulated in the memory, and at the same time, the pruning operation actually occurs on the state tree of persistent storage.
[0070] In one embodiment, when it is determined that none of the multiple monitoring parameters meets the trigger condition, the state change set of the blockchain node is scanned after a preset time interval to obtain multiple new monitoring parameters. For example, the pruning thread periodically scans all state change sets existing on the current node, and if the flushing condition (i.e., the trigger condition) is not met, it waits to enter the next round of scanning.
[0071] In one embodiment, a blockchain system is also provided. Figure 3 Schematic diagram of the blockchain system architecture of this embodiment. Figure 3 As shown, the system includes: a blockchain, a first execution module and a second execution module; wherein the blockchain includes multiple blockchain nodes; the first execution module is used to execute block transactions on the blockchain nodes; and the second execution module is used to execute the blockchain node status data processing method of the above embodiment on the blockchain nodes.
[0072] For example, in a blockchain system, a blockchain node may correspond to a blockchain process on a machine, the state tree is a data structure used by the storage module of the blockchain process, and the state tree node represents a component unit on the data structure. Each blockchain node is provided with a first execution module and a second execution module, wherein the first execution module is responsible for the transaction thread, and the second execution module is responsible for the pruning thread.
[0073] Although the present application provides the method operation steps as shown in the above embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative work. In the steps where there is no necessary causal relationship in logic, the execution order of these steps is not limited to the execution order provided in the embodiments of the present application. For example, in one embodiment, Figure 4 A flowchart of the operation of a blockchain system is provided, such as Figure 4 As shown in the figure, when the blockchain is running, it will continuously execute transactions in new blocks, apply the transaction execution results to the world state of the current ledger, and obtain a new world state. The state change information generated by each block can be recorded to form a state change set, and pruning can be performed based on the state change set. The specific process is as follows:
[0074] Step S301, the current blockchain node is started, and the transaction thread and pruning thread are opened in the background respectively, wherein the current blockchain node transaction thread is used to execute block transactions, record the write set and pruning set of the state tree node generated by the current block, and form the state change set of the current block. One copy of the state change set is packaged into a pruning log for persistent storage, and one copy is recorded in the memory cache and accessed with the block number as the index. Among them, the pruning log can cope with the situation of recovery after the node process crashes abnormally. The state data of the blockchain node is stored in a persistent storage space in a tree structure to form a state tree, and each child node in the state tree has only one unique parent node. For example, the state tree adopts the form of a JMT tree.
[0075] Step S302, when executing to the next blockchain node, if the execution layer finds that there is a state change set in the cache, it will first index back according to the block number from large to small, and try to find the state value required to execute the transaction from these state change sets in turn. If the required state value cannot be found in all state change sets, it means that the state value has not changed in these blocks, then go to the state tree to find it.
[0076] Step S303: The pruning thread scans the state change set of the current blockchain node to obtain multiple monitoring parameters.
[0077] Step S304, determine whether any of the monitoring parameters meets the trigger condition; if so, execute step S305; if not, return to step S303.
[0078] Step S305, indexing forward from small to large block numbers, and refreshing the state data of blockchain nodes based on the state change set in turn, that is, deleting the data in the pruning set in the state tree, and inserting the data in the writing set in the state tree.
[0079] Step S306, delete the pruning log corresponding to the state change set of the current blockchain node. This setting reduces the total size of the state change set accumulated in the memory, and at the same time makes the pruning operation actually occur on the blockchain state tree in persistent storage.
[0080] Based on the above pruning mechanism, each block will generate a set of state changes, and the pruning thread needs to apply these state change sets to the physical ledger at the right time to achieve the effect of reducing physical storage space. This embodiment comprehensively considers the three dimensions of time drive, transaction accumulation and data capacity, and the specific pruning mechanism is implemented as follows:
[0081] The pruning thread periodically scans all state change sets existing on the current node. If the flushing condition is not met, it waits to enter the next round of scanning. When the pruning thread scans that any of the monitoring parameters falls into the corresponding threshold range, the trigger condition is hit. That is: when the time-driven parameter is not less than the preset time threshold, it indicates that the time interval between the current time and the last persistence operation on the state data of the blockchain node is not less than the time threshold, and the trigger condition is hit. Or, when the transaction accumulation parameter is not less than the preset block number threshold, it indicates that the number of newly added blocks since the last persistence operation on the state data of the blockchain node is not less than the block number threshold, and the trigger condition is hit. Or, when the data capacity parameter is not less than the preset data volume threshold, it indicates that the data volume of the state data to be persisted on the blockchain node at the current time is not less than the data volume threshold, and the trigger condition is hit.
[0082] In this embodiment, the state tree can be continuously pruned during the operation of the blockchain node without stopping the node for pruning. At the same time, the pruning mechanism can be dynamically changed so that the node can be pruned only when it reaches the appropriate conditions. While ensuring the correctness of pruning, the performance impact of the pruning operation on the normal business of the blockchain node can be minimized.
[0083] In this embodiment, an electronic device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0084] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0085] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0086] Scan the state change set of blockchain nodes to obtain multiple monitoring parameters;
[0087] Determine whether any of the multiple monitoring parameters meets the trigger condition;
[0088] When it is determined that any monitoring parameter hits the trigger condition, the state data of the blockchain node is persisted according to the state change set.
[0089] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0090] In addition, in combination with the blockchain node status data processing method provided in the above embodiment, a storage medium can also be provided in this embodiment to implement. The storage medium stores a computer program; when the computer program is executed by the processor, any one of the blockchain node status data processing methods in the above embodiment is implemented.
[0091] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store a set of state changes of blockchain nodes. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for processing blockchain node state data is implemented.
[0092] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0093] It should be understood that the specific embodiments described above are only used to explain the relevant applications, rather than to limit them. According to the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of this application.
[0094] Obviously, the drawings are only some examples or embodiments of the present application. For ordinary technicians in the field, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that although the work done in this development process may be complicated and lengthy, for ordinary technicians in the field, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application.
[0095] The term "embodiment" in this application refers to a specific feature, structure or characteristic described in conjunction with the embodiment that can be included in at least one embodiment of the present application. The appearance of this phrase in various locations in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is clearly or implicitly understood by those of ordinary skill in the art that the embodiments described in this application can be combined with other embodiments without conflict.
[0096] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. The acquisition, storage, use, and processing of data involved in the embodiments of this application are in compliance with the relevant provisions of national laws and regulations.
[0097] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0098] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of patent protection. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the attached claims.
Claims
1. A blockchain node status data processing method, characterized in that: include: Scan the state change set of blockchain nodes to obtain multiple monitoring parameters; Determine whether any of the multiple monitoring parameters meets the trigger condition; When it is determined that any one of the monitoring parameters meets the trigger condition, a persistence operation is performed on the state data of the blockchain node according to the state change set; The monitoring parameters include at least one of the following: A time-driven parameter, which is used to represent the time interval between the current time and the last time a persistence operation was performed on the state data of the blockchain node; A transaction accumulation parameter, which is used to represent the number of blocks added since the last persistence operation was performed on the state data of the blockchain node; A data capacity parameter, which is used to characterize the amount of state data to be persisted for the blockchain node at the current time; The state change set includes a write set and a pruning set of state tree nodes generated when the blockchain node executes a block transaction; when it is determined that any monitoring parameter hits the trigger condition, the state data of the blockchain node is persisted according to the state change set, including: The data in the pruned set is deleted in the state tree, and the data in the write set is inserted in the state tree.
2. The blockchain node status data processing method according to claim 1 is characterized in that: The state data of the blockchain node is stored in a persistent storage space in a tree structure to form a state tree, and each child node in the state tree has only one unique parent node.
3. The blockchain node status data processing method according to claim 1 is characterized in that: Before performing a persistence operation on the state data of the blockchain node according to the state change set, the method further includes: Writing the state change set into a pruning log; The pruning log is persistently stored and cached respectively, and an index is set for the pruning log according to the block number of the execution block.
4. The blockchain node status data processing method according to claim 3 is characterized in that: After performing a persistence operation on the state data of the blockchain node according to the state change set, the method further includes: Delete the pruning log corresponding to the state change set of the current blockchain node.
5. The blockchain node status data processing method according to claim 3 is characterized in that: The method further comprises: When the blockchain node executes a block transaction, the cached pruning log is accessed according to the index, and a state value required to execute the transaction is found from the cached pruning log; If the state value does not exist in the cache, the state value required to execute the transaction is searched from the state tree.
6. The blockchain node status data processing method according to claim 1 is characterized in that: The method further comprises: When it is determined that none of the multiple monitoring parameters meets the trigger condition, after a preset time interval, the state change set of the blockchain node is scanned to obtain multiple new monitoring parameters.
7. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the blockchain node status data processing method according to any one of claims 1 to 6.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the blockchain node status data processing method described in any one of claims 1 to 6 are implemented.
