Main chain updating method, device, equipment, storage medium and product

By filtering block tag weights and hash calculations in the block pool and combining them with random number generation, the problems of blockchain forks and centralization are solved, and stable updates of the blockchain are achieved.

CN118921271BActive Publication Date: 2025-12-12CHINA MOBILE INFORMATION TECHNOLOGY CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410917102.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-09
Publication Date
2025-12-12
Estimated Expiration
2044-07-09

AI Technical Summary

Technical Problem

Existing technologies can easily lead to system forks and centralization during the blockchain fork selection process, resulting in blockchain instability.

Method used

By extracting candidate blocks with the same block height from the block pool, filtering them based on block tag weight value and/or block tag, and selecting the main chain block, and combining hash calculation and random number generation, the selection of a unique main chain block is ensured, avoiding multiple blocks from being updated at the same time.

Benefits of technology

It effectively avoids forks in the blockchain main chain, improves system stability, prevents system crashes, and ensures reasonable updates to the blockchain.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118921271B_ABST
    Figure CN118921271B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of blockchains, and discloses a main chain updating method, device, equipment, storage medium and product. The application extracts at least one candidate block from a block pool, the blocks in the block pool are set by block nodes in a blockchain, and the candidate blocks are blocks with the same block height; a main chain block is selected from the at least one candidate block according to the block label weight values and / or block labels corresponding to the candidate blocks; and the blockchain main chain is updated according to the main chain block. Since the blocks with the same block height exist in the block pool, one of the blocks is selected as the main chain block according to the block label weight values and / or block labels corresponding to the candidate blocks, so that the problem of simultaneously taking multiple blocks as the main chain block is avoided, a block can be reasonably selected as the main chain block, the blockchain main chain is updated only according to one block when the blockchain main chain is updated, and the problem of the blockchain main chain being forked is avoided, so that the corresponding fault is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of blockchain, in particular to a main chain updating method, device, equipment, storage medium and product. BACKGROUND

[0002] Fork is a phenomenon of change at a certain time in the blockchain technology. There are mainly two types of forks: soft fork and hard fork. The soft fork is a backward compatible protocol update, and the new and old versions of the blockchain can coexist. The hard fork is a protocol update that is not backward compatible, and the new and old versions of the blockchain cannot coexist. The blockchain node in the blockchain will copy the block obtained first, and then continue the block generation work on 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 generated by them are correct, but the contents of the blocks are different, which will cause the fork of the blockchain. After the blockchain forks, each forked sub-chain is followed by a number of blocks.

[0003] When multiple blockchain nodes generate different blocks at the same time, it is easy to cause the blockchain to fork, and it is difficult to select the forked chain. 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 generation contribution degree of the block generation node of the forked block in the forked chain in the main chain is determined, and the block generation contribution degree 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 the at least two forked chains for updating the main chain.

[0005] However, determining the block weight according to the contribution degree will cause the centralization of the system. If the block generation contribution degree is used as the block weight, the block weight generated by the node with more block generation will be larger, which will eventually cause the blockchain to concentrate on the node with more block generation, and is not conducive to the stability of the system. SUMMARY

[0006] The main purpose of the present application is to provide a main chain updating method, device, equipment, storage medium and product, which aims to solve the technical problems that the prior art is easy to cause the blockchain to fork, and the way of selecting the forked chain after the fork is easy to cause the centralization of the blockchain.

[0007] To achieve the above purpose, the present application provides a main chain updating method applied to a blockchain node, the main chain updating method comprising the following steps:

[0008] Extracting at least one candidate block from a block pool, the blocks in the block pool being set by a block generation node in the blockchain, and the candidate block being a block 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 corresponding to each candidate block and / or the block label;

[0010] updating the block chain main chain 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 corresponding to each candidate block and / or the block label comprises:

[0012] obtaining the block label weight value corresponding to each candidate block, the block label weight value being constructed according to the block label of the block and the node selection label corresponding to the block generation node of the block;

[0013] obtaining the maximum value in the block label weight value corresponding to each candidate block, to obtain a maximum label weight value;

[0014] detecting whether the maximum label weight value corresponds to multiple candidate blocks;

[0015] if the maximum label weight value does not correspond to multiple candidate blocks, taking the candidate block corresponding to the maximum label weight value as the main chain block.

[0016] Optionally, after the step of detecting whether the maximum label weight value corresponds to multiple candidate blocks, the method further comprises:

[0017] if the maximum label weight value corresponds to multiple candidate blocks, taking the candidate block corresponding to the maximum label weight value as a secondary screening block;

[0018] respectively performing hash calculation on the block label corresponding to each secondary screening block to obtain a label hash value corresponding to each secondary screening block;

