CN110784521B - Block chain consensus method, electronic device and storage medium - Google Patents

Block chain consensus method, electronic device and storage medium Download PDF

Info

Publication number
CN110784521B
CN110784521B CN201910945180.3A CN201910945180A CN110784521B CN 110784521 B CN110784521 B CN 110784521B CN 201910945180 A CN201910945180 A CN 201910945180A CN 110784521 B CN110784521 B CN 110784521B
Authority
CN
China
Prior art keywords
block
main chain
candidate
candidate main
witness nodes
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910945180.3A
Other languages
Chinese (zh)
Other versions
CN110784521A (en
Inventor
程晗蕾
向智宇
王超
黄昭慈
鲁静
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Yuanguang Software Co Ltd
Original Assignee
Yuanguang Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Yuanguang Software Co Ltd filed Critical Yuanguang Software Co Ltd
Priority to CN201910945180.3A priority Critical patent/CN110784521B/en
Publication of CN110784521A publication Critical patent/CN110784521A/en
Application granted granted Critical
Publication of CN110784521B publication Critical patent/CN110784521B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1097Protocols in which an application is distributed across nodes in the network for distributed storage of data in networks, e.g. transport arrangements for network file system [NFS], storage area networks [SAN] or network attached storage [NAS]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/12Applying verification of the received information
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/50Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Hardware Design (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a block chain consensus method, an electronic device and a storage medium, wherein the method comprises the steps of detecting whether a block chain has a plurality of branched chains; if yes, determining a plurality of first candidate main chains from the latest block to the created block; respectively calculating the sum of the number of witness nodes of each first candidate main chain; the blockchain backbone is determined based on the sum of the number of witness nodes. By the method, the most credible block chain main chain can be timely and accurately confirmed, and the safety and the credibility of data stored on the block chain are improved.

Description

Block chain consensus method, electronic device and storage medium
Technical Field
The present application relates to the field of blockchain technologies, and in particular, to a method, an electronic device, and a storage medium for identifying blockchains.
Background
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism and an encryption algorithm, and emphasizes decentralization, openness, independence, safety and anonymity. The block chain technology is being researched and developed, the technology itself is not completely mature, the performance, the safety and the expansion are difficult to be considered completely, and the improvement of the performance directly determines the system throughput and the transaction processing efficiency. One of the main means to improve the performance of the blockchain is to improve the consensus mechanism.
The consensus mechanism refers to that in a block chain distributed system, a plurality of nodes which are not trusted with each other participate in consensus according to a certain preset rule, and further reach the agreement confirmation of the transaction effectiveness. An efficient consensus mechanism is crucial to fast and reliable verification of transactions between different nodes. The traditional block chain technology is synchronous verification, wherein a block is packaged to obtain full network node synchronization, and the blocks are in sequence according to time. The single-thread transaction verification restricts the performance of the blockchain system, and is easy to cause the waste of computing resources of blockchain nodes.
Disclosure of Invention
The technical problem that this application mainly solved is: the block chain consensus method, the electronic device and the storage medium are provided, the most credible block chain main chain can be timely and accurately confirmed, and the safety and the credibility of data stored on the block chain are improved.
In order to solve the technical problem, the application adopts a technical scheme that: a block chain consensus method is provided, which comprises the following steps:
detecting whether the block chain has a plurality of branched chains or not;
if yes, determining a plurality of first candidate main chains from the latest block to the created block;
respectively calculating the sum of the number of witness nodes of each first candidate main chain;
the blockchain backbone is determined based on the sum of the witness node numbers.
Optionally, separately calculating the sum of the number of witness nodes of each first candidate main chain comprises:
calculating the sum of the number of different witness nodes in the witness nodes of part or all blocks of each first candidate main chain;
determining the blockchain backbone based on the sum of the witness node numbers includes:
and determining the first candidate main chain with the maximum sum of the different witness nodes as the block chain main chain.
Optionally, the calculating the sum of the number of different witness nodes in the witness nodes of the partial or whole block of each first candidate main chain comprises:
tracing back to the created blocks along the latest blocks of the first candidate main chain, acquiring witness nodes of part or all blocks of the first candidate main chain and counting different witness nodes.
Optionally, before calculating the sum of the number of different witness nodes in the witness nodes of the partial or whole block of each first candidate main chain, the method further includes:
establishing a witness node list, wherein the witness node list at least comprises the number and identity information of all witness nodes of the block chain;
tracing back to the founder block along the latest block of the first candidate main chain, obtaining witness nodes of part or all blocks of the first candidate main chain and counting different witness nodes comprises:
and acquiring identity information of witness nodes of part or all blocks of the first candidate main chain, and calculating the number of different identity information as the sum of the number of different witness nodes of the first candidate main chain.
Optionally, tracing back to the created block along the latest block of the first candidate main chain, obtaining witness nodes of part or all blocks of the first candidate main chain and counting different witness nodes further comprises:
if the sum of the number of the different witness nodes of the first candidate main chain is calculated to be equal to the number of the witness nodes stored in the witness node list, backtracking is stopped.
Optionally, if there are multiple first candidate main chains with the largest sum of the different witness nodes, determining the first candidate main chain with the largest sum of the different witness nodes as a second candidate main chain;
respectively calculating the block number of a plurality of second candidate main chains;
and determining the second candidate main chain with the largest block number as the block chain main chain.
Optionally, the calculating the block number of the second candidate backbones respectively comprises:
tracing back to the created blocks along the newest blocks of the second candidate main chain, and counting the blocks of the second candidate main chain.
Optionally, if there are multiple second candidate main chains with the largest number of blocks, determining the multiple second candidate main chains with the largest number of blocks as third candidate main chains;
respectively acquiring hash values of the latest blocks of the plurality of third candidate main chains;
and determining a third candidate main chain in which the latest block with the minimum hash value is positioned as a block chain main chain.
In order to solve the above technical problem, another technical solution adopted by the present application is: an electronic device is provided, comprising a processor and a memory, the processor being coupled to the memory; wherein the content of the first and second substances,
the memory is used for storing program instructions executed by the processor;
the processor is used for executing program instructions to realize the common identification method of the block chain in the application.
In order to solve the above technical problem, the present application adopts another technical solution: a storage medium is provided for storing program instructions that are executable by a processor to implement the block chain consensus method described above.
The beneficial effect of this application is: when a plurality of branched chains are generated in the block chain, the block chain main chain with the most credibility can be timely and accurately confirmed by determining the candidate main chains and calculating the sum of the number of witness nodes of each candidate main chain, wherein the sum of the number of witness nodes can indicate the number of times that the block in the candidate main chain is verified during winding.
Drawings
Fig. 1 is a schematic flowchart of a first embodiment of a block chain consensus method according to the present application;
FIG. 2 is a schematic flow chart of a block chain consensus method according to a second embodiment of the present application;
FIG. 3 is a schematic flow chart of a third embodiment of a block chain consensus method according to the present application;
FIG. 4 is a schematic structural diagram of an embodiment of an electronic device of the present application;
FIG. 5 is a schematic structural diagram of an embodiment of a storage medium according to the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The inventors of the present application have found, through long-term research: in the transaction process based on the block chain, the node packages the received transaction, continuously confirms the transaction, and stamps a time stamp to chain and store transaction information to form a block chain main chain, and the transaction on the main chain is real, credible and not falsifiable. However, when the number of users participating in the transaction is too large, the transaction is packed into blocks to be confirmed frequently, so that a plurality of latest blocks exist at a certain moment, a plurality of branched chains are generated on a block chain, a plurality of synchronous different chains are formed, and the safety and the reliability of data stored on the block chain are influenced. And if the subsequent uplink transaction information continues to extend along the plurality of branched chains, the reliability of the data cannot be guaranteed, the computing resources of the node are wasted, and the working efficiency of the node is influenced. Therefore, it is important to accurately confirm the most reliable blockchain main chain in time during the process of linking transaction information. To solve these problems, the present application proposes at least the following embodiments.
Referring to fig. 1, the first embodiment of the block chain consensus method of the present application includes:
s101: and detecting whether the block chain has a plurality of branched chains.
In the present embodiment, a plurality of bars means more than one bar. Whether the block chain has a plurality of branched chains or not can be detected by the block chain link points. The node is, for example, a billing node, and detects whether the block chain generates multiple branched chains before each time transaction information is packed into blocks for uplink. For example, the block chain nodes may exchange the block heights of the latest blocks, and determine whether the random numbers or root hash values of the blocks with the same block height are the same, so as to detect whether the block chain generates multiple branches.
In this embodiment, if no branches are detected, the detection may be continued or no other operation may be performed. If it is detected that there are multiple branches in the blockchain, the following step S102 may be performed.
S102: a plurality of first candidate backbones are determined that trace back from the most recent block to the founder block.
In this embodiment, if it is detected that the blockchain has a plurality of branches, the first candidate main chains from the newest block to the created block can be identified by tracing back from the newest block to the created block. The latest block may be the block with the largest block height for each branch at the current time.
In some embodiments, the trace back from the newest block to the created block is performed according to the hash value of the current block and the hash value of the previous block stored in the block header of each block. For example, the hash value of the previous block stored in the block header of the latest block is determined, and after the previous block is found, the hash value of the previous block is determined from the block header of the previous block, and the previous block is sequentially and continuously searched forward, so that the plurality of first candidate main chains are finally determined.
S103: and respectively calculating the sum of the number of witness nodes of each first candidate main chain.
In this embodiment, after the plurality of first candidate backbones are confirmed, the sum of the number of witness nodes of each first candidate backbone may be calculated. The witness node is, for example, a node that verifies a block when the block is uplink. Witness nodes may be all or some of the nodes in the blockchain. For example, in a federation chain, some nodes in a blockchain may be designated as witness points, for example, some nodes with high credibility and large contribution may be designated as witness nodes. Witness nodes are often fixed partial or complete nodes.
The sum of the number of witness nodes is calculated, for example, the sum of the number of witness nodes of each block of the first candidate backbone is calculated. The witness node number for a block may indicate the number of times the block was verified while uplink. The sum of the witness node numbers may indicate a total number of times that all blocks in the first candidate backbone are verified while uplink.
In some embodiments, during the process of verifying each block before uplink, the number of times the block is verified and/or information related to the node being verified may be recorded, and the information may be stored after uplink of the block for subsequent verification or other operations. When the sum of the number of witness nodes of each first candidate main chain is calculated, the calculation can be further performed by counting the number of times that each block of the first candidate main chain is verified and/or the related information of the verification nodes.
S104: the blockchain backbone is determined based on the sum of the witness node numbers.
In this embodiment, the blockchain backbone may be determined based on the sum of the witness nodes. For example, the first candidate backbone that the sum of the witness node numbers exceeds a set threshold may be selected as the blockchain backbone. For example, a threshold value of the sum of the corresponding witness nodes may be set according to the block height of the block chain.
In some embodiments, when the blockchain backbone is identified based on the sum of the number of witness nodes, the first candidate backbone with the largest sum of the number of witness nodes may also be selected as the blockchain backbone. The larger the sum of the witness node numbers is, the higher the total number of times that the block of the first candidate main chain is verified is, the larger the corresponding workload is, and the higher the reliability is.
In some embodiments, after determining the blockchain main chain, for the transaction information not on the blockchain main chain, rollback may be performed, and the uplink may be repackaged to ensure the validity of the transaction information.
In this embodiment, when a blockchain generates multiple branched chains, the candidate main chains are determined and the sum of the number of witness nodes of each candidate main chain is calculated, the sum of the number of witness nodes can indicate the number of times that a block in the candidate main chain is verified during uplink, and the blockchain main chain is confirmed based on the sum of the number of witness nodes, so that the most reliable blockchain main chain can be timely and accurately confirmed, and the security and the reliability of data stored on the blockchain are improved.
In the present embodiment, the sequence of steps S101 to S104 is the description sequence in the present embodiment, and is not limited to the sequence of the method in the execution process of the present embodiment. Some steps may be reversed in order to enable the method.
Referring to fig. 2, a second embodiment of the block chain consensus method is further described on the basis of the first embodiment of the block chain consensus method. The steps of this embodiment that are the same as those of the first embodiment of the block chain consensus method of this application are not described herein again. The embodiment comprises the following steps:
s201: and detecting whether the block chain has a plurality of branched chains.
In this embodiment, if no branches are detected, the detection may be continued or no other operation may be performed. If it is detected that there are multiple branches in the blockchain, the following step S202 may be performed.
S202: a plurality of first candidate backbones are determined that trace back from the most recent block to the founder block.
S203: the sum of the number of different witness nodes in the witness nodes of part or all of the blocks of each first candidate backbone is calculated.
In this embodiment, when the sum of the number of witness nodes of each first candidate main chain is calculated, the sum of the number of different witness nodes in the witness nodes of part or all of the blocks of each first candidate main chain may be calculated. In this embodiment, the different witness nodes may refer to different witness nodes located in the blockchain network, and addresses of the witness nodes are different. The larger the sum of the number of different witness nodes of the first candidate main chain is, the higher the credibility is, the more witness nodes verify the block of the first candidate main chain.
In this embodiment, when calculating the sum of the numbers of different witness nodes, a partial block of the first candidate main chain may be selected for calculation. For example, a block of the first candidate backbone is selected for computation from the most recent block back to the block that originally generated the branch. For example, two first candidate backbones exist for the blockchain, and the blocks backtracking from the respective latest block to the block generating the branch chain may be selected, and the sum of the number of different witness nodes of the blocks of the two first candidate backbones may be calculated respectively. Because the blocks of the first candidate main chains are the same before the blocks of the branched chains are generated, when the sum of the number of different witness nodes is calculated, the calculation is started from the block which initially generates the branched chains, the sum of the number of the different witness nodes of the first candidate main chains can be ensured to be unchanged, the calculation of the number of the witness nodes of the block chains before the branched chains are generated can be reduced, the calculation workload is saved, and the calculation efficiency is improved.
In this embodiment, when calculating the sum of the numbers of different witness nodes, all blocks of the first candidate main chain may be selected for calculation. For example, after a block chain generates branches to form a plurality of first candidate backbones, the blocks of the first candidate backbones continue to grow, and at some point, new branches may be generated again to form new first candidate backbones. The situation is further complicated when calculating the sum of the number of distinct witness nodes for each first candidate backbone due to the formation of intersections of multiple branches on the blockchain. The accuracy of the calculation result can be effectively ensured by calculating the sum of the number of different witness nodes of all the blocks of the first candidate main chain, and the error of the calculation result caused by calculation omission is reduced.
Optionally, S203 may further include: tracing back to the created blocks along the latest blocks of the first candidate main chain, acquiring witness nodes of part or all blocks of the first candidate main chain and counting different witness nodes.
In the present embodiment, the trace back to the created block along the newest block of the first candidate main chain is performed based on the hash value of the current block and the hash value of the previous block stored in the block header of each block, for example. The backtracking is carried out from the latest block to the created block, different witness nodes of the block of the first candidate main chain can be completely and orderly calculated, and calculation result errors caused by calculation missing are avoided.
In some embodiments, after detecting that there are multiple branches in the block chain, different witness nodes in the block may be counted simultaneously in the process of backtracking from the newest block to the created block to determine multiple first candidate backbones. Therefore, the calculation workload can be effectively saved, and the efficiency is improved.
Optionally, before calculating the sum of the number of different witness nodes in the witness nodes of part or all of the blocks of each first candidate backbone, a witness node list may also be established. The witness node list at least comprises the number of all witness nodes of the block chain and identity information. The identity information includes, for example, the address of the witness node, signature information, belonging user information, and other related information. The identity information may be used to identify the witness node. The witness node list may also be obtained by each block link point to facilitate supervision of witness nodes.
For example, in a blockchain system, witness nodes may be some more reputable and more contributing blockchain nodes generated by election, and are responsible for verifying blocks to be linked, and by establishing a witness node list, identity information of these witness nodes may be stored in the witness node list. When the witness nodes change, such as new witness nodes are added or the witness nodes drop or exit, the witness node list can be updated. In some embodiments, the witness list may also record the workload and reputation of the witness nodes for ease of management and supervision.
In this embodiment, establishing the witness node list may be completed before calculating the sum of the different witness node numbers of the first candidate main chain, for example, before the step S203, or may be completed before or at the same time as S201 or S202. Alternatively, the witness node list may be established before the blockchain is generated, and the witness node list may be maintained and updated.
In this embodiment, when counting different witness nodes, identity information of witness nodes of part or all of the blocks of the first candidate main chain may be acquired, and the identity information of different witness nodes may be counted. In this embodiment, the identity information of the witness node may be used to identify the witness node. When the block is on the uplink, the identity information of the witness node when being verified can be recorded and stored. When the latest block is traced back to the founding block, the identity information of the witness node stored in each block can be obtained, and different identity information is counted. The number of different identity information is calculated to be the sum of the number of different witness nodes of the first candidate main chain, so that the witness node of each block can be determined quickly and accurately, and the calculation of the sum of the number of different witness nodes of the first candidate main chain is completed.
In some embodiments, backtracking may also be stopped when the sum of the number of different witness nodes of the first candidate backbone is calculated to be equal to the number of witness nodes saved in the witness node list. In this embodiment, the identity information of the witness nodes identifies the witness nodes, and if the sum of the number of different witness nodes is calculated, that is, the number of the identity information of the different witness nodes is equal to the number of the witness nodes stored in the witness node list, it indicates that all the witness nodes in the witness node list have verified the first candidate main chain. At this time, if the number of the founding blocks is continuously backtracked and counted, the sum of the number of the witness nodes is not increased any more, and by stopping backtracking, the calculation amount can be saved, and the calculation efficiency can be improved.
S204: and determining the first candidate main chain with the maximum sum of the different witness nodes as the block chain main chain.
In this embodiment, when the blockchain main chain is determined based on the sum of the witness nodes, the first candidate main chain with the largest sum of the different witness nodes may be selected as the blockchain main chain. The larger the sum of the number of different witness nodes is, the more witness nodes verify the blocks of the first candidate main chain, so that the possibility of cheating by a few witness nodes is reduced, the higher the security of data stored on the corresponding block chain is, and the higher the credibility is.
In this embodiment, when it is detected that a blockchain generates multiple branched chains, the sum of the number of different witness nodes of each candidate main chain is calculated, and the larger the sum of the number of different witness nodes is, it is indicated that blocks of the first candidate main chain are verified by the more witness nodes, so that the possibility of cheating by a few witness nodes is reduced, and by determining the first candidate main chain with the largest sum of the number of different witness nodes as the blockchain main chain, the most reliable blockchain main chain can be timely and accurately determined, and the security and the reliability of data stored on the blockchain are improved.
In the present embodiment, the sequence of steps S201 to S204 is the description sequence in the present embodiment, and is not limited to the sequence of the method in the execution process of the present embodiment. Some steps may be permuted, provided that the method can be implemented.
Referring to fig. 3, a third embodiment of the block chain consensus method is further described on the basis of the first embodiment of the block chain consensus method. The steps of this embodiment that are the same as those of the first embodiment of the block chain consensus method of this application are not described herein again. The embodiment comprises the following steps:
s301: and detecting whether the block chain has a plurality of branched chains.
In this embodiment, if no branches are detected, the detection may be continued or no other operation may be performed. If it is detected that there are multiple branches in the blockchain, the following step S302 may be performed.
S302: a plurality of first candidate backbones are determined that trace back from the most recent block to the founder block.
S303: and calculating the sum of the number of different witness nodes in the witness nodes of the partial or whole blocks of each first candidate main chain.
S304: and judging whether the first candidate main chain with the maximum sum of the different witness nodes has a plurality of first candidate main chains.
In the present embodiment, a plurality of bars means more than one bar. The maximum sum of the number of different witness nodes indicates that the first candidate backbone has been verified by the most witness nodes. The first candidate main chain with the largest sum of the numbers of the different witness nodes is obtained by comparing the sum of the numbers of the different witness nodes of each first candidate main chain after the calculation of the sum of the numbers of the different witness nodes of each first candidate main chain is completed, for example. In this embodiment, it may be determined whether the first candidate main chain with the largest sum of the different witness nodes is one or more than one.
In some embodiments, when the sum of the numbers of different witness nodes of the first candidate backbone is calculated to be equal to the number of witness nodes stored in the witness node list, the first candidate backbone may also be determined to be the first candidate backbone having the largest sum of the numbers of different witness nodes. The description of the witness node list may refer to the above description of the second embodiment of the block chain consensus method of the present application.
In this embodiment, if it is determined that there is only one first candidate main chain with the largest sum of the numbers of different witness nodes, the following step S305 may be performed.
If the first candidate main chain with the largest sum of the numbers of the different witness nodes is determined to have a plurality of first candidate main chains, the following step S306 may be executed.
S305: and determining the first candidate main chain with the maximum sum of the different witness nodes as the block chain main chain.
In this embodiment, if it is determined that there is only one first candidate main chain with the largest sum of the numbers of different witness nodes, it may be determined that the first candidate main chain is the blockchain main chain.
Alternatively, after the blockchain backbone is determined in this step, the following steps may not be performed.
S306: and determining the first candidate main chain with the maximum sum of the different witness nodes as a second candidate main chain.
In this embodiment, if there are multiple first candidate backbones with the largest sum of the numbers of different witness nodes, the first candidate backbone with the largest sum of the numbers of different witness nodes may be determined as the second candidate backbone. Therefore, the first candidate main chains with higher relative reliability in the plurality of first candidate main chains can be screened out, and after the first candidate main chains are determined to be the second candidate main chains, subsequent processing is facilitated.
The terms "first", "second" and "third" in the present embodiment are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated.
S307: and respectively calculating the block number of the second candidate main chains.
In this embodiment, after determining the second candidate main chains, the number of blocks of each second candidate main chain may be respectively calculated, and the blockchain main chain may be determined based on the number of blocks of the second candidate main chains. For example, the block height of the latest block of each second candidate main chain may be obtained to obtain the block number of the second candidate main chain. Alternatively, the number of blocks may be obtained by counting the blocks of each second candidate main chain.
For example, S307 includes: tracing back to the founder block along the newest block of the second candidate main chain, and counting the blocks of the second candidate main chain.
After determining the second candidate backbone, a backtrack may be made along the most recent block of the second candidate backbone to the founder block to count blocks of the second candidate backbone. For example, the hash value of each chunk of the second candidate main chain may be counted by continuously backtracking the hash value to the created chunk, so as to obtain the number of chunks of the second candidate main chain.
In some embodiments, after detecting that the block chain generates a plurality of branches, while tracing back from the latest block to the created block to determine a plurality of first candidate backbones, the sum of the number of different witness nodes of each first candidate backbone may be calculated, or the number of blocks of each first candidate backbone may be counted. After the first candidate main chain with the largest sum of the different witness nodes is judged, the first candidate main chain with the largest sum of the different witness nodes is determined as a second candidate main chain, and meanwhile, the block number of the corresponding second candidate main chain is determined. Therefore, the calculation amount of multiple backtracking can be effectively reduced, and the calculation efficiency is improved.
S308: and judging whether the second candidate main chain with the largest block number has a plurality of second candidate main chains.
In this embodiment, the larger the number of blocks, the more data stored on the second candidate main chain, the larger the workload of data uplink. The second candidate main chain with the largest block number is obtained by comparing the block number of each second candidate main chain after the block number of each second candidate main chain is calculated. In this embodiment, it can be determined whether the second candidate main chain with the largest block number is one or more than one.
In this embodiment, if it is determined that there is only one second candidate main chain with the largest block number, the following step S309 may be performed.
If it is determined that there are a plurality of second candidate main chains with the largest number of blocks, the following step S310 may be performed.
S309: and determining the second candidate main chain with the largest block number as the block chain main chain.
In this embodiment, if only one second candidate main chain with the largest block number is determined, the second candidate main chain may be determined as the block chain main chain. The blockchain backbone determined in this step has the characteristics of the largest sum of the different witness nodes and the largest number of blocks. The maximum number of different witness nodes indicates the verification of the most witness nodes, so that the possibility of cheating by a few nodes is effectively reduced. The maximum number of blocks indicates that the more data is stored and the more workload is, so that the workload of most nodes is effectively guaranteed to be effective. The blockchain backbone thus determined effectively increases the security and trustworthiness of the data stored on the blockchain.
Alternatively, after the blockchain backbone is determined in this step, the following steps may not be performed.
S310: and determining the second candidate main chain with the largest number of blocks as a third candidate main chain.
In this embodiment, if there are multiple second candidate backbones with the largest number of blocks, the second candidate backbones with the largest number of blocks may be determined as the third candidate backbones. Therefore, the second candidate main chains with more relative workload in the plurality of second candidate main chains can be screened out, and the second candidate main chains are determined to be the second candidate main chains, so that the subsequent processing is facilitated.
S311: and respectively acquiring the hash values of the latest blocks of the plurality of third candidate main chains.
In this embodiment, the block header of each block in the block chain stores the hash value of the block and the hash value of the previous block, and a complete block chain is formed by linking the hash values. After determining the plurality of third candidate backbones, the hash value of the corresponding latest chunk may be obtained from the chunk header of the latest chunk of each third candidate backbone.
S312: and determining a third candidate main chain in which the latest block with the minimum hash value is positioned as a block chain main chain.
In this embodiment, after the third candidate main chain with the largest sum of different witness nodes and the largest number of blocks is determined, the third candidate main chain in which the latest block with the smallest hash value is located may be the block chain main chain. Determining the blockchain backbone based on the hash value ensures uniqueness of the blockchain backbone since the hash value is different for each chunk.
In this embodiment, for multiple branched chains of a block chain, a block chain main chain is determined by a method of maximizing the sum of different witness nodes, maximizing the block number, and minimizing a hash value in sequence. The maximum number of different witness nodes indicates the verification of the most witness nodes, so that the possibility of cheating by a few nodes is effectively reduced. The maximum number of blocks indicates that the more data is stored and the workload is larger, so that the workload of most nodes is effectively guaranteed to be effective. The minimum hash value ensures the uniqueness of the main chain of the block chain, so that the safety and the reliability of the data stored on the block chain are effectively improved.
In this embodiment, the sequence of steps S301 to S312 is the description sequence in this embodiment, and is not limited to the sequence of the method in the execution process of this embodiment. Some steps may be performed in reverse order, separately, or simultaneously, while still being able to perform the method. This embodiment can be combined with the first embodiment and/or the second embodiment of the block chain consensus method described above.
In a specific application scenario of the present application, the blockchain system at least includes a lightweight node, a hub node, and a witness node. The light weight node is, for example, a mobile phone mobile terminal, a PC terminal, etc., and is used for helping a user complete communication in the whole network, and is responsible for functions of interacting with the user, receiving and sending transactions, messages, payment verification, etc., and the light weight node can be connected to the hub node; the hub node is responsible for providing an end-to-end encrypted message transmission channel for equipment connected to the hub node and packaging the transaction provided by the light weight node; the witness node is responsible for constantly and commonly identifying and confirming the transaction and the block and storing complete block chain data.
The specific process is as follows: the user initiates a transaction through the light weight node, the transaction is transmitted to the central node for whole network broadcasting, the central node sorts the transaction according to the permit (Token) provided by the user, the transaction is packed into blocks according to the sequence with higher permit value and submitted to a plurality of witness nodes for verification, the witness nodes transmit the verification result back to the central node, and the central node broadcasts and shares the confirmation result to the whole network.
In some cases, when the number of users participating in a transaction is too large, the transactions are frequently packed into blocks for confirmation, resulting in a plurality of latest blocks at a certain time, so that a block chain generates a plurality of branched chains to form a plurality of synchronous different chains. When the witness node links the block verification, the block chain main chain may be confirmed in advance, for example, by tracing back from the latest block to the founder block, and sequentially confirming the block chain main chain by using the policy of the maximum sum of different witness nodes, the maximum block number, and the minimum hash value.
For example, when it is detected that the blockchain generates a plurality of branches, a plurality of first candidate main chains are determined from the current latest block back to the created block. During backtracking, different witness nodes of each first candidate backbone may be counted while blocks are counted. And when the backtracking is finished, judging whether the first candidate main chain with the maximum sum of the number of different witness nodes has a plurality of first candidate main chains. And if not, determining the first candidate main chain with the maximum sum of the numbers of the different witness nodes as the block chain main chain. And if the number of the main chains is multiple, determining the multiple first candidate main chains with the maximum sum of the different witness nodes as second candidate main chains. Further determine whether there are multiple second candidate backbones with the largest number of blocks. If not, determining the second candidate main chain with the largest block number as the block chain main chain. And if the number of the second candidate main chains is more than the number of the blocks, determining the second candidate main chains with the largest block number as third candidate main chains. And acquiring the hash value of the latest block of each third candidate main chain, and selecting the third candidate main chain where the block with the minimum hash value is positioned as the block chain main chain. After determining the blockchain main chain, rolling back can be performed on the transaction contract on the no-more-blockchain main chain, and repackaging the transaction contract which is uploaded to the blockchain main chain. By the method, the main chain of the block chain can be determined timely and quickly, resource waste of the nodes of the block chain is reduced, the effective workload of most nodes is guaranteed, and the safety and the reliability of data stored on the block chain are improved effectively.
Referring to fig. 4, fig. 4 is a schematic structural diagram of an embodiment of an electronic device according to the present application. In the embodiment, the electronic device 40 includes a processor 410 and a memory 420, and the processor 410 is coupled to the memory 420. In this embodiment, the processor 410 is connected to the memory 420 through a bus. In other embodiments, the processor 410 may also be directly connected to the memory 420; or may be connected by other means. The connection between the processor 410 and the memory 420 is not limited herein.
In this embodiment, the electronic device 40 is, for example, a computer, a tablet, a mobile phone, and the like. The electronic device 40 may also be a node in a blockchain network, and may participate in functions of blockchain transaction, communication, accounting, storage, and the like. Memory 420 of electronic device 40 is used to store program instructions that are executed by processor 410. The processor 410 is configured to execute the program instructions to implement at least the steps of the first to third embodiments of the block chain consensus method described above.
In the present embodiment, the processor 410 may also be referred to as a CPU (Central Processing Unit). The processor 410 may be an integrated circuit chip having signal processing capabilities. The processor 410 may also be a general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
For more execution processes and functions of the electronic device 40 in this embodiment, reference may be made to the first to third embodiments of the block chain consensus method in the present application, which is not described herein again.
Referring to fig. 5, fig. 5 is a schematic structural diagram of an embodiment of a storage medium according to the present application. The storage medium 50 is configured to store program instructions 510, and the program instructions 510 can be executed by the processor to implement the steps of the first to third embodiments of the block chain consensus method described above.
The block chain consensus method according to the present application, the methods according to the first to third embodiments, if implemented in the form of software functional units and sold or used as independent products, may be stored in a computer-readable storage medium. Based on such understanding, the technical solutions of the present application may substantially or partially contribute to the prior art, or all or part of the technical solutions may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, a network device, or the like) or a processor (processor) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium 510 includes: various media capable of storing program codes, such as a usb disk, a mobile hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, or other devices, such as a mobile terminal including a storage medium.
The above description is only for the purpose of illustrating embodiments of the present application and is not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings of the present application or are directly or indirectly applied to other related technical fields, are also included in the scope of the present application.

Claims (10)

1. A method for block chain consensus, comprising:
detecting whether the block chain has a plurality of branched chains or not;
if yes, determining a plurality of first candidate main chains from the latest block to the created block;
respectively calculating the sum of the witness nodes of each first candidate main chain;
determining the first candidate main chain with the maximum sum of the different witness nodes as the block chain main chain.
2. The consensus method of claim 1,
the calculating the sum of the number of witness nodes of each first candidate main chain comprises:
and calculating the sum of the number of different witness nodes in the witness nodes of the partial or whole blocks of each first candidate main chain.
3. The consensus method of claim 2,
the calculating the sum of the number of different witness nodes in the witness nodes of the partial or all blocks of each first candidate main chain comprises:
tracing back to the founder block along the latest block of the first candidate main chain, obtaining witness nodes of partial or all blocks of the first candidate main chain and counting different witness nodes.
4. The consensus method of claim 3,
before the calculating the sum of the number of different witness nodes in the witness nodes of the partial or whole block of each first candidate main chain, the method further comprises:
establishing a witness node list, wherein the witness node list at least comprises the number and identity information of all witness nodes of the block chain;
the backtracking to the created blocks along the latest block of the first candidate main chain, obtaining witness nodes of part or all blocks of the first candidate main chain and counting different witness nodes comprises:
and acquiring identity information of witness nodes of part or all blocks of the first candidate main chain, and calculating the number of different identity information as the sum of the number of different witness nodes of the first candidate main chain.
5. The consensus method of claim 4,
said tracing back to a founder block along the latest block of said first candidate backbone, obtaining witness nodes for part or all of the blocks of said first candidate backbone and counting the different witness nodes further comprises:
and if the sum of the number of the different witness nodes of the first candidate main chain is equal to the number of the witness nodes stored in the witness node list, stopping backtracking.
6. The consensus method of claim 2, further comprising:
if the number of the first candidate main chains with the largest sum of the different witness nodes is multiple, determining the first candidate main chain with the largest sum of the different witness nodes as a second candidate main chain;
respectively calculating the block number of a plurality of second candidate main chains;
and determining the second candidate main chain with the largest block number as the block chain main chain.
7. The consensus method of claim 6,
the calculating the block number of the second candidate backbones respectively comprises:
tracing back to a created block along a latest block of the second candidate backbone, and counting blocks of the second candidate backbone.
8. The consensus method of claim 7, further comprising:
if the second candidate main chain with the largest block number has a plurality of second candidate main chains, determining the plurality of second candidate main chains with the largest block number as third candidate main chains;
respectively acquiring hash values of the latest blocks of the third candidate main chains;
and determining a third candidate main chain where the latest block with the smallest hash value is located as a block chain main chain.
9. An electronic device comprising a processor and a memory, the processor coupled to the memory, wherein,
the memory is used for storing program instructions executed by the processor;
the processor is configured to execute the program instructions to implement the consensus method as claimed in any one of claims 1 to 8.
10. A storage medium for storing program instructions executable by a processor to perform the consensus method as claimed in any one of claims 1 to 8.
CN201910945180.3A 2019-09-30 2019-09-30 Block chain consensus method, electronic device and storage medium Active CN110784521B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910945180.3A CN110784521B (en) 2019-09-30 2019-09-30 Block chain consensus method, electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910945180.3A CN110784521B (en) 2019-09-30 2019-09-30 Block chain consensus method, electronic device and storage medium

Publications (2)

Publication Number Publication Date
CN110784521A CN110784521A (en) 2020-02-11
CN110784521B true CN110784521B (en) 2022-05-27

Family

ID=69385399

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910945180.3A Active CN110784521B (en) 2019-09-30 2019-09-30 Block chain consensus method, electronic device and storage medium

Country Status (1)

Country Link
CN (1) CN110784521B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111324489B (en) * 2020-02-18 2023-04-07 杭州复杂美科技有限公司 Main chain game result display method, equipment and storage medium
CN111683117B (en) * 2020-05-11 2021-12-10 厦门潭宏信息科技有限公司 Method, equipment and storage medium
CN111597268B (en) * 2020-05-21 2023-09-12 昆明大棒客科技有限公司 Block chain extension method, block chain node and block chain system
CN114884977B (en) * 2022-05-09 2023-07-04 深圳嘉业产业发展有限公司 Block chain-based data sharing method and system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107315786A (en) * 2017-06-12 2017-11-03 腾讯科技(深圳)有限公司 Business datum storage method and device
CN108960837A (en) * 2018-06-05 2018-12-07 上海和数软件有限公司 Block chain common recognition verification method, device and computer readable storage medium
CN109525671A (en) * 2018-11-26 2019-03-26 远光软件股份有限公司 Date storage method, electronic equipment and storage medium based on block chain
CN109859047A (en) * 2019-01-31 2019-06-07 北京瑞卓喜投科技发展有限公司 A kind of block chain update method and block chain more new system
CN110059136A (en) * 2019-04-17 2019-07-26 江苏全链通信息科技有限公司 Information storage means, equipment and storage medium based on domain name block chain

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10491378B2 (en) * 2016-11-16 2019-11-26 StreamSpace, LLC Decentralized nodal network for providing security of files in distributed filesystems
CN109240826B (en) * 2018-08-15 2020-10-23 泰链(厦门)科技有限公司 Method for allocating computing resources when nodes share computing equipment in multi-block chain network
CN109242685B (en) * 2018-08-29 2020-05-12 众安信息技术服务有限公司 Block chain-based consensus and verification method and device
CN109409889B (en) * 2018-11-13 2021-11-12 杭州秘猿科技有限公司 Block determining method and device in block chain and electronic equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107315786A (en) * 2017-06-12 2017-11-03 腾讯科技(深圳)有限公司 Business datum storage method and device
CN108960837A (en) * 2018-06-05 2018-12-07 上海和数软件有限公司 Block chain common recognition verification method, device and computer readable storage medium
CN109525671A (en) * 2018-11-26 2019-03-26 远光软件股份有限公司 Date storage method, electronic equipment and storage medium based on block chain
CN109859047A (en) * 2019-01-31 2019-06-07 北京瑞卓喜投科技发展有限公司 A kind of block chain update method and block chain more new system
CN110059136A (en) * 2019-04-17 2019-07-26 江苏全链通信息科技有限公司 Information storage means, equipment and storage medium based on domain name block chain

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
主从多链模型下的区块链共识性能研究;徐宇芹;《中国优秀博硕士学位论文全文数据库(硕士)信息科技辑》;20190115;全文 *

Also Published As

Publication number Publication date
CN110784521A (en) 2020-02-11

Similar Documents

Publication Publication Date Title
CN110784521B (en) Block chain consensus method, electronic device and storage medium
KR102469267B1 (en) Blockchain consensus method, accounting node and node
CN108023896B (en) Block synchronization method and system
CN106453415B (en) Block chain-based equipment authentication method, authentication server and user equipment
EP4053711A1 (en) Consensus method for blockchain, and consensus node, electronic device and storage medium
US20220272105A1 (en) Blockchain-based data detection method, apparatus, and computer-readable storage medium
CN108876384B (en) Transaction data processing method and device
CN110838063B (en) Transaction processing method based on blockchain, electronic equipment and storage medium
CN113301114B (en) Block chain consensus node selection method and device, computer equipment and storage medium
CN111444211A (en) Block chain consensus node checking method, device, equipment and storage medium
CN113326516A (en) Block chain consensus method, block chain system and computer equipment
CN110659905B (en) Transaction verification method, device, terminal equipment and storage medium
CN110704464B (en) Method and device for processing bifurcation problem
CN111010284B (en) Processing method of block to be identified, related device and block chain system
CN109145651B (en) Data processing method and device
CN112184436B (en) Data synchronization method, electronic device and readable storage medium
CN111061735A (en) Capacity expansion method and device based on single-chain block chain
CN111367621A (en) Intelligent contract timing processing method, block chain node and storage medium
CN111259428A (en) Data processing method and device based on block chain, node equipment and storage medium
CN116455974A (en) Transaction caching and ordering method, device, electronic equipment and storage medium
CN110730186A (en) Token issuing method, accounting node and medium based on block chain
CN112258184B (en) Method, apparatus, electronic device and readable storage medium for freezing blockchain network
CN111522876B (en) Block chain consensus method, device, computer equipment and block chain link point
CN112131602A (en) Method and device for quickly expanding trust relationship between nodes based on trusted computing and related products
CN112202875A (en) Method and device for safety detection based on block link point weight and related product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant