CN111586147B - Node synchronization method, device, equipment and storage medium of block chain - Google Patents

Node synchronization method, device, equipment and storage medium of block chain Download PDF

Info

Publication number
CN111586147B
CN111586147B CN202010363964.8A CN202010363964A CN111586147B CN 111586147 B CN111586147 B CN 111586147B CN 202010363964 A CN202010363964 A CN 202010363964A CN 111586147 B CN111586147 B CN 111586147B
Authority
CN
China
Prior art keywords
node
transaction
verified
standby
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
CN202010363964.8A
Other languages
Chinese (zh)
Other versions
CN111586147A (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.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen 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 Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202010363964.8A priority Critical patent/CN111586147B/en
Priority to PCT/CN2020/098929 priority patent/WO2021217849A1/en
Publication of CN111586147A publication Critical patent/CN111586147A/en
Application granted granted Critical
Publication of CN111586147B publication Critical patent/CN111586147B/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/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to a block chain technology, and provides a method, a device, equipment and a storage medium for synchronizing nodes of a block chain, namely, a master node is selected from nodes in the same organization based on a preset election algorithm, each transaction to be verified in a transaction block is processed through the master node, the validity of each transaction to be verified is marked based on a transaction processing result corresponding to the transaction to be verified, transaction information corresponding to each transaction to be verified is generated, the processed transaction information and the transaction block are sent to a standby node, and the standby node synchronizes the transaction information based on the verification result of the master node, so that the transaction block is verified only once for each node of the organization, the network flow of the block chain is greatly reduced, the performance of the whole block chain network is improved, and computing resources are saved. Wherein the information may be stored in a blockchain node. Most of the computing resources can be used for serving the query request, the query request throughput of the whole block chain network is improved, and the request delay is reduced.

Description

Node synchronization method, device, equipment and storage medium of block chain
Technical Field
The present invention relates to the field of blockchain technologies, and in particular, to a method, an apparatus, a device, and a computer-readable storage medium for synchronizing nodes of a blockchain.
Background
A blockchain is generally understood to be a distributed ledger, which is essentially a distributed database. One of the fundamental differences between federation blockchains and common blockchains is the need to provide privacy protection mechanisms, which are typically implemented through signature encryption and signature verification decryption in cryptography. The signature verification, i.e. verifying the block signature, needs to verify not only the validity of all transaction signatures in the block, but also whether the signed policy satisfies the current policy. Therefore, this step involves a large number of mathematical operations and is time-consuming. Generally, a plurality of transactions are packed into blocks and sent to nodes on a block chain, and the nodes unpack the blocks and acquire the transactions in the blocks. And then, the node checks each transaction firstly, and then performs multi-version check on all transactions passing the check. Transactions that fail either of the checkmark and multi-version checks are marked as invalid within the block. And finally, writing the transaction information into a disk, wherein the whole process is executed in a serial mode. Thereafter, the node receives the next block and repeats the above steps in a loop. The main implementation method of the block chain in the current industry is to send the packed blocks to all nodes, and each node needs to completely repeat the steps. If there are too many nodes in a block chain, sending a block to each node will not only generate huge network traffic and seriously affect the performance of the whole block chain network, but also the steps of signature verification and multi-version check performed by each node will waste a lot of computing resources, affect the throughput of the query request of the whole block chain network, and cause the delay of the query request.
Disclosure of Invention
The invention mainly aims to provide a node synchronization method, a node synchronization device, a node synchronization equipment and a computer readable storage medium of a block chain, and aims to solve the technical problems of poor performance of the existing block chain network and high query request throughput of the block chain network.
In order to achieve the above object, the present invention provides a node synchronization method for a block chain, including the following steps:
selecting a main node from nodes in the same organization based on a preset election algorithm, and taking other nodes except the main node in the same organization as standby nodes;
performing transaction processing on each transaction to be verified in a transaction block through the master node, marking the validity of each transaction to be verified based on a transaction processing result corresponding to the transaction to be verified, generating transaction information corresponding to each transaction to be verified, and writing the transaction information into a master node disk;
and sending the transaction information in the transaction block and the master node disk to the standby node so that the standby node writes the transaction information corresponding to each transaction to be verified in the transaction block into the standby node disk, and completing the transaction information synchronization of the master node and the standby node.
Optionally, the step of selecting a master node from nodes in the same organization based on a preset election algorithm, and using other nodes in the same organization except the master node as standby nodes specifically includes:
determining the node weight corresponding to each node according to the mechanical performance value of each node in the same organization and the corresponding weight mapping relation, and determining the node with the maximum weight as the master node;
and setting other nodes except the main node in the same organization as the standby node.
Optionally, after the step of setting other nodes in the same organization except the master node as the standby node, the method further includes:
monitoring the heartbeat sent by the main node through the standby node, and converting the standby node into a candidate node if the standby node does not receive the heartbeat sent by the main node within a preset time interval;
each candidate node casts a vote to the node, sends an election request to other candidate nodes and receives votes which are sent by the other candidate nodes and carry self weights;
and determining a next main node in each candidate node based on the vote corresponding to each candidate node, and taking other candidate nodes as standby nodes.
Optionally, after the step of determining a next master node in the candidate nodes and taking other candidate nodes as standby nodes based on the votes corresponding to the candidate nodes, the method further includes:
determining the priority corresponding to each main node according to the determined sequence of each main node;
and when detecting that the plurality of main nodes are started, switching the current main node according to the priority corresponding to each started main node.
Optionally, the performing, by the master node, transaction processing on each to-be-verified transaction in the transaction block, performing validity marking on each to-be-verified transaction based on a transaction processing result corresponding to the to-be-verified transaction, generating transaction information corresponding to each to-be-verified transaction, and writing the transaction information into the master node disk specifically includes:
checking each transaction to be verified in the transaction block through the master node, and performing multi-version check on the transaction passing the check;
adding a corresponding validity mark to the transaction to be verified based on the signature verification result corresponding to the transaction to be verified and the multi-version checking result;
and generating transaction information corresponding to the transaction to be verified based on the transaction to be verified and the corresponding validity mark, and writing the transaction information into the master node disk.
Optionally, the step of adding a corresponding validity flag to the transaction to be verified based on the signature verification result and the multi-version check result corresponding to the transaction to be verified includes:
and adding a valid mark to the transaction to be verified which passes the verification label and the multi-version check, and adding an invalid mark to the transaction to be verified which does not pass the verification label or the multi-version check.
Optionally, the sending the transaction information in the transaction block and the master node disk to the standby node so that the standby node writes the transaction information corresponding to each to-be-verified transaction in the transaction block into the standby node disk, and the step of completing the synchronization of the transaction information of the master node and the standby node specifically includes:
and sending the transaction information in the transaction block and the master node disk to the standby node so that the standby node writes the validity marks corresponding to the transactions to be verified after the master node verifies into the standby node disk, and the transaction information synchronization of the master node and the standby node is completed.
In addition, to achieve the above object, the present invention further provides a node synchronization apparatus for a block chain, including:
the master and standby node determination module is used for selecting a master node from nodes in the same organization based on a preset election algorithm and taking other nodes except the master node in the same organization as standby nodes;
the verification result writing module is used for performing transaction processing on each transaction to be verified in the transaction block through the master node, marking the validity of each transaction to be verified based on the transaction processing result corresponding to the transaction to be verified, generating transaction information corresponding to each transaction to be verified, and writing the transaction information into a master node disk;
and the verification result synchronization module is used for sending the transaction information in the transaction block and the master node disk to the standby node so that the standby node writes the transaction information corresponding to each transaction to be verified in the transaction block into the standby node disk and completes the transaction information synchronization of the master node and the standby node.
In addition, to achieve the above object, the present invention further provides a node synchronization apparatus of a blockchain, where the node synchronization apparatus of a blockchain includes a processor, a memory, and a node synchronization program of the blockchain stored on the memory and executable by the processor, where the node synchronization program of the blockchain, when executed by the processor, implements the steps of the node synchronization method of the blockchain as described above.
In addition, to achieve the above object, the present invention further provides a computer readable storage medium, having a node synchronization program of a blockchain stored thereon, wherein when the node synchronization program of the blockchain is executed by a processor, the steps of the method for node synchronization of blockchain as described above are implemented.
The invention provides a node synchronization method of a block chain, which selects a main node from nodes in the same organization based on a preset election algorithm and takes other nodes in the same organization except the main node as standby nodes; performing transaction processing on each transaction to be verified in a transaction block through the master node, marking the validity of each transaction to be verified based on a transaction processing result corresponding to the transaction to be verified, generating transaction information corresponding to each transaction to be verified, and writing the transaction information into a master node disk; and sending the transaction information in the transaction block and the master node disk to the standby node so that the standby node writes the transaction information corresponding to each transaction to be verified in the transaction block into the standby node disk, and completing the transaction information synchronization of the master node and the standby node. By the mode, the master node is determined in the same organization, the transaction block is processed by the master node, the processed transaction information and the transaction block are sent to the standby node, and the standby node synchronizes the transaction information based on the verification result of the master node, so that the transaction block is verified once for each organized node, the network flow of a block chain is greatly reduced, the performance of the whole block chain network is improved, and the computing resources are greatly saved. Most of computing resources of the standby node can be used for serving the query request, the throughput of the query request of the whole block chain network is improved, the delay of each query request is reduced, and the technical problems that the existing block chain network is poor in performance and the throughput of the query request of the block chain network is high are solved.
Drawings
Fig. 1 is a schematic hardware structure diagram of a node synchronization device of a block chain according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a first embodiment of a method for node synchronization of a blockchain according to the present invention;
FIG. 3 is a flowchart illustrating a second embodiment of a block chain node synchronization method according to the present invention;
fig. 4 is a functional block diagram of a first embodiment of a node synchronization apparatus for a block chain according to the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The node synchronization method of the block chain related to the embodiment of the invention is mainly applied to the node synchronization equipment of the block chain, and the node synchronization equipment of the block chain can be equipment with display and processing functions, such as a PC, a portable computer, a mobile terminal and the like.
Referring to fig. 1, fig. 1 is a schematic diagram of a hardware structure of a node synchronization device of a block chain according to an embodiment of the present invention. In this embodiment of the present invention, the node synchronization apparatus of the blockchain may include a processor 1001 (e.g., a CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used for realizing connection communication among the components; the user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard); the network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface); the memory 1005 may be a high-speed RAM memory, or may be a non-volatile memory (e.g., a magnetic disk memory), and optionally, the memory 1005 may be a storage device independent of the processor 1001.
Those skilled in the art will appreciate that the hardware architecture shown in fig. 1 does not constitute a limitation of the node synchronization apparatus of the blockchain, and may include more or fewer components than those shown, or some components in combination, or a different arrangement of components.
With continued reference to fig. 1, a memory 1005 of fig. 1, which is one type of computer-readable storage medium, may include an operating system, a network communication module, and a node synchronization program of a blockchain.
In fig. 1, the network communication module is mainly used for connecting to a server and performing data communication with the server; and the processor 1001 may call a node synchronization program of the blockchain stored in the memory 1005 and execute the node synchronization method of the blockchain provided by the embodiment of the present invention.
The embodiment of the invention provides a node synchronization method of a block chain.
Referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of a node synchronization method for a block chain according to the present invention.
In this embodiment, the node synchronization method for the block chain includes the following steps:
step S10, selecting a main node from nodes in the same organization based on a preset election algorithm, and taking other nodes except the main node in the same organization as standby nodes;
at present, the main implementation method of the block chain in the industry is to send the packed blocks to all nodes, and each node needs to completely perform transaction processing steps such as signature verification and multi-version inspection. If there are too many nodes in a block chain, sending a block to each node will not only generate huge network traffic and seriously affect the performance of the whole block chain network, but also the steps of signature verification and multi-version check performed by each node will waste a lot of computing resources, affect the throughput of the query request of the whole block chain network, and cause the delay of the query request. In order to solve the problems, the master node is determined in the same organization, the transaction block is processed through the master node, the processed transaction information and the transaction block are sent to the standby node, and the standby node performs transaction information synchronization based on the verification result of the master node, so that the transaction block is verified once for each organized node, the network flow of a block chain is greatly reduced, the performance of the whole block chain network is improved, and the computing resources are greatly saved. Most of computing resources of the standby nodes can be used for serving the query requests, the throughput of the query requests of the whole block chain network is improved, and the delay of each query request is reduced. Specifically, in a blockchain network, a plurality of nodes often belong to the same organization, and nodes in the same organization are all on the same certificate chain, so that the nodes belonging to the same organization are mutually trusted. Therefore, as long as one node in an organization completes the steps, the result can be directly shared with other nodes in the same organization, and the other nodes do not need to repeat the steps of signature verification and multi-version inspection. In the existing blockchain network, all nodes in the same organization are in equal positions, so that all nodes need to repeat the steps of signature verification and multi-version checking. The method mainly includes that in the same organization, nodes are divided into a master node and a slave node, the master node is elected through a preset election algorithm, only one master node is provided, and all other nodes except the master node in the same organization are slave nodes.
Step S20, processing each transaction to be verified in the transaction block by the master node, marking the validity of each transaction to be verified based on the transaction processing result corresponding to the transaction to be verified, generating the transaction information corresponding to each transaction to be verified, and writing the transaction information into the master node disk;
in this embodiment, the master node in the same organization is responsible for receiving a new block, and performing signature verification and multi-version check on the received block. And the master node unlocks the block and acquires each transaction to be verified in the block. Then, the master node performs corresponding transaction processing on each transaction to be verified. In particular, transaction processing includes signature verification and multi-version checking. And according to the transaction processing result, marking the validity of each transaction to be verified, namely marking the transaction to be verified as a valid transaction or marking the transaction to be invalid. And then generating the transaction information of each transaction to be verified based on the mark corresponding to each transaction to be verified, writing the transaction information into a master node disk, and finishing the transaction processing of the master node on the transaction block.
Wherein, the step S20 specifically includes:
checking each transaction to be verified in the transaction block through the master node, and performing multi-version check on the transaction passing the check;
adding a corresponding validity mark to the transaction to be verified based on the signature verification result corresponding to the transaction to be verified and the multi-version checking result;
and generating transaction information corresponding to the transaction to be verified based on the transaction to be verified and the corresponding validity mark, and writing the transaction information into the master node disk.
Wherein, the step of adding the corresponding validity mark to the transaction to be verified based on the signature verification result and the multi-version check result corresponding to the transaction to be verified comprises:
and adding a valid mark to the transaction to be verified which passes the verification label and the multi-version check, and adding an invalid mark to the transaction to be verified which does not pass the verification label or the multi-version check.
In this embodiment, the master node first checks each transaction to be verified, and then performs multi-version check on all transactions that pass the check. Any transaction that fails either of the checkmark and multi-version check is marked as invalid within the block, i.e., an invalid flag is added, e.g., the flag bit is marked as 0. For example, if a transaction is marked as valid, the data carried in the transaction will be applied to the blockchain state database. Invalid transactions are directly ignored and no operation is performed on the block chain state database. For example, there is one piece of data in the current blockchain state database, where a is 1. The content of one transaction is to change the value of a to 3(a to 3). If the transaction is marked as valid after signature verification and multi-version check, a-3 will be applied to the blockchain state database. Then, the value of a is queried in the blockchain state database, and the result is 3. If the transaction is marked as invalid, the transaction is directly ignored, and then the value of a is inquired in the blockchain state database, and the result is 1.
Step S30, sending the transaction information in the transaction block and the master node disk to the standby node, so that the standby node writes the transaction information corresponding to each to-be-verified transaction in the transaction block into the standby node disk, and completes the transaction information synchronization between the master node and the standby node.
In this embodiment, the transaction block with each transaction validity flag is sent to other slave nodes in the same organization. When the slave node receives the block sent by the master node, the slave node directly writes the transaction information into the spare node disk according to the validity mark of each transaction in the block, namely the following steps are included:
1. writing the received blocks into a disc, wherein the blocks contain validity marking information of each transaction;
2. the blockchain state database is modified according to the validity of each transaction, and no signature verification and multi-version check are performed.
Meanwhile, slave and master nodes can be freely switched, and the problem that the nodes of the whole organization cannot work normally due to the failure of the master node is avoided.
Among them, writing to a disk actually has two layers:
1, if the backup node receives a block, the backup node writes the block into a disk (a hard disk or other storage equipment) in a file form, and the block contains all transactions including valid transactions and invalid transactions;
2 in the blocks received by the standby node, the validity of each transaction is marked by the main node, and the standby node directly applies the valid transactions to the block chain state database according to the marks. Since the block chain state database is also stored on the disk, the action of writing to the hard disk is also generated by writing to the database.
The embodiment provides a node synchronization method for a block chain, which selects a master node from nodes in the same organization based on a preset election algorithm, and takes other nodes in the same organization except the master node as standby nodes; performing transaction processing on each transaction to be verified in a transaction block through the master node, marking the validity of each transaction to be verified based on a transaction processing result corresponding to the transaction to be verified, generating transaction information corresponding to each transaction to be verified, and writing the transaction information into a master node disk; and sending the transaction information in the transaction block and the master node disk to the standby node so that the standby node writes the transaction information corresponding to each transaction to be verified in the transaction block into the standby node disk, and completing the transaction information synchronization of the master node and the standby node. By the mode, the master node is determined in the same organization, the transaction block is processed by the master node, the processed transaction information and the transaction block are sent to the standby node, and the standby node synchronizes the transaction information based on the verification result of the master node, so that the transaction block is verified once for each organized node, the network flow of a block chain is greatly reduced, the performance of the whole block chain network is improved, and the computing resources are greatly saved. Most of computing resources of the standby node can be used for serving the query request, the throughput of the query request of the whole block chain network is improved, the delay of each query request is reduced, and the technical problems that the existing block chain network is poor in performance and the throughput of the query request of the block chain network is high are solved.
Referring to fig. 3, fig. 3 is a flowchart illustrating a node synchronization method for a block chain according to a second embodiment of the present invention.
Based on the foregoing embodiment shown in fig. 2, in this embodiment, the step S10 specifically includes:
step S11, determining the node weight corresponding to each node according to the machine performance value of each node in the same organization and the corresponding weight mapping relation, and determining the node with the maximum weight as the master node;
step S12, setting other nodes in the same organization except the master node as the standby nodes.
In this embodiment, nodes participating in election often belong to the same organization, and the positions of the nodes in one organization are sometimes not completely the same. For example, some nodes have high machine performance, and are preferably selected as the master node because the master node needs to verify the validity of block data and send the block to other standby nodes. The load on the master node is higher and is better suited to be borne by a better performing node. And setting the node weight of each node according to the machine performance value of each node and the corresponding weight mapping relation. In a specific embodiment, when the change of the machine performance value of each node is detected, the node weight of each node is dynamically adjusted. That is, when each node is started, each node is given a certain weight, and this weight may be set according to specific situations, for example, when the performance value of the machine is greater than a certain threshold, the weight is set to 0.5, when the performance value of the machine is lower than a certain threshold, the weight is set to 0.1, and so on. The higher the expectation that a node becomes a leader node, the larger the weight of the node can be set. The weight value distributed by each node is based on the weight corresponding to each node, so that the sum of the weight values is not easy to repeat. Initially, the node with the largest weight is set as the master node. And then setting other nodes except the main node in the same organization as the standby node.
Further, after the step S12, the method further includes:
monitoring the heartbeat sent by the main node through the standby node, and converting the standby node into a candidate node if the standby node does not receive the heartbeat sent by the main node within a preset time interval;
each candidate node casts a vote to the node, sends an election request to other candidate nodes and receives votes which are sent by the other candidate nodes and carry self weights;
and determining a next main node in each candidate node based on the vote corresponding to each candidate node, and taking other candidate nodes as standby nodes.
In this embodiment, in order to detect an abnormal master node in time, the abnormal master node is prevented from causing abnormal transaction processing of the block chain. Initializing a standby node into a Follower node Follower node state, initializing a main node into a Leader node, and monitoring heartbeat sent by the Leader node through the Follower node. If the following Node (Node a) cannot sense the heartbeat sent by the Leader Node first, the state of the following Node (Node a) is converted into Candidate. An election timeout period is randomly distributed between 150ms and 300ms, and after the election timeout period, the Follower node is converted into a Candidate node and a new election optional period Term is started. Specifically, after determining the leader node, the state of other nodes in the same organization to which the node belongs is set as the follow node follow state. And detecting whether the heartbeat sent by the Leader node is received in real time. If the heartbeat is received, the main node is indicated to work normally, and if the heartbeat is not received, the main node is indicated to be abnormal and cannot work normally. When other nodes in the same organization do not receive the heartbeat sent by the Leader node, the self state is set as a Candidate node Candidate node by the follow node, namely the standby node is converted into the Candidate node. Each backup node in the Candidate state firstly casts a Vote (Voted For a) to itself and sends an election request (Voted For me) to other nodes to require that the node itself is elected as a Leader. And the other nodes send the voting information carrying the self weight to the node initiating the election request. When one node votes to other nodes, its own weight (for example, a node with a weight of 0.7 votes for 0.7). In an election period, all nodes which have received votes compare the sum of the weights of the received votes, and the elected Leader with the largest sum is determined as the next Leader node. Specifically, when each node receives an election request sent by another node, if the other nodes receiving the Candidate volume request have not voted for the election deadline (Term 1), they respond to the voting for the Candidate sending the request and reset the election timeout setting of the node. If the Candidate node gets votes for most nodes, it becomes the new Leader node in the current deadline. Other nodes will automatically become standby nodes after learning that the master node has been elected. At this time, the states of the Leader node and each Follower node are sensed by sending heartbeat messages until a certain Follower node can not sense the heartbeat of the Leader node first and then becomes a Candidate state and then initiates a new election again. The master node is thus elected based on the Raft algorithm in combination with the weighting algorithm.
Further, after the step of determining a next master node in the candidate nodes and taking other candidate nodes as standby nodes based on the votes corresponding to the candidate nodes, the method further includes:
determining the priority corresponding to each main node according to the determined sequence of each main node;
and when detecting that the plurality of main nodes are started, switching the current main node according to the priority corresponding to each started main node.
In this embodiment, when the first leader is elected, it is assigned an identifier with a priority of 1. If the leader hangs, then a new leader is elected, and the leader is assigned a priority of 2. If the leader with the priority of 1 is started again after a period of time, all the nodes reconnect the node with the priority of 1 and take the node as the leader. Therefore, the function of automatically switching the main node according to the node priority of the leader is realized.
In addition, the embodiment of the invention also provides a node synchronization device of the block chain.
Referring to fig. 4, fig. 4 is a functional block diagram of a first embodiment of a node synchronization apparatus for a block chain according to the present invention.
In this embodiment, the node synchronization apparatus of the block chain includes:
a master/slave node determination module 10, configured to select a master node from nodes in the same organization based on a preset election algorithm, and use other nodes in the same organization except the master node as slave nodes;
a verification result writing module 20, configured to perform, by the master node, transaction processing on each to-be-verified transaction in the transaction block, perform validity marking on each to-be-verified transaction based on a transaction processing result corresponding to the to-be-verified transaction, generate transaction information corresponding to each to-be-verified transaction, and write the transaction information into a master node disk;
and the verification result synchronization module 30 is configured to send the transaction information in the transaction block and the host node disk to the standby node, so that the standby node writes the transaction information corresponding to each to-be-verified transaction in the transaction block into the standby node disk, and completes the transaction information synchronization between the host node and the standby node.
Further, the verification result writing module 20 specifically includes:
the processing unit is used for verifying the signature of each transaction to be verified in the transaction block through the master node and performing multi-version check on the transaction passing the signature verification;
the marking unit is used for adding a corresponding validity mark to the transaction to be verified based on the signature verification result corresponding to the transaction to be verified and the multi-version checking result;
and the writing unit is used for generating transaction information corresponding to the transaction to be verified based on the transaction to be verified and the corresponding validity mark, and writing the transaction information into the master node disk.
Further, the marking unit is further configured to:
and adding a valid mark to the transaction to be verified which passes the verification label and the multi-version check, and adding an invalid mark to the transaction to be verified which does not pass the verification label or the multi-version check.
Further, the active/standby node determining module 10 specifically includes:
a master node determining unit, configured to determine a node weight corresponding to each node according to the machine performance value of each node in the same organization and the corresponding weight mapping relationship, and determine a node with a largest weight as the master node;
and the standby node determining unit is used for setting other nodes except the main node in the same organization as the standby nodes.
Further, the active/standby node determining module 10 is further configured to:
monitoring the heartbeat sent by the main node through the standby node, and converting the standby node into a candidate node if the standby node does not receive the heartbeat sent by the main node within a preset time interval;
each candidate node casts a vote to the node, sends an election request to other candidate nodes and receives votes which are sent by the other candidate nodes and carry self weights;
and determining a next main node in each candidate node based on the vote corresponding to each candidate node, and taking other candidate nodes as standby nodes.
Further, the active/standby node determining module 10 is further configured to:
determining the priority corresponding to each main node according to the determined sequence of each main node;
and when detecting that the plurality of main nodes are started, switching the current main node according to the priority corresponding to each started main node.
Each module in the node synchronization apparatus of the block chain corresponds to each step in the embodiment of the node synchronization method of the block chain, and the functions and implementation processes thereof are not described in detail herein.
In addition, the embodiment of the invention also provides a computer readable storage medium.
The computer readable storage medium of the present invention stores thereon a node synchronization program of a blockchain, wherein when the node synchronization program of the blockchain is executed by a processor, the steps of the node synchronization method of the blockchain as described above are implemented.
Further, the computer-readable storage medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to the use of the blockchain node, and the like.
The method for implementing the node synchronization procedure of the block chain when executed may refer to various embodiments of the node synchronization method of the block chain of the present invention, and will not be described herein again.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
The application is operational with numerous general purpose or special purpose computing system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like. The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (9)

