Blockchain data storage method and on-chain data calling method based on graph database
By introducing a graph database into the blockchain system and encapsulating smart contracts as graph relations, a graph data model is constructed, which solves the problem of low efficiency of existing databases, achieves efficient data storage and retrieval, and reduces development and maintenance costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MR RAY CHENGDU TECH CO LTD
- Filing Date
- 2022-11-30
- Publication Date
- 2026-06-16
AI Technical Summary
In existing blockchain systems, using relational or non-relational databases to provide business queries for blockchain applications is inefficient and requires frequent deployment architecture modifications, increasing design and maintenance costs.
Blockchain data is stored using a graph database, and it is encapsulated into a graph relational structure through smart contracts. A graph data model with vertices, edges, labels, and attributes is constructed to achieve efficient data storage and retrieval.
It improves the data analysis efficiency of the blockchain system, reduces the complexity of business queries and the modification work, and lowers development and maintenance costs.
Smart Images

Figure CN115730013B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of blockchain data storage technology, specifically relating to a blockchain data storage method and an on-chain data retrieval method based on graph databases. Background Technology
[0002] Beyond its narrow distinction between distributed ledgers and its broader distinction between architecture and paradigms, blockchain, from a social perspective, achieves traceability, irreversibility, and immutability through cryptographic transaction mechanisms and consensus mechanisms. It reduces transaction costs through data trust, and decentralized technology lowers the trust costs between participants, enabling credit to be established within the network. In essence, this trust system still stems from the transaction system formed by people, machines, and data. While distributed ledgers enable traceability, irreversibility, and immutability, significant progress has not been made in facilitating querying, statistical analysis, and source tracing. Its basic usage pattern remains the same: finding blocks / transactions through hashes, then finding previous-generation blocks / transactions through previous-generation hashes, and so on.
[0003] In existing blockchain architectures, there are various choices regarding state databases, distributed file storage, and node databases. Typically, within a blockchain node's internal system, the state database is used to query the value corresponding to the key of on-chain data, and the hash table is used to query the index of the corresponding block and transaction. More block and transaction information is obtained through the block / blockchain. Its basic structure is as follows: Figure 1 As shown. State libraries typically use high-performance non-relational databases such as RocksDB and LevelDB, which can only support fuzzy queries with prefixes, and obtaining them by traversing and parsing block files is not a viable method.
[0004] Therefore, with the development and iteration of blockchain technology, to support large-scale business query, statistical analysis, and other operations, database components are typically mounted under nodes. By modifying and designing corresponding services, these services are executed upon startup of the blockchain node, providing the required services. The organizational structure is as follows: Figure 2 As shown.
[0005] Currently, the database selection for blockchain network node services typically uses relational / non-relational databases such as MySQLDB, SQLiteDB, OracleDB, MongoDB, and TiDB to provide relevant business queries and other operations for blockchain applications.
[0006] However, blockchain transactions operate on a key / value model at the code level. Using relational databases to implement table or join queries requires extensive adaptation and parsing modifications based on different business needs, essentially creating a customized blockchain application service. Even with the most general design, modifications to the underlying blockchain analysis will still occur due to different business requirements. Furthermore, inefficiency is inevitable when dealing with tens of millions of data points, necessitating database sharding and other deployment architecture modifications as the data volume increases. Using non-relational databases, the key / value model of blockchain transactions aligns with their characteristics. Designing data tables based on contracts is also popular, allowing for relatively simple design modifications for single-table statistical queries and convenient implementation of categorized aggregation queries. However, if the application service needs to find data relationships between tables, performance becomes inefficient not only when performing statistical analysis on single-table transactions but also when joining multiple tables. This inefficiency persists with large data volumes, requiring further architectural design modifications. Summary of the Invention
[0007] To address the problems of low query efficiency and increased design costs associated with existing technologies that use relational or non-relational databases for blockchain applications, this invention provides a blockchain data storage method based on graph databases. By introducing graph databases and leveraging their performance advantages, this invention effectively improves the data analysis efficiency within the blockchain system. Furthermore, the combination of blockchain and graph databases enables more convenient and versatile designs.
[0008] This invention is achieved through the following technical solution:
[0009] A blockchain data storage method based on graph database, comprising:
[0010] Submit the transaction and invoke the node service;
[0011] Verification is achieved through smart contracts; specifically, the smart contracts and their call encapsulation methods are graphically represented to adapt to the storage mode of the database within the node.
[0012] When the conditions are met, the data is packaged and stored through consensus to form a block.
[0013] The block content is parsed and synchronized to the node's state database and database; the node's database adopts a graph database, and a graph data model is constructed and stored based on the content of the smart contract.
[0014] In a preferred embodiment, the graph data model constructed by the present invention consists of points, edges, labels, and attributes.
[0015] In a preferred embodiment, the present invention graphically represents the relationship between smart contracts and their invocation encapsulation methods, and the transformed state is shown as follows:
[0016]
[0017] Its basic encapsulation structure maintains the internal data by grouping or encapsulating it in a readable manner according to relationships and corresponding situations.
[0018] As a preferred embodiment, the present invention parses the block content and synchronizes it to the database within the node, specifically as follows:
[0019] The storage configuration is set according to the contract agreement or the graph database is automatically started when the blockchain node starts;
[0020] Based on the key / value content of the contract, construct and store a graph data model.
[0021] In a preferred embodiment, the method of the present invention further includes:
[0022] When business service applications are needed, the node service or smart contract service can be used to directly call the database within the node to obtain various required business data.
[0023] Secondly, this invention proposes a blockchain node based on a graph database, which includes blocks, a state database, and a database.
[0024] The block parses the smart contract content and synchronizes it to the state library and the database; during the block formation process, the smart contract and its call encapsulation method are graphically represented to adapt to the storage mode of the database;
[0025] The database is a graph database, and a graph data model is constructed and stored based on the content of the smart contract.
[0026] In a preferred embodiment, the graph data model constructed by the present invention consists of points, edges, labels, and attributes.
[0027] In a preferred embodiment, the present invention graphically represents the relationship between smart contracts and their invocation encapsulation methods, and the transformed state is represented as follows:
[0028]
[0029] Its basic encapsulation structure maintains the internal data by grouping or encapsulating it in a readable manner according to relationships and corresponding situations.
[0030] Thirdly, the present invention proposes a blockchain structure based on a graph database, wherein the blockchain structure is composed of the aforementioned blockchain nodes of the present invention.
[0031] Fourthly, this invention proposes an on-chain data retrieval method based on a graph database, which is implemented based on the aforementioned blockchain structure of this invention; it includes:
[0032] When business services are needed, various required business data can be obtained by directly calling the blockchain node database through blockchain node services or smart contract services.
[0033] The present invention has the following advantages and beneficial effects:
[0034] The storage technology provided by this invention solves the complex statistics, querying, and analysis of data based on blockchain. This invention improves business service efficiency based on graph databases, and enhances service efficiency compared to the statistics and queries of relational databases / non-relational databases.
[0035] This invention, through the design of contract content, enables blockchain node databases to easily express and store data through points, edges, tags, and attributes. In contrast, relational databases require extensive analysis and transformation between actual business operations and are not suitable for generalization, while non-relational databases have significant disadvantages in implementing statistical analysis of various types of data. Attached Figure Description
[0036] The accompanying drawings, which are included to provide a further understanding of embodiments of the invention and form part of this application, do not constitute a limitation thereof. In the drawings:
[0037] Figure 1 This is an existing architecture system that enables business queries through the state database within blockchain nodes.
[0038] Figure 2 This is an existing architecture system that enables business queries through database components mounted inside blockchain nodes.
[0039] Figure 3 This is a schematic diagram illustrating the process of block generation and database data formation.
[0040] Figure 4 This is a schematic diagram of the basic relational model of a relational database.
[0041] Figure 5 This is a schematic diagram of the basic relational model for non-relational databases.
[0042] Figure 6 This is a schematic diagram illustrating the process of adapting and modifying a blockchain using a graph database, as described in an embodiment of the present invention.
[0043] Figure 7 This is a schematic diagram of the graph data model structure according to an embodiment of the present invention. In this diagram, (a) represents details such as points, edges, labels, and attributes, and (b) represents the graph database storage relationship format.
[0044] Figure 8 This is a schematic diagram of the blockchain network node service architecture according to an embodiment of the present invention. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the embodiments and accompanying drawings. The illustrative embodiments and descriptions of the present invention are only used to explain the present invention and are not intended to limit the present invention.
[0046] Example 1
[0047] like Figure 3 The block generation and database data formation process illustrated involves calling node services upon transaction submission, verifying through smart contracts, and packaging into blocks upon meeting certain conditions. A periodic service parses the block content and synchronizes it to the state repository and database. Because blockchain transactions use a key / value model, existing node databases employ a non-relational database, defining the associated smart contract as a table. Transaction content within a block (including but not limited to key, value, txHash, time, and various attributes) is defined as individual data records written to the non-relational database. If the node database were a relational database, it would require parsing the key and value, splitting the value into tables or intermediate tables (intermediate relational tables between two attribute tables) according to business logic, and then writing these tables into the same or different tables in the database. These tables need to be adapted to the business logic. A specific example illustrates the query relationship model using both relational and non-relational databases.
[0048] For example, the business scenario of Zhang San inviting Li Si to dinner.
[0049] For relational databases:
[0050] The contract includes: personnel contract and meal contract.
[0051] First, personnel information is uploaded to the blockchain to form a personnel information table; second, the transaction of Zhang San inviting Li Si to dinner is uploaded to the blockchain to form a dinner transaction table. This diagram is a simplified representation; there are also other elements such as blockchain hashing, which combine to form a more complex table. The basic relational model of a relational database is as follows: Figure 4 As shown. Figure 4The middle arrow indicates the relationships in a relational database table, typically implemented using foreign keys or coded forms. In specific business scenarios, if two tables are used—one storing personnel information (ID, gender, address, etc.) for Zhang San and Li Si, and the other storing (ID inviting someone else to dinner)—when querying and analyzing the actions of people at a specific address, a joint query of both tables is required. With large datasets and complex statistical analysis, this can impact query efficiency. Furthermore, the statistical methods must be clearly coded according to business needs. If the application scenario changes, and the entire business chain is analyzed (e.g., Zhang San sells goods to Li Si, or Zhang San purchases goods from Wang Wu, creating a separate purchase table), then three tables need to be joined based on the business logic. This necessitates extensive redevelopment of the business application and modifications to the blockchain infrastructure (how to allocate tables and fields) and smart contracts (how to add attributes for different business scenarios to adapt to the underlying data storage methods), increasing design and development complexity, hardware costs, and maintenance costs.
[0052] For NoSQL databases:
[0053] The contract includes: a meal contract for the staff.
[0054] The key / value model of blockchain transactions aligns with the characteristics of non-relational databases. Data tables are designed based on contracts, taking into account statistical data queries, and can easily implement categorized and aggregated queries. However, if the application service needs to find data relationships between tables, performance is too low when joining multiple tables, and performance efficiency also becomes inefficient when the data volume is too large. The basic relational model of non-relational databases is as follows: Figure 5 As shown. Figure 5 Let's take the example of Zhang San inviting Li Si to dinner. This is represented as a key / value pair: Zhang San's personal information, Li Si's personal information, and the details of the dinner invitation. When querying the activity or dining history of people at a specific address, or statistically analyzing the activity of people at a particular address, aggregation queries can easily retrieve the data. However, non-relational databases don't perform well with aggregation queries. Furthermore, from a design perspective, the need to transmit the entire dataset to the blockchain each time leads to excessive data redundancy, especially with large datasets. Adding further statistical analysis and querying the aggregated value further impacts performance. If implemented across multiple tables, the performance is similar to relational databases, with multi-table joins being even less efficient. Similarly, changes in business scenarios necessitate redevelopment and adaptation of business applications. While the underlying blockchain nodes and smart contracts don't require modification, their storage model results in significant memory consumption, increasing design and development complexity, hardware costs, and maintenance costs. Moreover, aggregation-based query and statistical analysis performs even worse.
[0055] Therefore, to address the aforementioned problems associated with existing node databases that use relational or non-relational databases, this embodiment proposes a blockchain data storage method based on a graph database. Specifically, as follows... Figure 6 As shown. The method includes:
[0056] Step 1: Submit the transaction and invoke the node service.
[0057] Step 2: Verify via smart contract.
[0058] Step 3: When the conditions are met, the data is packaged and stored through consensus to form a block.
[0059] Step 4: Parse the block content and synchronize it to the node's state library and database.
[0060] The database within each node utilizes a graph database. By introducing a graph database and combining it with a blockchain system, the aforementioned problems can be easily solved, providing better solutions for querying, statistics, and analysis. Furthermore, the performance advantages of graph data enhance the efficiency of the blockchain system. The relational model of the graph database is as follows: Figure 7 As shown, the relational model of a graph database consists of nodes, edges, labels, and attributes. Nodes have their own Labels and Properties, while edges can have Types and Properties. When using relational lookups, deep relational queries, or other methods with massive amounts of data, graph databases can represent various relationships to enable coherent queries, statistics, and analysis.
[0061] Graph databases offer high efficiency in storing and performing statistical analysis and queries on large datasets. Taking the scenario above as an example, after data storage is complete, when it's necessary to statistically analyze the activity of people at a given address, the Address attribute of the statistical points can be used to count all nodes. Then, related edges and nodes can be found, enabling simple and fast queries. When business scenarios change, requiring statistics on purchases and other related information, the graph database can still directly query suppliers, sellers, and buyers based on the edge relationship attributes. Graph databases primarily express the relationships between nodes, which aligns better with the essence of blockchain: establishing a transaction system between people or nodes. When business scenarios change, and nodes, edges, attributes, and tags change, it doesn't affect the graph database's ability to parse and construct node relationship states. Unlike non-relational databases, it doesn't have a large number of redundant fields. It also maintains good performance under large-scale statistical queries. The underlying nodes and smart contracts of the blockchain do not require modification; business applications only need to make corresponding modifications based on attribute changes when performing statistical analysis. Its product performance is user-friendly, and its development, hardware, and maintenance costs are all optimized.
[0062] The embodiments of the present invention have generalized the smart contract in step 2 to realize the expression of various human-machine interaction capabilities in the real world.
[0063] A blockchain contract contains the blockchain's own protocol format, such as chain ID, contract request, contract ID, calling method, caller, etc., as well as calling data information. The basic format of the contract request model is shown in Table 1 below.
[0064] The data to be retrieved is: {key:xxx,value:{xxx}}
[0065] Table 1
[0066] Chain ID Contract ID method Contract Request caller Call data
[0067] Data is encapsulated and transactions and read / write sets are generated through contract calls. After consensus verification, these are packaged and stored as blocks. The data calls are made via contract methods, and for ease of operation, a key / value format is used for non-relational data encapsulation. In computer technology, data that needs to be uploaded to the blockchain is all interactive relational data, such as transfers, operations, audits, data flow, etc. Therefore, this embodiment of the invention graphically represents the contract and call encapsulation method. The basic representation of the transition state is shown in Table 2 below.
[0068] Content breakdown of {key:xxx,value:{xxx}}
[0069] Table 2
[0070]
[0071] For example, {key: dining service 1, value: {FromPerson: {Label: Person, Properties: {Name: Zhang San, sex: male, Address: A}}, Action: {Label: friend, todo: treat to a meal}, ToPerson----}}
[0072] Its basic encapsulation structure maintains the internal data by grouping or encapsulating it in a readable manner according to relationships and corresponding situations. For example, relationship 1 is a transfer, and node M is the transfer to someone; relationship 2 is eating, and node N is eating with someone, etc.
[0073] In step 4, once the contract execution satisfies the node consensus requirements and packages the data into a block, the block content is parsed and synchronized to the state repository and the database. Specifically, storage configuration settings are configured according to the contract protocol, or the graph database is automatically started when the blockchain node starts. A graph data model is constructed and stored based on the key / value content. The specific graph data model is as follows: Figure 7The diagram shows a structure consisting of points, edges, labels, and attributes.
[0074] When a business needs to query relationships, perform statistics, or conduct analysis, it can directly call the graph database through blockchain node services or smart contract services to obtain various required business data.
[0075] The method proposed in this invention solves the problem of complex statistics and queries based on blockchain on-chain data. It improves the efficiency of business services based on graph databases, and its efficiency is improved compared to statistics and queries in relational databases / non-relational databases.
[0076] The essence of blockchain contracts and on-chain content is to establish a transaction and mutual trust mechanism between points. From the perspective of practical engineering, graph databases are introduced. By designing contract values, blockchain node databases can easily realize the expression and storage of points, edges, tags, and attributes. In contrast, relational databases require a lot of analysis and transformation between actual business and are not suitable for generalization. Non-relational databases have a huge disadvantage when implementing statistical analysis of various types of data.
[0077] This invention also proposes a blockchain node, which includes blocks, states, and a node database. The node database is a graph database, used to express and store the content of blocks through points, edges, labels, and attributes. This facilitates business services by directly calling the graph database through the blockchain node service to realize various required data services.
[0078] This invention also proposes a blockchain structure composed of the aforementioned blockchain nodes. This structure can directly call the blockchain node database through blockchain node services to realize business services such as on-chain data query and statistics.
[0079] Example 2
[0080] This invention proposes an on-chain data retrieval method based on the blockchain structure of Embodiment 1 described above, specifically as follows: Figure 8 As shown.
[0081] When a business needs to query relationships, perform statistics, and analyze data, it can directly access the blockchain node database through the blockchain node service to obtain the required data.
[0082] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A blockchain data storage method based on a graph database, characterized in that, include: Submit the transaction and invoke the node service; Verification is performed through smart contracts; among which, the smart contracts and their call encapsulation methods are graphically relationalized, and the state is transformed as follows: the smart contract and its call encapsulation format {key,value} is converted into {key,node,relationship1,nodeM,relationship2,nodeN}. Its basic encapsulation structure maintains the internal data grouped according to the relationship and corresponding situation or encapsulated for readability, so as to adapt to the storage mode of the database within the node. When the conditions are met, the data is packaged and stored through consensus to form a block. The block content is parsed and synchronized to the node's state database and database; the node's database is a graph database, which constructs and stores a graph data model based on the content of the smart contract. The block content is parsed and synchronized to the database within the node, specifically as follows: The storage configuration is set according to the contract agreement or the graph database is automatically started when the blockchain node starts; Based on the key / value content of the contract, construct and store a graph data model. 2.The method of claim 1, wherein, The constructed graph data model consists of points, edges, labels, and attributes.
3. The method of claim 1 or 2, wherein, Also includes: When business service applications are needed, the node service or smart contract service can be used to directly call the database within the node to obtain various required business data. 4.A blockchain node device based on a graph database, characterized in that, The blockchain node device includes blocks, a state database, and a database. The block parses the smart contract content and synchronizes it to the state library and database. During the block formation process, the smart contract and its call encapsulation method are graphically represented, and the state is transformed as follows: the smart contract and its call encapsulation format {key, value} is converted into {key, node, relationship 1, node M, relationship 2, node N}. Its basic encapsulation structure maintains the internal data grouped according to the relationship and corresponding situation or encapsulated for readability, so as to adapt to the storage mode of the database. The database is a graph database, and a graph data model is constructed and stored based on the content of the smart contract.
5. The blockchain node device based on a graph database according to claim 4, characterized in that, The constructed graph data model consists of points, edges, labels, and attributes.
6. A blockchain device based on a graph database, characterized in that, The blockchain device is composed of the blockchain node device as described in any one of claims 4-5.
7. A method for on-chain data retrieval based on a graph database, characterized in that, This method is implemented based on the blockchain device described in claim 6; It includes: When business services are needed, various required business data can be obtained by directly calling the blockchain node database through blockchain node services or smart contract services.