WO2021042920A1 - 区块链的数据索引方法、装置、计算机设备和存储介质 - Google Patents

区块链的数据索引方法、装置、计算机设备和存储介质 Download PDF

Info

Publication number
WO2021042920A1
WO2021042920A1 PCT/CN2020/106019 CN2020106019W WO2021042920A1 WO 2021042920 A1 WO2021042920 A1 WO 2021042920A1 CN 2020106019 W CN2020106019 W CN 2020106019W WO 2021042920 A1 WO2021042920 A1 WO 2021042920A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
index
signature
blockchain
uploaded
Prior art date
Application number
PCT/CN2020/106019
Other languages
English (en)
French (fr)
Inventor
鲁铁华
Original Assignee
深圳壹账通智能科技有限公司
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 深圳壹账通智能科技有限公司 filed Critical 深圳壹账通智能科技有限公司
Publication of WO2021042920A1 publication Critical patent/WO2021042920A1/zh

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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • 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/2272Management thereof
    • 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/2282Tablespace storage structures; Management thereof
    • 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/23Updating

Definitions

  • This application relates to the field of distributed ledgers of the blockchain, and in particular to a method, device, computer equipment and storage medium for data indexing of the blockchain.
  • the blockchain In order to facilitate the retrieval of blockchain data, the blockchain usually uses the LevelDB database to index transaction data. From the perspective of the client's execution of smart contracts, the blockchain only supports data queries in the form of key-value pairs by default. Compared with traditional SQL queries, the data retrieval function is still weak.
  • the method of establishing a cache index library is often used to store the index condition data in a relational database.
  • querying data first execute SQL statements on the cache index library to query the data primary key of the data on the blockchain, and then read the data key value corresponding to the data on the blockchain through the data primary key.
  • the inventor realizes that the index data will be inconsistent with the data on the blockchain due to timeout on the chain or other reasons, so the correct data cannot be queried in the blockchain according to the index conditions.
  • this application provides a block chain data indexing method, the method includes:
  • the index data is deleted from the cache index table.
  • the present application also provides a data indexing device for the blockchain, the device including:
  • the target data acquisition module is used to acquire the target data to be written into the blockchain
  • An index data generation module configured to calculate a data signature of the target data, associate the target data with the data signature, and save it in a cache index table to obtain index data corresponding to the target data;
  • the first data generation module is configured to generate data to be uploaded to the chain according to the index data
  • the first data synchronization module is configured to perform an upload operation on the data to be uploaded, and synchronize the data to be uploaded to the blockchain;
  • the index data deletion module is configured to delete the index data from the cache index table if it is determined that the uplink operation fails.
  • this application also provides a computer device, the computer device including a memory and a processor;
  • the memory is used to store a computer program
  • the processor is configured to execute the computer program and implement the following steps when the computer program is executed:
  • the index data is deleted from the cache index table.
  • the present application also provides a computer-readable storage medium, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the following steps:
  • the index data is deleted from the cache index table.
  • FIG. 1 is a schematic flowchart of a method for indexing data on a blockchain provided by an embodiment of the present application
  • FIG. 2 is a schematic flowchart of the sub-steps of generating index data in FIG. 1;
  • Fig. 3 is a schematic flowchart of the sub-steps of generating data to be uploaded in Fig. 1;
  • FIG. 4 is a schematic flowchart of querying blockchain data provided by an embodiment of the present application.
  • Fig. 5 is a schematic flowchart of updating blockchain data provided by an embodiment of the present application.
  • Fig. 6 is a schematic flow chart of verifying the data signature in Fig. 4 or Fig. 5;
  • FIG. 7 is a schematic flowchart of the execution steps after determining that the data signature is incorrect in FIG. 6; FIG.
  • FIG. 8 is a schematic block diagram of a block chain data indexing device provided by an embodiment of the application.
  • FIG. 9 is a schematic block diagram of sub-modules of the data indexing device of the blockchain in FIG. 8;
  • FIG. 10 is a schematic block diagram of sub-modules of the verification module in FIG. 9;
  • FIG. 11 is a schematic block diagram of the structure of a computer device according to an embodiment of the application.
  • the embodiments of the present application provide a data index method, device, computer equipment, and storage medium of a blockchain.
  • the data index method of the block chain can be applied to a terminal or server as a block chain node, so that the index data is consistent with the data on the block chain.
  • the terminal can be a mobile phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant, a wearable device, and other electronic devices;
  • the server can be an independent server or a server cluster.
  • the data index method of the blockchain includes steps S10 to S50.
  • Step S10 Obtain target data to be written into the blockchain.
  • nodes there are multiple nodes in the blockchain system, and the nodes may be computer devices, such as servers or terminals.
  • the node is used to perform operations on the data in the blockchain, for example, synchronize data, update data, delete data, modify data, query data, and so on.
  • the target data includes a data primary key and at least one field data.
  • the node obtains the target data to be written into the blockchain by obtaining the data primary key of the target data and the at least one field data.
  • the primary key of the data may be user:point:1001 or user:point:1002. It should be noted that the data primary key is used to determine the identity of the data, and the data primary key cannot be repeated or empty. For example, user:point:1001 and user:point:1002 are used to identify two different data.
  • the node Before the node writes the target data into the blockchain, it needs to determine the data primary key of the target data.
  • the data whose primary data key is user:point:1003 is written into the blockchain as the target data, and the primary data key of the target data is determined to be user:point:1003.
  • the target data not only includes a data primary key, but also includes at least one field data.
  • the field data includes a field and a value corresponding to the field.
  • the field data may include the following fields and values corresponding to each field: user number USER_ID and value 1003, user name USER_NAME and value Mike, field POINT and value 100.
  • the target data of "the user number is 1003, and the point value of the account with the user name Mike is 100" is written into the blockchain, and the target data is as shown in Table 1:
  • Table 1 is the target data
  • the primary key of the data is user:point:1003
  • the field data includes: USER_ID: 1003, USER_NAME: Mike and POINT: 100.
  • Step S20 Calculate the data signature of the target data, store the target data and the data signature in a cache index table in association with each other to obtain index data corresponding to the target data.
  • the node performs a hash operation on the target data according to a hash algorithm to obtain a data signature of the target data, and the data signature is used to verify whether the index data corresponding to the target data has errors or has been tampered with.
  • the node associates the target data with the data signature and saves it in a cache index table to obtain index data corresponding to the target data.
  • the node may also determine the index identification code corresponding to the target data, and compare the index identification code with the target data, the The data signature is associated and saved in the cache index table.
  • index identification code is used to distinguish different index data in the cache index table, and each index data has a unique corresponding index identification code.
  • Step S30 Generate data to be uploaded based on the index data.
  • the blockchain keeps the records of all transaction changes, and is orderly and tamper-proof.
  • Each transaction chain code needs to record data changes in the blockchain, and the data that needs to be recorded is called the state, which is stored in the form of key-value pairs (K-V).
  • the key-value pair includes a data primary key and a data key value corresponding to the data primary key.
  • the user's point data is stored in the form of key-value pairs on the blockchain, as shown in Table 2:
  • DATA_KEY represents the data primary key
  • DATA_VALUE represents the data key value
  • the data primary key may be user:point:1001 or user:point:1002, and the data key value may be ⁇ "USER_ID”:1001, “USER_NAME”: “Tom”, "point”: 100 ⁇ Or ⁇ "USER_ID”:1002,"USER_NAME":"Jack”,”point”:200 ⁇ .
  • the data key value corresponding to the data primary key and the data primary key is an index relationship, and the data key value corresponding to the data primary key can be obtained through the data primary key.
  • the data key value may be a simple value, or may be composed of a group of complex data.
  • the data key value may be 100; the data key value may also include fields USER_ID and USER_ID corresponding values 1003, fields USER_NAME and USER_NAME corresponding values Mike, and fields POINT and POINT corresponding values 100.
  • the node since data needs to be written into the blockchain in the form of key-value pairs, the node needs to generate data to be uploaded to the chain including the data primary key and the data key value according to the index data.
  • the node extracts the data primary key of the target data in the index data to determine the data primary key of the data to be uploaded, and extracts the field data of the target data in the index data and the data in the index data.
  • the data signature determines the data key value of the data to be uploaded, and finally constructs a key-value pair according to the determined data primary key and the data key value to obtain the data to be uploaded.
  • Step S40 Perform an upload operation on the data to be uploaded, and synchronize the data to be uploaded to the blockchain.
  • the node performs an upload operation on the data to be uploaded, and synchronizes the data to be uploaded to the blockchain.
  • the uploading operation refers to the operation of putting the data to be uploaded into the disk queue to be written. After the data to be uploaded is put into the disk queue to be written, it is sequentially written to the blockchain.
  • the blockchain feeds back a status value indicating the result of the uplink operation.
  • the status value of the blockchain feedback is 0, indicating that the upload operation is successful; if the data to be uploaded is not successfully saved to On the block chain, the state value of the block chain feedback is 1, indicating that the chain operation failed.
  • the node determines that the uplink operation is successful; the node marks the validity state of the index data as valid, for example, the validity of the index data
  • the state DIRTY_FLAG is marked as 0; if the state value of the blockchain feedback is 1, the node determines that the on-chain operation has failed; the node marks the validity state of the index data as invalid, for example, the index data
  • the validity status DIRTY_FLAG is marked as 1.
  • the marked index data is as shown in Table 3:
  • Table 3 shows the marked index data
  • the validity status DIRTY_FLAG is 0, indicating that the index data is valid.
  • index data consistent with the blockchain data can be generated. Ensure the accuracy of the blockchain data index; by receiving the state value fed back by the blockchain after the chaining operation, it can be determined whether the chaining operation is successful or not according to the state value.
  • Step S50 If it is determined that the uplink operation fails, delete the index data from the cache index table.
  • the node judges whether the link is successful according to the state value fed back by the blockchain.
  • the node determines that the chaining operation has failed, and performs a rollback operation.
  • the received status value is 1, the possible reason is that the data to be uploaded to the chain has not been successfully written into the blockchain.
  • the rollback refers to the behavior of restoring the program or data to the last correct state due to an error in the program or data processing.
  • the rollback includes program rollback and data rollback.
  • the node deletes the index data from the cache index table by performing a data rollback operation, so as to restore the cache index table to its original state, avoiding the failure of the on-chain operation, according to the index data
  • a data rollback operation so as to restore the cache index table to its original state, avoiding the failure of the on-chain operation, according to the index data
  • the block chain data indexing method calculates the data signature of the target data that needs to be written to the block chain, and associates the target data with the data signature and saves it in the cache index table to obtain the index data corresponding to the target data; Generate the data to be uploaded to the blockchain according to the index data, so that it can be written to the blockchain; perform the upload operation on the data to be uploaded, and synchronize the data to be uploaded to the blockchain; so as to achieve the goal of writing the target data to the blockchain At the time, the index data consistent with the blockchain data can be generated to ensure the accuracy of the blockchain data index; if it is determined that the on-chain operation fails, the index data is deleted from the cache index table to ensure that the index data in the cache index table The authenticity and reliability of index data.
  • FIG. 2 is a schematic diagram of calculating the data signature of the target data in step S20, and storing the target data and the data signature in a cache index table in association with each other to obtain the index data corresponding to the target data. Specifically, it includes the following steps S21 to S23.
  • Step S21 Determine the index identification code of the target data.
  • the node determines the index identification code corresponding to the target data, and the index identification code is used to uniquely determine the index data corresponding to the target data.
  • the index identification code may be a unique index identification code generated by a self-incrementing primary key or a UUID (Universally Unique Identifier) function, which is used to distinguish different index data in the cache index table.
  • UUID Universal Unique Identifier
  • the self-incrementing primary key automatically increments and fills in the index identification code of the previous index data in the cache index table in a way of generating an index identification code, can be automatically numbered, and is fast; the self-incrementing primary key At the same time, it is stored in order, which is very beneficial for retrieval, and there is no need to worry about the duplication of index identification codes.
  • the UUID function can generate a unique index identification code in time and space, and can ensure the uniqueness of the index identification code.
  • the index identification code includes a 32-bit character string.
  • an 8-bit character string abbreviation is used instead of the value of the index identification code.
  • Table 4 shows the new data inserted into the cache index table
  • REDO_UUID represents an index identification code
  • an 8-bit character string REDO1003 is used to replace the value of the index identification code.
  • Step S22 Calculate the data signature of the target data according to the hash algorithm.
  • the node calculates a hash value of the target data according to a hash algorithm, and the obtained hash value is a data signature of the target data.
  • the hash algorithm can calculate a fixed-length character string from a message of a certain length, and the hash algorithm can be SHA-1, SHA-224, SHA-256, SHA-384 or SHA-512 Wait.
  • the node uses the SHA-256 algorithm to calculate the data signature of the target data, and obtains the hash value of the 64-bit character string as the data signature corresponding to the target data.
  • an 8-bit string abbreviation such as SIGN1003, replaces the value of the data signature.
  • the node uses the SHA-256 algorithm to calculate the data signature of the target data, and according to the data signature, it can quickly discover whether the target data has changed. For example, if the target data is tampered with or timed out and other reasons cause a slight change, the calculated hash value will change significantly. Therefore, by calculating the data signature of the target data, it is possible to quickly discover whether the target data has changed.
  • the target data is: ⁇ "USER_ID”: 1003, “USER_NAME”: “Mike”, “POINT”: 100, "DATA_KEY”: “user:point: 1003” ⁇ , calculate the The hash value of the target data to obtain the hash value 75a6ae14b40de30b7821a5ad90cb0d86791167c11d0834e30a99e205baeb5446 of the target data is the data signature of the target data.
  • the hash value of the target data is calculated again, and the hash value of the target data is b68e02aac9888448ab8136f2cdcf1bf78e5b8e2902419b73d6f51a7ed9fdb291, so by verifying the data signature of the target data, It can be found whether the target data has changed.
  • Step S23 Associate and save the index identification code with the target data and the data signature in a cache index table to generate index data corresponding to the target data.
  • the index data has a one-to-one correspondence with the data signature.
  • the node associates the index identification code with the target data and the data signature and stores them in the corresponding position of the cache index table to obtain the index data corresponding to the target data, as shown in Table 5:
  • Table 5 shows the index data
  • DATA_SIGN represents a data signature
  • the data signature of the index data is SIGN1003.
  • FIG. 3 is a schematic diagram of generating data to be uploaded according to the index data in step S30, which specifically includes the following steps S31 to S33.
  • Step S31 Determine the data primary key of the data to be uploaded according to the data primary key of the target data in the index data.
  • the node extracts the data primary key of the target data in the index data. Since step S10 obtains the target data to be written to the blockchain, the target data includes a data primary key and at least one field data, therefore, the node can obtain the to-be-linked chain by extracting the data primary key corresponding to the target data The data primary key of the data.
  • the node may determine that the data primary key of the data to be uploaded is user:point:1003.
  • Step S32 Determine the data key value of the data to be uploaded according to the field data of the target data in the index data and the data signature.
  • the data to be uploaded is a key-value pair, it includes a data primary key and a data key value corresponding to the data primary key. Therefore, in addition to determining the data primary key of the data to be uploaded, the node also determines the data key value of the data to be uploaded.
  • the data key value of the data to be uploaded includes the field data of the target data and the data signature corresponding to the index data.
  • the node can obtain several field data corresponding to the target data.
  • the field data obtained by the node is ⁇ "USER_ID”: 1003 , “USER_NAME”: “Mike", "point”: 100 ⁇ .
  • step S20 calculates the data signature of the target data and obtains the data signature corresponding to the index data
  • the node can obtain the data signature corresponding to the index data.
  • the node acquires the data signature as SIGN1003.
  • the node may obtain the data key value of the data to be uploaded according to the acquired data signatures of the several fields and the index data.
  • the node generates a data key value of the data to be uploaded, and the data key value includes multiple key-value pairs, for example, ⁇ "USER_ID”:1003, “USER_NAME”:"Mike”,”POINT “:100,”DATA_SIGN”:"SIGN1003” ⁇ .
  • Step S33 Generate the data to be uploaded according to the data primary key and the data key value of the data to be uploaded.
  • the node stores the data to be uploaded in the form of key-value pairs according to the data primary key determined in step S31 and the data key value of the data to be uploaded determined in step S32 to obtain the data to be uploaded, as shown in Table 6. Shown:
  • Table 6 is the data to be chained
  • DATA_KEY represents the data primary key of the data to be uploaded
  • DATA_VALUE represents the data key value of the data to be uploaded
  • the data primary key value corresponding to the data primary key can be found in the blockchain data: ⁇ "USER_ID”: 1003, “USER_NAME”: “Mike”, “POINT”:100,”DATA_SIGN”:"SIGN1003" ⁇ .
  • the data to be uploaded including the data primary key and data key value according to the data primary key and field data of the target data in the index data, and the data signature of the index data, it can be ensured that the data to be uploaded is the key value
  • the correct form is written into the blockchain.
  • the node performs an upload operation on the data to be uploaded, and after synchronizing the data to be uploaded to the blockchain, it can also query the data on the blockchain, as shown in Figure 4 As shown, it specifically includes the following steps S61 to S64.
  • Step S61 Obtain a query instruction corresponding to the field to be queried, and query the index data corresponding to the field to be queried in the cache index table.
  • the query instruction may be an instruction input by the user or a corresponding instruction generated by other programs.
  • the query instruction is used to specify the field to be queried.
  • the field to be queried may be at least one of user number USER_ID, user name USER_NAME, point point, or data signature DATA_SIGN.
  • a query instruction includes the field to be queried, the user name Mike and the points POINT
  • Table 7 shows the index data corresponding to the field to be queried
  • the user name USER_NAME is Mike, and the points POINT is 100.
  • Step S62 Verify whether the data signature in the index data is correct.
  • the node calculates the data signature of the target data in the index data, if the calculated data signature is inconsistent with the data signature associated with the target data, or the data signature associated with the target data is consistent with the blockchain
  • the data signatures corresponding to the target data are inconsistent, and it is determined that the data signatures in the index data in the cache index table are incorrect.
  • the node reads the corresponding data from the blockchain according to the data primary key corresponding to the index data to update the index data.
  • the node Before querying the field to be queried, the node can promptly discover whether the index data has errors or has been tampered by verifying whether the data signature in the index data is correct, so as to avoid unindexing from the blockchain. To the correct data.
  • Step S63 If the data signature in the index data is correct, determine the data key value corresponding to the data primary key in the blockchain according to the data primary key in the index data.
  • the node determines the index data The data in the signature is correct.
  • the node can index the data key corresponding to the data primary key according to the data primary key in the index data value.
  • the data primary key in the index data is user:point:1003. Since there is a data primary key that is consistent with the index data on the blockchain, the node can use user:point:1003 to learn from the Obtain the data key value corresponding to user:point:1003 on the blockchain.
  • Step S64 Determine the value corresponding to the field to be queried from the data key value.
  • the data key value corresponding to user:point:1003 determined by the node is ⁇ "USER_ID”:1003, “USER_NAME”: “Mike”, “POINT”: 100, "DATA_SIGN”: “SIGN1003” ⁇ ,
  • the node determines from the determined data key value: ⁇ "USER_ID”: 1003, “USER_NAME”: “Mike”, “POINT”: 100, "DATA_SIGN”: “SIGN1003” ⁇ to determine the corresponding field to be queried Value.
  • the node may determine that the value corresponding to the field USER_ID to be queried is 1003; if the field to be queried is POINT, the node may determine that the field to be queried is POINT The corresponding value is 100.
  • the node performs an upload operation on the data to be uploaded, and after synchronizing the data to be uploaded to the blockchain, the data on the blockchain can also be updated, as shown in Figure 5 As shown, it specifically includes the following steps S71 to S76.
  • Step S71 Obtain the update instruction corresponding to the field to be updated, and query the index data corresponding to the field to be updated in the cache index table.
  • update instruction may be an instruction input by the user or a corresponding instruction generated by other programs.
  • the update instruction is used to specify the field to be updated.
  • the field to be updated may include at least one of a user number USER_ID, a user name USER_NAME, a point point, or a data signature DATA_SIGN.
  • Table 8 shows the index data of the field to be updated
  • the POINT of user Mike is 100.
  • Step S72 Verify whether the data signature in the index data is correct.
  • the node calculates the data signature of the target data in the index data, if the calculated data signature is inconsistent with the data signature associated with the target data, or the data signature associated with the target data is consistent with the blockchain
  • the data signatures corresponding to the target data are inconsistent, and it is determined that the data signatures in the index data in the cache index table are incorrect.
  • the node reads the corresponding data from the blockchain according to the data primary key corresponding to the index data to cover the index data.
  • the node Before updating the to-be-updated field of the data to be indexed, the node can find out whether the index data has errors or has been tampered in time by verifying whether the data signature in the index data is correct, so as to ensure the integrity of the index data. Authenticity and reliability. It can be avoided that after the field to be updated is updated in the index data, there are other field data errors in the index data.
  • Step S73 If the data signature in the index data is correct, update the field to be updated in the index data according to the update instruction, and update the data signature in the index data based on the updated field.
  • step S72 verifies whether the data signature in the index data is correct, if the data signature in the index data is verified to be correct, the node updates the field to be updated in the index data.
  • the node executes an update (Update) statement on the index data corresponding to the field to be updated to obtain updated index data.
  • Update update
  • Update statement is used to update the index data in the cache index table.
  • Table 9 shows the updated index data
  • the integral POINT is updated to 200, and the validity status DIRTY_FLAG is updated to 1.
  • the validity status DIRTY_FLAG corresponding to the updated index data is updated to 1, indicating that the index data is invalid.
  • the node updates the field to be updated to the index data, it recalculates the data signature in the index data.
  • the node recalculates the data signature corresponding to the target data in the updated index data according to the SHA-256 algorithm to obtain the digitally signed index data, as shown in Table 10:
  • Table 10 shows the index data after signing
  • the value corresponding to the data signature DATA_SIGN is SIGN2003.
  • Step S74 Generate the data to be uploaded according to the updated index data.
  • the node determines the data primary key of the data to be uploaded according to the data primary key of the updated index data, and determines the data to be uploaded according to the field data and data signature of the updated index data The data key value of the data.
  • the node stores the data in the form of key-value pairs according to the determined data primary key and data key value of the data to be uploaded to obtain the data to be uploaded, as shown in Table 11:
  • Table 11 shows the data to be uploaded
  • the data primary key of the data to be uploaded is user:point:1003, and the data key value is ⁇ "USER_ID”:1003, “USER_NAME”:”Mike", “POINT”:200, "DATA_SIGN”:”SIGN2003 " ⁇ .
  • Step S75 Perform an upload operation on the data to be uploaded, and synchronize the data to be uploaded to the blockchain.
  • step S74 Since step S74 generates the data to be uploaded according to the updated index data, the node performs an upload operation on the data to be uploaded, and synchronizes the data to be uploaded to the blockchain.
  • the node puts the data to be uploaded into the disk queue to be written, and the data to be uploaded is written into the blockchain.
  • the data to be chained By putting the data to be chained into the disk queue to be written, the data to be chained can be written into the block chain, and index data consistent with the block chain data can be generated to ensure the area The accuracy of the blockchain data index.
  • the node updates the validity status DIRTY_FLAG corresponding to the index data to 0 to indicate that the index data is valid, as shown in Table 12:
  • Table 12 shows the index data after signing
  • Step S76 If it is determined that the linking operation has failed, restore the updated index data to the index data before the update.
  • the node After the node synchronizes the data to be uploaded to the blockchain, it receives the state value fed back by the blockchain, and judges whether the uploading operation is successful according to the state value.
  • the node determines that the on-chain operation has failed, the node performs a data rollback operation, and restores the updated index data to the index data before the update, and the obtained index data As shown in Table 13:
  • Table 13 shows the restored index data
  • the integral POINT is restored to 100, the data signature DATA_SIGN is restored to SIGN1003, and the validity status DIRTY_FLAG is restored to 0.
  • the index data that still has other errors is synchronized to the blockchain.
  • FIG. 6 is a schematic diagram of verifying whether the data signature in the index data is correct in step S62 or step S72, which specifically includes the following steps S81 to S83.
  • step S62 verifies whether the data signature in the index data is correct, so as to ensure the consistency of the index data and the blockchain data.
  • step S72 verifies whether the data signature in the index data is correct, and it can be found in time whether the index data has errors or has been tampered with, so as to ensure the authenticity and authenticity of the index data. reliability.
  • Step S81 Calculate the data signature of the target data in the index data, and compare the calculated data signature with the data signature associated with the target data in the index data.
  • the node performs a hash calculation on the target data according to the SHA-256 algorithm, and the calculated hash value is a data signature of the target data.
  • the node compares the calculated data signature with the data signature associated with the target data in the index data.
  • the data signature associated with the target data in the index data is SIGN1003.
  • the hash value of the target data is calculated, and the hash value of the target data is obtained as SIGN1003, that is, the calculated data signature is SIGN1003, and the data associated with the target data
  • the signatures are the same. If the index data is incorrect or tampered with, the hash value of the target data is calculated, and the hash value obtained is different from the data signature associated with the target data. For example, the hash value of the target data is calculated as SIGN1024 .
  • SIGN1003 and SIGN1024 represent the abbreviations of 64-bit character strings.
  • Step S82 Compare the data signature associated with the target data in the index data with the data signature corresponding to the target data in the blockchain.
  • step S40 performs an upload operation on the data to be uploaded, and synchronizes the data to be uploaded to the blockchain, data corresponding to the index data exists on the blockchain.
  • the node obtains the data signature corresponding to the target data in the blockchain, and compares the obtained data signature with the data signature associated with the target data in the index data.
  • the data signature corresponding to the target data obtained by the node from the blockchain is SIGN1003
  • the data signature associated with the target data in the index data is SIGN1003
  • the data signature corresponding to the target data obtained by the node from the blockchain is SIGN1051
  • SIGN1051 it means that the index data is inconsistent with the data on the blockchain, and the possible cause It is that the index data is not successfully synchronized to the blockchain during the chaining operation.
  • SIGN1003 and SIGN1051 represent the abbreviations of 64-bit character strings.
  • Step S83 If the calculated data signature is consistent with the data signature associated with the target data, and the data signature associated with the target data is consistent with the data signature in the blockchain, determine the data signature in the index data correct.
  • step S81 compares the data signature of the target data in the index data with the data signature associated with the target data in the index data, the node can determine the data signature of the target data in the index data and the data signature of the target data in the index data. Whether the data signatures associated with the target data are consistent.
  • step S82 compares the data signature associated with the target data in the index data with the data signature corresponding to the target data in the blockchain, the node can determine the data associated with the target data in the index data Whether the signature is consistent with the data signature corresponding to the target data in the blockchain.
  • the node determines that the index data The data signature is correct.
  • the node can determine that the data signature in the index data is correct.
  • SIGN1003 represents the abbreviation of 64-bit character string.
  • Step S84 If the calculated data signature is inconsistent with the data signature associated with the target data, or the data signature associated with the target data is inconsistent with the data signature in the blockchain, determine the data signature in the index data Incorrect.
  • the node may determine that the data signature in the index data is incorrect.
  • the node may also determine the index data The data signature in is incorrect.
  • SIGN1024, SIGN1003, and SIGN1051 represent the abbreviations of 64-bit character strings.
  • FIG. 7 is a schematic diagram of steps performed after determining that the data signature in the index data is incorrect in step S84, and specifically includes the following steps S85 to S87.
  • Step S85 Mark the validity status corresponding to the index data as invalid.
  • step S84 Since it is determined in step S84 that the data signature in the index data is incorrect, the node marks the validity status of the index data as invalid.
  • the node determines that the data signature in the index data is incorrect, for example, the data signature is SIGN1024, and the data signature associated with the target data is inconsistent with SIGN1003, the node changes the index
  • the validity status DIRTY_FLAG of the data is set to 1, and the validity status DIRTY_FLAG is 1 indicating that the index data is invalid; at this time, the index data is as shown in Table 14:
  • Table 14 is invalid index data
  • the data signature DATA_SIGN is SIGN1024, and the validity status DIRTY_FLAG is 1.
  • Step S86 Read the data key value corresponding to the data primary key from the blockchain according to the data primary key in the index data, and update the index data according to the data key value.
  • the data primary key in the index data is user:point:1003. Since there is a data primary key that is consistent with the index data on the blockchain, the node can use user:point:1003 to learn from the Obtain the data key value corresponding to the data primary key on the blockchain.
  • the node obtains the data key value corresponding to the data primary key from the blockchain through user:point:1003 ⁇ "USER_ID”: 1003, “USER_NAME”: “Mike”,” POINT”:100,”DATA_SIGN”:"SIGN1003” ⁇ , update the index data according to the data key value to obtain the updated index data, as shown in Table 15:
  • Table 15 shows the updated index data
  • the data signature DATA_SIGN is SIGN1003
  • the validity status DIRTY_FLAG is 1.
  • Step S87 Mark the validity status corresponding to the index data as valid.
  • the validity status corresponding to the index data is marked as valid.
  • the node sets the validity status DIRTY_FLAG of the index data to 0, and the validity status DIRTY_FLAG of 0 indicates that the index data is valid, and the obtained index data is shown in Table 16:
  • Table 16 is valid index data
  • the validity status DIRTY_FLAG is 0, indicating that the index data is valid.
  • the erroneous data in the index data can be covered, and the index data can be ensured to be consistent with the blockchain data.
  • the validity status of the index data it is indicated that the index data is valid data without errors.
  • the node After determining the success of the chaining operation, the node records a log of the success of the chaining operation.
  • the log includes number, operation type, data type, operation data, operation status, etc.
  • the node inserts the operation status STATUS into the corresponding position of the system log, and sets the operation status STATUS to 1, and the operation status STATUS is 1 to indicate that the chaining operation is successful, and the chaining success log table is obtained, as shown in Table 17:
  • Table 17 is the log table of successful winding
  • REDO_TYPE represents the operation type, and the operation type may include INSERT corresponding to inserted data, UPDATE corresponding to update data, DELETE corresponding to delete data, or QUERY corresponding to query data;
  • REDO_DATA represents operation data.
  • the node After judging that the on-chain operation fails, the node records the operation failure log in the log. For example, in the system log, the operation status STATUS is set to 0, indicating that the winding operation failed; at the same time, the error code ERR_CODE and the error message ERR_MSG are inserted into the corresponding position of the log, and the winding failure log table is obtained, as shown in Table 18:
  • Table 18 shows the log of failures on the chain
  • the error code ERR_CODE is 10001
  • the error message ERR_MSG is ⁇ "userId”:1003, “userName”: “Mike”, “point”: 100, "dataSign”: “SIGN1003” ⁇ .
  • the node also regularly checks whether the index data is consistent with the blockchain data, for example, checks whether the data primary key of the index data is consistent with the data primary key of the data on the blockchain through a set timing task.
  • the timing task can be executed in batches to check the data primary key of the index data. For example, by adding a timestamp to the data primary key of the index data, the data of a certain time range can be checked at one time. Primary key.
  • the time stamp is a character sequence, which can uniquely identify the time of a certain moment.
  • the node performs a data rollback operation to convert the index
  • the data is deleted from the cache index table, and then the node synchronizes the blockchain data to the cache index table to ensure that the index data in the cache index table is consistent with the same piece of data on the blockchain.
  • the wrong index data can be found in time. If the wrong index data is checked, delete the wrong index data from the cache index table, and synchronize the blockchain data to the cache index table, which can ensure the authenticity and reliability of the index data in the cache index table Sex.
  • the block chain data indexing method synchronizes the data to be uploaded to the blockchain by performing an on-chain operation on the data to be on-chain, so as to realize that when the target data is written into the blockchain, it can generate
  • the index data consistent with the blockchain data ensures the accuracy of the blockchain data index; by verifying whether the data signature in the index data is correct, the authenticity and reliability of the data in the cache index table can be guaranteed; If the data signature is incorrect, read the data key value corresponding to the data primary key from the blockchain according to the data primary key in the index data, and update the index data according to the data key value, which can ensure that the index data is The data on the blockchain is kept consistent to avoid indexing to get wrong data.
  • FIG. 8 is a schematic block diagram of a block chain data indexing device provided by an embodiment of the present application.
  • the block chain data indexing device is used to execute the aforementioned block chain data indexing method.
  • the data indexing device of the blockchain can be configured in a server or a terminal.
  • the data indexing device 100 of the blockchain includes: a target data acquisition module 101, an index data generation module 102, a first data generation module 103, a first data synchronization module 104 and an index data deletion module 105.
  • the target data acquisition module 101 is used to acquire target data to be written into the blockchain.
  • the index data generation module 102 is configured to calculate a data signature of the target data, associate the target data with the data signature, and save it in a cache index table to obtain index data corresponding to the target data.
  • the first data generating module 103 is configured to generate data to be uploaded to the link according to the index data.
  • the first data synchronization module 104 is configured to perform an upload operation on the data to be uploaded, and synchronize the data to be uploaded to the blockchain.
  • the index data deletion module 105 is configured to delete the index data from the cache index table if it is determined that the uplink operation fails.
  • the first data generation module 103 includes: a data primary key determination submodule 1031, a data key value determination submodule 1032, and a first data generation submodule 1033.
  • the data primary key determining submodule 1031 is configured to determine the data primary key of the data to be uploaded to the link according to the data primary key of the target data in the index data.
  • the data key value determining sub-module 1032 is configured to determine the data key value of the data to be uploaded according to the field data of the target data in the index data and the data signature.
  • the first data generation sub-module 1033 is configured to generate the data to be uploaded according to the data primary key and the data key value of the data to be uploaded.
  • the blockchain data indexing device 100 further includes: a first index query module 201, a first verification module 202, a data key value determination module 203 and a field value determination module 204.
  • the first index query module 201 is configured to obtain a query instruction corresponding to the field to be queried, and query the index data corresponding to the field to be queried in the cache index table.
  • the first verification module 202 is used to verify whether the data signature in the index data is correct.
  • the data key value determining module 203 is configured to determine the data key value corresponding to the data primary key in the blockchain according to the data primary key in the index data if the data signature in the index data is correct.
  • the field value determining module 204 is configured to determine the value corresponding to the field to be queried from the data key value.
  • the data indexing device 100 of the blockchain further includes: a second index query module 301, a second verification module 302, an update module 303, a second data generation module 304, and a second The data synchronization module 305 and the data recovery module 306.
  • the second index query module 301 is configured to obtain the update instruction corresponding to the field to be updated, and query the index data corresponding to the field to be updated in the cache index table.
  • the second verification module 302 is used to verify whether the data signature in the index data is correct.
  • the update module 303 is configured to update the field to be updated in the index data according to the update instruction if the data signature in the index data is correct, and update the data in the index data based on the updated field data signature.
  • the second data generating module 304 is configured to generate the data to be uploaded according to the updated index data.
  • the second data synchronization module 305 is configured to perform an upload operation on the data to be uploaded, and synchronize the data to be uploaded to the blockchain.
  • the data recovery module 306 is configured to restore the index data after the update to the index data before the update if it is determined that the linking operation fails.
  • the first verification module 202 or the second verification module 302 each includes: a calculation sub-module 401, a comparison sub-module 402, a determination sub-module 403, an update sub-module 404, and a marking sub-module Module 405.
  • the calculation sub-module 401 is configured to calculate the data signature of the target data in the index data, and compare the calculated data signature with the data signature associated with the target data in the index data.
  • the comparison sub-module 402 is configured to compare the data signature associated with the target data in the index data with the data signature corresponding to the target data in the blockchain.
  • the determination sub-module 403 is configured to determine the index data if the calculated data signature is consistent with the data signature associated with the target data, and the data signature associated with the target data is consistent with the data signature in the blockchain.
  • the data signature in is correct; it is also used to determine if the calculated data signature is inconsistent with the data signature associated with the target data, or the data signature associated with the target data is inconsistent with the data signature in the blockchain.
  • the data signature in the index data is incorrect.
  • the update sub-module 404 is configured to read the data key value corresponding to the data primary key from the blockchain according to the data primary key in the index data if the data signature in the index data is incorrect, and according to the data The data key value updates the index data.
  • the marking submodule 405 is configured to mark the validity status corresponding to the index data as invalid if the data signature in the index data is incorrect; for after the index data is updated according to the data key value, Marking the validity status corresponding to the index data as valid; and also used to mark the validity status corresponding to the index data as valid if it is determined that the on-chain operation is successful.
  • the method and device of the present application can be used in many general or special computing system environments or configurations.
  • the above-mentioned method and device can be implemented in the form of a computer program, and the computer program can be run on the computer device as shown in FIG. 11.
  • FIG. 11 is a schematic block diagram of a structure of a computer device provided by an embodiment of the present application.
  • the computer device may be a server.
  • the computer device includes a processor and a memory connected through a system bus, where the memory may include a non-volatile or volatile storage medium and an internal memory.
  • the processor is used to provide computing and control capabilities and support the operation of the entire computer equipment.
  • the internal memory provides an environment for the operation of the computer program in the non-volatile or volatile storage medium.
  • the processor can execute any block chain data indexing method.
  • the processor may be a central processing unit (Central Processing Unit, CPU), and the processor may also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), and application specific integrated circuits (Application Specific Integrated Circuits). Circuit, ASIC), off-the-shelf programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc.
  • the general-purpose processor may be a microprocessor or the processor may also be any conventional processor.
  • the processor is used to run a computer program stored in a memory to implement the following steps:
  • the target data to be written to the blockchain calculate the data signature of the target data, associate the target data with the data signature and save it in the cache index table to obtain the index data corresponding to the target data;
  • the index data generates the data to be uploaded; the upload operation is performed on the data to be uploaded, and the data to be uploaded is synchronized to the blockchain; if it is determined that the upload operation fails, the index data is removed from Delete from the cache index table.
  • the processor when the processor realizes generating the data to be uploaded according to the index data, it is used to realize:
  • the processor realizes the synchronization of the data to be uploaded to the blockchain, it is further used to realize:
  • Obtain the query instruction corresponding to the field to be queried query the index data corresponding to the field to be queried in the cache index table; verify whether the data signature in the index data is correct; if the data signature in the index data is correct , According to the data primary key in the index data, determine the data key value corresponding to the data primary key in the blockchain; determine the value corresponding to the field to be queried from the data key value.
  • the processor realizes the synchronization of the data to be uploaded to the blockchain, it is further used to realize:
  • Obtain the update instruction corresponding to the field to be updated query the index data corresponding to the field to be updated in the cache index table; verify whether the data signature in the index data is correct; if the data signature in the index data is correct , Update the field to be updated in the index data according to the update instruction, and update the data signature in the index data based on the updated field data; generate the data to be uploaded according to the updated index data;
  • the data to be uploaded performs an upload operation, and the data to be uploaded is synchronized to the blockchain; if it is determined that the upload operation fails, the updated index data is restored to the index data before the update.
  • the processor verifies whether the data signature in the index data is correct, it is used to implement:
  • Calculate the data signature of the target data in the index data compare the calculated data signature with the data signature associated with the target data in the index data; compare the data signature associated with the target data in the index data with the The data signature corresponding to the target data in the blockchain is compared; if the calculated data signature is consistent with the data signature associated with the target data, and the data signature associated with the target data is the same as that in the blockchain If the data signature is consistent, it is determined that the data signature in the index data is correct; if the calculated data signature is inconsistent with the data signature associated with the target data, or the data signature associated with the target data is consistent with the data in the blockchain If the signatures are inconsistent, it is determined that the data signature in the index data is incorrect.
  • the processor verifies whether the data signature in the index data is correct, it is further used to implement:
  • the processor realizes the synchronization of the data to be uploaded to the blockchain, it is further used to realize:
  • the validity status corresponding to the index data is marked as valid.
  • the processor verifies whether the data signature in the index data is correct, it is further used to implement:
  • the processor after the processor implements updating the index data according to the data key value, it is further configured to implement:
  • the validity status corresponding to the index data is marked as valid.
  • the embodiments of the present application also provide a computer-readable storage medium.
  • the computer-readable storage medium may be volatile or non-volatile.
  • the computer-readable storage medium stores a computer program.
  • the computer program includes program instructions, and the processor executes the program instructions to implement any one of the blockchain data indexing methods provided in the embodiments of the present application.
  • the computer-readable storage medium may be the internal storage unit of the computer device described in the foregoing embodiment, for example, the hard disk or memory of the computer device.
  • the computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart media card (SMC), or a secure digital card equipped on the computer device. , SD Card, Flash Card, etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种区块链的数据索引方法、装置、计算机设备和存储介质,该方法包括:获取待写入区块链的目标数据(S10);计算目标数据的数据签名,将目标数据与数据签名关联保存至缓存索引表中,得到目标数据对应的索引数据(S20);根据索引数据生成待上链数据(S30);对待上链数据执行上链操作,将待上链数据同步到区块链中(S40);若判定上链操作失败,将索引数据从缓存索引表中删除(S50)。该方法通过将索引数据同步到区块链中,实现在将目标数据写入区块链时,可以生成与区块链数据一致的索引数据,保证区块链数据索引的准确性。

Description

区块链的数据索引方法、装置、计算机设备和存储介质
本申请要求于2019年9月6日提交中国专利局、申请号为CN201910851500.9、名称为“区块链的数据索引方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及区块链的分布式账本领域,尤其涉及一种区块链的数据索引方法、装置、计算机设备和存储介质。
背景技术
为了方便检索区块链数据,区块链通常使用LevelDB数据库对交易数据进行索引。从客户端执行智能合约的角度来看,区块链默认仅支持键值对形式的数据查询,与传统SQL查询相比较,数据检索功能仍然较弱。
为了支持查询更复杂的数据,常常采用建立缓存索引库的方法,将索引条件数据存储到关系型数据库中。在查询数据时,先在缓存索引库上执行SQL语句查询到区块链上的数据的数据主键,然后再通过数据主键读取区块链上的数据对应的数据键值。发明人意识到由于上链超时或其他原因会导致索引数据和区块链上的数据不一致,因此根据索引条件在区块链中查询不到正确的数据。
发明内容
第一方面,本申请提供了一种区块链的数据索引方法,所述方法包括:
获取待写入区块链的目标数据;
计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据;
根据所述索引数据生成待上链数据;
对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
第二方面,本申请还提供了一种区块链的数据索引装置,所述装置包括:
目标数据获取模块,用于获取待写入区块链的目标数据;
索引数据生成模块,用于计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据;
第一数据生成模块,用于根据所述索引数据生成待上链数据;
第一数据同步模块,用于对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
索引数据删除模块,用于若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
第三方面,本申请还提供了一种计算机设备,所述计算机设备包括存储器和处理器;
所述存储器,用于存储计算机程序;
所述处理器,用于执行所述计算机程序并在执行所述计算机程序时实现如下步骤:
获取待写入区块链的目标数据;
计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据;
根据所述索引数据生成待上链数据;
对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
第四方面,本申请还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时使所述处理器实现下步骤:
获取待写入区块链的目标数据;
计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据;
根据所述索引数据生成待上链数据;
对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
附图说明
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本申请的实施例提供的一种区块链的数据索引方法的示意流程图;
图2是图1中生成索引数据的子步骤示意流程图;
图3是图1中生成待上链数据的子步骤示意流程图;
图4是本申请的实施例提供的查询区块链数据的示意流程图;
图5是本申请的实施例提供的更新区块链数据的示意流程图;
图6为图4或图5中验证数据签名的示意流程图;
图7为图6中判定数据签名不正确后的执行步骤的示意流程图;
图8为本申请实施例提供的一种区块链的数据索引装置的示意性框图;
图9为图8中区块链的数据索引装置的子模块的示意性框图;
图10为图9中验证模块的子模块的示意性框图;
图11为本申请实施例提供的一种计算机设备的结构示意性框图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
附图中所示的流程图仅是示例说明,不是必须包括所有的内容和操作/步骤,也不是必须按所描述的顺序执行。例如,有的操作/步骤还可以分解、组合或部分合并,因此实际执行的顺序有可能根据实际情况改变。
应当理解,在此本申请说明书中所使用的术语仅仅是出于描述特定实施例的目的而并不意在限制本申请。如在本申请说明书和所附权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。
还应当理解,在本申请说明书和所附权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。
本申请的实施例提供了一种区块链的数据索引方法、装置、计算机设备和存储介质。其中,该区块链的数据索引方法可以应用于作为区块链节点的终端或服务器中,实现索引数据与区块链上的数据保持一致。
其中,终端可以是手机、平板电脑、笔记本电脑、台式电脑、个人数字助理和穿戴式设备等电子设备;服务器可以为独立的服务器,也可以为服务器集群。
下面结合附图,对本申请的一些实施方式作详细说明。在不冲突的情况下,下述的实施例及实施例中的特征可以相互组合。
如图1所示,区块链的数据索引方法包括步骤S10至步骤S50。
步骤S10、获取待写入区块链的目标数据。
示例性的,区块链***中存在多个节点,所述节点可以是计算机设备,比如服务器或终端。
所述节点用于对区块链中的数据进行操作,例如,同步数据,更新数据、删除数据、修改数据、查询数据等。
具体地,所述目标数据包括数据主键和至少一个字段数据。所述节点通过获取所述目标数据的数据主键,以及所述至少一个字段数据,以得到所述待写入区块链的目标数据。
示例性的,在用户积分的数据中,所述数据主键可以是user:point:1001或user:point:1002。需要说明的是,所述数据主键用于确定数据的标识,所述数据主键不能有重复的也不允许为空,例如,user:point:1001、user:point:1002用于标识两条不同的数据。
具体地,所述节点将目标数据写入所述区块链之前,要确定所述目标数据的数据主键。在本实 施例中,将数据主键为user:point:1003的数据作为目标数据写入所述区块链中,则确定所述目标数据的数据主键为user:point:1003。
具体地,所述目标数据除了包括数据主键,还包括至少一个字段数据。所述字段数据包括字段和所述字段对应的值。
在本实施例中,所述字段数据可以包括以下字段和各字段对应的值:用户编号USER_ID和值1003、用户名称USER_NAME和值Mike、字段POINT和值100。
示例性的,将“用户编号为1003,用户名称为Mike的账户的积分值为100”的目标数据写入所述区块链,则所述目标数据如表1所示:
表1为目标数据
USER_ID USER_NAME POINT DATA_KEY
1003 Mike 100 user:point:1003
表中,数据主键为user:point:1003,字段数据包括:USER_ID:1003、USER_NAME:Mike和POINT:100。
步骤S20、计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据。
所述节点根据哈希算法对所述目标数据进行哈希运算,得到所述目标数据的数据签名,所述数据签名用于验证所述目标数据对应的索引数据是否出现错误或被篡改。所述节点将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据。
具体地,在所述节点计算所述目标数据的数据签名之前或之后,所述节点还可以确定所述目标数据对应的索引识别码,并将所述索引识别码与所述目标数据、所述数据签名一起关联保存至缓存索引表中。
需要说明的是,所述索引识别码用于区分缓存索引表中不同的索引数据,每个索引数据都有唯一对应的索引识别码。
步骤S30、根据所述索引数据生成待上链数据。
需要说明的是,在区块链***中,区块链保存着所有交易变化的记录,具备有序和防篡改的特点。每一次交易链码需要将数据变化记录在所述区块链中,需要记录的数据称为状态,以键值对(K-V)的形式进行存储。
具体地,所述键值对包括数据主键和所述数据主键对应的数据键值。
示例性的,在区块链上以键值对的方式存储用户的积分数据,如表2所示:
表2为积分数据
DATA_KEY DATA_VALUE
user:point:1001 {"USER_ID":1001,"USER_NAME":"Tom","point":100}
user:point:1002 {"USER_ID":1002,"USER_NAME":"Jack","point":200}
表中,DATA_KEY表示数据主键,DATA_VALUE表示数据键值。
示例性的,所述数据主键可以是user:point:1001或user:point:1002,所述数据键值可以是{"USER_ID":1001,"USER_NAME":"Tom","point":100}或{"USER_ID":1002,"USER_NAME":"Jack","point":200}。
需要说明的是,所述数据主键与所述数据主键对应的数据键值为索引关系,通过所述数据主键,可以获取与所述数据主键对应的数据键值。
示例性的,所述数据键值可以是一个简单的值,也可以由一组复杂数据组成。例如,所述数据键值可以是100;所述数据键值还可以包括字段USER_ID以及USER_ID对应的值1003、字段USER_NAME以及USER_NAME对应的值Mike、字段POINT以及POINT对应的值100。
具体地,由于数据需要以键值对的形式写入所述区块链中,因此所述节点需要根据索引数据生成包括数据主键和数据键值的待上链数据。
在本实施例中,所述节点提取所述索引数据中目标数据的数据主键确定所述待上链数据的数据主键,以及提取所述索引数据中目标数据的字段数据和所述索引数据中的数据签名确定所述待上链 数据的数据键值,最后根据确定的所述数据主键和所述数据键值构造成一个键值对,得到所述待上链数据。
步骤S40、对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中。
具体的,所述节点对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中。
需要说明的是,所述上链操作是指将所述待上链数据放入待写入磁盘队列中的操作。所述待上链数据放入所述待写入磁盘队列后,会被依次写入所述区块链中。
具体地,所述节点对所述待上链数据执行上链操作后,所述区块链反馈一个用于表示上链操作结果的状态值。
具体地,若所述待上链数据成功保存到所述区块链上,则所述区块链反馈的状态值为0,表示上链操作成功;若所述待上链数据未成功保存到所述区块链上,则所述区块链反馈的状态值为1,表示上链操作失败。
示例性的,若所述区块链反馈的状态值为0,则所述节点判定上链操作成功;所述节点将所述索引数据的有效性状态标记为有效,例如将索引数据的有效性状态DIRTY_FLAG标记为0;若所述区块链反馈的状态值为1,则所述节点判定上链操作失败;所述节点将所述索引数据的有效性状态标记为无效,例如将索引数据的有效性状态DIRTY_FLAG标记为1。
其中索引数据的有效性状态DIRTY_FLAG为0时表示所述索引数据是有效的,有效性状态DIRTY_FLAG为1时表示所述索引数据是无效的。
在一些实施例中,若所述节点判定上链操作成功时,标记后的所述索引数据如表3所示:
表3为标记后的索引数据
Figure PCTCN2020106019-appb-000001
表中,有效性状态DIRTY_FLAG为0,表示所述索引数据是有效的。
通过先根据需要写入所述区块链的目标数据生成索引数据,然后将根据索引数据构造的待上链数据写入所述区块链中,可以生成与区块链数据一致的索引数据,确保区块链数据索引的准确性;通过在上链操作后接收所述区块链反馈的状态值,可以根据所述状态值判断上链操作是否成功。
步骤S50、若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
具体地,所述节点根据所述区块链反馈的状态值判断是否上链成功。
具体地,若所述节点接收到的状态值为1,则所述节点判定上链操作失败,执行回滚操作。示例性的,若接收到的状态值为1,可能原因是所述待上链数据没有成功写入所述区块链中。
需要说明的是,所述回滚是指程序或数据处理出现错误,将程序或数据恢复到上一次正确状态的行为。所述回滚包括程序回滚和数据回滚等类型。
具体地,所述节点通过执行数据回滚操作,将所述索引数据从所述缓存索引表中删除,以将所述缓存索引表恢复到原来状态,避免上链操作失败后,在根据索引数据进行索引时,从所述区块链上索引不到对应的数据的情况,保证缓存索引表中数据的真实性和可靠性。
上述实施例提供的区块链的数据索引方法,通过计算需要写入区块链的目标数据的数据签名,将目标数据与数据签名关联保存至缓存索引表中,得到目标数据对应的索引数据;根据索引数据生成待上链数据,以便于写入区块链中;对待上链数据执行上链操作,将待上链数据同步到区块链中;从而实现在将目标数据写入区块链时,可以生成与区块链数据一致的索引数据,保证区块链数据索引的准确性;若判定上链操作失败,将索引数据从所述缓存索引表中删除,可以保证缓存索引表中的索引数据的真实性和可靠性。
请参阅图2,图2是步骤S20中计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据的示意图,具体包括以下步骤S21至步骤S23。
步骤S21、确定所述目标数据的索引识别码。
所述节点确定所述目标数据对应的索引识别码,所述索引识别码用于唯一确定所述目标数据对应的索引数据。
具体的,所述索引识别码可以是自增主键或者UUID(Universally Unique Identifier)函数生成的唯一性的索引识别码,用于区分缓存索引表中不同的索引数据。
需要说明的是,所述自增主键以生成索引识别码的方式,自动根据所述缓存索引表中前一索引数据的索引识别码自增填充,能够自动编号,速度快;所述自增主键同时按顺序存放,对检索非常有利,不用担心索引识别码重复问题。
需要说明的是,所述UUID函数可以生成时间、空间上独一无二的索引识别码,能够保证所述索引识别码的唯一性。
具体的,所述索引识别码包括32位字符串。在本实施例中,为方便说明,使用8位字符串缩写代替所述索引识别码的值。
具体地,根据目标数据和目标数据对应的索引识别码,在缓存索引表中***一条新数据,如表4所示:
表4为***缓存索引表的新数据
USER_ID USER_NAME POINT DATA_KEY REDO_UUID
1003 Mike 100 user:point:1003 REDO1003
表中,REDO_UUID表示索引识别码,使用8位字符串REDO1003代替所述索引识别码的值。
步骤S22、根据哈希算法计算所述目标数据的数据签名。
具体地,所述节点根据哈希算法计算所述目标数据的哈希值,得到的哈希值为所述目标数据的数据签名。
需要说明的是,所述哈希算法能将一定长度的消息计算得到固定长度的字符串,所述哈希算法可以为SHA-1、SHA-224、SHA-256、SHA-384或SHA-512等。
在本实施例中,所述节点采用SHA-256算法计算所述目标数据的数据签名,得到64位字符串的哈希值作为所述目标数据对应的数据签名。为方便说明,以8位字符串缩写,如SIGN1003代替所述数据签名的值。
具体地,所述节点采用SHA-256算法计算所述目标数据的数据签名,根据所述数据签名可以快速发现所述目标数据是否发生变化。例如,若所述目标数据被篡改或超时等原因导致发生微小变化,计算出的哈希值会产生明显变化。因此,通过计算所述目标数据的数据签名可以快速发现所述目标数据是否发生变化。
当所述目标数据发生微小改动时,计算得到的哈希值发生明显变化,且没有规律。在一些实施例中,若所述目标数据为:{"USER_ID":1003,"USER_NAME":"Mike","POINT":100,"DATA_KEY":"user:point:1003"},计算所述目标数据的哈希值,得到所述目标数据的哈希值75a6ae14b40de30b7821a5ad90cb0d86791167c11d0834e30a99e205baeb5446为所述目标数据的数据签名。若将所述目标数据中积分POINT从100修改为200,重新对所述目标数据进行哈希值计算,得到所述目标数据的哈希值为b68e02aac9888448ab8136f2cdcf1bf78e5b8e2902419b73d6f51a7ed9fdb291,因此通过验证所述目标数据的数据签名,可以发现所述目标数据是否发生变化。
步骤S23、将所述索引识别码与所述目标数据、所述数据签名一起关联保存至缓存索引表中,以生成所述目标数据对应的索引数据。
具体地,所述索引数据与所述数据签名一一对应。
具体地,所述节点将所述索引识别码与所述目标数据、所述数据签名一起关联存储在缓存索引表的相应位置,得到所述目标数据对应的索引数据,如表5所示:
表5为索引数据
Figure PCTCN2020106019-appb-000002
表中,DATA_SIGN表示数据签名,所述索引数据的数据签名为SIGN1003。
请参阅图3,图3是步骤S30中根据所述索引数据生成待上链数据的示意图,具体包括以下步骤S31至步骤S33。
步骤S31、根据所述索引数据中目标数据的数据主键确定所述待上链数据的数据主键。
具体地,所述节点提取所述索引数据中目标数据的数据主键。由于步骤S10获取待写入区块链的目标数据,所述目标数据包括数据主键和至少一个字段数据,因此,所述节点通过提取所述目 标数据对应的数据主键,可以得到所述待上链数据的数据主键。
示例性的,若所述目标数据对应的数据主键为user:point:1003,则所述节点可以确定所述待上链数据的数据主键为user:point:1003。
步骤S32、根据所述索引数据中目标数据的字段数据,以及所述数据签名确定所述待上链数据的数据键值。
由于所述待上链数据为一个键值对,包括数据主键和所述数据主键对应的数据键值。因此,所述节点除了确定所述待上链数据的数据主键,还要确定所述待上链数据的数据键值。
具体地,所述待上链数据的数据键值包括所述目标数据的字段数据以及所述索引数据对应的数据签名。
由于上述步骤S10确定所述目标数据的若干字段数据,因此所述节点可以得到所述目标数据对应的若干字段数据。
在一些实施例中,若所述目标数据的若干字段数据包括字段USER_ID和值1003、字段USER_NAME和值Mike、字段POINT和值100,则所述节点获取到的字段数据为{"USER_ID":1003,"USER_NAME":"Mike","point":100}。
由于步骤S20计算所述目标数据的数据签名,得到所述索引数据对应的数据签名,因此,所述节点可以获取所述索引数据对应的数据签名。
在一些实施例中,若所述索引数据对应的数据签名为SIGN1003,则所述节点获取所述数据签名为SIGN1003。
具体地,所述节点根据获取的所述若干字段数据和所述索引数据对应的数据签名,可以得到所述待上链数据的数据键值。
示例性的,所述节点生成所述待上链数据的数据键值,所述数据键值包括多个键值对,例如,{"USER_ID":1003,"USER_NAME":"Mike","POINT":100,"DATA_SIGN":"SIGN1003"}。
步骤S33、根据所述待上链数据的数据主键和数据键值生成所述待上链数据。
具体地,所述节点根据步骤S31确定的所述数据主键和步骤S32确定的所述待上链数据的数据键值,以键值对的形式存储,得到所述待上链数据,如表6所示:
表6为待上链数据
Figure PCTCN2020106019-appb-000003
表中,DATA_KEY表示所述待上链数据的数据主键,DATA_VALUE表示所述待上链数据的数据键值。
具体的,根据所述数据主键与所述数据键值之间的索引关系,将所述待上链数据写入所述区块链后,可以通过所述数据主键查找到所述区块链中与所述数据主键对应的数据键值。例如,通过所述数据主键的值user:point:1003可以在所述区块链数据中查找到所述数据主键对应的数据键值:{"USER_ID":1003,"USER_NAME":"Mike","POINT":100,"DATA_SIGN":"SIGN1003"}。
通过根据所述索引数据中目标数据的数据主键和字段数据,以及所述索引数据的数据签名,确定包括数据主键和数据键值的待上链数据,可以保证所述待上链数据以键值对的形式写入所述区块链中。
具体地,所述节点对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中之后,还可以查询所述区块链上的数据,如图4所示,具体包括以下步骤S61至步骤S64。
步骤S61、获取待查询字段对应的查询指令,在所述缓存索引表中查询与所述待查询字段对应的索引数据。
需要说明的是,所述查询指令可以是用户输入的指令或者其他程序生成的相应指令。
具体地,所述查询指令用于指定待查询字段。例如,所述待查询字段可以是用户编号USER_ID、用户名称USER_NAME、积分POINT或数据签名DATA_SIGN等中的至少一项。
在本实施例中,某查询指令包括待查询字段用户名称Mike和积分POINT,则所述节点执行选择语句:Select*from user_point where user_name='Mike',从缓存索引表中选择用户Mike所在的索引数据,得到所述查询指令中待查询字段对应的索引数据,如表7所示:
表7为待查询字段对应的索引数据
Figure PCTCN2020106019-appb-000004
表中,用户名称USER_NAME为Mike,积分POINT为100。
步骤S62、验证所述索引数据中的数据签名是否正确。
具体地,所述节点计算所述索引数据中目标数据的数据签名,若计算得到的数据签名和所述目标数据关联的数据签名不一致,或者所述目标数据关联的数据签名和所述区块链中该目标数据对应的数据签名不一致,判定缓存索引表中所述索引数据中的数据签名不正确。
若所述索引数据中的数据签名不正确,可以判定所述索引数据是无效的。
具体的,若所述索引数据中的数据签名不正确,则所述节点根据所述索引数据对应的数据主键,从所述区块链中读取相应的数据,以更新所述索引数据。
在查询所述待查询字段之前,所述节点通过验证所述索引数据中的数据签名是否正确,可以及时地发现所述索引数据是否出现错误或被篡改,避免从所述区块链上索引不到正确的数据。
步骤S63、若所述索引数据中的数据签名正确,根据所述索引数据中的数据主键,确定所述区块链中与所述数据主键对应的数据键值。
具体地,若计算得到的数据签名和所述目标数据关联的数据签名一致,且所述目标数据关联的数据签名和所述区块链中的数据签名一致,则所述节点判定所述索引数据中的数据签名正确。
具体地,由于所述区块链中数据的数据主键和数据键值是键值对的形式,因此所述节点根据所述索引数据中的数据主键,可以索引与所述数据主键对应的数据键值。
示例性的,所述索引数据中数据主键为user:point:1003,由于所述区块链上存在与所述索引数据一致的数据主键,则所述节点可以通过user:point:1003从所述区块链上获取与user:point:1003对应的数据键值。
步骤S64、从所述数据键值中确定与所述待查询字段对应的值。
示例性的,所述节点确定的与user:point:1003对应的数据键值为{"USER_ID":1003,"USER_NAME":"Mike","POINT":100,"DATA_SIGN":"SIGN1003"},所述节点从确定的所述数据键值:{"USER_ID":1003,"USER_NAME":"Mike","POINT":100,"DATA_SIGN":"SIGN1003"},确定所述待查询字段对应的值。例如,若所述待查询字段为USER_ID,则所述节点可以确定所述待查询字段USER_ID对应的值为1003;若所述待查询字段为POINT,则所述节点可以确定所述待查询字段POINT对应的值为100。
具体地,所述节点对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中之后,还可以更新所述区块链上的数据,如图5所示,具体包括以下步骤S71至步骤S76。
步骤S71、获取待更新字段对应的更新指令,在所述缓存索引表中查询与所述待更新字段对应的索引数据。
需要说明的是,所述更新指令可以是用户输入的指令或者其他程序生成的相应指令。
具体地,所述更新指令用于指定待更新字段。例如,所述待更新字段可以包括用户编号USER_ID、用户名称USER_NAME、积分POINT或数据签名DATA_SIGN中的至少一项。
在本实施例中,某更新指令包括待更新字段用户名称Mike和积分POINT,则所述节点执行选择语句:Select*from user_point where user_name='Mike',从缓存索引表中选择用户Mike所在的索引数据,得到所述更新指令中待更新字段对应的索引数据,如表8所示:
表8为待更新字段的索引数据
Figure PCTCN2020106019-appb-000005
表中,用户Mike的积分POINT为100。
步骤S72、验证所述索引数据中的数据签名是否正确。
具体地,所述节点计算所述索引数据中目标数据的数据签名,若计算得到的数据签名和所述目标数据关联的数据签名不一致,或者所述目标数据关联的数据签名和所述区块链中该目标数据对应的数据签名不一致,判定缓存索引表中所述索引数据中的数据签名不正确。
若所述索引数据中的数据签名不正确,可以判定所述索引数据是无效的。
具体的,若所述索引数据中的数据签名不正确,则所述节点根据所述索引数据对应的数据主键,从所述区块链中读取相应的数据,以覆盖所述索引数据。
在更新所述待索引数据的待更新字段之前,所述节点通过验证所述索引数据中的数据签名是否正确,可以及时地发现所述索引数据是否出现错误或被篡改,保证所述索引数据的真实性和可靠性。可以避免在所述索引数据中更新所述待更新字段后,所述索引数据还存在其他字段数据错误。
步骤S73、若所述索引数据中的数据签名正确,根据所述更新指令对所述索引数据中的待更新字段进行更新,并基于更新后的字段更新所述索引数据中的数据签名。
由于步骤S72验证所述索引数据中的数据签名是否正确,因此,若所述索引数据中的数据签名经过验证是正确的,则所述节点对所述索引数据中的待更新字段进行更新。
示例性的,所述节点对所述待更新字段对应的索引数据执行更新(Update)语句,得到更新后的索引数据。
需要说明的是,所述Update语句用于更新缓存索引表中的索引数据。
在一些实施例中,若需要更新用户Mike的积分数据,将待更新字段POINT的值从100增加到200,可以使用“Update user_point set point=point+100where user_name='Mike'”语句实现,得到更新后的索引数据如表9所示:
表9为更新后的索引数据
Figure PCTCN2020106019-appb-000006
表中,积分POINT更新为200,有效性状态DIRTY_FLAG更新为1。
需要说明的是,由于更新后的索引数据还没有同步到所述区块链中,因此将所述更新后的索引数据对应的有效性状态DIRTY_FLAG更新为1,表示所述索引数据是无效的。
具体地,所述节点将所述待更新字段更新到所述索引数据之后,重新计算所述索引数据中的数据签名。
在一些实施例中,所述节点根据SHA-256算法重新计算所述更新后的索引数据中目标数据对应的数据签名,以得到数字签名后的索引数据,如表10所示:
表10为签名后的索引数据
Figure PCTCN2020106019-appb-000007
表中,数据签名DATA_SIGN对应的值为SIGN2003。
步骤S74、根据更新后的索引数据生成待上链数据。
具体地,所述节点根据所述更新后的索引数据的数据主键确定所述待上链数据的数据主键,以及根据所述更新后的索引数据的字段数据以及数据签名,确定所述待上链数据的数据键值。
具体地,所述节点根据确定的所述待上链数据的数据主键和数据键值,以键值对的形式存储,得到所述待上链数据,如表11所示:
表11为待上链数据
Figure PCTCN2020106019-appb-000008
表中,所述待上链数据的数据主键为user:point:1003,数据键值为{"USER_ID":1003,"USER_NAME":"Mike","POINT":200,"DATA_SIGN":"SIGN2003"}。
步骤S75、对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中。
由于步骤S74根据更新后的索引数据生成待上链数据,因此所述节点对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中。
具体地,所述节点将所述待上链数据放入待写入磁盘队列中,所述待上链数据被写入所述区块链中。
通过将所述待上链数据放入所述待写入磁盘队列中,实现将所述待上链数据写入所述区块链中, 可以生成与区块链数据一致的索引数据,保证区块链数据索引的准确性。
若上链操作成功,所述节点将所述索引数据对应的有效性状态DIRTY_FLAG更新为0,以表示所述索引数据是有效的,如表12所示:
表12为签名后的索引数据
Figure PCTCN2020106019-appb-000009
步骤S76、若判定上链操作失败,将更新后的索引数据恢复为更新前的索引数据。
具体地,所述节点将所述待上链数据同步到所述区块链后,接收到所述区块链反馈的状态值,并根据所述状态值判断上链操作是否成功。
示例性的,若接收到的状态值为1,则所述节点判定上链操作失败,所述节点执行数据回滚操作,将更新后的索引数据恢复为更新前的索引数据,得到的索引数据如表13所示:
表13为恢复的索引数据
Figure PCTCN2020106019-appb-000010
表中,积分POINT恢复为100,数据签名DATA_SIGN恢复为SIGN1003,有效性状态DIRTY_FLAG恢复为0。
通过验证所述索引数据中的数据签名是否正确,可以及时地发现所述索引数据是否出现错误或被篡改,保证所述索引数据的真实性和可靠性,避免更新所述索引数据中的待更新字段后,将还存在其它错误的索引数据同步到所述区块链中。
请参阅图6,图6是步骤S62或步骤S72中验证所述索引数据中的数据签名是否正确的示意图,具体包括以下步骤S81至步骤S83。
在查询所述区块链上的数据时,上述步骤S62验证所述索引数据中的数据签名是否正确,以确保所述索引数据与区块链数据的一致性。
在更新所述区块链的数据时,上述步骤S72验证所述索引数据中的数据签名是否正确,可以及时地发现所述索引数据是否出现错误或被篡改,保证所述索引数据的真实性和可靠性。
步骤S81、计算所述索引数据中目标数据的数据签名,将计算得到的数据签名和所述索引数据中所述目标数据关联的数据签名进行比较。
具体地,所述节点根据SHA-256算法对所述目标数据进行哈希计算,计算得到的哈希值为所述目标数据的数据签名。所述节点将计算得到的数据签名和所述索引数据中所述目标数据关联的数据签名进行比较。
示例性的,所述索引数据中所述目标数据关联的数据签名为SIGN1003。
示例性的,如果所述索引数据没有发生变化,计算所述目标数据的哈希值,得到所述目标数据的哈希值为SIGN1003,即计算得到的数据签名为SIGN1003,与目标数据关联的数据签名相同。如果所述索引数据出现错误或被篡改,计算所述目标数据的哈希值,得到的哈希值与所述目标数据关联的数据签名不同,例如,计算所述目标数据的哈希值为SIGN1024。
需要说明的是,SIGN1003、SIGN1024表示64位字符串的缩写。
步骤S82、将所述索引数据中目标数据关联的数据签名和所述区块链中与所述目标数据对应的数据签名进行比较。
由于步骤S40对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中,因此,所述区块链上存在与所述索引数据对应的数据。
具体地,所述节点获取所述区块链中与所述目标数据对应的数据签名,将获取的所述数据签名与所述索引数据中目标数据关联的数据签名进行比较。
在一些实施例中,若所述节点从所述区块链中获取与所述目标数据对应的数据签名为SIGN1003,所述索引数据中所述目标数据关联的数据签名为SIGN1003,则说明所述索引数据正确同步到所述区块链中。
在一些实施例中,若所述节点从所述区块链中获取与所述目标数据对应的数据签名为SIGN1051,则说明所述索引数据与所述区块链上的数据不一致,可能的原因是在上链操作时,所述索引数据未成功同步到所述区块链中。
需要说明的是,SIGN1003、SIGN1051表示64位字符串的缩写。
步骤S83、若计算得到的数据签名和所述目标数据关联的数据签名一致,且所述目标数据关联的数据签名和所述区块链中的数据签名一致,判定所述索引数据中的数据签名正确。
由于步骤S81将所述索引数据中目标数据的数据签名和所述索引数据中所述目标数据关联的数据签名进行比较,因此所述节点可以判定所述索引数据中目标数据的数据签名和所述目标数据关联的数据签名是否一致。
由于步骤S82将所述索引数据中目标数据关联的数据签名和所述区块链中与所述目标数据对应的数据签名进行比较,因此所述节点可以判定所述索引数据中目标数据关联的数据签名和所述区块链中与所述目标数据对应的数据签名是否一致。
具体地,若计算得到的数据签名和所述目标数据关联的数据签名一致,且所述目标数据关联的数据签名和所述区块链中的数据签名一致,所述节点判定所述索引数据中的数据签名正确。
在一些实施例中,若计算得到的数据签名为SIGN1003,所述索引数据中目标数据关联的数据签名为SIGN1003,且所述区块链中获取与所述目标数据对应的数据签名为SIGN1003,所述节点可以判定所述索引数据中的数据签名是正确的。
需要说明的是,SIGN1003表示64位字符串的缩写。
步骤S84、若计算得到的数据签名和所述目标数据关联的数据签名不一致,或者所述目标数据关联的数据签名和所述区块链中的数据签名不一致,判定所述索引数据中的数据签名不正确。
示例性的,若计算得到的数据签名为SIGN1024,所述索引数据中目标数据关联的数据签名为SIGN1003,则所述节点可以判定所述索引数据中的数据签名是不正确的。
示例性的,若所述目标数据关联的数据签名为SIGN1003,所述节点从所述区块链中获取与所述目标数据对应的数据签名为SIGN1051,则所述节点也可以判定所述索引数据中的数据签名是不正确的。
需要说明的是,SIGN1024、SIGN1003、SIGN1051表示64位字符串的缩写。
请参阅图7,图7是步骤S84判定所述索引数据中的数据签名不正确之后执行步骤的示意图,具体还包括以下步骤S85至步骤S87。
步骤S85、将所述索引数据对应的有效性状态标记为无效。
由于步骤S84判定所述索引数据中的数据签名是不正确的,因此所述节点将所述索引数据的有效性状态标记为无效。
示例性的,若所述节点判定所述索引数据中的数据签名不正确,例如,所述数据签名为SIGN1024,与所述目标数据关联的数据签名为SIGN1003不一致,则所述节点将所述索引数据的有效性状态DIRTY_FLAG置1,有效性状态DIRTY_FLAG为1表示所述索引数据是无效的;此时,所述索引数据如表14所示:
表14为无效的索引数据
Figure PCTCN2020106019-appb-000011
表中,数据签名DATA_SIGN为SIGN1024,有效性状态DIRTY_FLAG为1。
步骤S86、根据所述索引数据中的数据主键从所述区块链中读取所述数据主键对应的数据键值,并根据所述数据键值更新所述索引数据。
示例性的,所述索引数据中数据主键为user:point:1003,由于所述区块链上存在与所述索引数据一致的数据主键,则所述节点可以通过user:point:1003从所述区块链上获取与所述数据主键对应的数据键值。
在一些实施例中,所述节点通过user:point:1003从所述区块链上获取与所述数据主键对应的数据键值为{"USER_ID":1003,"USER_NAME":"Mike","POINT":100,"DATA_SIGN":"SIGN1003"},根据所述数据键值更新所述索引数据,得到更新后的索引数据,如表15所示:
表15为更新后的索引数据
Figure PCTCN2020106019-appb-000012
表中,数据签名DATA_SIGN为SIGN1003,有效性状态DIRTY_FLAG为1。
步骤S87、将所述索引数据对应的有效性状态标记为有效。
具体地,所述节点根据所述数据键值更新所述索引数据之后,将所述索引数据对应的有效性状态标记为有效。
示例性的,所述节点将所述索引数据的有效性状态DIRTY_FLAG置0,有效性状态DIRTY_FLAG为0表示所述索引数据为有效,得到的索引数据如表16所示:
表16为有效的索引数据
Figure PCTCN2020106019-appb-000013
表中,有效性状态DIRTY_FLAG为0,表示所述索引数据是有效的。
通过读取所述数据主键对应的数据键值,更新所述索引数据,可以覆盖所述索引数据中错误的数据,确保所述索引数据与所述区块链数据保持一致。通过更新所述索引数据的有效性状态,表示所述索引数据是没有存在错误的有效数据。
具体的,在判定上链操作成功之后,所述节点记录上链操作成功日志。所述日志包括编号、操作类型、数据类型、操作数据和操作状态等。
具体的,所述节点将操作状态STATUS******日志的相应位置,并将操作状态STATUS置1,操作状态STATUS为1表示上链操作成功,得到上链成功日志表,如表17所示:
表17为上链成功日志表
Figure PCTCN2020106019-appb-000014
表中,REDO_TYPE表示操作类型,所述操作类型可以包括对应于***数据的INSERT、对应于更新数据的UPDATE、对应于删除数据的DELETE或对应于查询数据的QUERY;REDO_DATA表示操作数据。
具体的,在判断上链操作失败之后,所述节点在日志中记录操作失败日志。例如,在***日志中将操作状态STATUS置0,表示上链操作失败;同时,将错误码ERR_CODE和错误信息ERR_MSG***到日志的相应位置,得到上链失败日志表,如表18所示:
表18为上链失败日志表
Figure PCTCN2020106019-appb-000015
表中,错误码ERR_CODE为10001,错误信息ERR_MSG为{"userId":1003,"userName":"Mike","point":100,"dataSign":"SIGN1003"}。
具体地,所述节点还定时检查索引数据与区块链数据是否一致,例如,通过设定的定时任务检查索引数据的数据主键与区块链上数据的数据主键是否一致。
具体的,若缓存索引表中索引数据过多,所述定时任务可以分批次执行检查索引数据的数据主键,例如,在索引数据的数据主键中增加时间戳,可以一次检查一定时间范围的数据主键。
具体的,所述时间戳是一个字符序列,可以唯一地标识某一刻的时间。
示例性的,若在区块链上不存在数据主键与所述索引数据的数据主键一致的数据,则判定所述索引数据是错误的;所述节点通过执行数据回滚操作,将所述索引数据从缓存索引表中删除,然后所述节点将区块链数据同步至所述缓存索引表,以确保所述缓存索引表中的索引数据与区块链上同一条数据是一致的。
通过定时检查索引数据的数据主键和区块链上是否存在相同的数据主键,可以及时发现出现错误的索引数据。若检查到错误的索引数据,将错误的索引数据从缓存索引表中删除,并将区块链数据同步至所述缓存索引表,可以保证所述缓存索引表中的索引数据的真实性和可靠性。
上述实施例提供的区块链的数据索引方法,通过对待上链数据执行上链操作,将待上链数据同步到区块链中,从而实现在将目标数据写入区块链时,可以生成与区块链数据一致的索引数据,保 证区块链数据索引的准确性;通过验证索引数据中的数据签名是否正确,可以保证缓存索引表中数据的真实性和可靠性;若索引数据中的数据签名不正确,则根据索引数据中的数据主键从区块链中读取数据主键对应的数据键值,并根据数据键值更新索引数据,可以保证在查询数据和更新数据时,索引数据与区块链上的数据保持一致,避免索引得到错误的数据。
请参阅图8,图8是本申请的实施例还提供一种区块链的数据索引装置的示意性框图,该区块链的数据索引装置用于执行前述的区块链的数据索引方法。其中,该区块链的数据索引装置可以配置于服务器或终端中。
如图8所示,该区块链的数据索引装置100,包括:目标数据获取模块101、索引数据生成模块102、第一数据生成模块103、第一数据同步模块104和索引数据删除模块105。
目标数据获取模块101,用于获取待写入区块链的目标数据。
索引数据生成模块102,用于计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据。
第一数据生成模块103,用于根据所述索引数据生成待上链数据。
第一数据同步模块104,用于对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中。
索引数据删除模块105,用于若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
在一些实施例中,如图9所示,该第一数据生成模块103,包括:数据主键确定子模块1031、数据键值确定子模块1032和第一数据生成子模块1033。
数据主键确定子模块1031,用于根据所述索引数据中目标数据的数据主键确定所述待上链数据的数据主键。
数据键值确定子模块1032,用于根据所述索引数据中目标数据的字段数据,以及所述数据签名确定所述待上链数据的数据键值。
第一数据生成子模块1033,用于根据所述待上链数据的数据主键和数据键值生成所述待上链数据。
在一些实施例中,如图9所示,该区块链的数据索引装置100还包括:第一索引查询模块201、第一验证模块202、数据键值确定模块203和字段值确定模块204。
第一索引查询模块201,用于获取待查询字段对应的查询指令,在所述缓存索引表中查询与所述待查询字段对应的索引数据。
第一验证模块202,用于验证所述索引数据中的数据签名是否正确。
数据键值确定模块203,用于若所述索引数据中的数据签名正确,根据所述索引数据中的数据主键,确定所述区块链中与所述数据主键对应的数据键值。
字段值确定模块204,用于从所述数据键值中确定与所述待查询字段对应的值。
在一些实施例中,如图9所示,该区块链的数据索引装置100还包括:第二索引查询模块301、第二验证模块302、更新模块303、第二数据生成模块304、第二数据同步模块305和数据恢复模块306。
第二索引查询模块301,用于获取待更新字段对应的更新指令,在所述缓存索引表中查询与所述待更新字段对应的索引数据。
第二验证模块302,用于验证所述索引数据中的数据签名是否正确。
更新模块303,用于若所述索引数据中的数据签名正确,根据所述更新指令对所述索引数据中的待更新字段进行更新,并基于更新后的字段数据更新所述索引数据中的数据签名。
第二数据生成模块304,用于根据更新后的索引数据生成待上链数据。
第二数据同步模块305,用于对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中。
数据恢复模块306,用于若判定上链操作失败,将更新后的索引数据恢复为更新前的索引数据。
在一些实施例中,如图10所示,该第一验证模块202或第二验证模块302,均包括:计算子模块401、比较子模块402、判定子模块403、更新子模块404和标记子模块405。
计算子模块401,用于计算所述索引数据中目标数据的数据签名,将计算得到的数据签名和所述索引数据中所述目标数据关联的数据签名进行比较。
比较子模块402,用于将所述索引数据中目标数据关联的数据签名和所述区块链中与所述目标数据对应的数据签名进行比较。
判定子模块403,用于若计算得到的数据签名和所述目标数据关联的数据签名一致,且所述目标数据关联的数据签名和所述区块链中的数据签名一致,判定所述索引数据中的数据签名正确;还用于若计算得到的数据签名和所述目标数据关联的数据签名不一致,或者所述目标数据关联的数据签名和所述区块链中的数据签名不一致,判定所述索引数据中的数据签名不正确。
更新子模块404,用于若所述索引数据中的数据签名不正确,根据所述索引数据中的数据主键从所述区块链中读取所述数据主键对应的数据键值,并根据所述数据键值更新所述索引数据。
标记子模块405,用于若所述索引数据中的数据签名不正确,将所述索引数据对应的有效性状态标记为无效;用于所述根据所述数据键值更新所述索引数据之后,将所述索引数据对应的有效性状态标记为有效;还用于若判定上链操作成功,将所述索引数据对应的有效性状态标记为有效。
需要说明的是,所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的装置和各模块、单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
本申请的方法、装置可用于众多通用或专用的计算***环境或配置中。例如:个人计算机、服务器计算机、手持设备或便携式设备、平板型设备、多处理器***、基于微处理器的***、可编程的消费电子设备、网络PC、小型计算机、大型计算机、包括以上任何***或设备的分布式计算环境等等。
上述的方法、装置可以实现为一种计算机程序的形式,该计算机程序可以在如图11所示的计算机设备上运行。
请参阅图11,图11是本申请实施例提供的一种计算机设备的结构示意性框图。该计算机设备可以是服务器。
请参阅图11,该计算机设备包括通过***总线连接的处理器和存储器,其中,存储器可以包括非易失性或易失性存储介质和内存储器。
处理器用于提供计算和控制能力,支撑整个计算机设备的运行。
内存储器为非易失性或易失性存储介质中的计算机程序的运行提供环境,该计算机程序被处理器执行时,可使得处理器执行任意一种区块链的数据索引方法。
应当理解的是,处理器可以是中央处理单元(Central Processing Unit,CPU),该处理器还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
其中,在一个实施例中,所述处理器用于运行存储在存储器中的计算机程序,以实现如下步骤:
获取待写入区块链的目标数据;计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据;根据所述索引数据生成待上链数据;对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
在一个实施例中,所述处理器在实现根据所述索引数据生成待上链数据时,用于实现:
根据所述索引数据中目标数据的数据主键确定所述待上链数据的数据主键;根据所述索引数据中目标数据的字段数据,以及所述数据签名确定所述待上链数据的数据键值;根据所述待上链数据的数据主键和数据键值生成所述待上链数据。
在一个实施例中,所述处理器在实现将所述待上链数据同步到所述区块链中之后,还用于实现:
获取待查询字段对应的查询指令,在所述缓存索引表中查询与所述待查询字段对应的索引数据;验证所述索引数据中的数据签名是否正确;若所述索引数据中的数据签名正确,根据所述索引数据中的数据主键,确定所述区块链中与所述数据主键对应的数据键值;从所述数据键值中确定与所述待查询字段对应的值。
在一个实施例中,所述处理器在实现将所述待上链数据同步到所述区块链中之后,还用于实现:
获取待更新字段对应的更新指令,在所述缓存索引表中查询与所述待更新字段对应的索引数据;验证所述索引数据中的数据签名是否正确;若所述索引数据中的数据签名正确,根据所述更新指令对所述索引数据中的待更新字段进行更新,并基于更新后的字段数据更新所述索引数据中的数据签 名;根据更新后的索引数据生成待上链数据;对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;若判定上链操作失败,将更新后的索引数据恢复为更新前的索引数据。
在一个实施例中,所述处理器在实现验证所述索引数据中的数据签名是否正确时,用于实现:
计算所述索引数据中目标数据的数据签名,将计算得到的数据签名和所述索引数据中所述目标数据关联的数据签名进行比较;将所述索引数据中目标数据关联的数据签名和所述区块链中与所述目标数据对应的数据签名进行比较;若计算得到的数据签名和所述目标数据关联的数据签名一致,且所述目标数据关联的数据签名和所述区块链中的数据签名一致,判定所述索引数据中的数据签名正确;若计算得到的数据签名和所述目标数据关联的数据签名不一致,或者所述目标数据关联的数据签名和所述区块链中的数据签名不一致,判定所述索引数据中的数据签名不正确。
在一个实施例中,所述处理器在实现验证所述索引数据中的数据签名是否正确之后,还用于实现:
若所述索引数据中的数据签名不正确,根据所述索引数据中的数据主键从所述区块链中读取所述数据主键对应的数据键值,并根据所述数据键值更新所述索引数据。
在一个实施例中,所述处理器在实现将所述待上链数据同步到所述区块链中之后,还用于实现:
若判定上链操作成功,将所述索引数据对应的有效性状态标记为有效。
在一个实施例中,所述处理器在实现验证所述索引数据中的数据签名是否正确之后,还用于实现:
若所述索引数据中的数据签名不正确,将所述索引数据对应的有效性状态标记为无效。
在一个实施例中,所述处理器在实现根据所述数据键值更新所述索引数据之后,还用于实现:
将所述索引数据对应的有效性状态标记为有效。
本申请的实施例中还提供一种计算机可读存储介质,所述计算机可读存储介质可以是易失性,也可以是非易失性,所述计算机可读存储介质存储有计算机程序,所述计算机程序中包括程序指令,所述处理器执行所述程序指令,实现本申请实施例提供的任一项区块链的数据索引方法。
其中,所述计算机可读存储介质可以是前述实施例所述的计算机设备的内部存储单元,例如所述计算机设备的硬盘或内存。所述计算机可读存储介质也可以是所述计算机设备的外部存储设备,例如所述计算机设备上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字卡(Secure Digital Card,SD Card),闪存卡(Flash Card)等。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。

Claims (20)

  1. 一种区块链的数据索引方法,其中,包括:
    获取待写入区块链的目标数据;
    计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据;
    根据所述索引数据生成待上链数据;
    对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
    若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
  2. 如权利要求1所述的区块链的数据索引方法,其中,所述目标数据包括数据主键和至少一个字段数据;
    所述根据所述索引数据生成待上链数据,包括:
    根据所述索引数据中目标数据的数据主键确定所述待上链数据的数据主键;
    根据所述索引数据中目标数据的字段数据,以及所述数据签名确定所述待上链数据的数据键值;
    根据所述待上链数据的数据主键和数据键值生成所述待上链数据。
  3. 如权利要求2所述的区块链的数据索引方法,其中,所述将所述待上链数据同步到所述区块链中之后,还包括:
    获取待查询字段对应的查询指令,在所述缓存索引表中查询与所述待查询字段对应的索引数据;
    验证所述索引数据中的数据签名是否正确;
    若所述索引数据中的数据签名正确,根据所述索引数据中的数据主键,确定所述区块链中与所述数据主键对应的数据键值;
    从所述数据键值中确定与所述待查询字段对应的值。
  4. 如权利要求2所述的区块链的数据索引方法,其中,所述将所述待上链数据同步到所述区块链中之后,还包括:
    获取待更新字段对应的更新指令,在所述缓存索引表中查询与所述待更新字段对应的索引数据;
    验证所述索引数据中的数据签名是否正确;
    若所述索引数据中的数据签名正确,根据所述更新指令对所述索引数据中的待更新字段进行更新,并基于更新后的字段数据更新所述索引数据中的数据签名;
    根据更新后的索引数据生成待上链数据;
    对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
    若判定上链操作失败,将更新后的索引数据恢复为更新前的索引数据。
  5. 如权利要求3或4所述的区块链的数据索引方法,其中,所述验证所述索引数据中的数据签名是否正确,包括:
    计算所述索引数据中目标数据的数据签名,将计算得到的数据签名和所述索引数据中所述目标数据关联的数据签名进行比较;
    将所述索引数据中目标数据关联的数据签名和所述区块链中与所述目标数据对应的数据签名进行比较;
    若计算得到的数据签名和所述目标数据关联的数据签名一致,且所述目标数据关联的数据签名和所述区块链中的数据签名一致,判定所述索引数据中的数据签名正确;
    若计算得到的数据签名和所述目标数据关联的数据签名不一致,或者所述目标数据关联的数据签名和所述区块链中的数据签名不一致,判定所述索引数据中的数据签名不正确。
  6. 如权利要求3或4所述的区块链的数据索引方法,其中,所述验证所述索引数据中的数据签名是否正确之后,还包括:
    若所述索引数据中的数据签名不正确,根据所述索引数据中的数据主键从所述区块链中读取所述数据主键对应的数据键值,并根据所述数据键值更新所述索引数据。
  7. 如权利要求6所述的区块链的数据索引方法,其中,所述索引数据还对应于有效性状态;
    所述将所述待上链数据同步到所述区块链中之后,包括:若判定上链操作成功,将所述索引数据对应的有效性状态标记为有效;
    所述验证所述索引数据中的数据签名是否正确之后,包括:
    若所述索引数据中的数据签名不正确,将所述索引数据对应的有效性状态标记为无效;
    所述根据所述数据键值更新所述索引数据之后,包括:
    将所述索引数据对应的有效性状态标记为有效。
  8. 一种区块链的数据索引装置,其中,包括:
    目标数据获取模块,用于获取待写入区块链的目标数据;
    索引数据生成模块,用于计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据;
    第一数据生成模块,用于根据所述索引数据生成待上链数据;
    第一数据同步模块,用于对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
    索引数据删除模块,用于若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
  9. 一种计算机设备,其中,所述计算机设备包括存储器和处理器;
    所述存储器,用于存储计算机程序;
    所述处理器,用于执行所述计算机程序并在执行所述计算机程序时实现如下步骤:
    获取待写入区块链的目标数据;
    计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据;
    根据所述索引数据生成待上链数据;
    对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
    若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
  10. 如权利要求9所述的计算机设备,其中,所述目标数据包括数据主键和至少一个字段数据;
    所述根据所述索引数据生成待上链数据,包括:
    根据所述索引数据中目标数据的数据主键确定所述待上链数据的数据主键;
    根据所述索引数据中目标数据的字段数据,以及所述数据签名确定所述待上链数据的数据键值;
    根据所述待上链数据的数据主键和数据键值生成所述待上链数据。
  11. 如权利要求10所述的计算机设备,其中,所述将所述待上链数据同步到所述区块链中之后,所述处理器在执行所述计算机程序时还实现如下步骤:
    获取待查询字段对应的查询指令,在所述缓存索引表中查询与所述待查询字段对应的索引数据;
    验证所述索引数据中的数据签名是否正确;
    若所述索引数据中的数据签名正确,根据所述索引数据中的数据主键,确定所述区块链中与所述数据主键对应的数据键值;
    从所述数据键值中确定与所述待查询字段对应的值。
  12. 如权利要求10所述的计算机设备,其中,所述将所述待上链数据同步到所述区块链中之后,所述处理器在执行所述计算机程序时还实现如下步骤:
    获取待更新字段对应的更新指令,在所述缓存索引表中查询与所述待更新字段对应的索引数据;
    验证所述索引数据中的数据签名是否正确;
    若所述索引数据中的数据签名正确,根据所述更新指令对所述索引数据中的待更新字段进行更新,并基于更新后的字段数据更新所述索引数据中的数据签名;
    根据更新后的索引数据生成待上链数据;
    对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
    若判定上链操作失败,将更新后的索引数据恢复为更新前的索引数据。
  13. 如权利要求11或12所述的计算机设备,其中,所述验证所述索引数据中的数据签名是否正确,包括:
    计算所述索引数据中目标数据的数据签名,将计算得到的数据签名和所述索引数据中所述目标数据关联的数据签名进行比较;
    将所述索引数据中目标数据关联的数据签名和所述区块链中与所述目标数据对应的数据签名进行比较;
    若计算得到的数据签名和所述目标数据关联的数据签名一致,且所述目标数据关联的数据签名和所述区块链中的数据签名一致,判定所述索引数据中的数据签名正确;
    若计算得到的数据签名和所述目标数据关联的数据签名不一致,或者所述目标数据关联的数据 签名和所述区块链中的数据签名不一致,判定所述索引数据中的数据签名不正确。
  14. 如权利要求11或12所述的计算机设备,其中,所述验证所述索引数据中的数据签名是否正确之后,所述处理器在执行所述计算机程序时还实现如下步骤:
    若所述索引数据中的数据签名不正确,根据所述索引数据中的数据主键从所述区块链中读取所述数据主键对应的数据键值,并根据所述数据键值更新所述索引数据。
  15. 如权利要求14所述的计算机设备,其中,所述索引数据还对应于有效性状态;
    所述将所述待上链数据同步到所述区块链中之后,所述处理器在执行所述计算机程序时还实现如下步骤:
    若判定上链操作成功,将所述索引数据对应的有效性状态标记为有效;
    所述验证所述索引数据中的数据签名是否正确之后,所述处理器在执行所述计算机程序时还实现如下步骤:
    若所述索引数据中的数据签名不正确,将所述索引数据对应的有效性状态标记为无效;
    所述根据所述数据键值更新所述索引数据之后,所述处理器在执行所述计算机程序时还实现如下步骤:
    将所述索引数据对应的有效性状态标记为有效。
  16. 一种计算机可读存储介质,其中,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时使所述处理器实现如下步骤:
    获取待写入区块链的目标数据;
    计算所述目标数据的数据签名,将所述目标数据与所述数据签名关联保存至缓存索引表中,得到所述目标数据对应的索引数据;
    根据所述索引数据生成待上链数据;
    对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
    若判定上链操作失败,将所述索引数据从所述缓存索引表中删除。
  17. 如权利要求16所述的计算机可读存储介质,其中,所述目标数据包括数据主键和至少一个字段数据;
    所述根据所述索引数据生成待上链数据,包括:
    根据所述索引数据中目标数据的数据主键确定所述待上链数据的数据主键;
    根据所述索引数据中目标数据的字段数据,以及所述数据签名确定所述待上链数据的数据键值;
    根据所述待上链数据的数据主键和数据键值生成所述待上链数据。
  18. 如权利要求17所述的计算机可读存储介质,其中,所述将所述待上链数据同步到所述区块链中之后,所述计算机程序被处理器执行时还实现如下步骤:
    获取待查询字段对应的查询指令,在所述缓存索引表中查询与所述待查询字段对应的索引数据;
    验证所述索引数据中的数据签名是否正确;
    若所述索引数据中的数据签名正确,根据所述索引数据中的数据主键,确定所述区块链中与所述数据主键对应的数据键值;
    从所述数据键值中确定与所述待查询字段对应的值。
  19. 如权利要求17所述的计算机可读存储介质,其中,所述将所述待上链数据同步到所述区块链中之后,所述计算机程序被处理器执行时还实现如下步骤:
    获取待更新字段对应的更新指令,在所述缓存索引表中查询与所述待更新字段对应的索引数据;
    验证所述索引数据中的数据签名是否正确;
    若所述索引数据中的数据签名正确,根据所述更新指令对所述索引数据中的待更新字段进行更新,并基于更新后的字段数据更新所述索引数据中的数据签名;
    根据更新后的索引数据生成待上链数据;
    对所述待上链数据执行上链操作,将所述待上链数据同步到所述区块链中;
    若判定上链操作失败,将更新后的索引数据恢复为更新前的索引数据。
  20. 如权利要求18或19所述的计算机可读存储介质,其中,所述验证所述索引数据中的数据签名是否正确,包括:
    计算所述索引数据中目标数据的数据签名,将计算得到的数据签名和所述索引数据中所述目标数据关联的数据签名进行比较;
    将所述索引数据中目标数据关联的数据签名和所述区块链中与所述目标数据对应的数据签名进行比较;
    若计算得到的数据签名和所述目标数据关联的数据签名一致,且所述目标数据关联的数据签名和所述区块链中的数据签名一致,判定所述索引数据中的数据签名正确;
    若计算得到的数据签名和所述目标数据关联的数据签名不一致,或者所述目标数据关联的数据签名和所述区块链中的数据签名不一致,判定所述索引数据中的数据签名不正确。
