Disclosure of Invention
In order to achieve the above object, the present application provides the following technical solutions:
an information processing method based on a block chain comprises the following steps:
the target node calculates the hash value of the latest block, the latest block is the block with the latest time of generation, the hash value of any one block is generated according to preset parameters, and the preset parameters comprise the hash value of the last block and the timestamp of the current time; the target node is any one node in the block chain;
and the target node determines a block node according to the hash value of the latest block and the hash value of the node.
Optionally, in the method, determining a block node according to the hash value of the latest block and the hash value of the node includes:
determining the position of the hash value of the latest block on a virtual hash ring;
and taking the node positioned after the position on the virtual hash ring as the block outlet node, wherein the position of the node on the virtual hash ring is determined by the hash value of the node.
The above method, optionally, further includes:
and the target node updates the associated node of the target node on the virtual hash ring based on the newly added and/or deleted node on the virtual hash ring, wherein the associated node comprises at least one of a preamble node, a subsequent node and a backup node.
The method optionally further includes, after the determining the block node:
and if the out-blocking node fails, taking a subsequent node of the out-blocking node on the virtual hash ring as a new out-blocking node.
The method optionally further includes, after the determining the block node:
and the target node takes the node of which the sequence with the out-block node meets the preset condition as a backup node of the out-block node.
In the foregoing method, optionally, the node whose ordering with the block output node meets a preset condition includes:
on the virtual hash ring, the position of the node on the virtual hash ring is determined by the hash value of the node, wherein the node is a preset number of nodes behind the block-out node.
In the foregoing method, optionally, the preset parameters further include:
and the target transaction information is the transaction information of a preset position in a preset transaction information tree.
The above method, optionally, further includes:
the target node checks other nodes through the blocks on the target node in a preset period;
wherein the process of checking other nodes by any one block on the target node comprises:
calculating a hash value of a target block, wherein the target block is any one block on the target node;
determining a block outlet node of the target block and a backup node of the block outlet node according to the hash value of the target block;
comparing the target transaction information of the target block on the egress node and the backup node;
and taking the nodes of the block outlet node and the backup node, wherein the target transaction information is different from other nodes, as illegal nodes.
An information processing apparatus based on a block chain, comprising:
the calculating unit is used for calculating the hash value of the latest block, the latest block is the block with the latest time of generation, the hash value of any one block is generated according to preset parameters, and the preset parameters comprise the hash value of the last block and the timestamp of the current time;
and the determining unit is used for determining the block node according to the hash value of the latest block and the hash value of the node.
An electronic device, comprising: the device comprises a processor and a memory, wherein the memory is used for storing an application program, and the processor is used for executing the application program so as to realize the information processing method based on the block chain.
A computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to execute the above-described block chain-based information processing method.
According to the method and the device, the target node calculates the hash value of the latest block, and the target node determines the block node according to the hash value of the latest block and the hash value of the node. The latest block is the block with the latest generation time, the hash value of any one block is generated according to preset parameters, and the preset parameters comprise the hash value of the last block and the timestamp of the current moment; the target node is any one node in the block chain. Therefore, compared with the prior workload consensus method, the technical scheme can determine the block nodes only by acquiring the hash value of the latest block and the hash values of all the nodes. Because the hash values of the blocks and the hash values of the nodes are calculated, the calculation is simple and the calculation amount is small, so that the problem that a large amount of resources are occupied due to large calculation amount in the workload consensus method is solved.
Detailed Description
In the process of building the blockchain network, firstly, the network needs to be initialized, a certain number of nodes are collected for blockchain initiating equipment in the initialization process, an initial account is created for each node, the initial account is used for initiating a transaction and is used as a carrier for bearing the transaction, and finally, a created block creating the blockchain is created, so that the initialization process of building the blockchain network is completed. On the basis of the initialization, the method provided by the following embodiment is combined to determine the node that has a block in the block quantity network.
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, 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 application.
Fig. 1 is an information processing method based on a block chain according to an embodiment of the present application, and the method may include the following steps:
s101, the target node calculates the hash value of the latest block.
The target node may be any node in the block chain, that is, any node in the collected nodes, and the latest block is the block whose generation time is the latest, that is, the last block in the current block chain. The hash value of the block is generated according to preset parameters, and the preset parameters comprise the hash value of the previous block and the timestamp of the current time. The prior art can be referred to for a specific implementation method for calculating the hash value of the block according to the preset parameters.
S102, the target node determines the block node according to the hash value of the latest block and the hash value of the node.
The hash value of the node is information capable of uniquely identifying the node, and for example, the hash value of the node can be obtained by using the MAC address of the node as a parameter and using the existing hash algorithm.
In the block chain network, a final block-out node needs to be selected from a plurality of nodes competing out blocks at the same time. One way to determine the block node according to the hash value of the latest block and the hash value of the node may be: and the target node determines the position of the hash value of the latest block on the virtual hash ring, and takes the node positioned after the position on the virtual hash ring as the out-block node.
The virtual hash ring is a virtual circular ring formed by hash values, each node has a corresponding position in the virtual hash ring, and the position of the node on the virtual hash ring is determined by the hash value of the node.
After the target node calculates the hash value of the latest block, the hash value is found in the virtual ring, so as to determine the position of the hash value in the virtual ring, and the node located after the position on the virtual hash ring is used as the block node, for example, in the virtual hash ring, the first node located after the hash value of the latest block is used as the block node in the clockwise direction.
It should be noted that, since the hash value of the latest block in the block chain is obtained by calculation according to the hash value of the last block and the timestamp of the current time, the hash values of the latest blocks at each time are different, and therefore the positions of the latest blocks at any time on the virtual hash ring cannot be the same, so that it is ensured that the nodes that go out of blocks at each time cannot be the same node, and fairness of the nodes that go out of blocks is ensured.
In the method provided in this embodiment, the target node calculates the hash value of the latest block, and determines the block node according to the hash value of the latest block and the hash value of the node. Compared with the prior workload consensus method, the technical scheme can determine the block nodes only by knowing the hash value of the latest block and the hash values of all the nodes. Because the hash values of the blocks and the hash values of the nodes are calculated, the calculation is simple and the calculation amount is small, and the problem that the existing workload consensus method needs to occupy a large amount of resources due to large calculation amount can be solved.
In the foregoing embodiment, after the block node is determined, it may be further determined whether the block node is a failed node, and if the block node fails, a subsequent node of the block node on the virtual hash ring is used as a new block node. For example, in the virtual hash ring, the first and non-existing failed node after the failed blocked node is treated as a new blocked node in the clockwise direction. Therefore, the phenomenon that the block is stopped because the failed node is used as the block outlet node is avoided.
Considering the situation that a new node usually accesses or exits a blockchain in a blockchain network, referring to fig. 2 in conjunction with fig. 1, it is shown that another information processing method based on blockchains provided by the embodiments of the present application may include the following steps:
s201, the target node calculates the hash value of the latest block.
S202, the target node determines the block node according to the hash value of the latest block and the hash value of the node.
In this embodiment, the specific implementation manners of S201 to S202 may refer to S101 to S102 in the above embodiments, and are not described herein again.
S203, the target node updates the associated node of the target node on the virtual hash ring based on the newly added or deleted node on the virtual hash ring.
When a new node is added into the block chain, the new node can broadcast the hash value of the new node added into the block chain, and the new node can be mapped into the virtual hash ring according to the hash value of the new node. Similarly, when a node exits a block chain, the node broadcasts the hash value of the node that exits the block chain, and after the node exits the block chain, the node is deleted from the virtual ring.
The target node is any node in the block chain, and based on a newly added or deleted node on the virtual hash ring, one way of updating the associated node of the target node on the virtual hash ring is as follows: and after the target node receives the hash value of the joining block chain or the hash value of the quitting block chain broadcasted by the node, updating the associated node according to the hash value broadcasted by the node, the hash value of the target node and the hash value of the associated node. The associated nodes of the target node are a preamble node, a subsequent node and a backup node. The backup node of the target node is: on the virtual hash ring, a preset number of nodes after the target node in the clockwise direction, for example, the nearest 3 nodes after the target node. The specific practical way for the target node to update the association node may refer to an existing hash algorithm, which is not described herein again.
It should be noted that fig. 2 is only an example of the present application, and the method provided by this embodiment may further perform step S203 before performing S201, or perform S203 after performing S201 and before performing S202. The specific execution sequence of S203 is determined according to the hash value of the joining or exiting block chain received by the target node from the other node. For example, the target node receives the hash value of joining or exiting the block chain broadcast by the other node before executing S201, and then executes S201 after executing S203.
According to the method provided by the embodiment of the application, the target node updates the associated node of the target node on the virtual hash ring according to the newly added or deleted node on the virtual hash ring, so that the method dynamically adapts to network fluctuation caused by adding or quitting the node, the probability that the newly added node can compete out the block fairly is ensured, and the node which does not participate in the block is deleted in time.
In a blockchain network, after a blocked node is blocked, the blocked node needs to store the block, so as to search the block or verify whether the block is tampered, with reference to fig. 1 and fig. 3, which are shown in fig. 3, that another information processing method based on a blockchain is provided in an embodiment of the present application, and may include the following steps:
s301, the target node calculates the hash value of the latest block.
S302, the target node determines a block node according to the hash value of the latest block and the hash value of the node.
In this embodiment, the specific implementation manners of S301 to S302 may refer to S101 to S102 in the above embodiments, and are not described herein again.
And S303, taking the node of which the sequence with the out-block node meets the preset condition as a backup node of the out-block node by the target node.
As described in the foregoing embodiment, the nodes whose ordering of the block output nodes meets the preset condition are: and on the virtual hash ring, a preset number of nodes are arranged after the block node. For example, on the virtual hash ring, i nodes (i ≧ 2) closest to the chunked node are located clockwise. And the position of the node on the virtual hash ring is determined by the hash value of the node.
S304, the target node stores the generated blocks of the out-of-block node into the out-of-block node and the backup node of the out-of-block node.
After the backup node of the block node is determined, the block generated by the block output node is stored in the block output node and the backup node of the block output node, and distributed storage is realized.
The method provided by the embodiment stores the block generated by the block output node into the block output node and the backup node of the block output node, thereby realizing distributed storage. Compared with the existing full-node storage mechanism for storing the blocks generated by the out-of-block nodes to all the nodes in the block chain network, the method provided by the embodiment of the application only needs to store the blocks generated by the out-of-block nodes to the out-of-block nodes and the backup nodes of the out-of-block nodes, not only has the advantage of distributed storage of the full-node storage mechanism, but also can avoid the problem that the storage resources are wasted because the same block occupies a large amount of storage space due to full-node storage.
In the block chain, since there may be an illegal node tampering the transaction information of the block, in order to timely find the illegal node in the block chain, in this embodiment, the target node checks whether other nodes are illegal nodes through the block on the target node at a preset period. Referring to fig. 4, it illustrates a method for checking other nodes by any one block on a target node according to an embodiment of the present application, which may include the following steps:
s401, the target node calculates the hash value of the target block.
The target node is any one node in the block chain, the target block is any one block stored in the target node, the hash value of the target block is generated according to preset parameters, and the preset parameters comprise the hash value of the last block of the target block, a timestamp and a random number corresponding to the generated target block, and target transaction information of the target block. The target transaction information is transaction information of a preset position in a preset transaction information tree. The transaction information tree is a binary tree formed by hash values of the transaction information, and the target transaction information is a hash value on a root node of the binary tree.
S402, the target node determines a block outlet node of the target block and a backup node of the block outlet node according to the hash value of the target block.
The process of the target node determining the out-blocking node of the target block according to the hash value of the target block is implemented as follows: the target node determines a block outlet node of the target block, the target node determines the position of the hash value of the target block on the virtual hash ring, and the first node after the position on the virtual hash ring is used as the block outlet node of the target block. Meanwhile, the target node takes the node which meets the preset condition with the sorting of the block outlet nodes of the target block as the backup node of the block outlet node.
S403, the target node compares the target transaction information of the block node and the target block on the backup node.
The block generated by the out-blocking node is not only stored in itself, but also stored in its backup node, that is, the target block is stored in the out-blocking node of the target block and the backup node of the out-blocking node. Because each target block has an identity number, the target block in the backup node can be found out through the identity number of the target block.
After the target node determines the target block on the backup node, the target node compares whether the target transaction information of the target block on the block node and the backup node is the same or not so as to verify whether the target transaction information of the target block is tampered or not.
S404, the target node takes the node with the target transaction information different from other nodes in the block node and the backup node as an illegal node.
And (4) taking the target node as an illegal node according to the principle that a small number of nodes obey a large number of nodes, wherein the target transaction information of the small number of nodes is different from that of other nodes in the backup nodes. For example, the total number of the block-out nodes and the backup nodes is 11, wherein the target transaction information of 9 nodes is the same, and the target transaction information of the rest 2 nodes is different from the 9 nodes, and then the 2 nodes are taken as illegal nodes. The illegal nodes will be permanently cleared out of the blockchain.
In the method provided by this embodiment, the target node verifies whether there is an illegal node in the block-out node and the backup node by comparing the target transaction information of the target block on the block-out node and the backup node, so that the purposes of clearing the illegal node and maintaining the block chain data security can be achieved.
Corresponding to the above information processing method based on a block chain provided in the embodiment of the present application, referring to fig. 5, a block diagram of a block chain based information processing apparatus 500 provided in the embodiment of the present application is shown, including:
a calculating unit 501, configured to calculate a hash value of a latest block, where the latest block is a block with the latest time of generation, and a hash value of any one block is generated according to preset parameters, where the preset parameters include a hash value of a previous block and a timestamp of a current time;
the determining unit 502 is configured to determine a block node according to the hash value of the latest block and the hash value of the node.
An updating unit 503, configured to update an associated node of the target node on the virtual hash ring based on a newly added and/or deleted node on the virtual hash ring, where the associated node includes at least one of a preamble node, a subsequent node, and a backup node.
The sorting unit 504 is configured to use a node, the sorting of which meets a preset condition, as a backup node of the out-block node. The nodes whose sequence with the out-block nodes meets the preset condition are: on the virtual hash ring, a preset number of nodes after the node is blocked, and the positions of the nodes on the virtual hash ring are determined by the hash values of the nodes.
The verifying unit 505 is configured to verify other nodes through the blocks on the target node at a preset period, where a specific implementation manner of verifying other nodes through any one of the blocks on the target node is as follows: calculating the hash value of a target block, wherein the target block is any one block on a target node; determining a block outlet node of the target block and a backup node of the block outlet node according to the hash value of the target block; comparing the target transaction information of the target blocks on the block nodes and the backup nodes; and taking the node of the block outlet node and the node of the backup node, wherein the target transaction information is different from other nodes, as illegal nodes. The hash value of the target block is calculated according to preset parameters, wherein the preset parameters comprise the hash value of the last block of the target block, a timestamp corresponding to the target block, a random number and target transaction information of the target block.
The specific implementation manner of determining the block node by the determining unit 502 according to the hash value of the latest block and the hash value of the node is as follows: determining the position of the hash value of the latest block on the virtual hash ring; and taking the node behind the position on the virtual hash ring as a block-out node, wherein the position of the node on the virtual hash ring is determined by the hash value of the node.
The updating unit 503 is further configured to, if the out-blocking node fails, take a subsequent node of the out-blocking node on the virtual hash ring as a new out-blocking node.
According to the device provided by the embodiment of the application, the target node calculates the hash value of the latest block, and the target node determines the block node according to the hash value of the latest block and the hash value of the node. The latest block is the block with the latest generation time, the hash value of any one block is generated according to preset parameters, and the preset parameters comprise the hash value of the last block and the timestamp of the current moment; the target node is any one node in the block chain. Therefore, compared with the prior workload consensus method, the technical scheme can determine the block nodes only by knowing the hash value of the latest block and the hash values of all the nodes. Because the hash values of the blocks and the hash values of the nodes are calculated, the calculation is simple and the calculation amount is small, so that the problem that a large amount of resources are required to be occupied due to the calculation amount in the workload consensus method is solved.
An embodiment of the present invention further provides an electronic device 600, a schematic structural diagram of which is shown in fig. 6, and the electronic device specifically includes: a processor 601 and a memory 602, the memory 602 being used for storing programs; the processor 601 is configured to run a program to implement the information processing method based on the block chain in the embodiment of the present invention.
An embodiment of the present invention further provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions are executed on a computer, the computer is enabled to execute the information processing method based on the block chain in the embodiment of the present invention.
The functions described in the method of the embodiment of the present application, if implemented in the form of software functional units and sold or used as independent products, may be stored in a storage medium readable by a computing device. Based on such understanding, part of the contribution to the prior art of the embodiments of the present application or part of the technical solution may be embodied in the form of a software product stored in a storage medium and including several instructions for causing a computing device (which may be a personal computer, a server, a mobile computing device or a network device) to execute all or part of the steps of the method described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. 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 application. Thus, the present application 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.