Disclosure of Invention
Aiming at the problems existing in the prior art, the embodiment of the invention provides a transaction verification method and device.
The embodiment of the invention provides a transaction verification method, which comprises the following steps:
in the process of the round of consensus based on a consensus algorithm, predicting the next proposal node of the current proposal node, and acquiring packaging information of the next proposal node; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node;
and in the non-consensus voting stage, carrying out transaction verification on the next proposal node according to the transaction set.
The obtaining the package information of the next proposal node includes:
and controlling the next proposal node to broadcast the packaging information so as to enable an executive party of the transaction verification method to acquire the packaging information.
The packaging information further comprises voting information corresponding to a proposal block of the current proposal node; correspondingly, the obtaining the package information of the next proposal node includes:
and controlling a next proposal node to receive the proposal block, checking the proposal block by the next proposal node, determining the voting information according to a checking result, and broadcasting packaging information carrying the voting information and the transaction set so as to enable an executive party of the transaction verification method to acquire the packaging information.
Wherein, after the step of transaction verification on the next proposal node, the transaction verification method further comprises:
and caching the transaction verification result, and executing corresponding processing actions according to the round block output result.
The executing corresponding processing actions according to the round block output result comprises the following steps:
if the block output result of the round is that the block output is unsuccessful, deleting the cached transaction verification result;
if the block output result of the current round is successful, determining the next proposal node as the current proposal node, and continuously executing the step of predicting the next proposal node of the current proposal node until all round consensus is completed.
Wherein the non-consensus voting phase comprises:
a consensus wait phase or an account book write wait IO phase.
The embodiment of the invention provides a transaction verification device, which comprises:
the acquisition unit is used for predicting the next proposal node of the current proposal node in the process of the round of consensus based on a consensus algorithm and acquiring packaging information of the next proposal node; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node;
and the transaction verification unit is used for carrying out transaction verification on the next proposal node according to the transaction set in the non-consensus voting stage.
The acquiring unit is specifically configured to:
and controlling the next proposal node to broadcast the packaging information so as to enable an executive party of the transaction verification method to acquire the packaging information.
An embodiment of the present invention provides an electronic device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein,
the processor performs the following method steps when executing the program:
in the process of the round of consensus based on a consensus algorithm, predicting the next proposal node of the current proposal node, and acquiring packaging information of the next proposal node; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node;
and in the non-consensus voting stage, carrying out transaction verification on the next proposal node according to the transaction set.
Embodiments of the present invention provide a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the method steps of:
in the process of the round of consensus based on a consensus algorithm, predicting the next proposal node of the current proposal node, and acquiring packaging information of the next proposal node; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node;
and in the non-consensus voting stage, carrying out transaction verification on the next proposal node according to the transaction set.
According to the transaction verification method and device provided by the embodiment of the invention, the packaging information of the next proposal node of the current proposal node is obtained in the current consensus process, and the transaction verification is carried out on the next proposal node in the non-consensus voting stage according to the transaction set of the next proposal node in the packaging information, so that the consensus efficiency can be improved.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Fig. 2 is a flowchart of an embodiment of a transaction verification method according to the present invention, as shown in fig. 2, and the transaction verification method according to the embodiment of the present invention includes the following steps:
s201: in the process of the round of consensus based on a consensus algorithm, predicting the next proposal node of the current proposal node, and acquiring packaging information of the next proposal node; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node.
Specifically, in the process of the round of consensus based on a consensus algorithm, predicting the next proposal node of the current proposal node, and acquiring packaging information of the next proposal node; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node. The method steps may be performed by a computer device, in particular a terminal, i.e. a consensus node. The embodiment of the invention is realized based on BFT type consensus algorithm, and the specific flow is as follows:
1) The consensus node (may be all consensus nodes) receives the proposal block of the current proposal node, with the block number N.
2) The consensus node predicts the next proposed block VPN, i.e. generates block information with block number n+1.
3) Controlling the VPN node to receive the proposal block N, checking the proposal block N by the VPN node, and determining voting information according to the checking result, namely if the block information of the proposal block N is wrong, the voting information is an anti-vote; if the block information of the proposed block N is correct, the voting information is an approval vote.
4) And controlling the VPN node to package the transaction set of the VPN and the voting information, and broadcasting the package information to a consensus network (similar to an ack reply mode of a tcp protocol) so that the consensus node can acquire the package information.
5) When the consensus node receives the package information broadcast by the VPN, the verification work of the transaction set can be immediately performed, the transaction verification result is cached, the verification work can be performed in a non-consensus voting stage in the round of consensus process, and the transaction verification is performed on the VPN according to the transaction set. That is, the verification work and the consensus work are performed in parallel, and the non-consensus voting stage may include a consensus waiting stage, a ledger writing waiting IO stage, or the like, without being limited in particular.
6) And if the block-out result of the round is that the block-out is unsuccessful, deleting the cached transaction verification result.
7) If the block-out result of the round is that the block-out is successful, determining the next proposal node as the current proposal node, and continuing to execute the step of predicting the next proposal node of the current proposal node until all round consensus is completed, namely, the consensus node can predict the proposal node of the (n+2) block, and repeating the step 2).
It should be noted that, the above-mentioned package information may also not include the above-mentioned voting information, and correspondingly, the method may include: and controlling the next proposal node to broadcast the packaging information so as to enable an executive party of the transaction verification method to acquire the packaging information.
S202: and in the non-consensus voting stage, carrying out transaction verification on the next proposal node according to the transaction set.
Specifically, in the non-consensus voting stage, according to the transaction set, transaction verification is performed on the next proposal node. The non-consensus voting phase may refer to the above description, and transaction verification may specifically include signature verification, integrity verification, etc., without limitation.
Fig. 3 is a schematic diagram of each round of unchanged proposal nodes in the embodiment of the invention, and fig. 4 is a schematic diagram of each round of changed proposal nodes in the embodiment of the invention, as shown in fig. 3 and fig. 4, the embodiment of the invention has the following beneficial effects:
1) And the consensus efficiency is improved, and the transaction verification time is reduced. The technical scheme can start to verify the next round of block transaction set in a round of consensus.
2) And the resource utilization rate is improved. During the voting waiting period and the account book writing period, the CPU resource is in an idle state, and the operation of consuming the CPU resource such as signature verification is performed by utilizing the time.
The embodiment of the invention is particularly suitable for the following application scenes:
the transaction is more in the block, the logic is complex and the transaction verification speed of the consensus node is low.
According to the transaction verification method provided by the embodiment of the invention, the packaging information of the next proposal node of the current proposal node is obtained in the current round of consensus, and the transaction verification is carried out on the next proposal node in the non-consensus voting stage according to the transaction set of the next proposal node in the packaging information, so that the consensus efficiency can be improved.
On the basis of the foregoing embodiment, the obtaining the package information of the next proposal node includes:
specifically, the next proposal node is controlled to broadcast the packaging information so that an executive party of the transaction verification method can acquire the packaging information. Reference is made to the above description and will not be repeated.
The transaction verification method provided by the embodiment of the invention can efficiently acquire the packaging information of the next proposal node, and is beneficial to further improving the consensus efficiency.
On the basis of the above embodiment, the package information further includes voting information corresponding to a proposal block of the current proposal node; correspondingly, the obtaining the package information of the next proposal node includes:
specifically, the next proposal node is controlled to receive the proposal block, the proposal block is checked by the next proposal node, the voting information is determined according to the checking result, and package information carrying the voting information and the transaction set is broadcasted so that an executive party of the transaction verification method can acquire the package information. Reference is made to the above description and will not be repeated.
According to the transaction verification method provided by the embodiment of the invention, the voting information is carried in the packaging information, so that the communication message carrying the voting information is prevented from being independently sent, and the communication resource can be saved.
On the basis of the above embodiment, after the step of performing transaction verification on the next proposal node, the transaction verification method further includes:
specifically, the transaction verification result is cached, and corresponding processing actions are executed according to the round block output result. Namely, executing corresponding processing actions according to the round block-out result specifically comprises: the above-mentioned case that the block-out result of this round is that the block-out is unsuccessful and the block-out result of this round is that the block-out is successful is not repeated.
The transaction verification method provided by the embodiment of the invention further optimizes the execution process of the method.
On the basis of the above embodiment, the performing corresponding processing actions according to the present round of block output result includes:
specifically, if the block-out result of the round is that the block-out is unsuccessful, deleting the cached transaction verification result; reference is made to the above description and will not be repeated.
Specifically, if the block output result of the current round is that the block output is successful, determining that the next proposed node is the current proposed node, and continuing to execute the step of predicting the next proposed node of the current proposed node until all round consensus is completed. Reference is made to the above description and will not be repeated.
The transaction verification method provided by the embodiment of the invention can delete the information in the cache in time on one hand, and can realize the rapid loop iteration of the method on the other hand, thereby further improving the consensus efficiency.
Based on the above embodiment, specifically, the non-consensus voting phase includes:
a consensus wait phase or an account book write wait IO phase.
According to the transaction verification method provided by the embodiment of the invention, the transaction verification is carried out on the next proposal node in the consensus waiting stage or the account book writing waiting IO stage, so that the parallel execution of the transaction verification and consensus is realized, and the consensus efficiency is further improved.
Fig. 5 is a schematic structural diagram of an embodiment of a transaction verification device according to the present invention, as shown in fig. 5, the embodiment of the present invention provides a transaction verification device, which includes an obtaining unit 501 and a transaction verification unit 502, wherein:
the obtaining unit 501 is configured to predict a next proposal node of a current proposal node and obtain packaging information of the next proposal node in a local consensus process based on a consensus algorithm; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node; the transaction verification unit 502 is configured to perform transaction verification on the next proposal node according to the transaction set in the non-consensus voting stage.
Specifically, the obtaining unit 501 is configured to predict a next proposal node of a current proposal node and obtain package information of the next proposal node in a local consensus process based on a consensus algorithm; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node; the transaction verification unit 502 is configured to perform transaction verification on the next proposal node according to the transaction set in the non-consensus voting stage.
According to the transaction verification device provided by the embodiment of the invention, the packaging information of the next proposal node of the current proposal node is obtained in the course of the current consensus, and the transaction verification is carried out on the next proposal node in the non-consensus voting stage according to the transaction set of the next proposal node in the packaging information, so that the consensus efficiency can be improved.
On the basis of the above embodiment, the acquiring unit specifically 501 is configured to:
and controlling the next proposal node to broadcast the packaging information so as to enable an executive party of the transaction verification method to acquire the packaging information.
The transaction verification device provided by the embodiment of the invention can efficiently acquire the packaging information of the next proposal node, and is beneficial to further improving the consensus efficiency.
The transaction verification device provided in the embodiment of the present invention may be specifically used to execute the processing flow of each method embodiment, and the functions thereof are not described herein again, and reference may be made to the detailed description of the method embodiments.
Fig. 6 is a schematic diagram of an entity structure of an electronic device according to an embodiment of the present invention, as shown in fig. 6, where the electronic device includes: a processor (processor) 601, a memory (memory) 602, and a bus 603;
wherein, the processor 601 and the memory 602 complete communication with each other through the bus 603;
the processor 601 is configured to invoke program instructions in the memory 602 to perform the methods provided in the above method embodiments, for example, including: in the process of the round of consensus based on a consensus algorithm, predicting the next proposal node of the current proposal node, and acquiring packaging information of the next proposal node; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node; and in the non-consensus voting stage, carrying out transaction verification on the next proposal node according to the transaction set.
The present embodiment discloses a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, are capable of performing the methods provided by the above-described method embodiments, for example comprising: in the process of the round of consensus based on a consensus algorithm, predicting the next proposal node of the current proposal node, and acquiring packaging information of the next proposal node; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node; and in the non-consensus voting stage, carrying out transaction verification on the next proposal node according to the transaction set.
The present embodiment provides a non-transitory computer-readable storage medium storing computer instructions that cause a computer to perform the methods provided by the above-described method embodiments, for example, including: in the process of the round of consensus based on a consensus algorithm, predicting the next proposal node of the current proposal node, and acquiring packaging information of the next proposal node; the consensus algorithm is a BFT-type consensus algorithm of a predictable proposal node, and the packaging information at least comprises a transaction set of the next proposal node; and in the non-consensus voting stage, carrying out transaction verification on the next proposal node according to the transaction set.
Those of ordinary skill in the art will appreciate that: all or part of the steps for implementing the above method embodiments may be implemented by hardware associated with program instructions, where the foregoing program may be stored in a computer readable storage medium, and when executed, the program performs steps including the above method embodiments; and the aforementioned storage medium includes: various media that can store program code, such as ROM, RAM, magnetic or optical disks.
The apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the respective embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.