[0019] obtaining the minimum value in the label hash value corresponding to each secondary screening block, to obtain a minimum label hash value;

[0020] detecting whether the minimum label hash value corresponds to multiple secondary screening blocks;

[0021] if the minimum label hash value does not correspond to multiple secondary screening blocks, taking the secondary screening block corresponding to the minimum label hash value as the main chain block.

[0022] Optionally, after the step of detecting whether the minimum label hash value corresponds to multiple secondary screening blocks, the method further comprises:

[0023] if the minimum label hash value corresponds to multiple secondary screening blocks, taking the secondary screening block corresponding to the minimum label hash value as a tertiary screening block;

[0024] generating a random number according to the block weight corresponding to each tertiary screening block to obtain a verifiable random number value corresponding to each tertiary screening block;

[0025] Obtaining the minimum value in the verifiable random values corresponding to the three screening blocks, to obtain a minimum random value;

[0026] Taking the three screening block corresponding to the minimum random value as the main chain block.

[0027] Optionally, before the step of obtaining at least one candidate block from the block pool, the method further comprises:

[0028] If a multi-fork fault is detected in the block chain, a fork sub-chain causing the multi-fork fault is obtained;

[0029] The block tag weight values corresponding to each sub-chain block in the fork sub-chain are accumulated to obtain an accumulated weight value corresponding to each fork sub-chain;

[0030] The fork sub-chain with the largest corresponding accumulated weight value is taken as the main chain of the block chain.

[0031] Optionally, before the step of obtaining at least one candidate block from the block pool, the method further comprises:

[0032] If a time offset fault is detected in the block chain, a fault-causing block causing the time offset fault is obtained;

[0033] The block tag weight values corresponding to each fault-causing block are obtained;

[0034] The main chain of the block chain is updated according to the fault-causing block with the smallest corresponding block tag weight value.

[0035] Optionally, before the step of obtaining at least one candidate block from the block pool, the method further comprises:

[0036] Each block in the block pool is subjected to connection detection;

[0037] If there is a target block in the block pool that cannot be linked to a parent block through a 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-mentioned purpose, the application further provides a main chain updating device, which comprises the following modules:

[0039] An obtaining module is configured to extract at least one candidate block from a block pool, wherein the blocks in the block pool are set by a block node in a block chain, and the candidate blocks are blocks with the same block height;

[0040] A selecting module is configured to select a main chain block from the at least one candidate block according to the block tag weight values and / or block tags corresponding to each candidate block;

[0041] an updating module configured to update the main chain of the block chain according to the main chain block.

[0042] In addition, to achieve the above object, the present application also provides a main chain updating device, which comprises a processor, a memory and a main chain updating program stored in the memory and executable on the processor, and the main chain updating program implements the steps of the main chain updating method when executed by the processor.

[0043] In addition, to achieve the above object, the present application also provides a computer readable storage medium, which stores a main chain updating program, and the main chain updating program implements the steps of the main chain updating method when executed.

[0044] In addition, to achieve the above object, the present application also provides a computer program product, which comprises a main chain updating program, and the main chain updating program implements the steps of the main chain updating method when executed.

[0045] The present application extracts at least one candidate block from a block pool, the blocks in the block pool are set by block nodes in the block chain, and the candidate blocks are blocks with the same block height; selects a main chain block from the at least one candidate block according to the block label weight value and / or block label corresponding to each candidate block; and updates the main chain of the block chain according to the main chain block. Since the blocks with the same block height in the block pool are selected as the main chain block according to the block label weight value and / or block label corresponding to the candidate block, the present application avoids selecting multiple blocks as the main chain block at the same time, ensures that a block can be reasonably selected as the main chain block, and enables the block chain main chain to be updated according to only one block when the block chain main chain is updated, thereby avoiding the occurrence of the block chain main chain bifurcation and the corresponding failure. BRIEF DESCRIPTION OF DRAWINGS

[0046] Figure 1 is a structural schematic diagram of an electronic device of a hardware running environment related to an embodiment scheme of the present application;

[0047] Figure 2 is a flowchart of a first embodiment of the main chain updating method of the present application;

[0048] Figure 3 is a flowchart of a second embodiment of the main chain updating method of the present application;

[0049] Figure 4 is a structural schematic diagram of a main chain updating system of an embodiment of the present application;

[0050] Figure 5 is a structural block diagram of a first embodiment of the main chain updating device of the present application.

[0051] The implementation, functional features and advantages of the present application will be further illustrated with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION

[0052] It should be understood that the specific embodiments described herein merely exemplify the application and do not limit the application.

[0053] Reference Figure 1 , Figure 1 The main chain updating device structure diagram of the hardware running environment involved in the embodiment of the present application.

