On-chain directory data storage and retrieval method based on block chain
By realizing the creation and management of dynamic directory tables on the blockchain, using the characteristics of two-dimensional relationship tables to provide precise queries, the problem of low directory data query efficiency on the blockchain is solved, query efficiency and flexibility are improved, and the Efficient handling of local directory entries updates and deletion.
Patent Information
- Application Number
- CN202411219927.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-02
- Publication Date
- 2025-01-07
AI Technical Summary
The existing technology has low efficiency in querying directory data on the blockchain and is difficult to implement. It has failed to effectively solve the storage and query mechanism of multiple directory entries, and has not designed well for the update and deletion of local directory entries, resulting in data demand. It is difficult to obtain data directory changes in time.
Adopt the on-chain directory data storage and retrieval method based on blockchain, and update the directory provider table and directory table by responding to the full life cycle management operation of the directory provider, realizing the creation and management of dynamic directory tables, supporting precise querying, and using the second The dimensional relationship table feature provides flexible query capabilities and automatically synchronizes local directory data through a monitoring mechanism.
It significantly improves query efficiency and flexibility, reduces the amount of single-table data, solves the problem of directory ID duplication, ensures efficient processing of local directory entries updates and deletion, and realizes timely acquisition of data demanders.
Smart Images

Figure CN119271846A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of directory data technology, and in particular to an on-chain directory data storage and retrieval method based on blockchain, an on-chain directory data storage and retrieval device based on blockchain, an electronic device, and a computer-readable medium. Background Art
[0002] There are currently many technical solutions for multi-party collaborative data transaction and sharing technology based on blockchain, which generally use the method of storing directory data on the chain to achieve directory sharing, such as the solutions disclosed in CN113239376A, CN113420319A, CN110969429A, CN111090385A, etc.
[0003] Domestic alliance blockchain technology has made great progress in recent years. Leading blockchain underlying platforms such as fisco-bcos already support the storage structure of on-chain two-dimensional relational tables. However, there are some limitations different from the two-dimensional relational tables in databases. Taking fisco-bcos as an example, the main limitations include: each on-chain two-dimensional table must have a Key field. The Key is allowed to be the same, but the number of records that can be accommodated by the same Key is limited, generally in tens of thousands; indexes cannot be established for two-dimensional fields other than the Key; any query requires setting the value of the Key field, that is, full table query is not supported.
[0004] The prior art solutions disclosed in the aforementioned CN113239376A, CN113420319A, and CN110969429A patents do not make any design on how to store the directory on the chain, so as to facilitate the data demander to quickly retrieve the data directory required by itself based on the blockchain. Based on the unique block chain transaction storage structure of the blockchain and the world state storage structure of Key-Value, it is difficult for the demander to achieve the purpose of fast retrieval. If the transaction traversal method is adopted, considering the update of the directory, the data demander needs to traverse all historical transactions in the blockchain to retrieve a certain data directory, and the historical transactions of the blockchain are constantly increasing and cannot be deleted; if the Key-Value method is adopted, it is necessary to ensure that the key contains all the search conditions that the demander may use, and if fuzzy search is required, it is necessary to traverse the keys of all directories on the chain. CN111090385A discloses a method based on blockchain + adding version number and block number inverted index in value to provide retrieval capability, but this means that the version number of the data directory must be provided for each retrieval, and it is difficult for the data demander to know the version number in advance.
[0005] In general, the prior art has the following disadvantages:
[0006] 1. The on-chain query efficiency is low and the implementation is difficult: CN113239376A, CN113420319A, and CN110969429A do not provide a design for fast query of on-chain directory data. CN111090385A discloses a method based on blockchain + adding version number and block number inverted index in value to provide retrieval capability, but this means that the version number of the data directory must be provided for each retrieval, and it is difficult for the data demander to know the version number in advance.
[0007] 2. There is no design for specific storage and query mechanisms for multiple directory providers with millions of directory entries (such as a complete set of electronic archive directories or other data);
[0008] 3. There is no good design for local directory entry updates and deletions to ensure that only necessary on-chain directory entries are updated and that data demanders can obtain data directory changes in a timely manner. Summary of the invention
[0009] In view of the above problems, the present invention is proposed to provide a blockchain-based on-chain directory data storage and retrieval method and a corresponding blockchain-based on-chain directory data storage and retrieval device, an electronic device and a computer-readable medium that overcome the above problems or at least partially solve the above problems.
[0010] The present invention discloses a method for storing and retrieving directory data on a blockchain, the method comprising:
[0011] In response to the directory provider's full life cycle management operation on the directory provider record, the directory provider table is updated, and based on the update of the directory provider table, full life cycle operations on the directory table corresponding to the directory provider record are performed; the full life cycle management operations include adding, deleting, and updating;
[0012] Respond to the directory provider's full life cycle management operations on the directory entry and update the directory table corresponding to the directory provider's record;
[0013] Respond to the directory provider query request of the directory demander, generate a target directory provider list, and respond to the directory entry query request of the directory demander, query the target directory entry from the directory table corresponding to the directory provider list; the directory provider query request carries the field information of the directory provider record; the directory entry query request carries the field information of the directory entry.
[0014] Optionally, the directory provider table is used to record directory providers, and each record represents a directory provider; the fields of the directory provider record include a key field, a name, a provider public key, a code, a status, an update time, a creation time, a deletion time, and a directory data update time, and the key field is a preset unified value;
[0015] The table name of the directory table is the unique identifier of the corresponding directory provider; the unique identifier of the data provider is a combination of the provider's public key, name, and code;
[0016] Each record of the directory table represents a directory entry of the directory provider; the fields of the directory entry include a key field, its own ID, name, code, creation time, update time, and descendant directory update time, and the key field is the ID of the parent directory entry to which the directory entry belongs.
[0017] Optionally, in response to the directory provider's full lifecycle management operation on the directory provider record, the directory provider table is updated, and based on the update of the directory provider table, a full lifecycle operation on the directory table corresponding to the directory provider record is performed, including:
[0018] In response to the directory provider registration request of the directory provider, perform a uniqueness check on the directory provider through a unique identifier, and after passing the check, create a directory provider record of the directory provider on the directory provider table, and create a directory table corresponding to the directory provider record;
[0019] or, in response to a directory provider update request from the directory provider, performing a uniqueness check on the directory provider through a unique identifier and an authority check on the directory provider through a provider public key, and updating the directory provider record of the directory provider on the directory provider table after the check passes;
[0020] Or, in response to the directory provider deletion request of the directory provider, the directory provider is checked for authority using the provider public key, and the directory provider record of the directory provider is double-deleted from the directory provider table after the check passes.
[0021] Optionally, in response to the directory provider's full lifecycle management operation on the directory entry, updating the directory table corresponding to the directory provider record includes:
[0022] Query the directory provider table according to the provider public key to obtain the directory provider record corresponding to the provider public key, and determine the unique identifier of the directory provider according to the directory provider record;
[0023] Determine the table name of the directory table to be operated according to the unique identifier of the directory provider;
[0024] Perform a directory entry duplication check based on the directory entry ID recorded in the input entry information, and insert the directory entry containing the input entry information into the directory table corresponding to the table name after passing the check; the key field recorded in the input entry information is the ID of the parent directory entry to which the directory entry belongs;
[0025] Or, perform a directory entry duplication check according to the directory entry ID recorded in the input entry information, and after passing the check, search for the target directory entry in the directory table corresponding to the table name according to the directory entry ID and the ID of the parent directory entry to which the key field belongs, and update the fields in the target directory entry;
[0026] Or, based on the directory entry ID recorded in the input entry information and the ID of the parent directory entry to which the key field belongs, the target directory entry is searched in the directory table corresponding to the table name, and the target directory entry or a field in the target directory entry is deleted.
[0027] Optionally, the method further comprises:
[0028] Respond to the directory provider query request from the directory demander, obtain a list of all directory providers, and query all directory entries of each directory provider in the list of all directory providers according to the directory hierarchy structure and store them locally.
[0029] Optionally, the method further comprises:
[0030] Respond to the directory provider query request from the directory demander, obtain a list of all directory providers, and use the last successful synchronization time as an input parameter to query all directory entries between the current time and the last successful synchronization time and store them locally.
[0031] Optionally, the method further comprises:
[0032] The monitoring mechanism monitors the directory entry change events of the on-chain directory data, and automatically synchronizes the local directory data with the on-chain directory data based on the directory entry change events.
[0033] The present invention also discloses a blockchain-based on-chain directory data storage and retrieval device, the device comprising:
[0034] The directory provider and directory table operation module is used to update the directory provider table in response to the directory provider's full life cycle management operation on the directory provider record, and perform full life cycle operations on the directory table corresponding to the directory provider record based on the update of the directory provider table; the full life cycle management operation includes adding, deleting, and updating;
[0035] A directory entry operation module, used to update the directory table corresponding to the directory provider record in response to the directory provider's full life cycle management operation on the directory entry;
[0036] A retrieval module is used to respond to a directory provider query request from a directory demander, generate a target directory provider list, and respond to a directory entry query request from a directory demander, and query the target directory entry from the directory table corresponding to the directory provider list; the directory provider query request carries field information recorded by the directory provider; the directory entry query request carries field information of the directory entry.
[0037] Optionally, the directory provider table is used to record directory providers, and each record represents a directory provider; the fields of the directory provider record include a key field, a name, a provider public key, a code, a status, an update time, a creation time, a deletion time, and a directory data update time, and the key field is a preset unified value;
[0038] The table name of the directory table is the unique identifier of the corresponding directory provider; the unique identifier of the data provider is a combination of the provider's public key, name, and code;
[0039] Each record of the directory table represents a directory entry of the directory provider; the fields of the directory entry include a key field, its own ID, name, code, creation time, update time, and descendant directory update time, and the key field is the ID of the parent directory entry to which the directory entry belongs.
[0040] Optionally, the directory provider and directory table operation module include:
[0041] A new submodule is added, which is used to respond to the directory provider registration request of the directory provider, perform a uniqueness check on the directory provider through a unique identifier, and create a directory provider record of the directory provider on the directory provider table after passing the check, and create a directory table corresponding to the directory provider record;
[0042] or, an update submodule, for responding to a directory provider update request of the directory provider, performing a uniqueness check on the directory provider through a unique identifier and an authority check on the directory provider through a provider public key, and updating the directory provider record of the directory provider on the directory provider table after passing the check;
[0043] Or, a deletion submodule is used to respond to the directory provider deletion request of the directory provider, perform an authority check on the directory provider through the provider public key, and double-delete the directory provider record of the directory provider in the directory provider table after passing the check.
[0044] Optionally, the directory entry operation module includes:
[0045] A unique identifier determination submodule, used to query the directory provider table according to the provider public key to obtain the directory provider record corresponding to the provider public key, and determine the unique identifier of the directory provider according to the directory provider record;
[0046] A table name determination submodule, used to determine the table name of the directory table to be operated according to the unique identifier of the directory provider;
[0047] A new submodule is added to the directory entry, which is used to check the duplication of the directory entry according to the directory entry ID recorded in the input parameter entry information, and insert the directory entry containing the input parameter entry information into the directory table corresponding to the table name after passing the check; the key field recorded in the input parameter entry information is the ID of the parent directory entry to which the directory entry belongs;
[0048] or, a directory entry update submodule, configured to perform a directory entry duplication check according to the directory entry ID recorded in the input entry information, and after passing the check, search for a target directory entry in the directory table corresponding to the table name according to the directory entry ID and the ID of the parent directory entry to which the key field belongs, and update the fields in the target directory entry;
[0049] Or, a directory entry deletion submodule is used to search for a target directory entry in the directory table corresponding to the table name based on the directory entry's own ID recorded in the input entry information and the ID of the parent directory entry to which the key field belongs, and delete the target directory entry or a field in the target directory entry.
[0050] Optionally, the device further comprises:
[0051] The first local synchronization sharing module is used to respond to the directory provider query request of the directory demander, obtain a list of all directory providers, and query all directory entries of each directory provider in the list of all directory providers according to the directory hierarchy structure and store them locally.
[0052] Optionally, the device further comprises:
[0053] The second local synchronization sharing module is used to respond to the directory provider query request of the directory demander, obtain the list of all directory providers, and use the last successful synchronization time as an input parameter to query all directory entries between the current time and the last successful synchronization time and store them locally.
[0054] Optionally, the device further comprises:
[0055] The third local synchronization sharing module is used to monitor the directory entry change events of the on-chain directory data through a monitoring mechanism, and automatically synchronize the local directory data with the on-chain directory data according to the directory entry change events.
[0056] The present invention also discloses an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0057] The memory is used to store computer programs;
[0058] The processor is used to implement the blockchain-based on-chain directory data storage and retrieval method as described in the present invention when executing the program stored in the memory.
[0059] The present invention also discloses one or more computer-readable media having instructions stored thereon, which, when executed by one or more processors, enable the processors to execute the blockchain-based on-chain directory data storage and retrieval method as described in the present invention.
[0060] The present invention includes the following advantages:
[0061] The blockchain-based on-chain directory data storage and retrieval method of the present invention updates the directory provider table by responding to the full life cycle management operation of the directory provider record by the directory provider, and performs the full life cycle operation of the directory table corresponding to the directory provider record based on the update of the directory provider table. The full life cycle management operation includes adding, deleting, and updating. The directory provider updates the directory table corresponding to the directory provider record in response to the full life cycle management operation of the directory entry by the directory provider, responds to the directory provider query request of the directory demander, generates a target directory provider list, and responds to the directory entry query request of the directory demander to query the target directory entry from the directory table corresponding to the directory provider list. The directory provider query request carries the field information of the directory provider record, and the directory entry query request carries the field information of the directory entry. The method innovatively uses the characteristics of the on-chain two-dimensional relationship table provided by the advanced blockchain platform to realize the on-chain storage of shared directory data, provides the ability to accurately query based on the two-dimensional relationship table instead of traversing block transactions or Key-Value databases, and significantly improves the flexibility of queries. It also innovatively implements the creation of dynamic directory tables, dynamically creating directory tables on the chain for each directory provider. When multiple directory providers exist at the same time, it can significantly reduce the amount of data in a single table and significantly improve query performance, and can also effectively solve the problem of possible duplication of directory IDs of different directory providers. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1This is a flowchart of a method for storing and retrieving directory data on a blockchain based on an embodiment of the present invention;
[0063] Figure 2 It is a structural block diagram of an on-chain directory data storage and retrieval device based on blockchain provided by an embodiment of the present invention;
[0064] Figure 3 is a block diagram of an electronic device provided by an embodiment of the present invention;
[0065] Figure 4 It is a schematic diagram of a computer-readable medium provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0066] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0067] Reference Figure 1 , shows a flowchart of a method for storing and retrieving directory data on a blockchain based on an embodiment of the present invention, which may specifically include the following steps:
[0068] Step 101, in response to the directory provider's full life cycle management operation on the directory provider record, the directory provider table is updated, and based on the update of the directory provider table, the full life cycle operation on the directory table corresponding to the directory provider record is performed; the full life cycle management operation includes adding, deleting, and updating;
[0069] Step 102, in response to the directory provider's full life cycle management operation on the directory entry, update the directory table corresponding to the directory provider record;
[0070] Step 103, respond to the directory provider query request of the directory demander, generate a target directory provider list, and respond to the directory entry query request of the directory demander, query the target directory entry from the directory table corresponding to the directory provider list; the directory provider query request carries the field information of the directory provider record; the directory entry query request carries the field information of the directory entry.
[0071] The present invention creates and manages a two-dimensional relationship table on the blockchain: a directory provider table and a directory table.
[0072] a) Catalog provider table: used to store the providers of catalog data. Each record represents a provider. The Key is a unified value that can be set according to actual conditions, such as CatalogProvider. Other fields may include name, provider public key, code, status, update time, creation time, deletion time, and catalog data update time.
[0073] b) Directory table: Each provider has a directory table, which is automatically created by the smart contract when a new record is added to the directory provider table (i.e., a new directory provider is added). The name of the directory table is the unique identifier of the corresponding directory provider, and the unique identifier of the data provider is a combination of the provider's public key, name, and code. Each record in the directory table represents a directory entry of the directory provider. The Key field of each directory table is the ID of the parent directory entry to which it belongs. Other fields may include its own ID, name, code, creation time, update time, descendant directory update time, etc. Other fields can be expanded according to actual business needs.
[0074] Through the blockchain two-dimensional relationship table designed by the present invention, data providers can share directory information on the chain based on the on-chain smart contract, and data demanders can quickly and accurately retrieve directory data based on the on-chain directory structure and two-dimensional relationship table design.
[0075] Specifically, based on the aforementioned on-chain smart contract, the directory provider shares directory information on the chain in the following ways:
[0076] a) Register as a directory provider: Call the smart contract "Directory Provider Record Addition".
[0077] b) Update self-related information: call the smart contract "Directory Provider Record Update".
[0078] c) Cancel itself: call the smart contract "Directory Provider Record Deletion".
[0079] d) Add a new directory entry: call the smart contract "add directory entry". In particular, any directory has a root directory entry. The parties need to agree that the "parent directory entry ID" of the root directory entry is a fixed value, such as "BlockChainCatalogRoot". It only needs to ensure that this value does not appear as an ID in the business directory entry.
[0080] e) Update Directory Entry: Call the smart contract “Update Directory Entry”.
[0081] f) Delete directory entry: Call the smart contract "Delete Directory Entry".
[0082] For the above operations of the data provider, the directory provider table can be updated in response to the directory provider's operations of adding, deleting, and updating the directory provider's records, and a record table can be created or the name of the record table can be updated or the record table can be deleted based on the update of the directory provider table. The directory provider can also insert directory entries into the directory table, delete directory entries, or update directory entry field information in response to the directory provider's operations of adding, deleting, and updating the directory entries.
[0083] Based on the aforementioned on-chain directory structure and design, and based on the business rules of the directory's natural hierarchical structure (any directory entry has a parent directory entry), when the directory demander does not synchronize directory data to the local, most business scenario requirements can be met. The process of the directory demander retrieving directory data and presenting a directory tree to each directory provider is as follows:
[0084] a) Call the smart contract "Directory Provider Query" to obtain and display the list of directory providers;
[0085] Among them, the smart contract "Directory Provider Query": the parameters for calling this contract are optional directory provider-related conditions, such as name, code, etc. The records in the directory provider two-dimensional relationship table are queried and returned with the Key equal to the aforementioned unified value and other conditions equal to the specified values of the input parameters.
[0086] b) Based on the catalog provider selected by the user, call the smart contract "Query Sub-Catalog Entries" to query and display the root catalog entry of the provider, and set the parent catalog entry ID as the fixed value agreed upon above, such as "BlockChainCatalogRoot";
[0087] c) Based on the directory entry selected by the user and the optional query conditions, the smart contract "Query Sub-Directory Entries" is called to query and display the list of sub-directory entries that meet the conditions.
[0088] Among them, the smart contract "query sub-directory entries": the query input parameters include the directory provider code, the parent directory entry ID, and optional directory entry conditions, such as ID, name, last updated time, etc.
[0089] 1) Query the directory provider table according to the directory provider code to obtain a matching record. Based on the record, use the rules in the aforementioned "Add Directory Provider Record" contract to determine the name of the directory table to be queried.
[0090] 2) Query records in the directory table selected in the previous step. The query conditions include the required Key equal to the "parent directory entry ID" in the input parameter and other optional directory entry conditions, typically including the entry ID to query a single directory entry, and the last update time to query all direct child directory entries belonging to the parent directory entry that have been updated after a certain time.
[0091] In one embodiment of the present invention, in response to a full life cycle management operation of a directory provider on a directory provider record by a directory provider, updating a directory provider table, and performing a full life cycle operation on a directory table corresponding to the directory provider record based on the update of the directory provider table, includes:
[0092] In response to the directory provider registration request of the directory provider, perform a uniqueness check on the directory provider through a unique identifier, and after passing the check, create a directory provider record of the directory provider on the directory provider table, and create a directory table corresponding to the directory provider record;
[0093] or, in response to a directory provider update request from the directory provider, performing a uniqueness check on the directory provider through a unique identifier and an authority check on the directory provider through a provider public key, and updating the directory provider record of the directory provider on the directory provider table after the check passes;
[0094] Or, in response to the directory provider deletion request of the directory provider, the directory provider is checked for authority using the provider public key, and the directory provider record of the directory provider is double-deleted from the directory provider table after the check passes.
[0095] The embodiment of the present invention deploys the following smart contracts on the blockchain to update the directory provider table in response to the directory provider's full life cycle management operation on the directory provider record, and performs full life cycle operations on the directory table corresponding to the directory provider record based on the update of the directory provider table:
[0096] a) Addition of directory provider record:
[0097] 1) Perform a uniqueness check (using the provider's public key, name, and code as a unique identifier). If it fails, it will be rejected; the provider's public key is set to the public key of the blockchain account used to call the blockchain (the same below);
[0098] 2) Insert a record into the directory provider table;
[0099] 3) Create a dedicated catalog table for the provider according to the field definition of the aforementioned catalog table. The table name should contain the unique identifier of the provider, for example, "provider code value_Catalog";
[0100] 4) Optional, if the blockchain platform supports contract events, send a blockchain event "Directory provider record added".
[0101] b) Directory provider record update:
[0102] 1) Perform a uniqueness check (using the provider's public key, name, and code as a unique identifier). If the check fails, the request is rejected;
[0103] 2) Perform permission check (digital signature verification based on the provider's public key. Generally, blockchain platforms will automatically complete this verification. If it is not completed, this contract will complete it. The same applies below). If the check fails, the request will be rejected;
[0104] 3) Update the record corresponding to the provider's public key in the directory provider table;
[0105] 4) Optional, if the blockchain platform supports contract events, send a blockchain event "Directory Provider Record Update".
[0106] c) Directory provider record deletion:
[0107] 1) Perform an authorization check. If the check fails, the request is rejected.
[0108] 2) Update the record status corresponding to the provider public key in the directory provider table to deleted and set the deletion time according to the input parameters;
[0109] 3) Optionally, if supported by the blockchain platform, delete the directory table corresponding to the provider;
[0110] 4) Optional, if the blockchain platform supports contract events, send a blockchain event "directory provider record deleted".
[0111] In one embodiment of the present invention, updating a directory table corresponding to a directory provider record in response to a full lifecycle management operation of a directory entry by a directory provider includes:
[0112] Query the directory provider table according to the provider public key to obtain the directory provider record corresponding to the provider public key, and determine the unique identifier of the directory provider according to the directory provider record;
[0113] Determine the table name of the directory table to be operated according to the unique identifier of the directory provider;
[0114] Perform a directory entry duplication check based on the directory entry ID recorded in the input entry information, and insert the directory entry containing the input entry information into the directory table corresponding to the table name after passing the check; the key field recorded in the input entry information is the ID of the parent directory entry to which the directory entry belongs;
[0115] Or, perform a directory entry duplication check according to the directory entry ID recorded in the input entry information, and after passing the check, search for the target directory entry in the directory table corresponding to the table name according to the directory entry ID and the ID of the parent directory entry to which the key field belongs, and update the fields in the target directory entry;
[0116] Or, based on the directory entry ID recorded in the input entry information and the ID of the parent directory entry to which the key field belongs, the target directory entry is searched in the directory table corresponding to the table name, and the target directory entry or a field in the target directory entry is deleted.
[0117] The embodiment of the present invention deploys the following smart contract on the blockchain to update the directory table corresponding to the directory provider's record in response to the directory provider's full life cycle management operation on the directory entry:
[0118] a) Adding a new directory entry: In addition to the relevant fields of the new directory entry and the technical fields required by the blockchain platform, the parameters for calling this contract must also include the ID of the parent directory entry to which the directory entry belongs. The processing logic is as follows:
[0119] 1) Determine the directory table to be operated based on the caller: query the directory provider table based on the caller's public key (the blockchain platform provides an interface for obtaining the caller's public key) to obtain the corresponding provider record, and determine the name of the directory table to be operated according to the rules in the aforementioned "Addition of Directory Provider Records" contract;
[0120] 2) Check for duplication of directory entries: the entry ID must not exist;
[0121] 3) Other business inspections: define inspection items based on actual business needs;
[0122] 4) Insert a record into the directory table selected in the previous step: the Key is set to the "parent directory entry ID" in the input parameter, and other values are set according to the input parameter;
[0123] 5) Optionally, update the "Directory Data Update Time" field of the directory provider;
[0124] 6) Optional, if the blockchain platform supports contract events, send a blockchain event "Directory Entry Added";
[0125] 7) Optional, if the blockchain platform does not support contract events, update the “descendant directory update time” of the parent directory level by level.
[0126] b) Update directory entries:
[0127] 1) Determine the directory table to be operated based on the caller: query the directory provider table based on the caller's public key (the blockchain platform provides an interface for obtaining the caller's public key) to obtain the corresponding provider record, and determine the name of the directory table to be operated according to the rules in the aforementioned "Addition of Directory Provider Records" contract;
[0128] 2) Directory entry existence check: the entry ID must exist;
[0129] 3) Other business inspections: define inspection items based on actual business needs;
[0130] 4) Update the record in the directory table selected in the previous step. The update conditions are: Key is equal to the "parent directory entry ID" in the input parameter, and ID is equal to the directory entry ID specified in the input parameter;
[0131] 5) Optionally, update the "Directory Data Update Time" field of the directory provider;
[0132] 6) Optionally, if the blockchain platform supports contract events, send a blockchain event "directory entry updated";
[0133] 7) Optional, if the blockchain platform does not support contract events, update the “descendant directory update time” of the parent directory level by level.
[0134] c) Delete the directory entry:
[0135] 1) Determine the directory table to be operated based on the caller: query the directory provider table based on the caller's public key (the blockchain platform provides an interface for obtaining the caller's public key) to obtain the corresponding provider record, and determine the name of the directory table to be operated according to the rules in the aforementioned "Addition of Directory Provider Records" contract;
[0136] 2) Delete the record in the directory table selected in the previous step. The deletion conditions are: Key is equal to the "parent directory entry ID" in the input parameter, and ID is equal to the directory entry ID specified in the input parameter;
[0137] 3) Optionally, update the "Directory Data Update Time" field of the directory provider;
[0138] 4) Optional, if the blockchain platform supports contract events, send a blockchain event "directory entry deleted";
[0139] 5) Optional, if the blockchain platform does not support contract events, update the “descendant directory update time” of the parent directory level by level.
[0140] In one embodiment of the present invention, the method further comprises:
[0141] Respond to the directory provider query request from the directory demander, obtain a list of all directory providers, and query all directory entries of each directory provider in the list of all directory providers according to the directory hierarchy structure and store them locally.
[0142] In one embodiment of the present invention, the method further comprises:
[0143] Respond to the directory provider query request from the directory demander, obtain a list of all directory providers, and use the last successful synchronization time as an input parameter to query all directory entries between the current time and the last successful synchronization time and store them locally.
[0144] In one embodiment of the present invention, the method further comprises:
[0145] The monitoring mechanism monitors the directory entry change events of the on-chain directory data, and automatically synchronizes the local directory data with the on-chain directory data based on the directory entry change events.
[0146] After the catalog demander queries the shared catalog data, it can also synchronize the catalog data to the local computer. Synchronizing catalog data to the local computer is generally applicable to more advanced search methods, such as building a local full-text search engine to support full-text search of catalog data. In this case:
[0147] 1) The directory requester obtains the latest shared directory data on the chain through the following steps when the system is first started or restarted:
[0148] a) Call the smart contract "Directory Provider Query" to obtain a list of all directory providers;
[0149] b) Traverse the list of all directory providers:
[0150] i. If the data of the provider has not been synchronized locally, the smart contract "Query Sub-Directory Entries" is called level by level according to the directory hierarchy to query all directory entries of the provider and store them locally;
[0151] ii. If the last local update time is less than the "directory data update time" of the provider on the chain, set the input parameter "last update time" to "the time when the provider's directory data was last successfully fully synchronized", and call the smart contract "query sub-directory entries" level by level to query all the changed directory entries of the provider and store them locally.
[0152] 2) Optional, if the blockchain platform supports an event mechanism, the monitoring mechanism provided by the blockchain platform can be used to monitor directory data change events to track subsequent directory data changes and maintain consistency between local directory data and shared directory data on the chain.
[0153] 3) Optionally, if the blockchain platform does not support the event mechanism, the aforementioned step 1) is executed periodically to ensure the consistency between the local data and the on-chain data.
[0154] In addition, in one embodiment of the present invention, when the directory demander synchronizes the directory data to the local, it can dynamically choose to re-acquire all blockchain events during this period or call the "Directory Provider Query" / "Query Sub-Directory Entry" interface to update the local directory data based on the blockchain height difference between the stop time and the current start time, so as to obtain higher data synchronization performance.
[0155] The blockchain-based on-chain directory data storage and retrieval method of the present invention has the following advantages:
[0156] 1. Effectively solve the problem of low on-chain query efficiency and high implementation difficulty:
[0157] a) Innovatively use the characteristics of the on-chain two-dimensional relational table provided by the advanced blockchain platform to realize the on-chain storage of shared directory data, providing the ability to accurately query based on the two-dimensional relational table instead of traversing block transactions or Key-Value databases (which means that the supported scenarios are very limited), significantly improving the flexibility of queries;
[0158] b) Under the constraints of the two-dimensional relational table on the chain, the natural hierarchical structure of the directory data is fully utilized. The parent directory entry of each directory entry is innovatively designed as the key (rather than the conventional self-ID set as the key), and fields such as "descendant directory update time" are designed. When the directory entry is updated, the "subdirectory update time" of all its parent nodes is synchronously updated, and the idea and method of quickly synchronizing the directory data to the directory demander based on this attribute is used. The relevant contracts are designed based on this storage structure: the query capability of the chain can be directly used (without synchronizing data to the local) to meet most of the query scenario requirements of the directory demander, which can save local storage space, and the usage method is in line with the business scenario;
[0159] 2. In view of the situation where there are multiple directory providers with millions of directory entries (such as a complete set of electronic archive directories or other data), a specific storage and query mechanism is designed: the creation of dynamic directory tables is innovatively realized, and a directory table is dynamically created on the chain for each directory provider to store the directory entry data of the provider. When multiple directory providers exist at the same time, it can significantly reduce the amount of data in a single table and significantly improve the query performance, and can also effectively solve the problem of possible duplication of directory IDs of different directory providers.
[0160] 3. Methods are provided for updating and deleting local directory entries to ensure that only necessary on-chain directory entries are updated. At the same time, in the scenario where the directory demander needs to synchronize directory data to the local, two fast and efficient query methods are provided, which are respectively suitable for the situation where the blockchain platform supports contract events and the blockchain platform does not support contract events, so that the data demander can obtain data directory changes in a timely manner.
[0161] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0162] Reference Figure 2, shows a structural block diagram of a blockchain-based on-chain directory data storage and retrieval device provided in an embodiment of the present invention, which may specifically include the following modules:
[0163] The directory provider and directory table operation module 201 is used to update the directory provider table in response to the directory provider's full life cycle management operation on the directory provider record, and perform full life cycle operations on the directory table corresponding to the directory provider record based on the update of the directory provider table; the full life cycle management operation includes adding, deleting, and updating;
[0164] The directory entry operation module 202 is used to update the directory table corresponding to the directory provider record in response to the directory provider's full life cycle management operation on the directory entry;
[0165] The retrieval module 203 is used to respond to the directory provider query request of the directory demander, generate a target directory provider list, and respond to the directory item query request of the directory demander, and query the target directory item from the directory table corresponding to the directory provider list; the directory provider query request carries the field information of the directory provider record; the directory item query request carries the field information of the directory item.
[0166] Optionally, the directory provider table is used to record directory providers, and each record represents a directory provider; the fields of the directory provider record include a key field, a name, a provider public key, a code, a status, an update time, a creation time, a deletion time, and a directory data update time, and the key field is a preset unified value;
[0167] The table name of the directory table is the unique identifier of the corresponding directory provider; the unique identifier of the data provider is a combination of the provider's public key, name, and code;
[0168] Each record of the directory table represents a directory entry of the directory provider; the fields of the directory entry include a key field, its own ID, name, code, creation time, update time, and descendant directory update time, and the key field is the ID of the parent directory entry to which the directory entry belongs.
[0169] Optionally, the directory provider and directory table operation module include:
[0170] A new submodule is added, which is used to respond to the directory provider registration request of the directory provider, perform a uniqueness check on the directory provider through a unique identifier, and create a directory provider record of the directory provider on the directory provider table after passing the check, and create a directory table corresponding to the directory provider record;
[0171] or, an update submodule, for responding to a directory provider update request of the directory provider, performing a uniqueness check on the directory provider through a unique identifier and an authority check on the directory provider through a provider public key, and updating the directory provider record of the directory provider on the directory provider table after passing the check;
[0172] Or, a deletion submodule is used to respond to the directory provider deletion request of the directory provider, perform an authority check on the directory provider through the provider public key, and double-delete the directory provider record of the directory provider in the directory provider table after passing the check.
[0173] Optionally, the directory entry operation module includes:
[0174] A unique identifier determination submodule, used to query the directory provider table according to the provider public key to obtain the directory provider record corresponding to the provider public key, and determine the unique identifier of the directory provider according to the directory provider record;
[0175] A table name determination submodule, used to determine the table name of the directory table to be operated according to the unique identifier of the directory provider;
[0176] A new submodule is added to the directory entry, which is used to check the duplication of the directory entry according to the directory entry ID recorded in the input parameter entry information, and insert the directory entry containing the input parameter entry information into the directory table corresponding to the table name after passing the check; the key field recorded in the input parameter entry information is the ID of the parent directory entry to which the directory entry belongs;
[0177] or, a directory entry update submodule, configured to perform a directory entry duplication check according to the directory entry ID recorded in the input entry information, and after passing the check, search for a target directory entry in the directory table corresponding to the table name according to the directory entry ID and the ID of the parent directory entry to which the key field belongs, and update the fields in the target directory entry;
[0178] Or, a directory entry deletion submodule is used to search for a target directory entry in the directory table corresponding to the table name based on the directory entry's own ID recorded in the input entry information and the ID of the parent directory entry to which the key field belongs, and delete the target directory entry or a field in the target directory entry.
[0179] Optionally, the device further comprises:
[0180] The first local synchronization sharing module is used to respond to the directory provider query request of the directory demander, obtain a list of all directory providers, and query all directory entries of each directory provider in the list of all directory providers according to the directory hierarchy structure and store them locally.
[0181] Optionally, the device further comprises:
[0182] The second local synchronization sharing module is used to respond to the directory provider query request of the directory demander, obtain the list of all directory providers, and use the last successful synchronization time as an input parameter to query all directory entries between the current time and the last successful synchronization time and store them locally.
[0183] Optionally, the device further comprises:
[0184] The third local synchronization sharing module is used to monitor the directory entry change events of the on-chain directory data through a monitoring mechanism, and automatically synchronize the local directory data with the on-chain directory data according to the directory entry change events.
[0185] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0186] In addition, an embodiment of the present invention further provides an electronic device, such as Figure 3 As shown, it includes a processor 301, a communication interface 302, a memory 303 and a communication bus 304, wherein the processor 301, the communication interface 302, and the memory 303 communicate with each other through the communication bus 304.
[0187] Memory 303, used for storing computer programs;
[0188] The processor 301 is used to implement the on-chain directory data storage and retrieval method based on blockchain as described in the above embodiment when executing the program stored in the memory 303.
[0189] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0190] The communication interface is used for communication between the above terminal and other devices.
[0191] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0192] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0193] like Figure 4 As shown, in another embodiment provided by the present invention, a computer-readable storage medium 401 is also provided, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the blockchain-based on-chain directory data storage and retrieval method described in the above embodiment.
[0194] In another embodiment provided by the present invention, a computer program product comprising instructions is also provided, which, when executed on a computer, enables the computer to execute the on-chain directory data storage and retrieval method based on blockchain described in the above embodiment.
[0195] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0196] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0197] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0198] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A method for storing and retrieving directory data on a blockchain, characterized in that: The method comprises: In response to the directory provider's full life cycle management operation on the directory provider record, the directory provider table is updated, and based on the update of the directory provider table, full life cycle operations on the directory table corresponding to the directory provider record are performed; the full life cycle management operations include adding, deleting, and updating; Respond to the directory provider's full life cycle management operations on the directory entry and update the directory table corresponding to the directory provider's record; Respond to the directory provider query request of the directory demander, generate a target directory provider list, and respond to the directory entry query request of the directory demander, query the target directory entry from the directory table corresponding to the directory provider list; the directory provider query request carries the field information of the directory provider record; the directory entry query request carries the field information of the directory entry.
2. The method according to claim 1, characterized in that The directory provider table is used to record directory providers, and each record represents a directory provider; the fields of the directory provider record include key field, name, provider public key, code, status, update time, creation time, deletion time, directory data update time, and the key field is a preset unified value; The table name of the directory table is the unique identifier of the corresponding directory provider; the unique identifier of the data provider is a combination of the provider's public key, name, and code; Each record of the directory table represents a directory entry of the directory provider; the fields of the directory entry include a key field, its own ID, name, code, creation time, update time, and descendant directory update time, and the key field is the ID of the parent directory entry to which the directory entry belongs.
3. The method according to claim 2, characterized in that In response to the directory provider's full lifecycle management operation on the directory provider record, the directory provider table is updated, and based on the update of the directory provider table, full lifecycle operations on the directory table corresponding to the directory provider record are performed, including: In response to the directory provider registration request of the directory provider, perform a uniqueness check on the directory provider through a unique identifier, and after passing the check, create a directory provider record of the directory provider on the directory provider table, and create a directory table corresponding to the directory provider record; or, in response to a directory provider update request from the directory provider, performing a uniqueness check on the directory provider through a unique identifier and an authority check on the directory provider through a provider public key, and updating the directory provider record of the directory provider on the directory provider table after the check passes; Or, in response to the directory provider deletion request of the directory provider, the directory provider is checked for authority using the provider public key, and the directory provider record of the directory provider is double-deleted from the directory provider table after the check passes.
4. The method according to claim 2, characterized in that: Respond to the directory provider's full lifecycle management operations on the directory entry and update the directory table corresponding to the directory provider record, including: Query the directory provider table according to the provider public key to obtain the directory provider record corresponding to the provider public key, and determine the unique identifier of the directory provider according to the directory provider record; Determine the table name of the directory table to be operated according to the unique identifier of the directory provider; Perform a directory entry duplication check based on the directory entry ID recorded in the input entry information, and insert the directory entry containing the input entry information into the directory table corresponding to the table name after passing the check; the key field recorded in the input entry information is the ID of the parent directory entry to which the directory entry belongs; Or, perform a directory entry duplication check according to the directory entry ID recorded in the input entry information, and after passing the check, search for the target directory entry in the directory table corresponding to the table name according to the directory entry ID and the ID of the parent directory entry to which the key field belongs, and update the fields in the target directory entry; Or, based on the directory entry ID recorded in the input entry information and the ID of the parent directory entry to which the key field belongs, the target directory entry is searched in the directory table corresponding to the table name, and the target directory entry or a field in the target directory entry is deleted.
5. The method according to claim 1, characterized in that The method further comprises: Respond to the directory provider query request from the directory demander, obtain a list of all directory providers, and query all directory entries of each directory provider in the list of all directory providers according to the directory hierarchy structure and store them locally.
6. The method according to claim 1, characterized in that The method further comprises: Respond to the directory provider query request from the directory demander, obtain a list of all directory providers, and use the last successful synchronization time as an input parameter to query all directory entries between the current time and the last successful synchronization time and store them locally.
7. The method according to claim 1, characterized in that The method further comprises: The monitoring mechanism monitors the directory entry change events of the on-chain directory data, and automatically synchronizes the local directory data with the on-chain directory data based on the directory entry change events.
8. A blockchain-based on-chain directory data storage and retrieval device, characterized in that: The device comprises: The directory provider and directory table operation module is used to update the directory provider table in response to the directory provider's full life cycle management operation on the directory provider record, and perform full life cycle operations on the directory table corresponding to the directory provider record based on the update of the directory provider table; the full life cycle management operation includes adding, deleting, and updating; A directory entry operation module, used to update the directory table corresponding to the directory provider record in response to the directory provider's full life cycle management operation on the directory entry; A retrieval module is used to respond to a directory provider query request from a directory demander, generate a target directory provider list, and respond to a directory entry query request from a directory demander, and query the target directory entry from the directory table corresponding to the directory provider list; the directory provider query request carries field information recorded by the directory provider; the directory entry query request carries field information of the directory entry.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor is used to implement the blockchain-based on-chain directory data storage and retrieval method as described in any one of claims 1 to 7 when executing the program stored in the memory.
10. One or more computer-readable media having instructions stored thereon, which, when executed by one or more processors, enable the processors to execute the blockchain-based on-chain directory data storage and retrieval method as described in any one of claims 1-7.
Citation Information
Patent Citations
Data directory storage method and device based on block chain technology
CN110969429A
Data management method and device based on block chain
CN111090385A
Block chain-based data sharing method and device, and block chain-based data request method and device
CN113239376A
Data privacy protection method and system based on block chain and authority contract
CN113420319A