Disclosure of Invention
In view of this, the invention provides a block chain data distribution method based on type attribute information, which can effectively reduce consensus time and effectively improve data distribution efficiency during data distribution.
The invention provides a block chain data distribution method based on type attribute information, which comprises the following steps:
each node on the block chain generates a dynamic routing table based on the type attribute information of the node;
and each node on the block chain transmits data based on the dynamic routing table corresponding to the node.
Preferably, each node on the block chain generates a dynamic routing table based on the type attribute information of the node, respectively, including:
the nodes on the block chain respectively send messages containing the type attribute information of the nodes;
a node on a block chain receives messages containing type attribute information of the node sent by other nodes on the block chain;
analyzing the received message containing the type attribute information of the node to obtain message analysis data;
judging the message analysis data, judging whether to add the message analysis data into a routing table of the node according to preset conditions, if so, then:
judging the type attribute of the message analysis data, and classifying adjacent nodes according to different types to obtain a classification result;
and modifying the original routing table of the node based on the classification result to generate a dynamic routing table containing type attribute information.
Preferably, each node on the block chain transmits data based on a dynamic routing table corresponding to the node, and the method includes:
reading a dynamic routing table of a node, and acquiring type attribute information of an adjacent node in the dynamic routing table of the node;
reading a data distribution rule of a node, wherein the data distribution rule comprises: a node type data sending rule;
and acquiring the sending node information of the corresponding type from the dynamic routing table of the node based on the node type data sending rule, and sending the specific data to the node of the corresponding type.
Preferably, the data distribution rule further includes: the method comprises the following steps of receiving a node type data receiving rule, and after the data distribution rule of the reading node, the method further comprises the following steps:
receiving broadcast data;
judging whether the received broadcast data accords with the node type data receiving rule, if so, then:
writing the received broadcast data into a cache;
performing account book verification on the received broadcast data, and judging whether consensus is achieved, if so:
and storing the broadcast data in a certificate uplink.
Preferably, the dynamic routing table includes: type of neighboring node and IP information.
A system for blockchain data distribution based on type attribute information, comprising:
the routing table initialization module is used for generating a dynamic routing table by each node on the block chain based on the type attribute information of the node;
and the data transmission module is used for transmitting data by each node on the block chain based on the dynamic routing table corresponding to the node.
Preferably, the routing table initialization module includes: the network detection module and the routing table maintenance module; wherein:
the network detection module is used for respectively sending messages containing type attribute information of the nodes by the nodes on the block chain;
the network detection module is also used for receiving messages containing the type attribute information of the nodes sent by other nodes on the block chain by the nodes on the block chain;
the network detection module is also used for analyzing the received message containing the type attribute information of the node to obtain message analysis data;
the network detection module is further configured to determine the packet analysis data, and determine whether to add the packet analysis data into a routing table of the node according to a preset condition;
the routing table maintenance module is used for judging the type attribute of the message analysis data when judging to add the message analysis data into the routing table of the node according to preset conditions, and classifying adjacent nodes according to different types to obtain a classification result;
and the routing table maintenance module is also used for modifying the original routing table of the node based on the classification result and generating a dynamic routing table containing type attribute information.
Preferably, the data transmission module includes:
the first reading module is used for reading a dynamic routing table of a node and acquiring the type attribute information of an adjacent node in the dynamic routing table of the node;
a second reading module, configured to read a data distribution rule of a node, where the data distribution rule includes: a node type data sending rule;
and the data sending module is used for acquiring sending node information of a corresponding type from the dynamic routing table of the node based on the node type data sending rule and sending specific data to the node of the corresponding type.
Preferably, the data distribution rule further includes: the node type data receiving rule, the data transmission module further includes:
a receiving module for receiving broadcast data;
the judging module is used for judging whether the received broadcast data conforms to the node type data receiving rule or not;
a writing module, configured to write the received broadcast data into a cache when the received broadcast data conforms to the node type data receiving rule;
the account book verification module is used for performing account book verification on the received broadcast data and judging whether consensus is achieved;
and the evidence uplink storing module is used for storing the broadcast data into an evidence uplink when the common identification is achieved.
Preferably, the dynamic routing table includes: type of neighboring node and IP information.
In summary, the present invention discloses a method for distributing blockchain data based on type attribute information, wherein when data needs to be distributed, first, each node in a blockchain generates a dynamic routing table based on the type attribute information of the node, and then each node in the blockchain transmits the data based on the dynamic routing table corresponding to the node. The invention can generate the dynamic routing table based on the type attribute information of the node to distribute the data, thereby effectively reducing the consensus time and improving the efficiency of data distribution.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1, which is a flowchart of an embodiment 1 of a method for distributing blockchain data based on type attribute information disclosed in the present invention, the method may include the following steps:
s101, each node on the block chain generates a dynamic routing table based on the type attribute information of the node;
when data needs to be distributed, firstly, each node on the block chain generates a dynamic routing table corresponding to each node according to the type attribute information of the adjacent node.
S102, each node on the block chain transmits data based on the dynamic routing table corresponding to the node.
Then, when data is distributed, each node on the block chain distributes the data to the nodes with the attributes meeting the rule requirements according to the corresponding dynamic routing table.
In summary, in the above embodiment, when data needs to be distributed, first, each node in the block chain generates a dynamic routing table based on the type attribute information of the node, and then each node in the block chain transmits the data based on the dynamic routing table corresponding to the node. By adopting the routing table with the node type attribute information, the number of unnecessary nodes participating in consensus can be reduced on the premise of ensuring normal data transmission, unnecessary data transmission among the nodes is reduced, network load is reduced, and data transmission efficiency is improved.
Specifically, in the foregoing embodiment, one implementation manner of generating the dynamic routing table by each node on the blockchain based on the type attribute information of the node is shown in fig. 2, and may include the following steps:
s201, respectively sending messages containing type attribute information of nodes by the nodes on the block chain;
and aiming at each node on the block chain, when a dynamic routing table of each node needs to be generated, each node on the block chain respectively starts to detect the routing table and sends a message containing the type attribute information of the node.
S202, receiving messages containing type attribute information of nodes sent by other nodes on a block chain by the nodes on the block chain;
when each node in the block chain sends a message containing the type attribute information of the node, each node in the block chain receives messages containing the type attribute information of the node sent by other nodes in the block chain by monitoring the specific port of the node.
S203, analyzing the received message containing the type attribute information of the node to obtain message analysis data;
after receiving messages containing the type attribute information of the nodes sent by other nodes on the block chain, further analyzing the received messages containing the type attribute information of the nodes to obtain message analysis data.
S204, judging the message analysis data, judging whether to add the message analysis data into a routing table of the node according to preset conditions, if so, then:
and then, judging the message analysis data, and judging whether to add the message analysis data into a routing table of the node according to a preset condition. And when the preset condition of adding the routing table of the node is not met, restarting to execute the step that the nodes on the block chain respectively send the messages containing the type attribute information of the nodes. The preset conditions can be flexibly set according to actual requirements. For example, the network detection module may determine node attributes and calculate distances between nodes by broadcasting block link points in the detection network, and record nodes whose distances satisfy certain conditions in the routing table of the node.
S205, judging the type attribute of the message analysis data, and classifying adjacent nodes according to different types to obtain a classification result;
and when the preset condition of the routing table added to the node is met, further performing type attribute judgment on the message analysis data, and classifying the adjacent nodes according to different types according to the judgment result.
S206, modifying the original routing table of the node based on the classification result, and generating a dynamic routing table containing type attribute information.
And finally, modifying the original routing table of the node according to the classification result to generate a dynamic routing table containing type attribute information. Each node on the block chain respectively maintains an IP information table of an adjacent node, wherein the IP information table comprises attribute information and IP information of the adjacent node, that is, a routing table maintained by each node dynamically changes according to network detection conditions.
Specifically, in the above embodiment, one implementation manner of each node in the block chain transmitting data based on the dynamic routing table corresponding to the node is shown in fig. 3, and may include the following steps:
s301, reading a dynamic routing table of a node, and acquiring type attribute information of an adjacent node in the dynamic routing table of the node;
when a node on the block chain needs to transmit data, a dynamic routing table corresponding to the node is read first, and type attribute information of an adjacent node is read in the dynamic routing table. Wherein the type attribute information includes the type and IP information of the neighboring node.
S302, reading a data distribution rule of the node, wherein the data distribution rule comprises the following steps: a node type data sending rule and a node type data receiving rule;
and then, reading the data distribution rule to obtain the data distribution rule related to the node type. Wherein, the data distribution rule comprises: a node type data sending rule and a node type data receiving rule.
S303, when the data distribution rule is a node type data sending rule, based on the node type data sending rule, obtaining sending node information of a corresponding type from a dynamic routing table of the node, and sending specific data to the node of the corresponding type;
when the data distribution rule is a node type data sending rule, the node acquires sending node information of a corresponding type from the dynamic routing table, wherein the sending node information comprises information such as IP (Internet protocol), ports and the like, and then sends specific data to the node of the corresponding type according to the rule.
S304, when the data distribution rule is a node type data receiving rule, receiving broadcast data;
when the data distribution rule is a node-type data reception rule, broadcast data is received first.
S305, judging whether the received broadcast data accords with the node type data receiving rule, if so, entering S306:
and then the node judges whether the broadcast data accords with a data receiving rule corresponding to the node type, if not, the broadcast data is discarded, the port is monitored continuously, and new broadcast data is received.
S306, writing the received broadcast data into a cache;
and when the received broadcast data accords with the node type data receiving rule, writing the received broadcast data into the cache, continuing monitoring the port, and receiving new broadcast data.
S307, performing account book verification on the received broadcast data, judging whether consensus is achieved, if yes, entering S308:
then, the received broadcast data is subjected to account book verification to judge whether consensus is achieved. If the consensus is not reached, the broadcast data is discarded.
S308, the broadcast data is stored and uplink is carried out.
If the agreement is achieved, the agreed upon broadcast data is credited uplink.
To further illustrate the technical solution of the present invention, the following is described with specific examples:
as shown in table 1, a routing table is provided for this example. In the routing table of this example, type a represents a data collection node, type B represents an accounting node, and type C represents a policing node.
Table 1 routing table
First, a routing table is initialized. Each node accessing the blockchain reads an initialized routing table from the database when the node program is started. The initialized routing table has two sources, if the node is a restarting node, the initialized routing table is the last routing table maintained by the node before restarting, and if the node is added into the block chain network for the first time, the routing table is a long-term active or stable node IP carried by the node program.
Then, according to the system rule, reading the initialized routing table, and sending message information through a port in the initialized routing table, wherein the message information comprises the IP address of the node, the network service information, the type information, the time information, the detected adjacent node information and necessary verification information. Then, monitoring a preset interface, receiving the message information, analyzing the network service of the adjacent node and calculating the network delay. And judging whether the network service and the network delay meet the requirement of the routing table of the current node, and if not, continuing to send and receive the message. If the routing table meets the requirement, the message information is analyzed, the information of the type, IP, port and the like of the adjacent node is obtained, and then the initialized routing table is updated.
In the process of chaining the collected power grid data, firstly, the power grid data collection node collects the power grid related data and signs the data.
And then, a data transmission module of the data acquisition node reads a preset rule and a routing table, and for the data acquisition node, the data transmission module is positioned at the most marginal end of the whole block chain network, so that the data acquisition node does not need to have the capacity to participate in accounting rights competition and does not store blocks. So the routing rule for data collection node is a- > B, i.e. data of data collection node a is only broadcast to accounting node B.
And broadcasting the signed data and the certificate address by a data transmission module of the data acquisition node according to the IP address of the type B in the distributed routing table.
And the data transmission module of the accounting node receives the data sent by the data transmission module of the data acquisition node, and stores the data in the data cache.
And starting an account book verification module according to the signature data received by the data transmission module of the accounting node, analyzing and obtaining the public key of the node according to the certificate address, verifying the signature through the public key, passing the verification, and writing the signature into a block chain to be generated.
The accounting node starts an accounting right contention module to contend for accounting right.
And the data transmission module of the node acquiring the accounting right reads a preset rule and reads a classified dynamic routing table, wherein the type A in the dynamic routing table represents a data acquisition node, the type B represents an accounting node, and the type C represents a supervision node. For a new block, the predetermined rule is B- > BC needs to broadcast all nodes except type A.
And the data transmission module of the node acquiring the accounting right proves the IP addresses corresponding to the broadcast type B, the broadcast type C and the node by the new block and the accounting right.
In summary, the present invention employs a classified routing technology to directly access all nodes to the blockchain network, so that the capacity of the blockchain network is greatly increased, the data security is ensured, and meanwhile, the performance degradation caused by the increase of nodes is avoided. By adopting the routing table with the attribute information, the number of unnecessary nodes participating in consensus can be reduced on the premise of ensuring normal data transmission, unnecessary data transmission among the nodes is reduced, network load is reduced, and transmission efficiency is improved. Through testing, compared with a direct uplink mode, the time required for achieving consensus by adopting the method of the patent is reduced by 95% under the virtual machine testing environment of the Ethernet with 100 nodes. In the aspect of safety, compared with the existing central data uploading process, the data uploading and modification need to be agreed by all accounting nodes in the block chain, so that the possibility of data tampering is greatly reduced, and the safety of the system is greatly improved.
As shown in fig. 4, which is a schematic structural diagram of an embodiment 1 of a system for distributing blockchain data based on type attribute information disclosed in the present invention, the system may include:
a routing table initialization module 401, configured to generate a dynamic routing table based on type attribute information of each node on the block chain;
when data needs to be distributed, firstly, each node on the block chain generates a dynamic routing table corresponding to each node according to the type attribute information of the adjacent node.
And a data transmission module 402, configured to transmit data by each node in the block chain based on the dynamic routing table corresponding to the node.
Then, when data is distributed, each node on the block chain distributes the data to the nodes with the attributes meeting the rule requirements according to the corresponding dynamic routing table.
In summary, in the above embodiment, when data needs to be distributed, first, each node in the block chain generates a dynamic routing table based on the type attribute information of the node, and then each node in the block chain transmits the data based on the dynamic routing table corresponding to the node. By adopting the routing table with the node type attribute information, the number of unnecessary nodes participating in consensus can be reduced on the premise of ensuring normal data transmission, unnecessary data transmission among the nodes is reduced, network load is reduced, and data transmission efficiency is improved.
Specifically, in the foregoing embodiment, one of the structures of the routing table initialization module is shown in fig. 5, and may include: a network detection module 501 and a routing table maintenance module 502, wherein:
a network detection module 501, configured to send, by a node in a block chain, a packet including type attribute information of the node;
and aiming at each node on the block chain, when a dynamic routing table of each node needs to be generated, each node on the block chain respectively starts to detect the routing table and sends a message containing the type attribute information of the node.
The network detection module 501 is further configured to receive, by a node in the block chain, a packet that includes type attribute information of the node and is sent by another node in the block chain;
when each node in the block chain sends a message containing the type attribute information of the node, each node in the block chain receives messages containing the type attribute information of the node sent by other nodes in the block chain by monitoring the specific port of the node.
The network detection module 501 is further configured to analyze the received message including the type attribute information of the node, so as to obtain message analysis data;
after receiving messages containing the type attribute information of the nodes sent by other nodes on the block chain, further analyzing the received messages containing the type attribute information of the nodes to obtain message analysis data.
The network detection module 501 is further configured to determine the packet analysis data, and determine whether to add the packet analysis data into the routing table of the node according to a preset condition;
and then, judging the message analysis data, and judging whether to add the message analysis data into a routing table of the node according to a preset condition. And when the preset condition of adding the routing table of the node is not met, restarting to execute the step that the nodes on the block chain respectively send the messages containing the type attribute information of the nodes. The preset conditions can be flexibly set according to actual requirements. For example, the network detection module may determine node attributes and calculate distances between nodes by broadcasting block link points in the detection network, and record nodes whose distances satisfy certain conditions in the routing table of the node.
A routing table maintenance module 502, configured to, when judging to add to the routing table of the node according to a preset condition, perform type attribute judgment on the packet analysis data, and classify adjacent nodes according to different types to obtain a classification result;
and when the preset condition of the routing table added to the node is met, further performing type attribute judgment on the message analysis data, and classifying the adjacent nodes according to different types according to the judgment result.
The routing table maintenance module 502 is further configured to modify the original routing table of the node based on the classification result, and generate a dynamic routing table containing type attribute information.
And finally, modifying the original routing table of the node according to the classification result to generate a dynamic routing table containing type attribute information. Each node on the block chain respectively maintains an IP information table of an adjacent node, wherein the IP information table comprises attribute information and IP information of the adjacent node, that is, a routing table maintained by each node dynamically changes according to network detection conditions.
Specifically, in the above embodiment, one of the structures of the data transmission module is as shown in fig. 6, and may include:
a first reading module 601, configured to read a dynamic routing table of a node, and obtain type attribute information of an adjacent node in the dynamic routing table of the node;
when a node on the block chain needs to transmit data, a dynamic routing table corresponding to the node is read first, and type attribute information of an adjacent node is read in the dynamic routing table. Wherein the type attribute information includes the type and IP information of the neighboring node.
A second reading module 602, configured to read a data distribution rule of a node, where the data distribution rule includes: a node type data sending rule and a node type data receiving rule;
and then, reading the data distribution rule to obtain the data distribution rule related to the node type. Wherein, the data distribution rule comprises: a node type data sending rule and a node type data receiving rule.
A data sending module 603, configured to, when the data distribution rule is a node type data sending rule, obtain, based on the node type data sending rule, sending node information of a corresponding type from a dynamic routing table of a node, and send specific data to the node of the corresponding type;
when the data distribution rule is a node type data sending rule, the node acquires sending node information of a corresponding type from the dynamic routing table, wherein the sending node information comprises information such as IP (Internet protocol), ports and the like, and then sends specific data to the node of the corresponding type according to the rule.
A receiving module 604, configured to receive broadcast data when the data distribution rule is a node type data receiving rule;
when the data distribution rule is a node-type data reception rule, broadcast data is received first.
A determining module 605, configured to determine whether the received broadcast data meets a node type data receiving rule;
and then the node judges whether the broadcast data accords with a data receiving rule corresponding to the node type, if not, the broadcast data is discarded, the port is monitored continuously, and new broadcast data is received.
A writing module 606, configured to write the received broadcast data into a cache when the received broadcast data meets the node type data receiving rule;
and when the received broadcast data accords with the node type data receiving rule, writing the received broadcast data into the cache, continuing monitoring the port, and receiving new broadcast data.
The account book verification module 607 is configured to perform account book verification on the received broadcast data, and determine whether consensus is achieved;
then, the received broadcast data is subjected to account book verification to judge whether consensus is achieved. If the consensus is not reached, the broadcast data is discarded.
A evidence uplink module 608 for broadcasting data evidence uplink when the consensus is achieved.
If the agreement is achieved, the agreed upon broadcast data is credited uplink.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.