This application relates to the technical field of computers, including to block chain-based block consensus.
With rapid development of network technology and attention given to data security by governments and enterprises, block chain has received greater attention and has been widely applied. Before a node in the block chain writes a proposal block in the block chain, it is needed to respectively verify the proposal block at first through validator nodes in a consensus network, so as to achieve consensus on the proposal block.
In the related art, a Tendermint (a protocol of byzantine fault tolerant type) consensus protocol is often adopted for block consensus. In the Tendermint consensus protocol, before a proposal block enters a commit phase, it is needed to perform two rounds of voting through the consensus network. Each round of voting needs to be recognized by two-thirds or above of the validator nodes in the consensus network to complete block consensus, and the proposal block enters the commit phase and then executes a contract to obtain a contract execution result. During each round of voting, each validator node needs to broadcast voting information in the consensus network, the consensus phase needs to consume a period of time due to network delay, and execution of the contract will also consume a substantial amount of time. Therefore, the proposal block needs to complete block consensus and then executes the contract. The whole course can take a long time, which results in a low throughput of the block chain.
Embodiments of this disclosure provide a block chain-based block consensus method and a related device. The time consumed by block chaining can be shortened and the throughput of the block chain can be improved.
On the one hand, the embodiments of this disclosure provide a block chain-based block consensus method. The method may be executed by a computer device, for example. In the method, a proposal block generated in an Nth round with a block height of M is acquired, and validity verification is performed on the proposal block. M and N are both positive integers. An application is executed based on transaction data in the proposal block to obtain a target execution result. A block hash of the proposal block and the target execution result are stored in a memory. The memory includes N execution results with the block height of M. The N execution results include the target execution result. While the application is executed based on the transaction data, two rounds of consensus voting processing are performed on the proposal block to obtain a first consensus result. Based on the first consensus result being a consensus pass result, the target execution result mapped by the block hash of the proposal block in the memory is acquired, and the proposal block and the target execution result are stored to a block chain.
On the one hand, the embodiments of this disclosure provide a block chain-based block consensus apparatus that includes processing circuitry. The apparatus may be deployed on a computer device, for example. The processing circuitry is configured to acquire a proposal block generated in an Nth round with a block height of M, and perform validity verification on the proposal block, M and N both being positive integers. The processing circuitry is configured to execute an application based on transaction data in the proposal block to obtain a target execution result, and store a block hash of the proposal block and the target execution result in a memory. The memory includes N execution results with the block height of M. The N execution results include the target execution result. The processing circuity is configured to, while the application is executed based on the transaction data, perform two rounds of consensus voting processing on the proposal block to obtain a first consensus result. Further, the processing circuitry is configured to, based on the first consensus result being a consensus pass result, acquire the target execution result mapped by the block hash of the proposal block in the memory, and store the proposal block and the target execution result to a block chain.
According to another aspect of the embodiments of this disclosure, a computer device is provided, including: a processor and a memory. The processor is connected to the memory, the memory being configured to store a computer program, and the computer program, when executed by the processor, causing the computer device to perform any of the methods according to the embodiments of this disclosure.
According to another aspect of the embodiments of this disclosure, a non-transitory computer-readable storage medium is provided, storing instructions which when executed by a processor cause the processor to perform any of the methods according to the embodiments of this disclosure.
According to another aspect of the embodiments of this disclosure, a computer program product or a computer program is provided, the computer program product or the computer program including computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, to cause the computer device to perform any of the methods according to the embodiments of this disclosure.
In an embodiment of this disclosure, after the proposal block generated in the Nth round with the block height of M is acquired, the transaction data in the proposal block is executed through the smart contract to obtain the target contract execution result, and the block hash of the proposal block and the target contract execution result are cached to the temporary list in the associated manner; in the process of executing the transaction data through the smart contract, two rounds of consensus voting processing are performed on the proposal block to obtain the first consensus result; and in a case that the first consensus result is a consensus pass result, the target contract execution result mapped by the block hash of the proposal block is acquired in the temporary list, and the proposal block and the target contract execution result are stored to a block chain in the associated manner. M and N both are positive integers. The temporary list includes N contract execution results with the block height of M, and the N contract execution results includes the target contract execution result. By adopting the method provided by the embodiments of this disclosure, execution of the contract and two rounds of voting of the block are parallelly processed, so that the time of storing the proposal block passing consensus and the target contract execution result to the block chain in the associated manner can be shortened, that is, the chaining efficiency of the block is improved, and therefore, the throughput of the chain block can be effectively improved.
To describe technical solutions of embodiments of this disclosure more clearly, the following briefly introduces the accompanying drawings for describing the embodiments. The accompanying drawings in the following description show only some embodiments of this disclosure. Other embodiments are within the scope of the present disclosure.
Technical solutions in exemplary embodiments of this disclosure are described below with reference to the accompanying drawings in the embodiments of this disclosure. The described embodiments are merely some rather than all of the embodiments of this disclosure. Other embodiments are within the scope of this disclosure.
Referring to
It is to be understood that a block is a data packet that carries transaction data (that is, transaction) on the block chain network, and is a data structure identified by a timestamp and a hash value of a previous block. The block is verified through the consensus mechanism of the network and transaction in the block is determined.
It is to be understood that the block chain system can include a smart contract. The smart contract can refer to a code capable of being understood and executed by each node (including the validator node) of the block chain, can execute any logic and obtain a result. It is to be understood that the block chain can include one or more smart contracts, and these smart contracts can be differentiated through identity documents (ID) or names. A transaction request can carry the IDs or names of the smart contracts, thereby appointing the smart contracts needed to be operated by the block chain.
The block chain node system shown in
It is to be understood that the nodes can transmit data or blocks through the above-mentioned data connections. The block chain network can realize the data connection among the nodes based on node identifiers. Each node in the block chain network has a corresponding node identifier. Each of the above-mentioned nodes can store the node identifiers of other nodes having connecting relations with the node, so that the acquired data or the generated blocks can be broadcasted to other nodes subsequently according to the node identifiers of other nodes. For example, the node 10a can maintain a node identifier list as shown in Table 1, and the node identifier list stores the node names and the node identifiers of other nodes.
The node identifier can be an Internet protocol (IP) address and any other type of information that can be used for identifying the node in the block chain network. Table 1 only uses the IP address as an example for description. For example, the node 10a can transmit information (for example, block) to the node 10b through the node identifier 117.116.189.145, and the node 10b can determine that the information is transmitted by the node 10a through the node identifier
It is to be understood that the above-mentioned data connection does not define the connecting mode, and the above-mentioned data connection can be a direct or indirect connection by way of wired communication, or direct or indirect connection by way of wireless communication, or connection by other connecting modes, which is not limited in this disclosure.
It is to be understood that the block consensus method provided by the embodiments of this disclosure can be executed by a computer device, and the computer device includes, but is not limited to, the above-mentioned validator nodes (the validator nodes can be terminals or servers). The server may be an independent physical server, or may be a server cluster comprising a plurality of physical servers or a distributed system, or may be a cloud server providing basic cloud computing services, such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a network service, cloud communication, a middleware service, a domain name service, a security service, a content delivery network (CDN), big data, and an artificial intelligence platform. The terminal may be a smartphone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smartwatch, or the like, but is not limited thereto.
As shown in
In one round of consensus, a certain node in the validator nodes can be taken as a proposer node to generate the proposal block, and the proposal block is respectively transmitted to other validator nodes in the block chain node system according to the node identifiers of other validator nodes in the block chain node system. Upon receiving the proposal block, each validator node will verify the validity of the proposal block. If the proposal block is valid, the validator node will execute the transaction data in the proposal block according to the smart contract to obtain the target contract execution result, and then cache the target contract execution result; in the process of executing the transaction data through the smart contract, the validator nodes will perform two rounds of consensus voting processing on the proposal block. If two-thirds or above of the validator nodes vote affirmative votes to the proposal block in both of the two rounds of consensus voting processing, it is considered that consensus passes. Then the validator nodes will add the proposal block and the target contract execution result together to the block chain stored thereby. The proposer node is also the validator node, and also needs to perform two rounds of consensus voting processing on the proposal block.
For example, description is made in a case that the proposer node is the node 10a, the node 10a generates the proposal block, and then the node 10a broadcasts the proposal block to other validator nodes, that is, the node 10b, the node 10c and the node 10d, and the nodes jointly perform consensus on the proposal block.
To facilitate understanding, further, referring to
As shown in
As shown in
Referring to
In step S101, a proposal block generated in an Nth round with a block height of M is acquired, M and N both being positive integer.
It is to be understood that the proposal block can also be referred to as an alternative block or a to-be-chained block, which is a block containing transaction data corresponding to each transaction and is assembled and generated after the proposer node monitors and collects all transactions of the whole network within a period of time. The proposer node can be held by a certain validator node in the consensus network and is responsible for proposing the alternative block and broadcasting the alternative block in the network. The proposal block cannot be directly stored to the block chain, needs to be subjected to consensus verification of the consensus network at first, can be chained after consensus passes, and is then connected to a previous block stored in the block chain. Therefore, in short, the block chain is a chain formed by linking the proposal blocks one by one after consensus passes.
Block height is an identifier of the block and is used for measuring a distance from a certain block to the first block in the block chain. The position of the certain block on the chain can be accurately known through the block height, which is equivalent to position a coordinate for the block. Assuming that there are five blocks in the block chain, the block height of the first block is 0, the block height of the second block is 1, . . . and by parity of reasoning, the block height of the fifth block is 4. At the moment, the corresponding block height of the proposal block as a new block prepared to be added into the block chain is 5. As described above, the proposal block cannot be directly stored to the block chain and only can be added into the block chain after block consensus passes. Block consensus can be vote type consensus, that is, after the proposer node in the consensus network generates the proposal block, the validator nodes perform the process of two rounds of consensus voting for the proposal block. For example, block consensus uses a Tendermint consensus algorithm, in a case that two-thirds or above of the validator nodes in both of the two rounds of consensus voting vote for the affirmative votes for the proposal block, it can be considered that consensus for the proposal block passes; and in a case that there are not two-thirds or above of the validator nodes in one of the two rounds of consensus voting vote for the affirmative votes for the proposal block, it can be considered that consensus for the proposal block fails, and the proposal block cannot be stored to the block chain. Assuming that the proposal block with the block height of 5 fails in consensus, a new validator node will be elected in the consensus network to serve as a new proposer node, then the new proposer node will generate a new proposal block, and the consensus network will perform block consensus for the new proposal block. It is to be understood that the block height of the new proposal block is still 5. For differentiation, the proposal block failing in consensus can be referred to as the proposal block generated in the first round with the block height of 5, and the new proposal block is referred to as the proposal block generated in the second round with the block height of 5. In a case that the proposal block generated in the second round with the block height of 5 still fails in consensus, a next proposal block is the proposal block generated in the third round with the block height of 5. The proposer node in each round is elected by an election algorithm (for example, generated in turn) and is not always constant.
In one possible implementation, after receiving the proposal block, the validator nodes will perform validity verification on the proposal block to obtain the validity verification result. Validity verification can be either verification of identity of the proposer node or verification of content of the proposal block.
In one embodiment, to perform validity verification on the proposal block to obtain the validity verification result the validator node may acquire the transaction data in the proposal block, and perform hash operation on the transaction data to obtain a to-be-verified hash value; perform hash operation on the to-be-verified hash value according to a Merkle tree path in the proposal block to obtain a to-be-verified tree root hash value; acquire a Merkle tree root hash value from a header of the proposal block; in a case that the to-be-verified tree root hash value is identical with the Merkle tree root hash value, determine that the validity verification result of the proposal block is a valid result; and in a case that the to-be-verified tree root hash value is not identical with the Merkle tree root hash value, determine that the validity verification result of the proposal block is an invalid result. The hash value is also referred to as an information characteristic value or a characteristic value. The hash value is generated by converting input data of any length into a code through a hash algorithm and fixedly outputting the code. Original input data cannot be retrieved by decrypting the hash value, and it is a unidirectional encryption function. The Merkle tree is composed of a root node, a group of intermediate nodes and a group of leaf nodes. The leaf nodes include storage data or hash values thereof, the intermediate nodes are hash values of contents of two child nodes thereof, and the root node is composed of hash values of contents of two sub nodes thereof. Therefore, the Merkle tree is also referred to as a hash tree.
For the convenience of understanding, referring to
In one embodiment, to perform validity verification on the proposal block to obtain the validity verification result the validator node may acquire the transaction data in the proposal block; call a transaction verification function to verify the transaction data to obtain a transaction verification result; in a case that the transaction verification result is a valid result, determine that the validity verification result of the proposal block is a valid result; and in a case that the transaction verification result is an invalid result, determine that the validity verification result of the proposal block is an invalid result. The transaction verification function is set according to a calibration standard rule, for example a Check function. Through the Check function, whether grammar of the data structure of the block is valid, whether the block size is within a length limit range, whether the timestamp of the block is two hours early than a verification moment in the future and whether the signature data in the block is less than the upper limit of the signature operation can be verified. In a case that the data format, size, signature and the like of the block comply with the calibration standard rule, the Check function can return 0, i.e., a valid transaction verification result, and at the moment, the validator node will determine that the validity verification result of the proposal block is the valid result, and in a case that the Check function is called to return other values, the validator node will determine that the validity verification result of the proposal block is the invalid result.
In one embodiment, to perform validity verification on the proposal block to obtain the validity verification result the validatory node may acquire a block hash of a parent block of the proposal block in the block chain as a target parent block hash; acquire a parent block hash from the header of the proposal block as a to-be-verified parent block hash; in a case that the to-be-verified parent block hash is identical with the target parent block hash, determine that the validity verification result of the proposal block is a valid result; and in a case that the to-be-verified parent block hash is not identical with the target parent block hash, determine that the validity verification result of the proposal block is an invalid result. The block hash is also an identifier of the block and is calculated through the hash algorithm after splicing three fields of the parent block hash, the block content and the block creation time. The parent block is the previous block of a certain block in the block chain. For example, the parent block of the block with the block height of 5 is the block with the block height of 4.
In one embodiment, to perform validity verification of the proposal block to obtain the validity verification result the validator node may acquire signature data associated with the proposal block; acquire a public key of the proposer node, and verify the signature data through the public key to obtain a signature verification result; in a case that the signature verification result shows successful signature verification, determine that the validity verification result of the proposal block is a valid result; and in a case that the signature verification result shows failed signature verification, determine that the validity verification result of the proposal block is an invalid result. The signature data with successful signature verification is obtained by signing, by the proposer node, the proposal block through a possessed private key. The public key and the private key are commonly known asymmetrical encryption modes. The public key is for public, that is to say, other validator nodes can acquire the public key of the proposer node, while the private key is private, and other validator nodes cannot acquire the private key of the proposer node. The proposer node uses its own private key to process the proposal block. Since the private key is only possessed by the proposer node, documents which cannot be generated by other nodes are generated, that is, digital signatures are formed. In one round of validation, the validator node can know which is the proposer node that generates the proposal block in this round, acquire the public key of the proposer node and then decrypt the signature data through the public key, that is, signature verification. Successful signature verification indicates that the signature data is transmitted by the proposer node, the proposal block associated with the signature data is the proposal block generated by the proposer node in this round of validation rather than the proposal block mistakenly transmitted by other nodes or other invalid blocks, and it can be determined that the validity verification of the proposal block passes; and otherwise, it is determined that the validity verification of the proposal block fails.
The validity verification method for the proposal block mentioned in the above-mentioned one or more embodiments can be used while verifying the validity of the proposal block.
In step S102, transaction data in the proposal block is executed through a smart contract to obtain a target contract execution result, and a block hash of the proposal block and the target contract execution result is cached to a temporary list in an associated manner. In an example, an application is executed based on transaction data in the proposal block to obtain a target execution result, and a block hash of the proposal block and the target execution result are stored in a memory. The memory includes N execution results with the block height of M, the N execution results including the target execution result.
When it is necessary to perform validity verification on the proposal block to obtain the validity verification result, an implementation mode of S102 can be as follows: in a case that the validity verification result is the valid result, execute the transaction data in the proposal block through the smart contract to obtain the target contract execution result.
After acquiring the proposal block and verifying that the proposal block is valid, the validator node will call the transaction execution function in the smart contract for executing the transaction data, then acquire read data for the transaction data through the transaction execution function and then execute the transaction execution function through the read data and the transaction data to obtain the target contract execution result. Then the validator node will acquire the block hash of the proposal block and cache the block hash of the proposal block and the target contract execution result to the temporary list in the associated manner. The smart contract is a computer protocol intended to propagate, verify or execute a contract in an informatization mode. In the block chain system, the smart contract is a code capable of being understood and executed by each node of the block chain, can execute any logic and obtain a result. During actual application, the smart contract is managed and tried through transaction on the block chain. The transaction data corresponding to each transaction is equivalent to a remote procedure call (RPC) request to the block chain system. In a case that the smart contract is equivalent to an executable program, the block chain is equivalent to an operating system that provides an operating environment. The block chain can include a plurality of contracts, and the contracts are differentiated with identities (ID), identity documents or names.
For the convenience of understanding, referring to
Then the validator node 50 can acquire historical transaction data for the transaction data according to the transaction execution function and determine the historical transaction data as the read data. As shown in
Taking the transaction 1 briefly as an example above, a relation among the transaction data, the read data and the transaction execution results is narrated, so that the transaction execution result 2 of the transaction 2 can be obtained according to the transaction 2, the read data 2 and the transaction execution function 2; the transaction execution result 3 of the transaction 3 can be obtained according to the transaction 3, the read data 3 and the transaction execution function 3; . . . ; and the transaction execution result n of the transaction n can be obtained according to the transaction n, the read data n and the transaction execution function n. The validator node will take the transaction execution result 1, the transaction execution result 2, the transaction execution result 3 . . . and the transaction execution result n as the target contract execution results, then establish an incidence relation between the target contract execution results and the block hash of the proposal block, and cache the incidence relation to the temporary list.
In the embodiments of this disclosure, the temporary list can further store the contract execution results corresponding to other proposal blocks, and how many proposal blocks in the proposal blocks generated in previous N rounds execute the transaction data, how many contract execution results can be obtained. In a case that the proposal blocks generated in previous N rounds all execute the transaction data, the temporary list includes N contract execution results with the block height of M, and the N contract execution results include the target contract execution result.
In step S103, in a process of executing the transaction data through the smart contract, two rounds of consensus voting processing are parallelly performed on the proposal block to obtain a first consensus result. In an example, while the application is executed based on the transaction data, two rounds of consensus voting processing are performed on the proposal block to obtain a first consensus result.
Contract execution and two rounds of consensus voting processing are performed parallelly, that is to say, when starting to perform consensus voting to the proposal block, the validator node simultaneously executes the transaction data through the smart contract. In the first round of consensus voting, the validator node performs prevote processing on the proposal block according to the validity verification result of the proposal block to obtain a prevote result; and in the second round of consensus voting, the validator node performs precommit processing on the proposal block according to the prevote result to obtain the first consensus result.
In the first round of consensus voting, to perform prevote processing on the proposal block according to the validity verification result of the proposal block to obtain a prevote result the validator node may in the first round of consensus voting, since the validator node has determined the validity of the proposal block, determine the first prevote result as a first affirmative result for the proposal block; broadcast the first prevote result to a plurality of target validator nodes; receive second prevote results respectively transmitted by the plurality of target validator nodes; determine the quantity of first affirmative votes and the quantity of first negative votes for the proposal block according to the first prevote result and the plurality of second prevote results; in a case that the quantity of first affirmative votes exceeds a first prevote threshold, determine that the prevote result is a successful prevote result; and in a case that the quantity of first negative votes exceeds a second prevote threshold, determine that the prevote result is a failed prevote result. There is the first affirmative result for the proposal block in the plurality of second prevote results, or there is a first negative result for the proposal block in the plurality of second prevote results. The first prevote threshold can be two-thirds of the total quantity of the validator nodes in the consensus network, for example, if the total quantity of the validator nodes is 30, the first prevote threshold can be 20; and the second prevote threshold can be one-third of the total quantity of the validator nodes in the consensus network, for example, if the total quantity of the validator nodes is 30, the second prevote threshold can be 10.
In the second round of consensus voting, to perform precommit processing on the proposal block according to the prevote result to obtain the first consensus result the validator node may in a case that the validator node determines that the prevote result is the successful prevote result in the first round of consensus voting, determine a first precommit result as a second affirmative result for the proposal block; otherwise, the validator node determines the first precommit result as a second negative result for the proposal block; then the validator node will broadcast the first precommit result to the plurality of target validator nodes; meanwhile, the validator node will receive second precommit results respectively transmitted by the plurality of target validator nodes; determine the quantity of second affirmative votes and the quantity of second negative votes for the proposal block according to the first precommit result and the plurality of second precommit results; in a case that the quantity of second affirmative votes exceeds a first precommit threshold, determine that the first consensus result is a consensus pass result; and in a case that the quantity of second negative votes exceeds a second precommit threshold, determine that the first consensus result is a consensus fail result. There is the second affirmative result for the proposal block in the plurality of second precommit results, or there is a second negative result for the proposal block in the plurality of second precommit results. The first precommit threshold can be two-thirds of the total quantity of the validator nodes in the consensus network, for example, if the total quantity of the validator nodes is 30, the first precommit threshold can be 20; and the second precommit threshold can be one-third of the total quantity of the validator nodes in the consensus network, for example, if the total quantity of the validator nodes is 30, the second precommit threshold can be 10.
For the convenience of understanding, referring to
As shown in
Under a possible circumstance, in the above-mentioned two rounds of consensus voting processes, when receiving the second prevote results or the second precommit results of the rest of validator nodes by the validator node 60, the validator node 60 can receive the second prevote results of the rest of validator nodes asynchronously due to reasons of distances between the validator node 60 and the rest of validator nodes and network speed and the like. For example, the validator node 60 can receive the second prevote result transmitted by the validator node 61 10 s after receiving the second prevote result of the validator node 62; and the second precommit result is in the similar way. Therefore, during two rounds of consensus voting processing, the validator node can persistently count the quantities of the affirmative votes or the negative votes according to obtained voting results. As long as the quantity of the affirmative votes reaches two-thirds of the total quantity of the validator nodes, a next action can be performed without waiting for receiving the voting results of all the validator nodes.
In step S104, in a case that the first consensus result is a consensus pass result, the target contract execution result mapped by the block hash of the proposal block in the temporary list is acquired, and the proposal block and the target contract execution result are stored to a block chain in an associated manner. In an example, based on the first consensus result being a consensus pass result, the target execution result mapped by the block hash of the proposal block in the memory is acquired, and the proposal block and the target execution result are stored to a block chain.
After consensus of the proposal block passes, the validator node can acquire the mapped target contract execution result in the temporary list according to the block hash of the proposal block, and then store the proposal block and the target contract execution result to the block chain in an associated manner.
Through the method provided by the embodiments of this disclosure, the validator node acquires the proposal block, then verifies that the proposal block is valid, performs contract execution in the proposal block and consensus voting processing of the proposal block at the same time, and cache the target contract execution result obtained by contract execution to the temporary list. If the consensus result for the proposal block is the consensus pass result, the validator node acquires the target contract execution result cached in the temporary list and stores the target contract execution result together with the proposal block to the block chain. By adopting the method provided by the embodiments of this disclosure, the time consumed by block chaining is shortened and the throughput of the block chain is greatly improved.
Referring to
As shown in
It can be known from above that one or more rounds are needed in order to write the current block height in the block chain into a new block. One round includes four phases (steps): Propose, Execute contract, Prevote and Precommit. It can be understood that the Execute contract step and the Prevote and Precommit steps are executed parallelly. The whole block consensus process is composed of one or more rounds in addition to two special phases: Commit and NewHeight, as shown below:
NewHeight→Propose→(Execute contract)/(Prevote→Precommit)}+→Commit→NewHeight→ . . .
In one possible implementation, in a case that the validity verification result of the proposal block is the invalid result, that is, the proposal block is the invalid block, the validator node still performs two rounds of consensus voting processing on the proposal block to obtain a second consensus result; in a case that the second consensus result is the consensus pass result, the proposal block, with the block height of M, that has been stored to the block chain is synchronized from the completed validator node and the target contract execution result corresponding to the proposal block. The completed validator node is the target validator node that successfully stores the proposal block and the target contract execution result to the block chain.
In one possible implementation, in one round, the validator node has not received the proposal block timely due to problems of network and the like, the validator node, of course, will not wait all the time. Therefore, in response to not acquiring the proposal block generated in the Nth round with the block height of M within a verification time threshold, the validator node will construct a temporary empty block, and then performs two rounds of consensus voting processing for the temporary empty block to obtain a third consensus result. In a case that the third consensus result is the consensus pass result, and there is no transaction data in the empty block, the validator node will synchronize the proposal block, with the block height of M, that has been stored to the block chain from the completed validator node and the target contract execution result corresponding to the proposal block. The completed validator node is the target validator node that successfully stores the proposal block and the target contract execution result to the block chain. Through the method provided by the embodiments of this disclosure, the contract is executed when it is detected that the proposal block is the valid block, that is, the contract can be executed while broadcasting the prevote information and the precommit information. When the time of executing the contract is equivalent to the time of the two times of broadcasting, the time of executing the contract is equivalently saved, and therefore, the performance of the block chain is greatly improved.
Referring to
In one possible implementation, after committing the final proposal block with the block height of M, the validator node can delete N contract execution results with the block height of M in the temporary list.
In one possible implementation, the validator node may acquire the total quantity of all the contract execution results in the temporary list, and in a case that the total quantity is greater than or equal to a stored quantity threshold, delete all the contract execution results in the temporary list, where all the contract execution results include the contract execution results respectively corresponding to one or more block heights.
Through the method provided by the embodiments of this disclosure, the contract execution result corresponding to the proposal block is identified by using the block hash. Even if there are a plurality of corresponding proposal blocks with the same block height, when the final proposal block is finally committed, the temporarily cached contract execution result can be found according to the block hash of the final proposal block without storage disorder. Meanwhile, the cached contract execution result is deleted after the proposal block is committed, so that internal memory can be released, and the performance of the block chain is improved.
Referring to
The block verification module 11 is configured to acquire a proposal block generated in an Nth round with a block height of M, M and N both being positive integers.
The contract execution module 12 is configured to execute transaction data in the proposal block through a smart contract to obtain a target contract execution result, and cache a block hash of the proposal block and the target contract execution result to a temporary list in an associated manner; the temporary list including N contract execution results with the block height of M, the N contract execution results including the target contract execution result.
The first consensus module 13 is configured to, in a process of executing the transaction data through the smart contract, parallelly perform two rounds of consensus voting processing on the proposal block to obtain a first consensus result.
The first storage module 14 is configured to, in a case that the first consensus result is a consensus pass result, acquire the target contract execution result mapped by the block hash of the proposal block in the temporary list, and store the proposal block and the target contract execution result to a block chain in an associated manner.
For exemplary function implementations of the block verification module 11, the contract execution module 12, the first consensus module 13 and the first storage module 14, reference can be made to S101-S104 in the embodiment corresponding to
In one possible implementation, the block verification module 11 is further configured to perform validity verification on the proposal block to obtain a validity verification result.
The contract execution module 12 is configured to in a case that the validity verification result is a valid result, execute the transaction data in the proposal block through the smart contract to obtain the target contract execution result.
In one possible implementation, the temporary list stores the block hash of the proposal block and the target contract execution result through a key-value pair, the block hash of the proposal block being a key in the key-value pair and the target contract execution result being a value in the key-value pair.
Referring to
The hash operation unit 1111 is configured to acquire the transaction data in the proposal block, and perform hash operation on the transaction data to obtain a to-be-verified hash value.
The hash operation unit 1111 is further configured to perform hash operation on the to-be-verified hash value according to a Merkle tree path in the proposal block to obtain a to-be-verified tree root hash value.
The root hash acquisition unit 1112 is configured to acquire a Merkle tree root hash value from a header of the proposal block.
The first verification unit 1113 is configured to, in a case that the to-be-verified tree root hash value is identical with the Merkle tree root hash value, determine that the validity verification result of the proposal block is a valid result.
The first verification unit 1113 is further configured to, in a case that the to-be-verified tree root hash value is not identical with the Merkle tree root hash value, determine that the validity verification result of the proposal block is an invalid result.
For exemplary function implementations of the hash operation unit 1111, the root hash acquisition unit 1112 and the first verification unit 1113, reference can be made to the steps of performing validity verification on the proposal block to obtain the validity verification result in the embodiment corresponding to
Referring to
The transaction acquisition unit 1121 is configured to acquire the transaction data in the proposal block.
The transaction verification unit 1122 is configured to call a transaction verification function to verify the transaction data to obtain a transaction verification result.
The second verification unit 1123 is configured to, in a case that the transaction verification result is a valid result, determine that the validity verification result of the proposal block is a valid result.
The second verification unit 1123 is further configured to, in a case that the transaction verification result is an invalid result, determine that the validity verification result of the proposal block is an invalid result.
For exemplary function implementations of the transaction acquisition unit 1121, the transaction verification unit 1122 and the second verification unit 1123, reference can be made to the steps of performing validity verification on the proposal block to obtain the validity verification result in the embodiment corresponding to
Referring to
The first hash acquisition unit 1131 is configured to acquire a block hash of a parent block of the proposal block in the block chain as a target parent block hash.
The second hash acquisition unit 1132 is further configured to acquire a parent block hash from the header of the proposal block as a to-be-verified parent block hash.
The third verification unit 1133 is configured to, in a case that the to-be-verified parent block hash is identical with the target parent block hash, determine that the validity verification result of the proposal block is a valid result.
The third verification unit 1133 is further configured to, in a case that the to-be-verified parent block hash is not identical with the target parent block hash, determine that the validity verification result of the proposal block is an invalid result.
For exemplary function implementations of the first hash acquisition unit 1131, the second hash acquisition unit 1132 and the third verification unit 1133, reference can be made to the steps of performing validity verification on the proposal block to obtain the validity verification result in the embodiment corresponding to
Referring to
The signature acquisition unit 1141 is configured to acquire signature data associated with the proposal block.
The signature verification unit 1142 is configured to acquire a public key of a proposer node, and verify the signature data through the public key to obtain a signature verification result.
The fourth verification unit 1143 is configured to, in a case that the signature verification result shows successful signature verification, determine that the validity verification result of the proposal block is a valid result; the signature data with successful signature verification being obtained by signing, by the proposer node, the proposal block through a possessed private key; and the proposal block associated with the signature data with successful signature verification being generated by the proposer node.
The fourth verification unit 1143 is further configured to, in a case that the signature verification result shows failed signature verification, determine that the validity verification result of the proposal block is an invalid result.
For exemplary function implementations of the signature acquisition unit 1141, the signature verification unit 1142 and the fourth verification unit 1143, reference can be made to the steps of performing validity verification on the proposal block to obtain the validity verification result in the embodiment corresponding to
Referring to
The first acquisition unit 121 is configured to acquire the transaction data in the proposal block, and call a transaction execution function for executing the transaction data in the smart contract.
The second acquisition unit 122 is configured to acquire read data for the transaction data according to the transaction execution function.
The result acquisition unit 123 is configured to execute the transaction execution function according to the read data and the transaction data to obtain the target contract execution result of the transaction data.
The caching unit 124 is configured to cache the block hash of the proposal block and the target contract execution result to the temporary list in an associated manner.
For exemplary function implementations of the first acquisition unit 121, the second acquisition unit 122, the result acquisition unit 123 and the caching unit 124, reference can be made to S102 in the embodiment corresponding to
Referring to
The prevote unit 131 is configured to, in the first round of consensus voting, perform prevote processing on the proposal block according to the validity verification result of the proposal block to obtain a prevote result.
The precommit unit 132 is configured to, in the second round of consensus voting, perform precommit processing on the proposal block according to the prevote result to obtain the first consensus result.
For exemplary functional implementations of the prevote unit 131 and the precommit unit 132, reference can be made to S103 in the embodiment corresponding to
Referring to
The first determination subunit 1311 is configured to, in the first round of consensus voting, determine a first prevote result as a first affirmative result for the proposal block according to the valid result.
The first broadcasting subunit 1312 is configured to broadcast the first prevote result to a plurality of target validator nodes.
The first receiving subunit 1313 is configured to receive second prevote results respectively transmitted by the plurality of target validator nodes; there being the first affirmative result for the proposal block in the plurality of second prevote results or there being a first negative result for the proposal block in the plurality of second prevote results.
The first counting subunit 1314 is configured to determine the quantity of first affirmative votes and the quantity of first negative votes for the proposal block according to the first prevote result and the plurality of second prevote results.
The prevote processing subunit 1315 is configured to, in a case that the quantity of first affirmative votes exceeds a first prevote threshold, determine that the prevote result is a successful prevote result.
The prevote processing subunit 1315 is further configured to, in a case that the quantity of first negative votes exceeds a second prevote threshold, determine that the prevote result is a failed prevote result.
For exemplary function implementations of the first determination subunit 1311, the first broadcasting subunit 1312, the first receiving subunit 1313, the first counting subunit 1314 and the prevote processing subunit 1315, reference can be made to specific description in the embodiment corresponding to
Referring to
The second determination subunit 1321 is configured to, in a case that the prevote result is the successful prevote result, determine a first precommit result as a second affirmative result for the proposal block.
The second determination subunit 1321 is further configured to, in a case that the prevote result is the failed prevote result, determine the first precommit result as a second negative result for the proposal block.
The second broadcasting subunit 1322 is configured to broadcast the first precommit result to a plurality of target validator nodes.
The second receiving subunit 1323 is configured to receive second precommit results respectively transmitted by the plurality of target validator nodes; there being the second affirmative result for the proposal block in the plurality of second precommit results or there being a second negative result for the proposal block in the plurality of second precommit results.
The second counting subunit 1324 is configured to determine the quantity of second affirmative votes and the quantity of second negative votes for the proposal block according to the first precommit result and the plurality of second precommit results.
The precommit processing subunit 1325 is configured to, in a case that the quantity of second affirmative votes exceeds a first precommit threshold, determine that the first consensus result is a consensus pass result.
The precommit processing subunit 1325 is further configured to, in a case that the quantity of second negative votes exceeds a second precommit threshold, determine that the first consensus result is a consensus fail result.
For exemplary function implementations of the second determination subunit 1321, the second broadcasting subunit 1322, the second receiving subunit 1323, the second counting subunit 1324 and the precommit processing subunit 1325, reference can be made to specific description in the embodiment corresponding to
Referring to
The second consensus module 15 is configured to, in a case that the validity verification result of the proposal block is the invalid result, perform two rounds of consensus voting processing on the proposal block to obtain a second consensus result.
The second storage module 16 is configured to, in a case that the second consensus result is the consensus pass result, synchronize the proposal block, with the block height of M, that has been stored to the block chain from the completed validator node and the target contract execution result corresponding to the proposal block; the completed validator node being the target validator node that successfully stores the proposal block and the target contract execution result to the block chain.
For exemplary function implementations of the second consensus module 15 and the second storage module 16, reference can be made to specific description in the embodiment corresponding to
Referring to
The successful acquisition unit 1151 is configured to, in response to acquiring the proposal block generated in the Nth round with the block height of M within a verification time threshold, perform validity verification on the proposal block.
The block consensus apparatus 1 can further include: a failed acquisition module 17, a third consensus module 18 and a third storage module 19.
The failed acquisition module 17 is configured to, in response to not acquiring the proposal block generated in the Nth round with the block height of M within the verification time threshold, construct a temporary empty block.
The third consensus module 18 is configured to perform two rounds of consensus voting processing on the temporary empty block to obtain a third consensus result.
The third storage module 19 is configured to, in a case that the third consensus result is the consensus pass result, synchronize the proposal block, with the block height of M, that has been stored to the block chain from the completed validator node and the target contract execution result corresponding to the proposal block; the completed validator node being the target validator node that successfully stores the proposal block and the target contract execution result to the block chain.
For exemplary function implementations of the successful acquisition unit 1151, the failed acquisition module 17, the third consensus module 18 and the third storage module 19, reference can be made to specific description in the embodiment corresponding to
Referring to
The first deleting module 110 is configured to delete the N contract execution results with the block height of M in the temporary list.
The second deleting module 111 is configured to acquire the total quantity of all the contract execution results in the temporary list, and in a case that the total quantity is greater than or equal to a stored quantity threshold, delete all the contract execution results in the temporary list; all the contract execution results including contract execution results respectively corresponding to one or more block heights.
For exemplary function implementations of the first deleting module 110 and the second deleting module 111, reference can be made to specific description in the embodiment corresponding to
Referring to
In the computer device 1000 shown in
It is to be understood that the computer device 1000 described in this embodiment of this disclosure can implement the descriptions of the block chain-based block consensus method in the foregoing embodiment corresponding to
In addition, an embodiment of this disclosure further provides a computer-readable storage medium, such as a non-transitory computer-readable storage medium, and the computer-readable storage medium stores the computer program executed by the block chain-based block consensus apparatus 1 mentioned above. When loading and executing the computer program, the processor may perform the descriptions of the block chain-based block consensus method in any one of the foregoing embodiments. Therefore, details are not described herein again. In addition, the description of beneficial effects of the same method is not described herein again. For technical details that are not disclosed in the embodiments of the computer-readable storage medium of this disclosure, refer to the method embodiments of this disclosure.
The computer-readable storage medium may be a block consensus apparatus provided in any one of the foregoing embodiments or an internal storage unit of the computer device, for example, a hard disk or a main memory of the computer device. The computer-readable storage medium may alternatively be an external storage device of the computer device, for example, a removable hard disk, a smart memory card (SMC), a secure digital (SD) card, or a flash card equipped on the computer device. Further, the computer-readable storage medium may further include both an internal storage unit and an external storage device of the computer device. The computer-readable storage medium is configured to store the computer program and another program and data that are required by the computer device. The computer-readable storage medium may further be configured to temporarily store data that has been output or data to be output.
What is disclosed above is merely exemplary embodiments of this disclosure, and is not intended to limit the scope of this disclosure. Therefore, equivalent variations and other embodiments shall fall within the scope of this disclosure.
Number | Date | Country | Kind |
---|---|---|---|
202110273266.3 | Mar 2021 | CN | national |
The present application is a continuation of International Application No. PCT/CN2022/080103, entitled “BLOCK CONSENSUS METHOD BASED ON BLOCKCHAIN, AND RELATED DEVICE” and filed on Mar. 10, 2022, which claims priority to Chinese Patent Application No. 202110273266.3, entitled “BLOCK CHAIN-BASED BLOCK CONSENSUS METHOD AND RELATED DEVICE” and filed on Mar. 12, 2021. The entire disclosures of the prior applications are hereby incorporated by reference in their entirety.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2022/080103 | Mar 2022 | US |
Child | 18071271 | US |