1. A node synchronization method of a block chain is characterized by comprising the following steps:
selecting a main node from nodes in the same organization based on a preset election algorithm, and taking other nodes except the main node in the same organization as standby nodes;
performing transaction processing on each transaction to be verified in a transaction block through the master node, marking the validity of each transaction to be verified based on a transaction processing result corresponding to the transaction to be verified, generating transaction information corresponding to each transaction to be verified, and writing the transaction information into a master node disk;
sending the transaction information in the transaction block and the master node disk to the standby node so that the standby node writes the transaction information corresponding to each transaction to be verified in the transaction block into the standby node disk to complete the transaction information synchronization of the master node and the standby node;
the method comprises the following steps of selecting a master node from nodes in the same organization based on a preset election algorithm, and taking other nodes except the master node in the same organization as standby nodes, wherein the steps specifically comprise:
determining the node weight corresponding to each node according to the mechanical performance value of each node in the same organization and the corresponding weight mapping relation, and determining the node with the maximum weight as the master node;
setting other nodes except the main node in the same organization as the standby nodes;
after determining the node weight corresponding to each node according to the machine performance value of each node in the same organization and the corresponding weight mapping relationship, the method further comprises the following steps:
and when detecting that the machine performance value of each node changes, dynamically adjusting the node weight of each node.
2. The method for node synchronization of a blockchain according to claim 1, wherein the step of setting the other nodes except the master node in the same organization as the standby node further comprises:
monitoring the heartbeat sent by the main node through the standby node, and converting the standby node into a candidate node if the standby node does not receive the heartbeat sent by the main node within a preset time interval;
each candidate node casts a vote to the node, sends an election request to other candidate nodes and receives votes which are sent by the other candidate nodes and carry self weights;
and determining a next main node in each candidate node based on the vote corresponding to each candidate node, and taking other candidate nodes as standby nodes.
3. The method for node synchronization of a blockchain according to claim 2, wherein after the step of determining a next master node among the candidate nodes based on the votes corresponding to the candidate nodes and using other candidate nodes as standby nodes, the method further comprises:
determining the priority corresponding to each main node according to the determined sequence of each main node;
and when detecting that the plurality of main nodes are started, switching the current main node according to the priority corresponding to each started main node.
4. The method for node synchronization of a block chain according to claim 1, wherein the step of performing, by the master node, transaction processing on each transaction to be verified in the transaction block, performing validity marking on each transaction to be verified based on a transaction processing result corresponding to the transaction to be verified, generating transaction information corresponding to each transaction to be verified, and writing the transaction information into a master node disk specifically includes:
checking each transaction to be verified in the transaction block through the master node, and performing multi-version check on the transaction passing the check;
adding a corresponding validity mark to the transaction to be verified based on the signature verification result corresponding to the transaction to be verified and the multi-version checking result;
and generating transaction information corresponding to the transaction to be verified based on the transaction to be verified and the corresponding validity mark, and writing the transaction information into the master node disk.
5. The method for node synchronization of a blockchain according to claim 4, wherein the step of adding the corresponding validity flag to the transaction to be verified based on the corresponding signature verification result and the multi-version check result of the transaction to be verified comprises:
and adding a valid mark to the transaction to be verified which passes the verification label and the multi-version check, and adding an invalid mark to the transaction to be verified which does not pass the verification label or the multi-version check.
6. The node synchronization method of a block chain according to any one of claims 1 to 5, wherein the sending of the transaction information in the transaction block and the primary node disk to the standby node is performed so that the standby node writes the transaction information corresponding to each to-be-verified transaction in the transaction block into the standby node disk, and the step of completing the transaction information synchronization of the primary node and the standby node specifically includes:
and sending the transaction information in the transaction block and the master node disk to the standby node so that the standby node writes the validity marks corresponding to the transactions to be verified after the master node verifies into the standby node disk, and the transaction information synchronization of the master node and the standby node is completed.
7. A node synchronization apparatus of a blockchain, the node synchronization apparatus of the blockchain comprising:
the master and standby node determination module is used for selecting a master node from nodes in the same organization based on a preset election algorithm and taking other nodes except the master node in the same organization as standby nodes;
the verification result writing module is used for performing transaction processing on each transaction to be verified in the transaction block through the master node, marking the validity of each transaction to be verified based on the transaction processing result corresponding to the transaction to be verified, generating transaction information corresponding to each transaction to be verified, and writing the transaction information into a master node disk;
the verification result synchronization module is used for sending the transaction information in the transaction block and the host node disk to the standby node so that the standby node writes the transaction information corresponding to each transaction to be verified in the transaction block into the standby node disk to complete the transaction information synchronization of the host node and the standby node;
the master-slave node determining module is further configured to determine a node weight corresponding to each node according to the machine performance value of each node in the same organization and the corresponding weight mapping relationship, and determine the node with the largest weight as the master node; setting other nodes except the main node in the same organization as the standby nodes;
the active/standby node determining module is further configured to dynamically adjust the node weight of each node when detecting that the machine performance value of each node changes.
8. A blockchain node synchronization apparatus comprising a processor, a memory, and a blockchain node synchronization program stored on the memory and executable by the processor, wherein the blockchain node synchronization program when executed by the processor implements the steps of the blockchain node synchronization method of any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a node synchronization program of a blockchain, wherein the node synchronization program of the blockchain, when executed by a processor, implements the steps of the node synchronization method of the blockchain according to any one of claims 1 to 6.
CN202010363964.8A 2020-04-30 2020-04-30 Node synchronization method, device, equipment and storage medium of block chain Active CN111586147B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202010363964.8A CN111586147B (en) 2020-04-30 2020-04-30 Node synchronization method, device, equipment and storage medium of block chain
PCT/CN2020/098929 WO2021217849A1 (en) 2020-04-30 2020-06-29 Blockchain node synchronization method, apparatus and device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010363964.8A CN111586147B (en) 2020-04-30 2020-04-30 Node synchronization method, device, equipment and storage medium of block chain

