CN112765271B - Block chain transaction index storage method and device, computer equipment and medium - Google Patents

Block chain transaction index storage method and device, computer equipment and medium Download PDF

Info

Publication number
CN112765271B
CN112765271B CN202011640211.3A CN202011640211A CN112765271B CN 112765271 B CN112765271 B CN 112765271B CN 202011640211 A CN202011640211 A CN 202011640211A CN 112765271 B CN112765271 B CN 112765271B
Authority
CN
China
Prior art keywords
transaction
database
target
sub
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011640211.3A
Other languages
Chinese (zh)
Other versions
CN112765271A (en
Inventor
邱炜伟
李伟
黄方蕾
胡麦芳
张珂杰
蔡亮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Qulian Technology Co Ltd
Original Assignee
Hangzhou Qulian Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Qulian Technology Co Ltd filed Critical Hangzhou Qulian Technology Co Ltd
Priority to CN202011640211.3A priority Critical patent/CN112765271B/en
Publication of CN112765271A publication Critical patent/CN112765271A/en
Priority to PCT/CN2021/141698 priority patent/WO2022143540A1/en
Application granted granted Critical
Publication of CN112765271B publication Critical patent/CN112765271B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables

Abstract

The invention discloses a storage method, a device, computer equipment and a medium for a block chain transaction index, wherein the method comprises the following steps: constructing transaction hash, wherein the transaction hash comprises version information, timestamp information and a transaction hash value and is based on the timestamp information; acquiring a sub-database matched with the timestamp information from a transaction index storage database as a target database, wherein the transaction index storage database comprises at least two sub-databases, and each sub-database is used for storing transaction hash of a preset time interval; the transaction hash is used as a Key, value is determined according to the block number of the transaction corresponding to the transaction hash and the number of the transaction in the block, and a Key Value pair consisting of the Key and the Value is used as a transaction hash index and is stored in a target database.

Description

Block chain transaction index storage method and device, computer equipment and medium
Technical Field
The present invention relates to the field of blockchain technologies, and in particular, to a method and an apparatus for storing a blockchain transaction index, a computer device, and a medium.
Background
In the current block chain, the transaction hash is a random character array calculated by a hash algorithm according to transaction contents. The blockchain often needs to provide an external interface to acquire the transaction and related information, including the receipt, through the transaction hash. Firstly, obtaining the block number of the block where the transaction is located through transaction hash, then obtaining a complete block through the block number, and traversing the blocks to find the transaction. Also, the blockchain system needs to store the transaction hash. Because the transaction hash is completely random, the transaction hash is very frequent to read and write, and a long time is needed to be consumed when the data volume is large, the storage layer faces the random reading and writing problem, and the efficiency is extremely low.
Disclosure of Invention
The embodiment of the invention provides a storage method and device for a blockchain transaction index, computer equipment and a storage medium, which are used for improving the efficiency of reading and writing transaction data on a blockchain.
In order to solve the above technical problem, an embodiment of the present application provides a method for storing a blockchain transaction index, including:
constructing a transaction hash, wherein the transaction hash comprises version information, timestamp information and a transaction hash value;
acquiring a sub-database matched with the timestamp information from a transaction index storage database as a target database based on the timestamp information, wherein the transaction index storage database comprises at least two sub-databases, and each sub-database is used for storing transaction hash of a preset time interval;
and taking the transaction hash as a Key, determining Value according to the block number of the transaction corresponding to the transaction hash and the number of the transaction in the block, and taking a Key Value pair consisting of the Key and the Value as a transaction hash index to store the Key Value pair in the target database.
Optionally, the building the transaction hash comprises:
when the block link receives transaction information, timestamp information in the transaction information is obtained, and a transaction hash value is calculated according to the transaction information;
determining version information based on a preset mode;
and generating a transaction hash according to the version information, the timestamp information and the transaction hash value.
Optionally, the obtaining, from a transaction index storage database based on the timestamp information, a sub-database matching the timestamp information as a target database includes:
acquiring a preset time interval corresponding to the sub-database;
determining a preset time interval to which the timestamp information belongs as a target time interval in a matching mode;
and taking a sub-database corresponding to the target time interval as the target database.
Optionally, the presetting, by the sub-database, a storage upper limit, and the storing, as a transaction hash index, a Key-Value pair composed of the Key and the Value to the target database includes:
judging whether the target database is the latest database or not to obtain a first judgment result;
when the first judgment result is that the target database is not the latest database, storing the Key and the Value as a Key-Value pair to the target database;
when the first judgment result is that the target database is the latest database, judging whether the timestamp information is less than or equal to the maximum timestamp corresponding to a preset time interval of the target database to obtain a second judgment result;
if the second result is that the timestamp information is less than or equal to the maximum timestamp corresponding to the preset time interval of the target database, storing the Key and the Value as a Key-Value pair to the target database;
if the second result is that the timestamp information is larger than the maximum timestamp corresponding to the preset time interval of the target database, judging whether the data volume stored in the target database reaches the preset storage upper limit or not, and obtaining a third judgment result;
when the third judgment result is that the preset storage upper limit is not reached, storing the Key and the Value as a Key Value pair to the target database, and updating the maximum timestamp of the target database by using the timestamp information to obtain an updated preset time interval;
and when the third judgment result is that the preset storage upper limit is reached, executing newly-built sub-database processing, setting the upper and lower boundaries of a preset time interval of the newly-built sub-database as the timestamp information, and storing the Key and the Value as a Key Value pair to the newly-built sub-database.
Optionally, the block chain storage method further includes:
if a transaction hash query request is received, analyzing the transaction hash query request to obtain target timestamp information;
determining a sub-database to be queried based on the target timestamp information;
acquiring a target block number from the sub-database to be inquired in a key-value pair inquiry mode;
acquiring a block corresponding to the target block number as a target block according to a disk reading mode;
and traversing the target block to acquire the transaction information corresponding to the transaction hash query request.
In order to solve the above technical problem, an embodiment of the present application further provides a device for storing a blockchain transaction index, including:
the system comprises a construction module, a processing module and a processing module, wherein the construction module is used for constructing transaction hash, and the transaction hash comprises version information, timestamp information and a transaction hash value;
the matching module is used for acquiring a sub-database matched with the timestamp information from a transaction index storage database as a target database based on the timestamp information, wherein the transaction index storage database comprises at least two sub-databases, and each sub-database is used for storing transaction hash of a preset time interval;
and the storage module is used for determining Value according to the block number of the transaction corresponding to the transaction hash and the number of the transaction in the block by taking the transaction hash as a Key, and storing a Key Value pair formed by the Key and the Value as a transaction hash index to the target database.
Optionally, the building module comprises:
the hash value calculation unit is used for acquiring timestamp information in the transaction information when the block link receives the transaction information, and calculating a transaction hash value according to the transaction information;
the version determining unit is used for determining version information based on a preset mode;
and the generating unit is used for generating transaction hash according to the version information, the timestamp information and the transaction hash value.
Optionally, the matching module comprises:
an interval range obtaining unit, configured to obtain a preset time interval corresponding to the sub-database;
a current interval determining unit, configured to determine, in a matching manner, a preset time interval to which the timestamp information belongs, as a target time interval;
and the target database determining unit is used for taking the sub-database corresponding to the target time interval as the target database.
Optionally, the sub-database presets a storage upper limit, and the storage module includes:
the first judgment unit is used for judging whether the target database is the latest database or not to obtain a first judgment result;
the first storage unit is used for storing the Key and the Value as a Key Value pair to the target database when the first judgment result indicates that the target database is not the latest database;
the second judgment unit is used for judging whether the timestamp information is less than or equal to the maximum timestamp corresponding to the preset time interval of the target database to obtain a second judgment result when the first judgment result indicates that the target database is the latest database;
the second storage unit is used for storing the Key and Value as a Key Value pair to the target database if the second result is that the timestamp information is less than or equal to the maximum timestamp corresponding to the preset time interval of the target database;
a third judging unit, configured to judge whether the data amount stored in the target database reaches a preset storage upper limit if the second result is that the timestamp information is greater than a maximum timestamp corresponding to a preset time interval of the target database, so as to obtain a third judgment result;
the third storage unit is used for storing the Key and the Value as a Key Value pair to the target database when the third judgment result is that the preset storage upper limit is not reached, and updating the maximum timestamp of the target database by adopting timestamp information to obtain an updated preset time interval;
and the newly-built sub-database unit is used for executing newly-built sub-database processing when the third judgment result is that the preset storage upper limit is reached, setting the upper boundary and the lower boundary of the preset time interval of the newly-built sub-database as timestamp information, and storing the Key and the Value as Key Value pairs to the newly-built sub-database. Optionally, the storage device of the blockchain transaction index further comprises:
the request analysis module is used for analyzing the transaction hash query request to obtain target timestamp information if the transaction hash query request is received;
the sub-database determining module is used for determining a sub-database to be inquired based on the target timestamp information;
the block number acquisition module is used for acquiring a target block number from the sub-database to be inquired in a key value pair inquiry mode;
the block determining module is used for acquiring a block corresponding to the target block number as a target block according to a disk reading mode;
and the traversing module is used for traversing the target block to acquire the transaction information corresponding to the transaction hash query request.
In order to solve the above technical problem, an embodiment of the present application further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the above method for storing a blockchain transaction index when executing the computer program.
In order to solve the above technical problem, an embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored, and the computer program, when executed by a processor, implements the steps of the above method for storing a blockchain transaction index.
The storage method, the device, the computer equipment and the storage medium for the block chain transaction index provided by the embodiment of the invention construct the transaction hash, wherein the transaction hash comprises version information, timestamp information and a transaction hash Value, a sub-database matched with the timestamp information is obtained from a transaction index storage database as a target database based on the timestamp information, the transaction index storage database comprises at least two sub-databases, each sub-database is used for storing the transaction hash of a preset time interval, the transaction hash is used as a Key, value is determined according to the block number of the transaction corresponding to the transaction hash and the number of the transaction in the block, a Key Value pair consisting of the Key and the Value is used as the transaction hash index and is stored in the target database, the random write optimization of the transaction hash to sequential write is realized, the transaction data query efficiency is improved, meanwhile, the transaction hash index is stored in an independent sub-database, when the transaction data query is carried out, the transaction hash index is favorable for quickly obtaining the transaction hash index to be queried, the block number is further determined according to the transaction hash index, the disk data frequency is reduced, and the transaction data read-write efficiency is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the description below are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without inventive labor.
FIG. 1 is an exemplary system architecture diagram to which the present application may be applied;
FIG. 2 is a flow diagram of one embodiment of a method of storing a blockchain transaction index of the present application;
FIG. 3 is a block diagram illustrating an embodiment of a memory device for blockchain transaction indexing according to the present application;
FIG. 4 is a block diagram of one embodiment of a computer device according to the present application.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "including" and "having," and any variations thereof, in the description and claims of this application and the description of the above figures are intended to cover non-exclusive inclusions. The terms "first," "second," and the like in the description and claims of this application or in the above-described drawings are used for distinguishing between different objects and not for describing a particular order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein may be combined with other embodiments.
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 some, not all, embodiments of the present invention. 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.
Referring to fig. 1, as shown in fig. 1, a system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 101, 102, 103 to interact with a server 105 over a network 104 to receive or send messages or the like.
The terminal devices 101, 102, 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, E-book readers, MP3 players (Moving Picture E interface displays the properties Group Audio Layer III, mpeg compression standard Audio Layer 3), MP4 players (Moving Picture E interface displays the properties Group Audio Layer IV, mpeg compression standard Audio Layer 4), laptop portable computers, desktop computers, and the like.
The server 105 may be a server providing various services, such as a background server providing support for pages displayed on the terminal devices 101, 102, 103.
It should be noted that, the storage method of the blockchain transaction index provided in the embodiment of the present application is executed by the server, and accordingly, the storage device of the blockchain transaction index is disposed in the server.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. Any number of terminal devices, networks and servers may be provided according to implementation needs, and the terminal devices 101, 102 and 103 in this embodiment may specifically correspond to an application system in actual production.
Referring to fig. 2, fig. 2 shows a method for storing a blockchain transaction index according to an embodiment of the present invention, which is described by taking the method applied to the server in fig. 1 as an example, and is detailed as follows:
s201: and constructing a transaction hash, wherein the transaction hash comprises version information, timestamp information and a transaction hash value.
Specifically, when a transaction occurs, version information, timestamp information and a transaction hash value are generated through transaction information, and then a transaction hash is constructed.
The version information is used for ensuring the compatibility of transaction hash, when the number of blocks is increased to exceed eight bytes, the version information is increased, the block field can be prolonged to sixteen bytes, and the problem of follow-up compatibility is avoided.
The time stamp information in the transaction hash is directly taken from the time stamp carried by the transaction, and in the normal execution process, the sequence of block chain packaging and transaction execution is basically consistent with the time generated by the transaction, so that the locality and the sequence of the transaction on database writing are ensured.
And each transaction corresponding to the hash is a unique transaction, so that the privacy and the safety of the transaction are ensured.
For a specific implementation process of constructing the transaction hash, reference may also be made to the description of the subsequent embodiments, and details are not described here for avoiding repetition.
Preferably, in this embodiment, the order of the version information, the timestamp information, and the transaction hash value stored in the transaction hash is, in turn, the version information, the timestamp information, and the transaction hash value. By adopting the transaction hash of the embodiment, the unordered transaction hash in the existing mode is ordered, and when subsequent read-write query processing is carried out, a large amount of time is saved and the data read-write efficiency is improved through the ordering mode.
Considering that the current block hash is similar to the transaction hash and is represented in the form of an irregular character array, when a block is searched, the block number of the block needs to be obtained through the block hash, and then the complete block is obtained through the block number and the block hash, so that a block chain system needs to store two types of information, namely index information from the block hash to the block number and index information from the block number and the block hash to the full amount of data of the block, and when the block chain system is obtained, two disk accesses need to be performed, which causes the data reading and writing efficiency to be low. As a preferable scheme, in a specific implementation of this embodiment, the block hash is re-encoded, the block number is directly embedded in the block hash, and the version number is increased, so as to obtain the block hash formed by combining the version information, the block number, and the block hash value in order.
Further, in the preferred block hash of this embodiment, the first byte is version information, the last eight bytes are block numbers, and the suffix byte is the block hash result. When the number of blocks is increased to exceed eight bytes, the version information is increased, and the block field can be extended to sixteen bytes, so that all problems of subsequent compatibility are ensured.
For example, in a specific implementation manner, when the block hash is calculated, assuming that the current version is 0 and a block No. 100 is to be stored, the first byte of the block hash is 0x00, the last eight bytes are 0x0000000000000064, that is, the first nine bytes are 0x 00000000000000000000000064, and then the hash value obtained by the old hash calculation manner is appended. When accessing the block through the block hash, the second to ninth bytes of the block hash are analyzed, and the block number 100 is obtained, and the block is obtained by the block number. The specific version information, block number, and number of bits used by the chunk hash value may all be changed according to the specific scenario.
It should be understood that, by using the block hash preferred in this embodiment, the original unordered block hashes can be sorted according to the version information and the block numbers, which is beneficial to improving the efficiency of data query, and meanwhile, since the block numbers are embedded into the block hash, the index storage overhead from the block hash to the block numbers is reduced, one-time disk access during interface reading is also reduced, which is beneficial to the storage and read-write efficiency of transaction data through the block hash.
S202: and acquiring a sub-database matched with the timestamp information from a transaction index storage database as a target database based on the timestamp information, wherein the transaction index storage database comprises at least two sub-databases, and each sub-database is used for storing transaction hash of a preset time interval.
In this embodiment, a transaction index storage database is preset, where the transaction index storage database includes at least two sub-databases, each sub-database is used to store transaction hashes in a preset time interval, and includes a preset time interval formed by a maximum timestamp and a minimum timestamp, and the sub-databases only store the corresponding transaction hashes in a preset time interval range, and determine the sub-database in which current transaction data needs to be stored as a target database by matching timestamp information corresponding to a transaction with each sub-database.
It should be noted that when the data volume is small, the transaction index storage database in this embodiment may include one sub-database, and the new creation of the sub-database is dynamically performed subsequently along with the increase of the storage volume.
It should be understood that the transaction index storage database in this embodiment includes at least two sub-databases, which is a preferred mode in practical application of this embodiment, and the transaction hash index is stored in order by means of a plurality of sub-databases, which is beneficial to improving the transaction query efficiency.
The preset time interval can be set with a constant initial value according to actual needs, and can be updated when a new transaction hash is inserted into the target database in the following process.
S203: and determining Value according to the block number of the transaction corresponding to the transaction hash and the number of the transaction in the block by taking the transaction hash as a Key, and storing a Key Value pair consisting of the Key and the Value as a transaction hash index to a target database.
Specifically, the transaction hash is used as a Key, value is determined according to the block number of the transaction corresponding to the transaction hash and the number of the transaction in the block, and the transaction hash and the block number of the transaction are stored in a target database in a Key Value pair mode.
The Value is determined according to the block number of the transaction corresponding to the transaction hash and the number of the transaction in the block, and specifically, the Value can be obtained by serially connecting the block number of the transaction and the number of the transaction in the block according to actual requirements.
In the embodiment, by constructing a transaction hash, the transaction hash includes version information, timestamp information and a transaction hash Value, and based on the timestamp information, a sub-database matched with the timestamp information is obtained from a transaction index storage database and is used as a target database, wherein the transaction index storage database includes at least two sub-databases, each sub-database is used for storing the transaction hash in a preset time interval, the transaction hash is used as a Key, value is determined according to a block number of a transaction corresponding to the transaction hash and a number of the transaction in the block, and a Key Value pair consisting of the Key and the Value is used as a transaction hash index and is stored in the target database, so that random write of the transaction is optimized to sequential write, the transaction is stored in an independent sub-database, high-performance read and write of the database are guaranteed, and data read-write efficiency is improved.
In some optional implementations of this embodiment, in step S201, constructing the transaction hash includes:
when the block link receives transaction information, timestamp information in the transaction information is obtained, and a transaction hash value is calculated according to the transaction information;
determining version information based on a preset mode;
and generating a transaction hash according to the version information, the timestamp information and the transaction hash value.
Specifically, the transaction hash is calculated according to the information in the transaction, including the time information, the transaction usually includes various information such as an initiator address, a receiver address, a transaction payload, a signature and the like, the transaction hash is usually obtained by integrating all transaction information and calculating by using a hash algorithm, and the hash algorithm has a great number of choices. In this embodiment, the time information is embedded in the transaction hash, and in a specific implementation, the first byte is version information, the timestamp information is filled in the following eight bytes, and finally, the transaction hash value calculated by the hash algorithm is connected, so that a transaction hash can be formed.
For example, assume that the current version is 0, the current timestamp is 1603975389074698000, and the hexadecimal representation indicates that the first byte of the transaction hash is 0x00, the last eight bytes are 0x1642771e3e442f00, that is, the first nine bytes are 0x001642771e3e442f00, and the hash value obtained by the old hash calculation method is appended later. And during storage, inserting the transaction into the database according to the timestamp and the flow of storing the transaction into the database.
The preset mode of the version number is determined, the preset mode can be set according to actual conditions, limitation is not made here, and unordered transaction hash can be ordered by the mode of the version number, so that the data processing efficiency during subsequent data processing such as query insertion and the like can be improved.
It should be noted that the setting of the version information, the setting of the timestamp information, and the number of bits used for the hash may all be changed according to a specific scenario, and are not limited herein.
Alternatively, when the number of blocks grows to exceed eight bytes, version information is increased, and the block field may be extended to sixteen bytes. Such a design guarantees all the problems of subsequent compatibility.
In the embodiment, the transaction hash is generated through the version information, the timestamp information and the transaction hash value, the version information and the timestamp information used for performing the transaction hash are written into the transaction hash, a number does not need to be obtained through a disk reading and writing mode, the number of disk reading and writing is reduced, the data reading and writing efficiency is improved, the timestamp information is adopted, random writing of the transaction is optimized to sequential writing, high-performance reading and writing of a database are guaranteed, and the data reading and writing efficiency is improved.
In some optional implementations of this embodiment, in step S202, based on the timestamp information, a sub-database matching the timestamp information is obtained from the transaction index storage database, and the obtaining a target database includes:
acquiring a preset time interval corresponding to the sub-database;
determining a preset time interval of the timestamp information as a target time interval in a matching mode;
and taking the sub-database corresponding to the target time interval as a target database.
Specifically, each sub-database is respectively used for storing transaction information within a specific time range, recording a minimum time stamp and a maximum time stamp of the transaction stored in the database, acquiring a preset time interval corresponding to each sub-database, and matching the preset time interval with a time point in the time stamp information, if the time point in the time stamp information is included between the minimum time stamp and the maximum time stamp of the preset time interval, taking the preset time interval as a target time interval, taking the sub-database corresponding to the target time interval as a target database, and subsequently adopting the target database to read and write the transaction data.
In the embodiment, the target database is determined by matching the timestamp information with the preset time interval corresponding to each sub-database, so that the target database is rapidly determined, and the subsequent data reading and writing efficiency and the data query efficiency are improved.
In some optional implementation manners of this embodiment, the sub-database presets a storage upper limit, and in step S203, storing a Key-Value pair composed of Key and Value as a transaction hash index into the target database includes:
judging whether the target database is the latest database or not to obtain a first judgment result;
when the first judgment result is that the target database is not the latest database, storing Key and Value as Key Value pairs to the target database;
when the first judgment result is that the target database is the latest database, judging whether the timestamp information is less than or equal to the maximum timestamp corresponding to the preset time interval of the target database to obtain a second judgment result;
if the second result is that the timestamp information is less than or equal to the maximum timestamp corresponding to the preset time interval of the target database, storing the Key and Value as a Key Value pair to the target database;
if the second result is that the timestamp information is larger than the maximum timestamp corresponding to the preset time interval of the target database, judging whether the data volume stored in the target database reaches a preset storage upper limit or not, and obtaining a third judgment result;
when the third judgment result is that the preset storage upper limit is not reached, storing Key and Value as a Key Value pair to a target database, and updating the maximum timestamp of the target database by using timestamp information to obtain an updated preset time interval;
and when the third judgment result is that the preset storage upper limit is reached, executing the newly-built sub-database processing, setting the upper boundary and the lower boundary of the preset time interval of the newly-built sub-database as timestamp information, and storing the Key and the Value as a Key Value pair to the newly-built sub-database.
For example, in one embodiment, there are three sub-databases, with time from 8 to 9, 9 to 10, and 10 to 11, respectively. If the new transaction hash timestamp is 7, a first sub-database exists, the time of the first database is updated to 7 to 9, if the new transaction hash timestamp is eight and a half, the first sub-database exists, a second sub-database exists when the new transaction hash timestamp is nine and a third sub-database when the new transaction hash timestamp is ten and a half.
Judging whether the target database is the latest database by judging whether the target database is the sub-database of the hash storage of the last transaction, if so, determining the target database is the latest database, and if not, determining the target database is not the latest database.
It should be noted that, even though an older transaction occurs occasionally, a correct sub-database can be found for writing according to the timestamp information, and since the read request of the block chain is concentrated on new data, the database which is long in time can be closed according to the situation, so that the memory occupation is reduced, and when the data needs to be read, the data can be opened again for reading, which is beneficial to improving the data reading and writing efficiency.
The preset upper storage limit may be set according to requirements of an actual application scenario, for example, 2 ten thousand storage limits are set, and no specific limitation is made here.
It should be understood that the storage upper limit is preset for the sub-databases, which limits the size of each sub-database, and ensures stable performance of the sub-databases during subsequent data reading and writing, thereby facilitating improvement of data reading and writing efficiency.
In the embodiment, the storage condition of the target database is limited, so that the transaction hash is stored according to the timestamp sequence, the efficiency of subsequent read-write query is improved, and meanwhile, the size of each sub-database is limited, so that the read-write performance is stable, and the data read-write efficiency is improved.
In some optional implementations of this embodiment, the method for storing a blockchain transaction index further includes:
if a transaction hash query request is received, analyzing the transaction hash query request to obtain target timestamp information;
determining a sub-database to be queried based on the target timestamp information;
acquiring a target block number from a sub-database to be inquired in a key-value pair inquiry mode;
acquiring a block corresponding to the target block number as a target block according to a disk reading mode;
and traversing the target block to acquire the transaction information corresponding to the transaction hash query request.
In this embodiment, each sub-database stores the transaction hash of a preset time interval, the sub-database to be queried is determined based on the target timestamp information, matching is performed through the preset time interval corresponding to each sub-database, and the sub-database containing the time point in the target timestamp information is determined as the sub-database in which the transaction hash corresponding to the target timestamp information is stored, and is further used as the sub-database to be queried.
In this embodiment, when a transaction hash query request is received, the transaction hash query request is analyzed to obtain target timestamp information, a sub-database to be queried is determined based on the target timestamp information, and sub-data are sequentially stored according to time intervals, which is beneficial to improving the efficiency of determining the sub-database to be queried.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Fig. 3 is a schematic block diagram of a storage apparatus for a blockchain transaction index, which corresponds to the storage method for a blockchain transaction index in one-to-one manner according to the foregoing embodiment. As shown in fig. 3, the storage device of the blockchain transaction index includes a construction module 31, a matching module 32 and a storage module 33. The detailed description of each functional module is as follows:
a construction module 31, configured to construct a transaction hash, where the transaction hash includes version information, timestamp information, and a transaction hash value;
the matching module 32 is configured to obtain, based on the timestamp information, a sub-database matched with the timestamp information from a transaction index storage database as a target database, where the transaction index storage database includes at least two sub-databases, and each sub-database is used to store a transaction hash in a preset time interval;
and the storage module 33 is configured to use the transaction hash as a Key, determine Value according to a block number of the transaction corresponding to the transaction hash and a number of the transaction in the block, and store a Key Value pair formed by the Key and the Value as a transaction hash index in the target database.
Optionally, the building block 31 comprises:
the hash value calculating unit is used for acquiring the timestamp information in the transaction information when the block link receives the transaction information and calculating the transaction hash value according to the transaction information;
the version determining unit is used for determining version information based on a preset mode;
and the generating unit is used for generating the transaction hash according to the version information, the timestamp information and the transaction hash value.
Optionally, the matching module 32 comprises:
the interval range acquiring unit is used for acquiring a preset time interval corresponding to the sub-database;
the current interval determining unit is used for determining a preset time interval to which the timestamp information belongs as a target time interval in a matching mode;
and the target database determining unit is used for taking the sub-database corresponding to the target time interval as a target database.
Optionally, the sub-database presets a storage upper limit, and the storage module 33 includes:
the first judgment unit is used for judging whether the target database is the latest database or not to obtain a first judgment result;
the first storage unit is used for storing the Key and the Value as a Key Value pair to the target database when the first judgment result indicates that the target database is not the latest database;
the second judgment unit is used for judging whether the timestamp information is less than or equal to the maximum timestamp corresponding to the preset time interval of the target database to obtain a second judgment result when the first judgment result indicates that the target database is the latest database;
the second storage unit is used for storing the Key and Value as a Key Value pair to the target database if the second result is that the timestamp information is less than or equal to the maximum timestamp corresponding to the preset time interval of the target database;
a third judging unit, configured to, if the second result is that the timestamp information is greater than a maximum timestamp corresponding to a preset time interval of the target database, judge whether the amount of data stored in the target database reaches a preset storage upper limit, and obtain a third judgment result;
the third storage unit is used for storing the Key Value pair serving as the Key Value pair to the target database when the third judgment result is that the preset storage upper limit is not reached, and updating the maximum timestamp of the target database by adopting timestamp information to obtain an updated preset time interval;
and the newly-built sub-database unit is used for executing newly-built sub-database processing when the third judgment result is that the preset storage upper limit is reached, setting the upper boundary and the lower boundary of the preset time interval of the newly-built sub-database as timestamp information, and storing the Key and the Value as Key Value pairs to the newly-built sub-database.
Optionally, the storage device for the blockchain transaction index further includes:
the request analysis module is used for analyzing the transaction hash query request to obtain target timestamp information if the transaction hash query request is received;
the sub-database determining module is used for determining a sub-database to be inquired based on the target timestamp information;
the block number acquisition module is used for acquiring a target block number from the sub-database to be inquired in a key value pair inquiry mode;
the block determining module is used for acquiring a block corresponding to the target block number as a target block according to a disk reading mode;
and the traversing module is used for traversing the target block and acquiring the transaction information corresponding to the transaction hash query request.
For specific definition of the storage device of the blockchain transaction index, reference may be made to the above definition of the storage method of the blockchain transaction index, and details are not described herein again. The various modules in the storage of the blockchain transaction index described above may be implemented in whole or in part by software, hardware, and combinations thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In order to solve the technical problem, an embodiment of the present application further provides a computer device. Referring to fig. 4, fig. 4 is a block diagram of a basic structure of a computer device according to the present embodiment.
The computer device 4 comprises a memory 41, a processor 42, a network interface 43 communicatively connected to each other via a system bus. It is noted that only the computer device 4 having the components connection memory 41, processor 42, network interface 43 is shown, but it is understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead. As will be understood by those skilled in the art, the computer device is a device capable of automatically performing numerical calculation and/or information processing according to a preset or stored instruction, and the hardware includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The computer device can be a desktop computer, a notebook, a palm computer, a cloud server and other computing devices. The computer equipment can carry out man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch panel or voice control equipment and the like.
The memory 41 includes at least one type of readable storage medium including a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or D interface display memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 41 may be an internal storage unit of the computer device 4, such as a hard disk or a memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the computer device 4. Of course, the memory 41 may also include both internal and external storage devices of the computer device 4. In this embodiment, the memory 41 is generally used for storing an operating system installed in the computer device 4 and various types of application software, such as program codes for controlling electronic files. Further, the memory 41 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 42 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 42 is typically used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is configured to execute the program code stored in the memory 41 or process data, such as program code for executing control of an electronic file.
The network interface 43 may comprise a wireless network interface or a wired network interface, and the network interface 43 is generally used for establishing a communication connection between the computer device 4 and other electronic devices.
The present application further provides another embodiment, which is to provide a computer-readable storage medium storing an interface display program, where the interface display program is executable by at least one processor to cause the at least one processor to execute the steps of the method for storing a blockchain transaction index as described above.
Through the description of the foregoing embodiments, it is clear to those skilled in the art that the method of the foregoing embodiments may be implemented by software plus a necessary general hardware platform, and certainly may also be implemented by hardware, but in many cases, the former is a better implementation. Based on such understanding, the technical solutions of the present application or portions thereof that contribute to the prior art may be embodied in the form of a software product, where the computer software product is stored in a storage medium (such as a ROM/RAM, a magnetic disk, and an optical disk), and includes several instructions for enabling a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present application.
It should be understood that the above-described embodiments are merely exemplary of some, and not all, embodiments of the present application, and that the drawings illustrate preferred embodiments of the present application without limiting the scope of the claims appended hereto. This application is capable of embodiments in many different forms and is provided for the purpose of enabling a thorough understanding of the disclosure of the application. Although the present application has been described in detail with reference to the foregoing embodiments, it will be apparent to one skilled in the art that the present application may be practiced without modification or with equivalents of some of the features described in the foregoing embodiments. All equivalent structures made by using the contents of the specification and the drawings of the present application are directly or indirectly applied to other related technical fields, and all the equivalent structures are within the protection scope of the present application.

Claims (9)

1. A method for storing a blockchain transaction index is characterized in that the method for storing the blockchain transaction index comprises the following steps:
constructing a transaction hash, wherein the transaction hash comprises version information, timestamp information and a transaction hash value;
acquiring a sub-database matched with the timestamp information from a transaction index storage database as a target database based on the timestamp information, wherein the transaction index storage database comprises at least two sub-databases, and each sub-database is used for storing transaction hash of a preset time interval;
taking the transaction hash as a Key, determining Value according to a block number of a transaction corresponding to the transaction hash and a number of the transaction in a block, taking a Key Value pair consisting of the Key and the Value as a transaction hash index, and storing the Key Value pair in the target database;
the building a transaction hash includes:
when the block link receives transaction information, timestamp information in the transaction information is obtained, and a transaction hash value is calculated according to the transaction information;
determining version information based on a preset mode;
and generating a transaction hash according to the version information, the timestamp information and the transaction hash value.
2. The method for storing the blockchain transaction index according to claim 1, wherein the obtaining the sub-database matching the timestamp information from the transaction index storage database based on the timestamp information as the target database comprises:
acquiring a preset time interval corresponding to the sub-database;
determining a preset time interval to which the timestamp information belongs as a target time interval in a matching mode;
and taking the sub-database corresponding to the target time interval as the target database.
3. The method for storing the blockchain transaction index according to claim 1, wherein the sub-database presets a storage upper limit, and the storing the Key-Value pair consisting of the Key and the Value as the transaction hash index into the target database comprises:
judging whether the target database is the latest database or not to obtain a first judgment result;
when the first judgment result is that the target database is not the latest database, storing the Key and the Value as a Key-Value pair to the target database;
when the first judgment result is that the target database is the latest database, judging whether the timestamp information is less than or equal to the maximum timestamp corresponding to a preset time interval of the target database to obtain a second judgment result;
if the second judgment result is that the timestamp information is less than or equal to the maximum timestamp corresponding to the preset time interval of the target database, storing the Key and the Value as a Key Value pair to the target database;
if the second judgment result is that the timestamp information is larger than the maximum timestamp corresponding to the preset time interval of the target database, judging whether the data volume stored in the target database reaches the preset storage upper limit or not, and obtaining a third judgment result;
when the third judgment result is that the preset storage upper limit is not reached, storing the Key and the Value as a Key Value pair to the target database, and updating the maximum timestamp of the target database by using the timestamp information to obtain an updated preset time interval;
and when the third judgment result is that the preset storage upper limit is reached, executing newly-built sub-database processing, setting the upper and lower boundaries of a preset time interval of the newly-built sub-database as the timestamp information, and storing the Key and the Value as a Key Value pair to the newly-built sub-database.
4. The method for storing a blockchain transaction index according to any one of claims 1 to 3, wherein the blockchain storage method further comprises:
if a transaction hash query request is received, analyzing the transaction hash query request to obtain target timestamp information;
determining a sub-database to be queried based on the target timestamp information;
acquiring a target block number from the sub database to be inquired in a key value pair inquiry mode;
acquiring a block corresponding to the target block number as a target block according to a disk reading mode;
and traversing the target block to acquire the transaction information corresponding to the transaction hash query request.
5. The method for storing the blockchain transaction index according to claim 1, wherein the version information, the timestamp information and the transaction hash value are stored in the transaction hash in sequence of the version information, the timestamp information and the transaction hash value.
6. A storage device for blockchain transaction index, the storage device for blockchain transaction index comprising:
the system comprises a construction module, a processing module and a processing module, wherein the construction module is used for constructing transaction hash, and the transaction hash comprises version information, timestamp information and a transaction hash value;
the matching module is used for acquiring a sub-database matched with the timestamp information from a transaction index storage database as a target database based on the timestamp information, wherein the transaction index storage database comprises at least two sub-databases, each sub-database is used for storing transaction hash in a preset time interval, the timestamp information in the transaction information is acquired when the block link receives the transaction information, and a transaction hash value is calculated according to the transaction information;
determining version information based on a preset mode;
generating a transaction hash according to the version information, the timestamp information and the transaction hash value;
and the storage module is used for determining Value according to the block number of the transaction corresponding to the transaction hash and the number of the transaction in the block by taking the transaction hash as a Key, and storing a Key Value pair formed by the Key and the Value as a transaction hash index to the target database.
7. The apparatus for storing a blockchain transaction index of claim 6, wherein the matching module comprises:
an interval range obtaining unit, configured to obtain a preset time interval corresponding to the sub-database;
a current interval determining unit, configured to determine, in a matching manner, a preset time interval to which the timestamp information belongs, as a target time interval;
and the target database determining unit is used for taking the sub-database corresponding to the target time interval as the target database.
8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor when executing the computer program implements a method of storing a blockchain transaction index according to any one of claims 1 to 5.
9. A computer-readable storage medium storing a computer program, wherein the computer program is executed by a processor to implement the method for storing a blockchain transaction index according to any one of claims 1 to 5.
CN202011640211.3A 2020-12-31 2020-12-31 Block chain transaction index storage method and device, computer equipment and medium Active CN112765271B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202011640211.3A CN112765271B (en) 2020-12-31 2020-12-31 Block chain transaction index storage method and device, computer equipment and medium
PCT/CN2021/141698 WO2022143540A1 (en) 2020-12-31 2021-12-27 Block chain index storage method and apparatus, computer device and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011640211.3A CN112765271B (en) 2020-12-31 2020-12-31 Block chain transaction index storage method and device, computer equipment and medium

Publications (2)

Publication Number Publication Date
CN112765271A CN112765271A (en) 2021-05-07
CN112765271B true CN112765271B (en) 2023-02-07

Family

ID=75698400

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011640211.3A Active CN112765271B (en) 2020-12-31 2020-12-31 Block chain transaction index storage method and device, computer equipment and medium

Country Status (2)

Country Link
CN (1) CN112765271B (en)
WO (1) WO2022143540A1 (en)

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112765271B (en) * 2020-12-31 2023-02-07 杭州趣链科技有限公司 Block chain transaction index storage method and device, computer equipment and medium
CN113343292A (en) * 2021-05-28 2021-09-03 网易(杭州)网络有限公司 Transaction number processing method and device, storage medium and computer equipment
CN113485949B (en) * 2021-05-28 2023-06-20 浙江毫微米科技有限公司 Data processing method, chip and computer readable storage medium
CN113282662B (en) * 2021-06-03 2023-11-03 广东辰宜信息科技有限公司 Block information processing method, device, equipment and medium
CN113139019B (en) * 2021-06-18 2022-03-25 智己汽车科技有限公司 Method and device for recording mileage data of vehicle on block chain
CN113836142A (en) * 2021-09-24 2021-12-24 中国农业银行股份有限公司 Data processing method and related equipment
CN114860730A (en) * 2022-05-17 2022-08-05 北京新五好农业科技有限公司 Land data storage method, system and storage medium based on block chain
CN115099817B (en) * 2022-06-17 2023-03-24 北京中科深智科技有限公司 Efficient block chain transaction verification and query method and system
CN115065458B (en) * 2022-08-08 2022-11-15 山东鼎信数字科技有限公司 Electronic commerce transaction system with data encryption transmission
CN115793992B (en) * 2023-02-07 2023-06-23 天翼云科技有限公司 Data storage method, device, electronic equipment and readable storage medium
CN116842223B (en) * 2023-08-29 2023-11-10 天津鑫宝龙电梯集团有限公司 Working condition data management method, device, equipment and medium
CN117271529B (en) * 2023-11-20 2024-03-29 阿里云计算有限公司 Index processing method, device and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107273556A (en) * 2017-08-23 2017-10-20 上海点融信息科技有限责任公司 Block chain data index method and equipment
CN110083604A (en) * 2019-04-17 2019-08-02 上海沄界信息科技有限公司 A kind of data really weigh method and device
CN111639080A (en) * 2020-06-01 2020-09-08 腾讯科技(深圳)有限公司 Data processing method and device, node equipment and storage medium
CN112148734A (en) * 2020-09-22 2020-12-29 国网浙江省电力有限公司信息通信分公司 Transaction data processing method, device, equipment and storage medium based on block chain

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109189782A (en) * 2018-08-02 2019-01-11 哈尔滨工程大学 A kind of indexing means in block chain commodity transaction inquiry
CN110263014A (en) * 2019-05-15 2019-09-20 广州致链科技有限公司 Block chain storage system and method towards timing type data
CN110689349B (en) * 2019-10-08 2023-07-11 深圳前海微众银行股份有限公司 Transaction hash value storage and searching method and device in blockchain
CN111708825B (en) * 2020-06-11 2021-08-24 腾讯科技(深圳)有限公司 Data processing method, device and equipment based on block chain and readable storage medium
CN111949672B (en) * 2020-07-30 2021-11-30 杭州电子科技大学 Block chain storage method for supporting incremental update of Internet-of-things data
CN112765271B (en) * 2020-12-31 2023-02-07 杭州趣链科技有限公司 Block chain transaction index storage method and device, computer equipment and medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107273556A (en) * 2017-08-23 2017-10-20 上海点融信息科技有限责任公司 Block chain data index method and equipment
CN110083604A (en) * 2019-04-17 2019-08-02 上海沄界信息科技有限公司 A kind of data really weigh method and device
CN111639080A (en) * 2020-06-01 2020-09-08 腾讯科技(深圳)有限公司 Data processing method and device, node equipment and storage medium
CN112148734A (en) * 2020-09-22 2020-12-29 国网浙江省电力有限公司信息通信分公司 Transaction data processing method, device, equipment and storage medium based on block chain

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
区块链原理及关键技术;王群,李馥娟;《计算机科学与探索》;20201030;全文 *

Also Published As

Publication number Publication date
CN112765271A (en) 2021-05-07
WO2022143540A1 (en) 2022-07-07

Similar Documents

Publication Publication Date Title
CN112765271B (en) Block chain transaction index storage method and device, computer equipment and medium
CN108427705B (en) Electronic device, distributed system log query method and storage medium
CN108388598B (en) Electronic device, data storage method, and storage medium
CN108388599B (en) Electronic device, data migration and calling method and storage medium
CN111414407A (en) Data query method and device of database, computer equipment and storage medium
CN111400308A (en) Processing method of cache data, electronic device and readable storage medium
CN101382876A (en) Data storage method
CN115757495A (en) Cache data processing method and device, computer equipment and storage medium
CN104881454A (en) Updating method and system of parameter
CN112784112A (en) Message checking method and device
CN113536185A (en) Application page loading method, storage medium and related equipment thereof
CN112631884A (en) Pressure measurement method and device based on data synchronization, computer equipment and storage medium
CN111782304A (en) Logic control method and device for paging loading data, computer equipment and medium
WO2020233045A1 (en) Plug-in update method and device, server and computer readable storage medium
CN111813517A (en) Task queue allocation method and device, computer equipment and medium
CN112765270B (en) Block chain data processing method and device, computer equipment and medium
CN112436943B (en) Request deduplication method, device, equipment and storage medium based on big data
CN114143191A (en) Distributed gateway-based micro-service arranging method and device and related equipment
CN116842012A (en) Method, device, equipment and storage medium for storing Redis cluster in fragments
CN111475468A (en) Log access method, device, equipment and storage medium of newly added system
CN115203672A (en) Information access control method and device, computer equipment and medium
CN114780519A (en) DBC file generation method, device, equipment and medium based on CAN communication
CN114626352A (en) Report automatic generation method and device, computer equipment and storage medium
CN114143308A (en) File uploading information processing method and device, computer equipment and storage medium
CN114625372A (en) Automatic component compiling method and device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant