System for realizing Mysql complex query on Hyperledger Fabric
By integrating MySQL database on Hyperledger Fabric, Fabric's query function is enhanced, and Fabric's query function is solved. Fabric cannot effectively support complex queries, and it realizes more complex and efficient query capabilities, which are suitable for complex systems such as traditional finance and supply chains.
Patent Information
- Application Number
- CN202411885242.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2044-12-20
AI Technical Summary
Hyperledger Fabric currently only supports LevelDb and Couchdb, and cannot effectively support efficient and complex queries in large and complex systems such as traditional finance and supply chains.
Integrate MySQL database on Hyperledger Fabric, enhance Fabric's query functionality through ExecSql and QuerySql interfaces, enabling it to perform more complex and efficient queries.
It realizes the better application of Hyperledger Fabric in complex systems such as traditional finance and supply chain, provides more complex and efficient query capabilities, and improves the performance and applicability of the system.
Smart Images

Figure CN119807302A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of blockchain, and more specifically, particularly relates to a system for implementing Mysql complex queries on Hyperledger Fabric. Background Art
[0002] Hyperledger Fabric is an open source enterprise-level permissioned distributed ledger technology that provides enterprise-level 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 in the verification chain code. Many traditional financial systems and supply chain systems require complex queries, and the current Hyperledger Fabric query function cannot make it a good secure digital foundation for such complex systems.
[0003] However, there are some problems with the existing technology: Currently, Hyperledger Fabric only supports LevelDb and Couchdb, and the query function of the verification chain code cannot well support large and complex systems such as traditional finance and supply chain; MySQL is integrated on Fabric. MySQL has excellent performance in reading 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, connection queries, subqueries, etc.; many traditional large project databases also use MySQL, which enables traditional projects and Fabric to be better combined. Therefore, we propose a system for implementing complex MySQL queries on Hyperledger Fabric. Summary of the invention
[0004] In view of the problems existing in the prior art, the purpose of the present invention is to provide a system for implementing MySQL complex 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 traditional financial, supply chain and other complex systems.
[0005] To achieve the above object, the present invention provides the following technical solutions: a system for implementing Mysql complex query on Hyperledger Fabric, comprising a Hyperledger Fabric chain platform and a 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.
[0006] 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.
[0007] 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.
[0008] 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 a configuration file, and the Fabric peer node is connected to the MySQL database at the same time when it is started.
[0009] Specifically, the Hyperledger Fabric chain platform saves the executed Mysql query statement in LevelDb or CouchDb in the form of (Key, Value), the Fabric peer node is used to verify the transaction data, and 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.
[0010] Specifically, the verification chain code in the Hyperledger Fabric chain platform communicates with the Fabric peer node 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, which is used to query the MySQL database in the verification chain code, the verification chain code and the Fabric peer node perform message type or status 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 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.
[0011] 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.
[0012] 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.
[0013] Specifically, the HashMysqlData method in the contract method of the verification chain code VerifyMysql.cc will perform salted hashing on the data 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 stored in the application, and finally save the salted hash value in the MySQL database.
[0014] 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.
[0015] Technical effects and advantages of the present invention: The present invention integrates the MySQL database on the Hyperledger Fabric chain platform, enhances the query function of Fabric, enables it to perform more complex and efficient queries, and thus better serve traditional financial, supply chain and other complex systems; 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; Add the relevant configuration of MySQL in the configuration file through the Fabric peer node, so that the Fabric peer node will connect to the MySQL database at the same time when it starts, so that the MySQL query statement can be queried; 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, and after successful verification, returns the queried data, making the data information easy to query and display; The endorsement node's tamper-proof verification of data can improve the security of data information, prevent data information from being tampered with, and perform 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, so that the salted hash can be used to determine whether the data has been tampered with during subsequent verification.
[0016] 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 attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a schematic diagram of the system structure provided by the present invention; Figure 2 It is a schematic diagram of the process of Fabric storing data to Mysql provided by the present invention; Figure 3 This is a schematic diagram of the Fabric query verification Mysql data flow provided by the present invention. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention is further described in detail below in conjunction with 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.
[0019] like Figures 1 to 3 As shown, a system for implementing Mysql complex query on Hyperledger Fabric provided by an embodiment of the present invention is characterized by comprising a Hyperledger Fabric chain platform and a 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.
[0020] 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; It should be noted that establishing a connection interface facilitates the connection between the Hyperledger Fabric chain platform and the MySQL database, and completes the creation of the Mysql table.
[0021] 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; 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 MySQL database.
[0022] 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; It should be noted that the setting of the Fabric peer node facilitates the setting of the relevant configuration of Mysql, facilitates the connection to the MySQL database when the Fabric peer node is started, and facilitates the query and upload of data.
[0023] In this embodiment, preferably, the Hyperledger Fabric chain platform saves the executed Mysql query statement in LevelDb or CouchDb in the form of (Key, Value), the Fabric peer node is used to verify the transaction data, and 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; 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.
[0024] In this embodiment, preferably, the verification chain code in the Hyperledger Fabric chain platform and the Fabricpeer 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, which is used to query 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; 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.
[0025] 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 for tamper-proof verification of the data stored in the MySQL database on the Fabric network; 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.
[0026] 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; It should be noted that the verification chain code VerifyMysql.cc uses the contract method func HashMysqlData(data string)(string,error) to perform salted hash processing on the data information to facilitate the storage of data verification information.
[0027] 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; 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.
[0028] 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; 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.
[0029] The specific operation process of this application: Write data in Fabric's MySQL database An interface is established between the Hyperledger Fabric chain platform and the MySQL database, and the ExecSql(sqlStatements[]interface{}) interface is implemented in Fabric, which 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; MySQL database is part of the Fabric peer node, and Mysql related configuration 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; Fabric verification chaincode developers customize and assemble their own MySQL statements in the application verification chaincode according to their own needs; save the MySQL statements to be executed in LevelDb or CouchDb in the form of (Key, Value). 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 prefix setting of the key is as follows: Create table: CreateTable_ChaincodeName, Delete table: DeleteTable_ChaincodeName, Modify table: AlterTable_ChaincodeName, Insert data: InsertData_ChaincodeName_TableName, Modify data: DeleteData_ChaincodeName_TableName, Delete data: UpdateData_ChaincodeName_TableName, After the Fabric peer node successfully verifies the transaction data, it will traverse the content of the write set. When it traverses to the key value above, it will parse the value of the Value, parse out the relevant Mysql query statement, and call the ExecSql interface method to execute the relevant statement; because Mysql storage is added on the basis of Fabric's original LevelDb or Couchdb storage, the Go language's coroutine channel, producer-consumer mode and other technologies are used to minimize the impact of the additional Mysql operation on Fabric performance; Query MySql data in the verification chaincode Fabric verification chaincode is a service. Fabric verification chaincode communicates with Fabric peer node through Grpc. Fabric verification chaincode itself cannot directly connect to database (including LevelDb, CouchDb, Mysql), and needs to communicate with Fabricpeer node through Grpc to interact with database. To query Mysql database in verification chaincode, it is necessary to process Grpc message ChaincodeMessage_GET_SQL_STATE of Mysql query on verification chaincode end and Fabric peer node end. Grpc message needs to be processed through HandleSqlQueryState interface on verification chaincode end and Fabric peer node end respectively. HandleSqlQueryState method on Fabric peer node end will eventually call QuerySql(sqlStatements []interface{}) of querying Mysql data interface, and then return the queried data to endorsement node verification chaincode. Verification chaincode will perform tamper-proof verification on the returned data, and return the queried data after successful verification. Verify the data stored in MySQL to prevent tampering Several endorsement nodes are elected on the Fabric network. These endorsement nodes are dedicated to tamper-proof verification of MySQL storage data on the Fabric network. Different verification endorsement nodes can be selected for verification of different applications. 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). When hashing, the Mysql data will be salted and hashed. 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. The HashMysqlData method in the contract method VerifyMysql.cc performs salted hashing on the data to be saved in the MySQL database, uses the returned salted hash value and the data to be saved as parameters, calls the verification chain code method for storing Mysql data in the application, and finally saves the salted hash value in the MySQL database; When querying 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.
[0030] 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, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments or to 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 protection scope 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.
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 Mysql complex 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 Mysql complex queries on Hyperledger Fabric according to claim 3, characterized in that: 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 a configuration file, and the Fabric peer node is connected to the MySQL database at the same time when it is started.
5. A system for implementing Mysql complex queries on Hyperledger Fabric according to claim 4, characterized in that: 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.
6. A system for implementing Mysql complex queries on Hyperledger Fabric according to claim 5, characterized in that: The verification chain code in the Hyperledger Fabric chain platform communicates with the Fabric peer node 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 indicate the message type or status of 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 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.
7. A system for implementing Mysql complex queries on Hyperledger Fabric according to claim 6, 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, and the endorsement nodes are used for tamper-proof verification of the data stored in the MySQL database on the Fabric network.
8. A system for implementing Mysql complex queries on Hyperledger Fabric according to claim 7, characterized in that: 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(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.
9. A system for implementing Mysql complex queries on Hyperledger Fabric according to claim 8, characterized in that: The HashMysqlData method in the contract method of the verification chain code VerifyMysql.cc will salt and hash 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.
10. A system for implementing complex MySQL queries on Hyperledger Fabric according to claim 9, 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