Business interaction process

The HyperGraph project is based on serving high-performance public chains, meeting the data needs of application development and reducing the threshold for developers and the cost of maintaining back-end services. HyperGraph aims to build a high-performance blockchain data service network. This high-performance includes two aspects. On the one hand, it meets the needs of high-performance blockchains like HECO, and on the other hand, it must meet the needs of decentralized services. At the same time, it has efficient service capabilities. In this data service network, the HyperGraph core developer team builds infrastructure and standards, provides development, optimization and maintenance solutions, coordinates network operations, index nodes build network nodes according to standards, and provides data storage, index query, API services, etc., participate Build the network together and get benefits. Developers define data acquisition requirements according to their own business, and use network resources to serve their own and third-party business services that require them. Pass holders can support the construction of network nodes by collateralizing the pass, and obtain value-added benefits of their own digital assets. Form an overall effective data service ecosystem.

2.1、Cloud infrastructure

In order to provide high-performance blockchain data services, HyperGraph sets standards and builds cloud infrastructure with all participants. The cloud infrastructure consists of two parts, one is a data index network composed of the bottom layer of each node, and the other is a tool that uses cloud facilities. , API and user interface. The schematic is shown in Figure 1. It should be noted here that each node in Figure 1 is not operated by a specific entity in the network, but is a member of the decentralized node in the HyperGraph network. The incentive coordination between each other is also coordinated by the contract on the blockchain, and the message transmission truly allows developers to use the HyperGraph service to achieve full-stack decentralization.

Developers submit their own requirements for data query and indexing through interface interaction, such as GraphQL query language, subgraph data set definition, etc. Use tools for convenient query and node construction, use APIs to query data, or combine HyperGraph API and Web3 API to initiate services such as meta transaction signatures to the HyperGraph network.

2.1.1、Data index network

Unlike traditional databases, the data stored on the blockchain does not have the concept of fields, and there is no relational query language available, and all applications share the same repository. Therefore, the data query itself becomes extremely difficult compared to traditional databases. Taking DEX business as an example, there is no quick way to query the transaction volume and transaction details of a certain trading pair in a certain period of time. The specific method has to be scanned. All the data of all blocks in the time period will be scanned out of the transactions belonging to the relevant contract, and then the specific transaction pair will be matched, and the data will be combined and calculated. This calculation method is very inefficient.

There are also projects such as TheGraph that provide open source processing methods, but there are two key points. First, the vast majority of open source software currently only supports the Ethereum network, and does not quickly support other high-performance blockchain networks, even if it supports There is also a relatively long time period. The second is that the services themselves are designed based on the Ethernet network, and many designs, especially performance, do not optimize the high-performance blockchain network.

Of course, developers can also use open source software to build their own data analysis nodes, just like in the era of cloud computing, users also set up their own servers to IDC. However, self-built nodes have the following costs and risks

  1. The DApp project focuses on the development of its own business logic, smart contracts, etc., and then increases the deployment of server-side nodes, which places higher requirements on personnel, which will inevitably increase labor costs

  2. Due to the large file size of the blockchain public chain storage itself, the full-node mode requires more storage space and good machine performance. For part of the business query, the full amount of data is synchronized, which brings a waste of hardware costs.

  3. Constructing the query index node by itself is a pure investment, and there is a single point of failure to a certain extent. The accumulation of optimization experience in performance and other aspects is also a relatively long-term process

In summary, in order to allow developers to focus on their own business, HyperGraph has built a data index network. For the open source software that can support data indexing, HyperGraph selects a matching data network software and hardware combination, specifically for high-performance blockchain, optimized parameters, storage, etc., can be extended in parallel, and added some special functions. At the same time, the index node is not only provided by HyperGraph developers, but also uses HGT incentives to build nodes together. On the one hand, it is more decentralized, better to avoid single points of failure, and users vote and incentivize to improve the quality of service. On the other hand, a larger data indexing network is also formed to give full play to the value of data

2.2 Business interaction process

The previous chapter introduced the basic use of HyperGraph, and what is HyperGraph in the chapter on HyperGraph? So this chapter is straight to the point, how to develop a subgraph and submit it to HyperGraph