[0054] As Figure 1 shown, the electronic device can 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. The communication bus 1002 is used to realize the connection and communication between the components. The user interface 1003 can include a display screen, an input unit such as a keyboard, and can also include a standard wired interface, a wireless interface. The network interface 1004 can optionally include a standard wired interface, a wireless interface (such as a wireless fidelity (WI-FI) interface). The memory 1005 can be a high-speed random access memory (RAM), and can also be a stable non-volatile memory (NVM), such as a disk memory. The memory 1005 can also be a storage device independent of the aforementioned processor 1001.

[0055] Those skilled in the art can understand that Figure 1 the structure shown in the figure does not constitute a limitation on the electronic device, and can include more or fewer components than the figure, or combine certain components, or different component arrangements.

[0056] As Figure 1 shown, the memory 1005 as a storage medium can include an operating system, a network communication module, a user interface module, and a main chain updating program.

[0057] In Figure 1The network interface 1004 is mainly used for data communication with a network server, and the user interface 1003 is mainly used for data interaction with a user. The processor 1001 and the memory 1005 in the electronic device can be arranged in the main chain updating device, and the electronic device calls the main chain updating program stored in the memory 1005 through the processor 1001, and executes the main chain updating method provided in the embodiment of the application.

[0058] The embodiment of the application provides a main chain updating method, which is applied to a block chain node, and the method comprises the steps of Figure 2 , Figure 2 FIG. 1 is a flowchart of a first embodiment of the main chain updating method.

[0059] In the embodiment, the main chain updating method comprises the following steps:

[0060] Step S10: extracting at least one candidate block from a block pool.

[0061] It should be noted that the execution subject of the embodiment can be the main chain updating device, the main chain updating device can be any block chain node in the block chain, the main chain updating device can be a personal computer, a server or other electronic devices, and can also be other devices that can realize the same or similar functions, and the embodiment does not limit this. In the embodiment and the following embodiments, the main chain updating device is taken as an example to describe the main chain updating method.

[0062] It should be noted that the block pool can store blocks waiting to be verified and packed and added to the block chain, and each block can store corresponding block chain data, such as transaction data, log data and the like. The blocks in the block pool are set by a block node in the block chain, wherein the block node can be selected by each node in the block chain through a consensus algorithm, for example: assuming that each node in the block chain has a number, the number is from 1 to N, and then the consensus algorithm in the block chain can generate a random integer, and the block chain node with the same number and the modulo result is taken as the block node.

[0063] In actual use, after the block node is selected, the block node can generate a new block and add the generated new block to the block pool, and at this time, the block pool in each block chain node is synchronized with the block pool of the block node.

[0064] For example, n nodes in the blockchain network hold their own node election label (block node election label = VRF (block node worker private key, block node serial number), wherein VRF is a verifiable random function (Verifiable Random Functions, VRF for short)), participate in the equal probability random draw consensus algorithm election calculation, and finally elect a block node, which generates a new block;

[0065] The generation process of the new block can include the following steps:

[0066] 1) The block label of the new block = VRF (block node private key, previous block label & node election label), as the unique label of the block, the blocks are linked by the block label for block sorting;

[0067] 2) The block node calculates the block label weight value according to the block label;

[0068] Block label weight value = sha256 (block label + block node node election label) % 100;

[0069] 3) The block node generates a new block;

[0070] The block node packs the current block label, the election random number R, the block node election label (ElectionTicketRandomness), the current block label weight value, the address (public key) of the block node, and all transaction data in the transaction time interval into the current block to generate a new block;

[0071] The block 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 the message are propagated by the P2P protocol, and the P2P protocol propagation is a protocol using the publish / subscribe mode. After a node subscribes to a title, it will accept messages related to the title. When the node accepts the 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 subscribe to the same title known to this node;

[0073] The P2P protocol has a security mechanism, which makes the protocol elastic and prevents attacks. The P2P protocol specification provides all design principles, implementation methods, protocol details, parameter settings, and specific forms of the subscription title in the P2P protocol based on the block tag weight value and the block tag sorting-based fork troubleshooting system, which 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 the candidate blocks are blocks with the same block height. The block height can be data used to identify the position of the block on the chain in the block chain. If there are blocks with the same block height in the block pool, it means that multiple blocks are theoretically consistent in the position on the main chain of the block chain at this time, and therefore, one of them needs to be selected as the main chain block. Therefore, the 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 tag weight value and / or the block tag 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 the main chain block. The greater the block tag weight value, the higher the weight of the block as the main chain block.

[0077] In actual use, one of the candidate blocks can be selected as the main chain block according to the block tag weight value and / or the block tag corresponding to each candidate block.

[0078] In a specific implementation, in order to avoid the block chain from branching as much as possible, the step S20 described in the embodiment can include:

