Heterogeneous multi-chain-oriented universal evidence storage and retrieval method and system
By designing a system that does not require the development of certificate deposit contracts in a heterogeneous multi-chain environment, the unified storage and retrieval of semi-structured JSON data is achieved, solving the versatility and retrieval problems of certificate deposit services in a heterogeneous blockchain environment. It provides full-text retrieval and data confidentiality guarantee, improving the query efficiency and flexibility of blockchain data.
Patent Information
- Application Number
- CN202310213520.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-08
- Publication Date
- 2024-09-10
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In a heterogeneous blockchain environment, existing technology is difficult to provide universal certificate storage services across multiple blockchains, especially the storage and retrieval of semi-structured JSON data, and lacks full-text retrieval capabilities and data confidentiality guarantees.
Designed a system that does not require users to develop certificate contracts in a heterogeneous multi-chain environment. It can store and retrieve JSON data, provide user permission control based on data type, use full-text index to achieve flexible query, and combine WebAssembly smart contracts and zones. Blockchain SDK performs data storage and query.
It realizes the unified storage and retrieval of semi-structured data in a heterogeneous multi-chain environment, provides cross-chain full-text retrieval capabilities and data confidentiality guarantees, and improves the query efficiency and flexibility of blockchain data.
Smart Images

Figure FT_1 
Figure FT_6 
Figure FT_2
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of semi-structured data storage and retrieval on a blockchain, and in particular to a heterogeneous multi-chain environment. Background Art
[0002] With the in-depth development of web3.0, the construction of various heterogeneous blockchains has become a common situation. Therefore, how to provide a universal evidence storage service across heterogeneous blockchains and provide a unified query interface for evidence storage data on multiple blockchains has become a technical problem that needs to be solved urgently.
[0003] In most blockchain systems, the data on the chain is encrypted binary data, so it is very difficult to retrieve the evidence data on the blockchain. From a business perspective, querying the corresponding original block data through business data is an essential business requirement. How to make up for this limitation of the blockchain and provide full-text retrieval capabilities for evidence in the general evidence service, while ensuring the confidentiality of the data, is also a problem that the general evidence service needs to solve.
[0004] Publication No. CN110851127A implements a universal evidence storage service, but is limited to a specific blockchain system, and there is a coupling correspondence between the evidence storage data structure and the smart contract.
[0005] The purpose of the present invention is to solve the multi-chain storage and retrieval of non-specific semi-structured JSON data in a heterogeneous multi-chain environment.
[0006] The following are relevant references: (1) Bai Yujie. “Chang’an Chain”, my country’s first autonomous and controllable blockchain[J]. Zhongguancun, 2021(04):62-65. (2) Web3.0: The new generation of Internet is gradually approaching, Yao Qian, China Finance, 2022-03-16. (3) Research on electronic data storage technology based on blockchain Lu Yiming; Ding Shumeng; Jiang Shuhan; Fan Pengyi; Zhang Yunfan Network Security Technology and Application 2022-11-04 (4) Research on electronic evidence storage technology based on blockchain Xu Ronghong North China University of Technology 2022-06-06 Master (5) A universal evidence storage method based on blockchain, publication number CN110851127A. Summary of the invention
[0007] The present invention discloses an arbitrary semi-structured data that can be stored on multiple chains and expressed as JSON in a heterogeneous multi-chain environment, without the need for users to develop a notarization contract; at the same time, it provides full-text retrieval of semi-structured data, and provides a notarization service interface for user authority control according to data type, providing an example for data fusion under heterogeneous multi-chain.
[0008] Compared with the evidence storage service on the traditional blockchain, users do not need to develop smart contracts, but only need to provide the JSON schema of the data type. They can also configure user access rights according to the data type, or store data on different blockchains, and realize flexible business query capabilities of blockchain data based on the full-text retrieval capability of business data. Description of the drawings: (1) Figure 1 The overall architecture of the universal evidence storage service (2) Figure 2 Data authority management and data verification flow chart (3) Figure 3 Blockchain connector based on plugin interface (4) Figure 4 Simple full-text indexing of evidence data (5) Figure 5 Evidence writing process (6) Figure 6 Evidence retrieval process. DETAILED DESCRIPTION
[0011] Overall system structure.
[0012] The overall architecture of the universal evidence contract automatic generation and indexing system is as follows: Figure 1 As shown, the system mainly includes the following main parts: (1) API service: It is a high-speed http server that provides general evidence storage services based on the RESTful API specification; (2) Data permissions: Define data permissions for adding, checking, modifying and deleting data according to the business data type. Different access permissions are divided according to the user's organization, department, position, etc. to limit users' unauthorized access to sensitive business data; (3) Data verification: For different business data, define the JSON schema corresponding to the data type. Based on this, perform format verification on the business data submitted by the user to prevent illegal data formats; (4) Business query: Data on the blockchain is basically stored in encrypted hash form, and the encryption level is generally very high. Due to the encryption algorithm, it is impossible to query or summarize data by business category. Therefore, it is necessary to provide business query capabilities outside the blockchain to meet the needs of business statistics, aggregation, and query. (5) Full-text indexing: Business query requirements are generally flexible and changeable. Full-text indexing can meet flexible and random business query needs. (6) Connector: As a general evidence storage service, it is generally not limited to a specific blockchain system. However, in order to achieve a seamless connection between the evidence storage service and the blockchain, it is necessary to develop a connector for a specific blockchain system using the blockchain SDK so that the smart contract on the blockchain can be called to complete the storage and query of business data on the blockchain; (7) WebAssembly smart contract: Smart contracts are logical encapsulations of business interactions on the blockchain. Smart contracts for evidence storage services have the main function of adding and querying JSON data. Depending on the function of the blockchain, they can give priority to supporting data indexing based on business fields to improve the query efficiency and query capability of block data.
[0013] Data type and permission management.
[0014] like Figure 2 As shown, the identity verification process is as follows: take out the value corresponding to the Authorization parameter in the request header, parse the value with base64, and get the encoded certificate. By parsing the certificate, you can get the sender's id, ou and org information, and then verify this information. After the verification passes, you can proceed to the next step.
[0015] like Figure 2 As shown in the figure, the data verification process is as follows: take out the datatype field in the request body, use the pre-saved json schema file to match the datatype, if the match is successful, use the corresponding json schema under the corresponding path to verify the json data, after the verification is successful, you can proceed to the next step, if the datatype match fails, it will prompt that there is no such data type.
[0016] Table 1: Data permissions and verification core interface: type Config struct { Models []Model Acls []Acl } type Model struct { Name string Schema string } type Acl struct { Model string Role string Operation string Action string }.
[0017] The following is the core code for certificate verification. Finally, the variable org can be obtained for further verification.
[0018] Table 2: User certificate verification core code / / Get certificate parameters decodeBytes, err := base64.StdEncoding.DecodeString(cert) ... certBlock, _ := pem.Decode([]byte(string(decodeBytes))) .... certBody, err := x509.ParseCertificate(certBlock.Bytes) .... org := certBody.Subject.Organization[0]
[0019] Table 3: Data verification core code: schemapath = schemapa + schemapath j := 0 flag := 0 num2 := len(conf.Config.Acls) if TestSchema(schemapath, bodyAsByteArray) { Loop2: for j <num2 { if org == conf.Config.Acls[j].Role { if conf.Config.Acls[i].Operation == "create" { flag = 1 break Loop2 } else { context.JSON(401, gin.H{"message": "no that item"}) } } j = j + 1 } if flag == 0 { logging.warn("The user cannot be found") } } else { logging.warn("Verification failed") }.
[0020] Table 4: Example of a schema for data type definition { "$schema": "https: / / json-schema.org / draft-04 / schema#", "title": "Contract", "description": "Contract schema", "type": "object", "properties": { "ContractId": { "description": "The unique identifier for a contract", "type": "string" }, "ContractType":{ "type": "string" }, "Terms":{ "type": "array", "items": { "type": "string" }, "minItems": 1, "maxItems": 2, "uniqueItems": true }, "Timestamp": { "type": "integer" } }, "required": [ "ContractId", "ContractType", "Terms", "Timestamp" ] }
[0021] Blockchain connection plugin.
[0022] In plug-in mode, multiple blockchain systems are connected through universal grpc. The overall plug-in architecture is as follows Figure 3 As shown. Among them: (1) Blockchain plug-in interface: an abstract, universal blockchain plug-in interface that allows upper-layer applications to call underlying blockchain services in a universal way without having to pay attention to the specificity of the blockchain; blockchain plug-ins generally provide services to the outside in the form of grpc services, and the main program calls grpc and uses independently started connector services, which gives the connector greater implementation and deployment flexibility; (2) XX Chain Connector: A blockchain connector service implemented based on the blockchain plug-in interface and using the SDK of a specific blockchain. This module implements the physical link of a specific blockchain and the call to the smart contract.
[0023] Table 4: Common plug-in interface: type Plugin interface { Init(ctx context.Context, prefix config.Prefix, callbacksCallbacks) error Start() error InvokeContract(ctx context.Context, operationID *types.UUID,signingKey string, location *types.JSONAny, method *types.FFIMethod, inputmap[string]interface{}) error QueryContract(ctx context.Context, location *types.JSONAny, method *types.FFIMethod, input map[string]interface{}) (interface{}, error) AddSubscription(ctx context.Context, subscription *types.ContractListenerInput) error DeleteSubscription(ctx context.Context, subscription *types.ContractListener) error ...... } type Event struct { Source string Name string Output types.JSONObject Info types.JSONObject Timestamp *time.Time BlockchainTXID string }。
[0024] Table 5: Core code of chainmaker connector: msg, err := utils.YAMLorJSONPayload(req) if err != nil { w.hookErrReply(res, req, err, 400) return } if msg["meth"] == "save" { filecontent := msg["fileContent"].(string) key := msg["key"].(string) id := msg["id"].(string) ou := msg["ou"].(string) org := msg["org"].(string) filehash, err := cmk.Save(key, filecontent, id, ou, org) if err == nil { reply := MyMsg{true, "send success", filehash} w.sendWebhookReply(res, req,&reply) } else { reply := MyMsg{false, "send failed", ""} w.sendWebhookReply(res, req,&reply) } } else if msg["meth"] == "find" { hash := msg["hash"].(string) res2, err := cmk.Find(hash) if err == nil { reply := MyMsg2{true, "123", "find success", res2.FileContent,res2.FileHash, res2.ID, res2.Org, res2.Ou, res2.TimeStamp} w.sendWebhookReply(res, req,&reply) } }
[0025] Lightweight full-text indexing.
[0026] For more flexible business support, such as fuzzy query, full-text index is generally required. Common elasticsearch is a full-text index with very powerful functions, but it consumes a lot of resources and has a more complex deployment architecture. Therefore, for a single evidence storage service, a relatively simple and efficient full-text index is required. The present invention uses bleve+gse implemented by golang to implement core services such as word segmentation, indexing and index storage to improve execution efficiency and support efficient operation with less resources.
[0027] The simplified full-text index implementation architecture is as follows Figure 4 shown.
[0028] Table 6: Core structures and functions related to full-text indexing / / Datatype field data type type Datatype string var TextFieldDatatype Datatype = "text" var NumbericFieldDatatype Datatype = "numberic" var DatetimeFieldDatatype Datatype = "datetime" var BoolFieldDatatype Datatype = "bool" func createFieldMapping(fieldType Datatype) *mapping.FieldMapping { switch fieldType { case TextFieldDatatype: return bleve.NewTextFieldMapping() case NumbericFieldDatatype: return bleve.NewNumericFieldMapping() } ..... return nil } / / FieldIndexConfig defines indexing config for document fields type FieldIndexConfig struct { FieldName string FieldDatatype Datatype FieldPath string FieldIndex bool FieldStore bool Language string } / / DocIndexConfig defines configuration about document index type DocIndexConfig struct { DocType string FieldsConfig []FieldIndexConfig } / / IndexingDoc index json file func IndexingDoc(docType string, docID string, docContent string)error { docIndex := InitDocIndex(docType) batch := (*docIndex).NewBatch() return batch.Index(docID, docContent) }.
[0029] Evidence storage service.
[0030] The process of writing evidence data is as follows: Figure 5 As shown in the figure, when writing evidence, the evidence service first checks the user permissions according to the ACL access control defined in the json type. The user information comes from the user certificate or the authorization data in the http header. If it meets the ACL permissions, the block data is written first, and the block ID number is returned. Then, the block ID number is used as the primary key to index the data corresponding to the json path related to the json.
[0031] The process of retrieving evidence data is as follows: Figure 6 As shown, when retrieving stored data, you need to provide the name of the json type, the json path of the search field, and the search keyword; for evidence retrieval, first check the user ACL permission; if the permission verification is passed, search the document index according to the field and keyword, and return the block ID as the search result; then use the block ID as a parameter to query the corresponding block content.
[0032] WebAssembly smart contracts.
[0033] Compared with other contract technologies, WebAssembly contracts have high operating efficiency, good support environment, rich code expression capabilities, and support for online dynamic upgrades. Therefore, more and more blockchains are beginning to support WebAssembly contracts.
[0034] The present invention adopts WebAssembly contract, and the data Fact structure stored in the contract is as follows: (1) file_hash: json hash value, (2) chain_name: blockchain name, (3) file_content: json data content, (4) time_stamp: timestamp, (5) ou: department, (6) org: organization code.
[0035] Table 7: Rust webAssembly contract data structure and core functions struct Fact { fact_id: String file_hash: String, chain_name: String, file_content: String, time_stamp:String, ou: String, org: String, ec: EasyCodec, } / / save save the evidence data pub extern "C" fn save() { / / Get the context let ctx =&mut sim_context::get_sim_context(); / / Get the incoming parameters let fact_id = ctx.arg_as_utf8_str("fact_id"); let file_hash = ctx.arg_as_utf8_str("file_hash"); let chain_name= ctx.arg_as_utf8_str("chain_name"); let file_content = ctx.arg_as_utf8_str("file_content"); ...... / / event ctx.emit_event("topic_vx",&fact.get_emit_event_data()); / / Store after serialization ctx.put_state( "fact_ec", fact.file_hash.as_str(), fact.marshal().as_slice(), ); } / / find_by_file_hash queries the stored data based on file_hash pub extern "C" fn find_by_file_hash() { / / Get the context let ctx =&mut sim_context::get_sim_context(); / / Get the incoming parameters let file_hash = ctx.arg_as_utf8_str("file_hash"); .... / / Query let r = ctx.get_state("fact_ec",&file_hash); let fact_vec = r.unwrap(); ... / / Query let r = ctx.get_state("fact_ec",&file_hash).unwrap(); let fact = Fact::unmarshal(&r); let json_str = fact.to_json(); / / Return the query results ctx.ok(json_str.as_bytes()); }
Claims
1. A general evidence storage and retrieval method and system for heterogeneous multi-chain, characterized by including the following main modules: (1) Data type definition and access rights: define data types, data validation, and access rights based on data types; (2) Connection plug-in: In plug-in mode, expand the connection plug-in for specific blockchains and support multi-chain access; (3) Evidence data service interface: supports the storage and retrieval of semi-structured evidence data according to business attributes and data types.
2. According to module (1), define data types, user access rights, and the target blockchain system of the route based on JSON schema, including interface definition, data model definition, etc.
3. According to module (2), the contract call interface and blockchain event collection for each blockchain are encapsulated in the form of a unified grcp interface plug-in, including the plug-in interface and event definition, as well as related implementation methods.
4. According to module (3), the semi-structured evidence data storage, retrieval and query method includes the evidence data format definition, data interface and implementation method; and the indexing method and retrieval interface function of JSON data.
