Block synchronization method, device and storage medium
By using the P2P module in the blockchain node to monitor the block height and reading the cache height from the database to send the block synchronization request, the problem of low block synchronization efficiency in the existing technology is solved and more efficient block synchronization is achieved.
Patent Information
- Application Number
- CN202011279723.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-16
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2040-11-16
AI Technical Summary
In existing blockchain technology, the block synchronization efficiency of nodes is low, especially when the blockchain module requests are slow or blocks when parsing block information.
Whether the latest block height of the current node through the P2P module is lower than the latest block height of the blockchain network. If so, read the latest cache height from the pre -configured database, and send the block to the connected nodes to request the block synchronized request to the connected node synchronized request , Synchronize blocks.
The efficiency of block synchronization has been improved, and the synchronization efficiency caused by blocking of block information is reduced due to the slow request request of the Blockchain module.
Smart Images

Figure CN112328693B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a block synchronization method, device and storage medium. Background Art
[0002] In the existing blockchain technology, a database is configured in the blockchain module of a node, and there are synchronized but unexecuted blocks in the database. For example, the latest block height of the blockchain network is 256, and the latest block height of node A is 200. Node A lags behind, and the database configured in the blockchain module of node A still contains synchronized but unexecuted blocks block (201) to block (212); the blockchain module of node A needs to send a block synchronization request including the block height 213 to be synchronized to the P2P module, so as to trigger the P2P module to request synchronized blocks from other connected nodes.
[0003] In the above mechanism, once the request of the blockchain module is slow, or the blockchain module blocks the block synchronization request when parsing other block information, the efficiency of node synchronization blocks will be reduced. Summary of the invention
[0004] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a block synchronization method, device and storage medium that improve the efficiency of block synchronization.
[0005] In a first aspect, the present invention provides a block synchronization method applicable to a blockchain node, the method comprising:
[0006] The P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network:
[0007] If yes, the latest cache height of the current node is read from the preconfigured database; the database is used by the blockchain module to store blocks that have been synchronized but not executed from other nodes, and the database can be accessed by the blockchain module and the P2P module. The latest cache height is the block height of the latest block that has been synchronized but not executed by the current node; and,
[0008] The P2P module sends block synchronization requests to several connected nodes according to the latest cache height to synchronize blocks.
[0009] In a second aspect, the present invention further provides a device, comprising one or more processors and a memory, wherein the memory contains instructions executable by the one or more processors so that the one or more processors execute the block synchronization method provided according to various embodiments of the present invention.
[0010] In a third aspect, the present invention further provides a storage medium storing a computer program, wherein the computer program enables a computer to execute the block synchronization method provided according to various embodiments of the present invention.
[0011] The block synchronization method, device and storage medium provided by many embodiments of the present invention monitor whether the latest block height of the current node is lower than the latest block height of the blockchain network through a P2P module: if so, the latest cache height of the current node is read from a preconfigured database; wherein the database is used for the blockchain module to store blocks synchronized from other nodes but not executed, the database can be accessed by the blockchain module and the P2P module, and the latest cache height is the block height of the latest block that has been synchronized but not executed by the current node; the P2P module sends a block synchronization request to several connected nodes according to the latest cache height to synchronize blocks, thereby improving the efficiency of block synchronization. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0013] Figure 1 A flowchart of a block synchronization method provided by an embodiment of the present invention.
[0014] Figure 2 A schematic diagram of the structure of a device provided in one embodiment of the present invention. DETAILED DESCRIPTION
[0015] The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the invention are shown in the accompanying drawings.
[0016] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0017] Figure 1 A flowchart of a block synchronization method provided by an embodiment of the present invention. Figure 1 As shown, in this embodiment, the present invention provides a block synchronization method applicable to a blockchain node, and the method includes:
[0018] S121: The P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network:
[0019] If yes, then execute step S122: read the latest cache height of the current node from a preconfigured database; wherein the database is used for the blockchain module to store blocks synchronized from other nodes but not executed, and the database can be accessed by the blockchain module and the P2P module, and the latest cache height is the block height of the latest block synchronized but not executed by the current node; and,
[0020] S123: The P2P module sends a block synchronization request to several connected nodes according to the latest cache height to synchronize the blocks.
[0021] Specifically, the P2P module sends a block synchronization request to several connected nodes according to the latest cache height to synchronize blocks, including "the P2P module sends a first block header request information to several seed nodes according to the latest cache height to obtain the first block headers of several first blocks to be synchronized by consensus; the P2P module sends a second block header request information to several connected nodes according to the latest cache height to obtain the second block headers of each first block by consensus; the P2P module sends a block synchronization request information to the nodes whose second block headers are the same as the first block headers to synchronize each first block" as an example;
[0022] Assume that the current node is node A, and the other nodes connected to node A are nodes B to G. The latest block height of the blockchain network is 256, and the latest block height of node A is 200. Node A lags behind, and the database configured in the blockchain module of node A still contains synchronized but unexecuted blocks block (201) to block (212); the first blocks to be synchronized are block (213) to block (223);
[0023] In the prior art, the blockchain module of node A reads the latest cache height 212 of node A from the configured database, and the blockchain module of node A sends a block synchronization request to the P2P module (the block synchronization request includes the block height 213 to be synchronized) to trigger the P2P module to request block (213) or several blocks including block (213) from several other connected nodes (such as node B and node C).
[0024] In the prior art, once the request of the blockchain module of node A is slow, or the blockchain module of node A blocks the block synchronization request when parsing other block information, the efficiency of synchronizing blocks of node A is reduced.
[0025] In this application:
[0026] The P2P module of node A executes step S121 to monitor whether the latest block height of the current node is lower than the latest block height of the blockchain network:
[0027] Since the latest block height of the blockchain network is 256, the latest block height of node A is 200, and 200 is less than 256, step S122 is executed to read the latest cache height of node A from the preconfigured database, and the latest cache height read is 212; and,
[0028] The P2P module of node A executes step S123. The P2P module of node A sends block header request information to several seed nodes (assuming that there are seed nodes seed1 to seed4 in the blockchain network, where the several seed nodes are seed1, seed2, and seed3) according to step 212 to obtain {blockheader(213) to blockheader(223)}_seed1 returned by seed1, {blockheader(213) to blockheader(223)}_seed2 returned by seed2, and {blockheader(213) to blockheader(223)}_seed2 returned by seed3. 23)}_seed3, according to {blockheader(213)~blockheader(223)}_seed1~{blockheader(213)~blockheader(223)}_seed3, obtain the consensus {blockheader(213)~blockheader(223)}; it should be noted that seed1, seed2 and seed3 are only examples, and the several seed nodes may be some of the seed nodes in the blockchain network, or all of the seed nodes in the blockchain network, or some of the seed nodes with better current performance in the blockchain network, which is not specifically limited in this application;
[0029] The P2P module sends block header request information to the connected nodes (assuming they are nodes B, C and D) according to 212, to obtain {blockheader(213)~blockheader(223)}_nodeB returned by node B, {blockheader(213)~blockheader(223)}_nodeC returned by node C, and {blockheader(213)~blockheader(223)}_nodeD returned by node D, and obtains the consensus {blockheader(213)~blockheader(223)}' according to {blockheader(213)~blockheader(223)}_nodeB~{blockheader(213)~blockheader(223)}_nodeD; it should be noted that nodes B, C and D are only examples here, and the connected nodes may be some of the other connected nodes, or all the connected nodes, or some of the other connected nodes with better current performance, which is not specifically limited in this application;
[0030] The P2P module sends a block synchronization request message to the node {blockheader(213)~blockheader(223)}'={blockheader(213)~blockheader(223)} (for example, node B) to synchronize block(213)~block(223); it should be noted that node B is only an example here, and the nodes {blockheader(213)~blockheader(223)}'={blockheader(213)~blockheader(223)} may be node B and node C, node B and node D, node C and node D, node B~node D, and when the node {blockheader(213)~blockheader(223)}'={blockheader(213)~blockheader(223)} is found, the block synchronization request message may be sent to one of the nodes, some of the nodes, or all of the nodes to synchronize block(213)~block(223), which is not specifically limited in the present application.
[0031] In more embodiments, the P2P module sends first block header request information to several seed nodes according to the latest cache height to obtain the first block headers of several first blocks to be synchronized by consensus, which can also be replaced with "the P2P module sends first block header request information to the first seed node according to the latest cache height to obtain the first block headers of several first blocks to be synchronized" according to actual needs. Since the seed node is generally a trusted node deployed by the blockchain operator, requesting the first block headers of several first blocks from any of the seed nodes can also achieve the same technical effect.
[0032] In more embodiments, the P2P module sends a block synchronization request to several connected nodes according to the latest cache height to synchronize the block. It can also be configured according to actual needs, for example, it is configured as "the P2P module sends a first block header request information to several seed nodes according to the latest cache height to obtain the first block header of the first block to be synchronized by consensus; the P2P module sends a second block header request information to several connected nodes according to the latest cache height to obtain the second block header of the first block to be synchronized by consensus; the P2P module sends a block synchronization request information to the node whose second block header is the same as the first block header to synchronize the block. Synchronize the first block, or several blocks including the first block. "Specifically, the P2P module of node A sends block header request information to several seed nodes (assuming that there are seed nodes seed1 to seed4 in the blockchain network, and the several seed nodes here are seed1, seed2, and seed3) according to 212 to obtain blockheader(213)_seed1 returned by seed1, blockheader(213)_seed2 returned by seed2, and blockheader(213)_seed3 returned by seed3. 3. Obtain the consensus blockheader (213) according to blockheader (213)_seed1~blockheader (213)_seed3; the P2P module sends block header request information to several connected nodes (assuming they are node B, node C and node D) according to 212 to obtain blockheader (213)_nodeB returned by node B, blockheader (213)_nodeC returned by node C, and blockheader (213)_nodeD returned by node D, and obtains the consensus blockheader (213)' according to blockheader (213)_nodeB~blockheader (213)_nodeD; the P2P module sends block synchronization request information to the node (for example, node B) where blockheader (213)'=blockheader (213) to synchronize block (213), or several blocks (for example, block (213)~block (223)) including block (213); the same technical effect can be achieved. Similarly, since seed nodes are generally trusted nodes deployed by blockchain operators, requesting the first block header of the first block to be synchronized from any of the seed nodes can also achieve the same technical effect.Those skilled in the art should also be able to associate appropriate variations of "the P2P module sends block synchronization requests to several connected nodes to synchronize blocks according to the latest cache height". For example, after the current node obtains the first block headers of several first blocks to be synchronized by consensus, it directly synchronizes the corresponding blocks to other connected nodes. During the synchronization process, it first compares the block headers of several first blocks of other nodes with the first block headers of several first blocks. If they are consistent, it requests synchronization of each first block. The advantage of this variation is that it saves network interaction actions.
[0033] It should be noted that in this embodiment, the P2P module requests the block header of the block to be synchronized from the seed nodes and the connected nodes. In more embodiments, the content of the request may be the block hash of the block to be synchronized, or the block hash of the block to be synchronized plus the parent hash, which can achieve the same technical effect.
[0034] It should be noted that those skilled in the art should understand that in the specific block synchronization process, certain improvements can be made according to actual needs. For example, the size of the blocks can be analyzed and the smaller and scattered blocks can be synchronized as a whole, which further saves the number of times the blocks are downloaded and improves the efficiency of block synchronization.
[0035] It should be noted that those skilled in the art should understand that the latest block height of the blockchain network can be configured according to actual needs, for example, configured as the latest block height of the node with the highest block height among the nodes to which the current node is connected, or the average of the latest block heights of the nodes to which the current node is connected.
[0036] It should be noted that those skilled in the art should understand that the current node may not go through the proofreading process (the P2P module sends the first block header request information to several seed nodes according to the latest cache height to obtain the first block headers of several first blocks to be synchronized by consensus; the P2P module sends the second block header request information to several connected nodes according to the latest cache height to obtain the second block headers of each first block by consensus; the P2P module sends the block synchronization request information to the nodes whose second block headers are the same as the first block headers to synchronize each first block) or other properly modified proofreading processes, and directly sends the block synchronization request to several connected nodes according to the latest cache height to synchronize the blocks. However, if there is no proofreading process, the current node may be connected to a forked chain, and the correctness of the acquired blocks cannot be guaranteed.
[0037] In this application, the P2P module does not need to wait for receiving the block synchronization request from the blockchain to synchronize the block. The P2P module will automatically and proactively synchronize the block according to the currently missing block, improving the synchronous processing of the blockchain module and the P2P module to the asynchronous processing of the blockchain module and the P2P, thereby improving the efficiency of block synchronization.
[0038] Preferably, the P2P module sends a block synchronization request to several connected nodes according to the latest cache height to synchronize blocks, including:
[0039] The P2P module sends a first block header request message to a number of seed nodes according to the latest cache height to obtain the first block header of the first block to be synchronized after consensus;
[0040] The P2P module sends a second block header request message to several connected nodes according to the latest cache height to obtain the second block header of the first block to be synchronized after consensus;
[0041] The P2P module sends a block synchronization request message to a node whose second block header is the same as the first block header to synchronize the first block, or several blocks including the first block.
[0042] The block synchronization principle of the above embodiment can be referred to Figure 1 The method shown will not be repeated here.
[0043] Preferably, the P2P module sends a block synchronization request to several connected nodes according to the latest cache height to synchronize blocks, including:
[0044] The P2P module sends first block header request information to several seed nodes according to the latest cache height to obtain the first block headers of several first blocks to be synchronized after consensus;
[0045] The P2P module sends a second block header request message to several connected nodes according to the latest cache height to obtain the second block header of each first block that has been agreed upon;
[0046] The P2P module sends block synchronization request information to nodes whose second block headers are the same as those of the first block headers to synchronize the first blocks.
[0047] The block synchronization principle of the above embodiment can be referred to Figure 1 The method shown will not be repeated here.
[0048] Preferably, the P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network, including:
[0049] When the current node starts the blockchain service, the P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network.
[0050] Preferably, the P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network, including:
[0051] When the current moment is a preconfigured moment, the P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network.
[0052] Figure 2 A schematic diagram of the structure of a device provided by an embodiment of the present invention. Figure 2 As shown, as another aspect, the present application also provides a device, including one or more central processing units (CPU) 201, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 202 or the program loaded from the storage part 208 to the random access memory (RAM) 203. In the RAM 203, various programs and data required for the operation of the device 200 are also stored. The CPU 201, the ROM 202, and the RAM 203 are connected to each other through a bus 204. An input / output (I / O) interface 205 is also connected to the bus 204.
[0053] The following components are connected to the I / O interface 205: an input section 206 including a keyboard, a mouse, etc.; an output section 207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 208 including a hard disk, etc.; and a communication section 209 including a network interface card such as a LAN card, a modem, etc. The communication section 209 performs communication processing via a network such as the Internet. A drive 210 is also connected to the I / O interface 205 as needed. A removable medium 211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 210 as needed, so that a computer program read therefrom is installed into the storage section 208 as needed.
[0054] In particular, according to an embodiment of the present disclosure, the method described in any of the above embodiments can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program tangibly contained on a machine-readable medium, and the computer program includes a program code for executing any of the above methods. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 209, and / or installed from the removable medium 211.
[0055] As another aspect, the present application also provides a computer-readable storage medium, which may be a computer-readable storage medium included in the apparatus of the above embodiment; or a computer-readable storage medium that exists independently and is not assembled into the device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the method described in the present application.
[0056] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a dedicated hardware-based system that performs a specified function or operation, or can be realized by a combination of dedicated hardware and computer instructions.
[0057] The units or modules involved in the embodiments described in the present application may be implemented by software or by hardware. The units or modules described may also be arranged in a processor. For example, each of the units may be a software program arranged in a computer or a mobile smart device, or may be a separately configured hardware device. The names of these units or modules do not, in some cases, constitute limitations on the units or modules themselves.
[0058] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the concept of the present application. For example, the above features are replaced with (but not limited to) technical features with similar functions disclosed in the present application.
Claims
1. A block synchronization method, characterized in that: Applicable to blockchain nodes, the method comprises: a P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network; if yes, the latest cache height of the current node is read from a preconfigured database; wherein the database is used for the blockchain module to store blocks synchronized from other nodes but not executed, the database can be accessed by the blockchain module and the P2P module, the latest cache height is the block height of the latest block synchronized but not executed by the current node; and the P2P module sends a block synchronization request to several connected nodes according to the latest cache height to synchronize blocks; The P2P module sends a block synchronization request to several connected nodes according to the latest cache height to synchronize blocks, including: the P2P module sends a first block header request information to several seed nodes according to the latest cache height to obtain a first block header of a first block to be synchronized that has been agreed upon; The P2P module sends a second block header request message to the connected nodes according to the latest cache height to obtain the second block header of the first block to be synchronized after consensus; The P2P module sends a block synchronization request message to a node whose second block header is the same as the first block header to synchronize the first block, or several blocks including the first block.
2. The method according to claim 1, characterized in that The P2P module sends a block synchronization request to the connected nodes according to the latest cache height to synchronize blocks, including: the P2P module sends a first block header request information to the seed nodes according to the latest cache height to obtain the first block headers of the first blocks to be synchronized according to consensus; The P2P module sends a second block header request message to the connected nodes according to the latest cache height to obtain the second block headers of each of the first blocks that have been agreed upon; The P2P module sends block synchronization request information to nodes whose second block headers are the same as those of the first block headers to synchronize the first blocks.
3. The method according to any one of claims 1 to 2, characterized in that: The P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network, including: when the current node starts the blockchain service, the P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network.
4. The method according to any one of claims 1 to 3, characterized in that: The P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network, including: when the current moment is a preconfigured moment, the P2P module monitors whether the latest block height of the current node is lower than the latest block height of the blockchain network.
5. A device, characterized in that: The device includes: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are caused to perform the method according to any one of claims 1 to 4.
6. A storage medium storing a computer program, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Data processing method and device based on block chain
CN109086325A
Equipment management method and device based on block chain and computer equipment
CN111737360A