[0079] obtaining the block tag weight value corresponding to each candidate block;

[0080] obtaining the maximum value in the block tag weight value corresponding to each candidate block, and obtaining the maximum tag weight value;

[0081] detecting whether the maximum tag weight value corresponds to multiple candidate blocks;

[0082] If the maximum tag weight value does not correspond to multiple candidate blocks, the candidate block corresponding to the maximum tag 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 generating the block. The specific calculation method can refer to the above example description of step S10, which will not be repeated here.

[0084] In actual use, the block label weight value is used to represent the weight of the block as the main chain block. The greater 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 in the block label weight value corresponding to each candidate block can be calculated first to obtain the maximum label weight. Since there can be multiple blocks with the same block label weight value, after determining the maximum label weight, it can be detected whether the maximum label weight corresponds to multiple candidate blocks.

[0085] In a specific implementation, if the maximum label weight does not correspond to multiple candidate blocks, it means that among the multiple blocks with the same block height 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 selected as the main chain block, so as to ensure that there is only one main chain block. After updating the main chain of the block chain, only one main chain block is used for updating, thereby avoiding the bifurcation of the main chain of the block 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 needed. Therefore, after the step of detecting whether the maximum label weight value corresponds to multiple candidate blocks, the embodiment can further include:

[0087] If it corresponds to multiple candidate blocks, the candidate block corresponding to the maximum label weight value is selected as a secondary screening block.

[0088] The block label corresponding to each secondary screening block is respectively subjected to hash calculation to obtain a label hash value corresponding to each secondary screening block.

[0089] The minimum value in the label hash value corresponding to each secondary screening block is obtained to obtain a minimum label hash value.

[0090] It is detected whether the minimum label hash value corresponds to multiple secondary screening blocks.

[0091] If it does not correspond to multiple secondary screening blocks, the secondary screening block corresponding to the minimum label hash value is selected as the main chain block.

[0092] It should be noted that when the block labels corresponding to the secondary screening blocks are respectively subjected to hash calculation, the block labels corresponding to the secondary screening blocks can be taken as parameters and respectively input into a preset hash algorithm for hash calculation, so as to generate the label hash values corresponding to the secondary screening blocks, wherein the preset hash algorithm can be a sha256 algorithm, of course, it can also be other similar algorithms, and the present embodiment does not limit this.

[0093] It can be understood that if the maximum label weight value corresponds to multiple candidate blocks, it means that at this time, in the multiple blocks with consistent block heights in the block pool, at least two corresponding block label weight values are consistent and are the maximum label weight value, and at this time it is difficult to select the main chain block through the block label weight value. At this time, further judgment can be made in combination with the label hash values of the blocks.

[0094] Similarly, after determining the minimum label hash value, it is further necessary to confirm whether there are multiple blocks with the same label hash value as the minimum label hash value, therefore, it is further necessary to detect whether the minimum label hash value corresponds to multiple secondary screening blocks, and if it does not correspond to multiple secondary screening blocks, it means that at this time, in the multiple blocks with consistent block heights, there is one block whose corresponding label hash value is smaller than that of other blocks, therefore, the block can be taken as the main chain block.

[0095] 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 part of the blocks, at this time, it is also difficult to judge according to the label hash value, therefore, after the step of detecting whether the minimum label hash value corresponds to multiple secondary screening blocks, the present embodiment further includes:

[0096] If it corresponds to multiple secondary screening blocks, the secondary screening block corresponding to the minimum label hash value is taken as a tertiary screening block;

[0097] According to the block weight corresponding to each tertiary screening block, a random number is generated, and a verifiable random number value corresponding to each tertiary screening block is obtained;

[0098] The minimum value in the verifiable random number values corresponding to the tertiary screening blocks is obtained, and a minimum random value is obtained;

[0099] The tertiary screening block corresponding to the minimum random value is taken 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, the label hash values of multiple blocks may be consistent due to the consistency of the block labels of part of the blocks or other factors. At this time, it is difficult to judge according to the label hash value, and further judgment needs to be combined 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 the verifiable random number value corresponding to each tertiary screening block.

[0101] Among them, in order to ensure the reasonable generation and verifiability of the random number, the random number generation algorithm used at this time can be a verifiable random function (VRF). Of course, it can also be an algorithm with similar functions and effects. The present embodiment does not limit this.

[0102] It can be understood that since a random number is generated, the verifiable random number values corresponding to each tertiary screening block are almost impossible to be the same at this time. Therefore, the tertiary screening block corresponding to the minimum random value in the verifiable random number value, that is, the minimum random value, can be directly selected as the main chain block.

