A method and device for synchronizing a Merkle directed acyclic graph
By creating a synchronous set of identification information and recursively obtaining child node identification information, the problem of the synchronization dependency order of Merkel directed acyclic graph nodes is solved, and the efficiency of parallel synchronization is improved and the number of requests is reduced.
Patent Information
- Application Number
- CN202210632582.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-27
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2042-05-27
AI Technical Summary
In the prior art, the synchronization of Merkle DAG nodes depends on the order of nodes, resulting in limited synchronization speed. During parallel synchronization, you need to wait for the missing nodes to be synchronized, resulting in waste of requests.
By creating an identification information synchronization set, a protocol for Merkel directed acyclic graph node identification information including root node identification information is sent to the second service node, node data packets are obtained and storage is deserialized, child node identification information is recursively obtained, sub-node identification information is filtered and obtained, synchronization set is updated, and the new node identification information protocol is synchronized to the second service node.
When synchronizing Merkle DAG nodes in parallel, subsequent node requests no longer depend on the synchronization completion order of the current Merkle DAG node, reducing the number of requests of nodes and improving synchronization efficiency.
Smart Images

Figure CN115080564B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a method and device for synchronizing a Merkle directed acyclic graph. Background Art
[0002] A Merkle DAG is a directed acyclic graph in which each node has an identifier, which is the result of hashing the node content using a cryptographic hash function such as SHA256. It consists of two types of nodes: leaf nodes and link nodes. Leaf nodes are used to store data, and link nodes are used to store identifiers of all child nodes. A Merkle DAG is similar to a Merkle tree. In a DAG, multiple branches can converge again, that is, a node can have multiple parent nodes.
[0003] Currently, the synchronization problem of synchronizing Merkle DAG data from another node is solved by starting from the Merkle DAG root CID to deeply traverse or traverse the entire Merkle DAG in breadth. If the local node cannot find the DAG node, it will synchronize the DAG node from another node. The protocol used is: send a request containing the DAG node CID to the other party, and then return the DAG node data of the CID. Regardless of whether the entire Merkle DAG is traversed by deep traversal or breadth traversal, it will depend on the order of the DAG nodes. However, in order to increase the synchronization speed, the method of synchronizing DAG nodes in parallel will be adopted. At this time, the order of the returned DAG node data cannot be determined, so it is often necessary to wait for the missing DAG nodes in the middle to be synchronized before continuing to traverse. Moreover, a DAG node CID request must be sent for each request, resulting in a waste of requests. Summary of the invention
[0004] One purpose of the present application is to provide a method and device for synchronizing a Merkel directed acyclic graph, so as to solve the problems in the prior art of relying on the synchronization completion order of the current Merkel directed acyclic graph nodes, needing to wait for the synchronization of the intermediate missing nodes before continuing, and the large number of requests for node data.
[0005] According to one aspect of the present application, a method for synchronizing a Merkle directed acyclic graph is provided, which is applied to a first service node, and the method includes:
[0006] A protocol for creating an identification information synchronization set and sending node identification information of a Merkle directed acyclic graph including root node identification information to a second service node that has established a connection relationship with the first service node;
[0007] Obtaining a node data packet fed back by the second service node after parsing the received node identification information based on a protocol, deserializing the node data packet and storing it in a local node data storage repository;
[0008] Recursively obtain all available sub-node identification information of the sub-Merkle directed acyclic graph, and filter the obtained sub-node identification information based on the existing identification information in the local node data repository;
[0009] The identification information of the remaining nodes to be synchronized after filtering is subtracted from the identification information synchronization set, the obtained difference is stored in the identification information synchronization set, and the protocol of the node identification information of the new Merkel directed acyclic graph is synchronized to the second service node, wherein the protocol of the node identification information of the new Merkel directed acyclic graph includes the root node identification information and the difference.
[0010] Optionally, after synchronizing the protocol of the node identification information of the new Merkel directed acyclic graph to the second service node, the method includes:
[0011] The identification information of the node in the protocol of the new Merkel directed acyclic graph node identification information is removed from the identification information synchronization set.
[0012] Optionally, before the protocol of sending the node identification information of the Merkle directed acyclic graph including the root node identification information to the second service node that has established a connection relationship with the first service node, the method includes:
[0013] The root node identification information of the Merkel directed acyclic graph is stored in the identification information synchronization set, and the root node identification information and the node identification information array of the Merkel directed acyclic graph are packaged into a protocol for the node identification information of the Merkel directed acyclic graph.
[0014] Optionally, after deserializing the node data packet and storing it in the local node data repository, the method further comprises:
[0015] The node data packet is parsed, and the sub-node identification information array obtained by the parsing is placed into a temporary identification information array.
[0016] Optionally, recursively obtaining all obtainable sub-node identification information of the sub-Merkle directed acyclic graph, and filtering the obtained sub-node identification information based on the existing identification information in the local node data repository, including:
[0017] Determine whether the temporary identification information array is empty, and if not, recursively obtain all obtainable sub-node identification information of the sub-Merkle directed acyclic graph from the temporary identification information array in sequence;
[0018] Based on the existing identification information in the local node data storage repository, it is determined whether each child node identification information exists. If not, it is put into the temporary synchronization identification information set. If so, the node data obtained by the analysis is re-acquired.
[0019] Optionally, obtaining a difference between the identification information of the remaining nodes to be synchronized after filtering and the identification information synchronization set, and storing the obtained difference in the identification information synchronization set, includes:
[0020] If the temporary identification information array is empty, determine whether the temporary synchronization identification information set is empty; if not, find the difference between the temporary synchronization identification information set and the identification information synchronization set and put the elements in the identification information difference set into the identification information synchronization set;
[0021] If so, remove the previously received identification information from the identification information synchronization set, and determine whether the identification information synchronization set is empty. If not, continue to receive the node data packet returned by the second service node. If so, complete the synchronization.
[0022] Optionally, the method comprises:
[0023] If the data error processing protocol fed back by the second service node is received, error information processing is performed according to the received data error processing protocol.
[0024] According to another aspect of the present application, a method for synchronizing a Merkel directed acyclic graph is provided, which is applied to a second service node, and the method includes:
[0025] A protocol for receiving node identification information of a Merkle directed acyclic graph including root node identification information sent by a first service node that has established a connection relationship with a second service node;
[0026] Parsing the protocol of the node identification information, and acquiring the node data of the Merkel directed acyclic graph according to the parsing result;
[0027] Packing the acquired node data to obtain a node data packet, and sending the node data packet to the first service node to obtain a difference set of the Merkel directed acyclic graph node identification information;
[0028] A protocol for receiving node identification information of a new Merkle directed acyclic graph synchronized by the first service node based on the node data packet, wherein the protocol for the node identification information of the new Merkle directed acyclic graph includes the root node identification information and the difference set.
[0029] Optionally, obtaining node data of the Merkle directed acyclic graph according to the parsing result includes:
[0030] The parsed node identification information is put into a queue, and after taking out an element from the head of the queue, the node data of the Merkel directed acyclic graph is obtained according to the node identification information.
[0031] Optionally, the node data packet includes root node identification information of the Merkel directed acyclic graph and node serialization data of the Merkel directed acyclic graph, and sending the node data packet to the first service node includes:
[0032] The root node identification information of the Merkel directed acyclic graph and the node serialization data of the Merkel directed acyclic graph are sent to the first service node according to the node data protocol, wherein the node data protocol is a unidirectional transmission protocol.
[0033] Optionally, the method comprises:
[0034] If the acquisition of the node data of the Merkel directed acyclic graph fails, a data error handling protocol is sent to the service configuration where the first service node is located, wherein the data error handling protocol includes the root node identification information, node identification information and error information of the Merkel directed acyclic graph.
[0035] According to another aspect of the present application, a first service node device for Merkel directed acyclic graph synchronization is also provided, and the first service node device includes:
[0036] one or more processors; and
[0037] A memory storing computer readable instructions, which, when executed, cause the processor to perform the operations of the method as described above.
[0038] According to another aspect of the present application, a second service node device for Merkel directed acyclic graph synchronization is also provided, and the second service node device includes:
[0039] one or more processors; and
[0040] A memory storing computer readable instructions, which, when executed, cause the processor to perform the operations of the method as described above.
[0041] According to another aspect of the present application, a computer-readable medium is provided, on which computer-readable instructions are stored. The computer-readable instructions can be executed by a processor to implement the method described above.
[0042] Compared with the prior art, the present application creates an identification information synchronization set, sends a protocol of node identification information of a Merkle directed acyclic graph including root node identification information to a second service node that establishes a connection relationship with the first service node; obtains a node data packet fed back by the second service node after parsing the protocol of the received node identification information, deserializes the node data packet and stores it in a local node data repository; recursively obtains all obtainable subnode identification information of the sub-Merkle directed acyclic graph, and filters the obtained subnode identification information based on the identification information already existing in the local node data repository; obtains a difference set between the identification information of the remaining nodes to be synchronized after filtering and the identification information synchronization set, stores the obtained difference set in the identification information synchronization set, and synchronizes the protocol of the node identification information of the new Merkle directed acyclic graph to the second service node, wherein the protocol of the node identification information of the new Merkle directed acyclic graph includes the root node identification information and the difference set. Thus, when synchronizing MerkleDAG nodes in parallel, the request of subsequent nodes no longer depends on the synchronization completion order of the current Merkle DAG nodes, and also reduces the number of node requests. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0044] Figure 1 A schematic flow chart of a method for synchronizing a Merkle directed acyclic graph provided according to one aspect of the present application is shown;
[0045] Figure 2 A schematic flow chart of a method for synchronizing a Merkle directed acyclic graph provided according to another aspect of the present application is shown;
[0046] Figure 3 A schematic diagram showing a process of synchronizing DAG data from a service node M to a service node N in an embodiment of the present application is shown;
[0047] Figure 4 A schematic diagram showing a first state change when a service node M synchronizes DAG data to a service node N in an example of the present application is shown;
[0048] Figure 5 A schematic diagram showing a second state change when a service node M synchronizes DAG data to a service node N in an example of the present application is shown;
[0049] Figure 6 A schematic diagram showing a third state change when a service node M synchronizes DAG data to a service node N in an example of the present application is shown;
[0050] Figure 7A schematic diagram showing a fourth state change when a service node M synchronizes DAG data to a service node N in an example of the present application is shown;
[0051] Figure 8 A schematic diagram of a fifth state change when a service node M synchronizes DAG data to a service node N in an example of the present application is shown.
[0052] The same or similar reference numerals in the drawings represent the same or similar components. DETAILED DESCRIPTION
[0053] The present application is described in further detail below in conjunction with the accompanying drawings.
[0054] In a typical configuration of the present application, the terminal, the device of the service network and the trusted party all include one or more processors (eg, a central processing unit (CPU)), an input / output interface, a network interface and a memory.
[0055] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0056] Computer readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, Phase-Change RAM (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 Disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include non-transitory media such as modulated data signals and carrier waves.
[0057] Figure 1 A schematic flow chart of a method for synchronizing a Merkel directed acyclic graph provided according to one aspect of the present application is shown, which is applied to a first service node. The method comprises: steps S11 to S14,
[0058] Step S11, create an identification information synchronization set, and send a protocol of node identification information of a Merkle directed acyclic graph including root node identification information to a second service node that has established a connection relationship with the first service node; here, the identification information is an identifier for each node, and can be obtained by hashing the node content using an encrypted hash function such as SHA256, and the node identifier is named CID (Content Identifier); create a CID synchronization set on the first service node to store CID tasks of Merkle directed acyclic graph (Merkle DAG) nodes to be synchronized, and each task contains a Merkle DAG node CID and a task creation timestamp. A connection between the first service node and the second service node is established through communication between the service configuration where the first service node is located and the service configuration where the second service node is located, so that the Merkle DAG node data that needs to be synchronized in the CID synchronization set created by the first service node can be synchronized to the second service node. After the CID synchronization set is created, the root node CID of the Merkle DAG that needs to be synchronized is sent to the second service node. The sending is carried out according to the protocol of the node identification information of the Merkle directed acyclic graph. The node CID protocol is a one-way transmission, that is, when sending the relevant data of the Merkle DAG to the other party, there is no need to wait for the returned data for processing.
[0059] Step S12, obtain the node data packet fed back by the second service node after parsing the protocol based on the received node identification information, deserialize the node data packet and store it in the local node data repository; here, after the protocol of the node identification information of the Merkel directed acyclic graph including the root node identification information is sent to the second service node, the second service node will parse the protocol of the node identification information to obtain the node data packet, and feed the node data packet back to the first service node, and the first service node will deserialize the received node data packet and store it in the local node data repository for caching.
[0060] Step S13, recursively obtain all available child node identification information of the sub-Merkle directed acyclic graph, and filter the obtained child node identification information based on the identification information already existing in the local node data repository; here, the node identification information that needs to be synchronized is filtered using the locally cached node data, and the filtering method is to recursively traverse all available child node identification information under the root node identification information after the root node identification information, and then compare it with the identification information already existing in the node data repository in the local cache, and filter out the node identification information that needs to be synchronized.
[0061] Step S14, the identification information of the remaining nodes to be synchronized after filtering is calculated as a difference set with the identification information synchronization set, the obtained difference set is stored in the identification information synchronization set, and the protocol of the node identification information of the new Merkel directed acyclic graph is synchronized to the second service node, wherein the protocol of the node identification information of the new Merkel directed acyclic graph includes the root node identification information and the difference set. Here, after filtering all the obtainable child node identification information obtained by traversal, the identification information of the remaining nodes to be synchronized is calculated as a difference set with the CID synchronization set, so that the elements in the obtained difference set are stored in the CID synchronization set, that is, the node identification information that needs to be synchronized but has not yet been synchronized is stored in the CID synchronization set for subsequent synchronization. When synchronizing, the obtained difference set and the original root node identification information are sent to the second service node using the CID protocol of the new Merkel directed acyclic graph, and the second service node obtains the DAG node data synchronized from the first service node. Therefore, when synchronizing Merkle DAG nodes in parallel, the requests of subsequent nodes no longer depend on the synchronization completion order of the current Merkle DAG nodes, and the number of node requests is also reduced.
[0062] In some embodiments of the present application, the identification information of the node in the protocol of the new Merkel directed acyclic graph node identification information is removed from the identification information synchronization set. Here, after the DAG node corresponding to the currently synchronized Merkel directed acyclic graph node identification information has been synchronized, the currently synchronized Merkel directed acyclic graph node identification information needs to be removed from the CID synchronization set, that is, after the protocol of the new Merkel directed acyclic graph node identification information is sent to the second service node, the CID carried in the protocol is removed from the CID synchronization set.
[0063] In some embodiments of the present application, the root node identification information of the Merkel directed acyclic graph is stored in the identification information synchronization set, and the root node identification information and the node identification information array of the Merkel directed acyclic graph are packaged into a protocol for the node identification information of the Merkel directed acyclic graph. Here, the synchronization protocol used in the prior art is to send a request including a DAG node CID to the other party, and then return the DAG node data of the CID; whereas in the embodiment of the present application, a Merkle DAG node CID protocol is used, which is a one-way transmission. The root node CID of the Merkle DAG is first stored in the created CID synchronization set, and then an array is formed according to the CIDs of all other nodes of the Merkle DAG, the array including the unique identifier CID of each DAG node to be synchronized, the root CID is packaged, and a data packet including the root CID and the CID array is obtained. The data packet is sent to the second service node using the Merkle DAG node CID protocol, that is, the Merkle DAG root CID and the Merkle DAG node CID array to be synchronized are sent to the second service node without waiting for the returned data to be processed.
[0064] In some embodiments of the present application, the node data packet is parsed, and the sub-node identification information array obtained by parsing is placed in a temporary identification information array. Then, it is determined whether the temporary identification information array is empty. If not, all available sub-node identification information of the sub-Merkle directed acyclic graph is recursively obtained from the temporary identification information array in sequence; based on the identification information already existing in the local node data repository, it is determined whether each sub-node identification information exists. If not, it is placed in a temporary synchronization identification information set. If so, the node data obtained by parsing is re-acquired.
[0065] Here, after the first service node receives the node data packet returned by the second service node, it parses the node data packet, that is, parses the DAG node data. When parsing, the node data is stored in the local node data storage library, and the sub-node identification information array of the node is obtained and stored in the temporary CID array of the DAG node. In this way, it is determined whether the temporary CID array is empty. If not, a CID is taken out from the temporary CID array to determine whether the DAG node data exists. If not, the taken CID is placed in the temporary synchronization CID set. If yes, the sub-node identification information CID array of the DAG node is parsed and stored in the temporary CID array. The above steps are repeated until the temporary CID array is empty.
[0066] Continuing with the above embodiment, if the temporary identification information array is empty, then determine whether the temporary synchronization identification information set is empty, if not, calculate the difference between the temporary synchronization identification information set and the identification information synchronization set and put the elements in the identification information difference set into the identification information synchronization set; if so, remove the previously received identification information from the identification information synchronization set, determine whether the identification information synchronization set is empty, if not, continue to receive the node data packet returned by the second service node, if so, complete the synchronization. Here, if the temporary CID array is empty, determine whether the temporary synchronization CID set is empty, if not, calculate the difference between the temporary synchronization CID set and the previous CID synchronization set, send the CID difference set to the second service node using the above-mentioned Merkle DAG node CID protocol, put the CID difference set elements into the CID synchronization set, and remove the previously received CID from the CID synchronization set. If the temporary synchronization CID set is empty, remove the previously received CID from the CID synchronization set, and determine whether the CID synchronization set is empty. If not, continue to receive node data. If so, it means that all node data that need to be synchronized have been synchronized.
[0067] In some embodiments of the present application, the method includes: if a data error handling protocol fed back by the second service node is received, error information processing is performed according to the received data error handling protocol. Here, if the first service node receives the data error handling protocol, it is processed according to the received error information, such as recording the error information in a log or retransmitting the protocol, and the data synchronization process ends early. In an embodiment of the present application, the data error handling protocol is a two-way transmission. After sending information to the other party, it is necessary to wait for the returned data for processing. The information sent includes the Merkle DAG root node, the CID of the DAG node with synchronization error, and the error information.
[0068] Figure 2 A schematic flow chart of a method for synchronizing a Merkel directed acyclic graph provided according to another aspect of the present application is shown, which is applied to a second service node. The method includes: steps S21 to S24,
[0069] Step S21, receiving a protocol of node identification information of a Merkle directed acyclic graph including root node identification information sent by a first service node that has established a connection relationship with a second service node; here, after the second service node establishes a connection with the first service node, the protocol of node identification information of a Merkle directed acyclic graph sent by the first service node is received, and the protocol carries a data packet of a Merkle DAG root node CID and a CID array.
[0070] Step S22, parse the protocol of the node identification information, and obtain the node data of the Merkle directed acyclic graph according to the parsing result; here, parse the received data packet to parse out the node data of the Merkle DAG, the node data includes a CID array, put the CID array into a queue, thereby entering the loop body for concurrent processing.
[0071] Step S23, the acquired node data is packaged to obtain a node data packet, and the node data packet is sent to the first service node to obtain a difference set of Merkle directed acyclic graph node identification information; here, when concurrent processing is performed, the node data obtained by parsing is packaged, so that the packaged node data packet is fed back to the first service node, and the first service node obtains a difference set of Merkle DAG node CIDs that need to be synchronized based on the node data packet.
[0072] Step S24, receiving a protocol of node identification information of a new Merkel directed acyclic graph synchronized by the first service node based on the node data packet, wherein the protocol of node identification information of the new Merkel directed acyclic graph includes the root node identification information and the difference set. Here, a CID protocol synchronized by the first service node is received, and the protocol carries the obtained difference set information and the root CID information, thereby completing the synchronization of node data.
[0073] In some embodiments of the present application, in step S22, the parsed node identification information is placed in a queue, and after taking out an element from the head of the queue, the node data of the Merkle directed acyclic graph is obtained according to the node identification information. Here, an element is taken out from the head of the data queue, and the DAG node data is obtained according to the CID, and then the obtained DAG node is packaged into a data packet including the root CID and the DAG node data, and sent to the first service node. The specific process is: the second service node receives and parses the CID array from the Merkle DAG node CID protocol, and assembles the service configuration of the first service node and the CID into a structure and puts it into the sending data queue; the sending data queue asynchronously performs the following steps: continuously obtain tasks from the sending data queue, and the task is to set the appropriate number of concurrent tasks according to the machine configuration, such as setting the number of concurrent tasks to 2 times the number of CPU cores; obtain Merkle DAG node data according to CID, and then send Merkle DAG node data protocol data to the first service node.
[0074] Continuing with the above embodiment, the node data packet includes the root node identification information of the Merkel directed acyclic graph and the node serialization data of the Merkel directed acyclic graph. In step S23, the root node identification information of the Merkel directed acyclic graph and the node serialization data of the Merkel directed acyclic graph are sent to the first service node according to the node data protocol, wherein the node data protocol is a unidirectional transmission protocol. Here, when the second service node feeds back the node data, the Merkle DAG node data protocol is adopted, which is a unidirectional transmission, and the Merkle DAG root CID and the Merkle DAG node serialization data are sent to the other party without waiting for the return data for processing. It should be noted that the DAG node is mainly composed of a payload field and a subnode CID array, and serializing the Merkle DAG node is convenient for storage and transmission.
[0075] In some embodiments of the present application, the method includes: if the acquisition of the node data of the Merkle directed acyclic graph fails, a data error handling protocol is sent to the service configuration where the first service node is located, wherein the data error handling protocol includes the root node identification information, node identification information and error information of the Merkle directed acyclic graph. Here, if the acquisition of the Merkle DAG node data fails, data error handling protocol data is sent to the first service node, and the data error handling protocol data includes the Merkle DAG root CID, the DAG CID with synchronization error and error information.
[0076] In a specific embodiment of the present application, the synchronization of DAG data from service node M to service node N is used as an example for explanation:
[0077] Step 1: Service node M establishes a connection with service node N;
[0078] Step 2: Create a CID synchronization set and scan the CID synchronization set regularly. If a CID synchronization task times out, the data synchronization process ends early.
[0079] Step 3: Service node M sends the Merkle DAG node CID protocol data including the Merkle DAG root CID, and puts the root CID into the CID synchronization set;
[0080] Step 4: Service node N receives and parses the CID array from the Merkle DAG node CID protocol, and assembles the connection object and CID into a structure and puts it into the send data queue. The send data queue executes asynchronously: it continuously obtains tasks from the send data queue, obtains the Merkle DAG node data according to the CID, and then sends the Merkle DAG node data protocol data to the connection object; if the acquisition of the Merkle DAG node data fails, it sends the data error handling protocol data to the connection object, and the data error handling protocol data contains the Merkle DAG root CID, DAGCID and error information;
[0081] Step 5: Service node M obtains Merkle DAG node data from the Merkle DAG node data protocol, stores it in the local node data repository, and recursively obtains all available sub-DAG node CIDs of the sub-Merkle DAG, filters out the node CIDs that already exist in the local node data repository, calculates the difference between the CID set of the remaining nodes to be synchronized and the CID synchronization set, puts the difference into the CID synchronization set, and sends the Merkle DAG node CID protocol to service node N. At this time, the node CID protocol contains the Merkle DAG root CID and the CID difference set obtained previously, and removes the CID of the DAG node in this data packet from the CID synchronization set.
[0082] Step 6: At the same time, if the service node M receives the data error processing protocol, it processes according to the error information, and the data synchronization process ends in advance;
[0083] Step 7: Repeat steps 4-6 until there is no data to be synchronized in the CID synchronization set of the service node M, and the data synchronization is completed.
[0084] Specifically, Figure 3 As shown, steps S11 to S14, steps S21 to S24 in the above embodiments and steps in each embodiment are executed in the service node M and the service node N. After the CID synchronization set is created in the service node M, the packaged data packet is sent to the service node N, so that the data is processed concurrently on the service node N. After the data is fed back to the service node M, the data is processed concurrently in the service node M, so that the service node M synchronizes the DAG data from the service node N. Therefore, when synchronizing the DAG nodes in parallel, the requests of the subsequent nodes do not depend on the synchronization completion order of the current Merkle DAG node, and the number of requests is reduced.
[0085] The following example describes the internal state changes of the Merkle DAGA synchronized by the service node M from the service node N. It should be noted that this data packet sequence is only one of the possibilities.
[0086] Among them, service nodes M and N represent two server process instances; data packets are data packets for network communication between service nodes M and N; CID synchronization set is the child node CID to be synchronized; Merkle DAG A is the entire MerkleDAG to be synchronized, in which nodes AF are all nodes in MerkleDAGA, dotted lines indicate unsynchronized, and solid lines indicate synchronized.
[0087] Specifically, Figure 4 As shown, service node M initiates a MerkleDAGA synchronization task to service node N, first synchronizing the root node CIDA, sending the Merkle DAG node CID protocol data (root CIDA and CID arrays are CIDA), and putting CIDA into the CID synchronization set.
[0088] like Figure 5 As shown, service node M receives the data packet sent by service node N, obtains the data of DAG node A after parsing, and obtains the child nodes (CIDB and CIDC) in node A. If these two child nodes cannot be found in the local node data storage repository, the Merkle DAG node CID protocol data is sent. At this time, the root CIDA and CID arrays contain CIDB and CIDC, and CIDB and CIDC are placed in the CID synchronization set, and CIDA is deleted.
[0089] like Figure 6 As shown, service node M receives the data packet sent by service node N, obtains the data of DAG node C after parsing, and obtains the child nodes (CIDF and CID E) in node C. If these two child nodes cannot be found in the local node data storage library, the Merkle DAG node CID protocol data is sent. At this time, the root CIDA and CID arrays contain CID F and CID E, and CID F and CID E are put into the CID synchronization set, and CID C is deleted.
[0090] like Figure 7 As shown, service node M receives the data packet sent by service node N, parses it to obtain the data of DAG node B, and obtains the child nodes (CID D and CIDE) in node B. If these two child nodes cannot be found in the local node data repository, but CIDE is already in the synchronization set and no synchronization is required, the Merkle DAG node CID protocol data (root CIDA and CIDD in the CID array) is sent, CID D is placed in the CID synchronization set, and CID B is deleted.
[0091] like Figure 8As shown, service node M receives the data packet sent by service node N, obtains the data of DAG nodes F, E, and D after parsing, obtains the child nodes in the node (at this time, nodes F, E, and D have no child nodes), deletes CIDF, E, and D from the CID synchronization set, and the CID synchronization set is empty, and the synchronization ends.
[0092] According to another aspect of the present application, a first service node device for Merkel directed acyclic graph synchronization is also provided, and the first service node device includes:
[0093] one or more processors; and
[0094] A memory storing computer readable instructions, which, when executed, cause the processor to perform the operations of the method as described above.
[0095] For example, the computer readable instructions, when executed, cause the one or more processors to:
[0096] A protocol for creating an identification information synchronization set and sending node identification information of a Merkle directed acyclic graph including root node identification information to a second service node that has established a connection relationship with the first service node;
[0097] Obtaining a node data packet fed back by the second service node after parsing the received node identification information based on a protocol, deserializing the node data packet and storing it in a local node data storage repository;
[0098] Recursively obtain all available sub-node identification information of the sub-Merkle directed acyclic graph, and filter the obtained sub-node identification information based on the existing identification information in the local node data repository;
[0099] The identification information of the remaining nodes to be synchronized after filtering is subtracted from the identification information synchronization set, the obtained difference is stored in the identification information synchronization set, and the protocol of the node identification information of the new Merkel directed acyclic graph is synchronized to the second service node, wherein the protocol of the node identification information of the new Merkel directed acyclic graph includes the root node identification information and the difference.
[0100] According to another aspect of the present application, a second service node device for Merkel directed acyclic graph synchronization is also provided, and the second service node device includes:
[0101] one or more processors; and
[0102] A memory storing computer readable instructions, which, when executed, cause the processor to perform the operations of the method as described above.
[0103] For example, the computer readable instructions, when executed, cause the one or more processors to:
[0104] A protocol for receiving node identification information of a Merkle directed acyclic graph including root node identification information sent by a first service node that has established a connection relationship with a second service node;
[0105] Parsing the protocol of the node identification information, and acquiring the node data of the Merkel directed acyclic graph according to the parsing result;
[0106] Packing the acquired node data to obtain a node data packet, and sending the node data packet to the first service node to obtain a difference set of the Merkel directed acyclic graph node identification information;
[0107] A protocol for receiving node identification information of a new Merkle directed acyclic graph synchronized by the first service node based on the node data packet, wherein the protocol for the node identification information of the new Merkle directed acyclic graph includes the root node identification information and the difference set.
[0108] In addition, an embodiment of the present application also provides a computer-readable medium on which computer-readable instructions are stored. The computer-readable instructions can be executed by a processor to implement the aforementioned method for synchronizing a Merkle directed acyclic graph.
[0109] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
[0110] It should be noted that the present application can be implemented in software and / or a combination of software and hardware, for example, can be implemented using an application specific integrated circuit (ASIC), a general purpose computer or any other similar hardware device. In one embodiment, the software program of the present application can be executed by a processor to implement the steps or functions described above. Similarly, the software program of the present application (including relevant data structures) can be stored in a computer-readable recording medium, for example, a RAM memory, a magnetic or optical drive or a floppy disk and similar devices. In addition, some steps or functions of the present application can be implemented using hardware, for example, as a circuit that cooperates with a processor to perform each step or function.
[0111] In addition, a part of the present application may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present application through the operation of the computer. The program instruction for calling the method of the present application may be stored in a fixed or removable recording medium, and / or transmitted through a data stream in a broadcast or other signal-bearing medium, and / or stored in a working memory of a computer device that runs according to the program instruction. Here, according to an embodiment of the present application, a device is included, the device including a memory for storing computer program instructions and a processor for executing program instructions, wherein, when the computer program instruction is executed by the processor, the device is triggered to run the method and / or technical solution based on the aforementioned multiple embodiments according to the present application.
[0112] It is obvious to those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and that the present application can be implemented in other specific forms without departing from the spirit or basic features of the present application. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present application is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present application. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
Claims
1. A method for synchronizing a Merkle directed acyclic graph, applied to a first service node, characterized in that: The method comprises: A protocol for creating an identification information synchronization set and sending node identification information of a Merkle directed acyclic graph including root node identification information to a second service node that has established a connection relationship with the first service node; Obtaining a node data packet fed back by the second service node after parsing the received node identification information based on a protocol, deserializing the node data packet and storing it in a local node data storage repository; Recursively obtain all available sub-node identification information of the sub-Merkle directed acyclic graph, and filter the obtained sub-node identification information based on the existing identification information in the local node data repository; The identification information of the remaining nodes to be synchronized after filtering is subtracted from the identification information synchronization set, the obtained difference is stored in the identification information synchronization set, and the protocol of the node identification information of the new Merkel directed acyclic graph is synchronized to the second service node, wherein the protocol of the node identification information of the new Merkel directed acyclic graph includes the root node identification information and the difference.
2. The method according to claim 1, characterized in that After synchronizing the protocol of the node identification information of the new Merkle directed acyclic graph to the second service node, it includes: The identification information of the node in the protocol of the new Merkel directed acyclic graph node identification information is removed from the identification information synchronization set.
3. The method according to claim 1, characterized in that Before sending the node identification information of the Merkle directed acyclic graph including the root node identification information to the second service node that has established a connection relationship with the first service node, the protocol includes: The root node identification information of the Merkel directed acyclic graph is stored in the identification information synchronization set, and the root node identification information and the node identification information array of the Merkel directed acyclic graph are packaged into a protocol for the node identification information of the Merkel directed acyclic graph.
4. The method according to claim 1, characterized in that: After deserializing the node data and storing it in the local node data repository, the following steps are included: The node data packet is parsed, and the sub-node identification information array obtained by the parsing is placed into a temporary identification information array.
5. The method according to claim 4, characterized in that Recursively obtain all available sub-node identification information of the sub-Merkle directed acyclic graph, and filter the obtained sub-node identification information based on the existing identification information in the local node data repository, including: Determine whether the temporary identification information array is empty, and if not, recursively obtain all obtainable sub-node identification information of the sub-Merkle directed acyclic graph from the temporary identification information array in sequence; Based on the existing identification information in the local node data storage library, it is determined whether each child node identification information exists. If not, it is put into the temporary synchronization identification information set. If so, the node data obtained by the analysis is re-acquired.
6. The method according to claim 5, characterized in that The identification information of the remaining nodes to be synchronized after filtering is used to obtain a difference set from the identification information synchronization set, and the obtained difference set is stored in the identification information synchronization set, including: If the temporary identification information array is empty, determine whether the temporary synchronization identification information set is empty; if not, find the difference between the temporary synchronization identification information set and the identification information synchronization set and put the elements in the identification information difference set into the identification information synchronization set; If so, remove the previously received identification information from the identification information synchronization set, and determine whether the identification information synchronization set is empty. If not, continue to receive the node data packet returned by the second service node. If so, complete the synchronization.
7. The method according to claim 1, characterized in that The method comprises: If the data error processing protocol fed back by the second service node is received, error information processing is performed according to the received data error processing protocol.
8. A method for synchronizing a Merkle directed acyclic graph, applied to a second service node, characterized in that: The method comprises: A protocol for receiving node identification information of a Merkle directed acyclic graph including root node identification information sent by a first service node that has established a connection relationship with a second service node; Parsing the protocol of the node identification information, and acquiring the node data of the Merkel directed acyclic graph according to the parsing result; The acquired node data is packaged to obtain a node data packet, and the node data packet is sent to the first service node, so that the node data packet is deserialized at the first service node and stored in a local node data repository, and all obtainable sub-node identification information of the sub-Merkle directed acyclic graph is recursively obtained, and the acquired sub-node identification information is filtered based on the identification information already existing in the local node data repository, and the identification information of the remaining nodes to be synchronized after filtering is subtracted from the identification information synchronization set to obtain the difference set of the Merkel directed acyclic graph node identification information; A protocol for receiving node identification information of a new Merkle directed acyclic graph synchronized by the first service node based on the node data packet, wherein the protocol for the node identification information of the new Merkle directed acyclic graph includes the root node identification information and the difference set.
9. The method according to claim 8, characterized in that The node data of the Merkle directed acyclic graph is obtained according to the parsing result, including: The parsed node identification information is put into a queue, and after taking out an element from the head of the queue, the node data of the Merkel directed acyclic graph is obtained according to the node identification information.
10. The method according to claim 9, characterized in that in, The node data packet includes the root node identification information of the Merkel directed acyclic graph and the node serialization data of the Merkel directed acyclic graph, and sending the node data packet to the first service node includes: The root node identification information of the Merkel directed acyclic graph and the node serialization data of the Merkel directed acyclic graph are sent to the first service node according to the node data protocol, wherein the node data protocol is a unidirectional transmission protocol.
11. The method according to claim 8, characterized in that The method comprises: If the acquisition of the node data of the Merkel directed acyclic graph fails, a data error handling protocol is sent to the service configuration where the first service node is located, wherein the data error handling protocol includes the root node identification information, node identification information and error information of the Merkel directed acyclic graph.
12. A first service node device for Merkle directed acyclic graph synchronization, characterized in that: The first service node device comprises: one or more processors; and A memory storing computer readable instructions which, when executed, cause the processor to perform the operations of the method as claimed in any one of claims 1 to 7.
13. A second service node device for Merkle directed acyclic graph synchronization, characterized in that: The second service node device includes: one or more processors; and A memory storing computer readable instructions which, when executed, cause the processor to perform the operations of the method as claimed in any one of claims 8 to 11.
14. A computer-readable medium having computer-readable instructions stored thereon, wherein the computer-readable instructions can be executed by a processor to implement the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Block chain-based data consistency comparison method and device, and medium
CN110990378A
Resource allocation method and device based on blockchain network technology and electronic equipment
CN112016954A