Block synchronization method and device of block chain network, equipment, medium and product
By sending requests to the second node and block archiving device in the blockchain network to obtain and verify the consistency of index information, the problem of node storage pressure and processing pressure in the blockchain network is solved, and more efficient block synchronization and security improvement are achieved.
Patent Information
- Application Number
- CN202310842763.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-10
- Publication Date
- 2025-01-10
AI Technical Summary
In a blockchain network, the storage of identical data by nodes increases storage costs, and when a new node joins, it needs to query and synchronize data with a specific node, which increases storage and processing pressure.
By sending a block synchronization request to the second node in the blockchain network, receiving index information, and sending an instruction to the block archiving device to obtain blocks within the target block height range, the block is added to the ledger of the first node after comparing the consistency of the index information, thus reducing the need for nodes to store complete blocks.
It reduces the storage costs and processing pressure on nodes, and improves the reliability and network security of block data by verifying the consistency of index information.
Smart Images

Figure CN119299465A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a method, device, equipment, medium and product for synchronizing blocks in a blockchain network. Background Art
[0002] With the rapid development of blockchain networks, a lot of data will be generated after a period of operation, so the data stored in the blockchain network is massive. Due to the characteristics of the blockchain network, each node in the blockchain network stores the same data, which increases the storage cost.
[0003] The current method is generally to select a node (such as node A) in the blockchain network to store all the data. The data stored in node A will not be archived, and the data of other nodes in the blockchain network except node A can be archived, thereby reducing the storage cost of the blockchain network. Although this method reduces the storage cost to a certain extent, when new nodes join the blockchain network in the future, they need to query and synchronize the corresponding block data with node A. It can be seen that this method will greatly increase the storage pressure and processing pressure of node A for block data. Summary of the invention
[0004] The embodiments of the present application provide a block synchronization method, device, equipment, medium and product for a blockchain network, which can reduce the storage pressure and processing pressure of nodes in the blockchain network for block data.
[0005] In a first aspect, the present application provides a block synchronization method for a blockchain network, the method being applied to a first node in the blockchain network; the method comprising:
[0006] Sending a first block synchronization request to a second node in the blockchain network, and receiving first index information sent by the second node based on the first block synchronization request; the first index information refers to index information of blocks within a target block height range, and the blocks within the target block height range refer to blocks that have been archived by the second node to a block archiving device;
[0007] Sending a second block synchronization request to the block archiving device; the second block synchronization request includes indication information, and the indication information is used to indicate the blocks within the target block height range that need to be synchronized;
[0008] receiving a first block indicated by the indication information and second index information of the first block sent by the block archiving device;
[0009] If the second index information is consistent with the first index information, the first block is added to the block ledger of the first node.
[0010] In a second aspect, the present application provides a block synchronization device for a blockchain network, the device being applied to a first node in the blockchain network; the device comprising:
[0011] A first request unit is used to send a first block synchronization request to a second node in the blockchain network, and receive first index information sent by the second node based on the first block synchronization request; the first index information refers to index information of blocks within a target block height range, and the blocks within the target block height range refer to blocks that have been archived by the second node to a block archiving device;
[0012] A second request unit is used to send a second block synchronization request to the block archiving device; the second block synchronization request includes indication information, and the indication information is used to indicate the blocks within the target block height range that need to be synchronized;
[0013] A data receiving unit, configured to receive the first block indicated by the indication information and the second index information of the first block sent by the block archiving device;
[0014] A data adding unit is used to add the first block to the block ledger of the first node if the second index information is consistent with the first index information.
[0015] In a third aspect, the present application provides a computer device comprising a processor and a memory, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the block synchronization method of the above-mentioned blockchain network.
[0016] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it can implement the block synchronization method of the above-mentioned blockchain network.
[0017] In a fifth aspect, the present application provides a computer program product or a computer program, which includes computer instructions, which, when executed by a processor, can implement the block synchronization method of the above-mentioned blockchain network.
[0018] In the embodiment of the present application, by sending a first block synchronization request to a second node in the blockchain network, receiving the first index information of the block within the target block height range sent by the second node based on the first block synchronization request; by sending a second block synchronization request containing indication information to a block archiving device, the first block indicated by the indication information sent by the block archiving device and the second index information of the first block are obtained, and then when the second index information is consistent with the first index information, the first block can be added to the block account book of the first node, thereby realizing the first node joining the blockchain network. By archiving the block of the second node in the blockchain network to the block archiving device, the second node in the blockchain network does not need to store the complete block, which can reduce the pressure on the nodes in the blockchain network to store block data, thereby reducing the storage cost of the node. In addition, when a new node joins the blockchain network, it can directly obtain the block from the block archiving device for synchronization, without obtaining the block from the second node in the blockchain network for synchronization, which can reduce the processing pressure on the nodes in the blockchain network for block data. In addition, by judging the consistency between the second index information obtained in the block archiving device and the first index information obtained in the blockchain network, it is possible to further verify whether the blocks in the block archiving device have been tampered with, thereby improving the reliability of the block data and thereby improving the security of the blockchain network. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1a It is a schematic diagram of a system architecture provided by an embodiment of the present application;
[0021] Figure 1b This is a schematic diagram of a block synchronization system of a blockchain network provided in an embodiment of the present application;
[0022] Figure 1c This is a schematic diagram of a blockchain provided by an embodiment of the present application;
[0023] Figure 2 It is a flowchart of a block synchronization method of a blockchain network provided in an embodiment of the present application;
[0024] Figure 3 It is a block archiving device and chain topology diagram provided in an embodiment of the present application;
[0025] Figure 4This is a schematic diagram of a scenario in which a first node detects the network status of a blockchain network, provided in an embodiment of the present application;
[0026] Figure 5 It is a flowchart of another block synchronization method of a blockchain network provided in an embodiment of the present application;
[0027] Figure 6 This is a schematic diagram of a scenario of synchronizing blocks from a blockchain network provided by an embodiment of the present application;
[0028] Figure 7 It is a schematic diagram of the composition structure of a block synchronization device of a blockchain network provided in an embodiment of the present application;
[0029] Figure 8 It is a schematic diagram of the composition structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0031] See also Figure 1a , Figure 1a is a schematic diagram of a system architecture provided by an embodiment of the present application, such as Figure 1a As shown, the system architecture diagram includes a blockchain network 11, a block archiving device 12, and a first node 13. Among them, the blockchain network 11 includes multiple second nodes, and the second node may refer to a node that has joined the blockchain network 11. The multiple second nodes in the blockchain network 11 can be used to store block data, the block archiving device 12 can be used to archive the block data in the blockchain network 11, and the first node 13 may refer to a new node that needs to be added to the blockchain network 11. Further, the multiple second nodes in the blockchain network 11 can archive the block data to the block archiving device 12 to reduce the resource storage space of the multiple second nodes in the blockchain network 11. When the first node 13 needs to join the blockchain network 11, the first index information of the archived block data can be obtained from the multiple second nodes in the blockchain network 11, and the archived block data and the second index information can be obtained from the block archiving device 12, and the first index information can be compared with the second index information to see if they are consistent. When the first index information is consistent with the second index information, it indicates that the first block is credible and has not been tampered with. Then, the first block can be synchronized to the first node 13, thereby adding the first node 13 to the blockchain network 11.
[0032] It is understandable that the first node, block archiving device, and second node mentioned in the embodiment of the present application may include but are not limited to terminal devices or servers, and may also be a system composed of servers and terminal devices. Among them, the terminal device mentioned above may be an electronic device, including but not limited to mobile phones, tablet computers, desktop computers, laptop computers, PDAs, vehicle-mounted devices, intelligent voice interaction devices, augmented reality / virtual reality (AR / VR) devices, helmet displays, wearable devices, smart speakers, smart home appliances, aircraft, digital cameras, cameras, and other mobile Internet devices (mobile internet device, MID) with network access capabilities. Among them, the server mentioned above may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, vehicle-road collaboration, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
[0033] It should be noted that the collection and processing of relevant data (such as block data and block synchronization requests, etc., which may include block and index information, etc.) in the embodiments of the present application should be strictly in accordance with the requirements of relevant national laws and regulations when applied in instances, and the informed consent or separate consent of the subject of personal information should be obtained, and subsequent data use and processing should be carried out within the scope of authorization of laws and regulations and the subject of personal information.
[0034] Also, see Figure 1b , Figure 1b Schematic diagram of a block synchronization system of a blockchain network provided in an embodiment of the present application, such as Figure 1b The block synchronization system shown in the figure may include multiple nodes in the block synchronization system. The node here may refer to the second node mentioned above. Each node can receive input information when performing normal work, and maintain the shared data in the block synchronization system based on the received input information. In order to ensure the information intercommunication in the block synchronization system, there may be an information connection between each node in the block synchronization system, and the nodes may transmit information through the above information connection. For example, when any node in the block synchronization system receives input information, other nodes in the block synchronization system obtain the input information according to the consensus algorithm, and store the input information as data in the shared data, so that the data stored on all nodes in the block synchronization system are consistent.
[0035] Each node in the block synchronization system has a corresponding node identifier, and each node in the block synchronization system can store the node identifiers of other nodes in the block synchronization system, so that the generated blocks can be broadcast to other nodes in the block synchronization system according to the node identifiers of other nodes. A node identifier list as shown in the following table can be maintained in each node, and the node name and node identifier are stored in the node identifier list accordingly. Among them, the node identifier can be an IP (Internet Protocol, a protocol for interconnecting networks) address and any other information that can be used to identify the node. Table 1 only takes the IP address as an example for explanation.
[0036] Table 1
[0037] Node Name Node ID Node 1 117.114.151.174 Node 2 117.116.189.145 … … Node N 119.123.789.258
[0038] Each node in the block synchronization system stores the same blockchain. The blockchain consists of multiple blocks, see Figure 1c , Figure 1c It is a schematic diagram of a blockchain provided by an embodiment of the present application. The blockchain is composed of multiple blocks. The genesis block includes a block header and a block body. The block header stores input information characteristic values, version numbers, timestamps and difficulty values, and the block body stores input information. The next block of the genesis block takes the genesis block as a parent block. The next block also includes a block header and a block body. The block header stores input information characteristic values of the current block, block header characteristic values, version numbers, timestamps and difficulty values of the parent block, and so on, so that the block data stored in each block in the blockchain are associated with the block data stored in the parent block, thereby ensuring the security of the input information in the block.
[0039] For further information, see Figure 2 , Figure 2 is a flowchart of a block synchronization method of a blockchain network provided in an embodiment of the present application; Figure 2 As shown, the block synchronization method of the blockchain network can be applied to the first node or the second node in the blockchain network, especially to the first node. The block synchronization method of the blockchain network may include but is not limited to the following steps:
[0040] S101, sending a first block synchronization request to a second node in the blockchain network, and receiving first index information sent by the second node based on the first block synchronization request.
[0041] The blockchain network involved in the embodiments of the present application may include multiple chains. The chain mentioned in the embodiments of the present application may refer to a blockchain, that is, a chain composed of blocks one after another. Each block stores certain information. They are connected into chains according to the time sequence of their respective generation. These chains are stored in all servers. As long as there is a server in the entire system that can work, the entire blockchain is safe. The server can be called a node in the blockchain network, which can provide storage space and computing power support for the entire blockchain network. If you want to modify the information in the blockchain, you must obtain the consent of more than half of the nodes and modify the information in all nodes. These nodes are usually in the hands of different entities, so it is extremely difficult to tamper with the information in the blockchain. Compared with traditional networks, blockchain networks are difficult to tamper with data on the one hand, and can be decentralized on the other hand, so that the information recorded in the blockchain is more authentic and reliable, which can help solve the problem of people's distrust of each other. The block in the blockchain network can refer to the unit in the blockchain implementation where data is stored on the chain, and the block number can be the block height. The node in the blockchain can refer to the service in the blockchain. A blockchain is generally composed of multiple nodes, and each node starts a blockchain software service.
[0042] In the embodiment of the present application, since there are multiple chains in the blockchain network, there are multiple nodes on each chain, and there are a lot of block data in each node. For the nodes on any chain, since the blockchain network will generate a lot of data after running for a period of time, these data are often stored in the form of blocks in multiple nodes on the chain. As the running time of the blockchain network increases, the block data stored in the nodes on the chain increases, and too much block data will increase the data storage pressure of the nodes on the chain. Therefore, archiving the long-standing block data on the chain can save server node space. For the archived block data, it is transferred to the block archiving device. After archiving, the nodes in the blockchain network occupy a significantly reduced disk space. Therefore, for various small disk IoT devices, block nodes can also be run, and the blocks on the nodes can also participate in consensus. For small disk IoT devices, these devices can also be a node, but the disk space of these devices is small, and the amount of block data generated after these devices run for a period of time is large. In order to ensure the normal operation of these devices, it is necessary to archive the block data on these devices.
[0043] However, since there is no complete block data in the archived nodes, it is more difficult for new nodes to join the blockchain network, because the new nodes cannot read the archived block data from the blockchain network for synchronization, and thus cannot achieve block data synchronization, and thus cannot achieve new node joining. Even if the new node obtains block data from the outside world, the authenticity of the block data obtained from the outside world cannot be guaranteed.
[0044] Based on this, the embodiment of the present application provides a block synchronization method of a blockchain network, which can realize a method for a new node to join an archived blockchain network after archiving the data in the blockchain network. The technical solution of the present application can be applied to the scenario where a node joins an archived blockchain network. For example, the massive data in the blockchain network can be archived and archived to a block archiving device. When a node needs to join the blockchain network, the data can be synchronized from the block archiving device to join the blockchain network. By archiving the data on the nodes in the blockchain network to the block archiving device, the data storage pressure of the nodes in the blockchain network can be reduced. When a node joins the blockchain network later, the data can be synchronized from the block archiving device without synchronizing the data from the nodes in the blockchain network, which can reduce the pressure on the nodes in the blockchain network.
[0045] In an embodiment of the present application, the first node may send a first block synchronization request to the second node in the blockchain network, and receive the first index information sent by the second node based on the first block synchronization request. Among them, the first node may refer to a node that needs to join the blockchain network, for example, the first node may refer to a blockchain node newly added to the blockchain network. The second node may refer to a node in the blockchain network, for example, the second node may refer to a blockchain node that joins the blockchain network before the first node, and the block on the second node may have been archived to the block archiving device before the first node joins the blockchain network. The first block synchronization request may be used to request a block data pair of the archived block from the second node, and the block data pair may refer to the index information of the block, for example, and the index information of the block may be used to find a certain block, for example, the index information of the block may include the block height and the block hash, and the first block synchronization request may be used to request the block height and the block hash of the archived block. The blockchain network may include multiple chains, each chain may include multiple nodes, and multiple nodes on each chain in the blockchain network may perform block consensus, so that the blocks between the nodes on each chain are synchronized, that is, the data in the multiple nodes on each chain are the same.
[0046] Among them, the first index information may refer to the index information of the block within the target block height range, and the index information may be used to uniquely indicate the block, for example, the index information may include but is not limited to at least one of the block height and the block hash. Block archiving may refer to transferring the block from the second node in the blockchain network to the block archiving device, and deleting the block in the second node. After the second node archives a block, the second node no longer has the complete data of the block. For example, the second node may only store the index information of the node, and the complete data of the block has been stored in the block archiving device. Generally speaking, there are multiple chains in the blockchain network, and the blocks with the same block height on the same chain are the same, that is, the blocks with the same block height on the same chain have the same block hash. When the block height and block hash of two blocks are the same, it means that the two blocks are exactly the same. The block within the target block height range refers to the block that the second node has archived to the block archiving device. For example, if the height of the block that the second node has archived to the block archiving device is 2000, then the target block height range may be 0 to 2000.
[0047] In an embodiment of the present application, a first node sends a first block synchronization request to a second node in the blockchain network. The second node can search for first index information corresponding to the first block synchronization request in the block of the second node based on the first block synchronization request, thereby returning the first index information to the first block. The first block can receive the first index information sent by the second node based on the first block synchronization request.
[0048] In an optional implementation, when a first node wants to join a blockchain network, it can shake hands with multiple second nodes in the blockchain network, thereby obtaining the block heights of the multiple second nodes and the block archiving heights of the multiple second nodes. The block archiving height may refer to the block height of the archived second blocks in the multiple second nodes, and the block archiving height may be used to indicate whether the blocks in the multiple second nodes are fully archived or partially archived. The block height of the second node is greater than or equal to the block archiving height. When the block height of the second node is greater than the block archiving height of the second node, it indicates that the blocks in the second node are partially archived. When the block height of the second node is equal to the block archiving height of the second node, it indicates that the blocks in the second node are fully archived. The second node can choose to archive the blocks on the block archiving device. For example, if the block height of the second node is 2000, the block archiving height may be 1900, indicating that the blocks with a block height range of 0 to 1900 on the second node have been archived to the block archiving device. Optionally, after the second block archives the block to the block archiving device, the first index information of the archived block can be saved on the second block. The first node can subsequently obtain the first index information of the archived block and use it to verify the index information of the block in the block archiving device, thereby preventing the block archiving device from tampering with the archived block data without permission and ensuring data security.
[0049] Optionally, before sending the first block synchronization request to the second node in the blockchain network, the block on the second node may be archived to the block archive device in advance. Figure 3 , Figure 3 This is a block archiving device and chain topology diagram provided in an embodiment of the present application. Figure 3 The blockchain network may include multiple chains, each of which may include multiple second nodes. Figure 3 The two chains shown in the figure are blockchain 1 and blockchain 2, respectively. Each chain may include multiple nodes. For example, each chain may include N nodes, where N is a positive integer. Figure 3The number of block archiving devices in the blockchain network may be one or more, and the block archiving device may be a storage warehouse, for example, it may be used to store block data and read block data, and the block archiving device may refer to a data storage device outside the blockchain network. Multiple second nodes on each chain in the blockchain network may archive their blocks to the block archiving device, and may also restore the archived blocks from the block archiving device, that is, restore the archived blocks to the second node. The second node in the blockchain network may include a node interaction module and an on-chain storage module, and the node interaction module may be used to call other second nodes on the chain, that is, multiple second nodes on the same chain may call each other through the node interaction module, thereby realizing data synchronization between multiple second nodes on the same chain. The on-chain storage module may be used to store blocks and index information of blocks. After the blocks in any second node are archived, the second node does not store the archived blocks, but may store the index information of the archived blocks.
[0050] In the embodiment of the present application, since each node on the same chain in the blockchain network will store a complete block data, but the content of these block data is basically the same, the storage cost will increase. By transferring the original block data (older block data) on each node to the block archiving device, only one block archiving device can be retained to store the block data of all nodes in the blockchain network. The block data commonly used by the node can be retained on the node without archiving, which can make the storage cost close to 1, that is, the storage cost is changed from multiple copies to one copy, thereby saving storage space. The block archiving device can be used to transfer the blocks on the blockchain network from the blockchain network to a storage warehouse outside the blockchain network, or the blocks on the blockchain network can be transferred from the blockchain network to the local database of the block archiving device. The block archiving device can also be used to store and manage blocks.
[0051] It is understandable that each of the multiple chains in the blockchain network can store different blocks. For example, the types of block data stored in each chain are different. For example, the block data stored on one chain is the block data in the transaction scenario, the block data stored on another chain is the block data in the financial scenario, and the block data stored on another chain is the block data in the insurance scenario, and so on. That is, the type of block data on each chain can be different. Therefore, when joining the blockchain network, the first node can first determine which chain to join, so as to synchronize the block data on the chain. Since the blocks on the same chain in the blockchain network are basically the same, multiple second nodes on the same chain can share the same data. A block archiving device can connect to multiple chains in the blockchain network, and the blocks in the nodes on different chains in the blockchain network can be stored separately on the block archiving device, so as to achieve separate storage of each type of block data and avoid data confusion. There can be a many-to-many relationship between the block archiving device and the second node, that is, when there are multiple block archiving devices, one second node can archive the same block to multiple block archiving devices, and one block archiving device can also connect to second nodes on multiple chains, that is, one block archiving device can also archive block data in second nodes on multiple chains. The embodiments of the present application are not limited to this.
[0052] Optionally, after the blocks on the second node in the blockchain network are archived, the first node can detect the network height of the blockchain network and the archiving status of the second node before joining the blockchain network, so as to determine the archiving status of the second node in the blockchain network, and subsequently determine which block heights to obtain from the block archiving device for data synchronization. Figure 4 As shown, Figure 4 It is a schematic diagram of a scenario in which a first node detects the network status of a blockchain network provided by an embodiment of the present application. For example, the first node can shake hands with each second node in the blockchain network, so that each second node can return its own block height and block archive height to the first node. For example, the second node can include archived nodes 1 to 4, the block height of node 1 can be 10000, and the block archive height of node 1 can be 2000; the block height of node 2 can be 10001, and the block archive height of node 2 can be 3000; the block height of node 3 can be 10000, and the block archive height of node 1 can be 4000; the block height of node 4 can be 10000, and the block archive height of node 1 can be 5000, then it can be determined that the highest block height that the first node can synchronize from the blockchain network is 10001, and the block height range that can be synchronized to the block from the blockchain network is 2001 to 10001.
[0053] That is to say, if the blocks with a block height range of 0 to 2000 have been archived to the block archiving device, the first node can synchronize from the block archiving device to the blocks with a block height range of 0 to 2000. It can be understood that the block heights within the target block height are continuous, that is, the block heights of the blocks that the second node has archived to the block archiving device are continuous, for example, 0 to 3000, indicating that the blocks with a block height of 0 to 3000 are all archived to the block archiving device.
[0054] S102, sending a second block synchronization request to the block archiving device.
[0055] In the embodiment of the present application, since the block on the second node in the blockchain network is archived in the block archiving device, the first node can send a second block synchronization request to the block archiving device to obtain the block on the block archiving device. The second block synchronization request includes indication information, and the indication information is used to indicate the blocks within the target block height range to be synchronized. The indication information may include at least one of the block height or block hash of the blocks within the target block height range to be synchronized.
[0056] Optionally, the first node can determine the block height of the blocks archived on the block archiving device by probing the network status of the blockchain network, such as probing the block height and block archiving height of multiple second nodes in the blockchain network, and then determine which blocks of which block heights can be requested from the block archiving device. For example, for any second node, the maximum block height is 10000, and the maximum block archiving height of the second node is 2000, then the first node can obtain blocks with a block height range of 0 to 2000 from the block archiving device. The target block height range to be synchronized can be 0 to 2000, then blocks with a block height range of 0 to 2000 can be obtained by sending indication information to the block archiving device, thereby synchronizing blocks with a block height range of 0 to 2000 to the first node.
[0057] In one implementation, the indication information included in the second block synchronization request can be used to indicate a block within the target block height range that needs to be synchronized, and the second block synchronization request can be used to request synchronization of a block. By sequentially obtaining a block within the target block height range that needs to be synchronized for block synchronization, the first node can join the blockchain network.
[0058] In another implementation, the indication information included in the second block synchronization request can be used to indicate multiple blocks within the target block height range that need to be synchronized, and the second block synchronization request can be used to request synchronization of multiple blocks. The synchronization method of each of the multiple blocks can be the same. By obtaining multiple blocks for synchronization through one request, the efficiency of the first node joining the blockchain network can be improved.
[0059] S103, receiving the first block indicated by the indication information sent by the block archiving device and the second index information of the first block.
[0060] In the embodiment of the present application, when the block archiving device obtains the second block synchronization request, since the second block synchronization request includes indication information, the block archiving device can obtain the first block indicated by the indication information and the second index information of the first block from the block archiving device based on the indication information, so that the first node can receive the first block indicated by the indication information sent by the block archiving device and the second index information of the first block. The second index information can be used to uniquely indicate the first block, for example, the second index information can include but is not limited to at least one of the block height of the first block and the block hash of the first block.
[0061] In the embodiment of the present application, the first block may refer to specific block data. For example, in a transaction scenario, the first block may include but is not limited to the transaction initiation time, transaction location, transaction method, transaction content, and information of both parties to the transaction, etc. For another example, in a financial management scenario, the first block may include but is not limited to the financial management initiation time, financial management location, financial management type, financial management party information, financial management amount, financial management period, etc. The first block may also be block data in other scenarios, which is not limited in the embodiment of the present application.
[0062] S104: If the second index information is consistent with the first index information, the first block is added to the block ledger of the first node.
[0063] In the embodiment of the present application, the first node obtains the first index information from the second node in the blockchain network, and obtains the first index information from the block archiving device, and then can compare whether the second index information is consistent with the first index information. If the second index information is consistent with the first index information, it means that the first block on the block archiving device has not been tampered with, and the first block is credible, so the first block can be added to the block account book of the first node, so that the data in the first block can be synchronized, so that the first node joins the blockchain network. By comparing the consistency between the index information in the block archiving device and the index information of the second node in the blockchain network, the reliability of the obtained block can be improved, the obtained block is more accurate, and the security of the blockchain network is improved. Optionally, the block account book of the second node does not contain the blocks that the second node has archived. That is to say, after the blocks in the second node are archived to the block archiving device, the archived blocks can be deleted from the block account book of the second node, thereby reducing the storage space of the second node. The second node can be a consensus node or a common node, and the embodiment of the present application is not limited to this.
[0064] In the embodiment of the present application, the synchronization method of any block (i.e., the first block) on the block archiving device is explained. For other blocks on the block archiving device, they can be processed with reference to the synchronization method of the first block, so as to synchronize all blocks that need to be synchronized by the first node on the block archiving device to the first node. When all blocks that need to be synchronized by the first node on the block archiving device are synchronized to the first node, the first node can join the blockchain network.
[0065] In a possible case, the method in the embodiment of the present application can also be applied to the second node in the blockchain network. For example, when a second node in the blockchain network needs to query or perform other operations on the archived blocks, the second node can also synchronize the archived blocks from the block archiving device, so as to restore the archived blocks, and then query or perform other operations based on the restored archived blocks. For example, when the second node synchronizes the blocks archived by itself on the block archiving device, it can restore the archived blocks. Specifically, by sending a second block synchronization request to the block archiving device, the block archiving device can return the archived blocks that the second node needs to restore. At this time, the second block synchronization request can include the first index information of the archived blocks that need to be restored, such as the archived block height or block hash that needs to be restored, so as to restore the archived blocks. Or when the second node synchronizes the blocks archived by other nodes on the block archiving device, it can also send a second block synchronization request to the block archiving device, and the block archiving device can return the archived blocks that the second node needs to restore, ensuring the normal execution of block queries and other block operations.
[0066] Optionally, if the archived block that the second node needs to recover is archived to the block archiving device by other second nodes, the second node can also send a block synchronization request to the other second nodes that archived the block. The other second nodes that archived the block can send a second block synchronization request from the block archiving device to restore the archived block, and send the restored block to the second node based on the block consensus, thereby restoring the archived block and ensuring the normal execution of block queries and other block operations.
[0067] In the embodiment of the present application, the long-standing block data on the chain can be archived based on the Chang'an Chain to save server storage space, and data synchronization when new nodes are added after the high-security and high-performance blockchain is archived can be achieved. Among them, Chang'an Chain can, for example, refer to a technical system that can have the outstanding characteristics of autonomous control, flexible assembly, hardware and software integration, and open source. It is oriented to the next generation of blockchain technology requirements such as large-scale node networking, high transaction processing performance, and strong data security and privacy. It integrates blockchain-specific acceleration chip hardware and assembleable underlying software platforms to provide new solutions for building high-performance, highly reliable, and highly secure digital infrastructure. After the blocks on the nodes in the blockchain network are archived, it does not affect the participation of the consensus between the nodes in the blockchain network. The archived blocks are stored in the block archiving device, and the archived blocks can still be accessed, which can save storage costs while ensuring that new nodes can join the blockchain network.
[0068] In the embodiment of the present application, by sending a first block synchronization request to a second node in the blockchain network, receiving the first index information of the block within the target block height range sent by the second node based on the first block synchronization request; by sending a second block synchronization request containing indication information to a block archiving device, the first block indicated by the indication information sent by the block archiving device and the second index information of the first block are obtained, and then when the second index information is consistent with the first index information, the first block can be added to the block account book of the first node, thereby realizing the first node joining the blockchain network. By archiving the block of the second node in the blockchain network to the block archiving device, the second node in the blockchain network does not need to store the complete block, which can reduce the pressure on the nodes in the blockchain network to store block data, thereby reducing the storage cost of the node. In addition, when a new node joins the blockchain network, it can directly obtain the block from the block archiving device for synchronization, without obtaining the block from the second node in the blockchain network for synchronization, which can reduce the processing pressure on the nodes in the blockchain network for block data. In addition, by judging the consistency between the second index information obtained in the block archiving device and the first index information obtained in the blockchain network, it is possible to further verify whether the block in the block archiving device has been tampered with, thereby improving the reliability of the block data and thereby improving the security of the blockchain network.
[0069] Optional, see Figure 5 , Figure 5 1 is a flow chart of another method for synchronizing blocks in a blockchain network provided in an embodiment of the present application. The method for synchronizing blocks in a blockchain network can be applied to a first node or a second node in a blockchain network, and in particular to a first node; Figure 5 As shown, the block synchronization method of the blockchain network includes but is not limited to the following steps:
[0070] S201, sending a first block synchronization request to a second node in the blockchain network, and receiving first index information sent by the second node based on the first block synchronization request.
[0071] S202: Send a second block synchronization request to the block archiving device.
[0072] S203, receiving the first block indicated by the indication information sent by the block archiving device and the second index information of the first block.
[0073] S204: If the second index information is consistent with the first index information, the first block is added to the block ledger of the first node.
[0074] In the embodiment of the present application, the specific implementation method of steps S201 to S204 can refer to the implementation method of the above-mentioned steps S101 to S104, which will not be repeated here.
[0075] In one embodiment, the second index information can be compared with the first index information to determine the consistency between the second index information and the first index information. For example, if the text content in the second index information is found to be exactly the same as the text content in the first index information, it means that the second index information is consistent with the first index information. If the text content in the second index information is not exactly the same as the text content in the first index information, it means that the second index information is inconsistent with the first index information. By judging the consistency between the second index information and the first index information, it can be determined whether the block in the block archiving device has been modified. If it has not been modified, block synchronization can be performed, thereby ensuring the accuracy of block synchronization.
[0076] Optionally, the first index information may include the first block hash and the first block height of the block within the target block height range that has been archived by the second node, and the second index information may include the second block hash and the second block height of the first block in the block archiving device; then the method for determining the consistency of the second index information with the first index information may include: comparing the second block hash with the first block hash, and comparing the second block height with the first block height; if the comparison shows that the second block hash is consistent with the first block hash, and the second block height is consistent with the first block height, then it is determined that the second index information is consistent with the first index information.
[0077] In an embodiment of the present application, when the first block and the second index information of the first block are obtained from the block archiving device, it is possible to determine whether the second index information is consistent with the first index information by comparing whether the second block height in the second index information is consistent with the first block height in the first index information, and comparing whether the second block hash in the second index information is consistent with the first block hash in the first index information. Since a block height and a block hash are used to indicate a block, when the block on the second node in the blockchain network is archived to the block archiving device, when the first node obtains the block on the block archiving device, it can compare the block height of the block with the block height on the second node, and compare the block hash of the block with the block hash on the second node. If the block height of the block is consistent with the block height on the second node, it means that the block obtained from the block archiving device is correct. If the block hash of the block is consistent with the block hash on the second node, it means that the block obtained from the block archiving device is credible, that is, the block obtained from the block archiving device has not been tampered with, so the block can be synchronized.
[0078] In one possible case, when verifying the block returned by the block archiving device, if the number of second nodes in the blockchain network is one, the first index information in the second node can be obtained from the blockchain network to verify whether the first index information is consistent with the second index information of the block returned by the block archiving device. If they are consistent, the block returned by the block archiving device is added to the block ledger of the first node, thereby achieving data synchronization for the returned block. By verifying the blocks in the block archiving device, the block archiving device can be prevented from tampering with the blocks, thereby improving data security.
[0079] In one possible case, when verifying the block returned by the block archiving device, if there are multiple second nodes in the blockchain network, the first index information of multiple second nodes containing the first block can be obtained from the blockchain network respectively, and the multiple first index information are compared with the second index information to determine whether they are consistent, so as to determine whether the block returned by the block archiving device is synchronized.
[0080] Specifically, the block hashes in the block index information containing the same block height in multiple first index information of multiple second nodes can be compared, and the target index information can be compared with the second index information; the target index information is the index information obtained after deduplication processing of the block index information containing the same block height in multiple first index information; if the block hashes in the block index information containing the same block height in multiple first index information are all consistent, and the target index information is consistent with the second index information, then it is determined that the second index information is consistent with the first index information.
[0081] Among them, each second node has its own first index information, and the first index information of any second node includes the block index information of each block that any second node has archived to the block archiving device, and the block index information of any block includes the block height and block hash of any block. The purpose of deduplication processing of block index information containing the same block height in multiple first index information is to reduce the amount of data compared with the second index information. Since the block heights of multiple first index information are the same, any first index information can be selected for comparison with the second index information, which can improve the data comparison efficiency compared with comparing multiple first index information with the second index information. Deduplication processing can be used to select a first index information as the target index information. The consistency of the target index information and the second index information can mean that: the block height contained in the target index information is consistent with the block height contained in the second index information, and the block hash contained in the target index information is consistent with the block hash contained in the second index information.
[0082] In the embodiment of the present application, since the block heights of multiple second nodes may be different, for example, a second node on the same chain generates a new block after the previous block is archived to the block archiving device and during the period between the first node joining the blockchain network, the new block is not archived to the block archiving device. Or, multiple second nodes use blocks at different frequencies, for example, some second nodes use a certain block more frequently than other second nodes, then the block in the second node may not be archived to the block archiving device, and the blocks of other second nodes may be archived to the block archiving device, thus resulting in different archiving degrees for multiple second nodes on the same chain.
[0083] Therefore, when comparing the consistency between the second index information of the first block returned by the block archiving device and the first index information in multiple second nodes, it is possible to first obtain whether the block hash comparison of the first index information indicating the same block on multiple second nodes is consistent. When the block hash comparison of the first index information indicating the same block on multiple second nodes is consistent, then select one of the multiple consistent first index information as the target index information, and compare the consistency of the target index information with the second index information in the block archiving device. If the target index information is consistent with the second index information in the block archiving device, it can be determined that the second index information is consistent with the first index information, that is, the first block returned by the block archiving device is correct, and the first block is trustworthy and has not been tampered with.
[0084] Optionally, if the number of block hashes that are consistent among the block index information containing the same block height in the multiple first index information is greater than the quantity threshold, any one of the first index information with consistent block hashes is selected as the target index information, and the target index information is consistent with the second index information, then it is determined that the second index information is consistent with the first index information. Here, since the number of block hashes that are consistent among the block index information containing the same block height in the multiple first index information is greater than the quantity threshold, it means that the index information of most of the second nodes in the multiple second nodes is consistent, that is, the index information of most of the second nodes in the blockchain network is consistent, and a small number of second nodes may be abnormal. At this time, it can also be considered that the first block returned by the block archiving device is credible and has not been tampered with, so that the first block can be synchronized to the first node.
[0085] In the embodiment of the present application, by comparing the index information of the block returned by the block archiving device with the index information of the blocks on multiple second nodes in the blockchain network, the security of the block returned by the block archiving device can be further verified, and a second node can be prevented from colluding with the block archiving device to modify the data of the archived block, thereby improving data security. Alternatively, data security can be further improved by preventing a second node from being abnormal and thus failing to obtain the first index information.
[0086] In an optional implementation, when verifying the block returned by the block archiving device, there are multiple second nodes in the blockchain network, each second node has its own first index information, and the block height range of the blocks archived by each second node to the block archiving device is the target block height range, the second index information can be compared with the first index information for consistency in the following manner: multiple first index information of multiple second nodes are compared with the second index information; if the compared target number is greater than or equal to a quantity threshold, it is determined that the second index information is consistent with the first index information; the target number refers to the number of first index information in multiple first index information that is the same as the second index information.
[0087] In an embodiment of the present application, if the target number is greater than or equal to the number threshold, it can be indicated that the first index information of most of the second nodes among the multiple second nodes is consistent with the second index information in the block archiving device, which can indicate that the block in the block archiving device has not been tampered with. By comparing the index information in most of the second nodes in the blockchain network with the index information in the block archiving device, it is possible to avoid collusion between a part of the second nodes in the blockchain network and the block archiving device to modify the data in the archived blocks, solve the problem of mutual distrust between nodes, and improve data security. By using most of the second nodes in the blockchain network for comparison, compared with using all of the second nodes for comparison, the amount of data comparison can be reduced, the data comparison efficiency can be improved, and thus the node synchronization efficiency can be improved.
[0088] Optionally, there may be a part of the second nodes in the blockchain network whose block height is less than the minimum value within the target block height range or greater than the maximum value within the target block height range, or there may be a part of the second nodes in the blockchain network whose block heights may all belong to the target block height range, that is, the block heights of these second nodes may be equal, and this embodiment of the present application is not limited to this.
[0089] In a possible implementation, if the second index information is inconsistent with the first index information, the first block sent by the block archiving device is discarded, and a prompt message indicating block synchronization failure is output.
[0090] Among them, when the second index information is inconsistent with the first index information, it may indicate that the first block is incorrect, or the first block has been tampered with, then the first block may be discarded, and a prompt message of block synchronization failure may be output, and the prompt message may be used to indicate that the first block is abnormal, so that relevant management personnel may manually check the first block based on the prompt message to improve data synchronization accuracy.
[0091] Optionally, when the number of second nodes is one, the inconsistency between the second index information and the first index information may mean that: the second block hash is inconsistent with the first block hash of the second node, or the second block height is inconsistent with the first block height of the second node.
[0092] Optionally, when the number of second nodes is multiple, the inconsistency between the second index information and the first index information may mean that: most of the block hashes in the block index information containing the same block height in the multiple first index information are inconsistent, or the target index information is inconsistent with the second index information; or the number of first index information in the multiple first index information that is identical to the second index information is less than a quantity threshold (that is, the target number is less than the quantity threshold).
[0093] In one embodiment, when the first node expects (needs to synchronize) a block A with a block height of (A.height), it can request the block hash (A.hash) of the block A that needs to be synchronized from the block archiving device. After the first node obtains the block hash (A.hash) returned by the block archiving device, it can request the block height (A`.height) from the second node in the blockchain network. When the second node in the blockchain network returns the block height (A`.height), the block height (A.height) expected by the first node can be compared with the block height (A`.height) returned by the second node. If (A.height) is consistent with (A`.height), it means that the block hash of block A returned by the block archiving device is correct. Furthermore, the first node can request a block with a block height of A.height from the block archiving device, and verify whether the block hash (A.hash) of the requested block is equal to the block hash (A.hash) of the previously returned block A. If the block hash of the block with a block height of A.height is equal to the block hash (A.hash) of block A previously returned by the block archiving device, it means that block A returned by the block archiving device is credible. In the above manner, the first node can sequentially pull the blocks that need to be synchronized in the block archiving device, and can pull one block that needs to be synchronized or multiple blocks that need to be synchronized at one time until the block with the highest block height existing on the block archiving device is pulled. For example, if the highest block height on the block archiving device is 2000, it means that the first node has pulled blocks with a block height range of 0 to 2000 from the block archiving device.
[0094] Since the second node in the blockchain network may be incompletely archived, the highest block height of the block on the block archiving device is generally lower than the highest block height of the block on the second node in the blockchain network. For the blocks on the second node that have not been archived to the block archiving device, the first node can synchronize from the second node. For example, if the highest block height of the second node in the blockchain network is 10001, and the block heights of the blocks on the second node that have been archived to the block archiving device are 0 to 2000, then the first node can synchronize blocks with a block height range of 0 to 2000 from the block archiving device, and for blocks with a block height of 2001 to 10001 on the second node, the first node can synchronize from the second node.
[0095] Optionally, for example, there are four second nodes on the chain that the first node in the blockchain network needs to join, namely node 1, node 2, node 3 and node 4, the block hash of the second node can be expressed as blockHash, and the block height of the node can be expressed as height.
[0096] If node 1 (blockHash1, height1) = node 2 (blockHash1, height1) = node 3 (blockHash1, height1) = node 4 (blockHash1, height1), it means that the block heights and block hashes of the four second nodes are equal, which means that the second index information is consistent with the first index information.
[0097] If node 1 (blockHash1, height1) = node 2 (blockHash1, height1) = node 3 (blockHash1, height1) ! = node 4 (blockHash1, height1), it means that the block height and block hash of most second nodes are equal, which means that the second index information is consistent with the first index information. Among them, ! = means unequal.
[0098] If node 1 (blockHash1, height1) = node 2 (blockHash1, height1)! = node 3 (blockHash1, height1)! = node 4 (blockHash1, height1), it means that the block height and block hash of most of the second nodes are not equal, that is, the block hash and block height of the nodes exceeding the number threshold are not equal, which can indicate that the second index information is inconsistent with the first index information.
[0099] Optionally, when the block heights and block hashes of most of the second nodes are not equal, it may indicate that there is an abnormality in the blockchain network. For example, the blockchain network may be forked. In this case, the block synchronization of the first node may be terminated, and relevant personnel may be prompted to conduct manual inspection to ensure network security.
[0100] S205: If the block height of the first block is less than the highest block height of blocks in the blockchain network, a third block synchronization request is sent to the second node.
[0101] In the embodiment of the present application, since there are multiple blocks on the second node that are not completely archived to the block archiving device, when the first node joins the blockchain network, it can first obtain the blocks that have been archived by the second node from the block archiving device. After synchronizing the blocks that have been archived by the second node, it is also possible to further synchronize the blocks that have not been archived to the block archiving device from the second node. By synchronizing the blocks that have been archived and the blocks that have not been archived on the second node, the first node can join the blockchain network.
[0102] Among them, by synchronizing the first block to the first node, if the block height of the first block is less than the highest block height of the blocks in the blockchain network, it means that all the blocks in the block archiving device are archived to the first node, then a third block synchronization request can be sent to the second node to request synchronization of unarchived blocks from the second node, and the third block synchronization request is used to pull the blocks in the blockchain network whose block height is greater than the block height of the first block. The blocks in the blockchain network whose block height is greater than the block height of the first block may refer to the blocks in the blockchain network that have not yet been archived to the block archiving device.
[0103] For example, the block that has not been archived to the block archiving device may be a block whose use frequency by the second node in the blockchain network is greater than the frequency threshold, or the block may be a block generated during the period after the second node archives the previous block to the block archiving device and before the first node joins the blockchain network, etc. For example, the highest block height of the block on the second node in the blockchain network is 10001, and the target block height range in the block archiving device is 0-2000, that is, the blocks with a block height range of 0-2000 on the second node have been archived to the block archiving device, and the blocks with a block height range of 2001-10001 have not been archived to the block archiving device. Then, for blocks 0-2000, the first node can synchronize from the block archiving device, and for blocks 2001-10001, block synchronization can be performed from the second node.
[0104] Optionally, if the blocks on a portion of the second nodes in the blockchain network are archived to the block archiving device, and the same blocks on another portion of the second nodes are not archived to the block archiving device, when the first node needs to synchronize the same blocks on the second node, it can be synchronized from the second node or from the block archiving device, which is not limited in the embodiments of the present application. In the case of reducing the pressure on the nodes in the blockchain network, the portion of the blocks can be synchronized from the block archiving device, thereby reducing the pressure on the second nodes in the blockchain network.
[0105] S206, receiving the second block sent by the second node, and adding the second block to the block ledger of the first node.
[0106] In the embodiment of the present application, when the first node needs to synchronize a block whose block height is greater than the block height of the first block in the blockchain network, a third block synchronization request can be sent to the second node, and the second node can return a block whose block height is greater than the block height of the first block in the blockchain network, so that the second node can pull a block whose block height is greater than the block height of the first block in the blockchain network. Among them, the second block refers to a block whose block height is greater than the block height of the first block in the blockchain network. By pulling the second block from the second node, the block on the first node is made the same as the block on the second node in the blockchain network, thereby joining the blockchain network.
[0107] See also Figure 6 , Figure 6 This is a schematic diagram of a scenario of synchronizing blocks from a blockchain network provided by an embodiment of the present application, such as Figure 6 As shown, multiple second nodes in the blockchain network can archive blocks to the block archiving device, and the second node can also restore the archived blocks from the block archiving device. When the first node joins the blockchain network, it can shake hands with multiple second nodes in the blockchain network to explore the block heights and block archiving heights of multiple second nodes. The first node can send a second block synchronization request to the block archiving device to request the block hash of the first block at a specified height, and the block archiving device can return the block hash of the first block to the first node. Further, the first node can send a first block synchronization request to the second node in the blockchain network, and the first block synchronization request can be used to request synchronization of a block at a specified height, and receive the first index information returned by the second node, and the first index information can be, for example, a data pair consisting of a block height and a block hash. Further, the first node can verify the block height returned by the second node, and request the block archiving device to obtain the first block. The block archiving device can return the first block to the first node, and the first node can verify whether the block hash of the first block is consistent with the block hash in the first index information. If the block hashes are consistent, the first block is stored in the first node.
[0108] In the embodiment of the present application, after the block on the second node in the blockchain network is archived, by retaining a small amount of the first index information in the second node, the storage space can be reduced compared to retaining the block. The first index information may refer to a block data pair, which may include a block hash and a block height of the archived block. The block data pair (first index information) may be used to find the corresponding block hash according to the block height, or to find the corresponding block height according to the block hash, so as to facilitate data search, and then the data found may be compared with the data returned by the block archiving device to improve data security.
[0109] In the embodiment of the present application, since the second node in the blockchain network needs to reach a block consensus with other nodes on the chain, and also needs to provide query access services for new nodes to join the blockchain network, the disk requirements for the nodes in the blockchain network are relatively high, so the disk cost is relatively high. However, there are fewer block accesses in the block archiving device, so the disk requirements for the block archiving device are relatively low. Therefore, after the blocks in the blockchain network are archived to the block archiving device, the new node can directly access the block archiving device to achieve block synchronization when joining the blockchain network. Compared with the new node accessing the nodes in the blockchain network, since the nodes in the blockchain network complete the general block consensus and also provide data query functions for the new nodes, it will cause the nodes in the blockchain network to be under greater pressure and the node disk pressure is greater. Therefore, the method in the embodiment of the present application can reduce the node pressure and node disk pressure in the blockchain network.
[0110] In the embodiment of the present application, multiple second nodes in the blockchain network can freely determine their own archiving degree, and can archive some blocks or all blocks. There is no need to reserve blocks for new nodes such as the first node to join the blockchain network, resulting in high storage costs, which can reduce the storage cost of the node. When the first node joins the blockchain network, after obtaining the archived blocks from the block archiving device, it can also further verify the archived blocks in combination with the index information stored in the blockchain network. There is no need to worry about the block archiving device privately tampering with the archived blocks, and the new node can still ensure the reliability of the block data based on the existing blockchain network. The new node can freely choose to synchronize the blocks in the nodes in the blockchain network from scratch, or it can also select the blocks that need to be synchronized according to the needs, without worrying about the block data being too old to be synchronized, and the blocks that need to be synchronized cannot be synchronized to the new node, resulting in the new node being unable to update to the latest block height network problem.
[0111] In the embodiment of the present application, by sending a first block synchronization request to a second node in the blockchain network, receiving the first index information of the block within the target block height range sent by the second node based on the first block synchronization request; by sending a second block synchronization request containing indication information to a block archiving device, the first block indicated by the indication information sent by the block archiving device and the second index information of the first block are obtained, and then when the second index information is consistent with the first index information, the first block can be added to the block account book of the first node, thereby realizing the first node joining the blockchain network. By archiving the block of the second node in the blockchain network to the block archiving device, the second node in the blockchain network does not need to store the complete block, which can reduce the pressure on the nodes in the blockchain network to store block data, thereby reducing the storage cost of the node. In addition, when a new node joins the blockchain network, it can directly obtain the block from the block archiving device for synchronization, without obtaining the block from the second node in the blockchain network for synchronization, which can reduce the processing pressure on the nodes in the blockchain network for block data. In addition, by judging the consistency between the second index information obtained in the block archiving device and the first index information obtained in the blockchain network, it is possible to further verify whether the block in the block archiving device has been tampered with, thereby improving the reliability of the block data and thereby improving the security of the blockchain network.
[0112] The method of the embodiment of the present application is introduced above, and the device of the embodiment of the present application is introduced below.
[0113] See also Figure 7 , Figure 7 : is a schematic diagram of the composition structure of a block synchronization device of a blockchain network provided in an embodiment of the present application. The block synchronization device of the blockchain network can be applied to the first node; the block synchronization device of the blockchain network can be used to execute the corresponding steps in the block synchronization method of the blockchain network provided in an embodiment of the present application. The block synchronization device 70 of the blockchain network includes:
[0114] The first request unit 701 is used to send a first block synchronization request to a second node in the blockchain network, and receive first index information sent by the second node based on the first block synchronization request; the first index information refers to index information of blocks within a target block height range, and the blocks within the target block height range refer to blocks that have been archived by the second node to a block archiving device;
[0115] The second request unit 702 is used to send a second block synchronization request to the block archiving device; the second block synchronization request includes indication information, and the indication information is used to indicate the blocks within the target block height range that need to be synchronized;
[0116] The data receiving unit 703 is used to receive the first block indicated by the indication information and the second index information of the first block sent by the block archiving device;
[0117] The data adding unit 704 is configured to add the first block to the block ledger of the first node if the second index information is consistent with the first index information.
[0118] Optionally, the first index information includes a first block hash and a first block height of a block within the target block height range that has been archived by the second node, and the second index information includes a second block hash and a second block height of the first block in the block archiving device;
[0119] The block synchronization device 70 of the blockchain network further includes a data comparison unit 705, which is used to:
[0120] Compare the second block hash with the first block hash, and compare the second block height with the first block height;
[0121] If the second block hash is consistent with the first block hash, and the second block height is consistent with the first block height, it is determined that the second index information is consistent with the first index information.
[0122] Optionally, there are multiple second nodes, each of which has its own first index information, the first index information of any second node includes block index information of each block that has been archived to the block archiving device by the second node, and the block index information of any block includes the block height and block hash of the block; the data comparison unit 705 is further used to:
[0123] Comparing block hashes in block index information containing the same block height in multiple first index information of multiple second nodes, and comparing target index information with the second index information; the target index information is index information obtained after deduplication processing of block index information containing the same block height in the multiple first index information;
[0124] If it is found that the block hashes in the block index information containing the same block height in the multiple first index information are all consistent, and the target index information is consistent with the second index information, it is determined that the second index information is consistent with the first index information.
[0125] Optionally, there are multiple second nodes, each of which has its own first index information, and the block height range of the blocks archived by each second node to the block archiving device is the target block height range; the data comparison unit 705 is further used to:
[0126] Comparing a plurality of first index information of a plurality of second nodes with the second index information;
[0127] If the target quantity is greater than or equal to the quantity threshold, it is determined that the second index information is consistent with the first index information; the target quantity refers to the quantity of first index information that is the same as the second index information among the multiple first index information.
[0128] Optionally, the block synchronization device 70 of the blockchain network further includes: an information prompting unit 706, wherein the information prompting unit 706 is used to:
[0129] If the second index information is inconsistent with the first index information, the first block sent by the block archiving device is discarded, and a prompt message indicating block synchronization failure is output.
[0130] Optionally, the block synchronization device 70 of the blockchain network further includes: a data pulling unit 707, wherein the data pulling unit 707 is used to:
[0131] If the block height of the first block is less than the highest block height of blocks in the blockchain network, a third block synchronization request is sent to the second node; the third block synchronization request is used to pull a block in the blockchain network whose block height is greater than the block height of the first block;
[0132] Receive the second block sent by the second node, and add the second block to the block ledger of the first node;
[0133] The second block refers to a block in the blockchain network whose block height is greater than the block height of the first block.
[0134] Optionally, the first node refers to a blockchain node newly added to the blockchain network, and the second node refers to a blockchain node that joined the blockchain network before the first node;
[0135] The block ledger of the second node does not include the blocks archived by the second node.
[0136] It should be noted that Figure 7 For the contents not mentioned in the corresponding embodiments, please refer to the description of the method embodiments, which will not be repeated here.
[0137] In the embodiment of the present application, by sending a first block synchronization request to a second node in the blockchain network, receiving the first index information of the block within the target block height range sent by the second node based on the first block synchronization request; by sending a second block synchronization request containing indication information to a block archiving device, the first block indicated by the indication information sent by the block archiving device and the second index information of the first block are obtained, and then when the second index information is consistent with the first index information, the first block can be added to the block account book of the first node, thereby realizing the first node joining the blockchain network. By archiving the block of the second node in the blockchain network to the block archiving device, the second node in the blockchain network does not need to store the complete block, which can reduce the pressure on the nodes in the blockchain network to store block data, thereby reducing the storage cost of the node. In addition, when a new node joins the blockchain network, it can directly obtain the block from the block archiving device for synchronization, without obtaining the block from the second node in the blockchain network for synchronization, which can reduce the processing pressure on the nodes in the blockchain network for block data. In addition, by judging the consistency between the second index information obtained in the block archiving device and the first index information obtained in the blockchain network, it is possible to further verify whether the blocks in the block archiving device have been tampered with, thereby improving the reliability of the block data and thereby improving the security of the blockchain network.
[0138] See also Figure 8 , Figure 8 Schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 8 As shown, the computer device may include: a processor 801 and a memory 802. Optionally, the computer device may also include a network interface or a power supply module. The processor 801 and the memory 802 may exchange data.
[0139] The processor 801 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0140] The above-mentioned network interface may include an input device and / or an output device. For example, the input device may be a control panel, a microphone, a receiver, etc., and the output device may be a display screen, a transmitter, etc., which are not listed here one by one.
[0141] The memory 802 may include a read-only memory and a random access memory, and provide program instructions and data to the processor 801. A portion of the memory 802 may also include a non-volatile random access memory. When the processor 801 calls the program instruction, it is used to execute:
[0142] Sending a first block synchronization request to a second node in the blockchain network, and receiving first index information sent by the second node based on the first block synchronization request; the first index information refers to index information of blocks within a target block height range, and the blocks within the target block height range refer to blocks that have been archived by the second node to a block archiving device;
[0143] Sending a second block synchronization request to the block archiving device; the second block synchronization request includes indication information, and the indication information is used to indicate the blocks within the target block height range that need to be synchronized;
[0144] receiving a first block indicated by the indication information and second index information of the first block sent by the block archiving device;
[0145] If the second index information is consistent with the first index information, the first block is added to the block ledger of the first node.
[0146] In the embodiment of the present application, by sending a first block synchronization request to a second node in the blockchain network, receiving the first index information of the block within the target block height range sent by the second node based on the first block synchronization request; by sending a second block synchronization request containing indication information to a block archiving device, the first block indicated by the indication information sent by the block archiving device and the second index information of the first block are obtained, and then when the second index information is consistent with the first index information, the first block can be added to the block account book of the first node, thereby realizing the first node joining the blockchain network. By archiving the block of the second node in the blockchain network to the block archiving device, the second node in the blockchain network does not need to store the complete block, which can reduce the pressure on the nodes in the blockchain network to store block data, thereby reducing the storage cost of the node. In addition, when a new node joins the blockchain network, it can directly obtain the block from the block archiving device for synchronization, without obtaining the block from the second node in the blockchain network for synchronization, which can reduce the processing pressure on the nodes in the blockchain network for block data. In addition, by judging the consistency between the second index information obtained in the block archiving device and the first index information obtained in the blockchain network, it is possible to further verify whether the blocks in the block archiving device have been tampered with, thereby improving the reliability of the block data and thereby improving the security of the blockchain network.
[0147] Optionally, when the program instructions are executed by the processor, other steps of the method in the above embodiment may also be implemented, which will not be repeated here.
[0148] The embodiment of the present application also provides a computer-readable storage medium, which stores a computer program, which includes program instructions, which, when executed by a computer, cause the computer to execute the method of the aforementioned embodiment, and the computer may be part of the computer device mentioned above. As an example, the program instructions may be deployed on a computer device for execution, or deployed on multiple computer devices located at one location for execution, or, executed on multiple computer devices distributed at multiple locations and interconnected by a communication network, and multiple computer devices distributed at multiple locations and interconnected by a communication network may constitute a blockchain network.
[0149] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction, and when the computer instruction is executed by a processor, some or all of the steps in the above method can be implemented. For example, the computer instruction is stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device performs the steps performed in the embodiments of the above methods.
[0150] Those skilled in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0151] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A block synchronization method for a blockchain network, characterized in that: The method is applied to a first node in the blockchain network; the method comprises: Sending a first block synchronization request to a second node in the blockchain network, and receiving first index information sent by the second node based on the first block synchronization request; the first index information refers to index information of blocks within a target block height range, and the blocks within the target block height range refer to blocks that have been archived by the second node to a block archiving device; Sending a second block synchronization request to the block archiving device; the second block synchronization request includes indication information, and the indication information is used to indicate the blocks within the target block height range that need to be synchronized; receiving a first block indicated by the indication information and second index information of the first block sent by the block archiving device; If the second index information is consistent with the first index information, the first block is added to the block ledger of the first node.
2. The method according to claim 1, characterized in that The first index information includes a first block hash and a first block height of a block within the target block height range that has been archived by the second node, and the second index information includes a second block hash and a second block height of the first block in the block archiving device; The method further comprises: Compare the second block hash with the first block hash, and compare the second block height with the first block height; If the comparison shows that the second block hash is consistent with the first block hash, and the second block height is consistent with the first block height, it is determined that the second index information is consistent with the first index information.
3. The method according to claim 1, characterized in that There are multiple second nodes, each of which has its own first index information. The first index information of any second node includes block index information of each block that has been archived to the block archiving device by any second node, and the block index information of any block includes the block height and block hash of any block. The method further comprises: Comparing block hashes in block index information containing the same block height in multiple first index information of multiple second nodes, and comparing target index information with the second index information; the target index information is index information obtained after deduplication processing of block index information containing the same block height in the multiple first index information; If it is found that the block hashes in the block index information containing the same block height in the multiple first index information are consistent, and the target index information is consistent with the second index information, it is determined that the second index information is consistent with the first index information.
4. The method according to claim 1, characterized in that: There are a plurality of second nodes, each of which has respective first index information, and the block height range of the blocks archived by each second node to the block archiving device is the target block height range; The method further comprises: Comparing a plurality of first index information of a plurality of second nodes with the second index information; If the target quantity is greater than or equal to the quantity threshold, it is determined that the second index information is consistent with the first index information; the target quantity refers to the number of first index information that is the same as the second index information among the multiple first index information.
5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: If the second index information is inconsistent with the first index information, the first block sent by the block archiving device is discarded, and a prompt message indicating block synchronization failure is output.
6. The method according to claim 5, characterized in that After adding the first block to the block ledger of the first node, the method further includes: If the block height of the first block is less than the highest block height of blocks in the blockchain network, a third block synchronization request is sent to the second node; the third block synchronization request is used to pull a block in the blockchain network whose block height is greater than the block height of the first block; Receive a second block sent by the second node, and add the second block to the block ledger of the first node; The second block refers to a block in the blockchain network whose block height is greater than the block height of the first block.
7. The method according to claim 1, characterized in that The first node refers to a blockchain node newly added to the blockchain network, and the second node refers to a blockchain node that joined the blockchain network before the first node; The block ledger of the second node does not include the blocks archived by the second node.
8. A block synchronization device for a blockchain network, characterized in that: The device is applied to a first node in the blockchain network; the device includes: A first request unit, configured to send a first block synchronization request to a second node in the blockchain network, and receive first index information sent by the second node based on the first block synchronization request; the first index information refers to index information of blocks within a target block height range, and the blocks within the target block height range refer to blocks that have been archived by the second node to a block archiving device; A second request unit is used to send a second block synchronization request to the block archiving device; the second block synchronization request includes indication information, and the indication information is used to indicate the blocks within the target block height range that need to be synchronized; A data receiving unit, configured to receive the first block indicated by the indication information sent by the block archiving device and second index information of the first block; A data adding unit is used to add the first block to the block ledger of the first node if the second index information is consistent with the first index information.
9. A computer device, characterized in that: The method comprises a processor and a memory, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method of any one of claims 1 to 7 is implemented.
11. A computer program product, characterized in that The computer program product comprises computer instructions, which implement the method according to any one of claims 1 to 7 when executed by a processor.