[0103] It should be noted that by using the above method, the main chain block is selected through multi-level screening. Therefore, it can be ensured that after the main chain block is selected in this way, the blockchain is almost impossible to appear a fork failure, and the appearance of the fork of the blockchain 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 ways can also be used for updating, such as adding to the head or the middle, and the like. The present embodiment does not limit this.

[0106] In a specific implementation, after the main chain block is selected, other blocks in the block pool with the same block height as the selected main chain block can also be removed.

[0107] The embodiment extracts at least one candidate block from a block pool, the blocks in the block pool are set by a block node in the block chain, and the candidate blocks are blocks with the same block height; selects 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; and updates the block chain main chain according to the main chain block. Since the blocks with the same block height in the block pool are selected as the main chain block according to the block label weight value and / or the block label corresponding to the candidate block, the plurality of blocks as the main chain block is avoided, a block as the main chain block is reasonably selected, the block chain main chain is updated according to only one block, and the occurrence of the block chain main chain bifurcation and the corresponding fault is avoided.

[0108] Reference Figure 3 , Figure 3 The flowchart of the second embodiment of the main chain updating method of the application is shown.

[0109] Based on the above-mentioned first embodiment, the main chain updating method of the embodiment further includes the following steps before step S10:

[0110] Step S01: If it is detected that the block chain has a multi-fork fault, a fork sub-chain causing the multi-fork fault is obtained.

[0111] It should be noted that if the method of selecting the main chain block in the above-mentioned first embodiment is applied, the block chain will hardly bifurcate again thereafter, and the bifurcation fault can also be avoided. However, before the method is applied, the block chain may have bifurcated, causing a multi-fork fault. In view of this situation, the bifurcation fault needs to be eliminated, and therefore, the bifurcation sub-chain causing the bifurcation fault can be obtained when it is detected that the block chain has a bifurcation fault.

[0112] For example, the block chain node E generates a plurality of blocks (such as two blocks) in the same block time period, the parent block set of the blocks is different, in order to obtain the maximum benefit, a block of the current block time period is generated for each block, and therefore, a plurality of block chain sub-chains are generated at this time. Therefore, the plurality of block chain sub-chains are the bifurcation sub-chains causing the multi-fork fault.

[0113] Step S02: The block label weight values corresponding to the sub-chain blocks in the bifurcation sub-chains are added to obtain the added weight values corresponding to the bifurcation sub-chains.

[0114] Step S03: The bifurcation sub-chain with the maximum added weight value is taken as the block chain main chain.

[0115] It should be noted that the blockchain main chain can be selected according to the weight of each fork sub-chain, and the weight of the fork sub-chain can be represented by the block tag weight value corresponding to the sub-chain block included in the fork sub-chain. Therefore, the block tag weight values corresponding to each sub-chain block in the fork sub-chain can be accumulated, and the sum value obtained by the accumulation can be used as the accumulated weight value corresponding to the fork sub-chain. Each fork sub-chain is processed respectively, and the accumulated weight value corresponding to each fork sub-chain can be obtained.

[0116] It can be understood that the higher the weight of the fork sub-chain, the more reasonable it is to be used as the blockchain main chain. The higher the accumulated weight value, the higher the weight of the fork sub-chain. Therefore, the fork sub-chain with the largest corresponding accumulated weight value can be used as the blockchain main chain.

[0117] Among them, the sub-chain block can be all blocks included in the fork sub-chain, or different blocks in each fork sub-chain, for example: assuming that the fork sub-chain has A and B, at this time A includes blocks 1, 2, 3, B includes blocks 1, 4, 5, at this time the block sub-chain corresponding to A can be 1, 2 and 3, or only include 2 and 3.

[0118] In actual use, when a multi-fork fault occurs, each block in the fork sub-chain may also not have been assigned a corresponding block tag and block tag weight value. At this time, the corresponding block tag weight value can also be generated according to the data included in the block and the related information of the block generation node that generates the block.

[0119] In a specific implementation, in order to ensure that other types of forks can also be processed when they occur, the step S10 described in the embodiment can further include:

[0120] If a time offset fault is detected in the blockchain, the fault caused block that causes the time offset fault is obtained.

[0121] The block tag weight value corresponding to each fault caused block is obtained.

[0122] The blockchain main chain is updated according to the fault caused block with the smallest corresponding block tag weight value.

[0123] It should be noted that if a time offset fault occurs, it means that two different block time period blocks are found in the same block set. At this time, the two different block time period blocks are the fault caused blocks.

[0124] In actual use, the blockchain node can generate two blocks in the same block time period, and the parent block set of the two blocks is the same, but the block time period is different, which is caused by the time offset to obtain two random numbers in a very short time, and different block time periods appear. At this time, the round number in the block with smaller round number is the main one, so the block label weight value corresponding to the fault caused block can be obtained, and the blockchain main chain is updated according to the fault caused block with the minimum block label weight value (such as removing the other fault caused blocks from the blockchain main chain except the fault caused block with the minimum block label weight value), so that the time offset fault of the blockchain can be excluded.

