A system for implementing complex MySQL queries on Hyperledger Fabric
By integrating the MySQL database on Hyperledger Fabric, complex queries are implemented, solving the problem of Hyperledger Fabric's inefficient query, enhancing query capabilities and data security, and is suitable for traditional financial and supply chain systems.
Patent Information
- Application Number
- CN202411885242.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2044-12-20
AI Technical Summary
Hyperledger Fabric only supports LevelDb and CouchDB, which cannot efficiently perform complex queries and is difficult to meet the needs of traditional financial and supply chain systems.
Integrate the MySQL database on Hyperledger Fabric, implement complex queries through the ExecSql and QuerySql interfaces, use the Fabric peer node configuration file to connect to MySQL, verify the chain code to query MySQL through Grpc communication, and perform tamper-proof verification on the endorsing node.
The query function of Fabric has been enhanced, enabling more complex and efficient queries, supporting traditional financial and supply chain systems, and improving the security and consistency of data queries.
Smart Images

Figure CN119807302B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of blockchain technology, and more specifically, relates to a system for implementing complex MySQL queries on Hyperledger Fabric. Background Art
[0002] Hyperledger Fabric is an open-source, enterprise-grade, permissioned distributed ledger technology. It provides enterprise-grade security, scalability, and high performance based on a modular blockchain architecture. However, Fabric currently only supports LevelDB and CouchDB, and cannot perform efficient and complex queries within verified chaincodes. Many traditional financial and supply chain systems require complex queries, and Hyperledger Fabric's current query capabilities do not yet make it a suitable secure digital foundation for such complex systems.
[0003] However, existing technologies have some problems: Currently, Hyperledger Fabric only supports LevelDb and CouchDB, and the query function of the verification chaincode cannot well support large and complex systems such as traditional finance and supply chains. Integrating MySQL on Fabric has excellent performance in read operations and can use indexes and other methods to efficiently and quickly read large amounts of data. At the same time, MySQL can perform more complex queries, such as join queries and subqueries. Many traditional large-scale project databases also use MySQL, which enables traditional projects to be better integrated with Fabric. Therefore, we propose a system for implementing complex MySQL queries on Hyperledger Fabric. Summary of the Invention
[0004] In response to the problems existing in the prior art, the purpose of the present invention is to provide a system for implementing complex MySQL queries on Hyperledger Fabric. By integrating MySQL on Hyperledger Fabric, the query function of Fabric is enhanced, enabling it to perform more complex and efficient queries, thereby better serving complex systems such as traditional finance and supply chain.
[0005] To achieve the above-mentioned object, the present invention provides the following technical solutions: a system for implementing Mysql complex queries on Hyperledger Fabric, comprising a Hyperledger Fabric chain platform and a MySQL database;
[0006] The Hyperledger Fabric chain platform is used to store core data, perform complex queries on business data, and verify query results;
[0007] The MySQL database is used to store synchronized data copies and provide SQL queries;
[0008] The interactive interface between the Hyperledger Fabric chain platform and the MySQL database adopts the ExecSql(sqlStatements[]interface{}) interface or the QuerySql(sqlStatements[]interface{}) interface, and allows users to query through the SQL query interface;
[0009] The core data on the Hyperledger Fabric chain platform is synchronized to the MySQL database to ensure the consistency of the core data in the Hyperledger Fabric chain platform and the MySQL database.
[0010] Specifically, the Hyperledger Fabric chain platform and the MySQL database interact through the established connection interface; the Hyperledger Fabric chain platform executes the Mysql create table of the MySQL database through the ExecSql(sqlStatements[]interface{}) interface, including deleting table, modifying table, adding data, modifying data and deleting data statements.
[0011] Specifically, a QuerySql(sqlStatements[]interface{}) interface for querying data is formed between the Hyperledger Fabric chain platform and the MySQL database, and the QuerySql(sqlStatements[]interface{}) is used to execute Mysql query statements on the MySQL database.
[0012] Specifically, the Hyperledger Fabric chain platform includes a Fabric peer node, the MySQL database is a part of the Fabric peer node, the Fabric peer node adds relevant configurations of MySQL in the configuration file, and the Fabric peer node is connected to the MySQL database at the same time when it is started.
[0013] Specifically, the Hyperledger Fabric chain platform saves the executed MySQL query statement to LevelDb or CouchDb in the form of (Key, Value). The Fabric peer node is used to verify the transaction data, traverse the content of the write set, parse the value of the Value, parse out the relevant MySQL query statement, and call the ExecSql(sqlStatements[]interface{}) interface to execute the relevant statement.
[0014] Specifically, the verification chain code in the Hyperledger Fabric chain platform and the Fabric peer node communicate through Grpc. The verification chain code sends a request to query the MySQL database to the peer node. The peer node directly queries the MySQL database and then returns the query result to the verification chain code of the endorsement node for querying the MySQL database in the verification chain code. The verification chain code and the Fabric peer node use ChaincodeMessage_GET_SQL_STATE to indicate the message type or status of the Grpc communication information of the Mysql query statement. The verification chain code and the Fabric peer node process the Grpc message through the HandleSqlQueryState interface. The HandleSqlQueryState interface of the Fabricpeer node calls the QuerySql(sqlStatements[]interface{}) interface of the MySQL database being queried, and then returns the queried data to the verification chain code of the endorsement node. The verification chain code performs tamper-proof verification on the returned data, and returns the queried data after successful verification.
[0015] Specifically, the MySQL database performs tamper-proof verification on the returned data, and the Hyperledger Fabric chain platform selects several endorsement nodes on the Fabric network, and the endorsement nodes are used for tamper-proof verification of the data stored in the MySQL database on the Fabric network.
[0016] Specifically, the endorsement node includes a verification chain code VerifyMysql.cc, and the verification chain code VerifyMysql.cc verifies data through a contract method. The contract method includes func HashMysqlData(data string)(string,error) and func VerifyMysqlData(params []interface{})(bool,error). The contract method func HashMysqlData(data string)(string,error) performs salted hash processing on the data.
[0017] Specifically, the HashMysqlData method in the contract method of the verification chain code VerifyMysql.cc will perform salted hashing on the data that needs to be saved in the Hyperledger Fabric chain platform and the MySQL database, and finally use the returned salted hash value and the data to be saved as parameters to call the verification chain code method of the MySQL database, and finally save the salted hash value in the MySQL database.
[0018] Specifically, when the Hyperledger Fabric chain platform queries the data in the MySQL database on the chain, it calls the verification chain code method of the application verification chain code to query the MySQL database, and then calls the VerifyMysqlData method of VerifyMysql.cc for verification after the query data is returned.
[0019] Technical effects and advantages of the present invention:
[0020] This invention integrates the MySQL database on the Hyperledger Fabric chain platform, enhancing Fabric's query function, enabling it to perform more complex and efficient queries, thereby better serving traditional financial, supply chain and other complex systems;
[0021] Establish the ExecSql(sqlStatements[]interface{}) interface and QuerySql(sqlStatements[]interface{}) interface for data operations between the Hyperledger Fabric chain platform and the MySQL database. The QuerySql(sqlStatements[]interface{}) interface is used to implement Mysql query statement query, and the ExecSql(sqlStatements[]interface{}) interface executes Mysql table creation, including table deletion, table modification, data addition, data modification, and data deletion statements;
[0022] Add MySQL related configurations to the configuration file of the Fabric peer node so that the Fabric peer node will connect to the MySQL database when it starts, allowing MySQL query statements to be queried;
[0023] And the HandleSqlQueryState interface of the Fabric peer node calls the QuerySql(sqlStatements[]interface{}) interface of the MySQL database to be queried, and then returns the queried data to the verification chain code on the endorsement node; the verification chain code on the endorsement node performs tamper-proof verification on the returned data. After successful verification, the queried data is returned, making the data information easy to query and display;
[0024] The endorsement node's tamper-proof verification of data can improve the security of data information and prevent data information from being tampered with. It also performs salted hashing on the data. Finally, the returned salted hash value and the data to be saved are used as parameters to call the verification chain code method of the application storage MySQL database. Finally, the salted hash will also be saved in the MySQL database, which is convenient for subsequent verification to use the salted hash to determine whether the data has been tampered with.
[0025] Further features and advantages of the present invention will become apparent from the following detailed description of exemplary embodiments of the present invention with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 It is a schematic diagram of the system structure provided by the present invention;
[0027] Figure 2 This is a schematic diagram of the process of storing data in MySQL using Fabric provided by the present invention;
[0028] Figure 3This is a schematic diagram of the Fabric query and verification MySQL data flow provided by the present invention. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is further described in detail below with reference to specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0030] like Figures 1 to 3 As shown, an embodiment of the present invention provides a system for implementing Mysql complex queries on Hyperledger Fabric, characterized by including a Hyperledger Fabric chain platform and a MySQL database;
[0031] The Hyperledger Fabric chain platform is used to store core data, perform complex queries on business data, and verify query results;
[0032] The MySQL database is used to store synchronized data copies and provide SQL queries;
[0033] The interactive interface between the Hyperledger Fabric chain platform and the MySQL database adopts the ExecSql(sqlStatements[]interface{}) interface or the QuerySql(sqlStatements[]interface{}) interface, and allows users to query through the SQL query interface;
[0034] The core data on the Hyperledger Fabric chain platform is synchronized to the MySQL database to ensure the consistency of the core data in the Hyperledger Fabric chain platform and the MySQL database.
[0035] In this embodiment, preferably, the Hyperledger Fabric chain platform and the MySQL database interact through the established connection interface; the Hyperledger Fabric chain platform executes the Mysql create table of the MySQL database through the ExecSql(sqlStatements[]interface{}) interface, including delete table, modify table, add data, modify data and delete data statements;
[0036] It should be noted that establishing a connection interface facilitates the connection between the Hyperledger Fabric chain platform and the MySQL database, completing the creation of the Mysql table.
[0037] In this embodiment, a QuerySql(sqlStatements[]interface{}) interface for querying data is preferably formed between the Hyperledger Fabric chain platform and the MySQL database, and the QuerySql(sqlStatements[]interface{}) is used to execute Mysql query statements on the MySQL database;
[0038] It should be noted that by establishing the QuerySql(sqlStatements[]interface{}) interface for querying data, the Mysql query statement is queried, which facilitates data query processing on the Hyperledger Fabric chain platform and the MySQL database.
[0039] In this embodiment, preferably, the Hyperledger Fabric chain platform includes a Fabric peer node, the MySQL database is a part of the Fabric peer node, the Fabric peer node adds relevant configurations of MySQL in the configuration file, and the Fabric peer node is connected to the MySQL database at the same time when it is started;
[0040] It should be noted that the setting of Fabric peer nodes facilitates the setting of Mysql-related configurations, facilitates the connection to the MySQL database when the Fabric peer node is started, and facilitates data query and upload.
[0041] In this embodiment, preferably, the Hyperledger Fabric chain platform saves the executed MySQL query statement to LevelDb or CouchDb in the form of (Key, Value). The Fabric peer node is used to verify the transaction data, traverse the content of the write set, parse the value of the Value, parse out the relevant MySQL query statement, and call the ExecSql(sqlStatements[]interface{}) interface to execute the relevant statement;
[0042] It should be noted that the Fabric peer node verifies the transaction data, and the Mysql query statement is stored in the form of (Key, Value). The Fabric peer node parses the value of the Value, obtains the Mysql query statement, and calls the ExecSql interface to execute the relevant statement to realize the storage and processing of the data information.
[0043] In this embodiment, preferably, the verification chain code in the Hyperledger Fabric chain platform and the Fabric peer node communicate through Grpc, the verification chain code sends a request to query the MySQL database to the peer node, the peer node directly queries the MySQL database, and then returns the query result to the verification chain code of the endorsement node for querying the MySQL database in the verification chain code, the verification chain code and the Fabric peer node perform message type or state indication on the Grpc communication information of the Mysql query statement through ChaincodeMessage_GET_SQL_STATE, the verification chain code and the Fabric peer node process the Grpc message through the HandleSqlQueryState interface, the HandleSqlQueryState interface of the Fabric peer node calls the QuerySql(sqlStatements[]interface{}) interface of the MySQL database being queried, and then returns the queried data to the endorsement node verification chain code; the verification chain code performs tamper-proof verification on the returned data, and returns the queried data after successful verification;
[0044] It should be noted that the verification chaincode and Fabric peer node interact with the MySQL database through Grpc communication, which is used to query the MySQL database in the verification chaincode, and the endorsement node verification chaincode performs tamper-proof verification on the returned data. After successful verification, the queried data is returned. The data information is securely processed through tamper-proof verification to prevent the data from being tampered with when it is returned.
[0045] In this embodiment, preferably, the MySQL database performs tamper-proof verification on the returned data, and the Hyperledger Fabric chain platform selects several endorsement nodes on the Fabric network, and the endorsement nodes are used as tamper-proof verification for the data stored in the MySQL database on the Fabric network;
[0046] It should be noted that by selecting several endorsement nodes on the Fabric network, it is convenient to perform tamper-proof verification on the stored data.
[0047] In this embodiment, preferably, the endorsement node includes a verification chain code VerifyMysql.cc, and the verification chain code VerifyMysql.cc verifies data through a contract method, and the contract method includes funcHashMysqlData(data string)(string,error) and func VerifyMysqlData(params []interface{}) (bool,error), and the contract method func HashMysqlData(data string)(string,error) performs salted hash processing on the data;
[0048] It should be noted that the verification chain code VerifyMysql.cc performs salted hash processing on the data information through the contract method func HashMysqlData(data string)(string,error) to facilitate the storage of data verification information.
[0049] In this embodiment, preferably, the HashMysqlData method in the contract method of the verification chain code VerifyMysql.cc performs salted hashing on the data to be saved in the Hyperledger Fabric chain platform and the MySQL database, and finally uses the returned salted hash value and the data to be saved as parameters to call the verification chain code method of the MySQL database, and finally saves the salted hash value in the MySQL database;
[0050] It should be noted that the salted hash value and the data to be saved are stored as parameters in the MySQL database to facilitate subsequent tamper-proof verification.
[0051] In this embodiment, preferably, when the Hyperledger Fabric chain platform queries the data in the MySQL database on the chain, it calls the verification chain code method of the application verification chain code to query the MySQL database, and then calls the VerifyMysqlData method of VerifyMysql.cc for verification after the query data is returned;
[0052] It should be noted that when querying data, the returned data will be verified through the VerifyMysqlData method of VerifyMysql.cc to ensure the security of the returned data.
[0053] The specific operation process of this application:
[0054] Write data to Fabric's MySQL database
[0055] An interface is established between the Hyperledger Fabric chain platform and the MySQL database. At the same time, the ExecSql(sqlStatements[]interface{}) interface is implemented in Fabric. This interface can execute MySQL create table, delete table, modify table, add data, modify data, delete data statements, and query data. The QuerySql(sqlStatements[]interface{}) interface can execute MySQL query statements. As part of the Fabric peer node, the MySQL database is added to the configuration file of the Fabric peer node. The MySQL function is optional and has no effect on the original Fabric function. If the MySQL function is enabled, the MySQL database will be connected to the Fabric peer node when it is started.
[0056] Fabric verification chain code developers customize and assemble their own MySQL statements in the application verification chain code according to their own needs; save the MySQL statements to be executed in LevelDb or CouchDb in the form of (Key, Value).
[0057] The key is assembled in a specific format. When the Fabric peer node submits a write set, it is parsed according to the key value. The key prefix is set as follows:
[0058] Create table: CreateTable_ChaincodeName,
[0059] Delete table: DeleteTable_ChaincodeName,
[0060] Modify table: AlterTable_ChaincodeName,
[0061] Insert data: InsertData_ChaincodeName_TableName,
[0062] Modify data: DeleteData_ChaincodeName_TableName,
[0063] Delete data: UpdateData_ChaincodeName_TableName,
[0064] After the Fabric peer node successfully verifies the transaction data, it will traverse the contents of the write set. When it traverses the key value above, it will parse the value, parse the relevant MySQL query statement, and call the ExecSql interface method to execute the relevant statement. Because MySQL storage is added on top of Fabric's original LevelDb or CouchDB storage, Go language coroutine channels and producer-consumer mode technologies are used to minimize the impact of the additional MySQL operations on Fabric performance.
[0065] Query MySql data in the verification chaincode
[0066] Fabric verification chaincode is a service. Fabric verification chaincode and Fabric peer node communicate through Grpc. Fabric verification chaincode itself cannot directly connect to the database (including LevelDb, CouchDb, MySQL), and needs to communicate with Fabric peer node through Grpc to interact with the database. To query the MySQL database in the verification chaincode, it is necessary to process the Grpc message ChaincodeMessage_GET_SQL_STATE of the MySQL query on the verification chaincode end and the Fabric peer node end. The Grpc message needs to be processed through the HandleSqlQueryState interface on the verification chaincode end and the Fabric peer node end respectively. The HandleSqlQueryState method on the Fabric peer node end will eventually call the QuerySql(sqlStatements[]interface{}) of the MySQL data query interface, and then return the queried data to the endorsing node verification chaincode. The verification chaincode will perform anti-tampering verification on the returned data, and after successful verification, the queried data will be returned.
[0067] Perform tamper-proof verification on data stored in Mysql
[0068] Several endorsement nodes are elected on the Fabric network. These endorsement nodes are dedicated to anti-tampering verification of MySQL storage data on the Fabric network. Different verification endorsement nodes can be selected for verification for different applications.
[0069] Install and instantiate the verification chain code VerifyMysql.cc on the elected endorsement node. The verification chain code mainly includes the contract method for verifying data func VerifyMysqlData(params []interface{})(bool,error), and implements data hashing, func HashMysqlData(data string)(string,error). The MySQL data will be salted when hashing. Different applications have different salts. The verified endorsement node will use Fabric's own privacy data storage method to save the salt of each application. The VerifyMysqlData and HashMysqlData methods in VerifyMysql.cc will use salt when hashing or verifying MySQL data, which can prevent the application data and hash value stored in the MySQL database from being tampered with at the same time, which will cause the data in the MySQL database to be tampered with. Neither VerifyMysqlData nor HashMysqlData will change the state data of the Fabric network, that is, the transaction will not be submitted for verification by the sorting node, so the execution efficiency is high and the impact on performance is low.
[0070] The HashMysqlData method in the VerifyMysql.cc contract method performs salted hashing on the data to be saved in the MySQL database. The returned salted hash value and the data to be saved are used as parameters to call the verification chaincode method of the application that stores the MySQL data. Finally, the salted hash value is also saved in the MySQL database.
[0071] When querying the Mysql data on the chain, call the verification chain code method of the application verification chain code to query Mysql. After the data is returned, call the VerifyMysqlData method of VerifyMysql.cc for verification.
[0072] Finally, it should be noted that the above is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A system for implementing complex MySQL queries on Hyperledger Fabric, characterized in that: Includes Hyperledger Fabric chain platform and MySQL database; The Hyperledger Fabric chain platform is used to store core data, perform complex queries on business data, and verify query results; The MySQL database is used to store synchronized data copies and provide SQL queries; The interactive interface between the Hyperledger Fabric chain platform and the MySQL database adopts the ExecSql(sqlStatements[]interface{}) interface or the QuerySql(sqlStatements[]interface{}) interface, and allows users to query through the SQL query interface; The core data on the Hyperledger Fabric chain platform is synchronized to the MySQL database to ensure the consistency of the core data in the Hyperledger Fabric chain platform and the MySQL database; The Hyperledger Fabric chain platform includes a Fabric peer node, and the MySQL database is a part of the Fabric peer node. The Fabric peer node adds relevant configurations of MySQL in the configuration file, and the Fabric peer node connects to the MySQL database when it is started; The Hyperledger Fabric chain platform saves the executed MySQL query statement to LevelDb or CouchDb in the form of (Key, Value). The Fabric peer node is used to verify the transaction data, traverse the contents of the write set, parse the value of the Value, parse the relevant MySQL query statement, and call the ExecSql(sqlStatements[]interface{}) interface to execute the relevant statement; The verification chain code in the Hyperledger Fabric chain platform and the Fabric peer node communicate through Grpc. The verification chain code sends a request to query the MySQL database to the peer node. The peer node directly queries the MySQL database and then returns the query result to the verification chain code of the endorsement node for querying the MySQL database in the verification chain code. The verification chain code and the Fabric peer node use ChaincodeMessage_GET_SQL_STATE to indicate the message type or status of the Grpc communication information of the Mysql query statement. The verification chain code and the Fabric peer node process the Grpc message through the HandleSqlQueryState interface. The HandleSqlQueryState interface of the Fabric peer node calls the QuerySql(sqlStatements[]interface{}) interface of the MySQL database being queried, and then returns the queried data to the verification chain code of the endorsement node; the verification chain code performs tamper-proof verification on the returned data, and returns the queried data after successful verification.
2. A system for implementing complex MySQL queries on Hyperledger Fabric according to claim 1, characterized in that: The Hyperledger Fabric chain platform and the MySQL database interact through the established connection interface; the Hyperledger Fabric chain platform executes the Mysql create table of the MySQL database through the ExecSql(sqlStatements[]interface{}) interface, including deleting table, modifying table, adding data, modifying data and deleting data statements.
3. A system for implementing complex MySQL queries on Hyperledger Fabric according to claim 1, characterized in that: A QuerySql(sqlStatements[]interface{}) interface for querying data is formed between the Hyperledger Fabric chain platform and the MySQL database, and the QuerySql(sqlStatements[]interface{}) is used to execute Mysql query statements on the MySQL database.
4. A system for implementing complex MySQL queries on Hyperledger Fabric according to claim 1, characterized in that: The MySQL database performs tamper-proof verification on the returned data, and the Hyperledger Fabric chain platform selects several endorsement nodes on the Fabric network. The endorsement nodes are used for tamper-proof verification of the data stored in the MySQL database on the Fabric network.
5. A system for implementing complex MySQL queries on Hyperledger Fabric according to claim 4, characterized in that: The endorsement node includes the verification chain code VerifyMysql.cc, and the verification chain code VerifyMysql.cc verifies the data through the contract method. The contract method includes func HashMysqlData(datastring)(string,error) and func VerifyMysqlData(params[]interface{}) (bool,error). The contract method func HashMysqlData(data string)(string,error) performs salted hash processing on the data.
6. A system for implementing complex MySQL queries on Hyperledger Fabric according to claim 5, characterized in that: The HashMysqlData method in the contract method of the verification chain code VerifyMysql.cc will perform salted hashing on the data that needs to be saved in the Hyperledger Fabric chain platform and the MySQL database, and finally use the returned salted hash value and the data to be saved as parameters to call the verification chain code method of the MySQL database, and finally save the salted hash value in the MySQL database.
7. A system for implementing complex MySQL queries on Hyperledger Fabric according to claim 6, characterized in that: When the Hyperledger Fabric chain platform queries the data in the MySQL database on the chain, it calls the verification chain code method of the application verification chain code to query the MySQL database, and then calls the VerifyMysqlData method of VerifyMysql.cc for verification after the query data is returned.
Citation Information
Patent Citations
Block chain data query method and device
CN115248820A
System and method for supporting SQL-based rich queries in hyperledger fabric blockchains
US20200034353A1