Block synchronization method and device, electronic equipment and storage medium
By sending synchronization requests to multiple target blockchain nodes and splitting data, the problem of low block synchronization efficiency is solved, and a high degree of consistency and system stability of each node block in the blockchain is achieved.
Patent Information
- Application Number
- CN202310477117.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-27
- Publication Date
- 2024-10-29
AI Technical Summary
Existing blockchain networks are inefficient at block synchronization, especially after node restarts or in networks with high block production efficiency, making it difficult for new nodes to catch up with the latest blocks on the chain, resulting in low synchronization efficiency.
By sending synchronization requests to multiple target blockchain nodes, including the block information to be synchronized, the total number of shards, and the shard sequence number, the target node splits the data of the blocks to be synchronized and returns the shard data. The node to be synchronized is based on the shards. Serial number splicing is used to obtain complete block data, using multi-node concurrent synchronization.
It greatly improves the block synchronization efficiency, ensures that the blocks of each node in the blockchain are highly consistent, and improves the stability of the blockchain system and the rapid synchronization capability of new nodes.
Smart Images

Figure CN118869710A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of blockchain technology, and in particular to a block synchronization method, device, electronic device and storage medium. Background Art
[0002] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. In the blockchain system, different blockchain nodes generally store the same blockchain, but some blockchain nodes may have problems with the stored blockchain being inconsistent with the blockchain in other blockchain nodes because they are newly added nodes or because of network disconnection. In this case, it is generally necessary to synchronize blocks from other blockchain nodes.
[0003] Generally, when synchronizing blocks, the blockchain node first determines whether its own height is the latest. If it is the latest height, it will not be processed. When its own height is lower than the latest block height on the chain, it calculates the number of blocks that need to be synchronized, and then selects a blockchain node to send a synchronization request to synchronize blocks. However, this block synchronization method is inefficient. If the node that needs to be synchronized lags behind many blocks, especially a blockchain network that has been running for a long time, or a network with a very high block generation efficiency, it will still lag behind a lot after the node is restarted. This block synchronization method is very inefficient. If the efficiency of synchronizing blocks is lower than the efficiency of new blocks in the blockchain network, then this new node will never catch up with the speed in the blockchain network.
[0004] Therefore, how to provide a technical solution that can improve block synchronization efficiency is a technical problem that urgently needs to be solved in this field. Summary of the invention
[0005] The embodiments of this specification provide a block synchronization method, device, electronic device, storage medium and computer program product, which can improve the efficiency of block synchronization.
[0006] On the one hand, an embodiment of this specification provides a block synchronization method, the method comprising:
[0007] Send a synchronization request to at least two target blockchain nodes, wherein the synchronization request includes the block information to be synchronized, the total number of shards and the shard sequence number corresponding to the target blockchain node, the block height of the target blockchain node is the specified block height; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized;
[0008] Receive multiple block data returned by each of the target blockchain nodes, wherein the block data includes a shard sequence number and block shard data corresponding to the target blockchain node, and the block shard data is data corresponding to the shard sequence number after the target blockchain node splits the block to be synchronized according to the total number of shards;
[0009] The block fragment data in the plurality of block data are sequentially spliced according to the order of the fragment sequence numbers in the plurality of block data to obtain synchronized block data.
[0010] On the other hand, an embodiment of the present specification provides a block synchronization method, the method comprising:
[0011] Receive a synchronization request sent by a blockchain node to be synchronized, wherein the synchronization request includes the block information to be synchronized, the shard sequence number and the total number of shards; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized;
[0012] Splitting the block to be synchronized according to the total number of shards to obtain multiple shard data;
[0013] According to the shard sequence number, the corresponding shard data is selected as the block shard data, and the shard sequence number and the block shard data are spliced and sent to the blockchain node to be synchronized, so that the blockchain node to be synchronized will splice the block shard data in each block data in the order of the shard sequence number to obtain the synchronized block data.
[0014] On the other hand, an embodiment of the present specification provides a block synchronization device, the device comprising:
[0015] A synchronization request sending module, used to send a synchronization request to at least two target blockchain nodes, wherein the synchronization request includes the block information to be synchronized, the total number of shards and the shard sequence number corresponding to the target blockchain node, and the block height of the target blockchain node is the specified block height; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized;
[0016] A synchronization data receiving module, used to receive multiple block data returned by each of the target blockchain nodes, wherein the block data includes a sharding sequence number and block sharding data corresponding to the target blockchain node, and the block sharding data is data corresponding to the sharding sequence number after the target blockchain node splits the block information to be synchronized corresponding to the block to be synchronized according to the total number of shards;
[0017] The data splicing module is used to splice the block fragment data in the multiple block data in sequence according to the fragment sequence numbers in the multiple block data to obtain synchronized block data.
[0018] On the other hand, an embodiment of the present specification provides a block synchronization device, the device comprising:
[0019] A synchronization request receiving module, used to receive a synchronization request sent by a blockchain node to be synchronized, wherein the synchronization request includes information of the block to be synchronized, a shard sequence number, and a total number of shards; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the information of the block to be synchronized;
[0020] A data splitting module, used for splitting the data of the block to be synchronized according to the total number of shards;
[0021] The synchronization data returning module is used to select the corresponding shard data as the block shard data according to the shard sequence number, splice the shard sequence number and the block shard data, and send them to the blockchain node to be synchronized, so that the blockchain node to be synchronized will splice the block shard data in each block data in the order of the shard sequence number to obtain the synchronized block data.
[0022] On the other hand, an embodiment of the present specification provides an electronic device, including: a processor;
[0023] a memory for storing instructions executable by the processor;
[0024] The processor is configured to execute the instructions to implement any of the above block synchronization methods.
[0025] On the other hand, a computer-readable storage medium is provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute any of the above-mentioned block synchronization methods.
[0026] On the other hand, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the block synchronization method provided in the above various optional implementations.
[0027] The block synchronization method, device, storage medium and computer program product provided in the embodiments of this specification have the following technical effects:
[0028] When block synchronization is required, the embodiments of this specification may send synchronization requests to multiple blockchain nodes, and by adding the total number of shards and shard numbers in the synchronization request, the target blockchain node that receives the request can split the data of the block to be synchronized, obtain multiple copies of block shard data, and then return the corresponding block data based on their respective shard numbers. The blockchain node to be synchronized performs data splicing based on the shard numbers in each block data to obtain synchronized block data. By splitting the data of the block to be synchronized and using a multi-node concurrent method to synchronize the blocks, batch synchronization of blocks can be achieved, which greatly improves the efficiency of block synchronization and ensures that the block heights of each node in the blockchain can be kept consistent. For the blockchain network, the blockchain node to be synchronized can quickly reach the latest block height and start to participate in consensus, thereby improving the stability of the blockchain system. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solutions and advantages of the embodiments of this specification or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0030] Figure 1 It is a schematic diagram of an application environment of a block synchronization method provided in an embodiment of this specification;
[0031] Figure 2 It is a flowchart of a block synchronization method provided in one embodiment of this specification;
[0032] Figure 3 It is a schematic diagram of the change of permissions of different nodes in the blockchain in a scenario example of this specification;
[0033] Figure 4 is a flowchart of a block synchronization method in another embodiment of the present specification;
[0034] Figure 5 is a schematic diagram of the principle of block synchronization in one embodiment of this specification;
[0035] Figure 6 It is a schematic diagram of the principle of data reorganization in block synchronization in one embodiment of this specification;
[0036] Figure 7 It is a schematic diagram of the principle of transaction filtering during block synchronization in one embodiment of this specification;
[0037] Figure 8 This is a schematic diagram of the block synchronization transaction filtering process in one embodiment of this specification;
[0038] Fig. 9 is a schematic diagram of the structure of a block synchronization device in one embodiment of this specification;
[0039] Fig.10 is a structural diagram of a block synchronization device in another embodiment of the present specification;
[0040] Fig.11 is a block diagram of an electronic device for block synchronization provided by an embodiment of this specification;
[0041] Fig.12 It is a block diagram of another electronic device for block synchronization provided in an embodiment of this specification. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. Based on the embodiments in the embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the embodiments of this specification.
[0043] It should be noted that the terms "first", "second", etc. in the description and claims of the embodiments of this specification and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of this specification described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0044] See also Figure 1 , Figure 1 1 is a schematic diagram of an application environment of a block synchronization method provided in an embodiment of this specification, and the application environment may at least include a server 100 and a terminal 200.
[0045] In an optional embodiment, the server 100 can be used to determine the information conversion rate. The server 100 can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.
[0046] In an optional embodiment, the terminal 200 can be used to provide block synchronization processing services to users. Specifically, the terminal 200 can include but is not limited to smart phones, desktop computers, tablet computers, laptops, smart speakers, digital assistants, augmented reality (AR) / virtual reality (VR) devices, smart wearable devices, vehicle terminals, smart TVs and other types of electronic devices; it can also be software running on the above electronic devices, such as applications, applets, etc. The operating system running on the electronic device in the embodiments of this specification can include but is not limited to Android system, IOS system, Linux, Windows, etc.
[0047] In addition, it should be noted that Figure 1 What is shown is only an application environment of a block synchronization method, and the embodiments of this specification are not limited to the above.
[0048] In the embodiments of this specification, the server 100 and the terminal 200 may be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of this specification.
[0049] The embodiments of this specification provide a block synchronization method, which is mainly used in blockchain. Blockchain is a new application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the blockchain underlying platform, platform product service layer and application service layer.
[0050] The underlying blockchain platform can include processing modules such as user management, basic services, smart contracts, and operation management. Among them, the user management module is responsible for the identity information management of all blockchain participants, including maintaining the generation of public and private keys (account management), key management, and the maintenance of the correspondence between the user's real identity and the blockchain address (authority management), etc., and, under authorization, supervises and audits the transactions of certain real identities and provides risk control rule configuration (risk control audit); the basic service module is deployed on all blockchain node devices to verify the validity of business requests, and records valid requests to storage after consensus is reached. For a new business request, the basic service first adapts the interface for parsing and authentication (interface adaptation), and then encrypts the business information through the consensus algorithm (consensus management ), and after encryption, it is transmitted completely and consistently to the shared ledger (network communication) and recorded and stored; the smart contract module is responsible for the registration and issuance of contracts, as well as contract triggering and contract execution. Developers can define the contract logic in a programming language and publish it to the blockchain (contract registration). According to the logic of the contract terms, the key or other event trigger execution is called to complete the contract logic. At the same time, it also provides the function of contract upgrade and cancellation; the operation management module is mainly responsible for the deployment, configuration modification, contract setting, cloud adaptation and real-time status visualization output of the product during the product release process, such as alarm, real-time management of network conditions, management of node equipment health status, etc.
[0051] The platform product service layer provides the basic capabilities and implementation framework of typical applications. Developers can superimpose business features based on these basic capabilities to complete the blockchain implementation of business logic. The application service layer provides application services based on blockchain solutions for business participants to use.
[0052] There are usually many nodes in a blockchain, each node generally corresponds to a client, and each node stores many blocks. Multiple blocks are connected to form a blockchain, and each block stores relevant data in the blockchain, such as transaction data, configuration data, or contract data. Generally, the blocks in each node in the blockchain are the same, but when a new node joins or due to network disconnection, there will be a problem that the stored blockchain is inconsistent with the blockchain in other blockchain nodes. In this case, block synchronization is required to ensure that the blocks in each node are the same.
[0053] The embodiments of this specification provide a block synchronization solution, which is different from the traditional block synchronization. When synchronizing the same block or the same batch of blocks, the synchronization requirements are sent to multiple target blockchain nodes. Each target blockchain node divides the data into multiple fragments according to the sharding strategy, and then sends the corresponding sharding data according to the index value after the node is sorted. When the new node receives the data sent by multiple target blockchain nodes, it reassembles the data according to the sharding strategy, and completes the complete data of this block or this batch of blocks, which greatly improves the efficiency of block synchronization.
[0054] The following introduces a block synchronization method according to an embodiment of the present specification. The method can be applied to a server or a client, such as a terminal device such as a computer, a tablet computer, or a smart phone. Figure 2 is a flowchart of a block synchronization method provided in one embodiment of this specification, such as Figure 2 As shown, the block synchronization method provided in some embodiments of this specification can be applied to the total number of blockchain nodes to be synchronized, and the method may include:
[0055] S202. Send a synchronization request to at least two target blockchain nodes, wherein the synchronization request includes the block information to be synchronized, the total number of shards and the shard sequence number corresponding to the target blockchain node, and the block height of the target blockchain node is the specified block height; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized.
[0056] In the specific implementation process, generally, a blockchain may contain multiple blockchain nodes, each blockchain node may contain one or more blocks, and the total height of all blocks in each blockchain node may be referred to as the block height of the blockchain node. In general, the blocks in each blockchain node are the same. When the blocks in a blockchain node are different from the blocks in other nodes, it means that the blockchain node needs to perform block synchronization, such as: when the block height of a blockchain node itself is lower than the specified block height, it can be considered that the blockchain node needs to perform block synchronization. Among them, the specified block height can generally be understood as the latest block height in the blockchain at the current time. The specified block height can be obtained according to the block list in the blockchain, or the block height of the consensus node in the blockchain can be used as the specified block height.
[0057] When a blockchain node finds that its own block height is lower than the specified block height, it can send a synchronization request to at least two target blockchain nodes to request the target blockchain node to return the block data that needs to be synchronized. The node can be called a blockchain node to be synchronized. Among them, generally, the target blockchain node can be a node with a block height of a specified block height in the blockchain. According to the actual application needs, at least two nodes with a block height of a specified block height can be selected from the blockchain as the target blockchain node. The block height equal to the specified block height indicates that the blockchain node contains the latest block, which also contains the block required by the node sending the request. The method of selecting the target blockchain node can be selected according to actual needs, such as: two or more blockchain nodes with a block height equal to the specified block height can be randomly selected from the blockchain as the target blockchain node, or two or more blockchain nodes with a block height equal to the specified block height can be selected from the node closest to itself as the target blockchain node, which is not specifically limited in the embodiments of this specification. Among them, the number of target blockchains can be determined according to actual needs, or according to the size of the blocks to be synchronized, which is not specifically limited in the embodiments of this specification.
[0058] In some other embodiments, at least two consensus nodes or super nodes in the blockchain can also be selected as target blockchain nodes, wherein the consensus node can be regarded as a special ordinary time node, which needs to reach a consensus to update the account book in addition to completing the work of an ordinary time node. In some blockchain networks, some consensus nodes have a higher level of authority than other nodes for some reasons, such as higher rights and interests, or some kind of certification. This type of node is usually more credible and usually has more voting rights in the blockchain network. This type of node can be called a super node. The block height of the consensus node and the super node is generally the latest block height in the blockchain, and the number of consensus nodes and super nodes in the blockchain is generally limited. In some embodiments, all consensus nodes in the blockchain can be used as target blockchain nodes, or all consensus nodes and super nodes in the blockchain can be used as target blockchain nodes.
[0059] When a blockchain node finds that it needs to synchronize blocks, it can send a synchronization request to at least two target blockchain nodes, and the synchronization request can include the block information to be synchronized, the total number of shards, and the shard sequence number corresponding to the target blockchain node. Of course, the synchronization request can also include other information such as: the identifier of the blockchain node to be synchronized, etc., which is not specifically limited in the embodiments of this specification. Among them, the block information to be synchronized can be understood as the block information that needs to be synchronized, such as: the block identifier that needs to be synchronized, so that the target blockchain node can determine which blocks need to be synchronized according to the synchronization request. In addition, the embodiments of this specification propose a solution for splitting the data of the synchronized blocks and then synchronizing them. The synchronization request can include the shard sequence number and the total number of shards, wherein the total number of shards can be understood as the total number of shards for data splitting of the synchronized blocks, and the shard sequence number can be understood as which one or which of the split shard data each target blockchain node needs to synchronize. The shard sequence number can be used as an index for each shard data after the data of the synchronization block is split. Based on the shard sequence number, each target blockchain node can accurately and quickly obtain the data it needs to return from each shard data after the data is split.
[0060] S204. Receive multiple block data returned by each target blockchain node, where the block data includes the shard sequence number and block shard data corresponding to the target blockchain node. The block shard data is the data corresponding to the shard sequence number after the target blockchain node splits the data of the block to be synchronized according to the total number of shards.
[0061] In the specific implementation process, after receiving the synchronization request, the target blockchain node can return the corresponding block data to the blockchain node to be synchronized that sent the request according to the synchronization request. Specifically, after receiving the synchronization request, the target blockchain node can split the data of the block to be synchronized corresponding to the synchronization block information according to the total number of shards in the synchronization request, and obtain multiple copies of block shard data. Then determine which piece or pieces of data after the split are the block shard data that you need to return according to the shard sequence number, and return the block shard data and the corresponding shard sequence number to the blockchain node to be synchronized. Among them, the method of data splitting for the synchronization block can be selected according to actual needs, or data splitting rules can be added in the synchronization request to facilitate the target blockchain node to split the data of the synchronization block based on the data splitting rules. The embodiment of this specification does not specifically limit this. However, the data splitting of the synchronization block is split according to the order of the synchronization block, and the shard sequence number corresponding to each block shard data is determined based on the original order of the data of the synchronization block.
[0062] For example: if the target blockchain node A receives a synchronization request sent by the blockchain node B to be synchronized, the synchronization request contains the total number of shards 3, the shard sequence number 1, and the block information to be synchronized is the block identifiers s1, s2, and s3. According to the synchronization request, the target blockchain node A splits the data of the block to be synchronized corresponding to the block identifiers s1, s2, and s3 into three parts, obtains three pieces of block shard data, and returns the first piece of block shard data and shard sequence number 1 as block data to the blockchain node B to be synchronized.
[0063] Generally, a target blockchain node corresponds to a shard number. The target blockchain node can accurately select which block shard data to return to the blockchain node to be synchronized after the block data to be synchronized is split based on the shard number. Of course, if it is actually needed, multiple shard numbers can also be sent to a target blockchain node, and then the target blockchain node needs to return multiple block shard data. For example, the number of shard numbers of each target blockchain node can be determined based on the computing power and response speed of the target blockchain node.
[0064] S206. Sequentially concatenate the block fragment data in the plurality of block data in the order of the fragment sequence numbers in the plurality of block data to obtain synchronized block data.
[0065] In the specific implementation process, after the synchronization blockchain node receives the block data returned by multiple target blockchain nodes, it can sequentially splice the block shard data in the multiple block data according to the order of the shard sequence numbers in the block data to obtain the synchronized block data.
[0066] For example: the blockchain node B to be synchronized receives block data 1 returned by the target blockchain node A, block data 2 returned by the target blockchain node C, and block data 3 returned by the target blockchain node D, where block data 1 contains shard sequence number 1 and block shard data x1, block data 2 contains shard sequence number 2 and block shard data x2, and block data 3 contains shard sequence number 3 and block shard data x3. According to the order of shard sequence numbers 1, 2, and 3, block shard data x1, block shard data x2, and block shard data x3 are spliced together in turn to obtain synchronized block data.
[0067] In some embodiments of this specification, if the blocks to be synchronized are two or more blocks, the method further includes:
[0068] The synchronization block data is divided according to the arrangement order of each block to be synchronized in the target blockchain node and the height of each block to be synchronized, and the block data corresponding to each block to be synchronized is obtained;
[0069] The block data are stored in sequence according to the order in which the blocks to be synchronized are arranged in the target blockchain node.
[0070] In the specific implementation process, the number of blocks to be synchronized is determined according to the block height of the blockchain node to be synchronized and the specified block height. It can be one block or two or more blocks. If the block to be synchronized is one block, then the synchronization block data obtained in the above embodiment is the data corresponding to the block to be synchronized. The obtained synchronization block data can be directly dropped to the local storage to complete the block synchronization. Generally, blocks have a fixed connection order in the blockchain node. If there are two or more blocks to be synchronized, the obtained synchronization block data can be divided according to the arrangement order of each block to be synchronized in the target blockchain node and the height of each block to be synchronized. The block data corresponding to each block to be synchronized can be obtained, and then the block data of each block to be synchronized can be dropped in turn according to the arrangement order of the block to be synchronized in the target blockchain node to complete the block synchronization. Among them, dropping a block can mean writing a block to the local storage of the blockchain. The synchronized block data obtained by synchronization is split and placed according to the order and height of the blocks to be synchronized, which can ensure that the blocks obtained after block synchronization have the same order and data as the blocks in other nodes, thereby ensuring the accuracy of block synchronization.
[0071] For example: if there are three blocks to be synchronized, s1, s2, and s3, and the order in the node is also s1, s2, and s3, according to the method described in the above embodiment, the target blockchain node splits blocks s1, s2, and s3 according to the total number of shards, and each returns the block data corresponding to the shard sequence number. Assuming that the total number of shards is 4, 4 block data can be obtained. After the blockchain node to be synchronized splices the 4 shard data together according to the shard sequence number in the block data, the synchronized block data S is obtained. Then, according to the order and height of s1, s2, and s3, the synchronized block data S is divided into 3 parts, and then the corresponding 3 pieces of block data are stored locally in the blockchain in the order of s1, s2, and s3.
[0072] The block synchronization method provided in the embodiment of this specification can send synchronization requests to multiple blockchain nodes when block synchronization is required, and by adding the total number of shards and shard sequence numbers in the synchronization request, the target blockchain node that receives the request can split the data of the block to be synchronized, obtain multiple copies of block shard data, and then return the corresponding block data based on their respective shard sequence numbers. The blockchain node to be synchronized splices data based on the shard sequence numbers in each block data to obtain synchronized block data. By splitting the data of the block to be synchronized and using a multi-node concurrent method to synchronize the blocks, batch synchronization of blocks can be achieved, which greatly improves the efficiency of block synchronization and ensures that the block heights of each node in the blockchain can be kept consistent. For the blockchain network, the blockchain node to be synchronized can quickly reach the latest block height and start to participate in consensus, which improves the stability of the blockchain system.
[0073] In some embodiments of this specification, sending a synchronization request to at least two target blockchain nodes includes:
[0074] When it is determined that the own block height is lower than the specified block height, at least two target blockchain nodes are determined according to the specified block height;
[0075] Determine the block information to be synchronized based on its own block list and the received real-time block list;
[0076] Determine the total number of shards and the shard sequence number corresponding to each target blockchain node according to the number of target blockchain nodes;
[0077] The synchronization request is sent to the corresponding target blockchain node according to the block information to be synchronized, the total number of shards, and the shard sequence number corresponding to each target blockchain node.
[0078] In the specific implementation process, the blockchain node to be synchronized can determine whether block synchronization is required based on its own block list and the real-time block list in the blockchain. Among them, the self-block list can be used for the block information of the blockchain node to be synchronized, and the real-time block list can be understood as a list storing all the block information of the blockchain. The real-time block list can be updated in real time based on the actual situation of the blockchain. When the blockchain node to be synchronized finds that its own block height is lower than the specified block height, it can select at least two nodes with block heights equal to the specified block height from the blockchain as the target blockchain node according to the specified block height, and then calculate the block information to be synchronized that needs to be synchronized according to its own block list and the real-time block list. After obtaining the target blockchain node, the total number of shards for data splitting of the synchronized block can be determined according to the number of target blockchain nodes, such as: the total number of selected target blockchain nodes can be used as the total number of shards. Then set the shard sequence number corresponding to each target blockchain node, such as: the shard sequence number corresponding to each target blockchain node can be set based on the distance from the blockchain node to be synchronized.
[0079] In some embodiments of this specification, determining the total number of shards and the shard numbers corresponding to each target blockchain node according to the number of target blockchain nodes includes:
[0080] Sort each target blockchain node according to the node ID;
[0081] The total number of target blockchain nodes is taken as the total number of shards, and the ranking of each target blockchain node is taken as the shard sequence number corresponding to each target blockchain node.
[0082] In the specific real-time process, after selecting each target blockchain node, each target blockchain node can be sorted based on the node identifier of the target blockchain node, and the total number of selected target blockchain nodes is used as the total number of shards, and the sort of each target blockchain node is used as the respective shard sequence number. By sorting the target blockchain nodes, the total number of shards for data splitting and the shard sequence number of each target blockchain node can be quickly obtained, laying a data foundation for the subsequent data splitting, data return, and data splicing of the blocks to be synchronized.
[0083] After determining the total number of shards of the block data to be synchronized and the shard sequence number corresponding to each target blockchain node, the total number of shards, the shard sequence number and the block information to be synchronized can be sent to the corresponding target blockchain node, that is, a synchronization request is sent to the target blockchain node. It can be seen that the specific information in the synchronization request received by each target blockchain node is different. For example, the synchronization request received by the target blockchain node 1 may include: block information to be synchronized s1, s2, s3, the total number of shards is 3, and the shard sequence number is 1; the synchronization request received by the target blockchain node 2 may include: block information to be synchronized s1, s2, s3, the total number of shards is 3, and the shard sequence number is 2; the synchronization request received by the target blockchain node 3 may include: block information to be synchronized s1, s2, s3, the total number of shards is 3, and the shard sequence number is 3. After receiving the synchronization request, each target blockchain node can split the data of the block to be synchronized based on the total number of shards in the synchronization request, and select the split data corresponding to the shard sequence number and return it to the blockchain node to be synchronized together with the shard sequence number.
[0084] The block synchronization method provided in the embodiment of this specification can select multiple blockchain nodes with a specified block height as target blockchain nodes when the blockchain node to be synchronized determines that it needs to synchronize blocks, and set the total number of shards for data splitting of the synchronized block according to the number of selected target blockchain nodes, and configure the shard sequence number for the target blockchain node. In this way, multiple target blockchain nodes can synchronously and concurrently return the corresponding block data to the blockchain node to be synchronized based on the total number of shards and shard sequence numbers, realizing the synchronous and concurrent execution of multi-node block synchronization, improving the efficiency of block synchronization, ensuring that the block height of each node in the blockchain can be consistent, and ensuring the stability of the blockchain system.
[0085] In some embodiments of this specification, determining the block information to be synchronized based on the own block list and the received real-time block list includes:
[0086] Determine the synchronization block information based on its own block list and the received real-time block list;
[0087] The synchronization block information is grouped, and each group of synchronization block information is used as the block information to be synchronized in turn, and the grouping information corresponding to the block information to be synchronized, the block information to be synchronized, the total number of shards, and the shard sequence number corresponding to each target blockchain node are sent to the corresponding target blockchain node as a synchronization request.
[0088] In the specific implementation process, when the blockchain node to be synchronized finds that its own block height is lower than the specified block height based on its own block list and the received real-time block list, it can select at least two nodes with block heights equal to the specified block height from the blockchain as the target blockchain nodes according to the specified block height, and then calculate the synchronization block information that needs to be synchronized according to its own block list and the real-time block list. Generally, the synchronization block information corresponds to multiple blocks. In some embodiments of this specification, the synchronization block information can be grouped, and the blocks to be synchronized can be divided into multiple groups, and then each group of blocks can be used as the block information to be synchronized in turn, and the scheme recorded in the above embodiment can be used for block synchronization. Among them, the specific method of grouping can be determined according to actual needs, such as: according to the number and size of the blocks to be synchronized, or according to the number of target blockchain nodes, and the embodiments of this specification do not make specific limitations.
[0089] For example: Assume that based on its own block list and real-time block list, it is calculated that there are 20 blocks that need to be synchronized, and the synchronization block information is s1, s2...s20 in sequence. The synchronization block information is divided into 2 groups, the first group is s1~s10, the grouping information is L1, and the second group is s11~s20, and the grouping information is L2. The first group s1~s10 can be used as the block information to be synchronized. After the method of the above embodiment is used to determine the total number of shards and the shard serial number of each target blockchain node, the grouping information, the total number of shards, the corresponding shard serial number and the block information s1~s10 to be synchronized are sent to the corresponding target blockchain node as a synchronization request. After the synchronization of the first group of block information to be synchronized is completed, the second group of block information s11~s20 can be used as the block information to be synchronized for block synchronization.
[0090] The embodiments of this specification can realize batch synchronization of different blocks by grouping the blocks to be synchronized, and can avoid the problem of slow data processing or data processing errors caused by synchronizing too much block data at one time, thereby improving the efficiency and accuracy of block synchronization and ensuring the stability of blockchain system performance.
[0091] In some embodiments of this specification, the synchronization block information is grouped, and each group of synchronization block information is sequentially used as the block information to be synchronized, including:
[0092] The synchronization block information is grouped, and the first group of synchronization block information is used as the block information to be synchronized according to the order of the blocks in the synchronization block information in the target blockchain node, and a synchronization request is sent to at least two target blockchain nodes;
[0093] After receiving multiple block data returned by each target blockchain node, the next set of synchronization block information is used as the block information to be synchronized, and the next synchronization request is sent to at least two target blockchain nodes until the synchronization of the blocks to be synchronized corresponding to all the synchronization block information is completed.
[0094] In the specific implementation process, if the blocks to be synchronized are grouped during block synchronization, multiple groups of blocks to be synchronized can be synchronized by different target blockchain nodes or by the same batch of target blockchain nodes. In the embodiment of this specification, after the synchronization block information is grouped to obtain multiple groups of synchronization block information, the first group of synchronization block information can be used as the block information to be synchronized according to the order of each block to be synchronized in the blockchain node, and a synchronization request can be sent to the target blockchain node. After the blockchain node to be synchronized receives the block data returned by each target blockchain node, the next group of synchronization block information can be used as the block information to be synchronized, and the next synchronization request can be sent to the same target blockchain node until the synchronization of all blocks corresponding to the synchronization block information is completed. In this way, the blockchain node to be synchronized can splice the block data corresponding to the first group of block information to be synchronized, and at the same time, the target blockchain node can split the data corresponding to the next group of block information to be synchronized, and return the corresponding block data after the split. It realizes the synchronization of multiple batches of blocks for block batch synchronization, thereby improving the efficiency of block synchronization.
[0095] For example: In the above example, there are 20 blocks that need to be synchronized. The synchronization block information is s1, s2...s20 in the order of the blocks in the node. The synchronization block information is divided into 2 groups in order. The first group is s1~s10, and the grouping information is L1. The second group is s11~s20, and the grouping information is L2. The method of the above embodiment is used to determine the three target blockchain nodes 1, 2, and 3. The first group s1~s10 can be used as the block information to be synchronized. After the total number of shards and the shard serial numbers corresponding to the target blockchain nodes 1, 2, and 3 are determined by the method of the above embodiment, the grouping information, the total number of shards, the corresponding shard serial numbers, and the block information s1~s10 to be synchronized are sent as synchronization requests to the corresponding target blockchain nodes 1, 2, and 3. When the target blockchain nodes 1, 2, and 3 return the corresponding block data, the second group of block information s11-s20 is used as the block information to be synchronized, and according to the grouping information, the total number of shards, the corresponding shard sequence number, and the block information s11-s20 to be synchronized, a synchronization request is sent to the target blockchain nodes 1, 2, and 3. At this time, the blockchain node to be synchronized can splice and block the block data of the first group of block information s1-s10 to be synchronized, and the target blockchain node can split the data of the second group of block information s11-s20 to be synchronized, and return the corresponding block data to the blockchain node to be synchronized based on the shard sequence number, so as to realize the synchronization processing of multiple groups of blocks in batches, and improve the data processing efficiency of block synchronization.
[0096] In some embodiments of the present specification, the received block data includes a shard sequence number, grouping information, and block shard data; sequentially splicing the block shard data in the plurality of block data in the order of the shard sequence numbers in the plurality of block data to obtain synchronized block data includes:
[0097] According to the grouping information in the plurality of block data, the block fragment data in the plurality of block data belonging to the same group are spliced in sequence according to the order of the fragment sequence numbers to obtain the synchronous block data.
[0098] In the specific implementation process, if the blocks to be synchronized are grouped during block synchronization, multiple groups of blocks to be synchronized may be synchronized by different target blockchain nodes, or they may be synchronized by the same batch of target blockchain nodes at different time nodes. It is possible that the blockchain nodes to be synchronized receive different groups of block data to be synchronized within a time period. In the embodiment of this specification, the grouping information corresponding to the block information to be synchronized can be added to the synchronization request. Similarly, the block data returned by each target blockchain node may also include grouping information. After receiving the block data returned by each target blockchain node, the blockchain node to be synchronized can determine which block data belongs to the same group based on the grouping information in the block data, and then based on the grouping information, splice the block shard data in the block data belonging to the same group according to the shard sequence number to obtain the synchronized block data corresponding to the same group of blocks.
[0099] The embodiments of this specification ensure that block data of the same group are spliced by adding grouping data to the synchronization request and the block data returned by the target blockchain node, and ensure that the synchronized block data is the same as the blocks in other nodes, thereby ensuring the accuracy of block synchronization.
[0100] In some embodiments of the present specification, the synchronization request also includes: node configuration information, so that each target blockchain node filters the data of the block to be synchronized based on the node configuration information, and obtains the block shard data after performing data splitting on the data in the block to be synchronized that satisfies the node configuration information.
[0101] In the specific implementation process, for many blockchain application scenarios, each node is part of the blockchain network and undertakes the work of distributed accounting. Among them, the blockchain nodes participating in the consensus are called consensus nodes. These nodes will participate in the consensus-related work of the blockchain. Usually, for the blockchain network itself, they have relatively high identity information or authority control. For example: Figure 3 This is a schematic diagram of the change of permissions of different nodes in the blockchain in a scenario example of this manual, such as Figure 3 As shown in the figure, in some blockchain networks that use the DPoS (Delegated Proof of Stake) consensus algorithm, nodes become candidate nodes for consensus nodes after staking a portion of their equity, and then pass certain selection conditions to eventually generate a group of nodes to become consensus nodes. In this way, there is not only one node identity in the entire blockchain network. In a blockchain network dominated by the DPoS consensus algorithm, there are three types of identity information: ordinary nodes ( Figure 3 Nodes 1 to 7 in the Node List), candidate nodes, and consensus nodes. Figure 3 As shown, the change process of different nodes can be expressed as:
[0102] 1. Ordinary nodes: Nodes joining the blockchain network are ordinary nodes by default. If they do not participate in equity staking, then this node will always be an ordinary node.
[0103] 2. Candidate Node: After ordinary nodes pledge a certain amount of rights and interests, the specific amount depends on the settings of each different blockchain network. They can become candidate nodes. At this time, these nodes are no longer ordinary nodes, and their identities are different. If the node fails to pass the election or does not revoke the pledged rights and interests below the minimum pledge amount, then this node will always be a candidate node and will participate in the candidate election of each generation.
[0104] 3. Consensus Node: To become a consensus node, you must first become a candidate node to be eligible to participate in the consensus node selection. When a candidate node is selected in a certain generation election, it becomes a consensus node. At the end of this generation, all consensus nodes will return to the candidate node status and participate in the consensus node election of the next generation.
[0105] 4. Generation: The noun definition of a certain period in consensus algorithms such as DPoS, that is, a generation is a period.
[0106] 5. Other identities: For blockchain networks, operators can also set certain identities for some special nodes through contracts, etc. according to actual operation scenarios. For example, the blockchain network of EOS (Enterprise Operation System, a blockchain operating system designed for commercial distributed applications) will give some nodes with a relatively large amount of pledged equity the identity of super nodes.
[0107] In a blockchain network, operators can grant different permissions to nodes based on their identities. For example, in a blockchain with DPoS consensus, ordinary nodes can be set to only synchronize block data and ledger data, and cannot initiate transactions. All candidate nodes can be set to synchronize block data and ledger data, and to initiate transfer transactions. Only consensus nodes can initiate transactions such as chain configuration modification and new contract deployment.
[0108] For the blockchain network, different node identities or node permissions will result in different types of nodes having different filtering requirements for each module of the blockchain system. In the embodiment of this specification, by adding a filtering process during the block synchronization data processing, the target blockchain node can filter the data of the block to be synchronized according to the configuration information of the blockchain node to be synchronized, and synchronize the data that meets the node configuration information of the blockchain node to be synchronized, and delete the data that does not meet the requirements, to ensure the accuracy of block synchronization. For example: some blockchain nodes can only synchronize the block data of certain organizations. The specific filtering rules can be set according to actual needs, and the embodiments of this specification do not make specific limitations.
[0109] The block transaction filtering scheme proposed in the embodiments of this specification allows block synchronization to filter transactions according to certain permissions and rules based on actual scenario requirements. For each new node (i.e., the blockchain node to be synchronized), only some transaction data within its own authority can be synchronized, and the full amount of transactions will not be synchronized, which ensures the accuracy of block synchronization and improves the efficiency of block synchronization.
[0110] In addition, this solution is effective for block synchronization in the blockchain, and can also be effective for similar scenarios in other modules such as transaction pools.
[0111] Figure 4 is a flowchart of a block synchronization method in another embodiment of this specification, such as Figure 4 As shown, the method can be applied to the target blockchain node recorded in the above embodiment, and the method may include:
[0112] S402. Receive a synchronization request sent by a blockchain node to be synchronized, where the synchronization request includes the block information to be synchronized, the shard sequence number, and the total number of shards; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized.
[0113] In the specific implementation process, when a blockchain node finds that its own block height is lower than the specified block height, it can send a synchronization request to at least two target blockchain nodes to request the target blockchain node to return the block data that needs to be synchronized. The node can be called a blockchain node to be synchronized, and the synchronization request can include synchronization block information, shard sequence number, and the total number of shards. Among them, the block information to be synchronized can be understood as the block information that needs to be synchronized, such as: the block identifier that needs to be synchronized, so that the target blockchain node can determine which blocks need to be synchronized according to the synchronization request. The total number of shards can be understood as the total number of data splits for the synchronized blocks, and the shard sequence number can be understood as which one or which split data each target blockchain node needs to synchronize. The specific setting method of the total number of shards, the shard sequence number, and the selection method and number setting of the target blockchain node can refer to the records of the above embodiment, which will not be repeated here.
[0114] S404: Split the block to be synchronized according to the total number of shards to obtain data of multiple shards.
[0115] In the specific implementation process, after the target blockchain node receives the synchronization request sent by the blockchain node to be synchronized, it can split the data of the block to be synchronized corresponding to the block information to be synchronized based on the total number of shards in the synchronization request to obtain multiple copies of block shard data. Among them, the method of splitting the data of the block to be synchronized can be selected according to actual needs, such as: randomly splitting into the number of copies corresponding to the total number of shards based on the total number of shards, or adding data splitting rules in the synchronization request to facilitate the target blockchain node to split the data of the block to be synchronized, which is not specifically limited in the embodiments of this specification.
[0116] In some embodiments of the present specification, data splitting of the to-be-synchronized blocks corresponding to the to-be-synchronized block information according to the total number of shards includes:
[0117] According to the total number of shards and the data size of the block to be synchronized, the block to be synchronized is evenly split to obtain multiple shard data.
[0118] In the specific implementation process, in some embodiments, the block to be synchronized can be evenly split according to the data size of the block to be synchronized and the total number of shards. For example, if in an example, the data size of the block to be synchronized is 300 bytes and the total number of shards is 3, then the block to be synchronized can be divided into 3 parts of 100 bytes each.
[0119] This method of evenly dividing the total number of shards and data size is simple and fast, and can ensure that the data processing volume of each target blockchain node is the same, ensure uniform data processing speed, and improve the efficiency of block synchronization. Of course, according to actual scenario requirements, there may be other data splitting methods, which are not specifically limited in the embodiments of this specification.
[0120] S406. Select the corresponding shard data as the block shard data according to the shard sequence number, splice the shard sequence number and the block shard data, and send them to the blockchain node to be synchronized, so that the blockchain node to be synchronized will splice the block shard data in each block data in the order of the shard sequence number to obtain the synchronized block data.
[0121] In the specific implementation process, Figure 5 Schematic diagram of the principle of block synchronization in one embodiment of this specification. Figure 5 As shown, in one embodiment, consensus node 1, consensus node 2, consensus node 3, and consensus node 4 in the blockchain can be selected as target blockchain nodes, and the block information to be synchronized is Block 1-10, that is, Block 1 to Block 10 are blocks to be synchronized. Each consensus node that receives a synchronization request sends a set of block data to be synchronized ( Figure 5 The number of blocks 1 to 10 in the figure corresponds to the number of shards that can be synchronized. Figure 5 As shown in the figure, based on the number of target blockchain nodes 4, the blocks 1-10 to be synchronized are split into 4 shard data, namely slice 1-slice 4. At the same time, after sorting according to the node ID (Identity document) of each consensus node, a corresponding shard index, namely a shard sequence number, can be assigned to each consensus node, such as: 1, 2, 3, 4 after slice. Figure 5 As shown, consensus node 1 corresponds to shard index 1, and consensus node 2 corresponds to shard index 2.
[0122] In the embodiments of this specification, each shard data may include two parts: a shard header and a shard content, wherein the shard header may mark the group to which the shard data belongs and the shard sequence number, the header length may be a fixed 4 bytes, and the shard content is the actual shard data content. The consensus node shards the block data to be synchronized according to its own shard index, that is, the shard sequence number, takes out the shard data of the corresponding index, assembles the data header, that is, the shard sequence number, and sends the data to the blockchain node to be synchronized. After receiving the data returned by each target blockchain node, the blockchain node to be synchronized can reorganize the data. For example, the 4 bytes of the header of each data can be used to identify the group to which the current shard belongs and the shard sequence number, and then the content part after removing the header is spliced into a complete data in the order of the shard sequence number. After the data is assembled, the blocks are placed in sequence according to the block height order within the segment. For the specific content of the reorganization, please refer to the records of the above embodiment, which will not be repeated here.
[0123] In addition, referring to the above embodiments, in some embodiments of this specification, the blocks to be synchronized can also be grouped, and the blocks can be synchronized to the blockchain nodes to be synchronized according to different batches. Figure 5 In the example, Block1-Block10 is a group (or segment), that is, these 10 blocks are synchronized together. Figure 6 FIG. 1 is a schematic diagram showing the principle of data reorganization in block synchronization in an embodiment of the present specification. Figure 6 As shown, shard 1, shard 2, shard 3, and shard 4 correspond to Figure 5 The block data sent by consensus node 1, consensus node 2, consensus node 3, and consensus node 4 in the data are respectively. Among them, the data header is used to identify the information of the shard data, and the data body is the actual data. After the four shards of data body 1, data body 2, data body 3, and data body 4 are assembled, the complete data of the current data segment is obtained, that is, the complete data of Block1-Block10 is obtained.
[0124] The block synchronization method provided in the embodiment of this specification can send synchronization requests to multiple blockchain nodes when block synchronization is required, and add the total number of shards and shard sequence numbers in the synchronization request. Each target blockchain node that receives the request can split the data of the block to be synchronized, obtain multiple copies of block shard data, and then return the corresponding block data based on their respective shard sequence numbers. The blockchain node to be synchronized splices the data based on the shard sequence numbers in each block data to obtain the synchronized block data. By splitting the data of the block to be synchronized and using a multi-node concurrent method to synchronize the blocks, batch synchronization of blocks can be achieved, which greatly improves the efficiency of block synchronization and ensures that the block heights of each node in the blockchain can be kept consistent. For the blockchain network, the blockchain node to be synchronized can quickly reach the latest block height and start to participate in consensus, thereby improving the stability of the blockchain system.
[0125] In some embodiments of this specification, the synchronization request also includes node configuration information of the blockchain node to be synchronized. Before data splitting of the block to be synchronized corresponding to the block information to be synchronized is performed according to the total number of shards, the method also includes:
[0126] According to the header information of the blocks to be synchronized, each block to be synchronized is screened to select common transaction blocks and configuration transaction blocks;
[0127] Filtering the transaction data in the common transaction block according to the node configuration information, deleting the transaction data that does not conform to the node configuration information, and obtaining a filtered common transaction block;
[0128] The configuration transaction blocks and the screening common transaction blocks are split according to the total number of shards.
[0129] In the specific implementation process, for the blockchain network, different node identities or node permissions set up will result in different types of nodes having different filtering requirements for various modules of the blockchain system. In the embodiment of this specification, by adding a filtering process during the block synchronization data processing, the target blockchain node can filter the data of the block to be synchronized according to the configuration information of the blockchain node to be synchronized, synchronize the data that meets the node configuration information of the blockchain node to be synchronized, and delete the data that does not meet the requirements, thereby ensuring the accuracy of block synchronization.
[0130] Generally, for the block synchronization of a blockchain network, the block itself contains the header information and transaction information of the block. In the embodiments of this specification, the information of the synchronized blocks is filtered, which mainly includes two categories: according to the block type and according to the transaction type.
[0131] According to the block type, the block type recorded in the block header information is filtered. Nodes that need to filter block types are usually restricted nodes, and these nodes can only synchronize ordinary transaction data. For blocks that configure transactions, the value in the block header Block.Header.Type is generally set to: config type. In this way, when the synchronization module filters transactions, it only needs to remove Block.Body.Txs. In other words, blocks can generally be divided into ordinary transaction blocks and configuration transaction blocks. Ordinary transaction blocks can store multiple transaction information, and configuration transaction blocks can store relevant configuration information in the blockchain, such as: contract information, transaction rules, etc. Generally, the data in the configuration transaction block cannot be modified, and the configuration transaction block can be synchronized directly without filtering.
[0132] According to the filtering of transaction types, each transaction in the blockchain body is filtered. If any transaction that does not meet the conditions is found, it is removed and then the filtered block is synchronized. Usually, there are many dimensions for filtering block data according to transaction types: organization, node identity, transaction type (transfer or contract release), etc. For the synchronization module, before synchronizing the block, it is necessary to verify each transaction in the block, filter out transactions that do not meet the identity or authority, and then synchronize the block. However, if the block transaction filtering strategy of the embodiment of this specification is enabled, when the synchronization module of the new node gets the filtered block and verifies the block, it will not be able to generate a read-write set by executing each transaction, but can only trust the read-write set of the synchronized block 100%.
[0133] Figure 7 This is a schematic diagram of the principle of transaction filtering during block synchronization in one embodiment of this specification. Figure 7 As shown, blocks Block1 and Block2 have their own Header and Body, and different information about the blocks is recorded in these two areas. For example, the Header generally marks the type of the block, whether it is a configuration block or an ordinary transaction block. The Body usually contains specific transaction information for each transaction, and each transaction information contains the identity information of the sending transaction node, role information, and whether the transaction itself is an ordinary transfer transaction or a publishing and modification contract transaction. When synchronizing blocks, you can first filter out the ordinary transaction blocks and configuration transaction blocks in the blocks to be synchronized based on the Header, and then filter and filter the Russian transaction data in the ordinary transaction blocks according to the node configuration information of the blockchain node to be synchronized, and delete the transaction data that does not conform to the node configuration information of the blockchain node to be synchronized. As shown in the figure, the header contains the information of the node configuration information of the blockchain node to be synchronized, and the body contains the information of the node configuration information of the blockchain node to be synchronized. Figure 7As shown, the corresponding filtering conditions can be determined based on the node configuration information of the blockchain node to be synchronized, and the blocks Block1 and Block2 can be filtered based on the filtering conditions. After filtering the ordinary transaction blocks, the filtered ordinary transaction blocks are obtained, and the configuration transaction blocks and the filtered ordinary transaction blocks are split according to the total number of shards. Then, the blocks are synchronized according to the contents recorded in the above embodiment, which can ensure that the data synchronized to the blockchain node to be synchronized meets the requirements, and the accuracy of block synchronization is guaranteed.
[0134] Normally, if the transactions in the block are filtered out by the above method, a problem will arise. The new node cannot follow the traditional synchronization logic and execute the newly received blocks in the virtual machine VM (Virtual Machine, the operating environment of the smart contract) in the transaction order in the DAG (Directed Acyclic Graph) because some transactions have been filtered out and therefore cannot be executed. For the blockchain nodes to be synchronized, the synchronized blocks are all blocks that have completed consensus and have been placed, so the transaction execution results for these blocks are certain. Based on this, Figure 8 This is a schematic diagram of the block synchronization transaction filtering process in one embodiment of this specification, such as Figure 8 As shown, in the embodiment of this specification, when synchronizing blocks, it is only necessary to directly apply the read-write set in the block to the local ledger.
[0135] The block synchronization method provided in the embodiments of this specification provides a solution for filtering block data on the basis of shard data synchronization, so that the blockchain network supports different nodes to filter transaction data according to dimensions such as roles and permissions. It can achieve multi-dimensional isolation of data between nodes, providing more possibilities for the application scenarios of the blockchain network.
[0136] Based on the block synchronization method described above, one or more embodiments of this specification may also provide a client and a server for determining the information conversion rate. The client and the server may include a device (including a distributed system), software (application), module, component, server, client, etc. using the method described in the embodiment of this specification and a device combined with necessary implementation hardware. Based on the same innovative concept, the device in one or more embodiments provided in the embodiment of this specification is as described in the following embodiments. Since the implementation scheme and method of the device to solve the problem are similar, the implementation of the specific device in the embodiment of this specification can refer to the implementation of the aforementioned method, and the repetitions will not be repeated. As used below, the term "unit" or "module" can implement a combination of software and / or hardware for predetermined functions. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.
[0137] It can be seen from the technical solutions provided in the above embodiments of this specification that the embodiments of this specification also provide a block synchronization device. Fig. 9 is a schematic diagram of the structure of a block synchronization device in one embodiment of this specification, such as Fig. 9 As shown, the device can be applied to the blockchain node to be synchronized in the above embodiment, and the above device may include:
[0138] A synchronization request sending module 910 is used to send a synchronization request to at least two target blockchain nodes, wherein the synchronization request includes the block information to be synchronized, the total number of shards and the shard sequence number corresponding to the target blockchain node, and the block height of the target blockchain node is the specified block height; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized;
[0139] The synchronization data receiving module 920 is used to receive multiple block data returned by each target blockchain node, wherein the block data includes the sharding sequence number and block sharding data corresponding to the target blockchain node, and the block sharding data is the data corresponding to the sharding sequence number after the target blockchain node splits the synchronization block according to the total number of shards;
[0140] The data splicing module 930 is used to sequentially splice the block fragment data in the plurality of block data according to the order of the fragment sequence numbers in the plurality of block data to obtain synchronized block data.
[0141] Fig.10 is a schematic diagram of the structure of a block synchronization device in another embodiment of the present specification, such as Fig.10 As shown, the device can be applied to the target blockchain node in the above embodiment, and the above device may include:
[0142] The synchronization request receiving module 1010 is used to receive the synchronization request sent by the blockchain node to be synchronized, wherein the synchronization request includes the block information to be synchronized, the shard sequence number and the total number of shards; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized;
[0143] A data splitting module 1020 is used to split the data of the synchronization block according to the total number of shards;
[0144] The synchronization data return module 1030 is used to select the corresponding shard data as the block shard data according to the shard sequence number, splice the shard sequence number and the block shard data, and send them to the blockchain node to be synchronized, so that the blockchain node to be synchronized will splice the block shard data in each block data in the order of the shard sequence number to obtain the synchronized block data.
[0145] Regarding the device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment of the method, and will not be elaborated in detail here. The device in the above embodiment may also include other implementation methods according to the description of the method embodiment. The specific implementation method can refer to the description of the relevant method embodiment, and will not be described one by one here.
[0146] Fig.11 is a block diagram of an electronic device for block synchronization provided by an embodiment of this specification. The electronic device may be a terminal, and its internal structure diagram may be as shown in FIG. Fig.11 As shown. The electronic device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a block synchronization method is implemented. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc.
[0147] Fig.12 is a block diagram of another electronic device for block synchronization provided by an embodiment of this specification. The electronic device may be a server, and its internal structure diagram may be as shown in FIG. Fig.12As shown. The electronic device includes a processor, a memory and a network interface connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a block synchronization method is implemented.
[0148] Those skilled in the art will understand that Fig.11 or Fig.12 The structure shown in the figure is merely a block diagram of a portion of the structure related to the embodiment scheme of this specification, and does not constitute a limitation on the electronic device to which the embodiment scheme of this specification is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0149] In an exemplary embodiment, an electronic device is also provided, including: a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the block synchronization method as in the embodiment of the embodiment of this specification.
[0150] In an exemplary embodiment, a computer-readable storage medium is also provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the block synchronization method in the embodiment of the present specification.
[0151] In an exemplary embodiment, a computer program product or a computer program is also provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the block synchronization method provided in the above-mentioned various optional implementations.
[0152] It is understandable that in the specific implementation of the embodiments of this specification, user-related data is involved. When the embodiments above the embodiments of this specification are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0153] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the embodiments of this specification may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0154] Those skilled in the art will readily appreciate other implementations of the embodiments of the present specification after considering the specification and practicing the invention disclosed herein. The embodiments of the present specification are intended to cover any variations, uses, or adaptations of the embodiments of the present specification, which follow the general principles of the embodiments of the present specification and include common knowledge or customary technical means in the art that are not disclosed in the embodiments of the present specification. The description and embodiments are to be considered merely as exemplary, and the true scope and spirit of the embodiments of the present specification are indicated by the claims below.
[0155] It should be understood that the embodiments of the present specification are not limited to the precise structures described above and shown in the drawings, and various modifications and changes may be made without departing from the scope thereof. The scope of the embodiments of the present specification is limited only by the appended claims.
Claims
1. A block synchronization method, characterized in that: The method comprises: Send a synchronization request to at least two target blockchain nodes, wherein the synchronization request includes the block information to be synchronized, the total number of shards, and the shard sequence number corresponding to the target blockchain node, the block height of the target blockchain node is the specified block height; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized; Receive multiple block data returned by each of the target blockchain nodes, wherein the block data includes a shard sequence number and block shard data corresponding to the target blockchain node, and the block shard data is data corresponding to the shard sequence number after the target blockchain node splits the block to be synchronized according to the total number of shards; The block fragment data in the plurality of block data are sequentially spliced according to the order of the fragment sequence numbers in the plurality of block data to obtain synchronized block data.
2. The method according to claim 1, characterized in that: If the blocks to be synchronized are two or more blocks, the method further includes: The synchronization block data is divided according to the arrangement order of each of the blocks to be synchronized in the target blockchain node and the height of each of the blocks to be synchronized, to obtain the block data corresponding to each of the blocks to be synchronized; The block data are stored in sequence according to the arrangement order of the blocks to be synchronized in the target blockchain node.
3. The method according to claim 1, characterized in that The sending of synchronization requests to at least two target blockchain nodes includes: When determining that the own block height is lower than the specified block height, determining at least two target blockchain nodes according to the specified block height; Determine the block information to be synchronized according to its own block list and the received real-time block list; Determine the total number of shards and the shard sequence number corresponding to each target blockchain node according to the number of the target blockchain nodes; The synchronization request is sent to the corresponding target blockchain node according to the block information to be synchronized, the total number of shards, and the shard sequence number corresponding to each target blockchain node.
4. The method according to claim 3, characterized in that Determining the block information to be synchronized according to the own block list and the received real-time block list includes: Determine the synchronization block information based on its own block list and the received real-time block list; The synchronization block information is grouped, and each group of synchronization block information is used as the block information to be synchronized in turn, and the grouping information corresponding to the block information to be synchronized, the block information to be synchronized, the total number of shards, and the shard sequence number corresponding to each target blockchain node are sent to the corresponding target blockchain node as the synchronization request.
5. The method according to claim 4, characterized in that The received block data includes the shard sequence number, grouping information and the block shard data; the block shard data in the plurality of block data are sequentially spliced in the order of the shard sequence numbers in the plurality of block data to obtain synchronized block data, including: According to the grouping information in the plurality of block data, the block fragment data in the plurality of block data belonging to the same group are sequentially spliced in the order of fragment sequence numbers to obtain the synchronous block data.
6. The method according to claim 3, characterized in that Determining the total number of shards and the shard sequence number corresponding to each target blockchain node according to the number of the target blockchain nodes includes: Sort each target blockchain node according to the node ID; The total number of target blockchain nodes is taken as the total number of shards, and the ranking of each target blockchain node is taken as the shard sequence number corresponding to each target blockchain node.
7. The method according to claim 4, characterized in that The step of grouping the synchronization block information and sequentially using each group of synchronization block information as the block information to be synchronized includes: The synchronization block information is grouped, and a first group of synchronization block information is used as the block information to be synchronized according to the order of blocks in the synchronization block information in the target blockchain node, and a synchronization request is sent to the at least two target blockchain nodes; After receiving multiple block data returned by each of the target blockchain nodes, the next set of synchronization block information is used as the block information to be synchronized, and the next synchronization request is sent to the at least two target blockchain nodes until the synchronization of the blocks to be synchronized corresponding to all the synchronization block information is completed.
8. The method according to claim 1, characterized in that The synchronization request also includes: node configuration information, so that each target blockchain node filters the data of the block to be synchronized based on the node configuration information, and obtains the block shard data after splitting the data in the block to be synchronized that meets the node configuration information.
9. A block synchronization method, characterized in that: The method comprises: Receive a synchronization request sent by a blockchain node to be synchronized, wherein the synchronization request includes the block information to be synchronized, the shard sequence number and the total number of shards; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized; Splitting the block to be synchronized according to the total number of shards to obtain multiple shard data; According to the shard sequence number, the corresponding shard data is selected as the block shard data, and the shard sequence number and the block shard data are spliced and sent to the blockchain node to be synchronized, so that the blockchain node to be synchronized will splice the block shard data in each block data in the order of the shard sequence number to obtain the synchronized block data.
10. The method according to claim 9, characterized in that The data splitting of the to-be-synchronized blocks corresponding to the to-be-synchronized block information according to the total number of shards includes: According to the total number of shards and the data size of the block to be synchronized, the block to be synchronized is evenly split to obtain multiple shard data.
11. The method according to claim 9, characterized in that The synchronization request also includes node configuration information of the blockchain node to be synchronized. Before splitting the data of the block to be synchronized corresponding to the block information to be synchronized according to the total number of shards, the method also includes: According to the header information of the block to be synchronized, each block to be synchronized is screened to select common transaction blocks and configuration transaction blocks; Filtering the transaction data in the common transaction block according to the node configuration information, deleting the transaction data that does not conform to the node configuration information, and obtaining a filtered common transaction block; The configuration transaction block and the screening common transaction block are data split according to the total number of shards.
12. A block synchronization device, characterized in that: The device comprises: A synchronization request sending module, used to send a synchronization request to at least two target blockchain nodes, wherein the synchronization request includes the block information to be synchronized, the total number of shards and the shard sequence number corresponding to the target blockchain node, and the block height of the target blockchain node is the specified block height; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the block information to be synchronized; A synchronization data receiving module, used to receive multiple block data returned by each of the target blockchain nodes, wherein the block data includes a sharding sequence number and block sharding data corresponding to the target blockchain node, and the block sharding data is data corresponding to the sharding sequence number after the target blockchain node splits the block to be synchronized according to the total number of shards; The data splicing module is used to splice the block fragment data in the multiple block data in sequence according to the fragment sequence numbers in the multiple block data to obtain synchronized block data.
13. A block synchronization device, characterized in that: The device comprises: A synchronization request receiving module, used to receive a synchronization request sent by a blockchain node to be synchronized, wherein the synchronization request includes information of the block to be synchronized, a shard sequence number, and a total number of shards; the total number of shards is the total number of shards for data splitting of the block to be synchronized corresponding to the information of the block to be synchronized; A data splitting module, used for splitting the data of the block to be synchronized according to the total number of shards; The synchronization data returning module is used to select the corresponding shard data as the block shard data according to the shard sequence number, splice the shard sequence number and the block shard data, and send them to the blockchain node to be synchronized, so that the blockchain node to be synchronized will splice the block shard data in each block data in the order of the shard sequence number to obtain the synchronized block data.
14. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method as described in any one of claims 1-8 or claims 9-11.
15. A computer-readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method of any one of claims 1-8 or claims 9-11.
Citation Information
Cited By
Transaction data synchronous management system and method for multiple payment platforms
CN120450701A
Transaction data synchronization management system and method for multiple payment platforms
CN120450701B
