WO2023124743A1 - Block synchronization - Google Patents

Block synchronization Download PDF

Info

Publication number
WO2023124743A1
WO2023124743A1 PCT/CN2022/135825 CN2022135825W WO2023124743A1 WO 2023124743 A1 WO2023124743 A1 WO 2023124743A1 CN 2022135825 W CN2022135825 W CN 2022135825W WO 2023124743 A1 WO2023124743 A1 WO 2023124743A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
block
blockchain
node device
network
Prior art date
Application number
PCT/CN2022/135825
Other languages
French (fr)
Chinese (zh)
Inventor
陶友贤
Original Assignee
支付宝(杭州)信息技术有限公司
蚂蚁区块链科技(上海)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 支付宝(杭州)信息技术有限公司, 蚂蚁区块链科技(上海)有限公司 filed Critical 支付宝(杭州)信息技术有限公司
Publication of WO2023124743A1 publication Critical patent/WO2023124743A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • H04L43/0852Delays
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1097Protocols in which an application is distributed across nodes in the network for distributed storage of data in networks, e.g. transport arrangements for network file system [NFS], storage area networks [SAN] or network attached storage [NAS]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/40Network security protocols

Definitions

  • the embodiments of this specification belong to the technical field of block chains, and in particular relate to a block synchronization method, device, electronic equipment, and storage medium.
  • Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • the data blocks are combined into a chained data structure in a sequentially connected manner in chronological order, and a non-tamperable and unforgeable distributed ledger is cryptographically guaranteed. Due to the characteristics of decentralization, non-tamperable information, and autonomy, the blockchain has also received more and more attention and application.
  • some nodes sometimes need to implement small-scale transactions to prevent other nodes from obtaining these transactions and their related data. Therefore, a blockchain subnet can be further established on the basis of the blockchain main network, and the blockchain main network and the blockchain subnet are both independent blockchain networks.
  • the various blockchain nodes contained in it use consensus agreements to ensure the consistency of the distributed ledgers maintained by them.
  • the blockchain node 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 cannot participate To the normal consensus process, affecting the operation of functions and services on blockchain nodes.
  • the object of the present invention is to provide a block synchronization method, device, electronic equipment and storage medium.
  • a block synchronization method is proposed, which is applied to a first node device, and the first node device is deployed with a block chain system belonging to multiple block chain networks multiple blockchain nodes, the first node device maintains a corresponding block cache space for its deployed blockchain nodes, wherein, the block cache space corresponding to any blockchain node deployed by the first node device
  • the size is positively related to the node weight factor of any of the blockchain nodes; the method includes: receiving the normal node in the blockchain network to which any of the blockchain nodes belongs sends to the any of the blockchain nodes The backward block, wherein, the normal node maintains the 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 Between the latest block heights of the actual latest block; cache the lagging block to the block cache space corresponding to any blockchain node, so that any blockchain node can retrieve data from the block Reading and processing the backward block in the block cache
  • a block synchronization device which is applied to a first node device, and the first node device is deployed with a block chain system belonging to multiple block chain networks multiple blockchain nodes, the first node device maintains a corresponding block cache space for its deployed blockchain nodes, wherein, the block cache space corresponding to any blockchain node deployed by the first node device
  • the size is positively related to the node weight factor of any of the blockchain nodes;
  • the device includes: a block receiving unit, used to receive the normal nodes in the blockchain network to which any of the blockchain nodes belong The backward block of any blockchain node, wherein the normal node maintains the actual latest block, and the block height of the backward block is the latest block locally maintained by any blockchain node Between the local block height of the local block height and the latest block height of the actual latest block; the block cache unit is used to cache the backward block to the block cache space corresponding to any one of the blockchain nodes, To read and process the backward block from the block
  • an electronic device including: a processor; a memory for storing processor-executable instructions; wherein, the processor executes the executable instructions To realize the method as described in any one of the first aspect.
  • a computer-readable storage medium on which computer instructions are stored, and when the instructions are executed by a processor, the method as described in any one of the first aspect is implemented. A step of.
  • the first node device caches the received outdated block sent to any blockchain node in the block cache space corresponding to any blockchain node, and the Any one of the above-mentioned blockchain nodes reads and processes the backward block, so that the blockchain node deployed on the first node device can obtain its corresponding backward block, so as to ensure that the functions on the blockchain node are consistent with normal operation of the service.
  • this solution is equivalent to adaptively allocating the storage resources of the first node device , giving priority to the block chain nodes with larger node weight factors deployed on the first node device to occupy a larger block cache space, so that in the block chain system composed of multiple block chain networks, different blocks
  • the block current-limiting strategy corresponding to the block chain nodes in the chain network is macro-regulated, and the hierarchical design of block synchronization tasks is realized.
  • Fig. 1 is a schematic diagram of building a blockchain subnet based on the blockchain main network provided by an exemplary embodiment.
  • Fig. 2 is a flowchart of a block synchronization method provided by an exemplary embodiment.
  • Fig. 3 is a schematic diagram of a network topology provided by an exemplary embodiment.
  • Fig. 4 is a schematic structural diagram of a device provided by an exemplary embodiment.
  • Fig. 5 is a block diagram of a block synchronization device provided by an exemplary embodiment.
  • all blockchain nodes in the blockchain network will maintain the same block data, which cannot meet the special needs of some nodes.
  • all consortium members that is, node members in the consortium
  • all consortium members can form a blockchain network, and all consortium members have corresponding blockchain nodes in the blockchain network, and can pass the corresponding zone Block chain nodes obtain all transactions and related data that occur on the block chain network.
  • there may be some alliance members who want to complete some transactions that require confidentiality. These alliance members hope that these transactions can be stored on the blockchain or take advantage of other advantages of blockchain technology, and can avoid other transactions. affiliate members see these transactions and related data.
  • the establishment method is similar to the above-mentioned blockchain network that includes all alliance members, but building a new blockchain network from scratch requires a lot of resources, and regardless of The establishment process of the blockchain network or the configuration process after completion is very time-consuming.
  • the needs among alliance members are often temporary or have a certain timeliness, so that the newly built blockchain network will soon lose the meaning of existence due to the disappearance of demand, thus 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 demand are often different. Therefore, whenever the alliance members change, it may be necessary to form a new blockchain network, resulting in resource and time constraints. A lot of waste.
  • the established blockchain network can be used as the blockchain main network, and a blockchain subnet can be formed on the basis of the blockchain main network.
  • the consortium members can build the required blockchain subnet based on their own needs while already participating in the blockchain main network. Since the blockchain subnet is established on the basis of the blockchain main network, the construction process of the blockchain subnet is compared to the completely independent establishment of a blockchain network, the resources consumed and the time required, etc. Both are greatly reduced, and the flexibility is extremely high.
  • each blockchain node in the blockchain main network obtains a transaction for establishing a blockchain subnet, and the transaction includes the configuration information of the blockchain subnet , the configuration information includes the identity information of the node members participating in the formation of the block chain subnet, each block chain node in the block chain main network respectively executes the transaction to disclose the configuration information, when the When the configuration information includes the identity information of the node members corresponding to the first block chain node, the node device deploying the first block chain node starts the first block belonging to the block chain subnet based on the genesis block containing the configuration information.
  • Two blockchain nodes Two blockchain nodes.
  • the blockchain main network is subnet0
  • the blockchain nodes contained in subnet0 are nodeA, nodeB, nodeC, nodeD, and nodeE.
  • nodeA, nodeB, nodeC and nodeD want to form a blockchain subnet: if nodeA is an administrator and only allows the administrator to initiate a transaction 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 allows the administrator to initiate the transaction of establishing a blockchain subnet, then nodeA ⁇ nodeD needs to make a request to nodeE, so that nodeE initiates the above transaction of establishing a blockchain subnet to subnet0; if nodeE is an administrator but allows Ordinary users initiate a transaction to establish a blockchain subnet, then nodeA ⁇ nodeE can initiate the above transaction to subnet0 to establish a blockchain subnet.
  • the blockchain node that initiates the transaction to form a blockchain subnet does not necessarily participate in the established blockchain subnet.
  • nodeE can initiate the above-mentioned transaction of establishing a blockchain subnet to subnet0, and nodeA ⁇ nodeD may not necessarily initiate the transaction of establishing a blockchain subnet.
  • the blockchain main network in this specification can be the underlying blockchain network, that is, the blockchain main network is not a blockchain subnet formed on the basis of other blockchain networks, such as the subnet0 can be regarded as the blockchain mainnet belonging to the underlying blockchain network type.
  • the blockchain main network in this specification can also be a subnet of other blockchain networks.
  • subnet1 is the blockchain main network corresponding to the blockchain subnet, and this does not affect that subnet1 also belongs to the blockchain subnet created on subnet0. It can be seen that the blockchain main network and the blockchain subnet are actually relative concepts. The same blockchain network can be the blockchain main network in some cases and the blockchain subnet in other cases.
  • the consensus nodes in the blockchain main network will conduct a consensus, and after the consensus is passed, each main network node will execute the transaction to complete the block The formation of the chain subnet.
  • the consensus process depends on the adopted consensus mechanism, which is not limited in this specification.
  • the configuration information can be used to configure the established blockchain subnet so that the established blockchain subnet meets the networking requirements. For example, by including the identity information of node members in the configuration information, it is possible to specify which blockchain nodes are included in the established blockchain subnet.
  • the identity information of the node members may include the public key of the node, or other information that can represent the identity of the node such as the node ID, which is not limited in this description.
  • each blockchain node has one or more sets of corresponding public-private key pairs.
  • the blockchain node holds the private key and the public key is public and uniquely corresponds to the private key. Therefore, it can be passed
  • the public key is used to represent the identity of the corresponding blockchain node. Therefore, for blockchain nodes that want to be node members of the blockchain subnet, the public keys of these blockchain nodes can be added to the above-mentioned transaction of forming the blockchain subnet as the identity information of the above-mentioned node members.
  • the above-mentioned public-private key pair can be used in the process of signature verification.
  • nodeA1 in subnet1 uses its own private key to sign the message, and then broadcasts the signed message in subnet1, while nodeB1, nodeC1 and nodeD1 can use the public key of nodeA1 Signature verification is performed on the received message to confirm that the message received by itself is indeed from nodeA1 and has not been tampered with.
  • the first main network node may be a blockchain node on the blockchain main network that is a node member indicated by the configuration information.
  • the first subnet node needs to be generated by the node device used to deploy the first main network node , and the first subnetwork node becomes a node member in the blockchain subnetwork.
  • 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
  • the node belongs to the blockchain subnet, so that the blockchain members 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 network, so that 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 device (the storage used can be a database, for example), realizing the first
  • the storage used by the main network node and the first subnet node is isolated from each other, so the data generated by the blockchain subnet will only be synchronized among the node members of the blockchain subnet, so that only those who participate in the blockchain main
  • the blockchain members of the network cannot obtain the data generated on the blockchain subnet, which realizes the data isolation between the blockchain main network and the blockchain subnet, and satisfies the requirements
  • the first main network node and the first subnet node are logically divided blockchain nodes, and from the perspective of physical equipment, it is equivalent to deploying the first main network node and the first subnet node
  • the node devices participate in the blockchain main network and the blockchain subnet at the same time. 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, so even if the first main network node and the first subnet node can use exactly the same public key, the two should still be considered as different blockchain nodes. For example, in FIG.
  • nodeA in subnet0 is equivalent to the first main network node, and the node device deploying the nodeA generates nodeA1 belonging to subnet1, and the nodeA1 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 will not affect the implementation of the scheme in this specification.
  • the node members of the blockchain subnet are not necessarily only part of the node members of the blockchain main network.
  • the node members of the blockchain subnet can be completely consistent with the node members of the blockchain main network.
  • all blockchain members can obtain the 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.
  • the two types of The business data generated by the business are isolated from each other.
  • 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 The attribute configuration of the code, etc., is not limited in this specification.
  • the network identifier is used to uniquely represent the blockchain subnet, so the network identifier of the blockchain subnet should be distinguished from the blockchain main network and other blockchain subnets formed 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; the administrators of the blockchain main network and the blockchain subnet can be the same or different.
  • One of the advantages of building a blockchain subnet through the blockchain mainnet is that since the first mainnet node has already been deployed on the node device that generates the first subnetwork node, the area used by the first mainnet node can be The block chain platform code is reused on the first subnet node, which eliminates the repeated deployment of the block chain platform code and greatly improves the efficiency of the block chain subnet.
  • the first subnet node can reuse the attribute configuration adopted on the first main network node; if the configuration information includes the attribute configuration for the blockchain platform code attribute configuration, the first subnetwork node can adopt the attribute configuration, so that the attribute configuration adopted by the first subnetwork node is not limited to the attribute configuration of the first main network node, and has nothing to do with the first main network node.
  • the attribute configuration for the blockchain platform code can include at least one of the following: code version number, whether consensus is required, consensus algorithm type, block size, etc., which are not limited in this specification.
  • Transactions that form blockchain subnets include transactions that call contracts.
  • the transaction can specify the address of the called smart contract, the method called and the parameters passed in.
  • the invoked contract can be the aforementioned genesis contract or system contract
  • the invoked method can be a method for building a blockchain subnet
  • the incoming parameters can include the above-mentioned configuration information.
  • the transaction may contain the following information:
  • the from field is the information of the initiator of the transaction.
  • Administrator indicates that the initiator is an administrator; the to field is the address of the called smart contract.
  • the smart contract can be a Subnet contract, and the to field is specifically the Subnet The address of the contract; the method field is the calling method.
  • the method used to build a blockchain subnet in the Subnet contract can be AddSubnet(string), and string is the parameter in the AddSubnet() method.
  • genesis is used to represent the The value of the parameter, the genesis is specifically the aforementioned configuration information.
  • nodeA ⁇ nodeE Take nodes nodeA ⁇ nodeE on Subnet0 executing a transaction calling the AddSubnet() method in the Subnet contract as an example. After the transaction passes the consensus, nodeA ⁇ nodeE respectively execute the AddSubnet() method and pass in the configuration information to obtain the corresponding execution results.
  • Contract execution results can be expressed as events in receipts.
  • the message mechanism can implement message delivery through events in the receipt to trigger blockchain nodes to perform corresponding processing.
  • the structure of an event can be, for example:
  • Blockchain nodes can listen to the topic of the event to perform preset processing when listening to a predefined topic, or read relevant content from the data field of the corresponding event, and can execute preset based on the read content deal with.
  • the monitoring code can be embedded in the blockchain platform code running on the blockchain node, so that the monitoring code can monitor the transaction content of the blockchain transaction, the contract status of the smart contract, the receipt generated by the contract, etc. or multiple types of data, and send the monitored data to a predefined listener.
  • the monitoring code is deployed in the blockchain platform code instead of the client of the listening party, this implementation based on the monitoring code is relatively more active than the event mechanism.
  • the above monitoring code can be added to the blockchain platform code by the developers of the blockchain platform during the development process, or can be embedded by the monitoring party based on its own needs, which is not limited in this manual.
  • the execution result of the above-mentioned Subnet contract may include the configuration information, and the execution result may be included in the above-mentioned receipt, and the receipt may include an event related to the execution of the AddSubnet() method, that is, a networking event.
  • the topic of networking events can contain predefined networking event identifiers to distinguish them 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 this keyword is different from the topic in the event generated by other methods.
  • nodeA ⁇ nodeE can determine to monitor the event related to the execution of the AddSubnet() method, that is, the networking event, when the topic containing the keyword subnet is monitored.
  • the event in the receipt is as follows:
  • the content of the data field may include, for example:
  • 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, such information can be maintained in In the above-mentioned Subnet contract, it may specifically correspond to the values of one or more contract states included in the Subnet contract.
  • nodeA ⁇ nodeE can determine whether the above-mentioned subnet1 already exists according to the recorded network identifiers of all 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 currently, and if it exists, it means that subnet1 already exists.
  • a predefined new network identifier which indicates that the corresponding networking event is used to form a new blockchain subnet.
  • the above subnet1 can be replaced with newsubnet, which is a predefined new network identifier.
  • nodeA ⁇ nodeE recognizes that the data field contains newsubnet, they can determine that the event containing this newsubnet is a networking event, and a new one needs to be created.
  • Blockchain subnet When nodeA ⁇ nodeE recognizes that the data field contains newsubnet, they can determine that the event containing this newsubnet is a networking event, and a new one needs to be created.
  • the above data field also includes identity information of each node member and so on.
  • the node device deploying 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 deployment second A node device of a main network node obtains the configuration information or the genesis block included in the networking event.
  • 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, trigger the deployment of the first blockchain node.
  • a node device of a blockchain node obtains the configuration information or the genesis block included in the networking event.
  • node devices can listen for receipts directly. Assuming that nodeA ⁇ nodeE are respectively deployed on node devices 1 ⁇ 5, and node devices 1 ⁇ 5 can monitor the receipts generated by nodeA ⁇ nodeE respectively, then when it is detected that subnet1 is a blockchain subnet that needs to be newly established, node device 1 ⁇ 5 will further identify the identity information of the node members contained in the data field to determine its own processing method.
  • nodeA and node device 1 Take nodeA and node device 1 as an example: if node device 1 finds that the data field contains identity information such as nodeA's public key, IP address, and port number, then node device 1 obtains configuration information from the data field based on the above message mechanism , generate a genesis block containing the configuration information, and node device 1 will deploy nodeA1 locally, and then nodeA1 will load the generated genesis block, thus 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. And, 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.
  • identity information such as nodeA's public key, IP address, and port number
  • the blockchain nodes in the blockchain main network can monitor receipts and trigger node devices to perform related processing according to the monitoring results.
  • nodeA ⁇ nodeE will further identify the identity information of the node members contained in the data field in order to determine their own processing methods when they determine that subnet1 is a blockchain subnet that needs to be newly established.
  • nodeA ⁇ nodeD will find that the data field contains their own identity information such as their public key, IP address, and port number. Assume that nodeA ⁇ nodeD are deployed on node devices 1 ⁇ 4 respectively.
  • nodeA will Trigger node device 1, so that node device 1 obtains configuration information from the data field based on the above-mentioned message mechanism and generates a genesis block containing the configuration information, and node device 1 will deploy nodeA1 locally, and nodeA1 will load the generated genesis block, Thus, it becomes 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.
  • 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 the node device 5 will not generate a genesis block based on the configuration information in the data field, nor will it generate subnet1 nodes in .
  • the data field may contain identity information generated in advance for nodeA1-nodeD1, which is different from the identity information of nodeA-nodeD.
  • 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 is in the data field If the identity information of nodeA1 is found in , 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.
  • the execution result of the contract can include the genesis block.
  • the corresponding node devices 1-4 can directly obtain the genesis block from the data field through the message mechanism without generating it by themselves, which can improve the deployment efficiency of nodeA1-nodeD1.
  • the node device implements the deployment of a blockchain node on the node device by creating an instance of running the blockchain platform code in the process.
  • the node device creates the first instance in the above process, and the first instance runs the blockchain platform code to form.
  • 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 to form.
  • the node device can first create the first instance in the process to form the first blockchain node in the blockchain main network; In the above process, a second instance is created, which is different from the above-mentioned first instance, and the second instance forms a second blockchain node in the blockchain subnet.
  • the second instance may also be in separate nodes from the first instance
  • this specification does not limit this; for example, the node device can create the first instance in the first process to form the first blockchain node in the blockchain main network; and when the node When the node member corresponding to the device wants to participate in the establishment 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 first instance above. Furthermore, the second instance forms a second blockchain node in the blockchain subnet.
  • 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 each blockchain node deployed on any node device
  • the blocks generated by the nodes 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.
  • a blockchain subnet can be created on the blockchain mainnet.
  • subnet0 originally included nodeA ⁇ nodeE
  • subnet1 can be built on the basis of subnet0.
  • This subnet1 includes nodeA1 ⁇ nodeD1, and nodeA and nodeA1, nodeB and nodeB1, nodeC and nodeC1, nodeD and nodeD1 are respectively deployed in on the same node device.
  • subnet2 or more blockchain subnets can also be established 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 respectively deployed on the same node device.
  • subnet1, subnet2, etc. can be used as the new blockchain main network, and a blockchain subnet can be further formed on this basis. The process is similar to the formation of subnet1 or subnet2, and will not be repeated here.
  • 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 all deployed on the main network nodes of the blockchain main network.
  • the node device where the subnet node of the blockchain subnet is located belongs to the subset of the node device where the main network node is located.
  • the main network node in the blockchain main network is deployed on the node device at .
  • a blockchain subnet can be established on the blockchain main network through registration (subsequently referred to as the registration network method), and the existing blockchain network can be directly registered to the blockchain main network, so that the newly registered blockchain network Managed by the blockchain main network, the newly registered blockchain network becomes a blockchain subnet of the blockchain main network.
  • the subnet information of the block chain subnet to be formed is directly registered to the block chain main network, so that the block chain main network can obtain the relevant information of the block chain subnet to be formed (by receiving and executing the A transaction issued by the block chain network for associating its identity information with the subnet identification assigned to the block chain network to be formed), such as the subnet identification and operating status of the block chain subnet to be formed, where
  • the public key and plug-in configuration information of each node member, the IP address and port information of each node device, etc. will be written into the contract state of the system contract corresponding to the blockchain main network, so that the blockchain main network will Obtain the management right of the blockchain subnet to be formed.
  • subnet0 creates a subnet4 (not shown in Figure 1) in the form of registration and networking.
  • subnet nodes corresponding to subnet4 can be deployed on any other node devices except node devices 1 to 5, or one or more subnet nodes in subnet4 are respectively deployed on node devices 1 to 5 Any node device within 5 (but it is still necessary to ensure that only one subnet node in subnet4 is deployed on a node device), and other subnet nodes in subnet4 are deployed on any other node device except node devices 1 to 5 , of course, the subnet nodes in subnet4 may also be deployed in node devices 1-5.
  • any blockchain network (referred to as the first blockchain network) in the blockchain system composed of the blockchain main network and its managed blockchain subnetworks
  • its Each block chain node of the network independently maintains a distributed ledger composed of several blocks connected in sequence.
  • Each block will have a corresponding block height to indicate the block's position in the distributed ledger.
  • Relative position for example, the block with the largest current block height maintained by a blockchain node is the block obtained by the latest consensus or synchronization of the blockchain node.
  • new blocks will continue to be generated and updated to the distributed ledgers maintained by these blockchain nodes.
  • each blockchain node in the first blockchain network will continuously update the distributed ledger maintained by itself in accordance with the consensus protocol, which makes the distributed ledger maintained by each blockchain node strictly consistent , but when the blockchain node 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 those in the first blockchain network other blockchain nodes, that is, the block height of the latest local block maintained by these blockchain nodes is behind the block height of the actual latest block in the first blockchain network.
  • the block height of the latest local block is called the local block height
  • the block height of the actual latest block is called the latest block height
  • the local block height of the latest local block maintained lags behind
  • the blockchain node in the first blockchain network with the latest block height is called a backward node
  • the local block height of the local latest block that will be maintained is the same as the latest block height in the first blockchain network
  • Blockchain nodes are called normal nodes.
  • the blocks need to be integrated and updated to the distributed ledger in order, for backward nodes, they cannot participate in the consensus and processing of the actual latest block in the first blockchain network like normal nodes, that is, they cannot participate in the normal
  • the consensus process affects the operation of functions and services on the lagging nodes and even the entire first blockchain network. Therefore, how to make the lagging nodes obtain the blocks they lag behind as soon as possible to complete the block chasing process is an urgent problem to be solved in this scenario .
  • this specification proposes a block synchronization method.
  • the first node device allocates the corresponding block cache space to the blockchain nodes deployed by it, and any blockchain node deployed by the first node device
  • the size of the corresponding block cache space is positively related to the node weight factor of any blockchain node, so that in a blockchain system composed of multiple blockchain networks, the blocks in different blockchain networks
  • the block current-limiting strategy corresponding to the block chain node is macro-regulated, and the hierarchical design of the block synchronization task is realized.
  • Fig. 2 is a flowchart of a block synchronization method provided by an exemplary embodiment.
  • the method is applied to the first node device, where multiple blockchain nodes belonging to multiple blockchain networks in the blockchain system are deployed on the first node device, and the first node device maintains There is a corresponding block cache space, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively related to the node weight factor of any blockchain node; the method includes : S202: Receive the outdated block sent to the any blockchain node by the normal node in the blockchain network to which the any blockchain node belongs, wherein the normal node maintains the 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.
  • S204 Cache the backward block to the block cache space corresponding to any blockchain node, so that any blockchain node can read and process the backward block from the block cache space blocks.
  • a node device is a hardware entity used to run a blockchain node
  • a blockchain node refers to a software process running on 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 block composed of the blockchain main network and its managed blockchain subnets.
  • the block chain system, the feature of the block chain system is that there are multiple block chain nodes deployed at the same time in the node equipment involved, and the block synchronization scheme involved in this specification is being applied to the deployment of multiple block chain nodes.
  • Any blockchain node involved in the embodiment of this specification belongs to a backward node, and after receiving a backward block, the backward node will process it in the order of block height from low to high, and the processing here may include: Verify the legitimacy of the block through the block header of the block, read the transactions contained in the block body of the block and execute these transactions in order, and finally add the block to the end of the distributed ledger maintained by the backward node to complete Block on-chain process. Therefore, any blockchain node needs to process the received backward blocks one by one in a certain order and it will take a certain amount of time to process each block.
  • the first node device will allocate a corresponding block cache space for each blockchain node deployed locally, wherein the block cache space corresponding to any blockchain node is used for temporary Storing the outdated blocks to be forwarded to any one of the blockchain nodes for processing, so that any one of the blockchain nodes can read from the block cache space and Process the backward blocks that need to be executed at present, so as to prevent the backward blocks from being discarded due to the lack of time for the blockchain nodes to process them.
  • the storage space corresponding to the block cache space involved in the embodiment of this specification may include memory space and/or hard disk space.
  • the embodiment of this specification proposes to assign multiple block chain nodes deployed on the first node device according to the node weight factor.
  • Block chain nodes maintain block cache spaces of different sizes, so that the size of the block cache space corresponding to any block chain node is positively related to the node weight factor of any block chain node, thereby realizing the first node Adaptive allocation of device storage resources.
  • the first node device first receives the block message, parses and obtains that the source communication address and the destination communication address corresponding to the block message are the normal node and the arbitrary block chain node respectively, and then obtains from the block message Extract the backward block and cache it in the block cache space corresponding to any blockchain node.
  • the local block height of the latest local block maintained by the lagging node is smaller than the latest block height of the actual latest block, which means that when the first blockchain node detects that it belongs to the lagging node, The first block chain node does not maintain the actual latest block, and the block that the first block chain node lacks compared with the normal nodes of the same period is called a lagging block, and the lagging block is
  • the allowable block height is between the local block height of the latest block locally maintained by the backward node (ie, the local latest block) and the latest block height, and the backward block includes the actual latest block block but does not contain said local latest block.
  • the size of the block cache space corresponding to any block chain node deployed by the first node device is positively related to the node weight factor of any block chain node.
  • the size of the block cache space corresponding to the block chain node is determined 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 block chain node. In one embodiment, if the size of the block cache space of any blockchain node determined by the first node device exceeds the number of backward blocks and the average size of a single block of any blockchain node The product of , it means that the size allocation of the block cache space is too large.
  • the size of the block cache space of any blockchain node can be re-determined as the number of backward blocks and the average value of a single block.
  • the product of size, wherein, the number of backward blocks of any blockchain node is the latest block height maintained by the blockchain network to which any blockchain node belongs and the height of the latest block maintained by any blockchain node. The difference between the local block heights of the local latest block.
  • the size of the block cache space may be set with upper and lower bounds, so as to constrain the size of the block cache space within a reasonable range.
  • 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 plurality of blockchain nodes.
  • the first node device can determine the node weight factor of any blockchain node it deploys in various ways.
  • the node weight factor of any blockchain node can be determined as the node cache weight corresponding to any blockchain node and the node cache weights of all blockchain nodes deployed on the first node device The ratio of the sum.
  • the first node device is deployed with the plurality of blockchain nodes, and the first node device maintains a node cache weight list, and the node cache weight list records all the locally deployed nodes of the first node device.
  • the node cache weights corresponding to the multiple blockchain nodes respectively and then when the first node device needs to calculate the node weight factor of any blockchain node deployed locally, it only needs to set the node weight factor corresponding to any blockchain node It can be obtained by dividing the node cache weight by the sum of the node cache weights of all blockchain nodes deployed locally.
  • the first node device is node device 1
  • 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 of nodeA
  • the storage resources of the node device are limited, in the embodiment 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, so as to adapt the block synchronization task of the first node device
  • the upper limit of storage that can be supported above prevents the total size of the allocated cache space of each block from exceeding the upper limit of storage resources of the first blockchain node when the blockchain nodes on the first node device are all backward nodes.
  • the first node device can also determine the node weight factor corresponding to any blockchain node as the node cache weight corresponding to any blockchain node and all nodes deployed on the first node device.
  • 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 It is currently a normal node in subnet0 and does not need to chase blocks (block synchronization), while nodeA1 and nodeA2 belong to the backward nodes in their respective subnet1 and subnet2, and needs to chase blocks, then the calculated nodeA1 at this time
  • the block cache space of the blockchain nodes that need to track blocks in the first blockchain node can be increased, so that The size of the block cache space of each blockchain node deployed in the first node device is dynamically maintained, and the upper limit of storage resources that the first node device can support in the block synchronization task is utilized as much as possible.
  • the node cache weight corresponding to each blockchain node in the node cache weight list maintained by the above-mentioned first node device may be the network weight corresponding to the blockchain network to which the respective blockchain node belongs, and the corresponding network weight of each blockchain network
  • the network weight can 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 nodes.
  • node device 1 can obtain the network weight of the blockchain main network and its managed blockchain subnets from the locally deployed main network node nodeA, such as subnet0
  • the network weight of subnet1 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 the node cache weight for the blockchain nodes deployed by itself, and specify the node cache weight of nodeA as The network weight of the blockchain network subnet0 to which nodeA belongs, the node cache weight of nodeA1 is designated as the network weight of the blockchain network subnet1 to which nodeA1 belongs, the node cache weight of nodeA2 is indicated as the network weight of subnet2, and finally these node cache weights are recorded List of node cache weights maintained locally.
  • the network weight of any blockchain network can also be recorded in the smart contract of any blockchain network, and the block in any blockchain network deployed locally by the first node device Chain nodes get this network weight.
  • the node weight factor corresponding to any blockchain node may also be directly determined as the network weight of the blockchain network to which any blockchain node belongs.
  • the first blockchain node After the first node device caches the received backward block into the block cache space corresponding to any blockchain node, the first blockchain node will read and process the block from the block cache space by itself. 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.
  • the first node device caches the received outdated block sent to any blockchain node in the block cache space corresponding to any blockchain node, and the Any one of the above-mentioned blockchain nodes reads and processes the backward block, so that the blockchain node deployed on the first node device can obtain its corresponding backward block, so as to ensure that the functions on the blockchain node are consistent with normal operation of the service.
  • this solution is equivalent to adaptively allocating the storage resources of the first node device , giving priority to the block chain nodes with larger node weight factors deployed on the first node device to occupy a larger block cache space, so that in the block chain system composed of multiple block chain networks, different blocks
  • the block current-limiting strategy corresponding to the block chain nodes in the chain network is macro-regulated, and the hierarchical design of block synchronization tasks is realized.
  • the size of the block cache space is also positively related to the degree of lag between the local block height and the latest block height.
  • the first node device may first multiply the node weight factor of any blockchain node deployed locally by the lagging degree factor to obtain the comprehensive factor corresponding to any blockchain node, and calculate any block The ratio of the comprehensive factor of the chain node to the sum of the comprehensive factors of all blockchain nodes, and finally the product of the ratio and the fixed storage size is determined as the size of the block cache space corresponding to any blockchain node,
  • the backward degree factor corresponding to any blockchain node is determined as the number of backward blocks of any blockchain node accounts for all blockchain nodes deployed on the first node device that are in a backward state.
  • the ratio of the sum of the number of backward blocks, wherein, the number of backward blocks of any blockchain node is the latest block height maintained by the blockchain network to which any blockchain node belongs and the height of any block chain The difference between the local block heights of the latest local blocks maintained by blockchain nodes.
  • the size of the block cache space is positively related to the degree of lag between the local block height and the latest block height of the actual latest block of any blockchain network, in any blockchain node
  • the greater the degree of backwardness that is, the degree of backwardness between the local block height and the latest block height of any blockchain node
  • the larger the block cache space which means that any block When a chain node lags far behind, its corresponding block cache space is also large, and as any blockchain node slowly synchronizes blocks, its lagging degree gradually shrinks, and its corresponding block cache space It will also gradually shrink.
  • the control of the block cache space in this scheme is equivalent to distinguishing the size of the block cache space of the backward nodes with different degrees of backwardness, so that the backward nodes with a greater degree of backwardness, that is, with a greater demand for block synchronization, occupy a larger space.
  • the block cache space reduces the restriction of the block current limiting strategy to complete the block tracking process faster, so that each lagging node can complete a more balanced synchronous block tracking, realizing a more intelligent dynamic Block synchronization strategy.
  • it also includes: receiving the information for the backward block that is sent periodically according to the dynamic request period when the local block height is behind the latest block height by any blockchain node. block synchronization request, and forward the block synchronization request to the normal node; wherein, the dynamic request period is negatively related to the degree of lag between the latest block height and the local block height.
  • any blockchain node deployed on the first node device will detect whether it belongs to a backward node in the blockchain network to which it belongs. Once it detects that it belongs to a backward node, it will follow the dynamic request cycle Periodically send a block synchronization request to the normal node in the blockchain network where any of the blockchain nodes is located, in order to obtain lagging blocks behind itself and complete the block chasing process. Therefore, the backward block sent by the normal node in the blockchain network of any blockchain node to the blockchain node received by the first node device is actually sent by the blockchain node The normal node is determined in response to the block synchronization request previously sent by any blockchain node.
  • 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 periodically sending a block synchronization request by the blockchain node involved in the embodiment of this specification.
  • the method is applied to the first blockchain node, and the first blockchain node dynamically maintains the local block height of the latest local block and the dynamic request period, and the dynamic request period is negatively related to the local block height and the first The degree of lag between the latest block heights of the actual latest block in the blockchain network; the method includes: Step A: In the case that the local block height is behind the latest block height, according to the dynamic
  • the request cycle periodically sends a block synchronization request for the backward block to the normal node in the first blockchain network that maintains the actual latest block, wherein the block height of the backward block is in the local area between the block height and the latest block height.
  • Step B receiving the backward block returned by the normal node in response to the block synchronization request, so as to re-determine the local latest block and the dynamic request period.
  • the first block chain node involved in the embodiment of this specification sends a block synchronization request to the normal node, which is essentially sent by the first block chain node to the first node device, and then forwarded by the first node device to normal nodes; similarly, the backward block received by the first blockchain node and returned by the normal node is actually first received by the first node device and first cached to the block corresponding to the first blockchain node cache space, and then read and receive from the block cache space by the first blockchain node.
  • the actual latest block in the first blockchain network involved in the embodiment of this specification refers to the block height of the block that passed the consensus last time in the first blockchain network.
  • the nodes process (execute the transactions in the block) and update it to the distributed ledger it maintains, so the actual latest block in the first blockchain network is also equivalent to each block in the first blockchain network The block with the largest block height among the blocks maintained by the chain node.
  • Block height once it finds that the local block height maintained by itself is less than the block height of the latest block maintained by other blockchain nodes, it considers itself to be a lagging node. On the contrary, if it finds that the local block height maintained by itself If it 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.
  • the latest local block involved in the embodiment of this specification refers to the latest local block obtained by the first blockchain node through consensus or block synchronization and maintained locally.
  • the first blockchain node detects the local block
  • the height falls behind the latest block height the local block height is less than the latest block height
  • the cycle of periodically sending the block synchronization request is the dynamic request cycle maintained on the first block chain node, and the dynamic request cycle is negatively related to the height of the local block and the actual latest block of the first block chain network.
  • the degree of lag between the latest block heights which means that the dynamic request cycle will send changes as the local block height or the latest block height changes, for example, the first blockchain node gets a new lagging block every time it is synchronized , the latest local block maintained by it will send changes, so the lag between the local block height and the latest block height will also send changes.
  • the first blockchain node also needs to update the dynamic The request cycle is updated synchronously.
  • the lagging degree of the first blockchain node ie, the first The greater the lag between the local block height of the blockchain node and the latest block height), the shorter its dynamic request cycle is, which means that the first blockchain node moves to the normal unit time when the lagging degree is large
  • the number of times the node sends block synchronization requests (the number of effective requests) will be more frequent, and as the first blockchain node slowly synchronizes the block, its lagging behind will gradually decrease, and the number of effective requests will gradually decrease.
  • the number of block requests corresponding to a block synchronization request often has an upper limit, which means that a single block synchronization request generally cannot directly complete the block chasing process. Therefore, the control of the number of effective requests in this scheme is equivalent to distinguishing the block synchronization rate of lagging nodes with different degrees of lagging behind, so that lagging nodes with a greater degree of lagging behind, that is, a greater need for block synchronization, can complete block synchronization faster , so as to reduce the proportion of lagging nodes with a relatively large degree of lagging behind in all lagging nodes in the first blockchain network as a whole, so that lagging nodes can complete a more balanced synchronous block pursuit and realize a more intelligent dynamic Block synchronization strategy.
  • the dynamic request period is also negatively related to the node weight factor of any blockchain node.
  • any blockchain node is the first blockchain node, and its corresponding node weight factor is the first node weight factor. Since the dynamic request cycle is also negatively related to the first node weight corresponding to the first blockchain node The size of the factor, so it is also possible to adjust the weight dimension of the block synchronization rate of the first blockchain node.
  • the first node weight factor can be recorded in the contract state of the smart contract in the first blockchain network, and the smart contract can be invoked by the administrator or other users of the first blockchain network to update the first
  • the node weight factor is updated, which enables the first blockchain node to dynamically adjust its own dynamic request cycle by reading the continuously updated first node weight factor on the smart contract. Since the smart contract will be deployed in the first block On each blockchain node in the blockchain network, this means that the node weight factors corresponding to each blockchain node in the first blockchain network are the same, which realizes the macro-control of the dynamic request cycle at the network level .
  • the first node weight factor is provided by the first node device where the first blockchain node is located.
  • the first node device calculates the second The calculation process of the first node weight factor corresponding to the first blockchain node corresponding to a blockchain node has been introduced in the foregoing embodiments, and will not be repeated here.
  • the first node device calculates the first node weight factor It is provided to the first blockchain node, so that the first blockchain node can dynamically adjust its own dynamic request period through the first node weight factor continuously updated by the first node device, that is, the dynamic request period is realized. Macro-control at the node level.
  • the block synchronization request involved in the embodiment of this 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 required backward block.
  • the block range is defined by the block The height is determined. For example, the local block height maintained by the first blockchain node is 1500, but 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 first block The block range of the backward block carried in the block synchronization request sent by the block chain node to the normal node can be (1500,1600], which is used to indicate that the normal node requests 100 blocks with block heights from 1501 to 1600 Block, of course, can also be (1500,1550] or (1900,2000].
  • the block range of the backward block requested by the first blockchain node does not start continuously from the local block height
  • the block range of (1900,2000] is indicated.
  • the first blockchain node will receive 100 blocks with a block height from 1901 to 2000, but due to the distributed ledger Updates need to be completed in the order of block heights, so even if the first blockchain node receives the above 100 blocks, it cannot complete the update of the distributed ledger.
  • the first blockchain node will often send to Multiple other normal nodes request backward blocks with a block range of (1500,1900], so that the first blockchain node receives 399 blocks with block heights from 1501 to 1900 returned by other normal nodes Afterwards, the 399 blocks are processed and uploaded to the chain first (block chaining is to update the block to the distributed ledger), and then the previously received 100 blocks are processed and uploaded to the chain, so that by requesting more normal nodes complete the block chasing process faster.
  • the first blockchain node in the first blockchain network detects that the block maintained by itself is behind
  • the normal node of the actual latest block periodically sends a block synchronization request for the backward block, so that the first blockchain node can obtain its corresponding backward block, so as to ensure that the functions on the first blockchain node are consistent with normal operation of the service.
  • the unit time for lagging nodes with a large degree of lag The number of effective requests is more, which enables the lagging nodes with the greater degree of lagging behind to complete the block chasing process faster, because the block synchronization request needs to consume computing resources when it is responded by a normal node, and it will also occupy the network when returning the lagging block Bandwidth resources, and the number of normal nodes and computing resources in the first blockchain network, as well as the network bandwidth resources of the first blockchain network are limited, so this solution is equivalent to giving priority to the backward nodes with a greater degree of backwardness to occupy more There are many normal node computing resources and the network bandwidth resources of the first blockchain network, that is, the computing resources of normal nodes and the network bandwidth resources of the first blockchain network are reasonably allocated.
  • the block synchronization rate of different blockchain nodes can also be macro-regulated, realizing the hierarchical design of block synchronization tasks.
  • the dynamic request period is determined in the following manner: searching for the backward interval corresponding to the backward degree, and determining the dynamic request period as a value corresponding to the backward interval; or, searching for the backward interval corresponding to the backward degree lag interval, and determine the dynamic request period as the ratio of the numerical value corresponding to the lag interval to the first node weight factor.
  • the dynamic request period will be determined according to the backward interval corresponding to the backwardness degree.
  • the dynamic request period is equal to the standard request period; or, in the case that the dynamic request period is also negatively related to the node weight factor of any blockchain node, the dynamic request period is equal to the ratio of the standard request period obtained from the search to the first node weight factor.
  • the degree of backwardness is specifically the difference between the local block height and the latest block height (that is, the number of backward blocks)
  • the relationship between the standard request cycle and the number of backward blocks is shown in Table 1.
  • Standard request cycle (unit: milliseconds) Number of lagging blocks (unit: piece) 1000 0 ⁇ 100 500 101 ⁇ 1000 200 >1000
  • the dynamic request period can be determined as 500ms; similarly, when the number of backward blocks is in the range of 101 to 1000, first find the standard request period as 500ms, and then compare it with the first node
  • the dynamic request period is 250ms by dividing the weight factor; when the number of backward blocks exceeds 1000, the standard request period is found to be 200ms, and then the dynamic request period is further determined as 100ms. It can be seen that, on the whole, the backward block The larger the number, the smaller the dynamic request period, that is, the dynamic request period is negatively related to the degree of lag, and at the same time.
  • the dynamic request period is determined in the following manner: the dynamic request period is determined as the product of a fixed request period and a lagging factor corresponding to the lagging degree; or, the dynamic requesting period is also negatively correlated with the any In the case of a node weight factor of a blockchain node, the dynamic request period is determined as the ratio of the product to the first node weight factor.
  • the lagging factor includes: the maximum number of blocks allowed for a single block synchronization request divided by the difference between the local block height and the latest block height; or, the local block The ratio of the height to the latest block height.
  • the degree of backwardness of the first blockchain node is specifically the difference between the height of the local block and the height of the latest block.
  • the greater the number of backward blocks that is, the greater the number of Hn-H1
  • the smaller the lag factor f the smaller the dynamic request period P is, that is, the dynamic request period is negatively related to the lagging degree.
  • the degree of backwardness of the first blockchain node is specifically the ratio between the height of the local block and the height of the latest block. Obviously, the greater the degree of backwardness, the greater the backwardness The smaller the factor f is, the smaller the dynamic request period P is, and the dynamic request period is also negatively related to the degree of lag.
  • the lag factor is set with a factor upper bound and/or a factor lower bound, and the factor upper bound is used to re-determine the lag factor as the The factor upper bound, the factor lower bound is used to re-determine the lagging factor as the factor lower bound if the lagging factor is lower than the factor lower bound.
  • the value range of the aforementioned lagging factor is limited, thereby indirectly restricting the value range of the dynamic request period so as to meet the actual requirements of the block synchronization task.
  • a value can be set for f The upper bound of the factor with a value of 1, so that 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, the first blockchain Although the f calculated by the node is greater than 1, it will be re-determined as 1 due to the effect of the upper bound of the factor, so as to ensure that there is a reasonable maximum value of the dynamic request period, so as to ensure that the lagging nodes can normally complete the block chasing process.
  • the dynamic request period is set with a period upper bound and/or a period lower bound, and the period upper bound is used to re-determine the dynamic request period when the dynamic request period exceeds the period upper bound is the upper bound of the period, and the lower bound of the period is used to re-determine the dynamic request period as the lower bound of the period when the dynamic request period is lower than the lower bound of the period.
  • the value range of the lagging factor can be limited, thereby indirectly restricting the range of the dynamic request period, and in the embodiment of this specification, the value range of the dynamic request period can also be directly limited , so that it meets the actual requirements of the block synchronization task.
  • the upper bound of the period includes an upper bound of a fixed period or an upper bound of a dynamic period
  • the lower bound of a period includes a lower bound of a fixed period or a lower bound of a dynamic period.
  • the upper bound of the dynamic period includes: the ratio of the maximum number of blocks allowed for a single block synchronization request to the block growth rate of the first blockchain network
  • the lower bound of the dynamic period includes: the The difference between the number of blocks requested by the block synchronization request and the maximum number of blocks currently stored in the block cache space corresponding to the first blockchain node is divided by the local block processing speed.
  • the cycle upper bound and/or the cycle lower bound can be set to a fixed value, called the fixed cycle upper bound and/or the fixed cycle lower bound, or can be set to a dynamic value, called the dynamic cycle upper bound and/or or dynamic period lower bound.
  • the block synchronization scheme involved in the embodiment of this specification will not affect the original block consensus process of the first block chain network during the implementation process, it means that during the block synchronization process, the first block The chain 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, and the block growth rate It 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.
  • the dynamic request cycle is too large, it may cause that even if each synchronization request requests M blocks, it will not be able to catch up with a waiting dynamic request
  • the first block chain node after the first block chain node receives the backward blocks returned by the normal nodes, it needs to process these blocks in the order of block height from low to high, that is, to process these blocks by itself.
  • the included transactions are then updated to the locally maintained distributed ledger, so for the first blockchain node, there is an objective local block processing speed, and at the same time, the first blockchain node will also
  • the first node device allocates a memory space dedicated to storing unprocessed blocks, that is, the aforementioned block cache space, and the first node device will first cache the received backward blocks in this block cache space,
  • the first blockchain node reads and processes blocks from the block cache space, and every time a block is processed, it will notify the first node device to remove the processed block from the block cache space , to make room for more blocks.
  • the number of requested blocks exceeds the current The limit that the block cache space can accommodate, and in order to avoid this phenomenon, it is theoretically necessary to ensure that the number of blocks requested for a block synchronization request does not exceed the maximum number of blocks remaining in the current block cache space ( It is estimated by dividing the remaining memory capacity by the average size of a single block), but since the block synchronization request is generated at the beginning of the waiting dynamic request cycle, there will still be some Blocks are processed and removed from the block cache space, which means that assuming that the number of blocks required for a newly determined block synchronization request in a certain period is M1, the area determined at the beginning of the new waiting period The maximum number of blocks currently stored in the block cache space is Z, and the local block processing speed is v, so it only needs to satisfy M1 ⁇ Z-vP, that is, the dynamic request period to be waited in this cycle
  • the dynamic period can be set as the difference between the number of blocks requested by the block synchronization request and the maximum number of blocks currently stored in the block cache space corresponding to the first blockchain node divided by At local block processing speed, thereby preventing memory overflow and block loss, while maximizing the use of block cache space vacated by block processing while waiting for a dynamic request cycle.
  • the blockchain system includes a blockchain main network and a blockchain subnet managed by it, and the node devices deployed with subnetwork nodes in the blockchain subnet are also deployed with main network nodes;
  • the first The node device maintains the network topology 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;
  • the block synchronization request Forwarding to the normal node includes: determining the forwarding path with the smallest total delay between the first node device and the target node device where the normal node is located from the network topology based on the network delay information, and transferring the The block synchronization request is forwarded to the normal node according to the determined forwarding path.
  • a node device is a hardware entity used to run a blockchain node
  • a blockchain node refers to a software process running in a node device, just like the network architecture shown in Figure 1, any area Different blockchain nodes in the blockchain network are deployed on different node devices, and the network links between the blockchain nodes are essentially the network links between corresponding node devices.
  • the blockchain network to which any blockchain node belongs is the blockchain main network subnet0
  • any blockchain node such as nodeC
  • Other main network nodes such as nodeE only need to send the message from the node device 3 where nodeC is located to the node device 5 where nodeE is located to complete the corresponding message transmission.
  • the first node device 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 Since the first node device needs to forward the block synchronization request to the normal node, the first node device needs to obtain 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 forwarding path by using the acquired forwarding path with the smallest total delay between the first node device and the target node device as routing information. The node device of the next hop, and gradually forwards to the target node device.
  • the first node device can generate the network topology among the node devices deployed with main network nodes by querying the network connection relationship of each main network node in the blockchain main network, And because 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 it is located, etc. Therefore, the first node device maintains In the network topology, in addition to the network connection relationship between each node device, it also includes the situation of the subnet nodes deployed on each node device, that is, the network topology includes the blockchain main network and each blockchain subnet. The overall network structure of the blockchain system formed.
  • the network topology involved in the embodiments of this specification refers to the connection relationship between the node devices where each main network node in the blockchain main network is located.
  • the network topology is based on the main network nodes in the blockchain main network. It is generated by the network connection relationship between them, which can be represented graphically.
  • Fig. 3 is a schematic diagram of a network topology provided by an exemplary embodiment. As shown in Fig. 3, the network topology is used to characterize the deployment of blockchain nodes on each node device, and the network topology between each node device Network link condition. Therefore, the connection relationship between the node devices shown in FIG. 3 can be regarded as a form of representation for representing the above-mentioned network topology structure.
  • the above-mentioned network topology structure can also be represented in the form of a matrix or a table. Here Do not make any restrictions.
  • the network delay information corresponding to the network topology involved in the embodiment of this specification includes: the link delay of the network link in the network topology, and/or the node device in the network topology is forwarding the message The node delay at time. As shown in FIG. 3 , the link delay of each network link included in the network topology structure and the node delay of each node device.
  • the link delay of the network link refers to the delay information required for message forwarding on the network link, for example, the link delay of the network link between node device 1 and node device 2 in Figure 3 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, specifically including the process of the node device parsing the message, checking the routing table, and forwarding the message, such as the node device in Figure 3
  • the node delay of 1 is 3, and the forwarding delay of node device 4 is 5.
  • the values corresponding to the link delay and the node delay may represent the specific delay length, and may also represent other delay indicators related to the specific delay length, but the link delay and node delay Units need to be unified.
  • the link delay 100 of the network link between node device 1 and node device 2 can be understood as 100 milliseconds (ms), that is, it takes 100 ms for a message to pass through the network link, then the node delay 3 of node device 1 should be It is understood as 3ms.
  • the forwarding path with the smallest total delay between the first node device involved in the embodiment of this specification and the target node device where the normal node is located is through the node devices where each main network node in the blockchain main network is respectively located.
  • the network topology and the network delay information corresponding to the network topology are determined.
  • the first node device needs to send a block synchronization request to the normal node, it can determine the distance between the first node device and the target node device through the locally maintained network topology structure and the network delay information.
  • the forwarding path with the least total delay is determined.
  • the first node device can determine the relative relationship between the first node device and the target node device in the network topology. In a case where the network location relationship is ensured and reachability is ensured, a forwarding path between the first node device and the target node device is generated.
  • the first node device is node device 3
  • nodeC is any one of the blockchain nodes
  • nodeE is a normal node. Now nodeC detects that it belongs to a lagging node and has waited for a dynamic request period.
  • nodeC needs to send a block synchronization request to nodeE, so nodeC sends the block synchronization request to the node device 3 where it is located.
  • node device 3 After receiving the block synchronization request, node device 3 first needs to base on the network topology maintained by itself The structure determines the forwarding path between the node device 3 (the first node device) and the node device 5 (the target node device) where nodeE is located.
  • 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; secondly, node device 3 ⁇ node device 1 ⁇ node device 4 ⁇ node device 2 ⁇ node device 5.
  • the node device 3 After the node device 3 determines the two optional forwarding paths, it further determines the forwarding path with the smallest total delay between the node device 3 and the node device 5 from the two optional forwarding paths based on the network delay information, wherein the forwarding path
  • the corresponding total delay is the link delay of at least one section of the network link from the first node device to the target node device on the forwarding path and/or at least one node device (excluding the first node device and the target node device) device) node delay sum. Therefore, when the first node device determines the total delay of the forwarding path, it may only calculate the link delay of all network links from the first node device to the target node device, or it may only calculate the link delay from the first node device to the target node device.
  • the node delays of all node devices passed by the target node device may also consider the link delays of all network links passed from the first node device to the target node device and the node delays of all the node devices passed by. For example, taking Figure 3 as an 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 node device 3 ⁇ node Device 1 ⁇ Node Device 4 ⁇ Node Device 2 ⁇ Node Device 5 The total delay of all network links and all node devices in this forwarding link path is 131, so 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.
  • node device 1 After node device 1 receives the block synchronization request, it can again determine the node with the shortest total delay between node device 1 and node device 5 based on the network topology structure maintained by node device 1 and the network delay information. Forwarding path, and the newly determined forwarding path forwards the block synchronization request for a second time, and the node device that subsequently receives the block synchronization request also follows the same process as above, first determines the new forwarding path and then follows The newly determined forwarding path forwards the block synchronization request; or, when the node device 3 forwards the block synchronization request to the node device 1, it may also carry the forwarding path determined by the node device 3 in the block synchronization request , then after receiving the block synchronization request, node device 1 can continue to find out that the next-hop node device is node device 4 based on the forwarding path carried in the block synchronization request, and The block synchronization request is forwarded to the node device 4, and the node device 4 and subsequent
  • the network delay information includes the link delay of the near-end network link and/or the link delay of the far-end network link in the network topology
  • the near-end network link is A network link between the first node device and its neighbor node device
  • the remote network link is a network link in the network topology except the near-end network link.
  • 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. Taking FIG. 3 as an example, the neighbor node device corresponding to node device 1 includes 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 .
  • the first node device For the first node device, it maintains two different types of network links, including a near-end network link and a far-end network link.
  • the near-end 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 neighbor node device;
  • the remote network link refers to the network link not connected to the first node device.
  • the network link directly connected to the node device is a network link in the network topology except the near-end network link corresponding to the first node device.
  • the near-end network link corresponding to node device 1 includes the network links between it and node device 3, node device 4, and node device 5 respectively, and the remote network link corresponding to node device 1 is It includes 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 .
  • the first node device obtains the link delay according to different strategies according to different types of network links.
  • the first node device determines the link delay of the near-end network link according to the local-end link delay and/or the opposite-end link delay; wherein, the local-end link delay is determined by the first node device through a request response mechanism
  • the near-end network link is detected, and the opposite-end link delay is obtained by the neighbor node device of the first node device detecting the near-end network link through a request response mechanism; and/or receiving the first
  • the link delay of the remote network link sent by the neighbor node device of the node device the link delay of the remote network link is sent by at least one end node device of the remote network link through a request response mechanism It is determined by the link delay obtained by detecting the remote network link.
  • the request-response mechanism involved in the embodiment 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 way: the requester sends a The request message carries the time t1, and t1 is the requester's local time recorded by the requester when sending the request message.
  • the request message and response message involved in the request-response mechanism can be dedicated messages dedicated to calculating link delays, or other ordinary normal service requests, or heartbeat messages in the network, because when calculating link delays, the response
  • the local processing time t3-t2 of the party is taken into account, so no matter what type of request message and reply message can be applied to the above request-response mechanism to make the requester measure the relative link delay.
  • the first node device determines the link delay of the near-end network link, it can be determined through the above request response mechanism. For example, the first node device may actively initiate a request response mechanism to its neighbor node device, so as to determine the link delay of the near-end network link between the first node device and the neighbor node device, which is determined by the first node device
  • the link delay of the near-end network measured through the request-response mechanism is called the local-end link delay.
  • the devices at both ends of it can measure the link delay of the network link by initiating a request response mechanism, so the first node device can also receive the link delay of its neighbors
  • the link delay of the near-end network link between the first node device and the neighbor node device measured by the node device through the request response mechanism directly obtains the link delay of the near-end network link, which is determined by the neighbor
  • the link delay of the near-end network link measured and provided by the node device to the first node device is referred to as the opposite-end link delay.
  • the first node device can obtain the link delay of a certain near-end network link through two means, so it can also choose between these two means or consider comprehensively, for example, the final result obtained by the first node device
  • the link delay of the near-end network link determined and recorded in the network delay information may include: the local link delay, the peer link delay, or the difference between the local link delay and the peer link delay. Weighted average of link delays. Wherein, when the link delay of the near-end network link is determined as the weighted average value of the local link delay and the peer link delay, the network delay information maintained by the first node device can be more robust.
  • the link delay of the near-end network link, or the peer link delay 98 measured by the node device 2 received from the node device 2 is determined as the link delay of the near-end network link, and can also be determined according to 1
  • the weight ratio of :1 determines the average value 100 of the local link delay and the peer link delay as the link delay of the near-end network link, and records it in the network delay information locally maintained by node device 1.
  • the first node device can only directly measure the link delay of the near-end network link between its neighbor node device, but cannot measure the link delay with the far-end network link, it is necessary to receive the Or the forwarded link delay sharing message containing the link delay of the remote network link, so as to directly obtain the link delay of the remote network link, and record it to the corresponding remote network link in the network delay information place.
  • 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 remote At least one end node device of the end network link is determined by the link delay obtained by detecting the remote network link through the request response mechanism.
  • the link delay of the remote network link may include: the remote The link delay detected by any end node device of the end network link, or the weighted average of the link delays detected by the node devices at both ends of the remote network link.
  • the link delay detected by any end node device is the link delay for the remote network link
  • the link delay of the remote network link is respectively 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.
  • the link delay of the remote network link between node device 2 and node device 5 cannot be directly Instead, it needs to be calculated and determined by node device 2 and/or node device 5 through the initiation request response mechanism, and node device 2 will encapsulate the final determined link delay of the remote network link into the link delay
  • the sharing message is sent or forwarded to the node device 1, and the node device 1 updates the network delay information maintained by itself based on the acquired link delay of the remote network link.
  • the first node device may receive the remote link delay measured from the neighbor node device, and in an embodiment, it also includes: receiving the response message sent by the neighbor node device of the first node device in the request response mechanism, the response The message includes the peer link delay and/or the link delay of the remote network link.
  • the peer link delay and/or the link delay of the remote network link received by the first node device can be directly carried when the first node device initiates the request response mechanism to the neighbor node device.
  • the first node device only needs to initiate a request response mechanism once to obtain the link delay of the peer end and/or the link delay of the remote network link while obtaining the link delay of the local end , thereby reducing the complexity of the interaction within the network.
  • the peer link delay and/or the link delay of the remote network link may also be carried in other messages sent or forwarded by the neighbor node device to the first node device.
  • the network delay information includes: link delays of network links in the network topology, and/or node delays of node devices in the network topology when forwarding messages.
  • it also includes: obtaining a node delay obtained by detecting any node device from at least one neighbor node device of any node device in the network topology, and determining the node delay of any node device according to the obtained node delay The node delay of the device; and/or, receiving the node delay of any node device shared by other node devices.
  • the node delay of any node device needs to be measured by any neighbor node device corresponding to any node device, specifically, it is measured by any neighbor node corresponding to any node device through backflow The message mechanism is measured.
  • the backflow message mechanism involved in the embodiment of this specification involves the interaction between the requester and the responder, and it is considered that the initiator of the backflow message mechanism is the above-mentioned requester.
  • the backflow message mechanism is specifically implemented in the following way: the requester first selects a The responder initiates a return message mechanism. First, the requester needs to construct a return message whose destination address points 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 return message sent at the same time. The requester's local time t5 at the time of the message.
  • the responder After receiving the backflow message, the responder knows that the destination address of the backflow message is the requester by looking up the routing table, so it will return the backflow message to the requester through the original route.
  • the backflow message mechanism requires that there are no other transit devices between the requester and the responder. This is because the object measured by the backflow message mechanism is the node delay of the responder's forwarded message. Therefore, adding other transit devices will result in failure to meet measurement expectations.
  • any neighbor node device of the any node device detects the any node device, including: the any neighbor node device sends a backflow message to the any node device, and through the The forwarding delay of the reflux message, the link delay of the network link between the any neighbor node device and the any node device, determine the node delay of the any node device, and the reflux message is the A message sent by a neighbor node device to the any node device with a destination address pointing to the any neighbor node device.
  • any neighbor node device of the any node device can initiate a backflow message mechanism to measure it.
  • the first node device can directly detect and obtain it by initiating a backflow message mechanism.
  • the node devices directly connected to the neighbor node device may not only include the first node device, Therefore, 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.
  • node device 1 detects that the node delay of node device 4 is 3 by initiating a return message mechanism to node device 4, and at the same time, it also receives that node device 2 initiates a return message mechanism to node device 4 to detect
  • the obtained node delay of node device 4 is 7, 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 local maintenance of node device 1
  • the network delay information of the node device 2 or determine the node delay 7 received from the node device 2 and measured by the node device 2 as the node delay of the node device 4, and record it in the network delay information locally maintained by the node device 1, and also
  • the average value 5 of the node delay 3 measured by itself and the node delay 7 measured by the node device 2 can be determined as the node delay of the node device 4 according to the weight ratio of 1:1, and it is recorded in the local maintenance of the node device 1.
  • the network delay information In the network delay information.
  • 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 in other ways, for example, the first node device A node device may directly receive the node delay of any node device shared by other node devices. Taking Figure 3 as an example, node device 1 cannot directly detect the node delay of node device 5, but node device 2 can measure it, so node device 1 can directly receive the node delay of node device 5 sent by node device 2 to node device 1. The delayed node delays sharing the message, thereby obtaining and determining that the node delay of the node device 5 is 2, and finally recording it in the local network delay information.
  • node device 1 does not necessarily need to obtain the node delay of node device 5 from node device 2.
  • the network delay information maintained by node device 4 actually includes the information of node device 5.
  • the node delay therefore, the node device 1 may also receive the node delay sharing message carrying the node delay of the node device 5 sent by the node device 4, so as to obtain the node delay of the node device 5.
  • the node delay of any node device in the network delay information maintained by the first node device includes: the node delay obtained by detecting any node device by any neighbor node device of the any node device, or the A weighted average of node delays obtained by detecting any node device by at least one neighbor node device of the above node device.
  • any neighbor node of any node device can detect the node delay of any node device, so when the first node device finally determines the node delay of any node device, it can directly use
  • the node delay for any node device detected by any neighbor node of any node device is recorded in the locally maintained network delay information, or one or more neighbor node devices of any node device can be
  • the weighted average of the node delays detected by any node device is determined as the node delay of the any node device, and is recorded in the locally maintained network delay information.
  • the node delay of any node device is finally determined as the weighted average of the node delays obtained by detecting any node device by at least one neighbor node device of the any node device, the first The network delay information maintained by node devices is more robust.
  • the node device 1 can respectively receive the node delay 1 of the node device 1 detected by the node device 3, the node delay 3 of the node device 1 detected by the node device 2, and the node delay 3 of the node device 1 detected by the node device 4.
  • Node delay 5 at this time, node device 1 can choose 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 according to the weight ratio of 3:1
  • the weighted average value 1.5 of the node delay measured by node device 3 and the node delay measured by node device 2 is determined as the node delay of node device 1 in the network delay information.
  • the weighted average 3 of the node delays of the node device 1 detected by the number of node devices is determined as the node delay of the node device 1 in the network delay information.
  • Fig. 4 is a schematic structural diagram of a device provided by an exemplary embodiment.
  • the device includes a processor 402 , an internal bus 404 , a network interface 406 , a memory 408 and a non-volatile memory 410 , and of course may include hardware required by other services.
  • the processor 402 reads a corresponding computer program from the non-volatile memory 410 into the memory 408 and then executes it.
  • 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 to say, the execution subject of the following processing flow is not limited to each A logic unit, which can also be a hardware or logic device.
  • FIG. 5 is a block diagram of a block synchronization device provided in this specification according to an exemplary embodiment.
  • the device can be applied to the device shown in FIG. 4 to implement the technical solution of this specification;
  • the device is applied to the first node device, where multiple blockchain nodes belonging to multiple blockchain networks in the blockchain system are deployed on the first node device, and the first node device maintains There is a corresponding block cache space, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively related to the node weight factor of any blockchain node.
  • the device includes: a block receiving unit 501, 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 The normal node maintains the 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 of the actual latest block between heights; the block cache unit 502 is used to cache the lagging block to the block cache space corresponding to any blockchain node, so that any blockchain node can retrieve the data from the block Read and process the lagging block in the buffer space; the block removal unit 503 is used to remove the lagging block when the lagging block has been processed by any of the blockchain nodes Remove the block cache space.
  • a block receiving unit 501 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 The normal node maintains the actual latest block, and the block height of the backward block is between
  • 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 plurality of blockchain nodes.
  • the size of the block cache space is also positively related to the degree of lag between the local block height and the latest block height.
  • a request forwarding unit 504 configured to receive the periodic sending by any blockchain node according to the dynamic request cycle when the local block height is behind the latest block height.
  • the dynamic request period is also negatively related to the node weight factor of any blockchain node.
  • the blockchain system includes a blockchain main network and a blockchain subnet managed by it, and the node devices deployed with subnetwork nodes in the blockchain subnet are also deployed with main network nodes;
  • the first The node device maintains the network topology 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;
  • the block synchronization request Forwarding to the normal node includes: determining the forwarding path with the smallest total delay between the first node device and the target node device where the normal node is located from the network topology based on the network delay information, and transferring the The block synchronization request is forwarded to the normal node according to the determined forwarding path.
  • the network delay information includes a link delay of a near-end network link and/or a link delay of a far-end network link in the network topology
  • the near-end network link is the first node A network link between a device and its neighbor node device
  • the remote network link is a network link in the network topology other than the near-end network link.
  • a link delay obtaining unit 505 configured to determine the link delay of the near-end network link according to the local-end link delay and/or the peer-end link delay; wherein, the local-end link The path delay is obtained by the first node device detecting the near-end network link through the request-response mechanism, and the opposite-end link delay is detected by the neighbor node device of the first node device through the request-response mechanism on the near-end network link.
  • the link delay of the remote network link sent by the neighbor node device of 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 remote network link It is determined by the link delay obtained by detecting the remote network link through at least one end node device of the path through the request response mechanism.
  • a response receiving unit 506 configured to receive a response message sent by a neighbor node device of the first node device in the request response mechanism, the response message including the peer link delay and/or all The link delay of the remote network link.
  • the link delay of the near-end network link includes: the local-end link delay, the peer-end link delay, or the local-end link delay and the peer-end link delay The weighted average value of the remote network link; the link delay of the remote network link, including: the link delay detected by any end node device of the remote network link, or the node device at both ends of the remote network link A weighted average of the link delays obtained from the respective detections.
  • the network delay information includes: link delays of network links in the network topology, and/or node delays of node devices in the network topology when forwarding messages.
  • a node delay obtaining unit 507 configured to obtain the node delay obtained by detecting any node device by at least one neighbor node device of any node device in the network topology, and according to the obtained The node delay determines the node delay of any node device; and/or receives the node delay of any node device shared by other node devices.
  • any neighbor node device of the any node device detecting the any node device includes: the any neighbor node device sends a backflow message to the any node device, and the backflow message is used to The forwarding delay of any neighbor node device, the link delay of the network link between the any neighbor node device and the any node device, determine the node delay of the any node device, and the return message is the The message sent by the device to any node device with a destination address pointing to any neighbor node device.
  • the node delay of any node device includes: a node delay obtained by detecting any node device by any neighbor node device of the any node device, or at least A weighted average of node delays obtained by a neighbor node device detecting any node device.
  • the improvement of a technology can be clearly distinguished as an improvement in hardware (for example, improvements in circuit structures such as diodes, transistors, and switches) or improvements in software (improvement in method flow).
  • improvements in circuit structures such as diodes, transistors, and switches
  • improvements in software improvement in method flow
  • the improvement of many current method flows can be regarded as the direct improvement of the hardware circuit structure.
  • Designers almost always get the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that the improvement of a method flow cannot be realized by hardware physical modules.
  • a programmable logic device Programmable Logic Device, PLD
  • PLD Programmable Logic Device
  • FPGA Field Programmable Gate Array
  • HDL Hardware Description Language
  • ABEL Advanced Boolean Expression Language
  • AHDL Altera Hardware Description Language
  • HDCal JHDL
  • Lava Lava
  • Lola MyHDL
  • PALASM RHDL
  • VHDL Very-High-Speed Integrated Circuit Hardware Description Language
  • Verilog Verilog
  • the controller may be implemented in any suitable way, for example the controller may take the form of a microprocessor or processor and a computer readable medium storing computer readable program code (such as software or firmware) executable by the (micro)processor , logic gates, switches, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable logic controllers and embedded microcontrollers, 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.
  • controller in addition to realizing the controller in a purely computer-readable program code mode, it is entirely possible to make the controller use logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded The same function can be realized in the form of a microcontroller or the like. Therefore, such a controller can be regarded as a hardware component, and the devices included in it for realizing various functions can also be regarded as structures within the hardware component. Or even, means for realizing various functions can be regarded as a structure within both a software module realizing a method and a hardware component.
  • the systems, devices, modules, or units described in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions.
  • a typical implementation device is a server system.
  • the present invention does not exclude that with the development of computer technology in the future, the computer that realizes the functions of the above embodiments can 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 , media players, navigation devices, email devices, game consoles, tablet computers, wearable devices, or any combination of these devices.
  • one or more embodiments of the present specification provide the operation steps of the method described in the embodiment or the flowchart, more or fewer operation steps may be included based on conventional or non-inventive means.
  • the sequence of steps enumerated in the embodiments is only one of the execution sequences of many steps, and does not represent the only execution sequence.
  • the methods shown in the embodiments or drawings can be executed sequentially or in parallel (such as a parallel processor or multi-thread processing environment, or even a distributed data processing environment).
  • These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions
  • the device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.
  • a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • Memory may include non-permanent storage in computer readable media, in the form of random access memory (RAM) and/or nonvolatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer readable media.
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash random access memory
  • Computer-readable media including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information.
  • Information may be computer readable instructions, data structures, modules of a program, 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 Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic cassettes, magnetic tape magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission medium that can be used to store information that can be accessed by computing devices.
  • computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.
  • one or more embodiments of this specification may be provided as a method, system or computer program product. Accordingly, one or more embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of the present description may employ a computer program embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein. The form of the product.
  • program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types.
  • program modules may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network.
  • program modules may be located in both local and remote computer storage media including storage devices.