PCT/CN2020/106019 2019-09-06 2020-07-30 区块链的数据索引方法、装置、计算机设备和存储介质 WO2021042920A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910851500.9A CN110704428A (zh) 2019-09-06 2019-09-06 区块链的数据索引方法、装置、计算机设备和存储介质
CN201910851500.9 2019-09-06

Publications (1)

Publication Number Publication Date
WO2021042920A1 true WO2021042920A1 (zh) 2021-03-11

Family

ID=69195921

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/106019 WO2021042920A1 (zh) 2019-09-06 2020-07-30 区块链的数据索引方法、装置、计算机设备和存储介质

Country Status (2)

Country Link
CN (1) CN110704428A (zh)
WO (1) WO2021042920A1 (zh)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110704428A (zh) * 2019-09-06 2020-01-17 深圳壹账通智能科技有限公司 区块链的数据索引方法、装置、计算机设备和存储介质
CN111680067A (zh) * 2020-05-28 2020-09-18 中国工商银行股份有限公司 基于区块链的数据处理方法、装置及***
CN111444195B (zh) * 2020-06-12 2020-10-30 支付宝(杭州)信息技术有限公司 一种块链式账本中索引的清除方法、装置及设备
CN113297201A (zh) * 2020-06-29 2021-08-24 阿里巴巴集团控股有限公司 索引数据同步方法、***及装置
CN113761564A (zh) * 2020-07-30 2021-12-07 北京京东振世信息技术有限公司 一种保护数据的方法和装置
CN114625767A (zh) * 2020-11-10 2022-06-14 支付宝(杭州)信息技术有限公司 一种数据查询方法、装置、设备及可读介质
CN112580103A (zh) * 2020-12-29 2021-03-30 郑州大学 基于中间数据库表的上链方法及***
CN113177224B (zh) * 2021-03-16 2022-01-04 深圳市名竹科技有限公司 基于区块链的数据密封方法、装置、设备和存储介质
CN112948898A (zh) * 2021-03-31 2021-06-11 北京众享比特科技有限公司 一种区块链中防止应用数据被篡改的方法和安全模块
CN113064900A (zh) * 2021-04-06 2021-07-02 北京瑞卓喜投科技发展有限公司 一种链上交易数据索引生成的方法、装置和电子设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017130038A1 (en) * 2016-01-26 2017-08-03 Stampery Inc. Systems and methods for using a block chain to certify the existence, integrity, and/or ownership of a file or communication
CN109299335A (zh) * 2018-08-31 2019-02-01 阿里巴巴集团控股有限公司 数据存储的控制方法、装置、服务器及可读存储介质
CN109815746A (zh) * 2019-01-11 2019-05-28 西安企业资本服务中心有限公司 一种基于区块链技术的数据防篡改方法及***
CN110163004A (zh) * 2018-02-14 2019-08-23 华为技术有限公司 一种区块链生成的方法、相关设备及***
CN110704428A (zh) * 2019-09-06 2020-01-17 深圳壹账通智能科技有限公司 区块链的数据索引方法、装置、计算机设备和存储介质

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8954407B2 (en) * 2010-07-13 2015-02-10 International Business Machines Corporation System and method for partially deferred index maintenance
CN110019211A (zh) * 2017-11-27 2019-07-16 北京京东尚科信息技术有限公司 关联索引的方法、装置和***
CN109165224B (zh) * 2018-08-24 2021-02-19 东北大学 一种在区块链数据库上针对关键字key的索引方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017130038A1 (en) * 2016-01-26 2017-08-03 Stampery Inc. Systems and methods for using a block chain to certify the existence, integrity, and/or ownership of a file or communication
CN110163004A (zh) * 2018-02-14 2019-08-23 华为技术有限公司 一种区块链生成的方法、相关设备及***
CN109299335A (zh) * 2018-08-31 2019-02-01 阿里巴巴集团控股有限公司 数据存储的控制方法、装置、服务器及可读存储介质
CN109815746A (zh) * 2019-01-11 2019-05-28 西安企业资本服务中心有限公司 一种基于区块链技术的数据防篡改方法及***
CN110704428A (zh) * 2019-09-06 2020-01-17 深圳壹账通智能科技有限公司 区块链的数据索引方法、装置、计算机设备和存储介质