[0125] In a specific implementation, in order to ensure that other types of faults can also be handled, the step S10 can further include the following steps before the step S10:

[0126] The connection detection is performed on each block in the block pool.

[0127] If there is a target block in the block pool that cannot be linked with the parent block through the block label 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 the block can be a block with smaller block height directly linked to the block, for example: assuming that in the constructed block subchain, 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 (possibly because of faults or data anomalies, etc. to remove part of the blocks), then on this basis, the subsequent blocks constructed can cause the blockchain to be abnormal, resulting in a parent block loss fault. In order to avoid this phenomenon, the connection detection can be performed on each block in the block pool to determine whether the link between the blocks can be established, wherein whether the link between the blocks can be established can be determined through the block label, for example: block A can access block B through the block label of block B to attempt to establish a link.

[0130] If there is a block in the block pool that cannot be linked with the parent block through the block label and the duration reaches a preset duration threshold, it indicates that the parent block corresponding to the block has been lost. At this time, the block can be taken as a target block, and the target block is removed from the block pool.

[0131] It should be noted that the processing of the fault does not have to be performed before the main chain updating method provided in the embodiment, but can also be performed during the execution of the main chain updating method or after the execution of the main chain updating method. Therefore, the steps related to the fault (for example, steps S01-S03) mentioned in the embodiment can be performed before or after any of the steps S10-S30, and the embodiment does not limit this.

[0132] For the sake of understanding, the following will be described in combination with Figure 4 , but the present solution is not limited thereto. Figure 4 FIG. 1 is a structural schematic diagram of a main chain updating system according to the embodiment.

[0133] As shown in Figure 4 , the main chain updating 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 configured to select a block node by using an equal-probability random drawing consensus algorithm (i.e., an algorithm for selecting a block node by using a random number modulo, as described above).

[0135] The block generation module is configured to generate a new block and add the new block to a block pool.

[0136] The block synchronization module is configured to synchronize the block pools of the blockchain nodes.

[0137] The candidate sub-chain selection algorithm module is configured to select a main chain block. The selection rules of the candidate sub-chain selection algorithm module include three layers, which are a block label weight value screening (i.e., selecting a candidate block corresponding to a maximum label weight value as a main chain block), a block label screening (i.e., selecting a candidate block as a main chain block), and a verifiable random function screening (i.e., selecting a third screening block corresponding to a minimum random value as a main chain block). The specific execution process can be referred to the above description, and will not be described here.

[0138] The fork fault processing module is configured to process the faults that have occurred in the blockchain. The processable faults can include multi-fork faults, time offset faults, and parent block loss faults. Of course, if necessary, other types of faults can also be processed after being set accordingly.

[0139] Each blockchain node in the blockchain performs the functions of the block node selection module, the block synchronization module, the candidate sub-chain selection algorithm module, and the fork fault processing module. The block generation module is only executed by the blockchain node selected as the block node.

[0140] The functions of the fork failure handling module do not necessarily need to be executed after the candidate subchain selection algorithm module has been executed. They can be executed before or after any of the above modules, such as the block node selection module, block generation module, block synchronization module, and candidate subchain selection algorithm module.

[0141] This embodiment performs corresponding fault detection on the blockchain, and when a fault is detected, it distinguishes the fault type and handles it in a corresponding manner, 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] Furthermore, this embodiment of the invention also proposes a storage medium storing a main chain update program, which, when executed by a processor, implements the steps of the main chain update method as described above.

[0143] Furthermore, this embodiment of the invention also proposes a computer program product, which includes a main chain update program. When the main chain update program is executed by a processor, it implements the steps of the main chain update method as described above.

[0144] Reference Figure 5 , Figure 5 This is a structural block diagram of the first embodiment of the main chain update device of the present invention.

[0145] like Figure 5 As shown, the main chain update device proposed in this embodiment of the invention includes:

[0146] The acquisition module 10 is used to extract at least one candidate block from the block pool, wherein the blocks in the block pool are set by the block producing nodes in the blockchain, and the candidate blocks are blocks with the same block height.

[0147] Selection module 20 is used to select a main chain block from the at least one candidate block according to the block tag weight value and / or block tag corresponding to each candidate block;

[0148] The update module 30 is used to update the blockchain main chain based on the main chain blocks.

