Main chain updating method and device, equipment, storage medium and product
By extracting candidate blocks with the same block height from the block pool in the blockchain, filtering the main chain blocks according to the weight value and hash value, the problem of blockchain forking and centralization is solved, and the problem of blockchain is realized Stable updates to blockchain.
Patent Information
- Application Number
- CN202410917102.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2044-07-09
AI Technical Summary
The prior art can easily lead to forks in blockchain, and the method of choosing a fork chain after forks can easily lead to blockchain centralization and affect system stability.
By extracting candidate blocks with the same block height from the block pool, filtering according to the block tag weight value and hash value, selecting reasonable main chain blocks, avoiding multiple blocks being updated at the same time, and ensuring the blockchain Stability of the main chain.
It effectively avoids the fork of the blockchain main chain, prevents system collapse and centralization trends, and ensures the stable operation of the blockchain.
Smart Images

Figure CN118921271A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a main chain updating method, device, equipment, storage medium and product. Background Art
[0002] Forking is a phenomenon in which blockchain technology changes at a certain moment. There are two main types of forks: soft forks and hard forks. Soft forks are backward-compatible protocol updates, and the old and new versions of the blockchain can coexist; while hard forks are not backward-compatible protocol updates, and the old and new versions of the blockchain cannot coexist. In the blockchain, the blockchain node will copy the block it obtained first, and then continue the new block generation work in this block. If two blockchain nodes in the blockchain are elected as block generation nodes at the same time, since the block data of each block generation node is different, the blocks they generate are correct, but the content of the blocks is different, which will cause the blockchain to fork. After the blockchain forks, each forked subchain is followed by several blocks.
[0003] When multiple blockchain nodes generate different blocks at the same time, it is easy to cause blockchain forks. The selection of forked chains is difficult. If different nodes select different forked chains, it is easy to cause the system to crash.
[0004] At present, in a blockchain including a main chain and at least two forked chains, the block production contribution of the block-producing node of the forked block in the forked chain in the main chain is determined, and the block production contribution is used as the block weight of the forked block; according to the block weight of the forked block, a target forked chain is selected from at least two forked chains for updating the main chain.
[0005] However, determining the block weight based on contribution will lead to the centralization of the system. If the block contribution is used as the block weight, the block weight generated by the node that produces more blocks will be greater, which will eventually lead to the concentration of the blockchain towards the nodes that produce more blocks, which is not conducive to the stability of the system. Summary of the invention
[0006] The main purpose of the present invention is to provide a main chain update method, device, equipment, storage medium and product, aiming to solve the technical problems that the existing technology easily leads to blockchain bifurcation and the method of selecting bifurcation connection after bifurcation easily leads to blockchain centralization.
[0007] To achieve the above object, the present invention provides a main chain update method, which is applied to a blockchain node. The main chain update method comprises the following steps:
[0008] Extracting at least one candidate block from a block pool, where the blocks in the block pool are set by a block-producing node in a blockchain, and the candidate blocks are blocks with the same block height;
[0009] Selecting a main chain block from the at least one candidate block according to the block label weight value and / or the block label corresponding to each candidate block;
[0010] The blockchain main chain is updated according to the main chain block.
[0011] Optionally, the step of selecting a main chain block from the at least one candidate block according to the block label weight value and / or the block label corresponding to each candidate block includes:
[0012] Obtaining a block label weight value corresponding to each candidate block, wherein the block label weight value is constructed according to the block label of the block and the node selection label corresponding to the block generation node generating the block;
[0013] Obtain the maximum value of the block label weight values corresponding to each candidate block to obtain the maximum label weight value;
[0014] Detecting whether the maximum label weight value corresponds to multiple candidate blocks;
[0015] If there are no corresponding candidate blocks, the candidate block corresponding to the maximum label weight value is used as the main chain block.
[0016] Optionally, after the step of detecting whether the maximum tag weight value corresponds to multiple candidate blocks, the step further includes:
[0017] If there are multiple candidate blocks, the candidate block corresponding to the maximum label weight value is used as the secondary screening block;
[0018] Perform hash calculations on the block labels corresponding to each secondary screening block to obtain the label hash values corresponding to each secondary screening block;
[0019] Obtaining the minimum value of the label hash values corresponding to the secondary screening blocks to obtain the minimum label hash value;
[0020] Detecting whether the minimum tag hash value corresponds to multiple secondary screening blocks;
[0021] If there are no corresponding secondary screening blocks, the secondary screening block corresponding to the minimum label hash value is used as the main chain block.
[0022] Optionally, after the step of detecting whether the minimum tag hash value corresponds to a plurality of secondary screening blocks, the step further includes:
[0023] If there are multiple secondary screening blocks, the secondary screening block corresponding to the minimum tag hash value is used as the tertiary screening block;
[0024] Generate a random number according to the block weight corresponding to each tertiary screening block, and obtain a verifiable random value corresponding to each tertiary screening block;
[0025] Obtaining the minimum value of the verifiable random values corresponding to each of the three screening blocks to obtain a minimum random value;
[0026] The three-times screened block corresponding to the minimum random value is used as the main chain block.
[0027] Optionally, before the step of obtaining at least one candidate block from the block pool, the step further includes:
[0028] If a multi-fork fault is detected in the blockchain, the forked sub-chain causing the multi-fork fault is obtained;
[0029] Accumulate the block label weight values corresponding to each subchain block in the forked subchain to obtain the accumulated weight value corresponding to each forked subchain;
[0030] The forked sub-chain with the largest corresponding cumulative weight value is used as the main chain of the blockchain.
[0031] Optionally, before the step of obtaining at least one candidate block from the block pool, the step further includes:
[0032] If a time offset fault is detected in the blockchain, the fault-causing block that caused the time offset fault is obtained;
[0033] Obtain the block label weight value corresponding to each block caused by the failure;
[0034] The block with the smallest corresponding block tag weight value causes the block to update the blockchain main chain.
[0035] Optionally, before the step of obtaining at least one candidate block from the block pool, the step further includes:
[0036] Perform connection detection on each block in the block pool;
[0037] If there is a target block in the block pool that cannot be connected to the parent block through the block tag and the duration reaches a preset duration threshold, the target block is removed from the block pool.
[0038] In addition, to achieve the above purpose, the present invention also proposes a main chain update device, which includes the following modules:
[0039] An acquisition module, configured to extract at least one candidate block from a block pool, wherein the blocks in the block pool are set by a block-producing node in a blockchain, and the candidate blocks are blocks having the same block height;
[0040] A selection module, configured to select a main chain block from the at least one candidate block according to a block label weight value and / or a block label corresponding to each candidate block;
[0041] An update module is used to update the blockchain main chain according to the main chain block.
[0042] In addition, to achieve the above-mentioned purpose, the present invention also proposes a main chain update device, which includes: a processor, a memory, and a main chain update program stored in the memory and executable on the processor, and the main chain update program implements the steps of the main chain update method described above when executed by the processor.
[0043] In addition, to achieve the above-mentioned purpose, the present invention also proposes a computer-readable storage medium, on which a main chain update program is stored, and when the main chain update program is executed, the steps of the main chain update method as described above are implemented.
[0044] In addition, to achieve the above-mentioned purpose, the present invention also proposes a computer program product, which includes a main chain update program, and when the main chain update program is executed, the steps of the main chain update method as described above are implemented.
[0045] The present invention extracts at least one candidate block from a block pool, wherein the blocks in the block pool are set by the block nodes in the blockchain, and the candidate blocks are blocks with the same block height; a main chain block is selected from at least one candidate block according to the block tag weight value and / or block tag corresponding to each candidate block; and the blockchain main chain is updated according to the main chain block. Since there are blocks with the same block height in the block pool, one is selected as the main chain block according to the block tag weight value and / or block tag corresponding to the candidate block, thereby avoiding using multiple blocks as the main chain blocks at the same time, ensuring that one block can be reasonably selected as the main chain block, so that when updating the blockchain main chain, it is updated only according to one block, thereby avoiding bifurcation of the blockchain main chain and avoiding the occurrence of corresponding faults. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 It is a schematic diagram of the structure of an electronic device in a hardware operating environment involved in an embodiment of the present invention;
[0047] Figure 2 It is a flowchart of the first embodiment of the main chain updating method of the present invention;
[0048] Figure 3 It is a flow chart of the second embodiment of the main chain updating method of the present invention;
[0049] Figure 4 A schematic diagram of the structure of a main chain update system according to an embodiment of the present invention;
[0050] Figure 5 It is a structural block diagram of the first embodiment of the main link updating device of the present invention.
[0051] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0052] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0053] Reference Figure 1 , Figure 1 It is a schematic diagram of the structure of the main chain update device of the hardware operating environment involved in the embodiment of the present invention.
[0054] like Figure 1 As shown, the electronic device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, WI-FI) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM), or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk storage. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0055] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0056] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a main link update program.
[0057] exist Figure 1In the electronic device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the electronic device of the present invention can be set in the main chain update device, and the electronic device calls the main chain update program stored in the memory 1005 through the processor 1001, and executes the main chain update method provided by the embodiment of the present invention.
[0058] The embodiment of the present invention provides a main chain update method, which is applied to a blockchain node, referring to Figure 2 , Figure 2 The figure is a flow chart of a first embodiment of a main chain updating method of the present invention.
[0059] In this embodiment, the main chain updating method includes the following steps:
[0060] Step S10: extract at least one candidate block from the block pool.
[0061] It should be noted that the executor of this embodiment can be the main chain update device, the main chain update device can be any blockchain node in the blockchain, the main chain update device can be a personal computer, server and other electronic devices, and can also be other devices that can achieve the same or similar functions. This embodiment does not limit this. In this embodiment and the following embodiments, the main chain update method of the present invention is described by taking the main chain update device as an example.
[0062] It should be noted that the block pool may store blocks waiting to be verified and packaged to be added to the blockchain, and each block may store corresponding blockchain data, such as transaction data, log data, etc. The blocks in the block pool are set by the block nodes in the blockchain, where the block nodes can be selected by each node in the blockchain through a consensus algorithm. For example, assuming that each node in the blockchain has a number from 1 to N, the consensus algorithm in the blockchain can generate a random integer, take the modulus of the random integer to N, and use the blockchain node with the same number as the modulus result as the block node.
[0063] In actual use, after selecting a block-producing node, the block-producing node can generate a new block and add the generated new block to the block pool. At this time, the block pool in each blockchain node will be synchronized with the block pool of the block-producing node.
[0064] For example, n nodes in a blockchain network hold their own node election labels (block node election label = VRF (block node worker private key, block node serial number), where VRF is a verifiable random function (Verifiable Random Functions, referred to as VRF)), participate in the equal probability random lottery consensus algorithm election calculation, and finally elect a block node, which generates a new block;
[0065] The generation process of the new block may include the following steps:
[0066] 1) The block label of the new block = VRF (the private key of the block-producing node, the previous block label & the node election label), which is used as the unique label of the block. Blocks are linked to each other by block labels for block sorting;
[0067] 2) The block-producing node calculates the block tag weight value based on the block tag;
[0068] Block label weight value = sha256 (block label + node election label of the block-producing node) % 100;
[0069] 3) The block-producing node generates a new block;
[0070] The block-producing node packs the current block label, election random number R, node election label (ElectionTicketRandomness) of the block-producing node, current block label weight value, address (public key) of the block-producing node, and all transaction data within the transaction time interval into the current block to generate a new block;
[0071] The block-producing node can push the newly generated current block into the block pool for storage, and synchronize it to the block pool of each blockchain node through the P2P (peer-to-peer lending, or peer-to-peer) protocol.
[0072] Among them, the block header and message are transmitted using the P2P protocol. The P2P protocol transmission is a protocol that adopts the publish-subscribe mode. After a node subscribes to a title, it will receive messages related to this title. When a node receives a message subscribed by the node, the node will run a processing process: 1. Pass the message to the application. 2. Pass the message to other nodes that the node knows and have subscribed to the same title;
[0073] The P2P protocol has a security mechanism that makes the protocol resilient and prevents attacks. The P2P protocol description provides all the design principles, implementation methods, protocol details, parameter settings, and the specific forms of subscription titles in the P2P protocol of the fork troubleshooting system based on block tag weight values and block tag sorting are fil / blocks / WinCount001 and fil / msgs / WinCount001. The block pool of each node synchronizes the blocks in the block pool by subscribing to fil / blocks / WinCount001, and the message pool of each node synchronizes the messages in the message pool by subscribing to fil / msgs / WinCount001.
[0074] It should be noted that candidate blocks are blocks with the same block height. Block height can be data used to identify the position of a block on the blockchain. If there are blocks with the same block height in the block pool, it means that the positions of multiple blocks on the blockchain main chain are basically the same in theory. At this time, one of them needs to be selected as the main chain block. Therefore, such blocks with the same block height in the block pool can be used as candidate blocks.
[0075] Step S20: selecting a main chain block from the at least one candidate block according to the block label weight value and / or the block label corresponding to each candidate block.
[0076] It should be noted that the block tag weight value is used to represent the weight of the block as a main chain block. The larger the block tag weight value, the higher the weight of the block as a main chain block.
[0077] In actual use, one can be selected from the candidate blocks as the main chain block based on the block label weight value and / or block label corresponding to each candidate block.
[0078] In a specific implementation, in order to avoid forks in the blockchain as much as possible, step S20 in this embodiment may include:
[0079] Obtain the block label weight value corresponding to each candidate block;
[0080] Obtain the maximum value of the block label weight values corresponding to each candidate block to obtain the maximum label weight value;
[0081] Detecting whether the maximum label weight value corresponds to multiple candidate blocks;
[0082] If there are no corresponding candidate blocks, the candidate block corresponding to the maximum label weight value is used as the main chain block.
[0083] It should be noted that the block label weight value is constructed according to the block label of the block and the node selection label corresponding to the block generation node that generates the block. The specific calculation method can refer to the relevant example of step S10 above, which will not be repeated here.
[0084] In actual use, the block label weight value is used to characterize the weight of the block as the main chain block. The larger the block label weight value, the higher the weight of the block as the main chain block. Therefore, in order to reasonably select the main chain block, the maximum value of the block label weight values corresponding to each candidate block can be calculated first to obtain the maximum label weight. Since there may be multiple blocks with the same block label weight value, after determining the maximum label weight, it is possible to first detect whether the maximum label weight corresponds to multiple candidate blocks.
[0085] In the specific implementation, if the maximum label weight does not correspond to multiple candidate blocks, it means that among the multiple blocks with consistent block heights in the block pool, there is a block whose corresponding block label weight value is higher than that of other blocks. Therefore, the candidate block corresponding to the maximum label weight value can be used as the main chain block, thereby ensuring that only one main chain block is selected. When the blockchain main chain is updated later, it is updated only according to one main chain block, avoiding forks in the blockchain main chain.
[0086] If the maximum label weight corresponds to multiple candidate blocks, it means that it is difficult to reasonably select the main chain block only by the block label weight value, and further judgment is required. At this time, after the step of detecting whether the maximum label weight value corresponds to multiple candidate blocks in this embodiment, the following may also be included:
[0087] If there are multiple candidate blocks, the candidate block corresponding to the maximum label weight value is used as the secondary screening block;
[0088] Perform hash calculations on the block labels corresponding to each secondary screening block to obtain the label hash values corresponding to each secondary screening block;
[0089] Obtaining the minimum value of the label hash values corresponding to the secondary screening blocks to obtain the minimum label hash value;
[0090] Detecting whether the minimum tag hash value corresponds to multiple secondary screening blocks;
[0091] If there are no corresponding secondary screening blocks, the secondary screening block corresponding to the minimum label hash value is used as the main chain block.
[0092] It should be noted that when performing hash calculations on the block labels corresponding to the secondary screening blocks respectively, the block labels corresponding to the secondary screening blocks can be used as parameters and input into the preset hash algorithm for hash calculation, so as to generate the label hash values corresponding to each secondary screening block, wherein the preset hash algorithm can be the sha256 algorithm, and of course, it can also be other algorithms with similar functions, which is not limited in this embodiment.
[0093] It can be understood that if the maximum label weight value corresponds to multiple candidate blocks, it means that among the multiple blocks with consistent block heights in the block pool at this time, there are at least two corresponding block label weight values that are consistent and are the maximum label weight values. At this time, it is difficult to select the main chain block by the block label weight value. At this time, further judgment can be made in combination with the label hash value of each block.
[0094] Similarly, after determining the minimum label hash value, it is necessary to further confirm whether there are multiple blocks with corresponding label hash values consistent with the minimum label hash value. Therefore, it is possible to further detect whether the minimum label hash value corresponds to multiple secondary screening blocks. If it does not correspond to multiple secondary screening blocks, it means that there is a block among the multiple blocks with consistent block heights, and its corresponding label hash value is smaller than the label hash values corresponding to other blocks. Therefore, this block can be used as the main chain block.
[0095] If the minimum label hash value corresponds to multiple secondary screening blocks, it means that the block labels of some blocks may be consistent, and it is difficult to judge based on the label hash value. In this case, after the step of detecting whether the minimum label hash value corresponds to multiple secondary screening blocks in this embodiment, the following is further included:
[0096] If there are multiple secondary screening blocks, the secondary screening block corresponding to the minimum tag hash value is used as the tertiary screening block;
[0097] Generate a random number according to the block weight corresponding to each tertiary screening block, and obtain a verifiable random value corresponding to each tertiary screening block;
[0098] Obtaining the minimum value of the verifiable random values corresponding to each of the three screening blocks to obtain a minimum random value;
[0099] The three-times screened block corresponding to the minimum random value is used as the main chain block.
[0100] It can be understood that if the minimum label hash value corresponds to multiple secondary screening blocks, it means that at this time it may be due to the consistency of the block labels of some blocks or the influence of other factors, resulting in the consistent label hash values of multiple blocks, all of which are the minimum label hash values. At this time, it is difficult to judge based on the label hash value, and further judgment is required in combination with other factors. At this time, a random number can be generated according to the block weight corresponding to each tertiary screening block to obtain a verifiable random value corresponding to each tertiary screening block.
[0101] In order to ensure the reasonable generation and verifiability of random numbers, the random number generation algorithm used at this time can be a verifiable random function (VRF). Of course, it can also be other algorithms with similar functions and effects, which is not limited in this embodiment.
[0102] It is understandable that, since random number generation is adopted, the verifiable random value corresponding to each tertiary screening block is almost impossible to be the same. Therefore, the minimum value of the verifiable random value, that is, the tertiary screening block corresponding to the minimum random value, can be directly used as the main chain block.
[0103] It should be noted that by adopting the above method and selecting the main chain block through multi-level screening, it can be ensured that after the main chain block is selected in this way, it is almost impossible for the blockchain to have a fork failure, and the blockchain fork can be avoided as much as possible.
[0104] Step S30: updating the blockchain main chain according to the main chain block.
[0105] It should be noted that updating the blockchain main chain according to the main chain block can be adding the main chain block to the end of the blockchain main chain. Of course, according to actual needs, other methods can also be used for updating, such as adding to the head or the middle, etc., which is not limited in this embodiment.
[0106] In a specific implementation, after the main chain block is selected, other blocks in the block pool that are consistent with the block height corresponding to the selected main chain block can also be removed.
[0107] This embodiment extracts at least one candidate block from a block pool, where blocks in the block pool are set by a block node in the blockchain, and candidate blocks are blocks with the same block height; a main chain block is selected from at least one candidate block according to the block tag weight value and / or block tag corresponding to each candidate block; and the blockchain main chain is updated according to the main chain block. Since there are blocks with the same block height in the block pool, one is selected as the main chain block according to the block tag weight value and / or block tag corresponding to the candidate block, thereby avoiding using multiple blocks as the main chain blocks at the same time, ensuring that one block can be reasonably selected as the main chain block, so that when updating the blockchain main chain, it is updated only according to one block, thereby avoiding bifurcation of the blockchain main chain and avoiding the occurrence of corresponding faults.
[0108] refer to Figure 3 , Figure 3 It is a flow chart of a second embodiment of a main chain updating method of the present invention.
[0109] Based on the first embodiment described above, the main chain updating method of this embodiment further includes, before step S10:
[0110] Step S01: If a multi-fork fault is detected in the blockchain, the forked sub-chain causing the multi-fork fault is obtained.
[0111] It should be noted that if the method for selecting the main chain block in the first embodiment is applied, the blockchain will hardly fork again, and fork failures can be avoided. However, before the method is applied, the blockchain may have forked, resulting in multiple fork failures. In this case, troubleshooting is required. Therefore, when a fork failure is detected in the blockchain, the forked sub-chain that caused the fork failure can be obtained.
[0112] For example: blockchain node E generates multiple blocks (such as two blocks) in the same block time period. The parent block sets of these blocks are different. In order to obtain the maximum benefit, a block of the current block time period will be generated for each block. At this time, multiple blockchain sub-chains will be generated. At this time, multiple blockchain sub-chains are generated, which are forked sub-chains that cause multi-fork failures.
[0113] Step S02: Accumulate the block label weight values corresponding to each sub-chain block in the forked sub-chain to obtain the accumulated weight values corresponding to each forked sub-chain.
[0114] Step S03: The forked sub-chain with the largest corresponding cumulative weight value is used as the blockchain main chain.
[0115] It should be noted that the blockchain main chain can be selected according to the weights corresponding to each forked sub-chain, and the blockchain main chain can be reasonably selected. The block label weight value corresponding to the sub-chain block contained in the forked sub-chain can represent the weight of the forked sub-chain. Therefore, the block label weight values corresponding to each sub-chain block in the forked sub-chain can be accumulated, and the accumulated sum can be used as the accumulated weight value corresponding to the forked sub-chain. Each forked sub-chain is processed separately, and the accumulated weight value corresponding to each forked sub-chain can be obtained.
[0116] It can be understood that the higher the weight corresponding to the forked sub-chain, the more reasonable it is to use it as the main chain of the blockchain, and the higher the cumulative weight value, the higher the weight corresponding to the forked sub-chain. Therefore, the forked sub-chain with the largest corresponding cumulative weight value can be used as the main chain of the blockchain.
[0117] Among them, the subchain blocks can be all the blocks contained in the forked subchain, or different blocks in each forked subchain. For example, assuming that there are forked subchains A and B, A contains blocks 1, 2, and 3, and B contains blocks 1, 4, and 5, then the block subchain corresponding to A can be 1, 2, and 3, or it can only include 2 and 3.
[0118] In actual use, when multiple fork failures occur, the blocks in the forked sub-chain may not have been assigned corresponding block labels and block label weight values. At this time, the corresponding block label weight value can also be generated based on the data contained in the block and the relevant information of the block-producing node that generated the block.
[0119] In a specific implementation, in order to ensure that other types of forks can also be processed, before step S10 in this embodiment, the following may also be included:
[0120] If a time offset fault is detected in the blockchain, the fault-causing block that caused the time offset fault is obtained;
[0121] Obtain the block label weight value corresponding to each block caused by the failure;
[0122] The block with the smallest corresponding block tag weight value causes the block to update the blockchain main chain.
[0123] It should be noted that if a time offset failure occurs, it means that two blocks in different block time periods are found in the same block set. At this time, the two blocks in different block time periods are the blocks that caused the failure.
[0124] In actual use, a blockchain node may generate two blocks in the same block time period. Their parent block sets are the same, but the block time periods are different. This is because the time offset causes two random numbers to be obtained in a very short period of time, resulting in different block time periods. At this time, the block with the smaller number of rounds can be used as the main block. Therefore, the block label weight value corresponding to the fault-causing block can be obtained, and the blockchain main chain can be updated according to the fault-causing block with the smallest block label weight value (such as removing other fault-causing blocks in the blockchain main chain except the fault-causing block with the smallest block label weight value from the blockchain main chain), thereby ensuring that the time offset fault of the blockchain can be eliminated.
[0125] In a specific implementation, in order to ensure that other types of faults can also be processed, before step S10 in this embodiment, the following may also be included:
[0126] Perform connection detection on each block in the block pool;
[0127] If there is a target block in the block pool that cannot be connected to the parent block through the block tag and the duration reaches a preset duration threshold, the target block is removed from the block pool.
[0128] It should be noted that the parent block corresponding to a block can be a block directly linked to the block and with a smaller block height. For example, assuming that in the constructed block sub-chain, the block height of block B is smaller than that of block A, and block B is directly connected to block A, then block A is the parent block of block B.
[0129] In actual use, if the parent block corresponding to a block is lost (it may be due to a failure or data anomaly that causes some blocks to be cleared), then the subsequent blocks constructed on this basis may cause blockchain anomalies, resulting in a parent block loss failure. In order to avoid this phenomenon, a connection test can be performed on each block in the block pool to determine whether a link can be established between the blocks. Whether a link can be established between blocks can be determined through block labels. For example, block A can access block B through the block label of block B, thereby trying to establish a link.
[0130] If there are blocks in the block pool that cannot be connected to the parent block through the block tag and the duration reaches the preset duration threshold, it means that the parent block corresponding to the block has been lost. At this time, such blocks can be used as target blocks and removed from the block pool.
[0131] It should be noted that fault handling does not necessarily have to be performed before the execution of the main chain update method provided in this embodiment, but can also be performed during its execution or after its execution. Therefore, the fault-related steps mentioned in this embodiment (such as steps S01-S03) can be executed before or after any of the above steps S10-S30, and this embodiment does not impose any restrictions on this.
[0132] For ease of understanding, now combined Figure 4 This is for illustration only, but not for limitation. Figure 4 Schematic diagram of the structure of the main chain update system of this embodiment.
[0133] like Figure 4 As shown, the main chain update system includes a block node selection module, a block generation module, a block synchronization module, a candidate sub-chain selection algorithm module and a fork fault processing module.
[0134] The block node selection module is used to select the block node through the equal probability random lottery consensus algorithm (that is, the algorithm for selecting the block node through random number modulus as mentioned above);
[0135] The block generation module is used to generate new blocks and add them to the block pool;
[0136] The block synchronization module is used to synchronize the block pools of each blockchain node;
[0137] The candidate subchain selection algorithm module is used to select the main chain block. Its screening rules are divided into three layers, namely, block label weight value screening (i.e., selecting the candidate block corresponding to the maximum label weight value as the main chain block), block label screening (i.e., selecting the candidate block as the main chain block), and verifiable random function screening (i.e., selecting the three-times screened block corresponding to the minimum random value as the main chain block). The specific execution process can refer to the above description and will not be repeated here;
[0138] The fork fault handling module is used to handle the faults that have occurred in the blockchain. The faults that can be handled include multiple fork faults, time offset faults, and parent block loss faults. Of course, if necessary, other types of faults can also be handled after making corresponding settings;
[0139] Among them, each blockchain node in the blockchain will execute the relevant functions of the block node selection module, block synchronization module, candidate sub-chain selection algorithm module and fork fault handling module, while the block generation module is only executed by the blockchain node selected as the block node.
[0140] The related functions of the fork fault handling module do not necessarily need to be executed after the candidate sub-chain selection algorithm module is executed. It can be executed before or after the execution of any of the above-mentioned block node selection module, block generation module, block synchronization module, and candidate sub-chain selection algorithm module.
[0141] This embodiment performs corresponding fault detection on the blockchain, and when a fault is found, it distinguishes the faults according to their types and handles them in corresponding ways, thereby ensuring that when a fault occurs in the blockchain, the fault can be eliminated and the blockchain can be restored to normal operation.
[0142] In addition, an embodiment of the present invention further proposes a storage medium, on which a main chain update program is stored. When the main chain update program is executed by a processor, the steps of the main chain update method described above are implemented.
[0143] In addition, an embodiment of the present invention further proposes a computer program product, which includes a main chain update program, and when the main chain update program is executed by a processor, the steps of the main chain update method described above are implemented.
[0144] Reference Figure 5 , Figure 5 It is a structural block diagram of the first embodiment of the main link updating device of the present invention.
[0145] like Figure 5 As shown, the main chain updating device proposed in the embodiment of the present invention includes:
[0146] An acquisition module 10 is used to extract at least one candidate block from a block pool, where the blocks in the block pool are set by a block-producing node in a blockchain, and the candidate blocks are blocks with the same block height;
[0147] A selection module 20, configured to select a main chain block from the at least one candidate block according to a block label weight value and / or a block label corresponding to each candidate block;
[0148] The updating module 30 is used to update the blockchain main chain according to the main chain block.
[0149] This embodiment extracts at least one candidate block from a block pool, where blocks in the block pool are set by a block node in the blockchain, and candidate blocks are blocks with the same block height; a main chain block is selected from at least one candidate block according to the block tag weight value and / or block tag corresponding to each candidate block; and the blockchain main chain is updated according to the main chain block. Since there are blocks with the same block height in the block pool, one is selected as the main chain block according to the block tag weight value and / or block tag corresponding to the candidate block, thereby avoiding using multiple blocks as the main chain blocks at the same time, ensuring that one block can be reasonably selected as the main chain block, so that when updating the blockchain main chain, it is updated only according to one block, thereby avoiding bifurcation of the blockchain main chain and avoiding the occurrence of corresponding faults.
[0150] Optionally, the selection module 20 is further used to obtain a block label weight value corresponding to each candidate block, wherein the block label weight value is constructed according to the block label of the block and the node selection label corresponding to the block generation node of the generated block; obtain the maximum value of the block label weight values corresponding to each candidate block to obtain a maximum label weight value; detect whether the maximum label weight value corresponds to multiple candidate blocks; if it does not correspond to multiple candidate blocks, the candidate block corresponding to the maximum label weight value is used as the main chain block.
[0151] Optionally, the selection module 20 is also used to, if it corresponds to multiple candidate blocks, use the candidate block corresponding to the maximum label weight value as the secondary screening block; perform hash calculations on the block labels corresponding to each secondary screening block to obtain the label hash value corresponding to each secondary screening block; obtain the minimum value among the label hash values corresponding to each secondary screening block to obtain the minimum label hash value; detect whether the minimum label hash value corresponds to multiple secondary screening blocks; if it does not correspond to multiple secondary screening blocks, use the secondary screening block corresponding to the minimum label hash value as the main chain block.
[0152] Optionally, the selection module 20 is also used to, if it corresponds to multiple secondary screening blocks, use the secondary screening block corresponding to the minimum label hash value as the tertiary screening block; generate a random number according to the block weight corresponding to each tertiary screening block, and obtain a verifiable random value corresponding to each tertiary screening block; obtain the minimum value of the verifiable random values corresponding to each tertiary screening block to obtain a minimum random value; and use the tertiary screening block corresponding to the minimum random value as the main chain block.
[0153] Optionally, the main chain updating device further includes a troubleshooting module;
[0154] The troubleshooting module is also used to obtain the forked sub-chain that causes the multi-fork fault if a multi-fork fault is detected in the blockchain; accumulate the block label weight values corresponding to each sub-chain block in the forked sub-chain to obtain the accumulated weight value corresponding to each forked sub-chain; and use the forked sub-chain with the largest corresponding accumulated weight value as the blockchain main chain.
[0155] Optionally, the troubleshooting module is also used to obtain the fault-causing block that causes the time offset fault if a time offset fault is detected in the blockchain; obtain the block label weight value corresponding to each fault-causing block; and update the blockchain main chain according to the fault-causing block with the smallest corresponding block label weight value.
[0156] Optionally, the troubleshooting module is also used to perform connection detection on each block in the block pool; if there is a target block in the block pool that cannot be connected to the parent block through the block tag and the duration reaches a preset duration threshold, the target block is removed from the block pool.
[0157] It should be understood that the above is only an example and does not constitute any limitation on the technical solution of the present invention. In specific applications, technicians in this field can make settings as needed, and the present invention does not limit this.
[0158] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of them according to actual needs to achieve the purpose of the present embodiment, and no limitation is made here.
[0159] In addition, for technical details not fully described in this embodiment, reference can be made to the main chain updating method provided in any embodiment of the present invention, and will not be repeated here.
[0160] In addition, it should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0161] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0162] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0163] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A main chain update method, characterized in that: Applied to a blockchain node, the main chain update method comprises the following steps: Extracting at least one candidate block from a block pool, where the blocks in the block pool are set by a block-producing node in a blockchain, and the candidate blocks are blocks with the same block height; Selecting a main chain block from the at least one candidate block according to the block label weight value and / or the block label corresponding to each candidate block; The blockchain main chain is updated according to the main chain block.
2. The main chain updating method according to claim 1, characterized in that: The step of selecting a main chain block from the at least one candidate block according to the block label weight value and / or the block label corresponding to each candidate block includes: Obtaining a block label weight value corresponding to each candidate block, wherein the block label weight value is constructed according to the block label of the block and the node selection label corresponding to the block generation node generating the block; Obtain the maximum value of the block label weight values corresponding to each candidate block to obtain the maximum label weight value; Detecting whether the maximum label weight value corresponds to multiple candidate blocks; If there are no corresponding candidate blocks, the candidate block corresponding to the maximum label weight value is used as the main chain block.
3. The main chain updating method according to claim 2, characterized in that: After the step of detecting whether the maximum tag weight value corresponds to multiple candidate blocks, the method further includes: If there are multiple candidate blocks, the candidate block corresponding to the maximum label weight value is used as the secondary screening block; Perform hash calculations on the block labels corresponding to each secondary screening block to obtain the label hash values corresponding to each secondary screening block; Obtaining the minimum value of the label hash values corresponding to the secondary screening blocks to obtain the minimum label hash value; Detecting whether the minimum tag hash value corresponds to multiple secondary screening blocks; If there are no corresponding secondary screening blocks, the secondary screening block corresponding to the minimum label hash value is used as the main chain block.
4. The main chain updating method according to claim 3, characterized in that: After the step of detecting whether the minimum tag hash value corresponds to a plurality of secondary screening blocks, the method further includes: If there are multiple secondary screening blocks, the secondary screening block corresponding to the minimum tag hash value is used as the tertiary screening block; Generate a random number according to the block weight corresponding to each tertiary screening block, and obtain a verifiable random value corresponding to each tertiary screening block; Obtaining the minimum value of the verifiable random values corresponding to each of the three screening blocks to obtain a minimum random value; The three-times screened block corresponding to the minimum random value is used as the main chain block.
5. The main chain updating method according to any one of claims 1 to 4, characterized in that: Before the step of obtaining at least one candidate block from the block pool, the method further includes: If a multi-fork fault is detected in the blockchain, the forked sub-chain causing the multi-fork fault is obtained; Accumulate the block label weight values corresponding to each subchain block in the forked subchain to obtain the accumulated weight value corresponding to each forked subchain; The forked sub-chain with the largest corresponding cumulative weight value is used as the main chain of the blockchain.
6. The main chain updating method according to any one of claims 1 to 4, characterized in that: Before the step of obtaining at least one candidate block from the block pool, the method further includes: If a time offset fault is detected in the blockchain, the fault-causing block that caused the time offset fault is obtained; Obtain the block label weight value corresponding to each block caused by the failure; The block with the smallest corresponding block tag weight value causes the block to update the blockchain main chain.
7. The main chain updating method according to any one of claims 1 to 4, characterized in that: Before the step of obtaining at least one candidate block from the block pool, the method further includes: Perform connection detection on each block in the block pool; If there is a target block in the block pool that cannot be connected to the parent block through the block tag and the duration reaches a preset duration threshold, the target block is removed from the block pool.
8. A main chain updating device, characterized in that: The main chain updating device includes the following modules: An acquisition module, configured to extract at least one candidate block from a block pool, wherein the blocks in the block pool are set by a block-producing node in a blockchain, and the candidate blocks are blocks having the same block height; A selection module, configured to select a main chain block from the at least one candidate block according to a block label weight value and / or a block label corresponding to each candidate block; An update module is used to update the blockchain main chain according to the main chain block.
9. A main chain update device, characterized in that: The main chain update device includes: a processor, a memory, and a main chain update program stored in the memory and executable on the processor. When the main chain update program is executed by the processor, the steps of the main chain update method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a main chain update program, and when the main chain update program is executed, the steps of the main chain update method according to any one of claims 1 to 7 are implemented.
11. A computer program product, characterized in that The computer program product includes a main chain update program, and when the main chain update program is executed, the steps of the main chain update method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Consensus verification method, check node and block chain system
CN110875893A
Block chain main chain determination method, device and equipment, and storage medium
CN111737358A
Block chain updating method and device, storage medium and electronic equipment
CN111738718A
Method and device for adjusting block generation difficulty, equipment and storage medium
CN114285860A
Method and apparatus for decentralized trust evaluation in a distributed network
US20210160056A1