Also Published As

Publication number Publication date
CN110704428A (zh) 2020-01-17

Similar Documents

Publication Publication Date Title
WO2021042920A1 (zh) 区块链的数据索引方法、装置、计算机设备和存储介质
WO2019232832A1 (zh) 数据监控方法、装置、计算机设备及存储介质
US10055446B2 (en) Ensuring data integrity of executed transactions
CN107688664B (zh) 图表生成方法、装置、计算机设备和存储介质
WO2021018020A1 (zh) 数据处理方法、装置、电子设备及计算机存储介质
WO2020233146A1 (zh) 数据操作记录的存储方法、***、装置及设备
JP2017534944A (ja) 条件付き検証規則
US9454590B2 (en) Predicting validity of data replication prior to actual replication in a transaction processing system
EP4379556A1 (en) Blockchain-based data processing method, and device and computer-readable storage medium
WO2021159639A1 (zh) 迁移数据的校对方法、装置、设备及存储介质
TWI699644B (zh) 電子裝置、資料洗滌裝置及對資料儲存裝置執行洗滌的方法
CN113312338A (zh) 数据一致性的校验方法、装置、设备、介质及程序产品
CN109101232B (zh) 一种产品开发的方法、装置、计算机设备及存储介质
US20240097919A1 (en) Consensus trusted cluster changing method, computer device and computer-readable storage medium
US20220368533A1 (en) System and method to cryptographically validate rich query results
CN111339551B (zh) 数据的验证方法及相关装置、设备
WO2021003532A1 (en) Application and database migration to a block chain data lake system
WO2020207008A1 (zh) 一种数据验证方法、装置、电子设备及存储介质
JP7163966B2 (ja) 変換方法、変換装置および変換プログラム
WO2020211233A1 (zh) 批量数据编辑方法、装置、计算机设备及存储介质
US11182375B2 (en) Metadata validation tool
CN112579591B (zh) 数据校验方法、装置、电子设备及计算机可读存储介质
CN111291001B (zh) 计算机文件的读取方法、装置、计算机***及存储介质
CN111835871A (zh) 传送数据文件的方法和装置、接收数据文件的方法和装置
WO2017054182A1 (zh) 一种数据校验方法和装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20861035

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205 DATED 20/07/2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20861035

Country of ref document: EP

Kind code of ref document: A1