[0149] The embodiment extracts at least one candidate block from a block pool, the blocks in the block pool are set by a block node in the block chain, and the candidate blocks are blocks with the same block height; selects 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; and updates the block chain main chain according to the main chain block. Since the candidate blocks with the same block height in the block pool are selected as the main chain block according to the block label weight value and / or the block label corresponding to each candidate block, the plurality of blocks are avoided from being simultaneously selected as the main chain block, a block can be reasonably selected as the main chain block, the block chain main chain is updated only according to one block, and the block chain main chain is avoided from being forked, thereby avoiding the occurrence of the corresponding fault.

[0150] Optionally, the selecting module 20 is further configured to obtain a block label weight value corresponding to each candidate block, and the block label weight value is constructed according to a block label of a block and a node selection label corresponding to a block node generating the block; obtain a maximum value in the block label weight values corresponding to the candidate blocks, and obtain a maximum label weight value; detect whether the maximum label weight value corresponds to a plurality of candidate blocks; if the maximum label weight value does not correspond to a plurality of candidate blocks, the candidate block corresponding to the maximum label weight value is selected as the main chain block.

[0151] Optionally, the selecting module 20 is further configured to, if the maximum label weight value corresponds to a plurality of candidate blocks, select the candidate block corresponding to the maximum label weight value as a secondary screening block; perform a hash calculation on a block label corresponding to each secondary screening block respectively, and obtain a label hash value corresponding to each secondary screening block; obtain a minimum value in the label hash values corresponding to the secondary screening blocks, and obtain a minimum label hash value; detect whether the minimum label hash value corresponds to a plurality of secondary screening blocks; and if the minimum label hash value does not correspond to a plurality of secondary screening blocks, the secondary screening block corresponding to the minimum label hash value is selected as the main chain block.

[0152] Optionally, the selecting module 20 is further configured to, if the minimum label hash value corresponds to a plurality of secondary screening blocks, select the secondary screening block corresponding to the minimum label hash value as a tertiary screening block; generate a random number according to a block weight corresponding to each tertiary screening block, and obtain a verifiable random number value corresponding to each tertiary screening block; obtain a minimum value in the verifiable random number values corresponding to the tertiary screening blocks, and obtain a minimum random value; and select the tertiary screening block corresponding to the minimum random value as the main chain block.

[0153] Optionally, the main chain updating apparatus further comprises an obstacle removing module.

[0154] The obstacle removing module is further configured to, if detecting that the blockchain has a multi-fork fault, acquire a fork sub-chain causing the multi-fork fault; accumulate the block tag weight values corresponding to each sub-chain block in the fork sub-chain to obtain an accumulated weight value corresponding to each fork sub-chain; and take the fork sub-chain with the largest corresponding accumulated weight value as the main chain of the blockchain.

[0155] Optionally, the obstacle removing module is further configured to, if detecting that the blockchain has a time offset fault, acquire a fault-causing block causing the time offset fault; acquire a block tag weight value corresponding to each fault-causing block; and update the main chain of the blockchain according to the fault-causing block with the smallest corresponding block tag weight value.

[0156] Optionally, the obstacle removing module is further configured to perform connection detection on each block in the block pool; if there is a target block in the block pool that cannot be linked with a parent block through a block tag and the duration of the target block reaches a preset duration threshold, remove the target block 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 solutions of the present application. In specific applications, those skilled in the art can set up as needed, and the present application does not limit this.

[0158] It should be noted that the above-described workflow is only illustrative and does not limit the scope of protection of the present application. In actual applications, those skilled in the art can select part or all of them to achieve the purpose of the embodiment according to actual needs, which is not limited here.

[0159] In addition, technical details not described in detail in this embodiment can be referred to the main chain updating method provided by any embodiment of the present application, which will not be repeated here.

[0160] In addition, it should be noted that in this document, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or system including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or system. Without more limitations, the element defined by the statement "includes a" does not exclude the presence of another identical element in the process, method, article or system that includes the element.

[0161] The above embodiment numbers of the present application are only for description and do not represent the advantages and disadvantages of the embodiments.

[0162] Those skilled in the art can clearly understand the above-mentioned embodiment method can be realized by means of software and the necessary general hardware platform, of course, can also be through hardware, but in many cases the former is a better embodiment. Based on such understanding, the technical solutions of the present application essentially or say the part of the prior art contribution can be embodied in the form of software products, the computer software product is stored in a storage medium (such as read only memory (Read Only Memory, ROM) / RAM, disk, optical disk), including a number of instructions to make a terminal device (may be a mobile phone, computer, server, or network equipment, etc.) executes the method described in various embodiments of the present application.