Publications (2)

Publication Number Publication Date
CN111586147A CN111586147A (en) 2020-08-25
CN111586147B true CN111586147B (en) 2021-09-28

Family

ID=72126247

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010363964.8A Active CN111586147B (en) 2020-04-30 2020-04-30 Node synchronization method, device, equipment and storage medium of block chain

Country Status (2)

Country Link
CN (1) CN111586147B (en)
WO (1) WO2021217849A1 (en)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111988203B (en) * 2020-09-03 2022-08-23 深圳壹账通智能科技有限公司 Node election method, device and storage medium
CN112202834B (en) * 2020-09-03 2024-04-23 金证财富南京科技有限公司 Data processing method, data processing device and node server
CN112804089B (en) * 2020-12-31 2023-07-25 北京百度网讯科技有限公司 Method, device, equipment and storage medium for realizing operation of alliance network
CN113783921A (en) * 2021-01-27 2021-12-10 北京京东振世信息技术有限公司 Method and device for creating cache component
CN114500525B (en) * 2021-12-24 2024-04-26 天翼云科技有限公司 Method, device, computer equipment and medium for updating nodes in distributed system
CN114420277A (en) * 2022-01-25 2022-04-29 河海大学 Block chain hospital bed management system based on improved Raft algorithm
CN114448769B (en) * 2022-04-02 2022-07-01 支付宝(杭州)信息技术有限公司 Node election voting method and device based on consensus system
CN115150273B (en) * 2022-06-30 2024-05-28 联想(北京)有限公司 Upgrade processing method and device
CN115835368B (en) * 2023-02-24 2023-06-02 深圳锦沃科技有限公司 Decentralizing multi-base-station time slot synchronization method, system and storage medium
CN116260707B (en) * 2023-05-15 2023-10-10 安徽中科晶格技术有限公司 Block chain node disaster recovery method, device and equipment based on consensus and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108122165A (en) * 2017-12-15 2018-06-05 北京中电普华信息技术有限公司 A kind of block chain common recognition method and system
CN108289129A (en) * 2018-02-26 2018-07-17 深圳智乾区块链科技有限公司 Block chain ecological environment creation method, system and computer readable storage medium
CN109614206A (en) * 2018-10-25 2019-04-12 深圳壹账通智能科技有限公司 Device, method and the storage medium of block chain issued transaction
KR20190092362A (en) * 2019-07-31 2019-08-07 네이버 주식회사 Data replicating in database sharding environment

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10200197B1 (en) * 2017-12-18 2019-02-05 Nec Corporation Scalable crash fault-tolerance consensus protocol with efficient message aggregation
CN108134706B (en) * 2018-01-02 2020-08-18 中国工商银行股份有限公司 Block chain multi-activity high-availability system, computer equipment and method
CN108537063A (en) * 2018-02-26 2018-09-14 阿里巴巴集团控股有限公司 A kind of method, apparatus and equipment of data storage
CN109859047A (en) * 2019-01-31 2019-06-07 北京瑞卓喜投科技发展有限公司 A kind of block chain update method and block chain more new system
CN110061856A (en) * 2019-03-07 2019-07-26 阿里巴巴集团控股有限公司 A kind of communication means based on block chain, device and electronic equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108122165A (en) * 2017-12-15 2018-06-05 北京中电普华信息技术有限公司 A kind of block chain common recognition method and system
CN108289129A (en) * 2018-02-26 2018-07-17 深圳智乾区块链科技有限公司 Block chain ecological environment creation method, system and computer readable storage medium
CN109614206A (en) * 2018-10-25 2019-04-12 深圳壹账通智能科技有限公司 Device, method and the storage medium of block chain issued transaction
KR20190092362A (en) * 2019-07-31 2019-08-07 네이버 주식회사 Data replicating in database sharding environment

