Method and device for increasing block generation speed
Technical Field
The present invention relates to the field of financial technologies, and in particular, to a method and an apparatus for increasing block generation speed.
Background
In recent years, the blockchain technology is used as a bottom layer technology of bitcoin, is a distributed database and account book recording technology which is almost impossible to change, and is enabled to go to the center, record the sequence of transaction events on the basis of ensuring data security and have the characteristic of being not capable of being tampered, so that the blockchain technology is undergoing a rapid development stage.
The encryption digital currency system constructed by taking the block chain as the bottom layer technology has high data recording safety due to the distributed characteristic. However, each node has a complete account book, and each record needs to be traced back when confirming a transaction, so that performance problems occur when transaction data is excessively large as time advances, for example, all historical transaction records need to be downloaded for normal operation when the transaction is used for the first time, or each historical transaction needs to be traced back to calculate a balance in order to verify that the transaction has enough money. Moreover, the capacity of a single block is limited, and as the data stored in the block is increased, the efficiency is lower when the data is used for trading compared with the traditional central server or trading operator, and the demand for timely processing of large-batch trading orders cannot be met at present.
Disclosure of Invention
In view of the above problems, the present invention provides a method and an apparatus for increasing block generation speed, so as to achieve the purpose of increasing transaction efficiency of a block chain network.
In order to achieve the above object, according to a first aspect of the present invention, there is provided a method of increasing a block generation speed, the method including:
when the block stores data, transaction information is stored in a database, and the hash value is stored in the block;
establishing an index relation between the hash value and transaction information in the database;
and when the true existence of the transaction information is verified, downloading the transaction information to be verified for verification according to the index relation.
Preferably, when the transaction information is stored in the block, the method further comprises:
and extracting the transaction information from the block and storing the transaction information into a database.
Preferably, the establishing an index relationship between the hash value and the transaction information in the database includes:
setting the number of a block storing the hash value;
acquiring transaction information corresponding to the hash value in a database, and setting the number of the transaction information to be the same as the number of the block storing the hash value;
and establishing an index relationship between the transaction information with the same block number and the hash value stored in the block.
Preferably, when the true existence of the transaction information is verified, the downloading the transaction information to be verified for verification according to the index relationship includes:
when the true existence of the transaction information is verified, downloading the transaction information needing verification in the database;
acquiring a hash value corresponding to the transaction information to be verified according to the index relation;
and verifying the transaction information to be verified by verifying the hash value.
Preferably, the database is a local database or a remote database.
According to a second aspect of the present invention, there is provided an apparatus for increasing a block generation speed, the apparatus comprising:
the storage module is used for storing the transaction information into the database and storing the hash value into the block when the data is stored in the block;
the establishing module is used for establishing an index relation between the hash value and the transaction information in the database;
and the verification module is used for downloading the transaction information to be verified for verification according to the index relation when the true existence of the transaction information is verified.
Preferably, when the transaction information is stored in the block, the apparatus further comprises:
and the extraction module is used for extracting the transaction information from the block and storing the transaction information into a database.
Preferably, the establishing module includes:
a first setting unit configured to set a number of a block storing the hash value;
the second setting unit is used for acquiring transaction information corresponding to the hash value in a database and setting the number of the transaction information to be the same as the number of the block for storing the hash value;
and the establishing unit is used for establishing the index relationship between the transaction information with the same block number and the hash value stored in the block.
Preferably, the verification module includes:
the downloading unit is used for downloading the transaction information needing to be verified in the database when the authenticity of the transaction information is verified;
the acquisition unit is used for acquiring a hash value corresponding to the transaction information to be verified according to the index relation;
and the verification unit is used for verifying the hash value to realize the verification of the transaction information to be verified.
Compared with the prior art, the transaction information is stored in the database when the data is stored in the block, only the hash value is stored in the block, the capacity of the data stored in the block is reduced, the authenticity of the transaction information is verified when the transaction information is confirmed, the specific transaction information can be indexed through the hash value according to the index relation, only the transaction information to be verified needs to be downloaded, and verification is performed through the hash value, so that the downloading time is saved, confirmation events are reduced, the block generation speed is increased, and the transaction efficiency of the block chain network can be greatly improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a flowchart illustrating a method for increasing block generation speed according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of an apparatus for increasing block generation speed according to a second embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terms "first" and "second," and the like in the description and claims of the present invention and the above-described drawings are used for distinguishing between different objects and not for describing a particular order. Furthermore, the terms "comprising" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not set forth for a listed step or element but may include steps or elements not listed.
Example one
Fig. 1 is a flowchart illustrating a method for increasing block generation speed according to an embodiment of the present invention, the method including the following steps:
s11, when the block stores data, storing the transaction information into the database, and storing the hash value into the block;
it can be understood that, in the existing blockchain technology, transaction information and hash values are both stored in a block, which increases the capacity of the block, and in the embodiment of the present invention, the transaction information is stored in a database, and only key data, namely, the hash values, are stored in the block, which reduces the capacity of the block for storing data. Meanwhile, the database stored by the transaction information can be a local database or a foreign database.
Preferably, if the existing block in the block chain already stores the transaction information, the transaction information may also be extracted from the corresponding block, and the extracted transaction information is stored in the database.
S12, establishing an index relationship between the hash value and the transaction information in the database;
specifically, the specific method steps adopted for establishing the index relationship in the embodiment of the present invention are as follows:
setting the number of a block storing the hash value;
acquiring transaction information corresponding to the hash value in a database, and setting the number of the transaction information to be the same as the number of the block storing the hash value;
and establishing an index relationship between the transaction information with the same block number and the hash value stored in the block.
Correspondingly, other methods for establishing an index in the prior art may also be adopted, as long as the index relationship between the hash value and the transaction information in the database can be established, and the specific establishment method is not specifically limited in the present invention.
And S13, when the true existence of the transaction information is verified, downloading the transaction information to be verified for verification according to the index relation.
Specifically, the verification process includes:
when the true existence of the transaction information is verified, downloading the transaction information needing verification in the database;
acquiring a hash value corresponding to the transaction information to be verified according to the index relation;
and verifying the transaction information to be verified by verifying the hash value.
According to the technical scheme disclosed by the embodiment of the invention, the transaction information is stored in the database, only the hash value is stored in the block, the specific transaction information can be indexed through the hash value, and then the index relationship between the hash value and the transaction information in the database is established.
Example two
Corresponding to the method for increasing the block generation speed disclosed in the first embodiment of the present invention, a second embodiment of the present invention further provides a device for increasing the block generation speed, and fig. 2 is a schematic structural diagram of the device for increasing the block generation speed provided in the second embodiment of the present invention, where the device includes:
the storage module 1 is used for storing the transaction information into a database and storing the hash value into the block when the block stores data;
the establishing module 2 is used for establishing an index relationship between the hash value and the transaction information in the database;
and the verification module 3 is used for downloading the transaction information to be verified for verification according to the index relation when the true existence of the transaction information is verified.
Correspondingly, when the transaction information is stored in the block, the device further comprises:
and the extraction module is used for extracting the transaction information from the block and storing the transaction information into a database.
Specifically, the establishing module 2 includes:
a first setting unit 21 for setting the number of a block storing the hash value;
the second setting unit 22 is configured to acquire transaction information corresponding to the hash value in the database, and set the number of the transaction information to the same number as that of the block storing the hash value;
the establishing unit 23 is configured to establish an index relationship between the transaction information with the same block number and the hash value stored in the block.
Specifically, the verification module 3 includes:
the downloading unit 31 is used for downloading the transaction information needing to be verified in the database when the true existence of the transaction information is verified;
the obtaining unit 32 is configured to obtain, according to the index relationship, a hash value corresponding to the transaction information to be verified;
and the verification unit 33 is configured to verify the transaction information to be verified by verifying the hash value.
In the second embodiment of the invention, the transaction information is stored in the database through the storage module, and the hash value is stored in the block, so that the capacity of data stored in the block is reduced, as the specific transaction information can be indexed through the hash value, namely, the index relationship between the hash value and the transaction information in the database is established in the establishing module, when the authenticity of the transaction information is verified through the verifying module, only the transaction information to be verified needs to be downloaded, and the verification is carried out through the hash value, so that the downloading time is saved, the confirmation time is reduced, the block generation speed is increased, the transaction efficiency of the block chain network can be greatly increased, and the promotion effect on the promotion of the block chain network payment is also achieved.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.