[0163] The above is only the preferred embodiment of the present application, not therefore limit the patent scope of the present application, any equivalent structure or equivalent flow transformation made by using the content of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A main chain update method, characterized in that, Applied to blockchain nodes, the main chain update method includes the following steps: At least one candidate block is extracted from the block pool, the blocks in the block pool being set by the block-producing nodes in the blockchain, and the candidate block being a block with the same block height; Main chain blocks are selected from at least one candidate block based on the block tag weight value and / or block tag corresponding to each candidate block; Update the blockchain main chain based on the main chain blocks; The step of selecting a main chain block from at least one candidate block based on the block tag weight value and / or block tag corresponding to each candidate block includes: Obtain the block label weight value corresponding to each candidate block. The block label weight value is constructed based on the block label of the block and the node selection label corresponding to the block-producing node that generates the block. Obtain the maximum value among the block label weight values ​​corresponding to each candidate block to get the maximum label weight value; Detect whether the maximum label weight value corresponds to multiple candidate blocks; If there are multiple candidate blocks, the candidate block corresponding to the maximum label weight value is used as the secondary screening block. Hash calculations are performed on the block tags corresponding to each secondary screening block to obtain the tag hash value corresponding to each secondary screening block; Obtain the minimum tag hash value among the tag hash values ​​corresponding to each of the secondary filtering blocks; Detect whether the minimum tag hash value corresponds to multiple secondary filtering blocks; If there are not multiple secondary filtering blocks, then the secondary filtering block corresponding to the smallest tag hash value shall be used as the main chain block.

2. The main chain update method as described in claim 1, characterized in that, After the step of detecting whether the maximum label weight value corresponds to multiple candidate blocks, the method further includes: If there are not multiple candidate blocks, the candidate block corresponding to the maximum tag weight value will be used as the main chain block.

3. The main chain update method as described in claim 1, characterized in that, After the step of detecting whether the minimum tag hash value corresponds to multiple secondary filtering blocks, the method further includes: If there are multiple secondary filtering blocks, the secondary filtering block corresponding to the smallest tag hash value is taken as the tertiary filtering block. Random numbers are generated based on the block weights corresponding to each of the three screening blocks, and verifiable random values ​​are obtained for each of the three screening blocks. Obtain the minimum value among the verifiable random values ​​corresponding to each of the three-stage filtering blocks to obtain the minimum random value; The block corresponding to the minimum random value after three rounds of filtering is taken as the main chain block.

4. The main chain update method as described in any one of claims 1-3, 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 failure is detected in the blockchain, obtain the forked sub-chain that caused the multi-fork failure; The block tag weight values ​​corresponding to each subchain block in the forked subchain are summed to obtain the accumulated weight value corresponding to each forked subchain. The forked subchain with the largest cumulative weight value is selected as the main blockchain chain.

5. The main chain update method as described in any one of claims 1-3, 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 retrieved. Obtain the block tag weight value corresponding to each block caused by each fault; The fault that results in the lowest corresponding block tag weight value causes the block to be updated on the main blockchain.

6. The main chain update method as described in any one of claims 1-3, characterized in that, Before the step of obtaining at least one candidate block from the block pool, the method further includes: Perform connectivity checks on each block in the block pool; If there is a target block in the block pool that cannot be connected to the parent blockchain via a block tag and whose duration reaches a preset duration threshold, then the target block will be removed from the block pool.

7. A main chain update device, characterized in that, The main chain update device includes the following modules: The acquisition module is used to extract at least one candidate block from the block pool, wherein the blocks in the block pool are set by the block producing nodes in the blockchain, and the candidate blocks are blocks with the same block height; The selection module is used to select a main chain block from the at least one candidate block based on the block tag weight value and / or block tag corresponding to each candidate block; The update module is used to update the blockchain main chain based on the main chain blocks; The selection module is further configured to obtain the block label weight value corresponding to each candidate block, wherein the block label weight value is constructed based on the block label of the block and the node selection label corresponding to the block-producing node that generates the block; obtain the maximum value among the block label weight values ​​corresponding to each candidate block to obtain the maximum label weight value; detect whether the maximum label weight value corresponds to multiple candidate blocks; if it corresponds to multiple candidate blocks, then the candidate block corresponding to the maximum label weight value is used as the secondary screening block; Hash calculations are performed on the block tags corresponding to each secondary screening block to obtain the tag hash value corresponding to each secondary screening block; Obtain the minimum tag hash value among the tag hash values ​​corresponding to each of the secondary filtering blocks; Detect whether the minimum tag hash value corresponds to multiple secondary filtering blocks; if it does not correspond to multiple secondary filtering blocks, then the secondary filtering block corresponding to the minimum tag hash value is taken as the main chain block.

8. 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, it implements the steps of the main chain update method as described in any one of claims 1-7.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a main chain update program, which, when executed, implements the steps of the main chain update method as described in any one of claims 1-7.

10. A computer program product, characterized in that, The computer program product includes a main chain update program, which, when executed, implements the steps of the main chain update method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • 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