Abstract

Provided in the present specification are a block synchronization method and apparatus, an electronic device and a storage medium. The method is applied to a first node device. A plurality of blockchain nodes belonging to a plurality of blockchain networks in a blockchain system are deployed on the first node device, and the first node device maintains corresponding block cache spaces for the deployed blockchain nodes, the size of the block cache space corresponding to any blockchain node being positively correlated with a node weighting factor of the blockchain node. The method comprises: receiving a lagging block sent by a normal node in a blockchain network to which any blockchain node belongs; caching the lagging block to a block cache space corresponding to any blockchain node, so that the blockchain node reads the lagging block from the block cache space and processes same; and when the lagging block is processed by the blockchain node, removing the lagging block from the block cache space.

Description

区块同步block synchronization 技术领域technical field
本说明书实施例属于区块链技术领域,尤其涉及一种区块同步方法、装置、电子设备和存储介质。The embodiments of this specification belong to the technical field of block chains, and in particular relate to a block synchronization method, device, electronic equipment, and storage medium.
背景技术Background technique
区块链(Blockchain)是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链系统中按照时间顺序将数据区块以顺序相连的方式组合成链式数据结构,并以密码学方式保证的不可篡改和不可伪造的分布式账本。由于区块链具有去中心化、信息不可篡改、自治性等特性,区块链也受到人们越来越多的重视和应用。在一些区块链网络中,部分节点有时存在实现小范围交易的需求,以避免其他节点获得这些交易及其相关数据。因此可以在区块链主网的基础上进一步建立区块链子网,且区块链主网和区块链子网均是作为独立的区块链网络。Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm. In the blockchain system, the data blocks are combined into a chained data structure in a sequentially connected manner in chronological order, and a non-tamperable and unforgeable distributed ledger is cryptographically guaranteed. Due to the characteristics of decentralization, non-tamperable information, and autonomy, the blockchain has also received more and more attention and application. In some blockchain networks, some nodes sometimes need to implement small-scale transactions to prevent other nodes from obtaining these transactions and their related data. Therefore, a blockchain subnet can be further established on the basis of the blockchain main network, and the blockchain main network and the blockchain subnet are both independent blockchain networks.
对于区块链主网或区块链子网,其所包含的各个区块链节点之间通过共识协议来确保各自维护的分布式账本的一致性。然而,当区块链节点宕机重启或有新的子网节点加入时,将导致区块链节点所维护的分布式账本中的区块数据落后于区块链网络中的正常节点,无法参与到正常的共识过程,影响区块链节点上功能与服务的运行。For the blockchain main network or blockchain subnet, the various blockchain nodes contained in it use consensus agreements to ensure the consistency of the distributed ledgers maintained by them. However, when the blockchain node 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 cannot participate To the normal consensus process, affecting the operation of functions and services on blockchain nodes.
发明内容Contents of the invention
本发明的目的在于提供一种区块同步方法、装置、电子设备和存储介质。The object of the present invention is to provide a block synchronization method, device, electronic equipment and storage medium.
根据本说明书一个或多个实施例的第一方面,提出了一种区块同步方法,应用于第一节点设备,第一节点设备上部署有区块链系统内分别属于多个区块链网络的多个区块链节点,第一节点设备针对其部署的区块链节点维护有对应的区块缓存空间,其中,第一节点设备部署的任一区块链节点对应的区块缓存空间的大小正相关于所述任一区块链节点的节点权重因子;所述方法包括:接收所述任一区块链节点所属区块链网络中的正常节点发送至所述任一区块链节点的落后区块,其中,所述正常节点维护有实际最新区块,且所述落后区块的区块高度处于所述任一区块链节点本地维护的最新区块的本地区块高度与所述实际最新区块的最新区块高度之间;将所述落后区块缓存至所述任一区块链节点对应的区块缓存空间,以由所述任一区块链节点从所述区块缓存空间中读取并处理所述落后区块;在所述落后区块由所述任一区块链节点处理完毕的情况下,将所述落后区块移除所述区块缓存空间。According to the first aspect of one or more embodiments of this specification, a block synchronization method is proposed, which is applied to a first node device, and the first node device is deployed with a block chain system belonging to multiple block chain networks multiple blockchain nodes, the first node device maintains a corresponding block cache space for its deployed blockchain nodes, wherein, the block cache space corresponding to any blockchain node deployed by the first node device The size is positively related to the node weight factor of any of the blockchain nodes; the method includes: receiving the normal node in the blockchain network to which any of the blockchain nodes belongs sends to the any of the blockchain nodes The backward block, wherein, the normal node maintains the 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 Between the latest block heights of the actual latest block; cache the lagging block to the block cache space corresponding to any blockchain node, so that any blockchain node can retrieve data from the block Reading and processing the backward block in the block cache space; when the backward block has been processed by any blockchain node, removing the backward block from the block cache space.
根据本说明书一个或多个实施例的第二方面,提出了一种区块同步装置,应用于第一节点设备,第一节点设备上部署有区块链系统内分别属于多个区块链网络的多个区块链节点,第一节点设备针对其部署的区块链节点维护有对应的区块缓存空间,其中,第一节点设备部署的任一区块链节点对应的区块缓存空间的大小正相关于所述任一区块链节点的节点权重因子;所述装置包括:区块接收单元,用于接收所述任一区块链节点所属区块链网络中的正常节点发送至所述任一区块链节点的落后区块,其中,所述正常节点维护有实际最新区块,且所述落后区块的区块高度处于所述任一区块链节点本地维护的最新区块的本地区块高度与所述实际最新区块的最新区块高度之间;区块缓存单元,用于将所述落后区块缓存至所述任一区块链节点对应的区块缓存空间,以由所述任一区块链节点从所述区块缓存空间中读取并处理所述落后区块;区块移除单元,用于在所述落后区块由所述任一区块链节点处理完毕的情况下,将所述落后区块移除所述区块缓存空间。According to the second aspect of one or more embodiments of this specification, a block synchronization device is proposed, which is applied to a first node device, and the first node device is deployed with a block chain system belonging to multiple block chain networks multiple blockchain nodes, the first node device maintains a corresponding block cache space for its deployed blockchain nodes, wherein, the block cache space corresponding to any blockchain node deployed by the first node device The size is positively related to the node weight factor of any of the blockchain nodes; the device includes: a block receiving unit, used to receive the normal nodes in the blockchain network to which any of the blockchain nodes belong The backward block of any blockchain node, wherein the normal node maintains the actual latest block, and the block height of the backward block is the latest block locally maintained by any blockchain node Between the local block height of the local block height and the latest block height of the actual latest block; the block cache unit is used to cache the backward block to the block cache space corresponding to any one of the blockchain nodes, To read and process the backward block from the block cache space by the any blockchain node; the block removal unit is used to be used by the any blockchain node in the backward block When the node finishes processing, remove the outdated block from the block cache space.
根据本说明书一个或多个实施例的第三方面,提出了一种电子设备,包括:处理器;用于存储处理器可执行指令的存储器;其中,所述处理器通过运行所述可执行指令以实现如第一方面中任一项所述的方法。According to a third aspect of one or more embodiments of the present specification, an electronic device is provided, including: a processor; a memory for storing processor-executable instructions; wherein, the processor executes the executable instructions To realize the method as described in any one of the first aspect.
根据本说明书一个或多个实施例的第四方面,提出了一种计算机可读存储介质,其上存储有计算机指令,该指令被处理器执行时实现如第一方面中任一项所述方法的步骤。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 method as described in any one of the first aspect is implemented. A step of.
在本说明书实施例中,第一节点设备通过将接收到的发送至所述任一区块链节点的落后区块缓存至所述任一区块链节点对应的区块缓存空间,并由所述任一区块链节点从中读取并处理所述落后及区块,从而使得第一节点设备上部署的区块链节点能够获取其对应的落后区块,以确保区块链节点上功能与服务的正常运行。同时,由于区块缓存空间正相关于所述任一区块链节点的节点权重因子而第一节点设备的存储资源有限,因此本方案相当于对第一节点设备的存储资源进行了适应性分配,优先让第一节点设备上部署的节点权重因子更大的区块链节点占用更大的区块缓存空间,从而在由多个区块链网络构成的区块链系统中,对不同区块链网络中的区块链节点对应的区块限流策略进行宏观调控,实现了区块同步任务的分层设计。In the embodiment of this specification, the first node device caches the received outdated block sent to any blockchain node in the block cache space corresponding to any blockchain node, and the Any one of the above-mentioned blockchain nodes reads and processes the backward block, so that the blockchain node deployed on the first node device can obtain its corresponding backward block, so as to ensure that the functions on the blockchain node are consistent with normal operation of the service. At the same time, since the block cache space is positively related to 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 block chain nodes with larger node weight factors deployed on the first node device to occupy a larger block cache space, so that in the block chain system composed of multiple block chain networks, different blocks The block current-limiting strategy corresponding to the block chain nodes in the chain network is macro-regulated, and the hierarchical design of block synchronization tasks is realized.
附图说明Description of drawings
为了更清楚地说明本说明书实施例的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本说明书中记载的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of this specification, the following will briefly introduce the drawings that need to be used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments recorded in this specification. , for those skilled in the art, other drawings can also be obtained according to these drawings without paying creative labor.
图1是一示例性实施例提供的一种基于区块链主网组建区块链子网的示意图。Fig. 1 is a schematic diagram of building a blockchain subnet based on the blockchain main network provided by an exemplary embodiment.
图2是一示例性实施例提供的一种区块同步方法的流程图。Fig. 2 is a flowchart of a block synchronization method provided by an exemplary embodiment.
图3是一示例性实施例提供的一种网络拓扑结构的示意图。Fig. 3 is a schematic diagram of a network topology provided by an exemplary embodiment.
图4是一示例性实施例提供的一种设备的结构示意图。Fig. 4 is a schematic structural diagram of a device provided by an exemplary embodiment.
图5是一示例性实施例提供的一种区块同步装置的框图。Fig. 5 is a block diagram of a block synchronization device provided by an exemplary embodiment.
具体实施方式Detailed ways
为了使本技术领域的人员更好地理解本说明书中的技术方案,下面将结合本说明书实施例中的附图,对本说明书实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本说明书一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都应当属于本说明书保护的范围。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 The embodiments are only some of the embodiments in this specification, not all of them. Based on the embodiments in this specification, all other embodiments obtained by persons of ordinary skill in the art without creative efforts shall fall within the protection scope of this specification.
由于区块链网络的去中心化特性,使得区块链网络中的所有区块链节点均会维护相同的区块数据,无法满足部分节点的特殊需求。以联盟链为例,所有联盟成员(即联盟内的节点成员)可以组成一区块链网络,所有联盟成员在该区块链网络中分别存在对应的区块链节点,并可以通过对应的区块链节点获得该区块链网络上发生的所有交易和相关数据。但在一些情况下,可能存在部分联盟成员希望完成一些具有保密需求的交易,这些联盟成员既希望这些交易能够在区块链上存证或借助于区块链技术的其他优势,又能够避免其他联盟成员查看到这些交易和相关数据。虽然这些联盟成员可以额外组建一新的区块链网络,其建立方式与上述包含所有联盟成员的区块链网络类似,但是从头开始建立一条新的区块链网络需要消耗大量的资源,且无论是该区块链网络的建立过程或是建成后的配置过程都非常耗时。联盟成员之间的需求往往是临时的或者具有一定的时效性,使得新建的区块链网络很快就会由于需求消失而失去存在的意义,从而进一步增加了上述区块链网络的建链成本。而联盟成员之间的需求经常会变化,而每一需求所对应的联盟成员也往往不同,因而每当联盟成员发生变化时就可能需要组建一新的区块链网络,从而造成资源和时间的大量浪费。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 consortium chain as an example, all consortium members (that is, node members in the consortium) can form a blockchain network, and all consortium members have corresponding blockchain nodes in the blockchain network, and can pass the corresponding zone Block chain nodes obtain all transactions and related data that occur on the block chain network. However, in some cases, there may be some alliance members who want to complete some transactions that require confidentiality. These alliance members hope that these transactions can be stored on the blockchain or take advantage of other advantages of blockchain technology, and can avoid other transactions. Affiliate members see these transactions and related data. Although these alliance members can additionally form a new blockchain network, the establishment method is similar to the above-mentioned blockchain network that includes all alliance members, but building a new blockchain network from scratch requires a lot of resources, and regardless of The establishment process of the blockchain network or the configuration process after completion is very time-consuming. The needs among alliance members are often temporary or have a certain timeliness, so that the newly built blockchain network will soon lose the meaning of existence due to the disappearance of demand, thus further increasing the chain construction cost of the above-mentioned blockchain network . However, the needs of alliance members often change, and the alliance members corresponding to each demand are often different. Therefore, whenever the alliance members change, it may be necessary to form a new blockchain network, resulting in resource and time constraints. A lot of waste.
为此,可以将已组建的区块链网络作为区块链主网,并在该区块链主网的基础上组建区块链子网。那么,在诸如上述的联盟链场景下,联盟成员可以在已经参与区块链主网的情况下,基于自身需求而在区块链主网的基础上组建所需的区块链子网。由于区块链子网是在区块链主网的基础上所建立,使得区块链子网的组建过程相比于完全独立地组建一条区块链网络,所消耗的资源和所需的耗时等都极大地降低,灵活性极高。To this end, the established blockchain network can be used as the blockchain main network, and a blockchain subnet can be formed on the basis of the blockchain main network. Then, in the consortium chain scenario such as the one mentioned above, the consortium members can build the required blockchain subnet based on their own needs while already participating in the blockchain main network. Since the blockchain subnet is established on the basis of the blockchain main network, the construction process of the blockchain subnet is compared to the completely independent establishment of a blockchain network, the resources consumed and the time required, etc. Both are greatly reduced, and the flexibility is extremely high.
基于区块链主网快捷组建区块链子网的过程如下:区块链主网中的各区块链节点分别获取组建区块链子网的交易,所述交易包含所述区块链子网的配置信息,所述配置信息包括参与组建所述区块链子网的节点成员的身份信息,所述区块链主网中的各区块链节点分别执行所述交易以透出所述配置信息,当所述配置信息包含第一区块链节点对应的节点成员的身份信息时,部署第一区块链节点的节点设备基于所述包含所述配置信息的创世块启动属于所述区块链子网的第二区块链节点。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 obtains a transaction for establishing a blockchain subnet, and the transaction includes the configuration information of the blockchain subnet , the configuration information includes the identity information of the node members participating in the formation of the block chain subnet, each block chain node in the block chain main network respectively executes the transaction to disclose the configuration information, when the When the configuration information includes the identity information of the node members corresponding to the first block chain node, the node device deploying the first block chain node starts the first block belonging to the block chain subnet based on the genesis block containing the configuration information. Two blockchain nodes.
以图1所示为例,区块链主网为subnet0,该subnet0包含的区块链节点为nodeA、nodeB、nodeC、nodeD和nodeE等。假定nodeA、nodeB、nodeC和nodeD希望组建一区块链子网:如果nodeA为管理员且仅允许管理员发起组建区块链子网的交易,那么可由nodeA向subnet0发起上述组建区块链子网的交易;如果nodeE为管理员且仅允许管理员发起组建区块链子网的交易,那么nodeA~nodeD需要向nodeE进行请求,使得nodeE向subnet0发起上述组建区块链子网的交易;如果nodeE为管理员但允许普通用户发起组建区块链子网的交易,那么nodeA~nodeE均可以向subnet0发起上述组建区块链子网的交易。当然,不论是管理员或者普通用户,发起组建区块链子网的交易的区块链节点并不一定参与所组建的区块链子网,比如虽然最终由nodeA、nodeB、nodeC和nodeD组建区块链子网,但可由nodeE向subnet0发起上述组建区块链子网的交易,而并不一定由nodeA~nodeD来发起该组建区块链子网的交易。Taking Figure 1 as an 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 allows the administrator to initiate a transaction 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 allows the administrator to initiate the transaction of establishing a blockchain subnet, then nodeA~nodeD needs to make a request to nodeE, so that nodeE initiates the above transaction of establishing a blockchain subnet to subnet0; if nodeE is an administrator but allows Ordinary users initiate a transaction to establish a blockchain subnet, then nodeA~nodeE can initiate the above transaction to subnet0 to establish a blockchain subnet. 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 established blockchain subnet. network, but nodeE can initiate the above-mentioned transaction of establishing a blockchain subnet to subnet0, and nodeA~nodeD may not necessarily initiate the transaction of establishing a blockchain subnet.
在区块链主网的基础上组建区块链子网时,容易理解的是,会使得该区块链子网与区块链主网之间存在逻辑上的层次关系。比如在图1所示的subnet0上组建区块链子网subnet1时,可以认为subnet0处于第一层、subnet1处于第二层。一种情况下,本说明 书中的区块链主网可以为底层区块链网络,即区块链主网并非在其他区块链网络的基础上组建的区块链子网,比如图1中的subnet0可以认为属于底层区块链网络类型的区块链主网。另一种情况下,本说明书中的区块链主网也可以为其他区块链网络的子网,比如可以在图1中subnet1的基础上进一步组建另一区块链子网,此时可以认为subnet1为该区块链子网对应的区块链主网,而这并不影响该subnet1同时属于subnet0上创建的区块链子网。可见,区块链主网与区块链子网实际上是相对概念,同一区块链网络在一些情况下可以为区块链主网、另一些情况下可以为区块链子网。When a blockchain subnet is established on the basis of the blockchain main network, it is easy to understand that there will be a logical hierarchical relationship between the blockchain subnet and the blockchain main network. For example, when a blockchain subnet subnet1 is established on subnet0 shown in Figure 1, it can be considered that subnet0 is at the first layer and subnet1 is at 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 formed on the basis of other blockchain networks, such as the subnet0 can be regarded as the blockchain mainnet belonging to the underlying blockchain network type. In another case, the blockchain main network in this specification can also be a subnet of other blockchain networks. For example, another blockchain subnet can be further established on the basis of subnet1 in Figure 1. At this time, it can be considered subnet1 is the blockchain main network corresponding to the blockchain subnet, and this does not affect that subnet1 also belongs to the blockchain subnet created on subnet0. It can be seen that the blockchain main network and the blockchain subnet are actually relative concepts. The same blockchain network can be the blockchain main network in some cases and the blockchain subnet in other cases.
上述组建区块链子网的交易在被发送至区块链主网后,由区块链主网内的共识节点进行共识,并在通过共识后由各主网节点执行该交易,以完成区块链子网的组建。共识过程取决于所采用的共识机制,本说明书并不对此进行限制。After the above-mentioned transaction for establishing a blockchain subnet is sent to the blockchain main network, the consensus nodes in the blockchain main network will conduct a consensus, and after the consensus is passed, each main network node will execute the transaction to complete the block The formation of the chain subnet. The consensus process depends on the adopted consensus mechanism, which is not limited in this specification.
通过在上述组建区块链子网的交易中包含配置信息,该配置信息可以用于对所组建的区块链子网进行配置,使得组建的区块链子网符合组网需求。例如,通过在配置信息中包含节点成员的身份信息,可以指定组建的区块链子网包含哪些区块链节点。By including the configuration information in the above-mentioned transaction of establishing the blockchain subnet, the configuration information can be used to configure the established blockchain subnet so that the established blockchain subnet meets the networking requirements. For example, by including the identity information of node members in the configuration information, it is possible to specify which blockchain nodes are included in the established blockchain subnet.
节点成员的身份信息可以包括节点的公钥,或者采用节点ID等其他能够表征节点身份的信息,本说明书并不对此进行限制。以公钥为例,每个区块链节点都存在对应的一组或多组公私钥对,由区块链节点持有私钥而公钥被公开且唯一对应于该私钥,因而可以通过公钥来表征相应区块链节点的身份。因此,对于希望作为区块链子网的节点成员的区块链节点,可以将这些区块链节点的公钥添加至上述组建区块链子网的交易中,以作为上述节点成员的身份信息。上述的公私钥对可以用于签名验证的过程。例如,在采用有签名的共识算法中,譬如subnet1上述的nodeA1采用自身维护的私钥对消息进行签名后,将经过签名的消息在subnet1中广播,而nodeB1、nodeC1和nodeD1可以用nodeA1的公钥对收到的消息进行签名验证,以确认自身收到的消息确实来自nodeA1且没有经过篡改。The identity information of the node members may include the public key of the node, or other information that can represent the identity of the node such as the node ID, which is not limited in this description. Taking the public key as an example, each blockchain node has one or more sets of corresponding public-private key pairs. The blockchain node holds the private key and the public key is public and uniquely corresponds to the private key. Therefore, it can be passed The public key is used to represent the identity of the corresponding blockchain node. Therefore, for blockchain nodes that want to be node members of the blockchain subnet, the public keys of these blockchain nodes can be added to the above-mentioned transaction of forming the blockchain subnet as the identity information of the above-mentioned node members. The above-mentioned public-private key pair can be used in the process of signature verification. For example, in a consensus algorithm with a signature, for example, nodeA1 in subnet1 uses its own private key to sign the message, and then broadcasts the signed message in subnet1, while nodeB1, nodeC1 and nodeD1 can use the public key of nodeA1 Signature verification is performed on the received message to confirm that the message received by itself is indeed from nodeA1 and has not been tampered with.
第一主网节点可以为区块链主网上属于配置信息所指示的节点成员的区块链节点。在组建区块链子网时,并非由第一主网节点直接参与组建区块链子网、成为其节点成员,而是需要由用于部署该第一主网节点的节点设备生成第一子网节点,并由第一子网节点成为区块链子网中的节点成员。第一主网节点和第一子网节点对应于同一个区块链成员,比如在联盟链场景下对应于同一联盟链成员,但第一主网节点属于区块链主网、第一子网节点属于区块链子网,使得该区块链成员可以分别参与到区块链主网和区块链子网的交易中;并且,由于区块链主网和区块链子网属于相互独立的两个区块链网络,使得第一主网节点生成的区块与第一子网节点生成的区块分别存入所述节点设备上的不同存储(采用的存储譬如可以为数据库),实现了第一主网节点与第一子网节点分别使用的存储之间的相互隔离,因而区块链子网所产生的数据仅会在区块链子网的节点成员之间同步,使得仅参与了区块链主网的区块链成员无法获得区块链子网上产生的数据,实现了区块链主网与区块链子网之间的数据隔离,满足了部分区块链成员(即参与区块链子网的区块链成员)之间的交易需求。The first main network node may be a blockchain node on the blockchain main network that is a node member indicated by the configuration information. When building a blockchain subnet, instead of the first main network node directly participating in the establishment of the blockchain subnet and becoming its node member, the first subnet node needs to be generated by the node device used to deploy the first main network node , and the first subnetwork node becomes a node member in the blockchain subnetwork. 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 The node belongs to the blockchain subnet, so that the blockchain members 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 network, so that 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 device (the storage used can be a database, for example), realizing the first The storage used by the main network node and the first subnet node is isolated from each other, so the data generated by the blockchain subnet will only be synchronized among the node members of the blockchain subnet, so that only those who participate in the blockchain main The blockchain members of the network cannot obtain the data generated on the blockchain subnet, which realizes the data isolation between the blockchain main network and the blockchain subnet, and satisfies the requirements of some blockchain members (that is, the districts participating in the blockchain subnet). Transaction requirements between blockchain members).
可见,第一主网节点和第一子网节点是在逻辑上划分出来的区块链节点,而从物理设备的角度来说,相当于上述部署了第一主网节点和第一子网节点的节点设备同时参与了区块链主网和区块链子网。由于区块链主网与区块链子网之间相互独立,使得这两个区块链网络的身份体系也相互独立,因而即便第一主网节点和第一子网节点可以采用完全相同的公钥,仍然应当将两者视为不同的区块链节点。譬如在图1中,subnet0中的nodeA相当于第一主网节点,而部署该nodeA的节点设备生成了属于subnet1的nodeA1,该nodeA1相当于第一子网节点。可见,由于身份体系相互独立,所以即便第一子网节点所采用的公钥区别于第一主网节点,也不影响本说明书方案的实施。It can be seen that the first main network node and the first subnet node are logically divided blockchain nodes, and from the perspective of physical equipment, it is equivalent to deploying the first main network node and the first subnet node The node devices participate in the blockchain main network and the blockchain subnet at the same time. 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, so even if the first main network node and the first subnet node can use exactly the same public key, the two should still be considered as different blockchain nodes. For example, in FIG. 1 , nodeA in subnet0 is equivalent to the first main network node, and the node device deploying the nodeA generates nodeA1 belonging to subnet1, and the nodeA1 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 will not affect the implementation of the scheme in this specification.
当然,区块链子网的节点成员并不一定只是区块链主网的部分节点成员。在一些情况下,区块链子网的节点成员可以与区块链主网的节点成员完全一致,此时所有的区块链成员都可以获得区块链主网和区块链子网上的数据,但是区块链主网与区块链子网所产生的数据依然可以相互隔离,比如可以通过在区块链主网上实现一类业务、在区块链子网上实现另一类业务,从而可以使得这两类业务分别产生的业务数据之间相互隔离。Of course, the node members of the blockchain subnet are not necessarily only part 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 the 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, by implementing one type of business on the blockchain main network and another type of business on the blockchain subnet, the two types of The business data generated by the business are isolated from each other.
除了上述的节点成员的身份信息之外,配置信息还可以包括下述至少之一:所述区块链子网的网络标识、所述区块链子网的管理员的身份信息、针对区块链平台代码的属性配置等,本说明书并不对此进行限制。网络标识用于唯一表征该区块链子网,因而该区块链子网的网络标识应当区别于区块链主网和该区块链主网上组建的其他区块链子网。区块链子网的管理员的身份信息,譬如可以为作为管理员的节点成员的公钥;其中,区块链主网与区块链子网的管理员可以相同,也可以不同。In addition to the above-mentioned identity information of node members, 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 The attribute configuration of the code, etc., is not limited in this specification. The network identifier is used to uniquely represent the blockchain subnet, so the network identifier of the blockchain subnet should be distinguished from the blockchain main network and other blockchain subnets formed 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; the administrators of the blockchain main network and the blockchain subnet can be the same or different.
通过区块链主网来组建区块链子网的优势之一,就是由于生成第一子网节点的节点设备上已经部署了第一主网节点,因而可以将第一主网节点所使用的区块链平台代码复用在第一子网节点上,免去了区块链平台代码的重复部署,极大地提高了区块链子网的组建效率。那么,如果配置信息中未包含针对区块链平台代码的属性配置,第一子网节点可以复用第一主网节点上采用的属性配置;如果配置信息中包含了针对区块链平台代码的属性配置,第一子网节点可以采用该属性配置,使得第一子网节点所采用的属性配置不受限于第一主网节点的属性配置、与第一主网节点无关。针对区块链平台代码的属性配置可以包括下述至少之一:代码版本号、是否需要共识、共识算法类型、区块大小等,本说明书并不对此进行限制。One of the advantages of building a blockchain subnet through the blockchain mainnet is that since the first mainnet node has already been deployed on the node device that generates the first subnetwork node, the area used by the first mainnet node can be The block chain platform code is reused on the first subnet node, which eliminates the repeated deployment of the block chain platform code and greatly improves the efficiency of the block chain subnet. Then, if the configuration information does not include the attribute configuration for the blockchain platform code, the first subnet node can reuse the attribute configuration adopted on the first main network node; if the configuration information includes the attribute configuration for the blockchain platform code attribute configuration, the first subnetwork node can adopt the attribute configuration, so that the attribute configuration adopted by the first subnetwork node is not limited to the attribute configuration of the first main network node, and has nothing to do with the first main network node. The attribute configuration for the blockchain platform code can include at least one of the following: code version number, whether consensus is required, consensus algorithm type, block size, etc., which are not limited in this specification.
组建区块链子网的交易包括调用合约的交易。该交易中可以指明被调用的智能合约的地址、调用的方法和传入的参数。例如,调用的合约可以为前述的创世合约或系统合约,调用的方法可以为组建区块链子网的方法,传入的参数可以包括上述的配置信息。在一实施例中,该交易可以包含如下信息:Transactions that form blockchain subnets include transactions that call contracts. The transaction can specify the address of the called smart contract, the method called and the parameters passed in. For example, the invoked contract can be the aforementioned genesis contract or system contract, the invoked method can be a method for building a blockchain subnet, and the incoming parameters can include the above-mentioned configuration information. In one embodiment, the transaction may contain the following information:
from:Administratorfrom: Administrator
to:Subnetto: Subnet
method:AddSubnet(string)method: AddSubnet(string)
string:genesisstring: genesis
其中,from字段为该交易的发起方的信息,譬如Administrator表明该发起方为管理员;to字段为被调用的智能合约的地址,譬如该智能合约可以为Subnet合约,则to字段具体为该Subnet合约的地址;method字段为调用的方法,譬如在Subnet合约中用于组建区块链子网的方法可以为AddSubnet(string),而string为AddSubnet()方法中的参数,上述示例中通过genesis表征该参数的取值,该genesis具体为前述的配置信息。Among them, the from field is the information of the initiator of the transaction. For example, Administrator indicates that the initiator is an administrator; the to field is the address of the called smart contract. For example, the smart contract can be a Subnet contract, and the to field is specifically the Subnet The address of the contract; the method field is the calling method. For example, the method used to build a blockchain subnet in the Subnet contract can be AddSubnet(string), and string is the parameter in the AddSubnet() method. In the above example, genesis is used to represent the The value of the parameter, the genesis is specifically the aforementioned configuration information.
以Subnet0上的节点nodeA~nodeE执行调用Subnet合约中AddSubnet()方法的交易为例。在交易通过共识后,nodeA~nodeE分别执行AddSubnet()方法并传入配置信息,得到相应的执行结果。Take nodes nodeA~nodeE on Subnet0 executing a transaction calling the AddSubnet() method in the Subnet contract as an example. After the transaction passes the consensus, nodeA~nodeE respectively execute the AddSubnet() method and pass in the configuration information to obtain the corresponding execution results.
区块链网络中的节点在执行调用智能合约的交易后,会生成相应的收据(receipt),以用于记录与执行该智能合约相关的信息。这样,可以通过查询交易的收据来获得合约执行结果的相关信息。合约执行结果可以表现为收据中的事件(event)。消息机制可以通过收据中的事件实现消息传递,以触发区块链节点执行相应的处理。事件的结构譬如可以为:After the nodes in the blockchain network execute the transaction that invokes the smart contract, they will generate a corresponding receipt (receipt), which is used to record information related to the execution of the smart contract. In this way, information about the contract execution result can be obtained by querying the receipt of the transaction. Contract execution results can be expressed as events in receipts. The message mechanism can implement message delivery through events in the receipt to trigger blockchain nodes to perform corresponding processing. The structure of an event can be, for example:
Event:Event:
[topic][data][topic][data]
[topic][data][topic][data]
...... …
在上述示例中,事件的数量可以为一个或多个;其中,每个事件分别包括主题(topic)和数据(data)等字段。区块链节点可以通过监听事件的topic,从而在监听到预定义的topic的情况下,执行预设处理,或者从相应事件的data字段读取相关内容,以及可以基于读取的内容执行预设处理。In the above example, there may be one or more events; each event includes fields such as topic and data. Blockchain nodes can listen to the topic of the event to perform preset processing when listening to a predefined topic, or read relevant content from the data field of the corresponding event, and can execute preset based on the read content deal with.
上述的事件机制中,相当于在监听方(比如存在监听需求的用户)处存在具有监听功能的客户端,譬如该客户端上运行了用于实现监听功能的SDK等,由该客户端对区块链节点产生的事件进行监听,而区块链节点只需要正常生成收据即可。除了上述的事件机制之外,还可以通过其他方式实现交易信息的透出。例如,可以通过在区块链节点运行的区块链平台代码中嵌入监听代码,使得该监听代码可以监听区块链交易的交易内容、智能合约的合约状态、合约产生的收据等其中的一种或多种数据,并将监听到的数据发送至预定义的监听方。由于监听代码部署于区块链平台代码中,而非监听方的客户端处,因而相比于事件机制而言,这种基于监听代码的实现方式相对更加的主动。其中,上述的监听代码可以由区块链平台的开发人员在开发过程中加入区块链平台代码,也可以由监听方基于自身的需求而嵌入,本说明书并不对此进行限制。In the above event mechanism, it is equivalent to the presence of a client with monitoring function at the listening party (such as a user with a monitoring requirement). The events generated by the block chain nodes are monitored, and the block chain nodes only need to generate receipts normally. In addition to the above-mentioned event mechanism, transaction information disclosure can also be realized in other ways. For example, the monitoring code can be embedded in the blockchain platform code running on the blockchain node, so that the monitoring code can monitor the transaction content of the blockchain transaction, the contract status of the smart contract, the receipt generated by the contract, etc. or multiple types of data, and send the monitored data to a predefined listener. Since the monitoring code is deployed in the blockchain platform code instead of the client of the listening party, this implementation based on the monitoring code is relatively more active than the event mechanism. Among them, the above monitoring code can be added to the blockchain platform code by the developers of the blockchain platform during the development process, or can be embedded by the monitoring party based on its own needs, which is not limited in this manual.
可见,上述Subnet合约的执行结果可以包括所述配置信息,该执行结果可以处于前文所述的收据中,该收据中可以包含与执行AddSubnet()方法相关的event,即组网事件。组网事件的topic可以包含预定义的组网事件标识,以区别于其他的事件。譬如在与执行AddSubnet()方法相关的event中,topic的内容为关键词subnet,且该关键词区别于其他方法所产生event中的topic。那么,nodeA~nodeE通过监听生成的收据中各个event所含的topic,可以在监听到包含关键词subnet的topic的情况下,确定监听到与执行AddSubnet()方法相关的event,即组网事件。例如,收据中的event如下: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 included in the above-mentioned receipt, and the receipt may include an event related to the execution of the AddSubnet() method, that is, a networking event. The topic of networking events can contain predefined networking event identifiers to distinguish them 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 this keyword is different from the topic in the event generated by other methods. Then, by monitoring the topics contained in each event in the generated receipt, nodeA~nodeE can determine to monitor the event related to the execution of the AddSubnet() method, that is, the networking event, when the topic containing the keyword subnet is monitored. For example, the event in the receipt is as follows:
Event:Event:
[topic:other][data][topic:other][data]
[topic:subnet][data][topic:subnet][data]
...... …
那么,nodeA~nodeE在监听到第1条event时,由于所含topic的内容为other,确定该event与AddSubnet()方法无关;以及,nodeA~nodeE在监听到第2条event时,由于所含topic的内容为subnet,确定该event与AddSubnet()方法相关,并进而读取该event对应的data字段,该data字段包含上述的配置信息。以配置信息包括区块链子网的节点成员的公钥为例,data字段的内容例如可以包括:Then, when nodeA~nodeE listens to the first event, because the content of the included topic is other, it is determined that the event has nothing to do with the AddSubnet() method; and, when nodeA~nodeE listens to the second event, because the content of the included The content of the topic is subnet, determine that the event is related to the AddSubnet() method, and then read 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, for example:
{subnet1;{subnet1;
nodeA的公钥,nodeA的IP、nodeA的端口号…;The public key of nodeA, the IP of nodeA, the port number of nodeA...;
nodeB的公钥,nodeB的IP、nodeB的端口号…;public key of nodeB, IP of nodeB, port number of nodeB...;
nodeC的公钥,nodeC的IP、nodeC的端口号…;The public key of nodeC, the IP of nodeC, the port number of nodeC...;
nodeD的公钥,nodeD的IP、nodeD的端口号…;The public key of nodeD, the IP of nodeD, the port number of nodeD...;
}}
其中,subnet1为希望创建的区块链子网的网络标识。区块链主网中的各个区块链节点可以记录该区块链主网上已创建的所有区块链子网的网络标识,或者与这些区块链子网相关的其他信息,这些信息譬如可以维护在上述的Subnet合约中,具体可以对应于该Subnet合约所含的一个或多个合约状态的取值。那么,nodeA~nodeE可以根据记录的已创建的所有区块链子网的网络标识,确定上述的subnet1是否已经存在;如果不存在,说明subnet1是当前需要创建的新区块链子网,如果存在则说明subnet1已经存在。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, such information can be maintained in In the above-mentioned Subnet contract, it may specifically correspond to the values of one or more contract states included in the Subnet contract. Then, nodeA~nodeE can determine whether the above-mentioned subnet1 already exists according to the recorded network identifiers of all 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 currently, and if it exists, it means that subnet1 already exists.
除了采用希望创建的新的区块链子网的网络标识之外,还可以采用预定义的新建网络标识,该新建网络标识表明相应的组网事件用于组建新的区块链子网。例如,可以将上述的subnet1替换为newsubnet,该newsubnet为预定义的新建网络标识,nodeA~nodeE在识别到data字段包含newsubnet时,即可确定包含该newsubnet的event为组网事件,需要创建新的区块链子网。In addition to adopting 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, they can determine that the event containing this newsubnet is a networking event, and a new one needs to be created. Blockchain subnet.
除了网络标识subnet1之外,上述data字段中还包含各个节点成员的身份信息等内容。部署第一主网节点的节点设备可以监听生成的收据,并在监听到所述组网事件且所述组网事件的内容表明第一主网节点属于所述节点成员的情况下,由部署第一主网节点的节点设备获取所述组网事件包含的配置信息或创世块。或者,第一区块链节点可以监听生成的收据,并在监听到所述组网事件且所述组网事件的内容表明第一区块链节点属于所述节点成员的情况下,触发部署第一区块链节点的节点设备获取所述组网事件包含的所述配置信息或所述创世块。In addition to the network identifier subnet1, the above data field also includes identity information of each node member and so on. The node device deploying 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 deployment second A node device of a main network node obtains the configuration information or the genesis block included 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, trigger the deployment of the first blockchain node. A node device of a blockchain node obtains the configuration information or the genesis block included in the networking event.
如前所述,节点设备可以直接监听收据。假定nodeA~nodeE分别部署在节点设备1~5上,节点设备1~5可以监听nodeA~nodeE分别生成的收据,那么在监听到subnet1是需要新组建的区块链子网的情况下,节点设备1~5会进一步识别data字段中包含的节点成员的身份信息,以确定自身的处理方式。以nodeA和节点设备1为例:如果节点设备1发现data字段包含nodeA的公钥、IP地址和端口号等身份信息,那么节点设备1在基于上述的消息机制从data字段获得配置信息的情况下,生成包含该配置信息的创世块,且节点设备1会在本地部署nodeA1,进而由nodeA1加载生成的创世块,从而成为subnet1的子网节点;类似地,节点设备2可以生成nodeB1、节点设备3可以生成nodeC1、节点设备4可以生成nodeD1。以及,节点设备5会发现data字段包含的身份信息与自身均不匹配,则该节点设备5不会根据data字段中的配置信息生成创世块,也不会生成subnet1中的区块链节点。As mentioned earlier, node devices can listen for receipts directly. Assuming that nodeA~nodeE are respectively deployed on node devices 1~5, and node devices 1~5 can monitor the receipts generated by nodeA~nodeE respectively, then when it is detected that subnet1 is a blockchain subnet that needs to be newly established, node device 1 ~5 will further identify the identity information of the node members contained in the data field to determine its own processing method. Take nodeA and node device 1 as an example: if node device 1 finds that the data field contains identity information such as nodeA's public key, IP address, and port number, then node device 1 obtains configuration information from the data field based on the above message mechanism , generate a genesis block containing the configuration information, and node device 1 will deploy nodeA1 locally, and then nodeA1 will load the generated genesis block, thus 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. And, 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.
如前所述,区块链主网中的区块链节点可以监听收据,并根据监听结果触发节点设备执行相关处理。例如,nodeA~nodeE在确定subnet1是需要新组建的区块链子网的情况下,会进一步识别data字段中包含的节点成员的身份信息,以确定自身的处理方式。比如,nodeA~nodeD会发现在data字段包含自身的公钥、IP地址和端口号等身份信息,假定nodeA~nodeD分别部署在节点设备1~4上,以nodeA和节点设备1为例:nodeA会触发节点设备1,使得节点设备1基于上述的消息机制从data字段获得配置信息并生成包含该配置信息的创世块,且节点设备1会在本地部署nodeA1,该nodeA1加载生成的创世块,从而成为subnet1中的1个子网节点;类似地,nodeB会触发节点设备2生成nodeB1、nodeC会触发节点设备3生成nodeC1、nodeD会触发节点设备4生成nodeD1。以及,nodeE会发现data字段包含的身份信息与自身均不匹配,假定nodeE部署在节点设备5上,那么该节点设备5不会根据data字段中的配置信息生成创世块,也不会生成 subnet1中的节点。As mentioned above, the blockchain nodes in the blockchain main network can monitor receipts and trigger node devices to perform related processing according to the monitoring results. For example, nodeA~nodeE will further identify the identity information of the node members contained in the data field in order to determine their own processing methods when they determine that subnet1 is a blockchain subnet that needs to be newly established. For example, nodeA~nodeD will find that the data field contains their own identity information such as their public key, IP address, and port number. Assume 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-mentioned message mechanism and generates a genesis block containing the configuration information, and node device 1 will deploy nodeA1 locally, and nodeA1 will load the generated genesis block, Thus, it becomes 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. And, 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 the node device 5 will not generate a genesis block based on the configuration information in the data field, nor will it generate subnet1 nodes in .
如前所述,第一主网节点与第一子网节点并不一定采用相同的身份信息。因此,在上述实施例中,data字段中可以包含预先为nodeA1~nodeD1生成的身份信息,且区别于nodeA~nodeD的身份信息。仍以nodeA和节点设备1为例:节点设备1如果在data字段中发现了nodeA1的身份信息,可以生成创世块、部署nodeA1,并由nodeA1加载该创世块;或者,nodeA如果在data字段中发现了nodeA1的身份信息,那么nodeA会触发节点设备1生成创世块、部署nodeA1,并由nodeA1加载该创世块。其他区块链节点或节点设备的处理方式类似,此处不再一一赘述。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 generated in advance for nodeA1-nodeD1, which is different from the identity information of nodeA-nodeD. Still take 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 is in the data field If the identity information of nodeA1 is found in , 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.
除了配置信息之外,合约的执行结果可以包括创世块。换言之,除了可以在data字段中包含配置信息,还可以直接在执行合约调用的过程中生成包含配置信息的创世块,从而将创世块包含于data字段中,那么对于上述的nodeA~nodeD而言,相应的节点设备1~4可以通过消息机制直接从data字段获得创世块,而无需自行生成,可以提升对nodeA1~nodeD1的部署效率。In addition to configuration information, the execution result of the contract can include the genesis block. In other words, in addition to including configuration information in the data field, you can also directly generate a genesis block containing configuration information in the process of executing the contract call, so that the genesis block is included in the data field, then for the above nodeA ~ nodeD and In other words, the corresponding node devices 1-4 can directly obtain the genesis block from the data field through the message mechanism without generating it by themselves, which can improve the deployment efficiency of nodeA1-nodeD1.
节点设备通过在该进程中创建一个运行区块链平台代码的实例,实现在该节点设备上部署一区块链节点。对于第一主网节点而言,由节点设备在上述进程中创建第一实例,并由该第一实例运行区块链平台代码而形成。类似地,对于第一子网节点而言,由节点设备在上述进程中创建区别于第一实例的第二实例,并由该第二实例运行区块链平台代码而形成。例如,节点设备可以首先在进程中创建第一实例,以形成区块链主网中的第一区块链节点;而当该节点设备对应的节点成员希望参与组建区块链子网时,可以在上述进程中创建第二实例,该第二实例区别于上述的第一实例,并由该第二实例形成区块链子网中的第二区块链节点。当第一实例与第二实例位于同一进程时,由于不涉及跨进程交互,可以降低对第一子网节点的部署难度、提高部署效率;当然,第二实例也可能与第一实例分别处于节点设备上的不同进程中,本说明书并不对此进行限制;例如,节点设备可以在第一进程中创建第一实例,以形成区块链主网中的第一区块链节点;而当该节点设备对应的节点成员希望参与组建区块链子网时,可以启动区别于第一进程的第二进程,并在该第二进程中创建第二实例,该第二实例区别于上述的第一实例,进而由该第二实例形成区块链子网中的第二区块链节点。事实上,本说明书实施例中涉及的任一节点设备上部署的各区块链节点均为运行在所述任一节点设备上的不同的区块链实例,任一节点设备上部署的各区块链节点生成的区块分别存入所述任一节点设备上的不同存储(例如数据库),且任一节点设备部署的各区块链节点分别使用的存储之间相互隔离。The node device implements the deployment of a blockchain node on the node device by creating an instance of running the blockchain platform code in the process. For the first main network node, the node device creates the first instance in the above process, and the first instance runs the blockchain platform code to form. Similarly, for the first subnetwork 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 to form. For example, the node device can first create the first instance in the process to form the first blockchain node in the blockchain main network; In the above process, a second instance is created, which is different from the above-mentioned first instance, and the second instance forms a second blockchain node in the blockchain subnet. When the first instance and the second instance are in the same process, because no cross-process interaction is involved, the difficulty of deploying the first subnet node can be reduced and the deployment efficiency can be improved; of course, the second instance may also be in separate nodes from the first instance In different processes on the device, this specification does not limit this; for example, the node device can create the first instance in the first process to form the first blockchain node in the blockchain main network; and when the node When the node member corresponding to the device wants to participate in the establishment 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 first instance above. Furthermore, the second instance forms a 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 each blockchain node deployed on any node device The blocks generated by the nodes 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.
通过上述方式,可以在区块链主网上创建出区块链子网。以图1为例,subnet0原本包含nodeA~nodeE,而在subnet0的基础上可以组建出subnet1,该subnet1包含nodeA1~nodeD1,且nodeA与nodeA1、nodeB与nodeB1、nodeC与nodeC1、nodeD与nodeD1分别部署在同一节点设备上。类似地,还可以在subnet0上组建出subnet2或更多的区块链子网,其中subnet2包含nodeA2、nodeB2、nodeC2和nodeE2,且nodeA与nodeA1、nodeA2,nodeB与nodeB1、nodeB2,nodeC、nodeC1与nodeC2,nodeD与nodeD1,nodeE与nodeE2分别部署在同一节点设备上。以及,可以将subnet1、subnet2等作为新的区块链主网,并在此基础上进一步组建出区块链子网,其过程与subnet1或subnet2的组建相似,此处不再赘述。可见,上述在区块链主网上发起交易选取节点成员以创建区块链子网的方式,可以使得新创建的区块链子网的子网节点均部署在区块链主网的主网节点所在的节点设备上,也就是从节点设备的角度上来说,区块链子网的子网节点所在的节点设备属于主网节点所在节点设备的子集,换言之,部署有区块链子网的子网节点所处的节点设备上部署有区块链主网中的主网节点。Through the above method, a blockchain subnet can be created on the blockchain mainnet. Taking Figure 1 as an example, subnet0 originally included nodeA~nodeE, and subnet1 can be built on the basis of subnet0. This subnet1 includes nodeA1~nodeD1, and nodeA and nodeA1, nodeB and nodeB1, nodeC and nodeC1, nodeD and nodeD1 are respectively deployed in on the same node device. Similarly, subnet2 or more blockchain subnets can also be established 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 respectively deployed on the same node device. And, subnet1, subnet2, etc. can be used as the new blockchain main network, and a blockchain subnet can be further formed 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 all deployed on the main network nodes of the blockchain main network. On the node device, that is, from the point of view of the node device, the node device where the subnet node of the blockchain subnet is located belongs to the subset of the node device where the main network node is located. The main network node in the blockchain main network is deployed on the node device at .
除了通过上述在区块链主网上发起交易选取节点成员以创建区块链子网的方式,还可以通过其他手段创建区块链子网,并使得其受到区块链主网的管理。例如,可以通过注册方式在区块链主网上组建区块链子网(后续简称注册组网方式),将现有区块链网络直接注册至区块链主网,使新注册的区块链网络受到区块链主网的管理,从而使得新注册的区块链网络成为区块链主网的区块链子网。通过注册组网方式,待组建区块链子网的子网信息被直接注册至区块链主网,使得区块链主网获取待组建区块链子网的相关信息(通过接收并执行待组建区块链网络发出的、用于将其身份信息与分配至该待组建区块链网络的子网标识进行关联存证的交易),例如待组建区块链子网的子网标识和运行状态,其中各节点成员的公钥和插件配置信息、各节点设备的IP地址和端口信息等,这些信息会被写入区块链主网对应的系统合约的合约状态中,由此区块链主网将获取该待组建区块链子网的管理权,在完成注册后,便意味着区块链子网组建完成。由于注册 组网方式并不需要通过交易在区块链主网上指定节点成员构成区块链子网,因此通过注册组网方式组建的区块链子网中的子网节点可以与部署在区块链主网中各节点的节点设备完全不同或部分不同,例如图1中subnet0以注册组网方式创建了一个subnet4(图1中未示出),假设subnet0自身所包含的主网节点nodeA~nodeE分别部署于节点设备1~5,那么subnet4对应的子网节点可以部署于除节点设备1~5外的其他任意节点设备上,或者,subnet4中的其中一个或多个子网节点分别部署于节点设备1~5内的任意节点设备(但仍需要保证一个节点设备上仅部署subnet4中的一个子网节点),而subnet4中的其他的子网节点部署于除节点设备1~5外的其他任意节点设备上,当然,subnet4中的子网节点也可以均部署于节点设备1~5之中。In addition to the above 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 subject to the management of the blockchain main network. For example, a blockchain subnet can be established on the blockchain main network through registration (subsequently referred to as the registration network method), and the existing blockchain network can be directly registered to the blockchain main network, so that the newly registered blockchain network Managed by the blockchain main network, the newly registered blockchain network becomes a blockchain subnet of the blockchain main network. Through the registration network method, the subnet information of the block chain subnet to be formed is directly registered to the block chain main network, so that the block chain main network can obtain the relevant information of the block chain subnet to be formed (by receiving and executing the A transaction issued by the block chain network for associating its identity information with the subnet identification assigned to the block chain network to be formed), such as the subnet identification and operating status of the block chain subnet to be formed, where The public key and plug-in configuration information of each node member, the IP address and port information of each node device, etc., will be written into the contract state of the system contract corresponding to the blockchain main network, so that the blockchain main network will Obtain the management right of the blockchain subnet to be formed. After the registration is completed, it means that the blockchain subnet has been established. Since the registration networking method does not need to specify node members on the blockchain main network through transactions to form a blockchain subnet, the subnet nodes in the blockchain subnet formed through the registration networking method can be deployed on the blockchain main network. The node devices of each node in the network are completely different or partly different. For example, in Figure 1, subnet0 creates a subnet4 (not shown in Figure 1) in the form of registration and networking. It is assumed that the main network nodes nodeA~nodeE contained in subnet0 itself are deployed separately For node devices 1 to 5, the subnet nodes corresponding to subnet4 can be deployed on any other node devices except node devices 1 to 5, or one or more subnet nodes in subnet4 are respectively deployed on node devices 1 to 5 Any node device within 5 (but it is still necessary to ensure that only one subnet node in subnet4 is deployed on a node device), and other subnet nodes in subnet4 are deployed on any other node device except node devices 1 to 5 , of course, the subnet nodes in subnet4 may also be deployed in node devices 1-5.
如图1所示,对于由区块链主网及其管理的区块链子网所构成的区块链系统内的任一区块链网络(称为第一区块链网络),其所包含的每个区块链节点均单独维护有一个由若干个区块顺序相连构成的分布式账本,每个区块都会有对应的区块高度,以用于指示该区块在分布式账本中的相对位置,例如某区块链节点所维护的当前区块高度最大的区块就是该区块链节点最近一次共识或同步得到的区块。并且,随着第一区块链网络中交易的发起、共识和执行,会不断有新的区块产生并被更新至这些区块链节点所维护的分布式账本中。As shown in Figure 1, for any blockchain network (referred to as the first blockchain network) in the blockchain system composed of the blockchain main network and its managed blockchain subnetworks, its Each block chain node of the network independently maintains a distributed ledger composed of several blocks connected in sequence. Each block will have a corresponding block height to indicate the block's position in the distributed ledger. Relative position, for example, the block with the largest current block height maintained by a blockchain node is the block obtained by the latest consensus or synchronization of the blockchain node. Moreover, 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.
在正常情况下,第一区块链网络中的每个区块链节点会依照共识协议不断更新自身维护的分布式账本,这使得每个区块链节点所维护的分布式账本是严格一致的,但当区块链节点宕机重启或有新的区块链节点加入时,将不可避免地导致部分区块链节点所维护的分布式账本中的区块落后于第一区块链网络中的其他区块链节点,即这些区块链节点所维护的本地最新区块的区块高度落后于第一区块链网络中实际最新区块的区块高度。本说明书实施例将本地最新区块的区块高度称为本地区块高度,将实际最新区块的区块高度称为最新区块高度,将维护的本地最新区块的本地区块高度落后于最新区块高度的第一区块链网络中的区块链节点称为落后节点,而将维护的本地最新区块的本地区块高度与最新区块高度相同的第一区块链网络中的区块链节点称为正常节点。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, which makes the distributed ledger maintained by each blockchain node strictly consistent , but when the blockchain node 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 those in the first blockchain network other blockchain nodes, that is, the block height of the latest local block maintained by these blockchain nodes is 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 latest local block is called the local block height, and the block height of the actual latest block is called the latest block height, and the local block height of the latest local block maintained lags behind The blockchain node in the first blockchain network with the latest block height is called a backward node, and the local block height of the local latest block that will be maintained is the same as the latest block height in the first blockchain network Blockchain nodes are called normal nodes.
由于区块需要按照顺序被整合更新至分布式账本,因此对于落后节点而言,其无法与正常节点一样参与第一区块链网络中实际最新区块的共识与处理,即无法参与到正常的共识过程,影响落后节点甚至整个第一区块链网络上功能与服务的运行,因此,如何使得落后节点尽快地获取其所落后的区块以完成追块过程,是该场景下亟待解决的问题。Since the blocks need to be integrated and updated to the distributed ledger in order, for backward nodes, they cannot participate in the consensus and processing of the actual latest block in the first blockchain network like normal nodes, that is, they cannot participate in the normal The consensus process affects the operation of functions and services on the lagging nodes and even the entire first blockchain network. Therefore, how to make the lagging nodes obtain the blocks they lag behind as soon as possible to complete the block chasing process is an urgent problem to be solved in this scenario .
为解决这一问题,本说明书提出一种区块同步方法,第一节点设备通过给其部署的区块链节点分配对应的区块缓存空间,且第一节点设备部署的任一区块链节点对应的区块缓存空间的大小正相关于所述任一区块链节点的节点权重因子,从而在由多个区块链网络构成的区块链系统中,对不同区块链网络中的区块链节点对应的区块限流策略进行宏观调控,实现了区块同步任务的分层设计。In order to solve this problem, this specification proposes a block synchronization method. The first node device allocates the corresponding block cache space to the blockchain nodes deployed by it, and any blockchain node deployed by the first node device The size of the corresponding block cache space is positively related to the node weight factor of any blockchain node, so that in a blockchain system composed of multiple blockchain networks, the blocks in different blockchain networks The block current-limiting strategy corresponding to the block chain node is macro-regulated, and the hierarchical design of the block synchronization task is realized.
下面结合图2对本说明书涉及的区块同步方法进行详细说明。图2是一示例性实施例提供的一种区块同步方法的流程图。该方法应用于第一节点设备,第一节点设备上部署有区块链系统内分别属于多个区块链网络的多个区块链节点,第一节点设备针对其部署的区块链节点维护有对应的区块缓存空间,其中,第一节点设备部署的任一区块链节点对应的区块缓存空间的大小正相关于所述任一区块链节点的节点权重因子;所述方法包括:S202:接收所述任一区块链节点所属区块链网络中的正常节点发送至所述任一区块链节点的落后区块,其中,所述正常节点维护有实际最新区块,且所述落后区块的区块高度处于所述任一区块链节点本地维护的最新区块的本地区块高度与所述实际最新区块的最新区块高度之间。The block synchronization method involved in this specification will be described in detail below with reference to FIG. 2 . Fig. 2 is a flowchart of a block synchronization method provided by an exemplary embodiment. The method is applied to the first node device, where multiple blockchain nodes belonging to multiple blockchain networks in the blockchain system are deployed on the first node device, and the first node device maintains There is a corresponding block cache space, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively related to the node weight factor of any blockchain node; the method includes : S202: Receive the outdated block sent to the any blockchain node by the normal node in the blockchain network to which the any blockchain node belongs, wherein the normal node maintains the 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.
S204:将所述落后区块缓存至所述任一区块链节点对应的区块缓存空间,以由所述任一区块链节点从所述区块缓存空间中读取并处理所述落后区块。S204: Cache the backward block to the block cache space corresponding to any blockchain node, so that any blockchain node can read and process the backward block from the block cache space blocks.
在本说明书实施例中,节点设备是用于运行区块链节点的硬件实体,而区块链节点则是指运行在节点设备中的软件进程。本说明书实施例所涉及的区块链系统是指由多个区块链网络共同构成的区块链系统,例如前述的由区块链主网及其管理的区块链子网所构成的区块链系统,所述区块链系统的特点在于其所涉及的节点设备中存在同时部署有多个区块链节点的现象,而本说明书所涉及的区块同步方案正应用于部署有多个区块链网络所属的多个区块链节点的第一节点设备。In the embodiment 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 on 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 block composed of the blockchain main network and its managed blockchain subnets. The block chain system, the feature of the block chain system is that there are multiple block chain nodes deployed at the same time in the node equipment involved, and the block synchronization scheme involved in this specification is being applied to the deployment of multiple block chain nodes. The first node device of multiple blockchain nodes to which the blockchain network belongs.
本说明书实施例所涉及的所述任一区块链节点属于落后节点,而落后节点在接收到落后区块后,会按照区块高度由低到高的顺序进行处理,这里的处理可以包括:通过区块的区块头验证区块的合法性,读取区块的区块体中包含的交易并按照顺序执行这些交易,最后将该区块添加至落后节点所维护的分布式账本的末尾完成区块上链过程。因此, 任一区块链节点对接收到的落后区块的处理需要按照一定的顺序逐个执行并且处理每个区块都会花费一定的时间,而如果第一节点设备在接收到发送至其上部署的任一区块链节点的落后区块时,就直接将所述落后区块转发至所述任一区块链节点,那么在落后区块包含多个或者所述任一区块链节点还在处理上一个区块的情况下,这些转发至所述任一区块链节点的落后区块就会因任一区块链节点的区块处理机制的限制而被所述任一区块链节点丢弃。因此,在本说明书实施例中,第一节点设备会为其本地部署的每个区块链节点分配对应的区块缓存空间,其中,任一区块链节点对应的区块缓存空间用于暂时存储拟转发至所述任一区块链节点进行处理的落后区块,从而使得所述任一区块链节点可以根据自身针对落后区块的处理进度,自行从该区块缓存空间读取并处理当前所需执行的落后区块,从而防止区块链节点因来不及处理而导致的落后区块被丢弃的现象。Any blockchain node involved in the embodiment of this specification belongs to a backward node, and after receiving a backward block, the backward node will process it in the order of block height from low to high, and the processing here may include: Verify the legitimacy of the block through the block header of the block, read the transactions contained in the block body of the block and execute these transactions in order, and finally add the block to the end of the distributed ledger maintained by the backward node to complete Block on-chain process. Therefore, any blockchain node needs to process the received backward blocks one by one in a certain order and it will take a certain amount of time to process each block. When the lagging block of any blockchain node is behind, the lagging block is directly forwarded to the any blockchain node, then if the lagging block contains multiple or the In the case of processing the previous block, these backward blocks forwarded to any blockchain node will be blocked by any blockchain node due to the limitation of the block processing mechanism of any blockchain node. Node dropped. Therefore, in the embodiment of this specification, the first node device will allocate a corresponding block cache space for each blockchain node deployed locally, wherein the block cache space corresponding to any blockchain node is used for temporary Storing the outdated blocks to be forwarded to any one of the blockchain nodes for processing, so that any one of the blockchain nodes can read from the block cache space and Process the backward blocks that need to be executed at present, so as to prevent the backward blocks from being discarded due to the lack of time for the blockchain nodes to process them.
本说明书实施例所涉及的区块缓存空间对应的存储空间可以包括内存空间和/或硬盘空间,然而,无论是哪种类型的存储空间,第一节点设备作为一个硬件实体其所包含的存储空间有限,因此为了能对第一节点设备上部署的多个区块链节点的区块同步任务进行分层设计,本说明书实施例提出了按照节点权重因子给第一节点设备上部署的多个区块链节点维护不同大小的区块缓存空间,使得任一区块链节点对应的区块缓存空间的大小正相关于所述任一区块链节点的节点权重因子,从而实现了对第一节点设备存储资源的适应性分配。The storage space corresponding to the block cache space involved in the embodiment of this specification may include memory space and/or hard disk space. However, no matter what type of storage space it is, the storage space contained in the first node device as a hardware entity Therefore, in order to perform hierarchical design on the block synchronization tasks of multiple blockchain nodes deployed on the first node device, the embodiment of this specification proposes to assign multiple block chain nodes deployed on the first node device according to the node weight factor. Block chain nodes maintain block cache spaces of different sizes, so that the size of the block cache space corresponding to any block chain node is positively related to the node weight factor of any block chain node, thereby realizing the first node Adaptive allocation of device storage resources.
第一节点设备首先接收到区块消息,解析得到该区块消息所对应的源通讯地址和目的通讯地址分别为所述正常节点和所述任一区块链节点,然后从所述区块消息中提取出所述落后区块并将其缓存至所述任一区块链节点对应的所述区块缓存空间。The first node device first receives the block message, parses and obtains that the source communication address and the destination communication address corresponding to the block message are the normal node and the arbitrary block chain node respectively, and then obtains from the block message Extract the backward block and cache it in the block cache space corresponding to any blockchain node.
如前所述,落后节点所维护的本地最新区块的本地区块高度小于实际最新区块的最新区块高度,这意味着在第一区块链节点检测到自身属于落后节点的情况下,第一区块链节点未维护有所述实际最新区块,并且,第一区块链节点相较于同时期的正常节点所缺少的区块称为落后区块,所述落后区块所被允许的区块高度处于所述落后节点本地维护的最新区块(即本地最新区块)的本地区块高度与所述最新区块高度之间,且所述落后区块包含所述实际最新区块但不包含所述本地最新区块。As mentioned above, the local block height of the latest local block maintained by the lagging node is smaller than the latest block height of the actual latest block, which means that when the first blockchain node detects that it belongs to the lagging node, The first block chain node does not maintain the actual latest block, and the block that the first block chain node lacks compared with the normal nodes of the same period is called a lagging block, and the lagging block is The allowable block height is between the local block height of the latest block locally maintained by the backward node (ie, the local latest block) and the latest block height, and the backward block includes the actual latest block block but does not contain said local latest block.
第一节点设备部署的任一区块链节点对应的区块缓存空间的大小正相关于所述任一区块链节点的节点权重因子,具体是指:第一节点设备将所述任一区块链节点对应的区块缓存空间的大小确定为固定存储大小(通常指第一节点设备中用于存放区块的存储上限)与所述任一区块链节点的节点权重因子的乘积。在一实施例中,如果第一节点设备确定出的所述任一区块链节点的区块缓存空间的大小超过了所述任一区块链节点的落后区块数与单个区块平均大小的乘积,就意味着所述区块缓存空间的大小分配过大,此时可以将所述任一区块链节点的区块缓存空间大小重新确定为所述落后区块数与单个区块平均大小的乘积,其中,任一区块链节点的落后区块数为所述任一区块链节点所属区块链网络所维护的最新区块高度与所述任一区块链节点所维护的本地最新区块的本地区块高度之间的差值。The size of the block cache space corresponding to any block chain node deployed by the first node device is positively related to the node weight factor of any block chain node. The size of the block cache space corresponding to the block chain node is determined 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 block chain node. In one embodiment, if the size of the block cache space of any blockchain node determined by the first node device exceeds the number of backward blocks and the average size of a single block of any blockchain node The product of , it means that the size allocation 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 number of backward blocks and the average value of a single block. The product of size, wherein, the number of backward blocks of any blockchain node is the latest block height maintained by the blockchain network to which any blockchain node belongs and the height of the latest block maintained by any blockchain node. The difference between the local block heights of the local latest block.
另外,区块缓存空间的大小可以被设置有上下界,以将所述区块缓存空间的大小约束在一个合理范围内。In addition, the size of the block cache space may be set with upper and lower bounds, so as to constrain the size of the block cache space within a reasonable range.
可选的,所述任一区块链节点的节点权重因子包括:所述任一区块链节点的节点缓存权重占所述多个区块链节点的节点缓存权重之和的比值。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 plurality of blockchain nodes.
第一节点设备可以采用多种方式确定其所部署的任一区块链节点的节点权重因子。在一实施例中,任一区块链节点的节点权重因子可以被确定为所述任一区块链节点对应的节点缓存权重与第一节点设备上部署的所有区块链节点的节点缓存权重之和的比值。在本说明书实施例中,第一节点设备部署有所述多个区块链节点,第一节点设备会维护一个节点缓存权重列表,该节点缓存权重列表记录有第一节点设备其本地部署的所述多个区块链节点分别对应的节点缓存权重,然后在第一节点设备需要计算本地部署的任一区块链节点的节点权重因子时,只需要将所述任一区块链节点对应的节点缓存权重除以本地部署的所有区块链节点的节点缓存权重之和就可以得到。以图1为例,第一节点设备为节点设备1,那么节点设备1所维护的节点缓存权重列表中就包含节点设备1所部署的nodeA、nodeA1和nodeA2对应的节点缓存权重,例如nodeA的节点缓存权重为1,nodeA1的节点缓存权重为2,nodeA2的节点缓存权重为3,那么节点设备1所能计算得到的nodeA1的节点权重因子为2/(1+2+3)=1/3。由于节点设备的存储资源有限,因此在本说明书实施例中,可以确保第一节点设备上所有区块链节点的节点权重因子之和存在上界,以适配第一节点设备在区块同步任务上所能够支持的存储上限,防止在第一节点设备上区块链节点均属于落后节点的情况下,分配的各区块缓存空间的总大小超出 第一区块链节点的存储资源上限。The first node device can determine the node weight factor of any blockchain node it deploys in various ways. In an embodiment, the node weight factor of any blockchain node can be determined as the node cache weight corresponding to any blockchain node and the node cache weights of all blockchain nodes deployed on the first node device The ratio of the sum. In the embodiment of this specification, the first node device is deployed with the plurality of blockchain nodes, and the first node device maintains a node cache weight list, and the node cache weight list records all the locally deployed nodes of the first node device. The node cache weights corresponding to the multiple blockchain nodes respectively, and then when the first node device needs to calculate the node weight factor of any blockchain node deployed locally, it only needs to set the node weight factor corresponding to any blockchain node It can be obtained by dividing the node cache weight by the sum of the node cache weights of all blockchain nodes deployed locally. Taking Figure 1 as an 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 of nodeA The cache weight of nodeA1 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 calculated by node device 1 is 2/(1+2+3)=1/3. Since the storage resources of the node device are limited, in the embodiment 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, so as to adapt the block synchronization task of the first node device The upper limit of storage that can be supported above prevents the total size of the allocated cache space of each block from exceeding the upper limit of storage resources of the first blockchain node when the blockchain nodes on the first node device are all backward nodes.
在另一实施例中,第一节点设备还可以将任一区块链节点对应的节点权重因子确定为所述任一区块链节点对应的节点缓存权重与第一节点设备上部署的所有处于区块落后状态的区块链节点的节点缓存权重之和的比值。在本说明书实施例中,在计算任一区块链节点对应的节点权重因子时,只需要考虑所述任一区块链节点的节点缓存权重,以及第一节点设备上部署的在各自区块链网络中属于落后节点的节点缓存权重。仍以图1为例,假如第一节点设备为节点设备1,那么节点设备1所维护的节点缓存权重列表中就包含节点设备1所部署的nodeA、nodeA1和nodeA2对应的节点缓存权重,如果nodeA当前属于subnet0中的正常节点,不需要进行追块(区块同步),而nodeA1和nodeA2则均属于各自所处的subnet1和subnet2中的落后节点,需要进行追块,那么此时计算得到的nodeA1的节点权重因子为2/(2+3)=0.4。在本说明书实施例中,可以在第一节点设备中存在无需进行追块的区块链节点时,增加第一区块链节点中需要进行追块的区块链节点的区块缓存空间,从而动态维持第一节点设备中部署的各区块链节点的区块缓存空间的大小,尽可能地利用第一节点设备在区块同步任务上所能够支持的存储资源上限。In another embodiment, the first node device can also determine the node weight factor corresponding to any blockchain node as the node cache weight corresponding to any blockchain node and all nodes deployed on the first node device. The ratio of the sum of the node cache weights of the blockchain nodes in the backward state of the block. In the embodiment of this specification, when calculating the node weight factor corresponding to any blockchain node, it is only necessary to consider the node cache weight of any blockchain node, as well as the node cache weight deployed on the first node device in the respective block Node cache weights belonging to lagging nodes in the chain network. Still taking Figure 1 as an 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 It is currently a normal node in subnet0 and does not need to chase blocks (block synchronization), while nodeA1 and nodeA2 belong to the backward nodes in their respective subnet1 and subnet2, and needs to chase blocks, then the calculated nodeA1 at this time The node weight factor of is 2/(2+3)=0.4. In the embodiment of this specification, when there are blockchain nodes that do not need to track blocks in the first node device, the block cache space of the blockchain nodes that need to track blocks in the first blockchain node can be increased, so that The size of the block cache space of each blockchain node deployed in the first node device is dynamically maintained, and the upper limit of storage resources that the first node device can support in the block synchronization task is utilized as much as possible.
上述第一节点设备所维护的节点缓存权重列表中每个区块链节点对应的节点缓存权重,可以是为各自区块链节点所属区块链网络对应的网络权重,而各区块链网络对应的网络权重可以被记录在区块链主网的子网管理合约中,并由第一节点设备读取本地部署的主网节点所获取。以图1为例,假如第一节点设备为节点设备1,那么节点设备1可以从本地部署的主网节点nodeA处获取区块链主网及其管理的各区块链子网的网络权重,例如subnet0的网络权重为1,subnet1的网络权重为2,subnet2的网络权重为3,那么节点设备1就会进一步为自身部署的区块链节点分配和指定节点缓存权重,将nodeA的节点缓存权重指定为nodeA所属区块链网络subnet0的网络权重,将nodeA1的节点缓存权重指定为nodeA1所属区块链网络subnet1的网络权重,将nodeA2的节点缓存权重指示为subnet2的网络权重,最后将这些节点缓存权重记录在本地维护的节点缓存权重列表。这样一来,相当于将针对区块缓存空间的网络层面的宏观调控与节点层面的宏观调控进行了结合,使得最终实现的所述区块链系统的区块缓存空间的维护策略既能够在网络层面实现对多个区块链节点的统一调控,也能够在不同的节点设备上做出差异化的局部优化以符合不同节点设备的存储资源的具体情况。当然,任一区块链网络的网络权重还可以被记载于所述任一区块链网络的智能合约中,由第一节点设备通过本地部署的所述任一区块链网络中的区块链节点获取该网络权重。在一实施例中,所述任一区块链节点对应的节点权重因子还可以被直接确定为所述任一区块链节点所属区块链网络的网络权重。The node cache weight corresponding to each blockchain node in the node cache weight list maintained by the above-mentioned first node device may be the network weight corresponding to the blockchain network to which the respective blockchain node belongs, and the corresponding network weight of each blockchain network The network weight can 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 nodes. Taking Figure 1 as an example, if the first node device is node device 1, then node device 1 can obtain the network weight of the blockchain main network and its managed blockchain subnets from the locally deployed main network node nodeA, such as subnet0 The network weight of subnet1 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 the node cache weight for the blockchain nodes deployed by itself, and specify the node cache weight of nodeA as The network weight of the blockchain network subnet0 to which nodeA belongs, the node cache weight of nodeA1 is designated as the network weight of the blockchain network subnet1 to which nodeA1 belongs, the node cache weight of nodeA2 is indicated as the network weight of subnet2, and finally these node cache weights are recorded List of node cache weights maintained locally. In this way, it is equivalent to combining the macro-control at the network level of the block cache space with the macro-control at the node level, so that the maintenance strategy of the block cache space of the blockchain system that is finally realized can be implemented on the network. At the same level, it can realize the unified control of multiple blockchain nodes, and can also make differentiated local optimizations 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 block in any blockchain network deployed locally by the first node device Chain nodes get this network weight. In an embodiment, the node weight factor corresponding to any blockchain node may also be directly determined as the network weight of the blockchain network to which any blockchain node belongs.
S206:在所述落后区块由所述任一区块链节点处理完毕的情况下,将所述落后区块移除所述区块缓存空间。S206: When the lagging block has been processed by any of the blockchain nodes, remove the lagging block from the block cache space.
第一节点设备在将接收到的落后区块缓存至所述任一区块链节点对应的区块缓存空间中后,第一区块链节点会自行从区块缓存空间中读取并处理区块,每次处理完一个区块就会通知第一节点设备将该处理完的这个区块从区块缓存空间中移除,以腾出空间存放更多的区块。After the first node device caches the received backward block into the block cache space corresponding to any blockchain node, the first blockchain node will read and process the block from the block cache space by itself. 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.
在本说明书实施例中,第一节点设备通过将接收到的发送至所述任一区块链节点的落后区块缓存至所述任一区块链节点对应的区块缓存空间,并由所述任一区块链节点从中读取并处理所述落后及区块,从而使得第一节点设备上部署的区块链节点能够获取其对应的落后区块,以确保区块链节点上功能与服务的正常运行。同时,由于区块缓存空间正相关于所述任一区块链节点的节点权重因子而第一节点设备的存储资源有限,因此本方案相当于对第一节点设备的存储资源进行了适应性分配,优先让第一节点设备上部署的节点权重因子更大的区块链节点占用更大的区块缓存空间,从而在由多个区块链网络构成的区块链系统中,对不同区块链网络中的区块链节点对应的区块限流策略进行宏观调控,实现了区块同步任务的分层设计。In the embodiment of this specification, the first node device caches the received outdated block sent to any blockchain node in the block cache space corresponding to any blockchain node, and the Any one of the above-mentioned blockchain nodes reads and processes the backward block, so that the blockchain node deployed on the first node device can obtain its corresponding backward block, so as to ensure that the functions on the blockchain node are consistent with normal operation of the service. At the same time, since the block cache space is positively related to 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 block chain nodes with larger node weight factors deployed on the first node device to occupy a larger block cache space, so that in the block chain system composed of multiple block chain networks, different blocks The block current-limiting strategy corresponding to the block chain nodes in the chain network is macro-regulated, and the hierarchical design of block synchronization tasks is realized.
可选的,所述区块缓存空间的大小还正相关于所述本地区块高度与所述最新区块高度之间的落后程度。Optionally, the size of the block cache space is also positively related to the degree of lag between the local block height and the latest block height.
例如,第一节点设备可以首先将本地部署的任一区块链节点的节点权重因子与落后程度因子相乘得到所述任一区块链节点对应的综合因子,并计算所述任一区块链节点的综合因子占所述所有区块链节点的综合因子之和的比值,最后将该比值与固定存储大小的乘积确定为所述任一区块链节点对应的区块缓存空间的大小,其中,所述任一区块链节点对应的落后程度因子被确定为所述任一区块链节点的落后区块数占第一节点设备上部署的所有处于区块落后状态的区块链节点的落后区块数之和的比值,其中,任一区 块链节点的落后区块数为所述任一区块链节点所属区块链网络所维护的最新区块高度与所述任一区块链节点所维护的本地最新区块的本地区块高度之间的差值。For example, the first node device may first multiply the node weight factor of any blockchain node deployed locally by the lagging degree factor to obtain the comprehensive factor corresponding to any blockchain node, and calculate any block The ratio of the comprehensive factor of the chain node to the sum of the comprehensive factors of all blockchain nodes, and finally the product of the ratio and the fixed storage size is determined as the size of the block cache space corresponding to any blockchain node, Wherein, the backward degree factor corresponding to any blockchain node is determined as the number of backward blocks of any blockchain node accounts for all blockchain nodes deployed on the first node device that are in a backward state. The ratio of the sum of the number of backward blocks, wherein, the number of backward blocks of any blockchain node is the latest block height maintained by the blockchain network to which any blockchain node belongs and the height of any block chain The difference between the local block heights of the latest local blocks maintained by blockchain nodes.
由于区块缓存空间的大小正相关于所述本地区块高度与所述任一区块链网络实际最新区块的最新区块高度之间的落后程度,因此在所述任一区块链节点的落后程度(即所述任一区块链节点的本地区块高度与最新区块高度之间的落后程度)越大,其区块缓存空间就越大,这意味着所述任一区块链节点在落后程度较大时其对应的区块缓存空间也较大,而随着所述任一区块链节点慢慢同步区块,其落后程度逐渐缩小后,其对应的区块缓存空间也会慢慢缩小。因此,本方案对区块缓存空间的控制相当于对不同落后程度的落后节点的区块缓存空间的大小进行了区分,让落后程度较大即区块同步需求较大的落后节点占用更大的区块缓存空间,减小其所受到区块限流策略的限制从而更快地完成追块过程,由此各落后节点可以完成更为均衡的同步追块,实现了一种更为智能的动态区块同步策略。Since the size of the block cache space is positively related to the degree of lag between the local block height and the latest block height of the actual latest block of any blockchain network, in any blockchain node The greater the degree of backwardness (that is, the degree of backwardness between the local block height and the latest block height of any blockchain node), the larger the block cache space, which means that any block When a chain node lags far behind, its corresponding block cache space is also large, and as any blockchain node slowly synchronizes blocks, its lagging degree gradually shrinks, and its corresponding block cache space It will also gradually shrink. Therefore, the control of the block cache space in this scheme is equivalent to distinguishing the size of the block cache space of the backward nodes with different degrees of backwardness, so that the backward nodes with a greater degree of backwardness, that is, with a greater demand for block synchronization, occupy a larger space. The block cache space reduces the restriction of the block current limiting strategy to complete the block tracking process faster, so that each lagging node can complete a more balanced synchronous block tracking, realizing a more intelligent dynamic Block synchronization strategy.
可选的,还包括:接收所述任一区块链节点在所述本地区块高度落后于所述最新区块高度的情况下,按照动态请求周期进行周期性发送的针对所述落后区块的区块同步请求,并将所述区块同步请求转发至所述正常节点;其中,所述动态请求周期负相关于所述最新区块高度与所述本地区块高度之间的落后程度。Optionally, it also includes: receiving the information for the backward block that is sent periodically according to the dynamic request period when the local block height is behind the latest block height by any blockchain node. block synchronization request, and forward the block synchronization request to the normal node; wherein, the dynamic request period is negatively related to the degree of lag between the latest block height and the local block height.
在本说明书实施例中,第一节点设备上部署的任一区块链节点都会检测在自身所属区块链网络中自身是否属于落后节点,一旦检测到自身属于落后节点,就会按照动态请求周期向所述任一区块链节点所处区块链网络中的正常节点周期性地发送区块同步请求,以期获取落后自身的落后区块从而完成追块过程。因此,第一节点设备所接收到的由所述任一区块链节点所述区块链网络中的正常节点发送至所述任一区块链节点的落后区块,实际上是由所述正常节点响应于所述任一区块链节点先前发出的区块同步请求所确定的。In the embodiment of this specification, any blockchain node deployed on the first node device will detect whether it belongs to a backward node in the blockchain network to which it belongs. Once it detects that it belongs to a backward node, it will follow the dynamic request cycle Periodically send a block synchronization request to the normal node in the blockchain network where any of the blockchain nodes is located, in order to obtain lagging blocks behind itself and complete the block chasing process. Therefore, the backward block sent by the normal node in the blockchain network of any blockchain node to the blockchain node received by the first node device is actually sent by the blockchain node The normal node is determined in response to the block synchronization request previously sent by any blockchain node.
下面以第一节点设备上部署的第一区块链网络中的第一区块链节点为例,来说明本说明书实施例所涉及的区块链节点周期性发送区块同步请求的方法,该方法应用于第一区块链节点,第一区块链节点动态维护有本地最新区块的本地区块高度以及动态请求周期,所述动态请求周期负相关于所述本地区块高度与第一区块链网络实际最新区块的最新区块高度之间的落后程度;所述方法包括:步骤A:在所述本地区块高度落后于所述最新区块高度的情况下,按照所述动态请求周期向第一区块链网络中维护有所述实际最新区块的正常节点周期性发送针对落后区块的区块同步请求,其中,所述落后区块的区块高度处于所述本地区块高度与所述最新区块高度之间。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 periodically sending a block synchronization request by the blockchain node involved in the embodiment of this specification. The method is applied to the first blockchain node, and the first blockchain node dynamically maintains the local block height of the latest local block and the dynamic request period, and the dynamic request period is negatively related to the local block height and the first The degree of lag between the latest block heights of the actual latest block in the blockchain network; the method includes: Step A: In the case that the local block height is behind the latest block height, according to the dynamic The request cycle periodically sends a block synchronization request for the backward block to the normal node in the first blockchain network that maintains the actual latest block, wherein the block height of the backward block is in the local area between the block height and the latest block height.
步骤B:接收所述正常节点响应于所述区块同步请求返回的所述落后区块,以重新确定所述本地最新区块以及所述动态请求周期。Step B: receiving the backward block returned by the normal node in response to the block synchronization request, so as to re-determine the local latest block and the dynamic request period.
本说明书实施例所涉及的第一区块链节点向所述正常节点发送区块同步请求,其实质上就是由第一区块链节点首先发送至第一节点设备,然后由第一节点设备转发至正常节点;同理,第一区块链节点所接收到的正常节点返回的落后区块,实质上也是由第一节点设备首先接收到并先缓存至第一区块链节点对应的区块缓存空间,然后再由第一区块链节点从该区块缓存空间中读取并接收。The first block chain node involved in the embodiment of this specification sends a block synchronization request to the normal node, which is essentially sent by the first block chain node to the first node device, and then forwarded by the first node device to normal nodes; similarly, the backward block received by the first blockchain node and returned by the normal node is actually first received by the first node device and first cached to the block corresponding to the first blockchain node cache space, and then read and receive from the block cache space by the first blockchain node.
本说明书实施例所涉及的第一区块链网络中的实际最新区块,指的是第一区块链网络最近一次通过共识的区块的区块高度,由于区块共识后会被所有正常节点处理(执行区块中的交易)并将其更新至其所维护的分布式账本,因此第一区块链网络中的实际最新区块也等价于第一区块链网络中的各区块链节点所维护的区块中区块高度最大的区块。The actual latest block in the first blockchain network involved in the embodiment of this specification refers to the block height of the block that passed the consensus last time in the first blockchain network. The nodes process (execute the transactions in the block) and update it to the distributed ledger it maintains, so the actual latest block in the first blockchain network is also equivalent to each block in the first blockchain network The block with the largest block height among the blocks maintained by the chain node.
由于正常节点也有变成落后节点的可能性,因此对于第一区块链网络中的任一区块链节点,都会周期性地向其他区块链节点问询其本地所维护的最新区块的区块高度,一旦发现自身所维护的本地区块高度小于其他区块链节点所维护的最新区块的区块高度,则认为自身属于落后节点,反之,如果发现自身所维护的本地区块高度大于或等于其他区块链节点所维护的最新区块的区块高度,则认为自身属于正常节点。Since normal nodes also have the possibility of becoming backward nodes, any blockchain node in the first blockchain network will periodically ask other blockchain nodes for the status of the latest block maintained locally. Block height, once it finds that the local block height maintained by itself is less than the block height of the latest block maintained by other blockchain nodes, it considers itself to be a lagging node. On the contrary, if it finds that the local block height maintained by itself If it 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.
本说明书实施例所涉及的本地最新区块即第一区块链节点最近一次通过共识得到或通过区块同步得到并维护在本地的最新区块,当第一区块链节点检测到本地区块高度落后于所述最新区块高度(本地区块高度小于最新区块高度)的情况下,确定自身属于落后节点,因此会开始周期性地向正常节点发送区块同步请求以期获取落后区块。上述周期性发送区块同步请求的周期即第一区块链节点上维护的动态请求周期,所述动态请求周期负相关于所述本地区块高度与第一区块链网络实际最新区块的最新区块高度之间的落后程度,这意味着动态请求周期会随着本地区块高度或最新区块高度的变化而发送 变化,例如第一区块链节点每次同步得到新的落后区块时,其所维护的本地最新区块就会发送变化,因此本地区块高度与最新区块高度之间的落后程度也会发送变化,此时第一区块链节点也需要对本地维护的动态请求周期进行同步更新。The latest local block involved in the embodiment of this specification refers to the latest local block obtained by the first blockchain node through consensus or block synchronization and maintained locally. When the first blockchain node detects the local block When the height falls behind the latest block height (the local block height is less than the latest block height), it is determined that it belongs to a backward node, so it will start to periodically send block synchronization requests to normal nodes in order to obtain backward blocks. The cycle of periodically sending the block synchronization request is the dynamic request cycle maintained on the first block chain node, and the dynamic request cycle is negatively related to the height of the local block and the actual latest block of the first block chain network. The degree of lag between the latest block heights, which means that the dynamic request cycle will send changes as the local block height or the latest block height changes, for example, the first blockchain node gets a new lagging block every time it is synchronized , the latest local block maintained by it will send changes, so the 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 update the dynamic The request cycle is updated synchronously.
由于动态请求周期负相关于所述本地区块高度与第一区块链网络实际最新区块的最新区块高度之间的落后程度,因此在第一区块链节点的落后程度(即第一区块链节点的本地区块高度与最新区块高度之间的落后程度)越大,其动态请求周期就越短,这意味着第一区块链节点在落后程度较大时单位时间内向正常节点发送区块同步请求的次数(有效请求次数)会更加频繁,而随着第一区块链节点慢慢同步区块,其落后程度逐渐缩小后,其有效请求次数就会慢慢降低,由于区块同步请求对应的区块请求数往往存在上限,这意味着单次区块同步请求一般不能直接完成追块过程。因此,本方案对有效请求次数的控制相当于对不同落后程度的落后节点的区块同步速率进行了区分,让落后程度较大即区块同步需求较大的落后节点更快地完成区块同步,从而在整体上降低第一区块链网络中落后程度较大的落后节点占所有落后节点中的比例,以使落后节点完成更为均衡的同步追块,实现了一种更为智能的动态区块同步策略。Since the dynamic request cycle 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, the lagging degree of the first blockchain node (ie, the first The greater the lag between the local block height of the blockchain node and the latest block height), the shorter its dynamic request cycle is, which means that the first blockchain node moves to the normal unit time when the lagging degree is large The number of times the node sends block synchronization requests (the number of effective requests) will be more frequent, and as the first blockchain node slowly synchronizes the block, its lagging behind will gradually decrease, and the number of effective requests will gradually decrease. The number of block requests corresponding to a block synchronization request often has an upper limit, which means that a single block synchronization request generally cannot directly complete the block chasing process. Therefore, the control of the number of effective requests in this scheme is equivalent to distinguishing the block synchronization rate of lagging nodes with different degrees of lagging behind, so that lagging nodes with a greater degree of lagging behind, that is, a greater need for block synchronization, can complete block synchronization faster , so as to reduce the proportion of lagging nodes with a relatively large degree of lagging behind in all lagging nodes in the first blockchain network as a whole, so that lagging nodes can complete a more balanced synchronous block pursuit and realize a more intelligent dynamic Block synchronization strategy.
可选的,所述动态请求周期还负相关于所述任一区块链节点的节点权重因子。假设所述任一区块链节点为第一区块链节点,其对应的节点权重因子为第一节点权重因子,由于动态请求周期还负相关于第一区块链节点对应的第一节点权重因子的大小,因此还可以对第一区块链节点的区块同步速率进行权重维度的调整。例如,第一节点权重因子可以被记录在第一区块链网络中的智能合约的合约状态中,而该智能合约可以由第一区块链网络的管理员或其他用户进行调用后对第一节点权重因子进行更新,这使得第一区块链节点可以通过读取该智能合约上持续更新的第一节点权重因子大小来动态调节自身的动态请求周期,由于智能合约会部署在第一区块链网络中的每个区块链节点上,这意味着第一区块链网络中的每个区块链节点所对应的节点权重因子均相同,即实现了动态请求周期在网络层面的宏观调控。Optionally, the dynamic request period is also negatively related to the node weight factor of any blockchain node. Assume that any blockchain node is the first blockchain node, and its corresponding node weight factor is the first node weight factor. Since the dynamic request cycle is also negatively related to the first node weight corresponding to the first blockchain node The size of the factor, so it is also possible to adjust the weight dimension of the block synchronization rate of the first blockchain node. For example, the first node weight factor can be recorded in the contract state of the smart contract in the first blockchain network, and the smart contract can be invoked by the administrator or other users of the first blockchain network to update the first The node weight factor is updated, which enables the first blockchain node to dynamically adjust its own dynamic request cycle by reading the continuously updated first node weight factor on the smart contract. Since the smart contract will be deployed in the first block On each blockchain node in the blockchain network, this means that the node weight factors corresponding to each blockchain node in the first blockchain network are the same, which realizes the macro-control of the dynamic request cycle at the network level .
又例如,第一节点权重因子由第一区块链节点所处的第一节点设备提供,在这种情况下,第一节点设备通过参考其本地针对区块链节点的部署情况,计算出第一区块链节点对应的第一区块链节点对应的第一节点权重因子,其计算过程前述实施例已经有所介绍,这里不再赘述,第一节点设备在计算出第一节点权重因子后将其提供至第一区块链节点,从而使得第一区块链节点可以通过第一节点设备持续更新的第一节点权重因子大小来动态调节自身的动态请求周期,即实现了动态请求周期在节点层面的宏观调控。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 second The calculation process of the first node weight factor corresponding to the first blockchain node corresponding to a blockchain node has been introduced in the foregoing embodiments, and will not be repeated here. After the first node device calculates the first node weight factor It is provided to the first blockchain node, so that the first blockchain node can dynamically adjust its own dynamic request period through the first node weight factor continuously updated by the first node device, that is, the dynamic request period is realized. Macro-control at the node level.
本说明书实施例所涉及的区块同步请求可以包含第一区块链节点的身份信息、源通讯地址、目的通讯地址和所需请求的落后区块的区块范围,该区块范围由区块高度所确定,例如第一区块链节点所维护的本地区块高度为1500,而实际最新区块高度为2000,单次区块同步请求对应的区块请求数上限为100,那么第一区块链节点发送给正常节点的区块同步请求中所携带的落后区块的区块范围就可以为(1500,1600],用于表示向正常节点请求区块高度从1501至1600的100个区块,当然也可以是(1500,1550]或(1900,2000]。特别的,在第一区块链节点所请求的落后区块的区块范围不从本地区块高度连续开始的情况下,例如上例中区块同步请求指示的(1900,2000]的区块范围,此时第一区块链节点将接收到区块高度由1901至2000的100个区块,但由于分布式账本的更新需要按照区块高度的顺序完成,因此第一区块链节点即使接收到了上述的100个区块也无法对分布式账本完成更新,这种情况下,第一区块链节点往往还会向其他的多个正常节点请求有区块范围为(1500,1900]的落后区块,从而使第一区块链节点在接收到其他正常节点返回的区块高度由1501至1900的399个区块后,首先对这399个区块进行处理和上链(区块上链即将区块更新至分布式账本),然后再对之前接收到的100个区块进行处理和上链,从而通过请求多个正常节点更快地完成追块过程。The block synchronization request involved in the embodiment of this 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 required backward block. The block range is defined by the block The height is determined. For example, the local block height maintained by the first blockchain node is 1500, but 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 first block The block range of the backward block carried in the block synchronization request sent by the block chain node to the normal node can be (1500,1600], which is used to indicate that the normal node requests 100 blocks with block heights from 1501 to 1600 Block, of course, can also be (1500,1550] or (1900,2000]. In particular, when the block range of the backward block requested by the first blockchain node does not start continuously from the local block height, For example, in the block synchronization request in the above example, the block range of (1900,2000] is indicated. At this time, the first blockchain node will receive 100 blocks with a block height from 1901 to 2000, but due to the distributed ledger Updates need to be completed in the order of block heights, so even if the first blockchain node receives the above 100 blocks, it cannot complete the update of the distributed ledger. In this case, the first blockchain node will often send to Multiple other normal nodes request backward blocks with a block range of (1500,1900], so that the first blockchain node receives 399 blocks with block heights from 1501 to 1900 returned by other normal nodes Afterwards, the 399 blocks are processed and uploaded to the chain first (block chaining is to update the block to the distributed ledger), and then the previously received 100 blocks are processed and uploaded to the chain, so that by requesting more normal nodes complete the block chasing process faster.
在本说明书实施例中,第一区块链网络中的第一区块链节点在检测到自身维护的区块落后的情况下,按照所述动态请求周期向第一区块链网络中维护有所述实际最新区块的正常节点周期性发送针对落后区块的区块同步请求,从而使得第一区块链节点能够获取其对应的落后区块,以确保第一区块链节点上功能与服务的正常运行。同时,由于动态请求周期负相关于所述本地区块高度与第一区块链网络实际最新区块的最新区块高度之间的落后程度,因此对于落后程度较大的落后节点其单位时间内的有效请求次数更多,这使得落后程度越大的落后节点能够更快地完成追块过程,由于区块同步请求被正常节点响应时需要消耗计算资源,且返回落后区块时也会占用网络带宽资源,而第一区块链网络中的正常节点的数量与计算资源,以及第一区块链网络的网络带宽资源均有限,因此本方案相当于优先让落后程度更大的落后节点占用更多的正常节点的计算资源以 及第一区块链网络的网络带宽资源,即对正常节点的计算资源以及第一区块链网络的网络带宽资源进行了合理分配。In the embodiment of this specification, when the first blockchain node in the first blockchain network detects that the block maintained by itself is behind The normal node of the actual latest block periodically sends a block synchronization request for the backward block, so that the first blockchain node can obtain its corresponding backward block, so as to ensure that the functions on the first blockchain node are consistent with normal operation of the service. At the same time, since 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 in the first blockchain network, the unit time for lagging nodes with a large degree of lag The number of effective requests is more, which enables the lagging nodes with the greater degree of lagging behind to complete the block chasing process faster, because the block synchronization request needs to consume computing resources when it is responded by a normal node, and it will also occupy the network when returning the lagging block Bandwidth resources, and the number of normal nodes and computing resources in the first blockchain network, as well as the network bandwidth resources of the first blockchain network are limited, so this solution is equivalent to giving priority to the backward nodes with a greater degree of backwardness to occupy more There are many normal node computing resources and the network bandwidth resources of the first blockchain network, that is, the computing resources of normal nodes and the network bandwidth resources of the first blockchain network are reasonably allocated.
进一步的,如果动态请求周期还受到第一节点权重因子的影响,那么还能够对不同区块链节点的区块同步速率进行宏观调控,实现了区块同步任务的分层设计。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 also be macro-regulated, realizing the hierarchical design of block synchronization tasks.
可选的,所述动态请求周期通过以下方式确定:查找所述落后程度对应的落后区间,并将所述动态请求周期确定为所述落后区间对应的数值;或者,查找所述落后程度对应的落后区间,并将所述动态请求周期确定为所述落后区间对应的数值与第一节点权重因子的比值。在本说明书实施例中,动态请求周期会根据落后程度对应的落后区间而确定,具体而言,不同的落后区间可以查找得到对应的标准请求周期,而动态请求周期等于标准请求周期;或者,在所述动态请求周期还负相关于所述任一区块链节点的节点权重因子的情况下,动态请求周期等于查找得到的标准请求周期与第一节点权重因子的比值。例如在落后程度具体为本地区块高度与最新区块高度之间的差值(即落后区块数)时,标准请求周期与落后区块数的关系如表1所示。Optionally, the dynamic request period is determined in the following manner: searching for the backward interval corresponding to the backward degree, and determining the dynamic request period as a value corresponding to the backward interval; or, searching for the backward interval corresponding to the backward degree lag interval, and determine the dynamic request period as the ratio of the numerical value corresponding to the lag interval to the first node weight factor. In the embodiment of this specification, the dynamic request period will be determined according to the backward interval corresponding to the backwardness degree. Specifically, different backward intervals can be found to obtain the corresponding standard request period, and the dynamic request period is equal to the standard request period; or, in In the case that the dynamic request period is also negatively related to the node weight factor of any blockchain node, the dynamic request period is equal to the ratio of the standard request period obtained from the search to the first node weight factor. For example, when the degree of backwardness is specifically the difference between the local block height and the latest block height (that is, the number of backward blocks), the relationship between the standard request cycle and the number of backward blocks is shown in Table 1.
标准请求周期(单位:毫秒)Standard request cycle (unit: milliseconds) 落后区块数(单位:个)Number of lagging blocks (unit: piece)
10001000 0~1000~100
500500 101~1000101~1000
200200 >1000>1000
表1Table 1
由表1可知,当落后区块数处于0至100的区间(含两端)内时,可以查找得到该区间对应的标准请求周期为1000ms,假设考虑第一节点权重因子的影响且第一节点权重因子的值为2,那么可将动态请求周期确定为500ms;同理,当落后区块数处于101至1000的区间时,首先查找得到标准请周期为500ms,让后将其与第一节点权重因子相除得到动态请求周期为250ms;当落后区块数超过1000时,查找得到标准请周期为200ms,然后进一步将动态请求周期确定为100ms.由此可见,从整体上来看,落后区块数越大,动态请求周期就越小,即动态请求周期负相关于落后程度,同时。It can be seen from Table 1 that when the number of lagging blocks is in the interval from 0 to 100 (both ends included), it can be found that the standard request cycle corresponding to this interval is 1000ms, assuming that the influence of the weight factor of the first node is considered and the first node The value of the weight factor is 2, then the dynamic request period can be determined as 500ms; similarly, when the number of backward blocks is in the range of 101 to 1000, first find the standard request period as 500ms, and then compare it with the first node The dynamic request period is 250ms by dividing the weight factor; when the number of backward blocks exceeds 1000, the standard request period is found to be 200ms, and then the dynamic request period is further determined as 100ms. It can be seen that, on the whole, the backward block The larger the number, the smaller the dynamic request period, that is, the dynamic request period is negatively related to the degree of lag, and at the same time.
或者,所述动态请求周期通过以下方式确定:将所述动态请求周期确定为固定请求周期与所述落后程度对应的落后因子的乘积;或者,在所述动态请求周期还负相关于所述任一区块链节点的节点权重因子的情况下,将所述动态请求周期确定为所述乘积与第一节点权重因子的比值。Alternatively, the dynamic request period is determined in the following manner: the dynamic request period is determined as the product of a fixed request period and a lagging factor corresponding to the lagging degree; or, the dynamic requesting period is also negatively correlated with the any In the case of a node weight factor of a blockchain node, the dynamic request period is determined as the ratio of the product to the first node weight factor.
在本说明书实施例中,动态请求周期需要通过计算式得到:动态请求周期P=P0×f或者P=P0×f/d,其中P0代表固定请求周期,该值由管理员进行指定,且在没有被修改之前不会发生变化而作为一个固定值,f代表落后因子,该参数正相关于所述落后程度,d代表第一节点权重因子。In the embodiment of this 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 in As a fixed value, it will not change until it is modified, f represents the backwardness factor, and this parameter is positively related to the backwardness degree, and d represents the weight factor of the first node.
所述落后因子包括:所述区块同步请求单次所允许请求的最大区块数除以所述本地区块高度与所述最新区块高度之间的差值;或者,所述本地区块高度与所述最新区块高度之比。The lagging factor includes: the maximum number of blocks allowed for a single block synchronization request divided by the difference between the local block height and the latest block height; or, the local block The ratio of the height to the latest block height.
例如,f=M/(Hn-Hl),其中,M代表区块同步请求单次所允许请求的最大区块数(区块请求数上限),Hn代表最新区块高度,Hl代表本地区块高度,在本说明书实施例中,第一区块链节点的落后程度具体为本地区块高度与最新区块高度之间的差值,显然,落后区块数越大(即Hn-Hl越大),则落后因子f越小,而动态请求周期P就随之越小,即动态请求周期负相关于落后程度。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 block requests), Hn represents the latest block height, and H1 represents the local block Height, in the embodiment of this description, the degree of backwardness of the first blockchain node is specifically the difference between the height of the local block and the height of the latest block. Obviously, the greater the number of backward blocks (that is, the greater the number of Hn-H1 ), the smaller the lag factor f is, the smaller the dynamic request period P is, that is, the dynamic request period is negatively related to the lagging degree.
又例如,f=H1/Hn,在本说明书实施例中,第一区块链节点的落后程度具体为本地区块高度与最新区块高度之间的比值,显然,落后程度越大,则落后因子f越小,而动态请求周期P就随之越小,动态请求周期同样负相关于落后程度。Another example, f=H1/Hn, in the embodiment of this specification, the degree of backwardness of the first blockchain node is specifically the ratio between the height of the local block and the height of the latest block. Obviously, the greater the degree of backwardness, the greater the backwardness The smaller the factor f is, the smaller the dynamic request period P is, and the dynamic request period is also negatively related to the degree of lag.
可选的,所述落后因子设置有因子上界和/或因子下界,所述因子上界用于在所述落后因子超过所述因子上界的情况下将所述落后因子重新确定为所述因子上界,所述因子下界用于在所述落后因子低于所述因子下界的情况下将所述落后因子重新确定为所述因子下界。在本说明书实施例中,会对上述的落后因子的取值范围进行限制,从而间接对动态请求周期的取值范围进行限制,以使其满足区块同步任务的实际要求。例如,在f=M/(Hn-Hl)的情况下,如果本地区块高度与最新区块高度之间的差值不超过区块同步请求单次所允许请求的最大区块数,那么第一区块链节点所确定的到的f将可能过大由此导致最终确定得到的动态请求周期P过大,从而无法正常完成追块过程,为了避免这种情况下,就可以为f设置一个值为1的因子上界,这样一来,当本地区块高度与最 新区块高度之间的差值不超过区块同步请求单次所允许请求的最大区块数时,第一区块链节点所计算出的f虽然大于1,然而由于因子上界的作用将被重新确定为1,这样就能保证动态请求周期存在一个合理的最大值,以确保落后节点能够正常完成追块过程。Optionally, the lag factor is set with a factor upper bound and/or a factor lower bound, and the factor upper bound is used to re-determine the lag factor as the The factor upper bound, the factor lower bound is used to re-determine the lagging factor as the factor lower bound if the lagging factor is lower than the factor lower bound. In the embodiment of this specification, the value range of the aforementioned lagging factor is limited, thereby indirectly restricting the value range of the dynamic request period so as to meet the actual requirements of the block synchronization task. For example, in the case of f=M/(Hn-H1), 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 first The f determined by a blockchain node may be too large, resulting in the final dynamic request period P being too large, so that the block chasing process cannot be completed normally. In order to avoid this situation, a value can be set for f The upper bound of the factor with a value of 1, so that 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, the first blockchain Although the f calculated by the node is greater than 1, it will be re-determined as 1 due to the effect of the upper bound of the factor, so as to ensure that there is a reasonable maximum value of the dynamic request period, so as to ensure that the lagging nodes can normally complete the block chasing process.
可选的,所述动态请求周期设置有周期上界和/或周期下界,所述周期上界用于在所述动态请求周期超过所述周期上界的情况下将所述动态请求周期重新确定为所述周期上界,所述周期下界用于在所述动态请求周期低于所述周期下界的情况下将所述动态请求周期重新确定为所述周期下界。如前所述,可以针对落后因子的取值范围进行限制由此间接地对动态请求周期的范围进行限制,而在本说明书实施例中,也可以直接对对动态请求周期的取值范围进行限制,以使其满足区块同步任务的实际要求。Optionally, the dynamic request period is set with a period upper bound and/or a period lower bound, and the period upper bound is used to re-determine the dynamic request period when the dynamic request period exceeds the period upper bound is the upper bound of the period, and the lower bound of the period is used to re-determine the dynamic request period as the lower bound of the period when the dynamic request period is lower than the lower bound of the period. As mentioned above, the value range of the lagging factor can be limited, thereby indirectly restricting the range of the dynamic request period, and in the embodiment of this specification, the value range of the dynamic request period can also be directly limited , so that it meets the actual requirements of the block synchronization task.
可选的,所述周期上界包括固定周期上界或动态周期上界,所述周期下界包括固定周期下界或动态周期下界。其中,所述动态周期上界包括:所述区块同步请求单次所允许请求的最大区块数与第一区块链网络的区块增长速度之比;所述动态周期下界包括:所述区块同步请求所需请求的区块数与第一区块链节点对应的区块缓存空间当前剩余存放的最大区块数之间的差值除以本地区块处理速度。在本说明书实施例中,周期上界和/或周期下界可以设置为一个固定值,称为固定周期上界和/或固定周期下界,也可以设置为动态值,称为动态周期上界和/或动态周期下界。Optionally, the upper bound of the period includes an upper bound of a fixed period or an upper bound of a dynamic period, and the lower bound of a period includes a lower bound of a fixed period or a lower bound of a dynamic period. Wherein, the upper bound of the dynamic period includes: the ratio of the maximum number of blocks allowed for a single block synchronization request to the block growth rate of the first blockchain network; the lower bound of the dynamic period includes: the The difference between the number of blocks requested by the block synchronization request and the maximum number of blocks currently stored in the block cache space corresponding to the first blockchain node is divided by the local block processing speed. In the embodiment of this specification, the cycle upper bound and/or the cycle lower bound can be set to a fixed value, called the fixed cycle upper bound and/or the fixed cycle lower bound, or can be set to a dynamic value, called the dynamic cycle upper bound and/or or dynamic period lower bound.
由于本说明书实施例所涉及的区块同步方案在实施过程中并不会影响第一区块链网络的原有的区块共识过程,这意味着在区块同步的过程中,第一区块链网络也会产生出新的区块,第一区块链网络对应的最新区块高度会不断的增加,即第一区块链网络存在一个客观的区块增长速度,所述区块增长速度可以由第一区块链节点通过检测最新区块高度的变化率所得到,所述区块增长速度是一个动态变化的值。假如区块同步请求单次所允许请求的最大区块数为M,那么如果动态请求周期过大,将可能导致即使每次同步请求都请求M个区块,也无法追上等待的一个动态请求周期中第一区块链网络自然增长的区块数,这样一来,任何落后节点都不可能追上正常节点所维护的区块,因此,可以通过将动态周期上界设置为所述区块同步请求单次所允许请求的最大区块数与第一区块链网络的区块增长速度之比,从而使得落后区块在理论上能够完成追块过程。Since the block synchronization scheme involved in the embodiment of this specification will not affect the original block consensus process of the first block chain network during the implementation process, it means that during the block synchronization process, the first block The chain 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, and the block growth rate It 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 for a single block synchronization request is M, then if the dynamic request cycle is too large, it may cause that even if each synchronization request requests M blocks, it will not be able to catch up with a waiting dynamic request The number of blocks that the first blockchain network naturally grows in the cycle, so that any lagging node cannot catch up with the blocks maintained by the normal nodes. Therefore, by setting the upper bound of the dynamic cycle to the block The ratio of the maximum number of blocks allowed for a single synchronous request to the block growth rate of the first blockchain network, so that lagging blocks can theoretically complete the block chasing process.
在本说明书实施例中,第一区块链节点在接收到正常节点返回的落后区块后,需要首先对这些区块按照区块高度由低到高的顺序进行处理,即自行这些区块中包含的交易,然后在将其更新至本地维护的分布式账本中,因此对于第一区块链节点而言,其存在一个客观的本地区块处理速度,同时,第一区块链节点还会由第一节点设备分配一个专门用于存放未处理的区块的内存空间,即前述的区块缓存空间,第一节点设备会将接收到的落后区块首先缓存在这个区块缓存空间中,由第一区块链节点从区块缓存空间中读取并处理区块,每次处理完一个区块就会通知第一节点设备将该处理完的这个区块从区块缓存空间中移除,以腾出空间存放更多的区块。假如动态请求周期过小,很可能会导致接收到的落后区块无法完全缓存在区块缓存空间中,从而产生内存溢出和区块丢失的现象,其本质上是请求的区块数超过了当前区块缓存空间所能容纳的极限,而为了避免这种现象,理论上需要确保某次区块同步请求所需请求的区块数不超过当前区块缓存空间所剩余存放的最大区块数(通过剩余的内存容量除以单个区块的平均大小估算得到),但由于区块同步请求是在等待动态请求周期的初期就已经生成,因此在等待一个动态请求周期的过程中,还会有一部分区块被处理并从区块缓存空间中移除,这意味着,假设某个周期中新确定的区块同步请求所需请求的区块数为M1,新的等待周期的初期所确定的区块缓存空间当前剩余存放的最大区块数为Z,本地区块处理速度为v,那么只需要满足M1≥Z-vP,即本周期所需等待的动态请求周期应该满足P≥(Z-M1)/v的情况下,就不会产生上述内存溢出和区块丢失的现象。因此,可以将所述动态周期设置为所述区块同步请求所需请求的区块数与第一区块链节点对应的区块缓存空间当前剩余存放的最大区块数之间的差值除以本地区块处理速度,从而防止内存溢出和区块丢失的现象,同时最大限度地利用在等待一个动态请求周期时由区块处理所腾出的区块缓存空间。In the embodiment of this specification, after the first block chain node receives the backward blocks returned by the normal nodes, it needs to process these blocks in the order of block height from low to high, that is, to process these blocks by itself. The included transactions are then updated to the locally maintained distributed ledger, so for the first blockchain node, there is an objective local block processing speed, and at the same time, the first blockchain node will also The first node device allocates a memory space dedicated to storing unprocessed blocks, that is, the aforementioned block cache space, and the first node device will first cache the received backward blocks in this block cache space, The first blockchain node reads and processes blocks from the block cache space, and every time a block is processed, it will notify the first node device 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 outdated blocks cannot be fully cached in the block cache space, resulting in memory overflow and block loss. In essence, the number of requested blocks exceeds the current The limit that the block cache space can accommodate, and in order to avoid this phenomenon, it is theoretically necessary to ensure that the number of blocks requested for a block synchronization request does not exceed the maximum number of blocks remaining in the current block cache space ( It is estimated by dividing the remaining memory capacity by the average size of a single block), but since the block synchronization request is generated at the beginning of the waiting dynamic request cycle, there will still be some Blocks are processed and removed from the block cache space, which means that assuming that the number of blocks required for a newly determined block synchronization request in a certain period is M1, the area determined at the beginning of the new waiting period The maximum number of blocks currently stored in the block cache space is Z, and the local block processing speed is v, so it only needs to satisfy M1≥Z-vP, that is, the dynamic request period to be waited in this cycle should satisfy P≥(Z-M1 )/v, the above memory overflow and block loss will not occur. Therefore, the dynamic period can be set as the difference between the number of blocks requested by the block synchronization request and the maximum number of blocks currently stored in the block cache space corresponding to the first blockchain node divided by At local block processing speed, thereby preventing memory overflow and block loss, while maximizing the use of block cache space vacated by block processing while waiting for a dynamic request cycle.
可选的,所述区块链系统包括区块链主网及其管理的区块链子网,且部署有区块链子网中的子网节点的节点设备上还部署有主网节点;第一节点设备上维护有所述区块链主网中各主网节点分别所处的节点设备之间的网络拓扑结构以及所述网络拓扑结构对应的网络延迟信息;所述将所述区块同步请求转发至所述正常节点,包括:基于所述网络延迟信息从所述网络拓扑结构中确定第一节点设备与所述正常节点所处目标节点设备之间总延迟最小的转发路径,将所述区块同步请求根据确定出的转发路径转发至所述正常节点。Optionally, the blockchain system includes a blockchain main network and a blockchain subnet managed by it, and the node devices deployed with subnetwork nodes in the blockchain subnet are also deployed with main network nodes; the first The node device maintains the network topology 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; the block synchronization request Forwarding to the normal node includes: determining the forwarding path with the smallest total delay between the first node device and the target node device where the normal node is located from the network topology based on the network delay information, and transferring the The block synchronization request is forwarded to the normal node according to the determined forwarding path.
在本说明书实施例中,节点设备是用于运行区块链节点的硬件实体,而区块链节点 则是指运行在节点设备中的软件进程,正如图1所示的网络架构,任一区块链网络中不同的区块链节点部署于不同的节点设备上,而各区块链节点之间的网络链路其实质上是对应所处的节点设备之间的网络链路。因此,在所述任一区块链节点所属区块链网络为区块链主网subnet0的情况下,对于所述任一区块链节点例如nodeC而言,假设其需要将消息发送至subnet0中的其他主网节点例如nodeE,只需要将该消息从nodeC所处的节点设备3发送至nodeE所处的节点设备5即可完成对应的消息传输。In the embodiment 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, just like the network architecture shown in Figure 1, any area Different blockchain nodes in the blockchain network are deployed on different node devices, and the network links between the blockchain nodes are essentially the network links between corresponding node devices. Therefore, in the case that the blockchain network to which any blockchain node belongs is the blockchain main network subnet0, for any blockchain node such as nodeC, it is assumed that it needs to send a message to subnet0 Other main network nodes such as nodeE, only need to send the message from the node device 3 where nodeC is located to the node device 5 where nodeE is located to complete the corresponding message transmission.
第一节点设备在接收到所述任一区块链节点所发出的区块同步请求后,根据所述区块同步请求的目的通讯地址获知该区块同步请求需要发送至所述正常节点,而由于第一节点设备需要将区块同步请求转发至正常节点,因此第一节点设备需要获知从第一节点设备到所述正常节点所处的目标节点设备的路由信息。在本说明书实施例中,第一节点设备通过将获取到的第一节点设备与所处目标节点设备之间总延迟最小的转发路径作为路由信息,将区块同步请求转发至该转发路径中作为下一跳的节点设备,并逐步转发至目标节点设备。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 Since the first node device needs to forward the block synchronization request to the normal node, the first node device needs to obtain 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 forwarding path by using the acquired forwarding path with the smallest total delay between the first node device and the target node device as routing information. The node device of the next hop, and gradually forwards to the target node device.
由于第一节点设备部署有主网节点,因此第一节点设备可以通过查询区块链主网中各主网节点的网络连接关系生成部署有主网节点的各节点设备之间的网络拓扑结构,并且由于区块链主网管理有各区块链子网的子网信息,这其中就包括任一区块链子网中各节点成员的身份信息、所在节点设备等,因此,第一节点设备所维护的网络拓扑结构中,除了包含有各节点设备之间的网络连接关系,还包含有各节点设备上所部署的子网节点的情况,即网络拓扑结构包含以区块链主网与各区块链子网所构成的区块链系统的整体网络结构。Since the first node device is deployed with main network nodes, the first node device can generate the network topology among the node devices deployed with main network nodes by querying the network connection relationship of each main network node in the blockchain main network, And because 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 it is located, etc. Therefore, the first node device maintains In the network topology, in addition to the network connection relationship between each node device, it also includes the situation of the subnet nodes deployed on each node device, that is, the network topology includes the blockchain main network and each blockchain subnet. The overall network structure of the blockchain system formed.
本说明书实施例所涉及的网络拓扑结构是指区块链主网中各主网节点所处节点设备之间的连接关系,该网络拓扑结构是基于所述区块链主网中各主网节点之间的网络连接关系而生成,可以通过图形形式所表示。图3是一示例性实施例提供的一种网络拓扑结构的示意图,如图3所示,该网络拓扑结构用于表征各节点设备上的区块链节点部署情况,以及各节点设备之间的网络链路情况。因此,可以将图3所示的各节点设备之间的连接关系视为一种用于表示上述网络拓扑结构的表现形式,当然,也可以通过矩阵或表格的形式来表示上述网络拓扑结构,这里不做任何限制。The network topology involved in the embodiments of this specification refers to the connection relationship between the node devices where each main network node in the blockchain main network is located. The network topology is based on the main network nodes in the blockchain main network. It is generated by the network connection relationship between them, which can be represented graphically. Fig. 3 is a schematic diagram of a network topology provided by an exemplary embodiment. As shown in Fig. 3, the network topology is used to characterize the deployment of blockchain nodes on each node device, and the network topology between each node device Network link condition. Therefore, the connection relationship between the node devices shown in FIG. 3 can be regarded as a form of representation for representing the above-mentioned network topology structure. Of course, the above-mentioned network topology structure can also be represented in the form of a matrix or a table. Here Do not make any restrictions.
本说明书实施例所涉及的所述网络拓扑结构对应的网络延迟信息,包括:所述网络拓扑结构中的网络链路的链路延迟,和/或所述网络拓扑结构中的节点设备在转发消息时的节点延迟。如图3所示,网络拓扑结构中包含的各网络链路的链路延迟以及各节点设备的节点延迟。其中,网络链路的链路延迟是指消息在该网络链路上转发所需的时延信息,例如图3中节点设备1与节点设备2之间的网络链路的链路延迟为100;节点设备的节点延迟是指消息在进入该节点设备到从该节点设备转发出去所需的时延信息,具体包含节点设备对消息进行解析、查路由表和转发的过程,例如图3中节点设备1的节点延迟为3,节点设备4的转发延迟为5。在本说明书实施例中,链路延迟和节点延迟对应的数值可以代表具体的时延时长,也可以代表与具体时延时长具有相关性的其他时延指标,但链路延迟和节点延迟之间需要统一单位。例如节点设备1与节点设备2之间的网络链路的链路延迟100可以理解为100毫秒(ms),即表征消息通过该网络链路需要经过100ms,那么节点设备1的节点延迟3就应理解为3ms。The network delay information corresponding to the network topology involved in the embodiment of this specification includes: the link delay of the network link in the network topology, and/or the node device in the network topology is forwarding the message The node delay at time. As shown in FIG. 3 , the link delay of each network link included in the network topology structure and the node delay of each node device. Wherein, the link delay of the network link refers to the delay information required for message forwarding on the network link, for example, the link delay of the network link between node device 1 and node device 2 in Figure 3 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, specifically including the process of the node device parsing the message, checking the routing table, and forwarding the message, such as the node device in Figure 3 The node delay of 1 is 3, and the forwarding delay of node device 4 is 5. In the embodiment of this specification, the values corresponding to the link delay and the node delay may represent the specific delay length, and may also represent other delay indicators related to the specific delay length, but the link delay and node delay Units need to be unified. For example, the link delay 100 of the network link between node device 1 and node device 2 can be understood as 100 milliseconds (ms), that is, it takes 100 ms for a message to pass through the network link, then the node delay 3 of node device 1 should be It is understood as 3ms.
本说明书实施例所涉及的第一节点设备与所述正常节点所处目标节点设备之间总延迟最小的转发路径是通过区块链主网中各主网节点分别所处的节点设备之间的网络拓扑结构以及所述网络拓扑结构对应的网络延迟信息所确定。具体而言,第一节点设备在需要向所述正常节点发送区块同步请求时,可以通过本地维护的所述网络拓扑结构以及所述网络延迟信息确定出第一节点设备与目标节点设备之间总延迟最小的转发路径。The forwarding path with the smallest total delay between the first node device involved in the embodiment of this specification and the target node device where the normal node is located is through the node devices where each main network node in the blockchain main network is respectively located. The network topology and the network delay information corresponding to the network topology are determined. Specifically, when the first node device needs to send a block synchronization request to the normal node, it can determine the distance between the first node device and the target node device through the locally maintained network topology structure and the network delay information. The forwarding path with the least total delay.
由于第一节点设备维护的所述网络拓扑结构包含各节点设备之间的网路链路连接关系,因此第一节点设备可以在确定所述网络拓扑结构中第一节点设备与目标节点设备的相对网络位置关系并确保可达性的情况下,生成第一节点设备与所述目标节点设备之间的转发路径。以图3为例,假设第一节点设备为节点设备3,nodeC为所述任一区块链节点,nodeE为正常节点,现在nodeC检测到自身属于落后节点,并已经等待了一个动态请求周期,nodeC需要向nodeE发送区块同步请求,于是nodeC将区块同步请求发送至其所处的节点设备3,节点设备3在接收到该区块同步请求后,首先需要基于自身维护的所述网络拓扑结构确定节点设备3(第一节点设备)至nodeE所处的节点设备5(目标节点设备)之间的转发路径,显然根据网络拓扑结构可以发现从节点设备3与节点设备5之间并不存在直接相连的网络链路,并且在不考虑环路和原路返回的转发路径中,节点设备3与节点设备5之间的转发路径包括两条:其一,是节点设备3→节点设 备1→节点设备2→节点设备5;其二,是节点设备3→节点设备1→节点设备4→节点设备2→节点设备5。节点设备3在确定可选的两条转发路径后,进一步基于网络延迟信息从可选的两条转发路径中确定出节点设备3与节点设备5之间总延迟最小的转发路径,其中,转发路径对应的总延迟为该转发路径上从第一节点设备到所述目标节点设备途经的至少一段网络链路的链路延迟和/或途经的至少一个节点设备(不包括第一节点设备和目标节点设备)的节点延迟之和。因此,第一节点设备在确定转发路径的总延迟时,可以仅计算从第一节点设备到所述目标节点设备途经的所有网络链路的链路延迟,也可以仅计算从第一节点设备到所述目标节点设备途经的所有节点设备的节点延迟,还可以同时考虑从第一节点设备到所述目标节点设备途经的所有网络链路的链路延迟以及途径的所有节点设备的节点延迟。例如,以图3为例,由于节点设备3→节点设备1→节点设备2→节点设备5这条转发路径途径的所有网络链路和所有节点设备的总延迟为166,而节点设备3→节点设备1→节点设备4→节点设备2→节点设备5这条转发链路途径的所有网络链路和所有节点设备的总延迟为131,因此节点设备3最终确定的转发路径为节点设备3→节点设备1→节点设备4→节点设备2→节点设备5,从而节点设备3可以进一步确定该转发路径中作为下一跳的节点设备1,于是将所述区块同步请求转发至节点设备1。Since the network topology maintained by the first node device includes the network link connection relationship between each node device, the first node device can determine the relative relationship between the first node device and the target node device in the network topology. In a case where the network location relationship is ensured and reachability is ensured, a forwarding path between the first node device and the target node device is generated. Taking Figure 3 as an example, assume that the first node device is node device 3, nodeC is any one of the blockchain nodes, and nodeE is a normal node. Now nodeC detects that it belongs to a lagging node and has waited for a dynamic request period. nodeC needs to send a block synchronization request to nodeE, so nodeC sends the block synchronization request to the node device 3 where it is located. After receiving the block synchronization request, node device 3 first needs to base on the network topology maintained by itself The structure determines the forwarding path between the node device 3 (the first node device) and the node device 5 (the target node device) where nodeE is located. Obviously, according to the network topology, it can be found that there is no Directly connected network links, and in the forwarding path without considering the loop and the original path 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; secondly, node device 3→node device 1→node device 4→node device 2→node device 5. After the node device 3 determines the two optional forwarding paths, it further determines the forwarding path with the smallest total delay between the node device 3 and the node device 5 from the two optional forwarding paths based on the network delay information, wherein the forwarding path The corresponding total delay is the link delay of at least one section of the network link from the first node device to the target node device on the forwarding path and/or at least one node device (excluding the first node device and the target node device) device) node delay sum. Therefore, when the first node device determines the total delay of the forwarding path, it may only calculate the link delay of all network links from the first node device to the target node device, or it may only calculate the link delay from the first node device to the target node device. The node delays of all node devices passed by the target node device may also consider the link delays of all network links passed from the first node device to the target node device and the node delays of all the node devices passed by. For example, taking Figure 3 as an 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 node device 3→node Device 1→Node Device 4→Node Device 2→Node Device 5 The total delay of all network links and all node devices in this forwarding link path is 131, so 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.
节点设备1在接收到所述区块同步请求后,可以由节点设备1所维护的所述网络拓扑结构以及所述网络延迟信息再次确定出节点设备1至节点设备5之间总时延最短的转发路径,并由新确定的转发路径对所述区块同步请求进行二次转发,后续接收到所述区块同步请求的节点设备也按照上述相同的流程,先确定新的转发路径然后再按照新确定的转发路径对所述区块同步请求进行转发;或者,节点设备3在将区块同步请求转发至节点设备1时,还可以在区块同步请求中携带节点设备3所确定的转发路径,那么节点设备1在接收到所述区块同步请求后,可以基于所述区块同步请求中携带的所述转发路径继续查找到下一跳的节点设备为节点设备4,并将所述区块同步请求转发至节点设备4,节点设备4以及后续的节点设备按照相同的流程继续转发所述区块同步请求,直至所述区块同步请求被转发至节点设备5。节点设备5在接收到所述区块同步请求后,会进一步将所述区块同步请求转发至本地部署的nodeE,从而完成向正常节点发送区块同步请求的全部流程。After node device 1 receives the block synchronization request, it can again determine the node with the shortest total delay between node device 1 and node device 5 based on the network topology structure maintained by node device 1 and the network delay information. Forwarding path, and the newly determined forwarding path forwards the block synchronization request for a second time, and the node device that subsequently receives the block synchronization request also follows the same process as above, first determines the new forwarding path and then follows The newly determined forwarding path forwards the block synchronization request; or, when the node device 3 forwards the block synchronization request to the node device 1, it may also carry the forwarding path determined by the node device 3 in the block synchronization request , then after receiving the block synchronization request, node device 1 can continue to find out that the next-hop node device is node device 4 based on the forwarding path carried in the block synchronization request, and The block synchronization request is forwarded to the node device 4, and the 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 the node device 5. After receiving the block synchronization request, the node device 5 will further forward the block synchronization request to the locally deployed nodeE, thereby completing the entire process of sending the block synchronization request to normal nodes.
在本说明书实施例中,所述网络延迟信息包括所述网络拓扑结构中的近端网络链路的链路延迟和/或远端网络链路的链路延迟,所述近端网络链路为第一节点设备与其邻居节点设备之间的网络链路,所述远端网络链路为所述网络拓扑结构中除所述近端网络链路之外的网络链路。第一节点设备的邻居节点设备指的是与第一节点设备通过一段网络链路直接相连的节点设备,以图3为例,节点设备1对应的邻居节点设备包括节点设备2、节点设备3和节点设备4,节点设备4的邻居节点设备包括节点设备1和节点设备2。In the embodiment of this specification, the network delay information includes the link delay of the near-end network link and/or the link delay of the far-end network link in the network topology, and the near-end network link is A network link between the first node device and its neighbor node device, the remote network link is a network link in the network topology except the near-end network link. 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. Taking FIG. 3 as an example, the neighbor node device corresponding to node device 1 includes 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 .
对于第一节点设备而言,其维护有两种不同类型的网络链路,包括近端网络链路和远端网络链路。其中,近端网络链路是指与第一节点设备直接相连的网络链路,也即第一节点设备与其邻居节点设备之间的网络链路;远端网络链路,是指不与第一节点设备直接相连的网络链路,也即所述网络拓扑结构中除第一节点设备对应的近端网络链路之外的网络链路。依然以图3为例,节点设备1对应的近端网络链路包括其分别与节点设备3、节点设备4与节点设备5之间的网络链路,节点设备1对应的远端网络链路则包括节点设备1与节点设备2之间、节点设备4与节点设备2之间以及节点设备2与节点设备5之间的网络链路。For the first node device, it maintains two different types of network links, including a near-end network link and a far-end network link. Among them, the near-end 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 neighbor node device; the remote network link refers to the network link not connected to the first node device. The network link directly connected to the node device is a network link in the network topology except the near-end network link corresponding to the first node device. Still taking Figure 3 as an example, the near-end network link corresponding to node device 1 includes the network links between it and node device 3, node device 4, and node device 5 respectively, and the remote network link corresponding to node device 1 is It includes 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 .
第一节点设备根据不同类型的网络链路,按照不同的策略获取链路延迟。第一节点设备根据本端链路延迟和/或对端链路延迟确定所述近端网络链路的链路延迟;其中,所述本端链路延迟由第一节点设备通过请求应答机制对所述近端网络链路进行检测得到,所述对端链路延迟由第一节点设备的邻居节点设备通过请求应答机制对所述近端网络链路进行检测得到;和/或,接收第一节点设备的邻居节点设备发送的所述远端网络链路的链路延迟,所述远端网络链路的链路延迟由所述远端网络链路的至少一端节点设备通过请求应答机制对所述远端网络链路进行检测得到的链路延迟所确定。The first node device obtains the link delay according to different strategies according to different types of network links. The first node device determines the link delay of the near-end network link according to the local-end link delay and/or the opposite-end link delay; wherein, the local-end link delay is determined by the first node device through a request response mechanism The near-end network link is detected, and the opposite-end link delay is obtained by the neighbor node device of the first node device detecting the near-end network link through a request response mechanism; and/or receiving the first The link delay of the remote network link sent by the neighbor node device of the node device, the link delay of the remote network link is sent by at least one end node device of the remote network link through a request response mechanism It is determined by the link delay obtained by detecting the remote network link.
本说明书实施例涉及的请求应答机制涉及请求方与应答方之间的交互,并且认为请求应答机制的发起方即为上述的请求方,请求应答机制具体通过以下方式实现:请求方向应答方发送一个携带有时刻t1的请求消息,t1即请求方记录的发送该请求消息时的请求方本地时刻。应答方在接收到该请求消息后,会记录下其接收到该请求消息时的应答方本地时刻t2,然后将响应于该请求消息生成的应答消息返回至请求方,同时在应答消息中携带时刻t2和时刻t3,其中t3为应答方记录的返回该应答消息时的应答方本地 时刻。最后请求方在获取到该应答消息后,记录下接受到该应答消息时的请求方本地时刻t4,接着,从获取的应答消息中提取出t2和t3,然后计算T0=[(t4-t1)-(t3-t2)]/2,将其确定为请求方与应答方之间的网络链路的链路延迟T0。为了避免中转设备的转发延迟的干扰,请求方与应答方之间不存在其他中转设备。请求应答机制中所涉及的请求消息和应答消息可以为专用于计算链路延迟的专用消息,也可以为其他普通的正常业务请求,或者网络中的心跳消息,由于在计算链路延迟时,应答方的本地处理时间t3-t2是被考虑在内的,因此无论何种类型的请求消息和应答消息都可以适用于上述请求应答机制来使得请求方测得相关的链路延迟。The request-response mechanism involved in the embodiment 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 way: the requester sends a The request message carries the time t1, and t1 is the requester's local time recorded by the requester when sending the request message. After receiving the request message, the responder will record the responder’s local time t2 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 in the response message t2 and time t3, where t3 is the local time of the responding party recorded by the responding party when returning the response message. Finally, after obtaining the response message, the requester records the requester’s local time t4 when the response message is received, then extracts t2 and t3 from the obtained response message, and then calculates T0=[(t4-t1) -(t3-t2)]/2, which is determined 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 device, there is no other transit device between the requester and the responder. The request message and response message involved in the request-response mechanism can be dedicated messages dedicated to calculating link delays, or other ordinary normal service requests, or heartbeat messages in the network, because when calculating link delays, the response The local processing time t3-t2 of the party is taken into account, so no matter what type of request message and reply message can be applied to the above request-response mechanism to make the requester measure the relative link delay.
在本说明实施例中,第一节点设备在确定近端网络链路的链路延迟时,即可通过上述请求应答机制来确定。例如,第一节点设备可以向其邻居节点设备主动发起请求应答机制,从而确定出第一节点设备与该邻居节点设备之间的近端网络链路的链路延迟,这种由第一节点设备通过请求应答机制而测得的近端网络的链路延迟称为本端链路延迟。另一方面,由于对于任何一个网络链路而言,其包含的两端设备都可以通过发起请求应答机制来测得该网络链路的链路延迟,因此第一节点设备也可以通过接收其邻居节点设备进行请求应答机制所测得的针对第一节点设备与该邻居节点设备之间的近端网络链路的链路延迟,直接获取该近端网络链路的链路延迟,这种由邻居节点设备测得并提供至第一节点设备的近端网络链路的链路延迟称为对端链路延迟。综上,第一节点设备可以通过两种手段获取某一近端网络链路的链路延迟,因此也可以在这两种手段之间进行选择或综合考虑,例如,由第一节点设备所最终确定并记录在网络延迟信息中的近端网络链路的链路延迟可以包括:所述本端链路延迟、所述对端链路延迟、或者所述本端链路延迟与所述对端链路延迟的加权平均值。其中,在近端网络链路的链路延迟被确定为所述本端链路延迟与所述对端链路延迟的加权平均值的情况下,可以使第一节点设备所维护的网络延迟信息更加鲁棒。In this illustrative embodiment, when the first node device determines the link delay of the near-end network link, it can be determined through the above request response mechanism. For example, the first node device may actively initiate a request response mechanism to its neighbor node device, so as to determine the link delay of the near-end network link between the first node device and the neighbor node device, which is determined by the first node device The link delay of the near-end network measured through the request-response mechanism is called the local-end link delay. On the other hand, since for any network link, the devices at both ends of it can measure the link delay of the network link by initiating a request response mechanism, so the first node device can also receive the link delay of its neighbors The link delay of the near-end network link between the first node device and the neighbor node device measured by the node device through the request response mechanism directly obtains the link delay of the near-end network link, which is determined by the neighbor The link delay of the near-end network link measured and provided by the node device to the first node device is referred to as the opposite-end link delay. To sum up, the first node device can obtain the link delay of a certain near-end network link through two means, so it can also choose between these two means or consider comprehensively, for example, the final result obtained by the first node device The link delay of the near-end network link determined and recorded in the network delay information may include: the local link delay, the peer link delay, or the difference between the local link delay and the peer link delay. Weighted average of link delays. Wherein, when the link delay of the near-end network link is determined as the weighted average value of the local link delay and the peer link delay, the network delay information maintained by the first node device can be more robust.
以图3为例,假设节点设备1通过发起请求应答机制所测得的与节点设备2之间的近端网络链路的本端链路延迟为102,而节点设备2通过发起请求应答机制所测得的该近端网络链路的对端链路延迟为98,那么,对于节点设备1而言,其可以直接将自身测得的本端链路延迟102确定为与节点设备2之间的近端网络链路的链路延迟,或者将从节点设备2处接收到的由节点设备2测得的对端链路延迟98确定为该近端网络链路的链路延迟,还可以按照1:1的权重比例将本端链路延迟与对端链路延迟的平均值100确定为该近端网络链路的链路延迟,并将其记录在节点设备1本地维护的网络延迟信息中。Taking Figure 3 as an example, suppose that the local link delay of the near-end network link between node device 1 and node device 2 measured by the mechanism of initiating a request response is 102, and the delay measured by node device 2 through the mechanism of initiating a request response is 102. The measured opposite-end link delay of the near-end network link is 98, then, for the node device 1, it can directly determine the local-end link delay 102 measured by itself as the distance between the node device 2 and the node device 2. The link delay of the near-end network link, or the peer link delay 98 measured by the node device 2 received from the node device 2 is determined as the link delay of the near-end network link, and can also be determined according to 1 The weight ratio of :1 determines the average value 100 of the local link delay and the peer link delay as the link delay of the near-end network link, and records it in the network delay information locally maintained by node device 1.
由于第一节点设备仅能直接测得与其邻居节点设备之间的近端网络链路的链路延迟,而无法测得与远端网络链路的链路延迟,因此需要通过接收邻居节点设备发送或转发的包含远端网络链路的链路延迟的链路延迟分享消息,从而直接获取所述远端网络链路的链路延迟,并将其记录至网络延迟信息中对应远端网络链路处。在本说明书实施例中,第一节点设备所接收第一节点设备的邻居节点设备发送的所述远端网络链路的链路延迟,所述远端网络链路的链路延迟由所述远端网络链路的至少一端节点设备通过请求应答机制对所述远端网络链路进行检测得到的链路延迟所确定,例如,所述远端网络链路的链路延迟可以包括:所述远端网络链路的任一端节点设备检测得到的链路延迟,或者所述远端网络链路两端的节点设备分别检测得到的链路延迟的加权平均值。其中,任一端节点设备检测得到的链路延迟均是针对该远端网络链路的链路延迟,在远端网络链路的链路延迟为所述远端网络链路两端的节点设备分别检测得到的链路延迟的加权平均值的情况下,可以使第一节点设备所维护的网络延迟信息更加鲁棒。Since the first node device can only directly measure the link delay of the near-end network link between its neighbor node device, but cannot measure the link delay with the far-end network link, it is necessary to receive the Or the forwarded link delay sharing message containing the link delay of the remote network link, so as to directly obtain the link delay of the remote network link, and record it to the corresponding remote network link in the network delay information place. In the embodiment of this 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 remote At least one end node device of the end network link is determined by the link delay obtained by detecting the remote network link through the request response mechanism. For example, the link delay of the remote network link may include: the remote The link delay detected by any end node device of the end network link, or the weighted average of the link delays detected by the node devices at both ends of the remote network link. Wherein, the link delay detected by any end node device is the link delay for the remote network link, and the link delay of the remote network link is respectively detected by the node devices at both ends of the remote network link. In the case of the obtained weighted average of link delays, the network delay information maintained by the first node device can be made more robust.
如图3所示,假设第一节点设备为节点设备1,那么对于节点设备1而言,节点设备2与节点设备5之间的远端网络链路的链路延迟就无法通过请求应答机制直接测得,而是需要由节点设备2和/或节点设备5通过发起请求应答机制进行测算和确定,并由节点设备2将最终确定得到的远端网络链路的链路延迟封装至链路延迟分享消息发送或转发至节点设备1,节点设备1基于获取到的该远端网络链路的链路延迟更新自身维护的网络延迟信息。As shown in Figure 3, 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 Instead, it needs to be calculated and determined by node device 2 and/or node device 5 through the initiation request response mechanism, and node device 2 will encapsulate the final determined link delay of the remote network link into the link delay The sharing message is sent or forwarded to the node device 1, and the node device 1 updates the network delay information maintained by itself based on the acquired link delay of the remote network link.
第一节点设备可以接收来自邻居节点设备测得的远端链路延迟,在一实施例中,还包括:接收第一节点设备的邻居节点设备在请求应答机制中发送的应答消息,所述应答消息中包含所述对端链路延迟和/或所述远端网络链路的链路延迟。在本实施例中,第一节点设备所接收到的对端链路延迟和/或远端网络链路的链路延迟可以直接携带在第一节点设备向邻居节点设备发起请求应答机制时所涉及的应答消息中,因此第一节点设备只需要通过发起一次请求应答机制就可以在获得本端链路延迟的情况下,同时获得对端链路延迟和/或远端网络链路的链路延迟,从而降低网络内部交互的复杂性。在另一实施 例中,对端链路延迟和/或所述远端网络链路的链路延迟也可以携带在邻居节点设备发送或转发至第一节点设备的其他消息中。The first node device may receive the remote link delay measured from the neighbor node device, and in an embodiment, it also includes: receiving the response message sent by the neighbor node device of the first node device in the request response mechanism, the response The message includes the peer link delay and/or the link delay of the remote network link. In this embodiment, the peer link delay and/or the link delay of the remote network link received by the first node device can be directly carried when the first node device initiates the request response mechanism to the neighbor node device. In the response message, the first node device only needs to initiate a request response mechanism once to obtain the link delay of the peer end and/or the link delay of the remote network link while obtaining the link delay of the local end , thereby reducing the complexity of the interaction within the network. In another embodiment, the peer link delay and/or the link delay of the remote network link may also be carried in other messages sent or forwarded by the neighbor node device to the first node device.
如前所述,所述网络延迟信息包括:所述网络拓扑结构中的网络链路的链路延迟,和/或所述网络拓扑结构中的节点设备在转发消息时的节点延迟。可选的,还包括:获取所述网络拓扑结构中的任一节点设备的至少一个邻居节点设备对该任一节点设备进行检测得到的节点延迟,并根据获取的节点延迟确定所述任一节点设备的节点延迟;和/或,接收其他节点设备共享的所述任一节点设备的节点延迟。在本说明书实施例中,任一节点设备的节点延迟需要通过该任一节点设备对应的任一邻居节点设备所测得,具体而言,是由任一节点设备对应的任一邻居节点通过回流消息机制测得。As mentioned above, the network delay information includes: link delays of network links in the network topology, and/or node delays of node devices in the network topology when forwarding messages. Optionally, it also includes: obtaining a node delay obtained by detecting any node device from at least one neighbor node device of any node device in the network topology, and determining the node delay of any node device according to the obtained node delay The node delay of the device; and/or, receiving the node delay of any node device shared by other node devices. In the embodiment of this specification, the node delay of any node device needs to be measured by any neighbor node device corresponding to any node device, specifically, it is measured by any neighbor node corresponding to any node device through backflow The message mechanism is measured.
本说明书实施例涉及的回流消息机制涉及请求方与应答方之间的交互,并且认为回流消息机制的发起方即为上述的请求方,回流消息机制具体通过以下方式实现:请求方首先选定一个应答方并发起回流消息机制,首先请求方需要构造一个目的地址指向请求方自身的回流消息,并根据与应答方直接相连的网络链路将该回流消息发送至应答方,同时记录下发送该回流消息时的请求方本地时刻t5。应答方在接收到该回流消息后,通过查找路由表得知该回流消息的目的地址为请求方,因此会将该回流消息原路返回至请求方,请求方在接收到该回流消息后,记录下请求方本地时刻t6,然后计算T1=t6-t5,得到该回流消息从由请求方出发到返回请求方的整个周期对应的转发延迟T1,然后,请求方再从其所维护的网络延迟信息中查找出请求方与应答方之间网络链路的链路延迟T2,然后计算T3=T1-2*T2,从而最终确定应答方对应的节点延迟为T3。回流消息机制要求请求方与应答方之间不存在其他中转设备,这是因为回流消息机制所测量的对象即应答方的转发消息的节点延迟,因此增加其他中转设备将导致无法达到测量预期。The backflow message mechanism involved in the embodiment of this specification involves the interaction between the requester and the responder, and it is considered that the initiator of the backflow message mechanism is the above-mentioned requester. The backflow message mechanism is specifically implemented in the following way: the requester first selects a The responder initiates a return message mechanism. First, the requester needs to construct a return message whose destination address points 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 return message sent at the same time. The requester's local time t5 at the time of the message. After receiving the backflow message, the responder knows that the destination address of the backflow message is the requester by looking up the routing table, so it will return the backflow message to the requester through the original route. After receiving the backflow message, the requester will record Lower the local time t6 of the requester, and then calculate 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, and then the requester delays the information from the network it maintains Find the link delay T2 of the network link between the requester and the responder, and then calculate T3=T1-2*T2, so as to finally determine that the node delay corresponding to the responder is T3. The backflow message mechanism requires that there are no other transit devices between the requester and the responder. This is because the object measured by the backflow message mechanism is the node delay of the responder's forwarded message. Therefore, adding other transit devices will result in failure to meet measurement expectations.
在本说明书实施例中,所述任一节点设备的任一邻居节点设备对该任一节点设备进行检测,包括:所述任一邻居节点设备向所述任一节点设备发送回流消息,通过所述回流消息的转发延迟、所述任一邻居节点设备与所述任一节点设备之间网络链路的链路延迟,确定所述任一节点设备的节点延迟,所述回流消息为所述任一邻居节点设备向所述任一节点设备发送的目的地址指向所述任一邻居节点设备的消息。如前所述,对于任一节点设备的节点延迟,该任一节点设备的任一邻居节点设备都可以发起回流消息机制以测得。In the embodiment of this specification, any neighbor node device of the any node device detects the any node device, including: the any neighbor node device sends a backflow message to the any node device, and through the The forwarding delay of the reflux message, the link delay of the network link between the any neighbor node device and the any node device, determine the node delay of the any node device, and the reflux message is the A message sent by a neighbor node device to the any node device with a destination address pointing 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.
对于第一节点设备的某一邻居节点设备的节点延迟,第一节点设备可以通过发起回流消息机制直接检测得到,当然,由于与该邻居节点设备直接相连的节点设备可能不仅包括第一节点设备,因此第一节点设备还可接收这些节点设备通过回流消息机制所测得的该邻居节点设备对应的节点延迟,并作为参考以最终确定该邻居节点设备对应的节点延迟。以图3为例,假设节点设备1通过向节点设备4发起回流消息机制从而检测得到的节点设备4的节点延迟为3,同时还接收到节点设备2通过向节点设备4发起回流消息机制从而检测得到的节点设备4的节点延迟为7,那么对于节点设备1而言,其可以直接将自身测得的节点延迟3确定为与节点设备4的节点延迟,并将其记录在节点设备1本地维护的网络延迟信息中,或者将从节点设备2处接收到的由节点设备2测得的节点延迟7确定为节点设备4的节点延迟,并记录在节点设备1本地维护的网络延迟信息中,还可以按照1:1的权重比例将自身测得的节点延迟3与节点设备2测得的节点延迟7的平均值5确定为节点设备4的节点延迟,并将其记录在节点设备1本地维护的网络延迟信息中。For the node delay of a neighbor node device of the first node device, the first node device can directly detect and obtain it 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, Therefore, 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. Taking Figure 3 as an example, it is assumed that node device 1 detects that the node delay of node device 4 is 3 by initiating a return message mechanism to node device 4, and at the same time, it also receives that node device 2 initiates a return message mechanism to node device 4 to detect The obtained node delay of node device 4 is 7, 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 local maintenance of node device 1 In the network delay information of the node device 2, or determine the node delay 7 received from the node device 2 and measured by the node device 2 as the node delay of the node device 4, and record it in the network delay information locally maintained by the node device 1, and also The average value 5 of the node delay 3 measured by itself and the node delay 7 measured by the node device 2 can be determined as the node delay of the node device 4 according to the weight ratio of 1:1, and it is recorded in the local maintenance of the node device 1. In the network delay information.
对于第一节点设备,其无法通过回流消息机制检测得到除其邻居节点设备以外的节点设备的节点延迟,因此,第一节点设备还可以通过其他方式获取任一节点设备的节点延迟,例如,第一节点设备可以直接接收其他节点设备共享的所述任一节点设备的节点延迟。以图3为例,节点设备1无法直接检测得到节点设备5的节点延迟,但是节点设备2可以测得,因此节点设备1可以直接接收节点设备2发送给节点设备1的携带有节点设备5节点延迟的节点延迟分享消息,从而获取并确定节点设备5的节点延迟为2,并最终将其记录在本地的网络延迟信息中。当然,节点设备1也不一定要从节点设备2处获取节点设备5的节点延迟,事实上,通过前述的节点延迟的获取方式,节点设备4维护的网络延迟信息中其实也包含节点设备5的节点延迟,因此节点设备1也可以接收节点设备4发送的携带有节点设备5节点延迟的节点延迟分享消息,以获取节点设备5的节点延迟。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 in other ways, for example, the first node device A node device may directly receive the node delay of any node device shared by other node devices. Taking Figure 3 as an example, node device 1 cannot directly detect the node delay of node device 5, but node device 2 can measure it, so node device 1 can directly receive the node delay of node device 5 sent by node device 2 to node device 1. The delayed node delays sharing the message, thereby obtaining and determining that the node delay of the node device 5 is 2, and finally recording it in the local network delay information. Of course, node device 1 does not necessarily need to obtain the node delay of node device 5 from node device 2. In fact, through the aforementioned method of obtaining node delay, the network delay information maintained by node device 4 actually includes the information of node device 5. The node delay, therefore, the node device 1 may also receive the node delay sharing message carrying the node delay of the node device 5 sent by the node device 4, so as to obtain the node delay of the node device 5.
第一节点设备所维护的网络延迟信息中所述任一节点设备的节点延迟,包括:所述任一节点设备的任一邻居节点设备对该任一节点设备进行检测得到的节点延迟,或者所述任一节点设备的至少一个邻居节点设备对该任一节点设备进行检测得到的节点延迟 的加权平均值。如前所述,对于任一节点设备的节点延迟,该任一节点设备的任一邻居节点都可以检测得到,因此第一节点设备在最终确定该任一节点设备的节点延迟时,可以直接将该任一节点设备的任一邻居节点检测得到的针对该任一节点设备的节点延迟记录在本地维护的网络延迟信息中,也可以将该任一节点设备的一个或多个邻居节点设备对该任一节点设备进行检测得到的节点延迟的加权平均值确定为该任一节点设备的节点延迟,并将其记录在本地维护的网络延迟信息中。在所述任一节点设备的节点延迟被最终确定为所述任一节点设备的至少一个邻居节点设备对该任一节点设备进行检测得到的节点延迟的加权平均值的情况下,可以使第一节点设备所维护的网络延迟信息更加鲁棒。The node delay of any node device in the network delay information maintained by the first node device includes: the node delay obtained by detecting any node device by any neighbor node device of the any node device, or the A weighted average of node delays obtained by detecting any node device by at least one neighbor node device of the above node device. As mentioned above, any neighbor node of any node device can detect the node delay of any node device, so when the first node device finally determines the node delay of any node device, it can directly use The node delay for any node device detected by any neighbor node of any node device is recorded in the locally maintained network delay information, or one or more neighbor node devices of any node device can be The weighted average of the node delays detected by any node device is determined as the node delay of the any node device, and is recorded 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 of the node delays obtained by detecting any node device by at least one neighbor node device of the any node device, the first The network delay information maintained by node devices is more robust.
以图3为例,节点设备1可以分别接收节点设备3检测得到的节点设备1的节点延迟1、节点设备2检测得到的节点设备1的节点延迟3和节点设备4检测得到的节点设备1的节点延迟5,此时节点设备1可以任选其中一个节点设备所测得的节点设备1的节点延迟作为本地维护的网络延迟信息中节点设备1的节点延迟,也可以按照3:1的权重比例将节点设备3测得的节点延迟和节点设备2测得的节点延迟的加权平均值1.5确定为网络延迟信息中节点设备1的节点延迟,还可以按照1:1:1的权重比例将上述三个节点设备所检测得到的节点设备1的节点延迟的加权平均值3确定为网络延迟信息中节点设备1的节点延迟。Taking Figure 3 as an example, the node device 1 can respectively receive the node delay 1 of the node device 1 detected by the node device 3, the node delay 3 of the node device 1 detected by the node device 2, and the node delay 3 of the node device 1 detected by the node device 4. Node delay 5, at this time, node device 1 can choose 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 according to the weight ratio of 3:1 The weighted average value 1.5 of the node delay measured by node device 3 and the node delay measured by node device 2 is determined as the node delay of node device 1 in the network delay information. The weighted average 3 of the node delays of the node device 1 detected by the number of node devices is determined as the node delay of the node device 1 in the network delay information.
图4是一示例性实施例提供的一种设备的示意结构图。请参考图4,在硬件层面,该设备包括处理器402、内部总线404、网络接口406、内存408以及非易失性存储器410,当然还可能包括其他业务所需要的硬件。本说明书一个或多个实施例可以基于软件方式来实现,比如由处理器402从非易失性存储器410中读取对应的计算机程序到内存408中然后运行。当然,除了软件实现方式之外,本说明书一个或多个实施例并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。Fig. 4 is a schematic structural diagram of a device provided by an exemplary embodiment. Please refer to FIG. 4 , at 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 of course may include hardware required by other services. One or more embodiments of this specification may be implemented based on software, for example, the processor 402 reads a corresponding computer program from the non-volatile memory 410 into the memory 408 and then executes it. Of course, in addition to software implementations, 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 to say, the execution subject of the following processing flow is not limited to each A logic unit, which can also be a hardware or logic device.
如图5所示,图5是本说明书根据一示例性实施例提供的一种区块同步装置的框图,该装置可以应用于如图4所示的设备中,以实现本说明书的技术方案;该装置应用于第一节点设备,第一节点设备上部署有区块链系统内分别属于多个区块链网络的多个区块链节点,第一节点设备针对其部署的区块链节点维护有对应的区块缓存空间,其中,第一节点设备部署的任一区块链节点对应的区块缓存空间的大小正相关于所述任一区块链节点的节点权重因子。As shown in FIG. 5, FIG. 5 is a block diagram of a block synchronization device provided in this specification according to an exemplary embodiment. The device can be applied to the device shown in FIG. 4 to implement the technical solution of this specification; The device is applied to the first node device, where multiple blockchain nodes belonging to multiple blockchain networks in the blockchain system are deployed on the first node device, and the first node device maintains There is a corresponding block cache space, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively related to the node weight factor of any blockchain node.
所述装置包括:区块接收单元501,用于接收所述任一区块链节点所属区块链网络中的正常节点发送至所述任一区块链节点的落后区块,其中,所述正常节点维护有实际最新区块,且所述落后区块的区块高度处于所述任一区块链节点本地维护的最新区块的本地区块高度与所述实际最新区块的最新区块高度之间;区块缓存单元502,用于将所述落后区块缓存至所述任一区块链节点对应的区块缓存空间,以由所述任一区块链节点从所述区块缓存空间中读取并处理所述落后区块;区块移除单元503,用于在所述落后区块由所述任一区块链节点处理完毕的情况下,将所述落后区块移除所述区块缓存空间。The device includes: a block receiving unit 501, 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 The normal node maintains the 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 of the actual latest block between heights; the block cache unit 502 is used to cache the lagging block to the block cache space corresponding to any blockchain node, so that any blockchain node can retrieve the data from the block Read and process the lagging block in the buffer space; the block removal unit 503 is used to remove the lagging block when the lagging block has been processed by any of the blockchain nodes Remove the block cache space.
可选的,所述任一区块链节点的节点权重因子包括:所述任一区块链节点的节点缓存权重占所述多个区块链节点的节点缓存权重之和的比值。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 plurality of blockchain nodes.
可选的,所述区块缓存空间的大小还正相关于所述本地区块高度与所述最新区块高度之间的落后程度。Optionally, the size of the block cache space is also positively related to the degree of lag between the local block height and the latest block height.
可选的,还包括:请求转发单元504,用于接收所述任一区块链节点在所述本地区块高度落后于所述最新区块高度的情况下,按照动态请求周期进行周期性发送的针对所述落后区块的区块同步请求,并将所述区块同步请求转发至所述正常节点;其中,所述动态请求周期负相关于所述最新区块高度与所述本地区块高度之间的落后程度。Optionally, it also includes: a request forwarding unit 504, configured to receive the periodic sending by any blockchain node according to the dynamic request cycle when the local block height is behind the latest block height. The block synchronization request for the backward block, and forward the block synchronization request to the normal node; wherein, the dynamic request cycle is negatively related to the latest block height and the local block The degree of lag between heights.
可选的,所述动态请求周期还负相关于所述任一区块链节点的节点权重因子。Optionally, the dynamic request period is also negatively related to the node weight factor of any blockchain node.
可选的,所述区块链系统包括区块链主网及其管理的区块链子网,且部署有区块链子网中的子网节点的节点设备上还部署有主网节点;第一节点设备上维护有所述区块链主网中各主网节点分别所处的节点设备之间的网络拓扑结构以及所述网络拓扑结构对应的网络延迟信息;所述将所述区块同步请求转发至所述正常节点,包括:基于所述网络延迟信息从所述网络拓扑结构中确定第一节点设备与所述正常节点所处目标节点设备之间总延迟最小的转发路径,将所述区块同步请求根据确定出的转发路径转发至所述正常节点。Optionally, the blockchain system includes a blockchain main network and a blockchain subnet managed by it, and the node devices deployed with subnetwork nodes in the blockchain subnet are also deployed with main network nodes; the first The node device maintains the network topology 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; the block synchronization request Forwarding to the normal node includes: determining the forwarding path with the smallest total delay between the first node device and the target node device where the normal node is located from the network topology based on the network delay information, and transferring the The block synchronization request is forwarded to the normal node according to the determined forwarding path.
可选的,所述网络延迟信息包括所述网络拓扑结构中的近端网络链路的链路延迟和/或远端网络链路的链路延迟,所述近端网络链路为第一节点设备与其邻居节点设备之间 的网络链路,所述远端网络链路为所述网络拓扑结构中除所述近端网络链路之外的网络链路。Optionally, the network delay information includes a link delay of a near-end network link and/or a link delay of a far-end network link in the network topology, and the near-end network link is the first node A network link between a device and its neighbor node device, the remote network link is a network link in the network topology other than the near-end network link.
可选的,还包括:链路延迟获取单元505,用于根据本端链路延迟和/或对端链路延迟确定所述近端网络链路的链路延迟;其中,所述本端链路延迟由第一节点设备通过请求应答机制对所述近端网络链路进行检测得到,所述对端链路延迟由第一节点设备的邻居节点设备通过请求应答机制对所述近端网络链路进行检测得到;和/或,接收第一节点设备的邻居节点设备发送的所述远端网络链路的链路延迟,所述远端网络链路的链路延迟由所述远端网络链路的至少一端节点设备通过请求应答机制对所述远端网络链路进行检测得到的链路延迟所确定。Optionally, it also includes: a link delay obtaining unit 505, configured to determine the link delay of the near-end network link according to the local-end link delay and/or the peer-end link delay; wherein, the local-end link The path delay is obtained by the first node device detecting the near-end network link through the request-response mechanism, and the opposite-end link delay is detected by the neighbor node device of the first node device through the request-response mechanism on the near-end network link. and/or, receive 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 remote network link It is determined by the link delay obtained by detecting the remote network link through at least one end node device of the path through the request response mechanism.
可选的,还包括:应答接收单元506,用于接收第一节点设备的邻居节点设备在请求应答机制中发送的应答消息,所述应答消息中包含所述对端链路延迟和/或所述远端网络链路的链路延迟。Optionally, it also includes: a response receiving unit 506, configured to receive a response message sent by a neighbor node device of the first node device in the request response mechanism, the response message including the peer link delay and/or all The link delay of the remote network link.
可选的,所述近端网络链路的链路延迟,包括:所述本端链路延迟、所述对端链路延迟、或者所述本端链路延迟与所述对端链路延迟的加权平均值;所述远端网络链路的链路延迟,包括:所述远端网络链路的任一端节点设备检测得到的链路延迟,或者所述远端网络链路两端的节点设备分别检测得到的链路延迟的加权平均值。Optionally, the link delay of the near-end network link includes: the local-end link delay, the peer-end link delay, or the local-end link delay and the peer-end link delay The weighted average value of the remote network link; the link delay of the remote network link, including: the link delay detected by any end node device of the remote network link, or the node device at both ends of the remote network link A weighted average of the link delays obtained from the respective detections.
可选的,所述网络延迟信息包括:所述网络拓扑结构中的网络链路的链路延迟,和/或所述网络拓扑结构中的节点设备在转发消息时的节点延迟。Optionally, the network delay information includes: link delays of network links in the network topology, and/or node delays of node devices in the network topology when forwarding messages.
可选的,还包括:节点延迟获取单元507,用于获取所述网络拓扑结构中的任一节点设备的至少一个邻居节点设备对该任一节点设备进行检测得到的节点延迟,并根据获取的节点延迟确定所述任一节点设备的节点延迟;和/或,接收其他节点设备共享的所述任一节点设备的节点延迟。Optionally, it also includes: a node delay obtaining unit 507, configured to obtain the node delay obtained by detecting any node device by at least one neighbor node device of any node device in the network topology, and according to the obtained The node delay determines the node delay of any node device; and/or receives the node delay of any node device shared by other node devices.
可选的,所述任一节点设备的任一邻居节点设备对该任一节点设备进行检测,包括:所述任一邻居节点设备向所述任一节点设备发送回流消息,通过所述回流消息的转发延迟、所述任一邻居节点设备与所述任一节点设备之间网络链路的链路延迟,确定所述任一节点设备的节点延迟,所述回流消息为所述任一邻居节点设备向所述任一节点设备发送的目的地址指向所述任一邻居节点设备的消息。Optionally, any neighbor node device of the any node device detecting the any node device includes: the any neighbor node device sends a backflow message to the any node device, and the backflow message is used to The forwarding delay of any neighbor node device, the link delay of the network link between the any neighbor node device and the any node device, determine the node delay of the any node device, and the return message is the The message sent by the device to any node device with a destination address pointing to any neighbor node device.
可选的,所述任一节点设备的节点延迟,包括:所述任一节点设备的任一邻居节点设备对该任一节点设备进行检测得到的节点延迟,或者所述任一节点设备的至少一个邻居节点设备对该任一节点设备进行检测得到的节点延迟的加权平均值。Optionally, the node delay of any node device includes: a node delay obtained by detecting any node device by any neighbor node device of the any node device, or at least A weighted average of node delays obtained by a neighbor node device detecting any node device.
在20世纪90年代,对于一个技术的改进可以很明显地区分是硬件上的改进(例如,对二极管、晶体管、开关等电路结构的改进)还是软件上的改进(对于方法流程的改进)。然而,随着技术的发展,当今的很多方法流程的改进已经可以视为硬件电路结构的直接改进。设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,不能说一个方法流程的改进就不能用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device,PLD)(例如现场可编程门阵列(Field Programmable Gate Array,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如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)等,目前最普遍使用的是VHDL(Very-High-Speed Integrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。In the 1990s, the improvement of a technology can be clearly distinguished as an improvement in hardware (for example, improvements in circuit structures such as diodes, transistors, and switches) or improvements in software (improvement in method flow). However, with the development of technology, the improvement of many current method flows can be regarded as the direct improvement of the hardware circuit structure. Designers almost always get the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that the improvement of a method flow cannot be realized by hardware physical modules. For example, a programmable logic device (Programmable Logic Device, PLD) (such as a field programmable gate array (Field Programmable Gate Array, FPGA)) is such an integrated circuit, the logic function of which is determined by the user's programming of the device. It is programmed by the designer to "integrate" a digital system on a PLD, instead of asking a chip manufacturer to design and make a dedicated integrated circuit chip. Moreover, nowadays, instead of making integrated circuit chips by hand, this kind of programming is mostly realized by "logic compiler (logic compiler)" software, which is similar to the software compiler used when program development and writing, but before compiling The original code of the computer must also be written in a specific programming language, which is called a hardware description language (Hardware Description Language, HDL), and there is not only one kind of 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., are currently the most commonly used The most popular are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. It should also be clear to those skilled in the art that only a little logical programming of the method flow in the above-mentioned hardware description languages and programming into an integrated circuit can easily obtain a hardware circuit for realizing the logic method flow.
控制器可以按任何适当的方式实现,例如,控制器可以采取例如微处理器或处理器以及存储可由该(微)处理器执行的计算机可读程序代码(例如软件或固件)的计算机可读介质、逻辑门、开关、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程逻辑控制器和嵌入微控制器的形式,控制器的例子包括但不限于以下微控制器:ARC 625D、Atmel AT91SAM、Microchip PIC18F26K20以及Silicone Labs C8051F320,存储器控制器还可以被实现为存储器的控制逻辑的一部分。本领域技术人员也知道,除 了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。The controller may be implemented in any suitable way, for example the controller may take the form of a microprocessor or processor and a computer readable medium storing computer readable program code (such as software or firmware) executable by the (micro)processor , logic gates, switches, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable logic controllers and embedded microcontrollers, 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 realizing the controller in a purely computer-readable program code mode, it is entirely possible to make the controller use logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded The same function can be realized in the form of a microcontroller or the like. Therefore, such a controller can be regarded as a hardware component, and the devices included in it for realizing various functions can also be regarded as structures within the hardware component. Or even, means for realizing various functions can be regarded as a structure within both a software module realizing a method and a hardware component.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为服务器系统。当然,本发明不排除随着未来计算机技术的发展,实现上述实施例功能的计算机例如可以为个人计算机、膝上型计算机、车载人机交互设备、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。The systems, devices, modules, or units described in the above embodiments can be specifically 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 realizes the functions of the above embodiments can 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 , media players, navigation devices, email devices, game consoles, tablet computers, wearable devices, or any combination of these devices.
虽然本说明书一个或多个实施例提供了如实施例或流程图所述的方法操作步骤,但基于常规或者无创造性的手段可以包括更多或者更少的操作步骤。实施例中列举的步骤顺序仅仅为众多步骤执行顺序中的一种方式,不代表唯一的执行顺序。在实际中的装置或终端产品执行时,可以按照实施例或者附图所示的方法顺序执行或者并行执行(例如并行处理器或者多线程处理的环境,甚至为分布式数据处理环境)。术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、产品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、产品或者设备所固有的要素。在没有更多限制的情况下,并不排除在包括所述要素的过程、方法、产品或者设备中还存在另外的相同或等同要素。例如若使用到第一,第二等词语用来表示名称,而并不表示任何特定的顺序。Although one or more embodiments of the present specification provide the operation steps of the method described in the embodiment or the flowchart, more or fewer operation steps may be included based on conventional or non-inventive means. The sequence of steps enumerated in the embodiments is only one of the execution sequences of many steps, and does not represent the only execution sequence. When an actual device or terminal product is executed, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (such as a parallel processor or multi-thread processing environment, or even a distributed data processing environment). The term "comprising", "comprising" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, product, or apparatus comprising a set of elements includes not only those elements, but also other elements not expressly listed elements, or also elements inherent in such a process, method, product, or apparatus. Without further limitations, it is not excluded that there are additional identical or equivalent elements in a process, method, product or device comprising said elements. For example, if the words first, second, etc. are used, they are used to indicate names and do not indicate any specific order.
为了描述的方便,描述以上装置时以功能分为各种模块分别描述。当然,在实施本说明书一个或多个时可以把各模块的功能在同一个或多个软件和/或硬件中实现,也可以将实现同一功能的模块由多个子模块或子单元的组合实现等。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。For the convenience of description, when describing the above devices, functions are divided into various modules and described separately. Of course, when implementing one or more of the present specification, the functions of each module can be realized in the same or more software and/or hardware, and the modules that realize the same function can also be realized by a combination of multiple submodules or subunits, etc. . The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated. to another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
本发明是参照根据本发明实施例的方法、装置(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each procedure and/or block in the flowchart and/or block diagram, and a combination of procedures and/or blocks in the flowchart and/or block diagram can be realized by computer program instructions. These computer program instructions may be provided to a general purpose computer, special purpose computer, embedded processor, or processor of other programmable data processing equipment to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing equipment produce a An apparatus for realizing the functions specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions The device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby The instructions provide steps for implementing the functions specified in the flow chart or blocks of the flowchart and/or the block or blocks of the block diagrams.
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent storage in computer readable media, in the form of random access memory (RAM) and/or nonvolatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer readable media.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁 带磁磁盘存储、石墨烯存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information. Information may be computer readable instructions, data structures, modules of a program, 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 Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic cassettes, magnetic tape magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission medium that can be used to store information that can be accessed by computing devices. As defined herein, computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.
本领域技术人员应明白,本说明书一个或多个实施例可提供为方法、系统或计算机程序产品。因此,本说明书一个或多个实施例可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本说明书一个或多个实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that one or more embodiments of this specification may be provided as a method, system or computer program product. Accordingly, one or more embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of the present description may employ a computer program embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein. The form of the product.
本说明书一个或多个实施例可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本本说明书一个或多个实施例,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。One or more embodiments of this specification may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. One or more embodiments of the present specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including storage devices.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本说明书的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。Each embodiment in this specification is described in a progressive manner, the same and similar parts of each embodiment 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 for relevant parts, refer to part of the description of the method embodiment. In the description of this specification, descriptions referring to the terms "one embodiment", "some embodiments", "example", "specific examples", or "some examples" mean that specific features described in connection with the embodiment or example , structures, materials or features are included in at least one embodiment or example of this specification. In this specification, the schematic representations of the above terms are not necessarily directed to the same embodiment or example. Furthermore, the described specific features, structures, materials or characteristics may be combined in any suitable manner in any one or more embodiments or examples. In addition, those skilled in the art can combine and combine different embodiments or examples and features of different embodiments or examples described in this specification without conflicting with each other.
以上所述仅为本说明书一个或多个实施例的实施例而已,并不用于限制本本说明书一个或多个实施例。对于本领域技术人员来说,本说明书一个或多个实施例可以有各种更改和变化。凡在本说明书的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在权利要求范围之内。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, various modifications and changes may occur in one or more embodiments of this description. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this specification shall be included in the scope of the claims.

Claims (17)

  1. 一种区块同步方法,应用于第一节点设备,第一节点设备上部署有区块链系统内分别属于多个区块链网络的多个区块链节点,第一节点设备针对其部署的区块链节点维护有对应的区块缓存空间,其中,第一节点设备部署的任一区块链节点对应的区块缓存空间的大小正相关于所述任一区块链节点的节点权重因子;所述方法包括:A block synchronization method, applied to a first node device, where multiple blockchain nodes in the blockchain system respectively belonging to multiple blockchain networks are deployed on the first node device, and the first node device is deployed for its The blockchain node maintains a corresponding block cache space, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively related to the node weight factor of any blockchain node ; the method comprising:
    接收所述任一区块链节点所属区块链网络中的正常节点发送至所述任一区块链节点的落后区块,其中,所述正常节点维护有实际最新区块,且所述落后区块的区块高度处于所述任一区块链节点本地维护的最新区块的本地区块高度与所述实际最新区块的最新区块高度之间;Receive the backward block sent to the arbitrary blockchain node by the normal node in the blockchain network to which the arbitrary blockchain node belongs, wherein the normal node maintains the actual latest block, and the backward The block height of the 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 to the block cache space corresponding to any blockchain node, so that any blockchain node can read and process the backward block from the block cache space ;
    在所述落后区块由所述任一区块链节点处理完毕的情况下,将所述落后区块移除所述区块缓存空间。In the case that the lagging block has been processed by any of the blockchain nodes, the lagging block is removed from the block cache space.
  2. 根据权利要求1所述的方法,所述任一区块链节点的节点权重因子包括:所述任一区块链节点的节点缓存权重占所述多个区块链节点的节点缓存权重之和的比值。The method according to claim 1, the node weight factor of any blockchain node includes: the node cache weight of any blockchain node accounts for the sum of the node cache weights of the multiple blockchain nodes ratio.
  3. 根据权利要求1所述的方法,所述区块缓存空间的大小还正相关于所述本地区块高度与所述最新区块高度之间的落后程度。According to the method of claim 1, the size of the block cache space is also positively related to the degree of lag between the local block height and the latest block height.
  4. 根据权利要求1所述的方法,还包括:The method according to claim 1, further comprising:
    接收所述任一区块链节点在所述本地区块高度落后于所述最新区块高度的情况下,按照动态请求周期进行周期性发送的针对所述落后区块的区块同步请求,并将所述区块同步请求转发至所述正常节点;receiving a block synchronization request for the backward block periodically sent by any blockchain node according to the dynamic request cycle when the local block height is behind the latest block height, and Forwarding the block synchronization request to the normal node;
    其中,所述动态请求周期负相关于所述最新区块高度与所述本地区块高度之间的落后程度。Wherein, the dynamic request period is negatively correlated with the degree of lag between the latest block height and the local block height.
  5. 根据权利要求4所述的方法,所述动态请求周期还负相关于所述任一区块链节点的节点权重因子。According to the method of claim 4, the dynamic request period is also negatively related to the node weight factor of any blockchain node.
  6. 根据权利要求4所述的方法,所述区块链系统包括区块链主网及其管理的区块链子网,且部署有区块链子网中的子网节点的节点设备上还部署有主网节点;第一节点设备上维护有所述区块链主网中各主网节点分别所处的节点设备之间的网络拓扑结构以及所述网络拓扑结构对应的网络延迟信息;所述将所述区块同步请求转发至所述正常节点,包括:According to the method described in claim 4, the block chain system includes a block chain main network and a block chain subnet managed by the block chain, and the node device deployed with the subnet node in the block chain subnet is also deployed with a main network node; the first node device maintains the network topology between the node devices where each main network node in the block chain main network is respectively located and the network delay information corresponding to the network topology; The block synchronization request is forwarded to the normal node, including:
    基于所述网络延迟信息从所述网络拓扑结构中确定第一节点设备与所述正常节点所处目标节点设备之间总延迟最小的转发路径,将所述区块同步请求根据确定出的转发路径转发至所述正常节点。Determine the forwarding path with the smallest total delay between the first node device and the target node device where the normal node is located from the network topology based on the network delay information, and forward the block synchronization request according to the determined forwarding path Forward to the normal node.
  7. 根据权利要求6所述的方法,所述网络延迟信息包括所述网络拓扑结构中的近端网络链路的链路延迟和/或远端网络链路的链路延迟,所述近端网络链路为第一节点设备与其邻居节点设备之间的网络链路,所述远端网络链路为所述网络拓扑结构中除所述近端网络链路之外的网络链路。The method according to claim 6, the network delay information comprises the link delay of the near-end network link and/or the link delay of the far-end network link in the network topology, the near-end network link A path is a network link between the first node device and its neighboring node devices, and the remote network link is a network link in the network topology except the near-end network link.
  8. 根据权利要求7所述的方法,还包括:The method according to claim 7, further comprising:
    根据本端链路延迟和/或对端链路延迟确定所述近端网络链路的链路延迟;其中,所述本端链路延迟由第一节点设备通过请求应答机制对所述近端网络链路进行检测得到,所述对端链路延迟由第一节点设备的邻居节点设备通过请求应答机制对所述近端网络链路进行检测得到;和/或,Determine the link delay of the near-end network link according to the link delay of the local end and/or the link delay of the opposite end; wherein, the link delay of the local end is provided by the first node device to the near-end through a request response mechanism The network link is detected, and the peer link delay is obtained by the neighbor node device of the first node device detecting the near-end network link through a request response mechanism; and/or,
    接收第一节点设备的邻居节点设备发送的所述远端网络链路的链路延迟,所述远端网络链路的链路延迟由所述远端网络链路的至少一端节点设备通过请求应答机制对所述远端网络链路进行检测得到的链路延迟所确定。Receive 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 responded by at least one end node device of the remote network link through a request The mechanism determines the link delay obtained by detecting the remote network link.
  9. 根据权利要求8所述的方法,还包括:The method of claim 8, further comprising:
    接收第一节点设备的邻居节点设备在请求应答机制中发送的应答消息,所述应答消息中包含所述对端链路延迟和/或所述远端网络链路的链路延迟。Receive a response message sent by a neighbor node device of the first node device in the request response mechanism, where the response message includes the peer link delay and/or the link delay of the remote network link.
  10. 根据权利要求8所述的方法,The method of claim 8,
    所述近端网络链路的链路延迟,包括:所述本端链路延迟、所述对端链路延迟、或者所述本端链路延迟与所述对端链路延迟的加权平均值;The link delay of the near-end network link includes: the local-end link delay, the peer-end link delay, or a weighted average of the local-end link delay and the peer-end link delay ;
    所述远端网络链路的链路延迟,包括:所述远端网络链路的任一端节点设备检测得到的链路延迟,或者所述远端网络链路两端的节点设备分别检测得到的链路延迟的加权平均值。The link delay of the remote network link includes: the link delay detected by any end node device of the remote network link, or the link delay detected by the node devices at both ends of the remote network link. The weighted average of the path delay.
  11. 根据权利要求6-10中任一项所述的方法,所述网络延迟信息包括:所述网络 拓扑结构中的网络链路的链路延迟,和/或所述网络拓扑结构中的节点设备在转发消息时的节点延迟。According to the method according to any one of claims 6-10, the network delay information includes: link delays of network links in the network topology, and/or node devices in the network topology Node latency when forwarding messages.
  12. 根据权利要求11所述的方法,还包括:The method of claim 11, further comprising:
    获取所述网络拓扑结构中的任一节点设备的至少一个邻居节点设备对该任一节点设备进行检测得到的节点延迟,并根据获取的节点延迟确定所述任一节点设备的节点延迟;和/或,Obtaining a node delay obtained by detecting any node device from at least one neighbor node device of any node device in the network topology, and determining the node delay of any node device according to the obtained node delay; and/ or,
    接收其他节点设备共享的所述任一节点设备的节点延迟。receiving the node delay of any node device shared by other node devices.
  13. 根据权利要求12所述的方法,所述任一节点设备的任一邻居节点设备对该任一节点设备进行检测,包括:According to the method according to claim 12, any neighbor node device of said any node device detects any node device, comprising:
    所述任一邻居节点设备向所述任一节点设备发送回流消息,通过所述回流消息的转发延迟、所述任一邻居节点设备与所述任一节点设备之间网络链路的链路延迟,确定所述任一节点设备的节点延迟,所述回流消息为所述任一邻居节点设备向所述任一节点设备发送的目的地址指向所述任一邻居节点设备的消息。The any neighbor node device sends a return message to the any node device, through the forwarding delay of the return message, the link delay of the network link between the any neighbor node device and the any node device , to determine the node delay of the any node device, the return message is a message sent by the any neighbor node device to the any node device with a destination address pointing to the any neighbor node device.
  14. 根据权利要求12所述的方法,所述任一节点设备的节点延迟,包括:The method according to claim 12, the node delay of any node device comprising:
    所述任一节点设备的任一邻居节点设备对该任一节点设备进行检测得到的节点延迟,或者所述任一节点设备的至少一个邻居节点设备对该任一节点设备进行检测得到的节点延迟的加权平均值。The node delay obtained by any neighbor node device of any node device detecting the any node device, or the node delay obtained by detecting any node device by at least one neighbor node device of the any node device weighted average of .
  15. 一种区块同步装置,应用于第一节点设备,第一节点设备上部署有区块链系统内分别属于多个区块链网络的多个区块链节点,第一节点设备针对其部署的区块链节点维护有对应的区块缓存空间,其中,第一节点设备部署的任一区块链节点对应的区块缓存空间的大小正相关于所述任一区块链节点的节点权重因子;所述装置包括:A block synchronization device, applied to a first node device, where multiple blockchain nodes in the blockchain system respectively belonging to multiple blockchain networks are deployed on the first node device, and the first node device is deployed for the The blockchain node maintains a corresponding block cache space, wherein the size of the block cache space corresponding to any blockchain node deployed by the first node device is positively related to the node weight factor of any blockchain node ; the device comprises:
    区块接收单元,用于接收所述任一区块链节点所属区块链网络中的正常节点发送至所述任一区块链节点的落后区块,其中,所述正常节点维护有实际最新区块,且所述落后区块的区块高度处于所述任一区块链节点本地维护的最新区块的本地区块高度与所述实际最新区块的最新区块高度之间;A block receiving unit, configured to receive a backward block sent to any of the blockchain nodes by a normal node in the blockchain network to which any of the blockchain nodes belongs, wherein the normal node maintains the 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 into the block cache space corresponding to any blockchain node, so that any blockchain node can read from the block cache space and process the lagging block;
    区块移除单元,用于在所述落后区块由所述任一区块链节点处理完毕的情况下,将所述落后区块移除所述区块缓存空间。A block removal unit, configured to remove the lagging block from the block cache space when the lagging block has been processed by any of the blockchain nodes.
  16. 一种电子设备,包括:An electronic device comprising:
    处理器;processor;
    用于存储处理器可执行指令的存储器;memory for storing processor-executable instructions;
    其中,所述处理器通过运行所述可执行指令以实现如权利要求1-14中任一项所述的方法。Wherein, the processor implements the method according to any one of claims 1-14 by running the executable instructions.
  17. 一种计算机可读存储介质,其上存储有计算机指令,该指令被处理器执行时实现如权利要求1-14中任一项所述方法的步骤。A computer-readable storage medium, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method according to any one of claims 1-14 are implemented.
PCT/CN2022/135825 2021-12-31 2022-12-01 Block synchronization WO2023124743A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111670006.6 2021-12-31
CN202111670006.6A CN114338724A (en) 2021-12-31 2021-12-31 Block synchronization method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
WO2023124743A1 true WO2023124743A1 (en) 2023-07-06

Family

ID=81021895

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/135825 WO2023124743A1 (en) 2021-12-31 2022-12-01 Block synchronization

Country Status (2)

Country Link
CN (1) CN114338724A (en)
WO (1) WO2023124743A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114338724A (en) * 2021-12-31 2022-04-12 支付宝(杭州)信息技术有限公司 Block synchronization method and device, electronic equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107302505A (en) * 2017-06-22 2017-10-27 迈普通信技术股份有限公司 Manage the method and device of caching
CN109274754A (en) * 2018-10-11 2019-01-25 上海保险交易所股份有限公司 For the method for synchrodata, equipment and storage medium in block chain network
CN110609872A (en) * 2019-09-20 2019-12-24 北京海益同展信息科技有限公司 Method and apparatus for synchronizing node data
US10860259B1 (en) * 2019-07-17 2020-12-08 Tyson York Winarski Multi-tiered storage system for blockchain
CN113067904A (en) * 2021-06-02 2021-07-02 支付宝(杭州)信息技术有限公司 Method for building block chain sub-network and block chain system
CN114338724A (en) * 2021-12-31 2022-04-12 支付宝(杭州)信息技术有限公司 Block synchronization method and device, electronic equipment and storage medium

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110569305B (en) * 2019-08-27 2021-09-03 网易(杭州)网络有限公司 Block synchronization method, device, medium and computing equipment
CN111259220B (en) * 2020-01-11 2021-03-02 杭州拾贝知识产权服务有限公司 Data acquisition method and system based on big data
CN111444203B (en) * 2020-03-24 2021-09-28 腾讯科技(深圳)有限公司 Synchronous processing method, device, equipment and medium
CN112968967B (en) * 2020-09-25 2023-05-19 支付宝(杭州)信息技术有限公司 Block synchronization method and device
CN112328693A (en) * 2020-11-16 2021-02-05 杭州复杂美科技有限公司 Block synchronization method, device and storage medium
CN112287031B (en) * 2020-12-15 2021-04-23 腾讯科技(深圳)有限公司 Data synchronization method and device of block chain system, readable medium and electronic equipment
CN113037852B (en) * 2021-03-22 2022-08-09 中国人民银行数字货币研究所 Block chain link point synchronization method and device
CN113259117B (en) * 2021-06-02 2021-09-24 支付宝(杭州)信息技术有限公司 Method for synchronizing node information lists
CN113259455B (en) * 2021-06-02 2021-09-24 支付宝(杭州)信息技术有限公司 Cross-subnet interaction method and device
CN114338714B (en) * 2021-12-31 2024-04-02 支付宝(杭州)信息技术有限公司 Block synchronization method and device, electronic equipment and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107302505A (en) * 2017-06-22 2017-10-27 迈普通信技术股份有限公司 Manage the method and device of caching
CN109274754A (en) * 2018-10-11 2019-01-25 上海保险交易所股份有限公司 For the method for synchrodata, equipment and storage medium in block chain network
US10860259B1 (en) * 2019-07-17 2020-12-08 Tyson York Winarski Multi-tiered storage system for blockchain
CN110609872A (en) * 2019-09-20 2019-12-24 北京海益同展信息科技有限公司 Method and apparatus for synchronizing node data
CN113067904A (en) * 2021-06-02 2021-07-02 支付宝(杭州)信息技术有限公司 Method for building block chain sub-network and block chain system
CN114338724A (en) * 2021-12-31 2022-04-12 支付宝(杭州)信息技术有限公司 Block synchronization method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN114338724A (en) 2022-04-12

Similar Documents

Publication Publication Date Title
WO2018112805A1 (en) Blockchain storage method and device, and node device
CN113259455B (en) Cross-subnet interaction method and device
WO2023124744A1 (en) Cross-subnet interaction
JP6551547B2 (en) Traffic-aware group reconfiguration in multi-group P2P networks
WO2018121201A1 (en) Distributed cluster service structure, node cooperation method and device, terminal and medium
JPH11338836A (en) Load distribution system for computer network
WO2010127618A1 (en) System and method for implementing streaming media content service
CN111338806B (en) Service control method and device
CN113067897B (en) Cross-chain interaction method and device
WO2023124743A1 (en) Block synchronization
CN114301828A (en) Cross-subnet interaction method and device, electronic equipment and storage medium
US20210328907A1 (en) Blockchain systems, and message transmission methods and apparatuses
WO2023050966A1 (en) Blockchain data verification
JP2010515133A (en) Method and system for publishing content, method and system for searching content
CN114338714B (en) Block synchronization method and device, electronic equipment and storage medium
CN113259457B (en) Information synchronization method and device for block chain sub-network
CN114422526B (en) Block synchronization method and device, electronic equipment and storage medium
CN111934997B (en) Message transmission method and device
CN114866560B (en) Block chain node migration method and device, electronic equipment and readable storage medium
CN114422520B (en) Cross-chain interaction method and device
CN113259462B (en) Block chain message distribution method and device
CN113259119B (en) Block chain message distribution method and device
CN114338676A (en) Block synchronization method and device, electronic equipment and storage medium
CN114338723A (en) Block synchronization method and device, electronic equipment and storage medium
EP3188531B1 (en) Cluster system self-organizing method, device, and cluster system

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22913998

Country of ref document: EP

Kind code of ref document: A1