Disclosure of Invention
In view of the foregoing drawbacks or deficiencies of the prior art, it is desirable to provide a consensus method, apparatus and storage medium that reduces a threshold for a blockchain.
In a first aspect, the present application provides a consensus method, device and storage medium applicable to all nodes, where a blockchain network is configured with a plurality of all nodes, ledger nodes and status nodes, the method includes:
generating a first block in response to the mining weight of the first block with the first block height, and broadcasting the first block to all network nodes so that other all nodes and each account node can store the first block, and each state node can buffer the first block; wherein the first block header of the first block does not include the first state hash of the first block;
executing the first block to generate a first state result set; the first state result set comprises first block hash of a first block, first state information and second state information of each first transaction in a first transaction list of the first block, wherein the first state information is state information of a transaction related party in the first transaction before the first transaction is executed, and the second state information is state information of the transaction related party after the first transaction is executed;
broadcasting the first state result set to all network nodes so that other all nodes and all state nodes execute a first step, and all account nodes execute a second step; the first step is as follows:
searching a corresponding second block locally according to the first block hash;
searching corresponding third state information according to the second transactions of the second block; the third status information is status information of a transaction related party of the second transaction before the second transaction is executed;
judging whether each third state information is identical to each first state information:
if yes, judging whether the second state information is the same as the fourth state information after the corresponding second transaction is updated and executed:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, not broadcasting the first state result set;
if not, not broadcasting the first state result set;
the second step is:
searching a corresponding second block locally according to the first block hash;
obtaining fifth state information according to the first state information and corresponding second transactions in the second block;
judging whether each fifth state information is identical to each second state information:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, the first set of state results is not broadcast.
In a second aspect, the present application provides a consensus method, device and storage medium applicable to ledger nodes, where a blockchain network is configured with a plurality of full nodes, ledger nodes and status nodes, the method includes:
receiving and storing a first block; the first block is generated by a first full node in response to the mining weight of the first block with the height of the first block, and is sent to the full network node, the first state hash of the first block is not included in the first block head of the first block, and the first block is also cached by all state nodes;
receiving a first state result set; the first state result set is generated by executing a first block by a first full node and is sent to the full network node, the first state result set comprises first block hash of the first block, first state information and second state information of each first transaction in a first transaction list of the first block, the first state information is state information of a transaction related party in the first transaction before executing the first transaction, and the second state information is state information of the transaction related party after executing the first transaction;
searching a corresponding second block locally according to the first block hash;
obtaining fifth state information according to the first state information and corresponding second transactions in the second block;
judging whether each fifth state information is identical to each second state information:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, not broadcasting the first state result set;
wherein, each full node and each state node except the first full node further execute the following steps:
searching a corresponding second block locally according to the first block hash;
searching corresponding third state information according to the second transactions of the second block; the third status information is status information of a transaction related party of the second transaction before the second transaction is executed;
judging whether each third state information is identical to each first state information:
if yes, judging whether the second state information is the same as the fourth state information after the corresponding second transaction is updated and executed:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, not broadcasting the first state result set;
if not, the first set of state results is not broadcast.
In a third aspect, the present application provides a consensus method, device and storage medium applicable to a state node, where a blockchain network is configured with a plurality of full nodes, ledger wall nodes and state nodes, the method includes:
receiving and caching the first block; the first block is generated by a first full node in response to the mining weight of the first block, which is the height of the first block, and is sent to the full network node, the first state hash of the first block is not included in the first block head of the first block, and the first block is also stored by all nodes and all account book nodes;
receiving a first state result set; the first state result set is generated by executing a first block by a first full node and is sent to the full network node, the first state result set comprises first block hash of the first block, first state information and second state information of each first transaction in a first transaction list of the first block, the first state information is state information of a transaction related party in the first transaction before executing the first transaction, and the second state information is state information of the transaction related party after executing the first transaction;
searching a corresponding second block locally according to the first block hash;
searching corresponding third state information according to the second transactions of the second block; the third status information is status information of a transaction related party of the second transaction before the second transaction is executed;
judging whether each third state information is identical to each first state information:
if yes, judging whether the second state information is the same as the fourth state information after the corresponding second transaction is updated and executed:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, not broadcasting the first state result set;
if not, not broadcasting the first state result set;
wherein each full node except the first full node also performs the steps of receiving the first state result set to broadcast the first state result set to the full network node, and each ledger node further performs the steps of:
searching a corresponding second block locally according to the first block hash;
obtaining fifth state information according to the first state information and corresponding second transactions in the second block;
judging whether each fifth state information is identical to each second state information:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, the first set of state results is not broadcast.
In a fourth aspect, the present application also provides an apparatus comprising one or more processors and a memory, wherein the memory contains instructions executable by the one or more processors to cause the one or more processors to perform the consensus method provided in accordance with the various embodiments of the present application.
In a fifth aspect, the present application also provides a storage medium storing a computer program that causes a computer to execute the consensus method provided according to the embodiments of the present application.
The consensus method, the consensus device and the consensus storage medium provided by the embodiments of the application generate the first block by responding to the mining weight of the first block which obtains the height of the first block, and broadcast the first block to the nodes of the whole network; executing the first block to generate a first state result set; a method of broadcasting a first set of state results to nodes of a full network reduces the threshold of blockchains.
Detailed Description
The application is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the application and are not limiting of the application. It should be noted that, for convenience of description, only the portions related to the application are shown in the drawings.
It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other. The application will be described in detail below with reference to the drawings in connection with embodiments.
Fig. 1 is a flowchart of a consensus method according to an embodiment of the present application. As shown in fig. 1, in this embodiment, the present application provides a consensus method, device and storage medium applicable to all nodes, where a blockchain network is configured with a plurality of all nodes, ledger nodes and status nodes, and the method includes:
s12: generating a first block in response to the mining weight of the first block with the first block height, and broadcasting the first block to all network nodes so that other all nodes and each account node can store the first block, and each state node can buffer the first block; wherein the first block header of the first block does not include the first state hash of the first block;
s14: executing the first block to generate a first state result set; the first state result set comprises first block hash of a first block, first state information and second state information of each first transaction in a first transaction list of the first block, wherein the first state information is state information of a transaction related party in the first transaction before the first transaction is executed, and the second state information is state information of the transaction related party after the first transaction is executed;
s16: broadcasting the first state result set to all network nodes so that other all nodes and all state nodes execute a first step, and all account nodes execute a second step; the first step is as follows:
searching a corresponding second block locally according to the first block hash;
searching corresponding third state information according to the second transactions of the second block; the third status information is status information of a transaction related party of the second transaction before the second transaction is executed;
judging whether each third state information is identical to each first state information:
if yes, judging whether the second state information is the same as the fourth state information after the corresponding second transaction is updated and executed:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, not broadcasting the first state result set;
if not, not broadcasting the first state result set;
the second step is:
searching a corresponding second block locally according to the first block hash;
obtaining fifth state information according to the first state information and corresponding second transactions in the second block;
judging whether each fifth state information is identical to each second state information:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, the first set of state results is not broadcast.
Specifically, assuming that 10 nodes are shared in the blockchain network, N1 to N4 are all nodes, N5 to N7 are ledger nodes, and N8 to N10 are state nodes; n1 obtains the mining weight of a block with the block height of 100;
in response to obtaining the mining weight of a block with a block height of 100, N1 performs step S12, generates block (100) _N1, and broadcasts block (100) _N1 to N2-N10; block (100) _N1 does not include statehash (100);
N2-N7 store block (100) _N1, N8-N10 cache block (100) _N1;
n1 executes step S14, executes block (100) _N1, and generates a state result set; assuming block (100) _n1 includes tx1, tx2, tx1 being a to B10coin, tx2 being C to D20 coin, and the balance of A, B, C, D being 50coin before tx1, tx2 are performed; the state result set includes { blockhash (100) _n1, {50,50,50,50}, {40,60,30,70};
n1 executes step S16, and { blockhash (100) _N1, {50,50,50,50}, {40,60,30,70} is broadcasted to N2-N10;
N2-N4, N8-N10 find the correspondent block hash (100) _n1' locally according to the block hash (100) _n1; it should be noted that, for network reasons, it is possible that N2 to N4, N8 to N10 cannot find the blockhash (100) _n1' locally, the blockhash (100) _n1 should be desynchronized to other blockchain nodes through P2P, then the current step is executed, if the synchronization is not completed, then the subsequent step is not executed;
N2-N4, N8-N10 find each state information before executing tx1, tx2 according to the transaction in the blockhash (100) _n1' (if the blockhash (100) _n1' is consistent with the blockhash (100) _n1), the found transaction should be tx1, tx2, in this embodiment, the blockhash (100) _n1' is consistent with the blockhash (100) _n1), for example, the found state information is {50,50,50,50};
because the searched state information is the same as the state information before executing tx1 and tx2 in the state result set, N2-N4 and N8-N10 update executing tx1 and tx2 according to the searched state information {50,50,50,50} to update A, B, C, D state information {40,60,30,70}; because the state information after executing tx1 and tx2 in the state result set is the same as the state information after executing tx1 and tx2, which are updated locally by N2-N4 and N8-N10, N2-N4 and N8-N10 broadcast { blockhash (100) _n1, {50,50,50,50}, {40,60,30,70} to the nodes of the whole network;
N5-N7 search the corresponding block blockhash (100) _N1' locally according to the blockhash (100) _N1; for network reasons, if the N5-N7 cannot find the blockhash (100) _N1' locally, the blockhash (100) _N1 should be desynchronized to other blockchain nodes through P2P, then the current step is executed, and if the synchronization is not completed, the subsequent steps are not executed;
N5-N7 obtain each state information after executing tx1 and tx2 according to {50,50,50,50}, tx1 and tx 2;
if the blockhash (100) _n1' is consistent with the blockhash (100) _n1, N5-N7 judge that the state information after executing tx1 and tx2 is the same as the state information after executing tx1 and tx2 in the state result set, and N5-N7 broadcast { blockhash (100) _n1, {50,50,50,50}, {40,60,30,70} to the full network node.
When the state information found by N2 to N4 and N8 to N10 is different from the state information before tx1 and tx2 are executed in the state result set, or the state information after tx1 and tx2 are executed in the state result set is different from the state information after tx1 and tx2 are executed in the local update of N2 to N4 and N8 to N10, N2 to N4 and N8 to N10 do not broadcast { blockhash (100) _n1, {50,50,50,50}, {40,60,30,70}; when N5-N7 judge that each state information after executing tx1 and tx2 is different from each state information after executing tx1 and tx2 in the state result set, N5-N7 do not broadcast { blockhash (100) _N1, {50,50,50,50}, {40,60,30,70 }.
It should be noted that, N8 to N10 buffer blocks (100) _n1, and when the block height reaches a second preset block height, N8 to N10 delete the buffered blocks (100) _n1, where the second block height is determined by the first block height and the preset security depth, that is, the state node finally only stores the state tree of the state data, and the ledger node only stores the history ledger data.
In the embodiment, 10 nodes in total are used in a blockchain network, N1-N4 are all nodes, N5-N7 are account book nodes, and N8-N10 are state nodes; the mining weight of the block with the block height of 100 is obtained by N1 as an example to exemplarily illustrate the consensus principle of the present application, and in other embodiments, the number of each type of node in the blockchain network may be configured according to actual requirements, so that the same technical effect may be achieved.
The above embodiments lower the threshold for machines to join the blockchain.
Fig. 2 is a flowchart of another consensus method according to an embodiment of the present application. As shown in fig. 2, in this embodiment, the present application provides a consensus method, device and storage medium applicable to ledger nodes, where a blockchain network is configured with a plurality of full nodes, ledger nodes and status nodes, and the method includes:
s22: receiving and storing a first block; the first block is generated by a first full node in response to the mining weight of the first block with the height of the first block, and is sent to the full network node, the first state hash of the first block is not included in the first block head of the first block, and the first block is also cached by all state nodes;
s23: receiving a first state result set; the first state result set is generated by executing a first block by a first full node and is sent to the full network node, the first state result set comprises first block hash of the first block, first state information and second state information of each first transaction in a first transaction list of the first block, the first state information is state information of a transaction related party in the first transaction before executing the first transaction, and the second state information is state information of the transaction related party after executing the first transaction;
s24: searching a corresponding second block locally according to the first block hash;
s25: obtaining fifth state information according to the first state information and corresponding second transactions in the second block;
s261: judging whether each fifth state information is identical to each second state information:
if yes, step S262 is executed: broadcasting a first state result set to all network nodes;
if not, then step S263 is performed: not broadcasting the first set of state results;
wherein, each full node and each state node except the first full node further execute the following steps:
searching a corresponding second block locally according to the first block hash;
searching corresponding third state information according to the second transactions of the second block; the third status information is status information of a transaction related party of the second transaction before the second transaction is executed;
judging whether each third state information is identical to each first state information:
if yes, judging whether the second state information is the same as the fourth state information after the corresponding second transaction is updated and executed:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, not broadcasting the first state result set;
if not, the first set of state results is not broadcast.
The consensus principle of the above embodiment may refer to the method shown in fig. 1, and will not be described herein.
Fig. 3 is a flowchart of another consensus method according to an embodiment of the present application. As shown in fig. 3, in this embodiment, the present application provides a consensus method, device and storage medium applicable to a state node, where a blockchain network is configured with a plurality of full nodes, ledger nodes and state nodes, and the method includes:
s32: receiving and caching the first block; the first block is generated by a first full node in response to the mining weight of the first block, which is the height of the first block, and is sent to the full network node, the first state hash of the first block is not included in the first block head of the first block, and the first block is also stored by all nodes and all account book nodes;
s33: receiving a first state result set; the first state result set is generated by executing a first block by a first full node and is sent to the full network node, the first state result set comprises first block hash of the first block, first state information and second state information of each first transaction in a first transaction list of the first block, the first state information is state information of a transaction related party in the first transaction before executing the first transaction, and the second state information is state information of the transaction related party after executing the first transaction;
s34: searching a corresponding second block locally according to the first block hash;
s35: searching corresponding third state information according to the second transactions of the second block; the third status information is status information of a transaction related party of the second transaction before the second transaction is executed;
s361: judging whether each third state information is identical to each first state information:
if yes, go to step S3621: judging whether each second state information is the same as each fourth state information after updating and executing the corresponding second transaction:
if yes, go to step S3622: broadcasting a first state result set to all network nodes;
no, step S3633 is performed: not broadcasting the first set of state results;
if not, then step S363 is executed: not broadcasting the first set of state results;
wherein each full node except the first full node also performs the steps of receiving the first state result set to broadcast the first state result set to the full network node, and each ledger node further performs the steps of:
searching a corresponding second block locally according to the first block hash;
obtaining fifth state information according to the first state information and corresponding second transactions in the second block;
judging whether each fifth state information is identical to each second state information:
if yes, broadcasting a first state result set to the nodes of the whole network;
if not, the first set of state results is not broadcast.
The consensus principle of the above embodiment may refer to the method shown in fig. 1, and will not be described herein.
Preferably, the method further comprises:
deleting the first block of the cache when the block height reaches the preset second block height;
the second block height is determined by the first block height and the pre-configured safety depth.
The consensus principle of the above embodiment may refer to the method shown in fig. 1, and will not be described herein.
Fig. 4 is a schematic structural diagram of an apparatus according to an embodiment of the present application.
As shown in fig. 4, as another aspect, the present application also provides an apparatus 400 including one or more Central Processing Units (CPUs) 401, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 402 or a program loaded from a storage section 408 into a Random Access Memory (RAM) 403. In the RAM403, various programs and data required for the operation of the device 400 are also stored. The CPU401, ROM402, and RAM403 are connected to each other by a bus 404. An input/output (I/O) interface 405 is also connected to bus 404.
The following components are connected to the I/O interface 405: an input section 406 including a keyboard, a mouse, and the like; an output portion 407 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker, and the like; a storage section 408 including a hard disk or the like; and a communication section 409 including a network interface card such as a LAN card, a modem, or the like. The communication section 409 performs communication processing via a network such as the internet. The drive 410 is also connected to the I/O interface 405 as needed. A removable medium 411 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed on the drive 410 as needed, so that a computer program read therefrom is installed into the storage section 408 as needed.
In particular, according to embodiments of the present disclosure, the method described in any of the above embodiments may be implemented as a computer software program. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for performing any of the methods described above. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 409 and/or installed from the removable medium 411.
As still another aspect, the present application also provides a computer-readable storage medium, which may be a computer-readable storage medium contained in the apparatus of the above-described embodiment; or may be a computer-readable storage medium, alone, that is not assembled into a device. The computer-readable storage medium stores one or more programs for use by one or more processors to perform the methods described herein.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units or modules involved in the embodiments of the present application may be implemented in software or in hardware. The described units or modules may also be provided in a processor, for example, each of the units may be a software program provided in a computer or a mobile smart device, or may be separately configured hardware devices. Wherein the names of the units or modules do not in some cases constitute a limitation of the units or modules themselves.
The above description is only illustrative of the preferred embodiments of the present application and of the principles of the technology employed. It will be appreciated by persons skilled in the art that the scope of the application referred to in the present application is not limited to the specific combinations of the technical features described above, but also covers other technical features formed by any combination of the technical features described above or their equivalents without departing from the spirit of the application. Such as the above-mentioned features and the technical features disclosed in the present application (but not limited to) having similar functions are replaced with each other.