In the traditional relational database, in order to improve the query speed, we need to build an index on the data of the data table. In the blockchain query, the same is true. If we want to obtain a stable query result, we must first get the data from the chain in advance and index the data. This process requires the development of the subgraph. The developer completes the development of the subgraph and provides it to HyperGraph. HyperGraph's data engine will automatically run the data index of the deployed subgraph. After the index is completed, the developer can use a Graph API link to submit Query to obtain the desired query result.

A subgraph is a specific project that can be deployed on the HyperGraph network. Just like a smart contract project deployed on the blockchain can run logic and store data on the blockchain, a subgraph project deployed on the HyperGraph can also be used. Let the HyperGraph data engine index the block data of the high-performance blockchain, and provide a query interface after the index is stored.

The subgraph item is described or defined by a yaml file. This subgraph query is for which smart contract, the data of which event of the smart contract needs to be analyzed, and tells HyperGraph how to store the data in the event in the database, so as to finally realize the query conveniently.

When you have developed a subgraph application, if it is deployed in API mode, you can use the Graph CLI command line tool to deploy the subgraph. More detailed commands are provided in the Dashboard (console) of HyperGraph. The definition of the subgraph is first stored in IPFS through the command, and then the index node is also notified to start indexing data for the subgraph through the authority authentication password. The following figure shows the more detailed data flow in more detail, and tells how to process the transactions and data of the blockchain network after the sub-figure is deployed.

The above figure outlines the specific data and business interaction process, and here is a specific example for illustration. Take the user's Swap digital assets on the DEX as an example to illustrate how the data is generated from the user, and then stored on the blockchain network, and then analyzed and stored by the index node, and then the front-end developer fetches the data for display.

  1. DApps are generally serverless applications, that is, there is no database on the server side, and there is no dynamic script for server-side processing directly related to users. The program consists of two parts. One part is a smart contract responsible for routing, transaction pair generation, transaction and liquidity pool logic processing, etc., deployed on the blockchain, and the other part is static resources and scripts, including pictures, CSS, JavaScript, etc., It is deployed on a static server and is provided to users through CDN acceleration. Users interact with DApps through wallet support for Web3 API.

  2. Users use DEX to exchange one asset for another. For example, to exchange HUSD for WHT, the user selects the currency of the trading pair on the interface, as shown in Figure 3.

Since the HUSD HRC20 Token is used for the first time, Approve is required first. Approve is to authorize the contract to use your Token quota and then Swap. Because HUSD and HT do not have a direct liquidity pool or a direct liquidity pool, there is no ideal price. , And now there are pools of HUSD and HBTC and HBTC and WHT (WHT can be understood as the HRC20 mapping of the native Gas asset HT) with better liquidity or better prices, so a layer of intermediate exchange is added, and HUSD is automatically exchanged by the contract It is converted into HBTC and then converted into WHT, thus completing the process of users getting HT.

  1. Such an operation involves a lot of operations and entities, including users (a certain address), routing contracts (for forwarding transaction routing), transaction contracts (processing multi-layer exchange logic), transaction pair contracts (update transaction pair inventory) ), the various currency contracts involved (check ownership, balance, etc.)

  2. In this process, in addition to transactions such as transactions from one address to another, there will be a large number of events generated, such as authorized Approval, swap with exchange assets, Sync with synchronization balance, etc., as shown in the figure. 4 shown

It is precisely because of the generation and loading of these events that not only the need for data analysis, but also a wealth of data analysis sources. HyperGraph network nodes are defined according to requirements, continuously analyzing and scanning high-performance blockchain data, and analyzing the data defined in subgraph requirements. Since HyperGraph is optimized for high-performance blockchains, compared to Graph Node on the Ethereum network, there are more custom optimization methods and node optimization suggestions to ensure efficient operation

  1. HyperGraph nodes process data according to defined subgraphs and transaction processing procedures. In response to events in the blockchain network, the HyperGraph built-in program creates and updates entities in the HyperGraph storage database.

DApps or pages that do not support Web3 can also obtain remote query data. Developers use GraphQL to query HyperGraph remote nodes. Get data back in JSON format. Then the developer displays it on the interface as needed.

Repeatedly, the use process of HyperGraph node is completed.

In the following chapters, we will explain in more detail how to define subgraphs, deploy subgraphs, and how to query subgraphs.

Last updated