Block synchronization method, device, electronic device and storage medium
By deploying block cache space on blockchain nodes and processing backward blocks, the problem of backward data in blockchain nodes is solved, synchronization of the blockchain network and efficient utilization of storage resources are achieved, ensuring the normal operation of the nodes. and network flexibility.
Patent Information
- Application Number
- CN202111670006.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2041-12-31
AI Technical Summary
When a blockchain node crashes and restarts or a new node joins, the block data in the distributed ledger will lag behind and cannot participate in the consensus process, affecting the operation of functions and services.
Deploy block cache space on the blockchain node to receive and process backward blocks to ensure node synchronization. The size of the block cache space is related to the node weight factor to achieve hierarchical design of block synchronization tasks and adaptation of storage resources. sexual distribution.
It ensures the normal operation of blockchain node functions, realizes block synchronization in the blockchain network, reduces the waste of storage resources, and improves the flexibility and efficiency of the network.
Smart Images

Figure CN114338724B
Abstract
Description
Technical Field
[0001] The embodiments of this specification belong to the field of blockchain technology, and in particular, relate 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, data blocks are combined into a chain data structure in a sequential manner according to time order, and a distributed ledger that cannot be tampered with or forged is guaranteed by cryptography. Due to the characteristics of decentralization, information cannot be tampered with, and autonomy, blockchain has also received more and more attention and application. In some blockchain networks, some nodes sometimes have the need to implement small-scale transactions to prevent other nodes from obtaining these transactions and related data. Therefore, a blockchain subnet can be further established on the basis of the blockchain mainnet, and both the blockchain mainnet and the blockchain subnet are independent blockchain networks.
[0003] For the blockchain main network or blockchain subnet, the various blockchain nodes contained therein use consensus protocols to ensure the consistency of the distributed ledgers maintained by each of them. However, when a blockchain node crashes and restarts or a new subnet node joins, the block data in the distributed ledger maintained by the blockchain node will lag behind the normal nodes in the blockchain network, and it will be unable to participate in the normal consensus process, affecting the operation of functions and services on the blockchain node. Summary of the invention
[0004] The object of the present invention is to provide a block synchronization method, device, electronic device and storage medium.
[0005] According to a first aspect of one or more embodiments of the present specification, a block synchronization method is proposed, which is applied to a first node device, on which a plurality of blockchain nodes belonging to a plurality of blockchain networks in a blockchain system are deployed, and the first node device maintains a corresponding block cache space for the blockchain nodes deployed by it, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively correlated to the node weight factor of the any blockchain node; the method comprises:
[0006] Receiving a backward block sent to any blockchain node by a normal node in the blockchain network to which any blockchain node belongs, wherein the normal node maintains an actual latest block, and the block height of the backward block is between the local block height of the latest block locally maintained by any blockchain node and the latest block height of the actual latest block;
[0007] Cache the backward block in the block cache space corresponding to any one of the blockchain nodes, so that any one of the blockchain nodes reads and processes the backward block from the block cache space;
[0008] When the backward block is processed by any of the blockchain nodes, the backward block is removed from the block cache space.
[0009] According to a second aspect of one or more embodiments of the present specification, a block synchronization device is proposed, which is applied to a first node device, on which a plurality of blockchain nodes belonging to a plurality of blockchain networks in a blockchain system are deployed, and the first node device maintains a corresponding block cache space for the blockchain nodes deployed by it, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively correlated to the node weight factor of any blockchain node; the device comprises:
[0010] A block receiving unit, configured to receive a backward block sent to any blockchain node by a normal node in the blockchain network to which any blockchain node belongs, wherein the normal node maintains an actual latest block, and the block height of the backward block is between the local block height of the latest block locally maintained by any blockchain node and the latest block height of the actual latest block;
[0011] A block cache unit, configured to cache the backward block to a block cache space corresponding to any one of the blockchain nodes, so that any one of the blockchain nodes reads and processes the backward block from the block cache space;
[0012] The block removal unit is used to remove the backward block from the block cache space when the backward block is processed by any blockchain node.
[0013] According to a third aspect of one or more embodiments of this specification, an electronic device is provided, including:
[0014] processor;
[0015] a memory for storing processor-executable instructions;
[0016] The processor implements the method as described in any one of the first aspects by running the executable instructions.
[0017] According to a fourth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in any one of the first aspects are implemented.
[0018] In the embodiment of this specification, the first node device caches the received backward blocks sent to any blockchain node into the block cache space corresponding to any blockchain node, and any blockchain node reads and processes the backward blocks therefrom, so that the blockchain node deployed on the first node device can obtain its corresponding backward blocks to ensure the normal operation of the functions and services on the blockchain node. At the same time, since the block cache space is positively correlated with the node weight factor of any blockchain node and the storage resources of the first node device are limited, this solution is equivalent to adaptively allocating the storage resources of the first node device, giving priority to the blockchain nodes with larger node weight factors deployed on the first node device to occupy larger block cache space, so that in a blockchain system composed of multiple blockchain networks, the block flow limiting strategies corresponding to blockchain nodes in different blockchain networks are macro-regulated, and the hierarchical design of block synchronization tasks is realized. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0020] Figure 1 This is a schematic diagram of establishing a blockchain subnet based on a blockchain mainnet, provided by an exemplary embodiment.
[0021] Figure 2 It is a flowchart of a block synchronization method provided by an exemplary embodiment.
[0022] Figure 3 It is a schematic diagram of a network topology structure provided by an exemplary embodiment.
[0023] Figure 4 It is a structural schematic diagram of a device provided by an exemplary embodiment.
[0024] Figure 5 It is a block diagram of a block synchronization device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.
[0026] Due to the decentralized nature of the blockchain network, all blockchain nodes in the blockchain network will maintain the same block data, which cannot meet the special needs of some nodes. Taking the alliance chain as an example, all alliance members (i.e., node members within the alliance) can form a blockchain network. All alliance members have corresponding blockchain nodes in the blockchain network, and can obtain all transactions and related data occurring on the blockchain network through the corresponding blockchain nodes. However, in some cases, some alliance members may want to complete some transactions with confidentiality requirements. These alliance members hope that these transactions can be stored on the blockchain or with the help of other advantages of blockchain technology, and can avoid other alliance members from viewing these transactions and related data. Although these alliance members can form a new blockchain network in addition, the establishment method is similar to the above-mentioned blockchain network containing all alliance members, but it takes a lot of resources to establish a new blockchain network from scratch, and both the establishment process of the blockchain network and the configuration process after it is established are very time-consuming. The needs between alliance members are often temporary or have a certain timeliness, so that the newly established blockchain network will soon lose its meaning of existence due to the disappearance of needs, thereby further increasing the chain construction cost of the above-mentioned blockchain network. The needs of alliance members often change, and the alliance members corresponding to each need are often different. Therefore, whenever the alliance members change, it may be necessary to establish a new blockchain network, resulting in a huge waste of resources and time.
[0027] To this end, the established blockchain network can be used as the blockchain main network, and a blockchain subnet can be established on the basis of the blockchain main network. Then, in the above-mentioned alliance chain scenario, alliance members can establish the required blockchain subnet on the basis of the blockchain main network based on their own needs after participating in the blockchain main network. Since the blockchain subnet is established on the basis of the blockchain main network, the process of establishing the blockchain subnet greatly reduces the resources consumed and the time required compared to establishing a completely independent blockchain network, and is extremely flexible.
[0028] The process of quickly establishing a blockchain subnet based on the blockchain main network is as follows: each blockchain node in the blockchain main network respectively obtains a transaction for establishing a blockchain subnet, the transaction includes configuration information of the blockchain subnet, the configuration information includes identity information of node members participating in establishing the blockchain subnet, each blockchain node in the blockchain main network respectively executes the transaction to reveal the configuration information, when the configuration information includes the identity information of the node member corresponding to the first blockchain node, the node device deploying the first blockchain node starts the second blockchain node belonging to the blockchain subnet based on the genesis block including the configuration information.
[0029] by Figure 1 As shown in the example, the blockchain main network is subnet0, and the blockchain nodes contained in subnet0 are nodeA, nodeB, nodeC, nodeD, and nodeE. Assume that nodeA, nodeB, nodeC, and nodeD want to form a blockchain subnet: if nodeA is an administrator and only administrators are allowed to initiate transactions to form a blockchain subnet, then nodeA can initiate the above-mentioned transaction to form a blockchain subnet to subnet0; if nodeE is an administrator and only administrators are allowed to initiate transactions to form a blockchain subnet, then nodeA~nodeD needs to make a request to nodeE so that nodeE initiates the above-mentioned transaction to form a blockchain subnet to subnet0; if nodeE is an administrator but ordinary users are allowed to initiate transactions to form a blockchain subnet, then nodeA~nodeE can all initiate the above-mentioned transaction to form a blockchain subnet to subnet0. Of course, whether it is an administrator or an ordinary user, the blockchain node that initiates the transaction to form a blockchain subnet does not necessarily participate in the formed blockchain subnet. For example, although the blockchain subnet is ultimately formed by nodeA, nodeB, nodeC, and nodeD, nodeE can initiate the above-mentioned transaction to form a blockchain subnet to subnet0, and it is not necessarily nodeA~nodeD that initiate the transaction to form a blockchain subnet.
[0030] When a blockchain subnet is established on the basis of the blockchain mainnet, it is easy to understand that there will be a logical hierarchical relationship between the blockchain subnet and the blockchain mainnet. Figure 1 When the blockchain subnet subnet1 is established on the subnet0 shown in the figure, it can be considered that subnet0 is in the first layer and subnet1 is in the second layer. In one case, the blockchain main network in this specification can be the underlying blockchain network, that is, the blockchain main network is not a blockchain subnet established on the basis of other blockchain networks, for example Figure 1The subnet0 in the example can be considered as the main blockchain network of the underlying blockchain network type. In another case, the main blockchain network in this specification can also be a subnet of other blockchain networks, such as Figure 1 Another blockchain subnet is further established on the basis of subnet1. At this time, subnet1 can be considered as the blockchain mainnet corresponding to the blockchain subnet, and this does not affect the fact that subnet1 also belongs to the blockchain subnet created on subnet0. It can be seen that the blockchain mainnet and the blockchain subnet are actually relative concepts. The same blockchain network can be a blockchain mainnet in some cases and a blockchain subnet in other cases.
[0031] After the transaction for establishing the blockchain subnet is sent to the blockchain main network, it is reached by consensus nodes in the blockchain main network, and after reaching consensus, each main network node executes the transaction to complete the establishment of the blockchain subnet. The consensus process depends on the consensus mechanism adopted, and this manual does not limit this.
[0032] By including configuration information in the transaction of forming a blockchain subnet, the configuration information can be used to configure the formed blockchain subnet so that the formed blockchain subnet meets the networking requirements. For example, by including the identity information of the node members in the configuration information, it is possible to specify which blockchain nodes are included in the formed blockchain subnet.
[0033] The identity information of the node member may include the public key of the node, or other information that can characterize the node identity, such as the node ID, which is not limited in this specification. Taking the public key as an example, each blockchain node has a corresponding one or more sets of public-private key pairs, the blockchain node holds the private key and the public key is made public and uniquely corresponds to the private key, so the identity of the corresponding blockchain node can be characterized by the public key. Therefore, for the blockchain nodes that wish to be node members of the blockchain subnet, the public keys of these blockchain nodes can be added to the transactions of the above-mentioned blockchain subnet formation as the identity information of the above-mentioned node members. The above-mentioned public-private key pairs can be used in the process of signature verification. For example, in a consensus algorithm with a signature, for example, the nodeA1 above subnet1 signs the message with its own private key, and then broadcasts the signed message in subnet1, and nodeB1, nodeC1 and nodeD1 can use the public key of nodeA1 to verify the signature of the received message to confirm that the message received by itself is indeed from nodeA1 and has not been tampered with.
[0034] The first main network node can be a blockchain node on the blockchain main network that is a node member indicated by the configuration information. When forming a blockchain subnet, the first main network node does not directly participate in forming the blockchain subnet and become its node member, but the node device used to deploy the first main network node needs to generate the first subnet node, and the first subnet node becomes a node member in the blockchain subnet. The first main network node and the first subnet node correspond to the same blockchain member, for example, in the alliance chain scenario, they correspond to the same alliance chain member, but the first main network node belongs to the blockchain main network and the first subnet node belongs to the blockchain subnet, so that the blockchain member can participate in the transactions of the blockchain main network and the blockchain subnet respectively; and, since the blockchain main network and the blockchain subnet belong to two independent blockchain networks, the blocks generated by the first main network node and the blocks generated by the first subnet node are respectively stored in different storages on the node devices (the storage used may be, for example, a database), thereby achieving mutual isolation between the storages used by the first main network node and the first subnet node respectively, and thus the data generated by the blockchain subnet will only be synchronized between the node members of the blockchain subnet, so that the blockchain members who only participate in the blockchain main network cannot obtain the data generated on the blockchain subnet, thereby achieving data isolation between the blockchain main network and the blockchain subnet, and meeting the transaction needs between some blockchain members (i.e., blockchain members participating in the blockchain subnet).
[0035] It can be seen that the first main network node and the first subnet node are logically divided blockchain nodes. From the perspective of physical devices, it is equivalent to the node devices that deploy the first main network node and the first subnet node participating in both the blockchain main network and the blockchain subnet. Since the blockchain main network and the blockchain subnet are independent of each other, the identity systems of the two blockchain networks are also independent of each other. Therefore, even if the first main network node and the first subnet node can use exactly the same public key, they should still be regarded as different blockchain nodes. For example, in Figure 1 In the example, nodeA in subnet0 is equivalent to the first main network node, and the node device that deploys nodeA generates nodeA1 belonging to subnet1, which is equivalent to the first subnet node. It can be seen that since the identity systems are independent of each other, even if the public key used by the first subnet node is different from that of the first main network node, it does not affect the implementation of the solution in this specification.
[0036] Of course, the node members of the blockchain subnet are not necessarily only some of the node members of the blockchain main network. In some cases, the node members of the blockchain subnet can be completely consistent with the node members of the blockchain main network. At this time, all blockchain members can obtain data on the blockchain main network and the blockchain subnet, but the data generated by the blockchain main network and the blockchain subnet can still be isolated from each other. For example, one type of business can be implemented on the blockchain main network and another type of business can be implemented on the blockchain subnet, so that the business data generated by these two types of business can be isolated from each other.
[0037] In addition to the identity information of the node members mentioned above, the configuration information may also include at least one of the following: the network identifier of the blockchain subnet, the identity information of the administrator of the blockchain subnet, the attribute configuration for the blockchain platform code, etc., which is not limited in this specification. The network identifier is used to uniquely characterize the blockchain subnet, so the network identifier of the blockchain subnet should be different from the blockchain main network and other blockchain subnets established on the blockchain main network. The identity information of the administrator of the blockchain subnet can be, for example, the public key of the node member who is the administrator; wherein, the administrators of the blockchain main network and the blockchain subnet can be the same or different.
[0038] One of the advantages of forming a blockchain subnet through the blockchain mainnet is that since the first mainnet node has been deployed on the node device that generates the first subnet node, the blockchain platform code used by the first mainnet node can be reused on the first subnet node, eliminating the need for repeated deployment of the blockchain platform code, greatly improving the efficiency of forming the blockchain subnet. Then, if the configuration information does not contain the attribute configuration for the blockchain platform code, the first subnet node can reuse the attribute configuration used on the first mainnet node; if the configuration information contains the attribute configuration for the blockchain platform code, the first subnet node can use the attribute configuration, so that the attribute configuration used by the first subnet node is not limited to the attribute configuration of the first mainnet node and has nothing to do with the first mainnet node. The attribute configuration for the blockchain platform code may include at least one of the following: code version number, whether consensus is required, consensus algorithm type, block size, etc., and this manual does not limit this.
[0039] The transaction for forming a blockchain subnet includes a transaction for calling a contract. The transaction may specify the address of the smart contract being called, the calling method, and the parameters passed in. For example, the called contract may be the aforementioned genesis contract or system contract, the called method may be the method for forming a blockchain subnet, and the parameters passed in may include the aforementioned configuration information. In one embodiment, the transaction may include the following information:
[0040] from:Administrator
[0041] to:Subnet
[0042] method:AddSubnet(string)
[0043] string: genesis
[0044] Among them, the from field is the information of the initiator of the transaction, for example, Administrator indicates that the initiator is the administrator; the to field is the address of the called smart contract, for example, the smart contract can be a Subnet contract, then the to field is specifically the address of the Subnet contract; the method field is the calling method, for example, the method used to form a blockchain subnet in the Subnet contract can be AddSubnet(string), and string is the parameter in the AddSubnet() method. In the above example, the value of the parameter is represented by genesis, and the genesis is specifically the aforementioned configuration information.
[0045] Take the transaction in which nodes nodeA~nodeE on Subnet0 execute the AddSubnet() method in the Subnet contract as an example. After the transaction passes consensus, nodeA~nodeE respectively execute the AddSubnet() method and pass in the configuration information to obtain the corresponding execution results.
[0046] After executing a transaction that calls a smart contract, a node in the blockchain network will generate a corresponding receipt to record information related to the execution of the smart contract. In this way, you can query the transaction receipt to obtain relevant information about the contract execution result. The contract execution result can be expressed as an event in the receipt. The message mechanism can realize message transmission through the event in the receipt to trigger the blockchain node to perform corresponding processing. The structure of the event can be, for example:
[0047] Event:
[0048] [topic][data]
[0049] [topic][data] ......
[0051] In the above example, the number of events can be one or more, wherein each event includes fields such as topic and data. The blockchain node can monitor the topic of the event, and when a predefined topic is monitored, perform a preset process, or read relevant content from the data field of the corresponding event, and perform a preset process based on the read content.
[0052] In the above event mechanism, it is equivalent to having a client with a monitoring function at the listening party (such as a user with a monitoring demand), such as running an SDK for implementing the monitoring function on the client, and the client monitors the events generated by the blockchain node, and the blockchain node only needs to generate receipts normally. In addition to the above event mechanism, the disclosure of transaction information can also be achieved in other ways. For example, the listening code can be embedded in the blockchain platform code running on the blockchain node, so that the listening code can monitor one or more data such as the transaction content of the blockchain transaction, the contract status of the smart contract, and the receipt generated by the contract, and send the monitored data to the predefined listening party. Since the listening code is deployed in the blockchain platform code, rather than at the client of the listening party, this implementation method based on the listening code is relatively more active than the event mechanism. Among them, the above listening code can be added to the blockchain platform code by the developers of the blockchain platform during the development process, or it can be embedded by the listening party based on its own needs, and this specification does not limit this.
[0053] It can be seen that the execution result of the above-mentioned Subnet contract may include the configuration information, and the execution result may be in the receipt mentioned above, which may include an event related to the execution of the AddSubnet() method, that is, a networking event. The topic of the networking event may contain a predefined networking event identifier to distinguish it from other events. For example, in the event related to the execution of the AddSubnet() method, the content of the topic is the keyword subnet, and the keyword is different from the topic in the event generated by other methods. Then, nodeA~nodeE can determine that it has listened to the event related to the execution of the AddSubnet() method, that is, the networking event, by monitoring the topics contained in each event in the generated receipt when it monitors the topic containing the keyword subnet. For example, the event in the receipt is as follows:
[0054] Event:
[0055] [topic:other][data]
[0056] [topic:subnet][data] ......
[0058] Then, when nodeA~nodeE listens to the first event, since the content of the topic is other, it determines that the event is not related to the AddSubnet() method; and when nodeA~nodeE listens to the second event, since the content of the topic is subnet, it determines that the event is related to the AddSubnet() method, and then reads the data field corresponding to the event, which contains the above configuration information. Taking the configuration information including the public key of the node member of the blockchain subnet as an example, the content of the data field may include:
[0059] {subnet1;
[0060] Public key of nodeA, IP address of nodeA, port number of nodeA...;
[0061] nodeB's public key, nodeB's IP, nodeB's port number...;
[0062] Public key of nodeC, IP address of nodeC, port number of nodeC...;
[0063] nodeD's public key, nodeD's IP, nodeD's port number...;
[0064] }
[0065] Among them, subnet1 is the network identifier of the blockchain subnet you want to create. Each blockchain node in the blockchain main network can record the network identifiers of all blockchain subnets that have been created on the blockchain main network, or other information related to these blockchain subnets. This information can be maintained in the above-mentioned Subnet contract, and specifically can correspond to the value of one or more contract states contained in the Subnet contract. Then, nodeA~nodeE can determine whether the above-mentioned subnet1 already exists based on the network identifiers of all the blockchain subnets that have been created; if it does not exist, it means that subnet1 is a new blockchain subnet that needs to be created at present, and if it does exist, it means that subnet1 already exists.
[0066] In addition to using the network identifier of the new blockchain subnet you want to create, you can also use a predefined new network identifier, which indicates that the corresponding networking event is used to form a new blockchain subnet. For example, the above subnet1 can be replaced with newsubnet, which is a predefined new network identifier. When nodeA~nodeE recognizes that the data field contains newsubnet, it can be determined that the event containing newsubnet is a networking event and a new blockchain subnet needs to be created.
[0067] In addition to the network identifier subnet1, the above data field also includes the identity information of each node member and other content. The node device that deploys the first main network node can monitor the generated receipt, and when the networking event is monitored and the content of the networking event indicates that the first main network node belongs to the node member, the node device that deploys the first main network node obtains the configuration information or the genesis block contained in the networking event. Alternatively, the first blockchain node can monitor the generated receipt, and when the networking event is monitored and the content of the networking event indicates that the first blockchain node belongs to the node member, the node device that deploys the first blockchain node is triggered to obtain the configuration information or the genesis block contained in the networking event.
[0068] As mentioned above, the node device can directly monitor the receipt. Assuming that nodeA~nodeE are deployed on node devices 1~5 respectively, node devices 1~5 can monitor the receipts generated by nodeA~nodeE respectively. Then, when it is monitored that subnet1 is a blockchain subnet that needs to be newly formed, node devices 1~5 will further identify the identity information of the node members contained in the data field to determine their own processing methods. Take nodeA and node device 1 as an example: if node device 1 finds that the data field contains the identity information of nodeA, such as the public key, IP address and port number, then node device 1 generates a genesis block containing the configuration information when obtaining the configuration information from the data field based on the above message mechanism, and node device 1 will deploy nodeA1 locally, and then nodeA1 will load the generated genesis block, thereby becoming a subnet node of subnet1; similarly, node device 2 can generate nodeB1, node device 3 can generate nodeC1, and node device 4 can generate nodeD1. Furthermore, node device 5 will find that the identity information contained in the data field does not match itself, then the node device 5 will not generate a genesis block according to the configuration information in the data field, nor will it generate a blockchain node in subnet1.
[0069] As mentioned above, the blockchain nodes in the blockchain main network can monitor receipts and trigger the node devices to perform relevant processing based on the monitoring results. For example, when nodeA~nodeE determines that subnet1 is a newly formed blockchain subnet, it will further identify the identity information of the node members contained in the data field to determine its own processing method. For example, nodeA~nodeD will find that the data field contains its own identity information such as public key, IP address and port number. Assuming that nodeA~nodeD are deployed on node devices 1~4 respectively, taking nodeA and node device 1 as an example: nodeA will trigger node device 1, so that node device 1 obtains configuration information from the data field based on the above message mechanism and generates a genesis block containing the configuration information, and node device 1 will deploy nodeA1 locally, and the nodeA1 will load the generated genesis block, thereby becoming a subnet node in subnet1; similarly, nodeB will trigger node device 2 to generate nodeB1, nodeC will trigger node device 3 to generate nodeC1, and nodeD will trigger node device 4 to generate nodeD1. Also, nodeE will find that the identity information contained in the data field does not match itself. Assuming that nodeE is deployed on node device 5, then node device 5 will not generate a genesis block based on the configuration information in the data field, nor will it generate a node in subnet1.
[0070] As mentioned above, the first main network node and the first subnet node do not necessarily use the same identity information. Therefore, in the above embodiment, the data field may contain identity information pre-generated for nodeA1~nodeD1, and different from the identity information of nodeA~nodeD. Still taking nodeA and node device 1 as an example: if node device 1 finds the identity information of nodeA1 in the data field, it can generate a genesis block, deploy nodeA1, and nodeA1 loads the genesis block; or, if nodeA finds the identity information of nodeA1 in the data field, then nodeA will trigger node device 1 to generate a genesis block, deploy nodeA1, and nodeA1 will load the genesis block. The processing methods of other blockchain nodes or node devices are similar and will not be repeated here.
[0071] In addition to configuration information, the execution result of the contract may include a genesis block. In other words, in addition to including configuration information in the data field, a genesis block containing configuration information can also be generated directly during the execution of the contract call, thereby including the genesis block in the data field. For the above-mentioned nodeA~nodeD, the corresponding node devices 1~4 can obtain the genesis block directly from the data field through the message mechanism without generating it themselves, which can improve the deployment efficiency of nodeA1~nodeD1.
[0072] The node device deploys a blockchain node on the node device by creating an instance running the blockchain platform code in the process. For the first main network node, the node device creates a first instance in the above process, and the first instance runs the blockchain platform code. Similarly, for the first subnet node, the node device creates a second instance different from the first instance in the above process, and the second instance runs the blockchain platform code. For example, the node device can first create a first instance in the process to form the first blockchain node in the blockchain main network; and when the node member corresponding to the node device wants to participate in the formation of the blockchain subnet, a second instance can be created in the above process, the second instance is different from the above first instance, and the second instance forms the second blockchain node in the blockchain subnet. When the first instance and the second instance are in the same process, since there is no cross-process interaction involved, the deployment difficulty of the first subnet node can be reduced and the deployment efficiency can be improved; of course, the second instance may also be in different processes on the node device from the first instance, and this specification does not limit this; for example, the node device can create a first instance in the first process to form a first blockchain node in the blockchain main network; and when the node member corresponding to the node device wants to participate in the formation of a blockchain subnet, it can start a second process different from the first process, and create a second instance in the second process, which is different from the above-mentioned first instance, and then the second instance forms the second blockchain node in the blockchain subnet. In fact, each blockchain node deployed on any node device involved in the embodiments of this specification is a different blockchain instance running on any node device, and the blocks generated by each blockchain node deployed on any node device are respectively stored in different storages (such as databases) on any node device, and the storages used by each blockchain node deployed by any node device are isolated from each other.
[0073] Through the above method, a blockchain subnet can be created on the blockchain mainnet. Figure 1For example, subnet0 originally includes nodeA~nodeE, and subnet1 can be built on the basis of subnet0, which includes nodeA1~nodeD1, and nodeA and nodeA1, nodeB and nodeB1, nodeC and nodeC1, nodeD and nodeD1 are deployed on the same node device. Similarly, subnet2 or more blockchain subnets can be built on subnet0, where subnet2 includes nodeA2, nodeB2, nodeC2 and nodeE2, and nodeA and nodeA1, nodeA2, nodeB and nodeB1, nodeB2, nodeC, nodeC1 and nodeC2, nodeD and nodeD1, nodeE and nodeE2 are deployed on the same node device. In addition, subnet1, subnet2, etc. can be used as new blockchain main networks, and blockchain subnets can be further built on this basis. The process is similar to the formation of subnet1 or subnet2, and will not be repeated here. It can be seen that the above-mentioned method of initiating transactions on the blockchain main network to select node members to create a blockchain subnet can make the subnet nodes of the newly created blockchain subnet deployed on the node device where the main network node of the blockchain main network is located. That is, from the perspective of the node device, the node device where the subnet node of the blockchain subnet is located belongs to a subset of the node device where the main network node is located. In other words, the main network node of the blockchain main network is deployed on the node device where the subnet node of the blockchain subnet is deployed.
[0074] In addition to the above-mentioned method of initiating transactions on the blockchain main network to select node members to create a blockchain subnet, other means can also be used to create a blockchain subnet and make it managed by the blockchain main network. For example, a blockchain subnet can be established on the blockchain main network through registration (hereinafter referred to as the registration networking method), and the existing blockchain network can be directly registered to the blockchain main network, so that the newly registered blockchain network is managed by the blockchain main network, thereby making the newly registered blockchain network a blockchain subnet of the blockchain main network. Through the registration networking method, the subnet information of the blockchain subnet to be established is directly registered to the blockchain main network, so that the blockchain main network obtains the relevant information of the blockchain subnet to be established (by receiving and executing the transaction sent by the blockchain network to be established, which is used to associate its identity information with the subnet identifier assigned to the blockchain network to be established), such as the subnet identifier and operating status of the blockchain subnet to be established, including the public key and plug-in configuration information of each node member, the IP address and port information of each node device, etc. This information will be written into the contract status of the system contract corresponding to the blockchain main network. As a result, the blockchain main network will obtain the management rights of the blockchain subnet to be established. After the registration is completed, it means that the blockchain subnet is established. Since the registration networking method does not require the node members to be specified on the blockchain main network through transactions to constitute the blockchain subnet, the subnet nodes in the blockchain subnet established by the registration networking method can be completely different or partially different from the node devices deployed in each node in the blockchain main network. For example Figure 1 In the subnet0, a subnet4 is created by registering the network. Figure 1 (not shown), assuming that the main network nodes nodeA~nodeE contained in subnet0 are deployed on node devices 1~5 respectively, then the subnet nodes corresponding to subnet4 can be deployed on any other node devices except node devices 1~5, or, one or more subnet nodes in subnet4 are deployed on any node devices in node devices 1~5 respectively (but it is still necessary to ensure that only one subnet node in subnet4 is deployed on a node device), and the other subnet nodes in subnet4 are deployed on any other node devices except node devices 1~5. Of course, the subnet nodes in subnet4 can also be deployed in node devices 1~5.
[0075] like Figure 1As shown, for any blockchain network (referred to as the first blockchain network) in the blockchain system composed of the blockchain main network and the blockchain subnets it manages, each blockchain node contained therein independently maintains a distributed ledger composed of several blocks connected in sequence, and each block has a corresponding block height to indicate the relative position of the block in the distributed ledger. For example, the block with the largest current block height maintained by a blockchain node is the block that the blockchain node has most recently reached consensus or synchronization with. In addition, with the initiation, consensus, and execution of transactions in the first blockchain network, new blocks will continue to be generated and updated to the distributed ledgers maintained by these blockchain nodes.
[0076] Under normal circumstances, each blockchain node in the first blockchain network will continuously update the distributed ledger maintained by itself in accordance with the consensus protocol, so that the distributed ledger maintained by each blockchain node is strictly consistent, but when the blockchain node crashes and restarts or a new blockchain node joins, it will inevitably cause the blocks in the distributed ledger maintained by some blockchain nodes to lag behind other blockchain nodes in the first blockchain network, that is, the block height of the local latest block maintained by these blockchain nodes lags behind the block height of the actual latest block in the first blockchain network. In the embodiment of this specification, the block height of the local latest block is referred to as the local block height, the block height of the actual latest block is referred to as the latest block height, and the blockchain node in the first blockchain network whose local block height of the local latest block is maintained behind the latest block height is referred to as a lagging node, and the blockchain node in the first blockchain network whose local block height of the local latest block maintained is the same as the latest block height is referred to as a normal node.
[0077] Since blocks need to be integrated and updated into the distributed ledger in order, lagging nodes cannot participate in the consensus and processing of the actual latest blocks in the first blockchain network like normal nodes, that is, they cannot participate in the normal consensus process, which affects the operation of functions and services on the lagging nodes and even the entire first blockchain network. Therefore, how to enable lagging nodes to obtain the blocks they are lagging behind as soon as possible to complete the block chasing process is an urgent problem to be solved in this scenario.
[0078] To solve this problem, this specification proposes a block synchronization method, in which the first node device allocates corresponding block cache space to the blockchain nodes deployed by it, and the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively correlated to the node weight factor of any blockchain node. In this way, in a blockchain system composed of multiple blockchain networks, the block flow limiting strategies corresponding to blockchain nodes in different blockchain networks are macro-controlled, thereby realizing a hierarchical design of block synchronization tasks.
[0079] Combine the following Figure 2 The block synchronization method involved in this specification is described in detail. Figure 2 This is a flowchart of a block synchronization method provided by an exemplary embodiment. The method is applied to a first node device, on which multiple blockchain nodes belonging to multiple blockchain networks in a blockchain system are deployed, and the first node device maintains corresponding block cache space for the blockchain nodes deployed by it, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively correlated to the node weight factor of any blockchain node; the method includes:
[0080] S202: Receive a backward block sent to any blockchain node by a normal node in the blockchain network to which any blockchain node belongs, wherein the normal node maintains an actual latest block, and the block height of the backward block is between the local block height of the latest block locally maintained by any blockchain node and the latest block height of the actual latest block.
[0081] S204: Cache the backward block to the block cache space corresponding to any blockchain node, so that any blockchain node reads and processes the backward block from the block cache space.
[0082] In the embodiments of this specification, a node device is a hardware entity for running a blockchain node, and a blockchain node refers to a software process running in a node device. The blockchain system involved in the embodiments of this specification refers to a blockchain system composed of multiple blockchain networks, such as the aforementioned blockchain system composed of a blockchain main network and a blockchain subnet managed by it. The characteristic of the blockchain system is that there are multiple blockchain nodes deployed simultaneously in the node devices involved, and the block synchronization scheme involved in this specification is being applied to the first node device where multiple blockchain nodes belonging to multiple blockchain networks are deployed.
[0083] Any blockchain node involved in the embodiments of this specification belongs to a backward node, and after receiving the backward block, the backward node will process it in order from low to high block height, and the processing here may include: verifying the legitimacy of the block through the block header of the block, reading the transactions contained in the block body of the block and executing these transactions in order, and finally adding the block to the end of the distributed ledger maintained by the backward node to complete the block chain process. Therefore, the processing of the received backward blocks by any blockchain node needs to be executed one by one in a certain order and it will take a certain amount of time to process each block. If the first node device directly forwards the backward block to any blockchain node when receiving the backward block sent to any blockchain node deployed thereon, then in the case where the backward block contains multiple or any blockchain node is still processing the previous block, these backward blocks forwarded to any blockchain node will be discarded by any blockchain node due to the limitations of the block processing mechanism of any blockchain node. Therefore, in the embodiments of the present specification, the first node device will allocate a corresponding block cache space to each blockchain node deployed locally, wherein the block cache space corresponding to any blockchain node is used to temporarily store backward blocks to be forwarded to any blockchain node for processing, so that any blockchain node can read and process the backward blocks currently required to be executed from the block cache space according to its own processing progress for the backward blocks, thereby preventing the backward blocks from being discarded due to the blockchain node not having enough time to process them.
[0084] The storage space corresponding to the block cache space involved in the embodiments of this specification may include memory space and / or hard disk space. However, no matter which type of storage space, the first node device, as a hardware entity, contains limited storage space. Therefore, in order to be able to perform a hierarchical design for the block synchronization tasks of multiple blockchain nodes deployed on the first node device, the embodiments of this specification propose to maintain block cache spaces of different sizes for multiple blockchain nodes deployed on the first node device according to the node weight factor, so that the size of the block cache space corresponding to any blockchain node is positively correlated to the node weight factor of any blockchain node, thereby realizing adaptive allocation of storage resources of the first node device.
[0085] The first node device first receives the block message, parses it to obtain the source communication address and destination communication address corresponding to the block message, which are the normal node and any blockchain node respectively, and then extracts the backward block from the block message and caches it to the block cache space corresponding to any blockchain node.
[0086] As mentioned above, the local block height of the local latest block maintained by the lagging node is less than the latest block height of the actual latest block, which means that when the first blockchain node detects that it is a lagging node, the first blockchain node does not maintain the actual latest block, and the block that the first blockchain node lacks compared to the normal nodes of the same period is called a lagging block, and the block height allowed for the lagging block is between the local block height of the latest block (i.e., the local latest block) maintained locally by the lagging node and the latest block height, and the lagging block includes the actual latest block but does not include the local latest block.
[0087] The size of the block cache space corresponding to any blockchain node deployed by the first node device is positively correlated with the node weight factor of any blockchain node, specifically: the first node device determines the size of the block cache space corresponding to any blockchain node as the product of a fixed storage size (usually referring to the storage upper limit for storing blocks in the first node device) and the node weight factor of any blockchain node. In one embodiment, if the size of the block cache space of any blockchain node determined by the first node device exceeds the product of the number of backward blocks of any blockchain node and the average size of a single block, it means that the size of the block cache space is too large. At this time, the size of the block cache space of any blockchain node can be re-determined as the product of the number of backward blocks and the average size of a single block, wherein the number of backward blocks of any blockchain node is the difference between the latest block height maintained by the blockchain network to which any blockchain node belongs and the local block height of the latest local block maintained by any blockchain node.
[0088] In addition, the size of the block cache space may be set with upper and lower bounds to constrain the size of the block cache space within a reasonable range.
[0089] Optionally, the node weight factor of any blockchain node includes: the ratio of the node cache weight of any blockchain node to the sum of the node cache weights of the multiple blockchain nodes.
[0090] The first node device can use a variety of methods to determine the node weight factor of any blockchain node it deploys. In one embodiment, the node weight factor of any blockchain node can be determined as the ratio of the node cache weight corresponding to any blockchain node to the sum of the node cache weights of all blockchain nodes deployed on the first node device. In the embodiment of the present specification, the first node device is deployed with the multiple blockchain nodes, and the first node device maintains a node cache weight list, which records the node cache weights corresponding to the multiple blockchain nodes locally deployed by the first node device. Then, when the first node device needs to calculate the node weight factor of any blockchain node deployed locally, it only needs to divide the node cache weight corresponding to any blockchain node by the sum of the node cache weights of all locally deployed blockchain nodes. Figure 1 For example, the first node device is node device 1, then the node cache weight list maintained by node device 1 includes the node cache weights corresponding to nodeA, nodeA1 and nodeA2 deployed by node device 1, for example, the node cache weight of nodeA is 1, the node cache weight of nodeA1 is 2, and the node cache weight of nodeA2 is 3, then the node weight factor of nodeA1 that can be calculated by node device 1 is 2 / (1+2+3)=1 / 3. Since the storage resources of the node device are limited, in the embodiments of this specification, it can be ensured that the sum of the node weight factors of all blockchain nodes on the first node device has an upper bound to adapt to the storage limit that the first node device can support in the block synchronization task, and prevent the total size of the allocated block cache space from exceeding the storage resource limit of the first blockchain node when all blockchain nodes on the first node device are backward nodes.
[0091] In another embodiment, the first node device may also determine the node weight factor corresponding to any blockchain node as the ratio of the node cache weight corresponding to any blockchain node to the sum of the node cache weights of all blockchain nodes deployed on the first node device that are in a backward state. In the embodiment of this specification, when calculating the node weight factor corresponding to any blockchain node, only the node cache weight of any blockchain node and the node cache weight of the backward nodes deployed on the first node device in the respective blockchain network need to be considered. Figure 1For example, if the first node device is node device 1, then the node cache weight list maintained by node device 1 includes the node cache weights corresponding to nodeA, nodeA1 and nodeA2 deployed by node device 1. If nodeA currently belongs to a normal node in subnet0 and does not need to chase blocks (block synchronization), while nodeA1 and nodeA2 are both backward nodes in their respective subnet1 and subnet2 and need to chase blocks, then the node weight factor of nodeA1 calculated at this time is 2 / (2+3)=0.4. In the embodiment of this specification, when there are blockchain nodes that do not need to chase blocks in the first node device, the block cache space of the blockchain nodes that need to chase blocks in the first blockchain node can be increased, thereby dynamically maintaining the size of the block cache space of each blockchain node deployed in the first node device, and making the best use of the upper limit of storage resources that the first node device can support in the block synchronization task.
[0092] The node cache weight corresponding to each blockchain node in the node cache weight list maintained by the first node device may be the network weight corresponding to the blockchain network to which the respective blockchain node belongs, and the network weight corresponding to each blockchain network may be recorded in the subnet management contract of the blockchain main network and obtained by the first node device reading the locally deployed main network node. Figure 1For example, if the first node device is node device 1, node device 1 can obtain the network weights of the blockchain main network and each blockchain subnet managed by it from the locally deployed main network node nodeA, for example, the network weight of subnet0 is 1, the network weight of subnet1 is 2, and the network weight of subnet2 is 3, then node device 1 will further allocate and specify node cache weights for the blockchain nodes deployed by itself, specify the node cache weight of nodeA as the network weight of the blockchain network subnet0 to which nodeA belongs, specify the node cache weight of nodeA1 as the network weight of the blockchain network subnet1 to which nodeA1 belongs, and indicate the node cache weight of nodeA2 as the network weight of subnet2, and finally record these node cache weights in the locally maintained node cache weight list. In this way, it is equivalent to combining the macro-control of the network level with the macro-control of the node level for the block cache space, so that the maintenance strategy of the block cache space of the blockchain system finally realized can not only realize the unified control of multiple blockchain nodes at the network level, but also make differentiated local optimization on different node devices to meet the specific conditions of the storage resources of different node devices. Of course, the network weight of any blockchain network can also be recorded in the smart contract of any blockchain network, and the first node device obtains the network weight through the blockchain node in any blockchain network deployed locally. In one embodiment, the node weight factor corresponding to any blockchain node can also be directly determined as the network weight of the blockchain network to which the any blockchain node belongs.
[0093] S206: When the backward block is processed by any of the blockchain nodes, remove the backward block from the block cache space.
[0094] After the first node device caches the received lagging blocks into the block cache space corresponding to any of the blockchain nodes, the first blockchain node will read and process the blocks from the block cache space on its own. Each time a block is processed, the first node device will be notified to remove the processed block from the block cache space to make room for more blocks.
[0095] In the embodiment of this specification, the first node device caches the received backward blocks sent to any blockchain node into the block cache space corresponding to any blockchain node, and any blockchain node reads and processes the backward blocks therefrom, so that the blockchain node deployed on the first node device can obtain its corresponding backward blocks to ensure the normal operation of the functions and services on the blockchain node. At the same time, since the block cache space is positively correlated with the node weight factor of any blockchain node and the storage resources of the first node device are limited, this solution is equivalent to adaptively allocating the storage resources of the first node device, giving priority to the blockchain nodes with larger node weight factors deployed on the first node device to occupy larger block cache space, so that in a blockchain system composed of multiple blockchain networks, the block flow limiting strategies corresponding to blockchain nodes in different blockchain networks are macro-regulated, and the hierarchical design of block synchronization tasks is realized.
[0096] Optionally, the size of the block cache space is also positively correlated to the degree of lag between the local block height and the latest block height.
[0097] For example, the first node device may first multiply the node weight factor of any locally deployed blockchain node by the lagging factor to obtain a comprehensive factor corresponding to the any blockchain node, and calculate the ratio of the comprehensive factor of the any blockchain node to the sum of the comprehensive factors of all blockchain nodes, and finally determine the product of the ratio and the fixed storage size as the size of the block cache space corresponding to the any blockchain node, wherein the lagging factor corresponding to the any blockchain node is determined as the ratio of the number of lagging blocks of the any blockchain node to the sum of the number of lagging blocks of all blockchain nodes deployed on the first node device that are in a block lagging state, wherein the number of lagging blocks of any blockchain node is the difference between the latest block height maintained by the blockchain network to which the any blockchain node belongs and the local block height of the latest local block maintained by the any blockchain node.
[0098] Since the size of the block cache space is positively correlated to the lag between the local block height and the latest block height of the actual latest block of any blockchain network, the greater the lag of any blockchain node (i.e., the lag between the local block height of any blockchain node and the latest block height), the larger its block cache space is, which means that when the lag of any blockchain node is large, its corresponding block cache space is also large, and as any blockchain node slowly synchronizes blocks, its lag gradually decreases, and its corresponding block cache space will also slowly decrease. Therefore, the control of the block cache space in this scheme is equivalent to distinguishing the size of the block cache space of backward nodes with different lag levels, allowing backward nodes with larger lag levels, i.e., larger block synchronization requirements, to occupy larger block cache spaces, reducing the restrictions of the block current limiting strategy on them, thereby completing the block chasing process faster, so that each backward node can complete a more balanced synchronization block chasing, and realize a more intelligent dynamic block synchronization strategy.
[0099] Optionally, it also includes: receiving a block synchronization request for the lagging block periodically sent by any blockchain node according to a dynamic request period when the local block height lags behind the latest block height, and forwarding the block synchronization request to the normal node; wherein the dynamic request period is negatively correlated to the degree of lag between the latest block height and the local block height.
[0100] In the embodiments of this specification, any blockchain node deployed on the first node device will detect whether it is a backward node in the blockchain network to which it belongs. Once it is detected that it is a backward node, it will periodically send block synchronization requests to normal nodes in the blockchain network where any blockchain node is located according to the dynamic request cycle, in order to obtain backward blocks that lag behind itself and complete the block chasing process. Therefore, the backward blocks received by the first node device and sent to any blockchain node by normal nodes in the blockchain network of any blockchain node are actually determined by the normal node in response to the block synchronization request previously issued by any blockchain node.
[0101] The following takes the first blockchain node in the first blockchain network deployed on the first node device as an example to illustrate the method for the blockchain node involved in the embodiment of this specification to periodically send a block synchronization request. The method is applied to the first blockchain node. The first blockchain node dynamically maintains the local block height of the local latest block and the dynamic request cycle. The dynamic request cycle is negatively correlated to the degree of lag between the local block height and the latest block height of the actual latest block of the first blockchain network; the method includes:
[0102] Step A: When the local block height lags behind the latest block height, a block synchronization request for the lagging block is periodically sent to a normal node in the first blockchain network that maintains the actual latest block according to the dynamic request period, wherein the block height of the lagging block is between the local block height and the latest block height.
[0103] Step B: Receive the backward block returned by the normal node in response to the block synchronization request to re-determine the local latest block and the dynamic request period.
[0104] The first blockchain node involved in the embodiments of this specification sends a block synchronization request to the normal node, which is essentially sent by the first blockchain node to the first node device first, and then forwarded by the first node device to the normal node; similarly, the lagging block returned by the normal node and received by the first blockchain node is actually first received by the first node device and cached in the block cache space corresponding to the first blockchain node, and then read and received by the first blockchain node from the block cache space.
[0105] The actual latest block in the first blockchain network involved in the embodiments of this specification refers to the block height of the block that has been most recently agreed upon by the first blockchain network. Since the block will be processed by all normal nodes (execute transactions in the block) after consensus and updated to the distributed ledger maintained by them, the actual latest block in the first blockchain network is also equivalent to the block with the largest block height among the blocks maintained by each blockchain node in the first blockchain network.
[0106] Since normal nodes may also become backward nodes, any blockchain node in the first blockchain network will periodically inquire other blockchain nodes about the block height of the latest block maintained locally. Once it is found that the local block height maintained by itself is less than the block height of the latest block maintained by other blockchain nodes, it is considered to be a backward node. Conversely, if it is found that the local block height maintained by itself is greater than or equal to the block height of the latest block maintained by other blockchain nodes, it is considered to be a normal node.
[0107] The local latest block involved in the embodiment of this specification is the latest block obtained by the first blockchain node through consensus or block synchronization and maintained locally. When the first blockchain node detects that the local block height lags behind the latest block height (the local block height is less than the latest block height), it determines that it belongs to a lagging node, so it will start to periodically send block synchronization requests to normal nodes in order to obtain lagging blocks. The above-mentioned periodic block synchronization request period is the dynamic request period maintained on the first blockchain node. The dynamic request period is negatively related to the degree of lag between the local block height and the latest block height of the actual latest block of the first blockchain network, which means that the dynamic request period will change with the change of the local block height or the latest block height. For example, each time the first blockchain node synchronizes a new lagging block, the local latest block it maintains will send changes, so the degree of lag between the local block height and the latest block height will also send changes. At this time, the first blockchain node also needs to synchronize and update the dynamic request period maintained locally.
[0108] Since the dynamic request cycle is negatively correlated with the degree of lag between the local block height and the latest block height of the actual latest block of the first blockchain network, the greater the lag of the first blockchain node (i.e., the lag between the local block height of the first blockchain node and the latest block height), the shorter its dynamic request cycle is, which means that when the lag is large, the number of times the first blockchain node sends block synchronization requests to normal nodes per unit time (valid request number) will be more frequent, and as the first blockchain node slowly synchronizes blocks, its lag gradually decreases, and its valid request number will slowly decrease. Since the number of block requests corresponding to the block synchronization request often has an upper limit, this means that a single block synchronization request generally cannot directly complete the block chasing process. Therefore, the control of the valid request number in this scheme is equivalent to distinguishing the block synchronization rates of backward nodes with different degrees of lag, allowing backward nodes with larger lag, i.e., larger block synchronization requirements, to complete block synchronization faster, thereby reducing the proportion of backward nodes with larger lag in the first blockchain network as a whole, so that backward nodes can complete more balanced synchronization and block chasing, and realize a more intelligent dynamic block synchronization strategy.
[0109] Optionally, the dynamic request cycle is also negatively correlated to the node weight factor of any blockchain node. Assuming that any blockchain node is the first blockchain node, its corresponding node weight factor is the first node weight factor. Since the dynamic request cycle is also negatively correlated to the size of the first node weight factor corresponding to the first blockchain node, the block synchronization rate of the first blockchain node can also be adjusted in the weight dimension. For example, the first node weight factor can be recorded in the contract status of the smart contract in the first blockchain network, and the smart contract can be called by the administrator or other users of the first blockchain network to update the first node weight factor, which enables the first blockchain node to dynamically adjust its own dynamic request cycle by reading the size of the first node weight factor that is continuously updated on the smart contract. Since the smart contract will be deployed on each blockchain node in the first blockchain network, this means that the node weight factor corresponding to each blockchain node in the first blockchain network is the same, that is, the macro-control of the dynamic request cycle at the network level is realized.
[0110] For another example, the first node weight factor is provided by the first node device where the first blockchain node is located. In this case, the first node device calculates the first node weight factor corresponding to the first blockchain node by referring to its local deployment of blockchain nodes. The calculation process has been introduced in the aforementioned embodiment and will not be repeated here. After calculating the first node weight factor, the first node device provides it to the first blockchain node, so that the first blockchain node can dynamically adjust its own dynamic request cycle through the size of the first node weight factor continuously updated by the first node device, thereby realizing macro-control of the dynamic request cycle at the node level.
[0111] The block synchronization request involved in the embodiments of the present specification may include the identity information of the first blockchain node, the source communication address, the destination communication address and the block range of the backward blocks to be requested. The block range is determined by the block height. For example, the local block height maintained by the first blockchain node is 1500, and the actual latest block height is 2000. The upper limit of the number of block requests corresponding to a single block synchronization request is 100. Then, the block range of the backward blocks carried in the block synchronization request sent by the first blockchain node to the normal node can be (1500, 1600], which is used to indicate that 100 blocks with block heights from 1501 to 1600 are requested from the normal node. Of course, it can also be (1500, 1550] or (1900, 2000]. In particular, when the block range of the backward blocks requested by the first blockchain node does not start continuously from the local block height, for example, in the above example, The block synchronization request indicates a block range of (1900, 2000]. At this time, the first blockchain node will receive 100 blocks with block heights from 1901 to 2000. However, since the update of the distributed ledger needs to be completed in the order of block heights, the first blockchain node cannot complete the update of the distributed ledger even if it receives the above 100 blocks. In this case, the first blockchain node often requests other multiple normal nodes for backward blocks with a block range of (1500, 1900]. Therefore, after receiving 399 blocks with block heights from 1501 to 1900 returned by other normal nodes, the first blockchain node first processes and chains these 399 blocks (block chaining means updating blocks to the distributed ledger), and then processes and chains the 100 blocks received previously, thereby completing the block chasing process faster by requesting multiple normal nodes.
[0112] In the embodiment of the present specification, when the first blockchain node in the first blockchain network detects that the block maintained by itself is behind, it periodically sends a block synchronization request for the behind-the-back block to the normal node in the first blockchain network that maintains the actual latest block according to the dynamic request cycle, so that the first blockchain node can obtain its corresponding behind-the-back block to ensure the normal operation of the functions and services on the first blockchain node. At the same time, since the dynamic request cycle is negatively correlated with the degree of backwardness between the local block height and the latest block height of the actual latest block of the first blockchain network, the number of valid requests per unit time for the backward node with a larger degree of backwardness is greater, which enables the backward node with a larger degree of backwardness to complete the block chasing process faster. Since the block synchronization request needs to consume computing resources when being responded to by the normal node, and the network bandwidth resources will also be occupied when the backward block is returned, and the number and computing resources of the normal nodes in the first blockchain network, as well as the network bandwidth resources of the first blockchain network are limited, this scheme is equivalent to giving priority to the backward nodes with a larger degree of backwardness to occupy more computing resources of the normal nodes and the network bandwidth resources of the first blockchain network, that is, the computing resources of the normal nodes and the network bandwidth resources of the first blockchain network are reasonably allocated.
[0113] Furthermore, if the dynamic request cycle is also affected by the weight factor of the first node, then the block synchronization rate of different blockchain nodes can be macro-controlled, realizing the hierarchical design of block synchronization tasks.
[0114] Optionally, the dynamic request period is determined by:
[0115] Find the lagging interval corresponding to the lagging degree, and determine the dynamic request period as the value corresponding to the lagging interval; or, find the lagging interval corresponding to the lagging degree, and determine the dynamic request period as the ratio of the value corresponding to the lagging interval to the first node weight factor. In the embodiment of this specification, the dynamic request period will be determined according to the lagging interval corresponding to the lagging degree. Specifically, different lagging intervals can find the corresponding standard request period, and the dynamic request period is equal to the standard request period; or, when the dynamic request period is also negatively correlated with the node weight factor of any blockchain node, the dynamic request period is equal to the ratio of the found standard request period to the first node weight factor. For example, when the lagging degree is specifically the difference between the local block height and the latest block height (i.e., the number of lagging blocks), the relationship between the standard request period and the number of lagging blocks is shown in Table 1:
[0116] Standard request cycle (unit: milliseconds) Number of lagging blocks (unit: pieces) 1000 0~100 500 101~1000 200 >1000
[0117] Table 1
[0118] It can be seen from Table 1 that when the number of lagging blocks is in the interval of 0 to 100 (including both ends), the standard request period corresponding to the interval can be found to be 1000ms. Assuming that the influence of the first node weight factor is considered and the value of the first node weight factor is 2, the dynamic request period can be determined to be 500ms; similarly, when the number of lagging blocks is in the interval of 101 to 1000, the standard request period is first found to be 500ms, and then it is divided by the first node weight factor to obtain a dynamic request period of 250ms; when the number of lagging blocks exceeds 1000, the standard request period is found to be 200ms, and then the dynamic request period is further determined to be 100ms. It can be seen that, overall, the larger the number of lagging blocks, the smaller the dynamic request period, that is, the dynamic request period is negatively correlated with the degree of lagging, and at the same time.
[0119] Alternatively, the dynamic request period is determined by: determining the dynamic request period as the product of a fixed request period and a lag factor corresponding to the lag degree; or, when the dynamic request period is also negatively correlated with a node weight factor of any blockchain node, determining the dynamic request period as the ratio of the product to the first node weight factor.
[0120] In the embodiments of the present specification, the dynamic request period needs to be obtained through the calculation formula: dynamic request period P = P0×f or P = P0×f / d, where P0 represents a fixed request period, which is specified by the administrator and will not change until it is modified and serves as a fixed value, f represents the lag factor, which is positively correlated to the degree of lag, and d represents the first node weight factor.
[0121] The lagging factor includes: the maximum number of blocks allowed to be requested by the block synchronization request at a time divided by the difference between the local block height and the latest block height; or the ratio of the local block height to the latest block height.
[0122] For example, f=M / (Hn-Hl), where M represents the maximum number of blocks allowed for a single block synchronization request (the upper limit of the number of block requests), Hn represents the latest block height, and Hl represents the local block height. In the embodiment of this specification, the degree of lag of the first blockchain node is specifically the difference between the local block height and the latest block height. Obviously, the larger the number of lagging blocks (that is, the larger Hn-Hl), the smaller the lag factor f, and the smaller the dynamic request period P, that is, the dynamic request period is negatively correlated to the degree of lag.
[0123] For another example, f=H1 / Hn. In the embodiment of this specification, the degree of lag of the first blockchain node is specifically the ratio between the local block height and the latest block height. Obviously, the greater the degree of lag, the smaller the lag factor f, and the smaller the dynamic request period P. The dynamic request period is also negatively correlated with the degree of lag.
[0124] Optionally, the lag factor is provided with an upper factor bound and / or a lower factor bound, the upper factor bound is used to redefine the lag factor as the upper factor bound when the lag factor exceeds the upper factor bound, and the lower factor bound is used to redefine the lag factor as the lower factor bound when the lag factor is lower than the lower factor bound. In the embodiment of this specification, the value range of the above-mentioned lag factor is restricted, thereby indirectly restricting the value range of the dynamic request period so that it meets the actual requirements of the block synchronization task. For example, in the case of f=M / (Hn-Hl), if the difference between the local block height and the latest block height does not exceed the maximum number of blocks allowed for a single block synchronization request, then the f determined by the first blockchain node may be too large, resulting in the dynamic request period P finally determined to be too large, and thus the block chasing process cannot be completed normally. In order to avoid this situation, a factor upper bound of 1 can be set for f. In this way, when the difference between the local block height and the latest block height does not exceed the maximum number of blocks allowed for a single block synchronization request, although the f calculated by the first blockchain node is greater than 1, it will be re-determined to 1 due to the effect of the factor upper bound, thus ensuring that the dynamic request period has a reasonable maximum value to ensure that the lagging node can complete the block chasing process normally.
[0125] Optionally, the dynamic request period is provided with an upper period limit and / or a lower period limit, the upper period limit is used to redefine the dynamic request period as the upper period limit when the dynamic request period exceeds the upper period limit, and the lower period limit is used to redefine the dynamic request period as the lower period limit when the dynamic request period is lower than the lower period limit. As mentioned above, the range of the dynamic request period can be indirectly limited by limiting the value range of the lag factor, and in the embodiments of this specification, the range of the dynamic request period can also be directly limited to meet the actual requirements of the block synchronization task.
[0126] Optionally, the cycle upper bound includes a fixed cycle upper bound or a dynamic cycle upper bound, and the cycle lower bound includes a fixed cycle lower bound or a dynamic cycle lower bound. Among them, the dynamic cycle upper bound includes: the ratio of the maximum number of blocks allowed to be requested by the block synchronization request at a single time to the block growth rate of the first blockchain network; the dynamic cycle lower bound includes: the difference between the number of blocks required to be requested by the block synchronization request and the maximum number of blocks currently remaining in the block cache space corresponding to the first blockchain node divided by the local block processing speed. In the embodiments of this specification, the cycle upper bound and / or cycle lower bound can be set to a fixed value, referred to as a fixed cycle upper bound and / or a fixed cycle lower bound, or can be set to a dynamic value, referred to as a dynamic cycle upper bound and / or a dynamic cycle lower bound.
[0127] Since the block synchronization scheme involved in the embodiment of this specification does not affect the original block consensus process of the first blockchain network during implementation, this means that during the block synchronization process, the first blockchain network will also generate new blocks, and the latest block height corresponding to the first blockchain network will continue to increase, that is, the first blockchain network has an objective block growth rate, which can be obtained by the first blockchain node by detecting the change rate of the latest block height, and the block growth rate is a dynamically changing value. If the maximum number of blocks allowed to be requested by a single block synchronization request is M, then if the dynamic request cycle is too large, it may result in that even if M blocks are requested for each synchronization request, it is impossible to catch up with the number of blocks that naturally grow in the first blockchain network in a waiting dynamic request cycle. In this way, any lagging node cannot catch up with the blocks maintained by normal nodes. Therefore, the upper limit of the dynamic cycle can be set to the ratio of the maximum number of blocks allowed to be requested by the block synchronization request at a single time to the block growth rate of the first blockchain network, so that the lagging block can theoretically complete the block chasing process.
[0128] In the embodiment of the present specification, after receiving the backward blocks returned by the normal nodes, the first blockchain node needs to first process these blocks in order of block height from low to high, that is, the transactions contained in these blocks, and then update them to the locally maintained distributed ledger. Therefore, for the first blockchain node, there is an objective local block processing speed. At the same time, the first blockchain node will also be allocated a memory space dedicated to storing unprocessed blocks by the first node device, that is, the aforementioned block cache space. The first node device will first cache the received backward blocks in this block cache space, and the first blockchain node will read and process the blocks from the block cache space. Each time a block is processed, the first node device will be notified to remove the processed block from the block cache space to make room for more blocks. If the dynamic request cycle is too small, it is likely that the received backward blocks cannot be completely cached in the block cache space, resulting in memory overflow and block loss. In essence, the number of requested blocks exceeds the limit that the current block cache space can accommodate. In order to avoid this phenomenon, in theory, it is necessary to ensure that the number of blocks required for a block synchronization request does not exceed the maximum number of blocks remaining in the current block cache space (estimated by dividing the remaining memory capacity by the average size of a single block). However, since the block synchronization request is generated at the beginning of the waiting dynamic request cycle, some blocks will be processed and removed from the block cache space during the waiting process for a dynamic request cycle. This means that, assuming that the number of blocks required for the newly determined block synchronization request in a certain cycle is M1, the maximum number of blocks currently remaining in the block cache space determined at the beginning of the new waiting cycle is Z, and the local block processing speed is v, then as long as M1≥Z-vP is satisfied, that is, the dynamic request cycle required to wait for this cycle should satisfy P≥(Z-M1) / v, the above-mentioned memory overflow and block loss will not occur. Therefore, the dynamic period can be set to the difference between the number of blocks required for the block synchronization request and the maximum number of blocks currently remaining in the block cache space corresponding to the first blockchain node divided by the local block processing speed, thereby preventing memory overflow and block loss, and maximizing the use of the block cache space freed up by block processing while waiting for a dynamic request period.
[0129] Optionally, the blockchain system includes a blockchain main network and a blockchain subnet managed by it, and a main network node is also deployed on the node device where the subnet node in the blockchain subnet is deployed; the first node device maintains the network topology structure between the node devices where each main network node in the blockchain main network is located and the network delay information corresponding to the network topology structure; forwarding the block synchronization request to the normal node includes: determining, from the network topology structure based on the network delay information, a forwarding path with the smallest total delay between the first node device and the target node device where the normal node is located, and forwarding the block synchronization request to the normal node according to the determined forwarding path.
[0130] In the embodiments of this specification, a node device is a hardware entity used to run a blockchain node, and a blockchain node refers to a software process running in a node device, as Figure 1 In the network architecture shown, different blockchain nodes in any blockchain network are deployed on different node devices, and the network links between the blockchain nodes are actually the network links between the corresponding node devices. Therefore, in the case where the blockchain network to which any blockchain node belongs is the blockchain main network subnet0, for any blockchain node such as nodeC, assuming that it needs to send a message to other main network nodes in subnet0 such as nodeE, it only needs to send the message from node device 3 where nodeC is located to node device 5 where nodeE is located to complete the corresponding message transmission.
[0131] After receiving the block synchronization request sent by any of the blockchain nodes, the first node device learns that the block synchronization request needs to be sent to the normal node according to the destination communication address of the block synchronization request, and because the first node device needs to forward the block synchronization request to the normal node, the first node device needs to learn the routing information from the first node device to the target node device where the normal node is located. In the embodiment of this specification, the first node device forwards the block synchronization request to the node device as the next hop in the forwarding path by using the forwarding path with the smallest total delay between the first node device and the target node device as the routing information, and then gradually forwards it to the target node device.
[0132] Since the first node device is deployed with a main network node, the first node device can generate a network topology structure between each node device deployed with a main network node by querying the network connection relationship of each main network node in the blockchain main network, and since the blockchain main network manages the subnet information of each blockchain subnet, which includes the identity information of each node member in any blockchain subnet, the node device where the node is located, etc. Therefore, the network topology structure maintained by the first node device, in addition to the network connection relationship between each node device, also includes the situation of the subnet nodes deployed on each node device, that is, the network topology structure includes the overall network structure of the blockchain system composed of the blockchain main network and each blockchain subnet.
[0133] The network topology structure involved in the embodiments of this specification refers to the connection relationship between the node devices of each main network node in the blockchain main network. The network topology structure is generated based on the network connection relationship between the main network nodes in the blockchain main network and can be represented in a graphical form. Figure 3 is a schematic diagram of a network topology structure provided by an exemplary embodiment, such as Figure 3 As shown in Figure 1, the network topology is used to characterize the blockchain node deployment on each node device and the network link status between each node device. Figure 3 The connection relationship between the node devices shown is regarded as a form of expression for representing the above network topology structure. Of course, the above network topology structure can also be represented in the form of a matrix or a table, and there is no limitation here.
[0134] The network delay information corresponding to the network topology structure involved in the embodiments of this specification includes: the link delay of the network link in the network topology structure, and / or the node delay of the node device in the network topology structure when forwarding a message. Figure 3 As shown in FIG. 1 , the network topology structure includes the link delay of each network link and the node delay of each node device. The link delay of a network link refers to the delay information required for a message to be forwarded on the network link, for example Figure 3 The link delay of the network link between node device 1 and node device 2 is 100; the node delay of a node device refers to the delay information required for a message to enter the node device and be forwarded from the node device, which specifically includes the process of the node device parsing the message, looking up the routing table, and forwarding it, for example Figure 3The node delay of node device 1 is 3, and the forwarding delay of node device 4 is 5. In the embodiments of this specification, the values corresponding to the link delay and the node delay can represent the specific delay duration, or other delay indicators that are correlated with the specific delay duration, but the link delay and the node delay need to be in a unified unit. For example, the link delay of 100 of the network link between node device 1 and node device 2 can be understood as 100 milliseconds (ms), which means that it takes 100ms for the message to pass through the network link, so the node delay of 3 of node device 1 should be understood as 3ms.
[0135] The forwarding path with the minimum total delay between the first node device involved in the embodiments of this specification and the target node device where the normal node is located is determined by the network topology structure between the node devices where each main network node in the blockchain main network is located and the network delay information corresponding to the network topology structure. Specifically, when the first node device needs to send a block synchronization request to the normal node, the forwarding path with the minimum total delay between the first node device and the target node device can be determined by the locally maintained network topology structure and the network delay information.
[0136] Since the network topology structure maintained by the first node device includes the network link connection relationship between each node device, the first node device can generate a forwarding path between the first node device and the target node device while determining the relative network position relationship between the first node device and the target node device in the network topology structure and ensuring reachability. Figure 3For example, assuming that the first node device is node device 3, nodeC is any of the blockchain nodes, and nodeE is a normal node. Now nodeC detects that it is a lagging node and has been waiting for a dynamic request cycle. NodeC needs to send a block synchronization request to nodeE, so nodeC sends the block synchronization request to node device 3 where it is located. After receiving the block synchronization request, node device 3 first needs to determine the forwarding path between node device 3 (first node device) and node device 5 (target node device) where nodeE is located based on the network topology structure maintained by itself. Obviously, according to the network topology structure, it can be found that there is no directly connected network link between node device 3 and node device 5, and in the forwarding path without considering the loop and the original return, the forwarding path between node device 3 and node device 5 includes two: one is node device 3→node device 1→node device 2→node device 5; the other is node device 3→node device 1→node device 4→node device 2→node device 5. After determining the two optional forwarding paths, node device 3 further determines the forwarding path with the minimum total delay between node device 3 and node device 5 from the two optional forwarding paths based on the network delay information, wherein the total delay corresponding to the forwarding path is the sum of the link delay of at least one network link from the first node device to the target node device on the forwarding path and / or the node delay of at least one node device (excluding the first node device and the target node device) passed through. Therefore, when determining the total delay of the forwarding path, the first node device may only calculate the link delay of all network links from the first node device to the target node device, or only calculate the node delay of all node devices from the first node device to the target node device, or may simultaneously consider the link delay of all network links from the first node device to the target node device and the node delay of all node devices passed through. For example, Figure 3 For example, since the total delay of all network links and all node devices in the forwarding path of node device 3→node device 1→node device 2→node device 5 is 166, and the total delay of all network links and all node devices in the forwarding link path of node device 3→node device 1→node device 4→node device 2→node device 5 is 131, the forwarding path finally determined by node device 3 is node device 3→node device 1→node device 4→node device 2→node device 5, so that node device 3 can further determine node device 1 as the next hop in the forwarding path, and then forward the block synchronization request to node device 1.
[0137] After receiving the block synchronization request, node device 1 can determine the forwarding path with the shortest total delay between node device 1 and node device 5 again based on the network topology structure maintained by node device 1 and the network delay information, and forward the block synchronization request for a second time based on the newly determined forwarding path. The node devices that subsequently receive the block synchronization request also follow the same process as above, first determine the new forwarding path and then forward the block synchronization request based on the newly determined forwarding path; or, when node device 3 forwards the block synchronization request to node device 1, it can also carry the forwarding path determined by node device 3 in the block synchronization request. Then, after receiving the block synchronization request, node device 1 can continue to find the next-hop node device as node device 4 based on the forwarding path carried in the block synchronization request, and forward the block synchronization request to node device 4. Node device 4 and subsequent node devices continue to forward the block synchronization request according to the same process until the block synchronization request is forwarded to node device 5. After receiving the block synchronization request, the node device 5 will further forward the block synchronization request to the locally deployed node E, thereby completing the entire process of sending the block synchronization request to a normal node.
[0138] In the embodiment of the present specification, the network delay information includes the link delay of the proximal network link and / or the link delay of the distal network link in the network topology structure, the proximal network link is the network link between the first node device and its neighbor node device, and the distal network link is the network link other than the proximal network link in the network topology structure. The neighbor node device of the first node device refers to the node device directly connected to the first node device through a network link. Figure 3 For example, the neighbor node devices corresponding to node device 1 include node device 2, node device 3 and node device 4, and the neighbor node devices of node device 4 include node device 1 and node device 2.
[0139] For the first node device, it maintains two different types of network links, including proximal network links and distal network links. Among them, the proximal network link refers to the network link directly connected to the first node device, that is, the network link between the first node device and its neighboring node device; the distal network link refers to the network link not directly connected to the first node device, that is, the network link in the network topology structure except the proximal network link corresponding to the first node device. Figure 3For example, the proximal network link corresponding to node device 1 includes the network links between it and node device 3, and between node device 4 and node device 5 respectively, and the remote network link corresponding to node device 1 includes the network links between node device 1 and node device 2, between node device 4 and node device 2, and between node device 2 and node device 5.
[0140] The first node device obtains the link delay according to different strategies based on different types of network links. The first node device determines the link delay of the proximal network link based on the local link delay and / or the opposite link delay; wherein the local link delay is obtained by the first node device detecting the proximal network link through a request response mechanism, and the opposite link delay is obtained by the neighbor node device of the first node device detecting the proximal network link through a request response mechanism; and / or, the link delay of the remote network link sent by the neighbor node device of the first node device is received, and the link delay of the remote network link is determined by the link delay obtained by at least one end node device of the remote network link detecting the remote network link through a request response mechanism.
[0141] The request-response mechanism involved in the embodiments of this specification involves the interaction between the requester and the responder, and it is considered that the initiator of the request-response mechanism is the above-mentioned requester. The request-response mechanism is specifically implemented in the following manner: the requester sends a request message carrying a time t1 to the responder, and t1 is the local time of the requester recorded by the requester when sending the request message. After receiving the request message, the responder will record the local time t2 of the responder when it receives the request message, and then return the response message generated in response to the request message to the requester, and carry the time t2 and time t3 in the response message, wherein t3 is the local time of the responder recorded by the responder when returning the response message. Finally, after obtaining the response message, the requester records the local time t4 of the requester when receiving the response message, then extracts t2 and t3 from the obtained response message, and then calculates T0=[(t4-t1)-(t3-t2)] / 2, and determines it as the link delay T0 of the network link between the requester and the responder. In order to avoid the interference of the forwarding delay of the transit equipment, there is no other transit equipment between the requester and the responder. The request message and response message involved in the request-response mechanism can be a dedicated message dedicated to calculating the link delay, or other ordinary normal business requests, or heartbeat messages in the network. Since the local processing time t3-t2 of the responder is taken into account when calculating the link delay, no matter what type of request message and response message, the above request-response mechanism can be applied to enable the requester to measure the relevant link delay.
[0142] In the present illustrative embodiment, when determining the link delay of the proximal network link, the first node device may determine it through the above-mentioned request response mechanism. For example, the first node device may actively initiate a request response mechanism to its neighboring node device, thereby determining the link delay of the proximal network link between the first node device and the neighboring node device. The proximal network link delay measured by the first node device through the request response mechanism is called the local link delay. On the other hand, since for any network link, the two end devices included therein can measure the link delay of the network link by initiating a request response mechanism, the first node device may also directly obtain the link delay of the proximal network link by receiving the link delay of the proximal network link between the first node device and the neighboring node device measured by the request response mechanism of its neighboring node device. The link delay of the proximal network link measured by the neighboring node device and provided to the first node device is called the opposite end link delay. In summary, the first node device can obtain the link delay of a certain proximal network link by two means, so it can also choose between the two means or make comprehensive considerations. For example, the link delay of the proximal network link finally determined by the first node device and recorded in the network delay information may include: the local link delay, the opposite link delay, or the weighted average of the local link delay and the opposite link delay. Among them, when the link delay of the proximal network link is determined as the weighted average of the local link delay and the opposite link delay, the network delay information maintained by the first node device can be made more robust.
[0143] by Figure 3 For example, assuming that the local link delay of the proximal network link between node device 1 and node device 2 measured by initiating a request response mechanism is 102, and the opposite link delay of the proximal network link measured by node device 2 by initiating a request response mechanism is 98, then, for node device 1, it can directly determine the local link delay 102 measured by itself as the link delay of the proximal network link between itself and node device 2, or determine the opposite link delay 98 received from node device 2 and measured by node device 2 as the link delay of the proximal network link, and can also determine the average value of the local link delay and the opposite link delay 100 as the link delay of the proximal network link according to a weight ratio of 1:1, and record it in the network delay information locally maintained by node device 1.
[0144] Since the first node device can only directly measure the link delay of the proximal network link between its neighbor node device, but cannot measure the link delay with the remote network link, it is necessary to directly obtain the link delay of the remote network link by receiving the link delay sharing message containing the link delay of the remote network link sent or forwarded by the neighbor node device, and record it in the network delay information corresponding to the remote network link. In an embodiment of the present specification, the first node device receives the link delay of the remote network link sent by the neighbor node device of the first node device, and the link delay of the remote network link is determined by the link delay obtained by detecting the remote network link through a request response mechanism by at least one end node device of the remote network link. For example, the link delay of the remote network link may include: the link delay detected by any end node device of the remote network link, or the weighted average of the link delays detected by the node devices at both ends of the remote network link. Among them, the link delay detected by any end node device is the link delay for the remote network link. When the link delay of the remote network link is the weighted average of the link delays detected by the node devices at both ends of the remote network link, the network delay information maintained by the first node device can be made more robust.
[0145] like Figure 3 As shown, assuming that the first node device is node device 1, then for node device 1, the link delay of the remote network link between node device 2 and node device 5 cannot be directly measured through the request response mechanism, but needs to be measured and determined by node device 2 and / or node device 5 by initiating a request response mechanism, and node device 2 encapsulates the finally determined link delay of the remote network link into a link delay sharing message and sends or forwards it to node device 1. Node device 1 updates the network delay information it maintains based on the acquired link delay of the remote network link.
[0146] The first node device can receive the remote link delay measured from the neighbor node device. In one embodiment, it also includes: receiving a response message sent by the neighbor node device of the first node device in the request response mechanism, wherein the response message includes the opposite link delay and / or the link delay of the remote network link. In this embodiment, the opposite link delay and / or the link delay of the remote network link received by the first node device can be directly carried in the response message involved when the first node device initiates the request response mechanism to the neighbor node device. Therefore, the first node device only needs to initiate the request response mechanism once to obtain the local link delay while obtaining the opposite link delay and / or the link delay of the remote network link, thereby reducing the complexity of the internal interaction of the network. In another embodiment, the opposite link delay and / or the link delay of the remote network link can also be carried in other messages sent or forwarded by the neighbor node device to the first node device.
[0147] As mentioned above, the network delay information includes: the link delay of the network link in the network topology structure, and / or the node delay of the node device in the network topology structure when forwarding the message. Optionally, it also includes: obtaining the node delay of any node device in the network topology structure by detecting the any node device through at least one neighbor node device, and determining the node delay of the any node device based on the obtained node delay; and / or, receiving the node delay of the any node device shared by other node devices. In the embodiments of the present specification, the node delay of any node device needs to be measured by any neighbor node device corresponding to the any node device, specifically, it is measured by any neighbor node corresponding to any node device through a backflow message mechanism.
[0148] The return message mechanism involved in the embodiments of this specification involves the interaction between the requester and the responder, and it is considered that the initiator of the return message mechanism is the above-mentioned requester. The return message mechanism is specifically implemented in the following way: the requester first selects a responder and initiates the return message mechanism. First, the requester needs to construct a return message with a destination address pointing to the requester itself, and send the return message to the responder according to the network link directly connected to the responder, and record the local time t5 of the requester when sending the return message. After receiving the return message, the responder finds out that the destination address of the return message is the requester by searching the routing table, so it will return the return message to the requester by the original route. After receiving the return message, the requester records the local time t6 of the requester, and then calculates T1=t6-t5 to obtain the forwarding delay T1 corresponding to the entire cycle of the return message from the requester to the return to the requester. Then, the requester finds out the link delay T2 of the network link between the requester and the responder from the network delay information it maintains, and then calculates T3=T1-2*T2, thereby finally determining that the node delay corresponding to the responder is T3. The return message mechanism requires that there is no other transit equipment between the requester and the responder. This is because the object measured by the return message mechanism is the node delay of the forwarding message of the responder, so adding other transit equipment will result in failure to achieve measurement expectations.
[0149] In an embodiment of the present specification, any neighbor node device of any node device detects the any node device, including: any neighbor node device sends a backflow message to the any node device, and determines the node delay of the any node device through the forwarding delay of the backflow message and the link delay of the network link between the any neighbor node device and the any node device, wherein the backflow message is a message sent by the any neighbor node device to the any node device, and the destination address points to the any neighbor node device. As mentioned above, for the node delay of any node device, any neighbor node device of the any node device can initiate a backflow message mechanism to measure it.
[0150] The first node device can directly detect the node delay of a neighbor node device of the first node device by initiating a backflow message mechanism. Of course, since the node devices directly connected to the neighbor node device may not only include the first node device, the first node device can also receive the node delay corresponding to the neighbor node device measured by these node devices through the backflow message mechanism, and use it as a reference to finally determine the node delay corresponding to the neighbor node device. Figure 3For example, assuming that node device 1 detects that the node delay of node device 4 is 3 by initiating a backflow message mechanism to node device 4, and also receives a node delay of node device 4 detected by node device 2 as 7 by initiating a backflow message mechanism to node device 4, then for node device 1, it can directly determine the node delay 3 measured by itself as the node delay with node device 4, and record it in the network delay information locally maintained by node device 1, or determine the node delay 7 measured by node device 2 and received from node device 2 as the node delay of node device 4, and record it in the network delay information locally maintained by node device 1, and can also determine the average value 5 of the node delay 3 measured by itself and the node delay 7 measured by node device 2 as the node delay of node device 4 according to a weight ratio of 1:1, and record it in the network delay information locally maintained by node device 1.
[0151] For the first node device, it cannot detect the node delay of node devices other than its neighbor node devices through the backflow message mechanism. Therefore, the first node device can also obtain the node delay of any node device through other methods. For example, the first node device can directly receive the node delay of any node device shared by other node devices. Figure 3 For example, node device 1 cannot directly detect the node delay of node device 5, but node device 2 can measure it. Therefore, node device 1 can directly receive the node delay sharing message carrying the node delay of node device 5 sent by node device 2 to node device 1, thereby obtaining and determining that the node delay of node device 5 is 2, and finally recording it in the local network delay information. Of course, node device 1 does not necessarily have to obtain the node delay of node device 5 from node device 2. In fact, through the aforementioned node delay acquisition method, the network delay information maintained by node device 4 actually also includes the node delay of node device 5. Therefore, node device 1 can also receive the node delay sharing message carrying the node delay of node device 5 sent by node device 4 to obtain the node delay of node device 5.
[0152] The node delay of any node device in the network delay information maintained by the first node device includes: the node delay obtained by any neighbor node device of the node device when detecting the node device, or the weighted average value of the node delay obtained by at least one neighbor node device of the node device when detecting the node device. As mentioned above, the node delay of any node device can be detected by any neighbor node of the node device. Therefore, when the first node device finally determines the node delay of the node device, it can directly record the node delay for the node device detected by any neighbor node of the node device in the locally maintained network delay information, or it can determine the weighted average value of the node delay obtained by one or more neighbor node devices of the node device when detecting the node device as the node delay of the node device, and record it in the locally maintained network delay information. In the case where the node delay of any node device is finally determined as the weighted average value of the node delay obtained by at least one neighbor node device of the node device when detecting the node device, the network delay information maintained by the first node device can be made more robust.
[0153] by Figure 3 For example, node device 1 can respectively receive node delay 1 of node device 1 detected by node device 3, node delay 3 of node device 1 detected by node device 2, and node delay 5 of node device 1 detected by node device 4. At this time, node device 1 can optionally select the node delay of node device 1 measured by one of the node devices as the node delay of node device 1 in the locally maintained network delay information, or determine the weighted average value 1.5 of the node delay measured by node device 3 and the node delay measured by node device 2 as the node delay of node device 1 in the network delay information at a weight ratio of 3:1, and can also determine the weighted average value 3 of the node delays of node device 1 detected by the above three node devices as the node delay of node device 1 in the network delay information at a weight ratio of 1:1:1.
[0154] Figure 4 is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 4At the hardware level, the device includes a processor 402, an internal bus 404, a network interface 406, a memory 408, and a non-volatile memory 410, and may also include hardware required for other services. One or more embodiments of this specification may be implemented based on software, such as the processor 402 reading the corresponding computer program from the non-volatile memory 410 into the memory 408 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0155] like Figure 5 As shown, Figure 5 is a block diagram of a block synchronization device provided by this specification according to an exemplary embodiment. The device can be applied to Figure 4 In the device shown, the technical solution of this specification is implemented; the device is applied to a first node device, and a plurality of blockchain nodes belonging to a plurality of blockchain networks in a blockchain system are deployed on the first node device. The first node device maintains a corresponding block cache space for the blockchain nodes deployed by it, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively correlated to the node weight factor of any blockchain node; the device includes:
[0156] A block receiving unit 501 is used to receive a backward block sent to any blockchain node by a normal node in the blockchain network to which any blockchain node belongs, wherein the normal node maintains an actual latest block, and the block height of the backward block is between the local block height of the latest block locally maintained by any blockchain node and the latest block height of the actual latest block;
[0157] A block cache unit 502, configured to cache the backward block to a block cache space corresponding to any blockchain node, so that any blockchain node reads and processes the backward block from the block cache space;
[0158] The block removal unit 503 is used to remove the backward block from the block cache space when the backward block is processed by any blockchain node.
[0159] Optionally, the node weight factor of any blockchain node includes: the ratio of the node cache weight of any blockchain node to the sum of the node cache weights of the multiple blockchain nodes.
[0160] Optionally, the size of the block cache space is also positively correlated to the degree of lag between the local block height and the latest block height.
[0161] Optionally, also include:
[0162] The request forwarding unit 504 is used to receive a block synchronization request for the lagging block periodically sent by any blockchain node according to a dynamic request period when the local block height lags behind the latest block height, and forward the block synchronization request to the normal node;
[0163] The dynamic request period is negatively correlated to the lag between the latest block height and the local block height.
[0164] Optionally, the dynamic request period is also negatively correlated to a node weight factor of any blockchain node.
[0165] Optionally, the blockchain system includes a blockchain main network and a blockchain subnet managed by it, and a main network node is also deployed on a node device where a subnet node in the blockchain subnet is deployed; a network topology structure between node devices where each main network node in the blockchain main network is respectively located and network delay information corresponding to the network topology structure are maintained on the first node device; forwarding the block synchronization request to the normal node includes:
[0166] Based on the network delay information, a forwarding path with the smallest total delay between the first node device and the target node device where the normal node is located is determined from the network topology structure, and the block synchronization request is forwarded to the normal node according to the determined forwarding path.
[0167] Optionally, the network delay information includes the link delay of a proximal network link and / or the link delay of a distal network link in the network topology structure, the proximal network link being a network link between a first node device and its neighboring node device, and the distal network link being a network link in the network topology structure other than the proximal network link.
[0168] Optionally, also include:
[0169] A link delay acquisition unit 505 is used to determine the link delay of the proximal network link according to the local link delay and / or the opposite link delay; wherein the local link delay is obtained by the first node device detecting the proximal network link through a request response mechanism, and the opposite link delay is obtained by the neighboring node device of the first node device detecting the proximal network link through a request response mechanism; and / or,
[0170] A link delay of the remote network link sent by a neighboring node device of the first node device is received, where the link delay of the remote network link is determined by a link delay obtained by detecting the remote network link by at least one end node device of the remote network link through a request response mechanism.
[0171] Optionally, also include:
[0172] The response receiving unit 506 is configured to receive a response message sent by a neighbor node device of the first node device in a request response mechanism, wherein the response message includes the link delay of the opposite end and / or the link delay of the remote network link.
[0173] Optional,
[0174] The link delay of the proximal network link includes: the local link delay, the opposite link delay, or a weighted average of the local link delay and the opposite link delay;
[0175] The link delay of the remote network link includes: the link delay detected by a node device at any end of the remote network link, or the weighted average value of the link delays respectively detected by node devices at both ends of the remote network link.
[0176] Optionally, the network delay information includes: link delay of a network link in the network topology structure, and / or node delay of a node device in the network topology structure when forwarding a message.
[0177] Optionally, also include:
[0178] A node delay acquisition unit 507 is used to acquire a node delay of any node device in the network topology structure obtained by detecting the node device by at least one neighbor node device, and determine the node delay of the node device according to the acquired node delay; and / or,
[0179] Receive the node delay of any node device shared by other node devices.
[0180] Optionally, any neighboring node device of any node device detects the any node device, including:
[0181] Any one of the neighboring node devices sends a backflow message to any one of the node devices, and determines the node delay of any one of the node devices through the forwarding delay of the backflow message and the link delay of the network link between any one of the neighboring node devices and any one of the node devices. The backflow message is a message sent by any one of the neighboring node devices to any one of the node devices, and the destination address of the message points to any one of the neighboring node devices.
[0182] Optionally, the node delay of any node device includes:
[0183] The node delay obtained by any neighbor node device of any node device through detection of the any node device, or the weighted average of the node delays obtained by at least one neighbor node device of any node device through detection of the any node device.
[0184] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0185] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0186] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, the present invention does not exclude that with the development of computer technology in the future, the computer that implements the functions of the above embodiments may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0187] Although one or more embodiments of the present specification provide method operation steps as described in the embodiments or flow charts, more or less operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps, and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements. For example, if the words first, second, etc. are used to represent the name, they do not represent any specific order.
[0188] For the convenience of description, the above devices are described in various modules according to their functions. Of course, when implementing one or more of the present specification, the functions of each module can be implemented in the same or more software and / or hardware, or the module implementing the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0189] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0190] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0191] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0192] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0193] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0194] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0195] It should be understood by those skilled in the art that one or more embodiments of the present specification may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, one or more embodiments of the present specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0196] One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0197] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. In the description of this specification, the description of the reference terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representation of the above terms does not necessarily target the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples without contradiction.
[0198] The above description is only an example of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. For those skilled in the art, one or more embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included in the scope of the claims.
Claims
1. A block synchronization method is applied to a first node device, on which a plurality of blockchain nodes belonging to a plurality of blockchain networks in a blockchain system are deployed, and the first node device maintains a corresponding block cache space for the blockchain nodes deployed thereon, wherein: The size of the block cache space corresponding to any blockchain node deployed by the first node device is positively correlated to the node weight factor of any blockchain node, and the node weight factor of any blockchain node includes: the ratio of the node cache weight of any blockchain node to the sum of the node cache weights of the multiple blockchain nodes, or the ratio of the node cache weight of any blockchain node to the sum of the node cache weights of the blockchain nodes in the multiple blockchain nodes that are in a block lagging state; the method includes: Receiving a backward block sent to any blockchain node by a normal node in the blockchain network to which any blockchain node belongs, wherein the normal node maintains an actual latest block, and the block height of the backward block is between the local block height of the latest block locally maintained by any blockchain node and the latest block height of the actual latest block; Cache the backward block in the block cache space corresponding to any one of the blockchain nodes, so that any one of the blockchain nodes reads and processes the backward block from the block cache space; When the backward block is processed by any of the blockchain nodes, the backward block is removed from the block cache space.
2. According to the method of claim 1, the size of the block cache space is also positively correlated with the degree of lag between the local block height and the latest block height.
3. The method according to claim 1, further comprising: Receiving a block synchronization request for the lagging block periodically sent by any blockchain node according to a dynamic request period when the local block height lags behind the latest block height, and forwarding the block synchronization request to the normal node; The dynamic request period is negatively correlated to the lag between the latest block height and the local block height.
4. According to the method of claim 3, the dynamic request period is also negatively correlated with the node weight factor of any blockchain node.
5. According to the method of claim 3, the blockchain system includes a blockchain main network and a blockchain subnet managed by it, and a main network node is also deployed on the node device where the subnet node in the blockchain subnet is deployed; the first node device maintains the network topology structure between the node devices where each main network node in the blockchain main network is located and the network delay information corresponding to the network topology structure; forwarding the block synchronization request to the normal node includes: Based on the network delay information, a forwarding path with the smallest total delay between the first node device and the target node device where the normal node is located is determined from the network topology structure, and the block synchronization request is forwarded to the normal node according to the determined forwarding path.
6. According to the method according to claim 5, the network delay information includes the link delay of the proximal network link and / or the link delay of the distal network link in the network topology structure, the proximal network link is the network link between the first node device and its neighboring node device, and the distal network link is the network link in the network topology structure except the proximal network link.
7. The method according to claim 6, further comprising: The link delay of the proximal network link is determined according to the local link delay and / or the opposite link delay; wherein the local link delay is obtained by the first node device detecting the proximal network link through a request response mechanism, and the opposite link delay is obtained by the neighboring node device of the first node device detecting the proximal network link through a request response mechanism; and / or, A link delay of the remote network link sent by a neighboring node device of the first node device is received, where the link delay of the remote network link is determined by a link delay obtained by detecting the remote network link by at least one end node device of the remote network link through a request response mechanism.
8. The method according to claim 7, further comprising: A response message is received from a neighbor node device of the first node device in a request response mechanism, wherein the response message includes the link delay of the opposite end and / or the link delay of the remote network link.
9. The method according to claim 7, The link delay of the proximal network link includes: The local link delay, the opposite link delay, or a weighted average of the local link delay and the opposite link delay; The link delay of the remote network link includes: the link delay detected by a node device at any end of the remote network link, or the weighted average value of the link delays respectively detected by node devices at both ends of the remote network link.
10. The method according to any one of claims 5 to 9, wherein the network delay information comprises: The link delay of the network links in the network topology structure, and / or the node delay of the node devices in the network topology structure when forwarding messages.
11. The method according to claim 10, further comprising: Obtaining a node delay of any node device in the network topology structure obtained by detecting the node device by at least one neighboring node device, and determining the node delay of the node device according to the obtained node delay; and / or, Receive the node delay of any node device shared by other node devices.
12. The method according to claim 11, wherein any neighboring node device of any node device detects the any node device, comprising: Any one of the neighboring node devices sends a backflow message to any one of the node devices, and determines the node delay of any one of the node devices through the forwarding delay of the backflow message and the link delay of the network link between any one of the neighboring node devices and any one of the node devices. The backflow message is a message sent by any one of the neighboring node devices to any one of the node devices, and the destination address of the message points to any one of the neighboring node devices.
13. The method according to claim 11, wherein the node delay of any node device comprises: The node delay obtained by any neighbor node device of any node device through detection of the any node device, or the weighted average of the node delays obtained by at least one neighbor node device of any node device through detection of the any node device.
14. A block synchronization device, applied to a first node device, on which a plurality of blockchain nodes belonging to a plurality of blockchain networks in a blockchain system are deployed, and the first node device maintains a corresponding block cache space for the blockchain nodes deployed thereon, wherein: The size of the block cache space corresponding to any blockchain node deployed by the first node device is positively correlated to the node weight factor of any blockchain node, and the node weight factor of any blockchain node includes: the ratio of the node cache weight of any blockchain node to the sum of the node cache weights of the multiple blockchain nodes, or the ratio of the node cache weight of any blockchain node to the sum of the node cache weights of the blockchain nodes in the multiple blockchain nodes that are in a block lagging state; the device includes: A block receiving unit, configured to receive a backward block sent to any blockchain node by a normal node in the blockchain network to which any blockchain node belongs, wherein the normal node maintains an actual latest block, and the block height of the backward block is between the local block height of the latest block locally maintained by any blockchain node and the latest block height of the actual latest block; A block cache unit, configured to cache the backward block to a block cache space corresponding to any one of the blockchain nodes, so that any one of the blockchain nodes reads and processes the backward block from the block cache space; The block removal unit is used to remove the backward block from the block cache space when the backward block is processed by any blockchain node.
15. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 13 by running the executable instructions.
16. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 13.
