Construction and Query Method of Verifiable Hierarchical Index Based on Blockchain Temporal Data
By building verifiable hierarchical indexes on the blockchain, expanding the transaction structure and adding new traceability pointers, the problem of inefficient temporal data query in traditional blockchain is solved, and efficient and flexible temporal data query is achieved.
Patent Information
- Application Number
- CN202310611053.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-26
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2043-05-26
AI Technical Summary
Traditional blockchain technology is inefficient in temporal data query, and existing improved methods often introduce off-chain storage tools, resulting in poor performance or unsupported range query.
Build a verifiable hierarchical index based on blockchain temporal data. By expanding the blockchain transaction structure, adding transaction time attributes and forward traceability pointers, forming an uncertain length hierarchical index, using the leaf nodes of State Trie to maintain the latest transaction pointers, building a complete traceability chain, and supporting efficient query.
It realizes efficient query of temporal data on the blockchain, supports scope query, improves query efficiency, and maintains stable operation when system parameters change, avoiding the need for off-chain storage.
Smart Images

Figure CN117009347B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data management, and more specifically, relates to a method for constructing and querying a verifiable hierarchical index based on blockchain temporal data. Background Art
[0002] The concept of blockchain was first proposed by Nakamoto in 2008 and applied to digital currencies. It is an integration of multiple computer technologies such as P2P networks, cryptography, consensus algorithms, and smart contracts. Its initial application goal was to store data securely and efficiently, and it was different from traditional databases in terms of decentralization, anti-tampering, and traceability, and thus received extensive attention. In recent years, blockchain technology has developed rapidly, and its applications have gradually expanded from the initial digital currency to many semi-financial and non-financial fields. In these application scenarios and related data auditing scenarios, only supporting queries of the latest state is not sufficient, and temporal queries have become a research hotspot. The concept of temporal queries was first proposed in the database field. During the development and use of databases, people discovered the great value of temporal data. The time attribute can express the sequence of data, which has great reference value for the analysis of data evolution.
[0003] Traditional blockchains do not give a clear definition of temporal data, and the provided method of traversing block by block for querying cannot meet the efficient query requirements for massive data. A large number of related studies have been conducted on the efficient query of blockchain data, but most of the work provides rich query functions by introducing other storage products off-chain. This method does not essentially improve the performance of the blockchain itself; a small part of the work is to improve the blockchain's own structure from the on-chain perspective, but it often has deficiencies such as a long chain, constant parameters, and lack of support for range queries. Summary of the Invention
[0004] In view of this, the present invention provides a method for constructing and querying a verifiable hierarchical index based on blockchain temporal data. Specifically, the index structure Txchain-index constructed by the present invention is an extension of the on-chain structure of traditional blockchains without introducing any other off-chain storage tools.
[0005] The technical solution of the present invention is as follows:
[0006] A method for constructing and querying a verifiable hierarchical index based on blockchain temporal data, the method includes a method for constructing a verifiable hierarchical index based on blockchain temporal data, and also includes a method for querying a verifiable hierarchical index based on blockchain temporal data;
[0007] Among them, the steps of the method for constructing a verifiable hierarchical index based on blockchain temporal data include:
[0008] Step 1: The user initiates a blockchain transaction request through the client. When initiating the request, the user needs to provide the hash addresses from and to of the two parties involved in the transaction, as well as the transaction amount value.
[0009] Step 2: After receiving the transaction request, the blockchain system formats the transaction request: assigns it a time attribute Timestamp and the signature information of the user's account, and submits the formatted transaction information.
[0010] Step 3: The blockchain system checks the parameters of the formatted transaction information. If the check passes, it proceeds to Step 4; otherwise, the process ends.
[0011] Step 4: The blockchain system queries the world state tree State Trie based on from and to, obtains the corresponding paths of from and to in the State Trie, and retrieves the latest transactions PreFromTx and PreToTx corresponding to from and to from the leaf nodes.
[0012] Step 5: Determine the transaction roles played by the two parties in their respective latest transactions.
[0013] If it is the initiating party from in the transaction role, then PreFrom is first updated to the PreFromTx found in Step 14. Determine whether the IndexNum of the transaction role Role1 played by from in PreFromTx is equal to the set parameter k. When IndexNum is equal to the set parameter k, set the current transaction's FromIndexNum to 1, set FromStartTime to the Timestamp of the current transaction, and set FromFirstIndex to nil. When IndexNum is not equal to the set parameter k, increment FromIndexNum by 1, keep FromStartTime from the previous transaction, and if IndexNum is exactly 1, set FromFirstIndex to PreFrom; otherwise, keep it from the previous transaction.
[0014] If it is the receiver to in the transaction role, PreTo is first updated to PreToTx found in step 14; determine whether the IndexNum of the transaction role Role2 played by to in PreToTx is equal to the set parameter k. If IndexNum is equal to the set parameter k, set the ToIndexNum of the current transaction to 1, ToStartTime to the Timestamp of the current transaction, and ToFirstIndex to nil. If IndexNum is not equal to the set parameter k, add 1 to ToIndexNum, and use ToStartTime and ToFirstIndex of the previous transaction. If IndexNum is exactly 1, set ToFirstIndex to PreTo, otherwise use the previous transaction.
[0015] Step 6, calculate the unique identification hash value curTx of the transaction, and update the latest transaction maintained in the leaf node of the path corresponding to from and to in the State Trie to curTx.
[0016] Among them, the query method based on the verifiable hierarchical index of blockchain temporal data includes the following steps:
[0017] Step 1: The user initiates a blockchain query request through the client. When initiating the request, the user needs to provide the specified query account key and the query time range.<startTime,endTime> , the client generates a query request according to the standardized format. It is worth noting that the single-value query is a special case of the range query, which is valid when startTime = endTime;
[0018] Step 2: After receiving the query request, the blockchain system verifies whether the parameters are legal. If the parameters are illegal, the request is rejected. Otherwise, the extended State Trie is queried to obtain the most recent transaction LatestTx of the key and proceed to step 3.
[0019] Step 3: Determine the trading role of the query key in the current transaction. If the trading role is "from", then when PreFrom is nil, i.e., there is no forward transaction of the key anymore, the query ends; if the FromStartTime of the transaction <= startTime, it means the query ends after traversing the current transaction index group level and there is no need to continue traversing forward. At this time, only add all transactions that meet the conditions in this transaction index group level to the result set according to the Timestamp of the transaction and end the query. If the FromStartTime of the transaction > endTime, it means that none of the transactions in the current transaction index group level meet the query requirements. Find the last transaction of the previous transaction index group level according to FirstFromIndex and enter Step 4. If the FromStartTime of the transaction is between startTime and endTime, first add all transactions that meet the conditions in the current transaction index group level to the result set according to the Timestamp of the transaction. Then, judge FirstFromIndex. If FirstFromIndex is not nil, find the last transaction of the previous transaction index group level according to FirstFromIndex; otherwise, find the last transaction of the previous transaction index group level according to PreFrom; enter Step 4. If the trading role is "to", then when PreTo is nil, i.e., there is no forward transaction of the key anymore, the query ends; if the ToStartTime of the transaction <= startTime, it means the query ends after traversing the current transaction index group level and there is no need to continue traversing forward. At this time, only add all transactions that meet the conditions in this transaction index group level to the result set according to the Timestamp of the transaction and end the query. If the ToStartTime of the transaction > endTime, it means that none of the transactions in the current transaction index group level meet the query requirements. Find the last transaction of the previous transaction index group level according to FirstToIndex and enter Step 4. If the FromToTime of the transaction is between startTime and endTime, first add all transactions that meet the conditions in the current transaction index group level to the result set according to the Timestamp of the transaction. Then, judge FirstToIndex. If FirstToIndex is not nil, find the last transaction of the previous transaction index group level according to FirstTomIndex; otherwise, find the last transaction of the previous transaction index group level according to PreTo; enter Step 4;
[0020] Step 4: Repeat Step 3 until the query ends;
[0021] Step 5: The blockchain system outputs the query result set to the user through the client;
[0022] It should be noted that the index construction method is based on the real-time x value of the system, while the query method is based on the index attributes of the transaction. Therefore, the change of x will not block the construction and query of the index.
[0023] The present invention takes the temporal data in the blockchain as the research object, hereinafter all referred to as transactions. A transaction consists of the following attributes: From represents the transaction initiator; To is the transaction recipient; Value is the transaction amount; SignAttrs represents the signature-related attributes of the transaction; PreFrom and PreTo are two hash pointers, PreFrom points to the previous transaction of from, and PreTo points to the previous transaction of to; Timestamp is the timestamp when the current transaction is completed. FromStartTime and Timestamp form the time interval in the current partial index of account From; ToStartTime and Timestamp form the time interval in the current partial index of account To; FromFirstIndex and ToFirstIndex respectively represent the first transaction hash of the complete index to which from and to belong in the current transaction, and FromIndexNum and ToIndexNum respectively represent the serial numbers of the current transaction in the complete indexes to which from and to belong; Others represents other auxiliary attributes during the transaction process, such as transaction remarks, etc. The above attributes can be classified into three parts: basic transaction attributes, time attributes, and index attributes. The basic transaction attributes are the basic components of the transaction and are consistent with traditional blockchain transactions; the time attributes represent the temporality of the data and the characteristics of the research object; the index attributes are the support for efficient query. The transactions form a traceability chain through the forward traceability pointers. However, this traceability chain is incomplete because there is a lack of a traceability entry. For this reason, the present invention also expands the leaf nodes of the State Trie. The State Trie is the world state tree in the blockchain. Given the value of each account, that is, the query key, the latest state corresponding to this key can be found in this MPT tree. The present invention additionally maintains the latest transaction pointer of the account key represented by the node in the leaf nodes of the State Trie, so that the latest transaction corresponding to the specified key can be queried according to the key, and then the forward traceability pointer is used to query forward from the latest transaction to construct a complete traceability query chain. The index is divided in the form of variable-length groups, and the length of the current index group level is determined by relying on the variable parameter x during construction.
[0024] Beneficial effects
[0025] (1) In the method of the present invention, the entire index structure extends the traditional on-chain structure of the blockchain from two aspects without the need to introduce other off-chain storage tools. These two aspects are: the extension of the leaf nodes of the world state MPT tree (State Trie) and the extension of the transaction structure. Secondly, the index is divided into several levels, with every k indexes forming a group level, where k is a dynamically variable parameter, and the construction of the index depends on this;
[0026] (2) In the method of the present invention, the leaf nodes of the State Trie additionally maintain the latest transaction pointer of the account represented by the node, so that the latest transaction corresponding to the specified key can be queried according to the key;
[0027] (3) In the method of the present invention, the temporal data, i.e., the transaction, maintains multiple time attributes and index attributes. A transaction consists of the following attributes: From represents the transaction initiator; To is the transaction recipient; Value is the transaction amount; SignAttrs represents the signature-related attributes of the transaction; PreFrom and PreTo are two hash pointers, where PreFrom points to the previous transaction of from, and PreTo points to the previous transaction of to; Timestamp is the timestamp when the current transaction is completed. FromStartTime and Timestamp form the time interval in the current partial index of account From; ToStartTime and Timestamp form the time interval in the current partial index of account To; FromFirstIndex and ToFirstIndex respectively represent the first transaction hash of the complete index to which fron and to belong in the current transaction; FromIndexNum and ToIndexNum respectively represent the sequence numbers of the current transaction in the complete indexes to which from and to belong; Others represents other auxiliary attributes during the transaction process, such as transaction remarks, etc.;
[0028] (4) In the method of the present invention, the latest transaction pointer maintained by the State Trie and the forward traceability pointer in the transaction constitute a complete traceability chain; the time attribute of the transaction provides a judgment basis for the range query of the temporal data; the index attributes of the transaction can judge whether the data meets the query conditions in groups, effectively alleviating the problem of too long traceability chain;
[0029] (5) In the method of the present invention, it can adapt to the continuous change of parameter x. For this reason, the construction of the index is based on the real-time x value of the system, while the query is based on the index attributes of the transaction;
[0030] (6) The present invention discloses a method for constructing and querying a verifiable hierarchical index based on blockchain temporal data. First, the present invention defines the research object, i.e., the structural model of temporal data in the blockchain. This structural model is an extension of the traditional blockchain transaction structure. Every x transactions form a complete level of index, where x is a non-fixed parameter that can change continuously during the operation of the system. Specifically, this structure adds a transaction time attribute to the original blockchain transaction structure to identify the temporality of the data; adds a forward traceability pointer for both trading parties to provide a traceability basis for queries; adds an index time interval attribute to provide a judgment basis for range queries; adds an index serial number attribute and an index-level first transaction pointer attribute to improve query efficiency;
[0031] (7) The present invention extends the State Trie in Ethereum and additionally maintains the latest transaction pointer of the account key represented by the node in its leaf nodes, thus forming a complete traceability query chain with the forward traceability pointer in the transaction structure. To meet the flexibility of the system, the present invention uses the currently set parameter x as the judgment basis during the index construction phase and uses the serial number attribute of the temporal data as the judgment basis during the query phase, ensuring the flexible change of the parameter x without affecting the normal operation of the system, and constructing an efficient variable-length hierarchical index structure. The present invention details this index structure and its construction and query methods, providing a new solution for the secure use and efficient query of temporal data in the blockchain. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 is the overall structure diagram of Txchain-index, Figure 1 The top represents the time line, and time flows from left to right. During this period, numerous temporal data are generated, and the parameter x is constantly changing; serial number 3 represents the extended State Trie. According to the given key value, starting from the root, the leaf node where the key is located can be queried, and the latest transaction pointer corresponding to the key: LatestTx is maintained in the leaf node; serial numbers 1 and 2 respectively identify two complete traceability chains, which are composed of LatestTx and the forward traceability pointer in the transaction; the attributes in the transaction are updated and grouped according to the parameter x.
[0033] Figure 2This is a specific example diagram of Txchain-index. The top represents the timeline. Time passes from left to right, and a lot of temporal data is generated during this period. The parameter x is set to 2; serial number 4 represents the extended State Trie. According to the given key value, the query starts from the root and the leaf node where the key is located can be queried. The leaf node maintains the latest transaction pointer corresponding to the key: LatestTx. The figure shows three keys: k1, k2, and k3; serial numbers 1, 2, and 3 respectively identify the complete traceability chain of k1, k2, and k3, which are composed of LatestTx and the forward traceability pointer in the transaction; the attributes in the transaction are updated according to the parameter x, and every 2 are divided into a group level. DETAILED DESCRIPTION
[0034] The present invention is further described in detail with reference to the following specific embodiments and the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0035] like Figure 1 As shown, a method for constructing and querying a verifiable hierarchical index based on blockchain temporal data, the method includes a method for constructing a verifiable hierarchical index based on blockchain temporal data, and also includes a method for querying a verifiable hierarchical index based on blockchain temporal data;
[0036] The steps of the method for constructing a verifiable hierarchical index based on blockchain temporal data include:
[0037] Step 1: The user initiates a blockchain transaction request through the client. When initiating the request, the user needs to provide the hash addresses from and to of both parties to the transaction and the transaction amount value;
[0038] Step 2: After receiving the transaction request, the blockchain system formats the transaction request by assigning it the time attribute Timestamp and the signature information of the user account, and submitting the formatted transaction information;
[0039] Step 3: The blockchain system performs parameter checks on the formatted transaction information. If the check passes, it proceeds to step 4, otherwise the process ends.
[0040] Step 4: The blockchain system queries the world state tree State Trie based on from and to, obtains the corresponding paths of from and to in State Trie, and obtains the latest transactions PreFromTx and PreToTx corresponding to transactions from and to from the leaf nodes;
[0041] Step 5: Determine the transaction roles played by the two parties in their respective latest transactions;
[0042] If it is the initiator from in the transaction role, PreFrom is first updated to PreFromTx found in step 14, and it is determined whether the IndexNum of the transaction role Role1 played by from in PreFromTx is equal to the set parameter k. If IndexNum is equal to the set parameter k, the FromIndexNum of the current transaction is set to 1, FromStartTime is set to the Timestamp of the current transaction, and FromFirstIndex is set to nil; if IndexNum is not equal to the set parameter k, FromIndexNum is increased by 1, FromStartTime uses the previous transaction, if IndexNum is exactly 1, FromFirstIndex is set to PreFrom, otherwise it uses the previous transaction;
[0043] If it is the receiver to in the transaction role, PreTo is first updated to PreToTx found in step 14; determine whether the IndexNum of the transaction role Role2 played by to in PreToTx is equal to the set parameter k. If IndexNum is equal to the set parameter k, set the ToIndexNum of the current transaction to 1, ToStartTime to the Timestamp of the current transaction, and ToFirstIndex to nil. If IndexNum is not equal to the set parameter k, add 1 to ToIndexNum, and use ToStartTime and ToFirstIndex of the previous transaction. If IndexNum is exactly 1, set ToFirstIndex to PreTo, otherwise use the previous transaction.
[0044] Step 6, calculate the unique identification hash value curTx of the transaction, and update the latest transaction maintained in the leaf node of the path corresponding to from and to in the State Trie to curTx.
[0045] Among them, the query method based on the verifiable hierarchical index of blockchain temporal data includes the following steps:
[0046] Step 1: The user initiates a blockchain query request through the client. When initiating the request, the user needs to provide the specified query account key and the query time range.<startTime,endTime> , the client generates a query request according to the standardized format. It is worth noting that the single-value query is a special case of the range query, which is valid when startTime = endTime;
[0047] Step 2: After the blockchain system receives a query request, it verifies whether the parameters are legal. If the parameters are illegal, the request is rejected; otherwise, it queries the extended State Trie to obtain the latest transaction LatestTx of the key and proceeds to Step 3.
[0048] Step 3: Determine the transaction role of the query key in the current transaction. If the transaction role is from: when PreFrom is nil, i.e., there is no previous transaction of the key, the query ends; if the FromStartTime of the transaction <= startTime, it means that after traversing the current transaction index group level, the query ends and there is no need to continue traversing forward. At this time, only the transactions that meet the conditions in this transaction index group level need to be added to the result set according to the Timestamp of the transaction, and the query ends. If the FromStartTime of the transaction > endTime, it means that all transactions in the current transaction index group level do not meet the query requirements. Find the last transaction of the previous transaction index group level according to FirstFromIndex and proceed to Step 4. If the FromStartTime of the transaction is between startTime and endTime, first, all transactions that meet the conditions in the current transaction index group level need to be added to the result set according to the Timestamp of the transaction. Then, judge FirstFromIndex. If FirstFromIndex is not nil, find the last transaction of the previous transaction index group level according to FirstFromIndex; otherwise, find the last transaction of the previous transaction index group level according to PreFrom; proceed to Step 4. If the transaction role is to: when PreTo is nil, i.e., there is no previous transaction of the key, the query ends; if the ToStartTime of the transaction <= startTime, it means that after traversing the current transaction index group level, the query ends and there is no need to continue traversing forward. At this time, only the transactions that meet the conditions in this transaction index group level need to be added to the result set according to the Timestamp of the transaction, and the query ends. If the ToStartTime of the transaction > endTime, it means that all transactions in the current transaction index group level do not meet the query requirements. Find the last transaction of the previous transaction index group level according to FirstToIndex and proceed to Step 4. If the FromToTime of the transaction is between startTime and endTime, first, all transactions that meet the conditions in the current transaction index group level need to be added to the result set according to the Timestamp of the transaction. Then, judge FirstToIndex. If FirstToIndex is not nil, find the last transaction of the previous transaction index group level according to FirstTomIndex; otherwise, find the last transaction of the previous transaction index group level according to PreTo; proceed to Step 4.
[0049] Step 4, repeat Step 3 until the query ends;
[0050] Step 5, the blockchain system outputs the query result set to the user through the client;
[0051] It is worth noting that the index construction method is based on the real-time x value of the system, while the query method is based on the index attributes of the transaction. Therefore, the change of x will not block the construction and query of the index.
[0052] The present invention takes the temporal data in the blockchain as the research object, hereinafter all referred to as transactions. A transaction consists of the following attributes: From represents the transaction initiator; To is the transaction recipient; Value is the transaction amount; SignAttrs represents the signature-related attributes of the transaction; PreFrom and PreTo are two hash pointers, PreFrom points to the previous transaction of from, and PreTo points to the previous transaction of to; Timestamp is the timestamp when the current transaction is completed. The combination of FromStartTime and Timestamp forms the time interval in the current partial index of account From; the combination of ToStartTime and Timestamp forms the time interval in the current partial index of account To; FromFirstIndex and ToFirstIndex respectively represent the first transaction hash of the complete index to which from and to belong in the current transaction, and FromIndexNum and ToIndexNum respectively represent the serial numbers of the current transaction in the complete indexes to which from and to belong; Others represents other auxiliary attributes in the transaction process, such as transaction remarks, etc. The above attributes can be summarized into three parts: basic transaction attributes, time attributes, and index attributes. The basic transaction attributes are the basic components of the transaction and are consistent with traditional blockchain transactions; the time attributes represent the temporality of the data and the characteristics of the research object; the index attributes are the support for efficient query. The transactions form a traceability chain through the forward traceability pointers. However, this traceability chain is incomplete because there is no traceability entry. For this reason, the present invention also expands the leaf nodes of the State Trie. The StateTrie is the world state tree in the blockchain. Given the value of each account, that is, the query key, the latest state corresponding to this key can be found in this MPT tree. The present invention additionally maintains the latest transaction pointer of the account key represented by the node in the leaf node of the State Trie, so that the latest transaction corresponding to the specified key can be queried according to the key, and then the forward traceability pointer is used to query forward from the latest transaction to construct a complete traceability query chain. The index is divided in the form of variable-length groups and depends on the variable parameter x to determine the length of the current index group level during construction.
[0053] Embodiment
[0054] The user initiates 3 transaction requests through the client, and the input parameters are respectively: {k1, k2, 1}, {k1, k3, 2}, and {k2, k1, 3}, where k1, k2, and k3 represent 3 different accounts, and the format is a fixed-length hexadecimal number, e.g., 0x2cf1e19fBc2D121c0F73da26C34baA668781eFeD. The indefinite system parameter x is set to 2. Every time the blockchain system receives a request, it will perform a series of transaction processing, as well as the construction and update of a verifiable hierarchical index structure.
[0055] Figure 2 Among them, the 3 Txs respectively correspond to the 3 requests, and the specific values of Tx1, Tx2, and Tx3 are the transaction hashes of the 3 transactions, e.g.,
[0056] All time-related attributes in the transaction are identified by hexadecimal numbers. First, process Request 1. The Timestamp of Tx1 is 1677211859, and from, to, and Value are the same as the input parameters. Searching the extended State Trie, it is found that Tx1 is the first transaction of k1 and k2. Therefore, both PreFrom and PreTo are set to nil; FromStartTime and ToStartTime are both set to 1677211859; FromFirstIndex and ToFirstIndex are set to nil; FromIndexNum and ToIndexNum are both set to 1. Update the paths of k1 and k2 in the State Trie, and set the latest pointers of the leaf nodes of the two paths to point to the hash pointer of Tx1. Next, process Request 2. The Timestamp of Tx2 is 1677212859, and from, to, and Value are the same as the input parameters. Searching the extended State Trie, it is found that Tx1 is the most recent transaction of k1, and Tx2 is the first transaction of k3. Therefore, PreFrom is set to Tx1 and PreTo is set to nil; FromStartTime follows Tx1, and ToStartTime is set to 1677212859; FromFirstIndex is set to Tx1, and ToFirstIndex is set to nil; FromIndexNum is set to 2, and ToIndexNum is set to 1. Update the paths of k1 and k2 in the State Trie, and set the latest pointers of the leaf nodes of the two paths to point to the hash pointer of Tx2. Finally, process Request 3. The Timestamp of Tx3 is 1677213859, and from, to, and Value are the same as the input parameters. Searching the extended State Trie, it is found that Tx1 is the most recent transaction of k2, and Tx2 is the most recent transaction of k1. Since the previous index number 2 of k1 = x, it indicates that a new set of hierarchical indexes needs to be constructed for k1. Therefore, PreFrom is set to Tx1 and PreTo is set to Tx2; FromStartTime follows Tx1, and ToStartTime is set to 1677213859; FromFirstIndex is set to Tx1, and ToFirstIndex is set to nil; FromIndexNum is set to 2, and ToIndexNum is set to 1. Update the paths of k2 and k1 in the State Trie, and set the latest pointers of the leaf nodes of the two paths to point to the hash pointer of Tx3.
[0057] The user initiates a query request to the client, with the input parameters being {k1, 1677212759, 1677214859}. After the blockchain system receives a legitimate query request, it first queries the extended State Trie based on k1 and obtains the LatestTx of k1 as Tx3; the Timestamp of Tx3 is greater than 1677212759, so the query continues; it is determined that the role of k1 in Tx3 is to, the ToIndexNum is 1, and the Timestamp of Tx3 is between 1677212759 and 1677214859, so Tx3 is added to the result set, and the last transaction in the previous index level group where k1 is located, that is, Tx2 pointed to by PreTo, is found; the Timestamp of Tx2 is greater than 1677212759, so the query continues; it is determined that the role of k1 in Tx2 is from, the FromIndexNum is 2, and the FromStartTime is 1677211859 which is less than 1677212759, indicating that there is no need to continue tracing the previous index group, and only the transactions that meet the conditions in the current index group need to be added to the result set; Tx2 meets the conditions and is added to the result set, and the previous transaction Tx1 at the same index group level is found according to PreFrom for judgment, and it is found that the Timestamp of Tx1 is less than 1677212759, so the query ends; the result set {Tx2, Tx3} is returned to the user through the client.
[0058] The above is the preferred implementation manner of the present invention. It should be pointed out that for those of ordinary skill in the art in this technical field, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements are also regarded as the protection scope of the present invention.
Claims
1. A method for constructing and querying a verifiable hierarchical index based on blockchain temporal data, characterized in that: The method includes a method for constructing a verifiable hierarchical index based on blockchain temporal data, and also includes a method for querying a verifiable hierarchical index based on blockchain temporal data; The steps of the method for constructing a verifiable hierarchical index based on blockchain temporal data include: Step 11: The user initiates a blockchain transaction request through the client; Step 12: After receiving the transaction request, the blockchain system formats the transaction request by assigning it the time attribute Timestamp and the signature information of the user account, and submitting the formatted transaction information; Step 13: The blockchain system performs parameter checks on the formatted transaction information. If the check passes, it proceeds to step 14, otherwise the process ends. Step 14: The blockchain system queries the world state tree State Trie according to from and to, obtains the corresponding paths of from and to in State Trie, and obtains the latest transactions PreFromTx and PreToTx corresponding to transactions from and to from the leaf nodes; Step 15, determining the transaction roles played by the transaction parties in their respective latest transactions; If it is the initiator from in the transaction role, PreFrom is first updated to PreFromTx found in step 14, and it is determined whether the IndexNum of the transaction role Role1 played by from in PreFromTx is equal to the set parameter k. If IndexNum is equal to the set parameter k, the FromIndexNum of the current transaction is set to 1, FromStartTime is set to the Timestamp of the current transaction, and FromFirstIndex is set to nil; if IndexNum is not equal to the set parameter k, FromIndexNum is increased by 1, FromStartTime uses the previous transaction, if IndexNum is exactly 1, FromFirstIndex is set to PreFrom, otherwise it uses the previous transaction; If it is the receiver to in the transaction role, PreTo is first updated to PreToTx found in step 14; determine whether the IndexNum of the transaction role Role2 played by to in PreToTx is equal to the set parameter k. If IndexNum is equal to the set parameter k, set the ToIndexNum of the current transaction to 1, ToStartTime to the Timestamp of the current transaction, and ToFirstIndex to nil; if IndexNum is not equal to the set parameter k, add 1 to ToIndexNum, and use ToStartTime and ToFirstIndex of the previous transaction. If IndexNum is exactly 1, set ToFirstIndex to PreTo, otherwise use the previous transaction; Step 16: Calculate the unique identifier hash value curTx of the transaction, and update the latest transaction maintained in the leaf nodes of the paths corresponding to from and to in the State Trie to curTx; A transaction consists of the following attributes: From represents the transaction initiator; To is the transaction recipient; Value is the transaction amount; SignAttrs represents the signature-related attributes of the transaction; PreFrom and PreTo are two hash pointers, where PreFrom points to the previous transaction of from, and PreTo points to the previous transaction of to; Timestamp is the timestamp when the current transaction is completed. FromStartTime and Timestamp form the time interval in the current partial index of account From; ToStartTime and Timestamp form the time interval in the current partial index of account To; FromFirstIndex and ToFirstIndex respectively represent the first transaction hash of the complete index to which from and to belong in the current transaction, and FromIndexNum and ToIndexNum respectively represent the sequence numbers of the current transaction in the complete indexes to which from and to belong; Others represents other auxiliary attributes during the transaction process.
2. The method for constructing and querying a verifiable hierarchical index based on blockchain temporal data according to claim 1, wherein: In step 11, the transaction request parameters that the user needs to provide when initiating a request include: the hash addresses from and to of the two parties to the transaction and the transaction amount value.
3. The method for constructing and querying a verifiable hierarchical index based on blockchain temporal data according to claim 1 or 2, wherein: The method for querying the verifiable hierarchical index based on blockchain temporal data, the steps of the method include: Step 21: The user initiates a blockchain query request through the client. Step 22: After the blockchain system receives the query request, it verifies whether the parameters are legal. If the parameters are illegal, the request is rejected. If the parameters are legal, it queries the extended State Trie to obtain the latest transaction LatestTx of the query account key and proceeds to step 23; Step 23: Determine the trading role of the query key in the current transaction. If the trading role is "from", then when PreFrom is nil, i.e., there is no more forward transaction for the key, the query ends; if the FromStartTime of the transaction <= startTime, it means that after traversing the current transaction index group level, the query ends and there is no need to continue traversing forward. At this time, only add all transactions that meet the conditions in this transaction index group level to the result set according to the Timestamp of the transaction, and end the query. If the FromStartTime of the transaction > endTime, it means that all transactions in the current transaction index group level do not meet the query requirements. Find the last transaction in the previous transaction index group level according to FirstFromIndex, and enter Step 24. If the FromStartTime of the transaction is between startTime and endTime, first add all transactions that meet the conditions in the current transaction index group level to the result set according to the Timestamp of the transaction. Then, judge FirstFromIndex. If FirstFromIndex is not nil, find the last transaction in the previous transaction index group level according to FirstFromIndex; otherwise, find the last transaction in the previous transaction index group level according to PreFrom; enter Step 24. If the trading role is "to", then when PreTo is nil, i.e., there is no more forward transaction for the key, the query ends; if the ToStartTime of the transaction <= startTime, it means that after traversing the current transaction index group level, the query ends and there is no need to continue traversing forward. At this time, only add all transactions that meet the conditions in this transaction index group level to the result set according to the Timestamp of the transaction, and end the query. If the ToStartTime of the transaction > endTime, it means that all transactions in the current transaction index group level do not meet the query requirements. Find the last transaction in the previous transaction index group level according to FirstToIndex, and enter Step 24. If the FromToTime of the transaction is between startTime and endTime, first add all transactions that meet the conditions in the current transaction index group level to the result set according to the Timestamp of the transaction. Then, judge FirstToIndex. If FirstToIndex is not nil, find the last transaction in the previous transaction index group level according to FirstTomIndex; otherwise, find the last transaction in the previous transaction index group level according to PreTo; enter Step 24; Step 24: Repeat Step 23 until the query ends; Step 25: The blockchain system outputs the query result set to the user through the client.
4. The construction and query method of the verifiable hierarchical index based on blockchain temporal data according to claim 3, characterized in that: In step 21, when initiating the request, the user needs to provide a specified query account key and the query time range <startTime, endTime>, and the client generates a query request according to the standardized format.
5. The method for constructing and querying a verifiable hierarchical index based on blockchain temporal data according to claim 4, wherein: When startTime = endTime in the query time range, it is a single-value query.
6. The method for constructing and querying a verifiable hierarchical index based on blockchain temporal data according to claim 3, wherein: The construction method of the index is based on the real-time x value as the judgment basis, and the query method is based on the index attribute of the transaction as the judgment basis.
7. The method for constructing and querying a verifiable hierarchical index based on blockchain temporal data according to claim 1, wherein: Transaction attributes are classified into three parts: basic transaction attributes, time attributes, and index attributes; The basic transaction attributes are the basic components of the transaction; The time attribute represents the temporality of the data and the characteristics of the research object; The index attribute is the support for efficient query.
8. The method for constructing and querying a verifiable hierarchical index based on blockchain temporal data according to claim 1 or 7, wherein: Transactions form a traceability chain through forward traceability pointers, expand the leaf nodes of the State Trie. The State Trie is the world state tree in the blockchain. Given the value of each account, i.e., the query key, find the latest state corresponding to this key in this MPT tree. Additionally, maintain the latest transaction pointer of the account key represented by this node in the leaf nodes of the State Trie. According to the specified key, query the latest transaction corresponding to this key, and then query forward according to the forward traceability pointer from the latest transaction to construct a complete traceability query chain.
9. The method for constructing and querying a verifiable hierarchical index based on blockchain temporal data according to claim 8, wherein: The index is divided in the form of variable-length group levels, and the length of the current index group level is determined by relying on the variable parameter x during construction.
Citation Information
Patent Citations
Efficient and credible indexing method for block chain data
CN114020737A
Blockchain system and blockchain transaction data processing method based on ethereum
US20210256007A1