Also Published As

Publication number Publication date
WO2021217849A1 (en) 2021-11-04
CN111586147A (en) 2020-08-25

Similar Documents

Publication Publication Date Title
CN111586147B (en) Node synchronization method, device, equipment and storage medium of block chain
US10984134B2 (en) Blockchain system for leveraging member nodes to achieve consensus
Shraer et al. Venus: Verification for untrusted cloud storage
Xiao et al. Achieving accountable MapReduce in cloud computing
US7487348B2 (en) System for authenticating and screening grid jobs on a computing grid
CN110569251A (en) Data processing method, related equipment and computer readable storage medium
WO2022166637A1 (en) Blockchain network-based method and apparatus for data processing, and computer device
US8938648B2 (en) Multi-entity test case execution workflow
CN111414413A (en) Block chain endorsement verification
CN103077345B (en) Based on software authorization method and the system of virtual machine
CN111159143A (en) Block chain based evaluation system and method thereof
CN115328645A (en) Computing task scheduling method, computing task scheduling device and electronic equipment
CN112422368A (en) Database cluster monitoring method and system based on clickhouse
CN110998535A (en) Restoring application functionality via analysis of application operation requests
CN101129043A (en) Method, system, and program product for connecting a client to a network
CN109818965B (en) Personal identity verification device and method
WO2022141024A1 (en) Blockchain technology-based business transaction method and system, and storage medium
CN111832018A (en) Virus detection method, virus detection device, computer device and storage medium
CN108600156A (en) A kind of server and safety certifying method
JP2023509209A (en) Cloud system migration method and device, and hybrid cloud system
CN111899018A (en) Order data processing method, device, server and storage medium
CN102868594B (en) Method and device for message processing
CN111988202B (en) Node switching method, device and storage medium
CN112350868B (en) Wall opening processing method, device, server, system and readable storage medium
CN114237991A (en) Main/standby service switching method, device, equipment and medium based on cold standby mode

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