The Graph 백서

The Graph

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 18쪽 중 11쪽

publish [SUBGRAPH-MANIFEST] [-h] [--protocol-network arbitrum-one|arbitrum-sepolia --subgraph-id <value>] [-i <value>] [--ipfs-hash <value>] [--webapp-url 3 <value>] 4 5 FLAGS 6 -h, --help Show CLI help. 7 -i, --ipfs=<value> [default: https://ipfs.thegraph.com/api/v0] Upload build results to an IPFS node. 8 --ipfs-hash=<value> IPFS hash of the subgraph manifest to deploy. 9 --protocol-network=<option> [default: arbitrum-one] The network to use for the subgraph deployment. 10 <options: arbitrum-one|arbitrum-sepolia> 11 --subgraph-id=<value> Subgraph ID to publish to. 12 --webapp-url=<value> [default: https://cli.thegraph.com/publish] URL of the web UI you want to use to deploy. Add GRT signal to your Subgraph to incentivize Indexers to query your Subgraph. Refer to Adding Signal for specifics. Final Step: Query your Subgraph After publishing, access your Subgraph’s Query URL from Graph Explorer . You can query your Subgraph by sending GraphQL queries to its Query URL, which you can find by clicking the Query button. You get access to 100,000 free queries/month with your Subgraph on The Graph Network. Refer to Querying The Graph to structure GraphQL queries. ## /docs/en/substreams/quick-start Substreams Discover how to utilize ready-to-use substream packages or develop your own. Overview Integrating Substreams can be quick and easy. They are permissionless, and you can obtain a key here ⁠ without providing personal information to start streaming on-chain data. Start Building Use Substreams Packages There are many ready-to-use Substreams packages available. You can explore these packages by visiting the Substreams Registry ⁠ and sinking them . The registry lets you search for and find any package that meets your needs. Once you find a package that fits your needs, you can choose how you want to consume the data: Subgraph : Configure an API to meet your data needs and host it on The Graph Network. SQL Database ⁠ : Send the data to a database. Direct Streaming ⁠ : Stream data directly to your application. PubSub ⁠ : Send data to a PubSub topic. Develop Your Own If you can’t find a Substreams package that meets your specific needs, you can develop your own. Substreams are built with Rust, so you’ll write functions that extract and filter the data you need from the blockchain. To get started, check out the following tutorials: EVM ⁠ Solana ⁠ TRON ⁠ Starknet ⁠ Injective ⁠ MANTRA ⁠ Stellar ⁠ To build and optimize your Substreams from zero, use the minimal path within the Dev Container . Note: Substreams guarantees that you’ll never miss data ⁠ with a simple reconnection policy. Additional Resources For additional guidance, reference the Tutorials ⁠ and follow the How-To Guides ⁠ on Streaming Fast docs. For a deeper understanding of how Substreams works, explore the architectural overview ⁠ of the data service. ## /docs/en/indexing/tooling/graph-node Indexer Software > Indexer Tooling Graph Node is the component which indexes Subgraphs, and makes the resulting data available to query via a GraphQL API. As such it is central to the indexer stack, and correct operation of Graph Node is crucial to running a successful indexer. This provides a contextual overview of Graph Node, and some of the more advanced options available to indexers. Detailed documentation and instructions can be found in the Graph Node repository ⁠ . Graph Node Graph Node ⁠ is the reference implementation for indexing Subgraphs on The Graph Network, connecting to blockchain clients, indexing Subgraphs and making indexed data available to query. Graph Node (and the whole indexer stack) can be run on bare metal, or in a cloud environment. This flexibility of the central indexing component is crucial to the robustness of The Graph Protocol. Similarly, Graph Node can be built from source ⁠ , or indexers can use one of the provided Docker Images ⁠ . PostgreSQL database The main store for the Graph Node, this is where Subgraph data is stored, as well as metadata about Subgraphs, and Subgraph-agnostic network data such as the block cache, and eth_call cache. Network clients In order to index a network, Graph Node needs access to a network client via an EVM-compatible JSON-RPC API. This RPC may connect to a single client or it could be a more complex setup that load balances across multiple. While some Subgraphs may just require a full node, some may have indexing features which require additional RPC functionality. Specifically Subgraphs which make eth_calls as part of indexing will require an archive node which supports EIP-1898 ⁠ , and Subgraphs with callHandlers , or blockHandlers with a call filter, require trace_filter support ( see trace module documentation here ⁠ ). Network Firehoses - a Firehose is a gRPC service providing an ordered, yet fork-aware, stream of blocks, developed by The Graph’s core developers to better support performant indexing at scale. This is not currently an Indexer requirement, but Indexers are encouraged to familiarise themselves with the technology, ahead of full network support. Learn more about the Firehose here ⁠ . IPFS Nodes Subgraph deployment metadata is stored on the IPFS network. The Graph Node primarily accesses the IPFS node during Subgraph deployment to fetch the Subgraph manifest and all linked files. Network indexers do not need to host their own IPFS node. An IPFS node for the network is hosted at https://ipfs.thegraph.com ⁠ . Prometheus metrics server To enable monitoring and reporting, Graph Node can optionally log metrics to a Prometheus metrics server. Getting started from source Install prerequisites Rust PostgreSQL IPFS Additional Requirements for Ubuntu users - To run a Graph Node on Ubuntu a few additional packages may be needed. 1 sudo apt-get install -y clang libpq-dev libssl-dev pkg-config Setup Start a PostgreSQL database server 1 initdb -D .postgres 2 pg_ctl -D .postgres -l logfile start 3 createdb graph-node Clone Graph Node ⁠ repo and build the source by running cargo build Now that all the dependencies are setup, start the Graph Node: 1 cargo run -p graph-node --release -- \ 2 --postgres-url postgresql://[USERNAME]:[PASSWORD]@localhost:5432/graph-node \ 3 --ethereum-rpc [NETWORK_NAME]:[URL] \ 4 --ipfs https://ipfs.thegraph.com Getting started with Kubernetes A complete Kubernetes example configuration can be found in the indexer repository ⁠ . Ports When it is running Graph Node exposes the following ports: Port Purpose Routes CLI Argument Environment Variable 8000 GraphQL HTTP server (for Subgraph queries) /subgraphs/id/… /subgraphs/name/…/… —http-port - 8001 GraphQL WS (for Subgraph subscriptions) /subgraphs/id/… /subgraphs/name/…/… —ws-port - 8020 JSON-RPC (for managing deployments) / —admin-port - 8030 Subgraph indexing status API /graphql —index-node-port - 8040 Prometheus metrics /metrics —metrics-port - WARNING: Never expose Graph Node’s administrative ports to the public . Exposing Graph Node’s internal ports can lead to a full system compromise. These ports must remain private : JSON-RPC Admin endpoint, Indexing Status API, and PostgreSQL. Do not expose 8000 (GraphQL HTTP) and 8001 (GraphQL WebSocket) directly to the internet. Even though these are used for GraphQL queries, they should ideally be proxied though indexer-agent and served behind a production-grade proxy. Lock everything else down with firewalls or private networks. Advanced Graph Node configuration At its simplest, Graph Node can be operated with a single instance of Graph Node, a single PostgreSQL database, an IPFS node, and the network clients as required by the Subgraphs to be indexed. This setup can be scaled horizontally, by adding multiple Graph Nodes, and multiple databases to support those Graph Nodes. Advanced users may want to take advantage of some of the horizontal scaling capabilities of Graph Node, as well as some of the more advanced configuration options, via the config.toml file and Graph Node’s environment variables. config.toml A TOML ⁠ configuration file can be used to set more complex configurations than those exposed in the CLI. The location of the file is passed with the —config command line switch. When using a configuration file, it is not possible to use the options —postgres-url, —postgres-secondary-hosts, and —postgres-host-weights. A minimal config.toml file can be provided; the following file is equivalent to using the —postgres-url command line option: 1 [store] 2 [store.primary] 3 connection="<.. postgres-url argument ..>" 4 [deployment] 5 [[deployment.rule]] 6 indexers = [ "<.. list of all indexing nodes ..>" ] Full documentation of config.toml can be found in the Graph Node docs ⁠ . Multiple Graph Nodes Graph Node indexing can scale horizontally, running multiple instances of Graph Node to split indexing and querying across different nodes. This can be done simply by running Graph Nodes configured with a different node_id on startup (e.g. in the Docker Compose file), which can then be used in the config.toml file to specify dedicated query nodes , block ingestors , and splitting Subgraphs across nodes with deployment rules . Note that multiple Graph Nodes can all be configured to use the same database, which itself can be horizontally scaled via sharding. Deployment rules Given multiple Graph Nodes, it is necessary to manage deployment of new Subgraphs so that the same Subgraph isn’t being indexed by two different nodes, which would lead to collisions. This can be done by using deployment rules, which can also specify which shard a Subgraph’s data should be stored in, if database sharding is being used. Deployment rules can match on the Subgraph name and the network that the deployment is indexing in order to make a decision. Example deployment rule configuration: 1 [deployment] 2 [[deployment.rule]] 3 match = { name = "(vip|important)/.*" } 4 shard = "vip" 5 indexers = [ "index_node_vip_0", "index_node_vip_1" ] 6 [[deployment.rule]] 7 match = { network = "kovan" } 8 # No shard, so we use the default shard called 'primary' 9 indexers = [ "index_node_kovan_0" ] 10 [[deployment.rule]] 11 match = { network = [ "xdai", "poa-core" ] } 12 indexers = [ "index_node_other_0" ] 13 [[deployment.rule]] 14 # There's no 'match', so any Subgraph matches 15 shards = [ "sharda", "shardb" ] 16 indexers = [ 17 "index_node_community_0", 18 "index_node_community_1", 19 "index_node_community_2", 20 "index_node_community_3", 21 "index_node_community_4", 22 "index_node_community_5" 23 ] Read more about deployment rules here ⁠ . Dedicated query nodes Nodes can be configured to explicitly be query nodes by including the following in the configuration file: 1 [general] 2 query = "<regular expression>" Any node whose —node-id matches the regular expression will be set up to only respond to queries. Database scaling via sharding For most use cases, a single Postgres database is sufficient to support a graph-node instance. When a graph-node instance outgrows a single Postgres database, it is possible to split the storage of graph-node’s data across multiple Postgres databases. All databases together form the store of the graph-node instance. Each individual database is called a shard. Shards can be used to split Subgraph deployments across multiple databases, and can also be used to use replicas to spread query load across databases. This includes configuring the number of available database connections each graph-node should keep in its connection pool for each database, which becomes increasingly important as more Subgraphs are being indexed. Sharding becomes useful when your existing database can’t keep up with the load that Graph Node puts on it, and when it’s not possible to increase the database size anymore. It is generally better make a single database as big as possible, before starting with shards. One exception is where query traffic is split very unevenly between Subgraphs; in those situations it can help dramatically if the high-volume Subgraphs are kept in one shard and everything else in another because that setup makes it more likely that the data for the high-volume Subgraphs stays in the db-internal cache and doesn’t get replaced by data that’s not needed as much from low-volume Subgraphs. In terms of configuring connections, start with max_connections in postgresql.conf set to 400 (or maybe even 200) and look at the store_connection_wait_time_ms and store_connection_checkout_count Prometheus metrics. Noticeable wait times (anything above 5ms) is an indication that there are too few connections available; high wait times there will also be caused by the database being very busy (like high CPU load). However if the database seems otherwise stable, high wait times indicate a need to increase the number of connections. In the configuration, how many connections each graph-node instance can use is an upper limit, and Graph Node will not keep connections open if it doesn’t need them. Read more about store configuration here ⁠ . Dedicated block ingestion If there are multiple nodes configured, it will be necessary to specify one node which is responsible for ingestion of new blocks, so that all configured index nodes aren’t polling the chain head. This is done as part of the chains namespace, specifying the node_id to be used for block ingestion: 1 [chains] 2 ingestor = "block_ingestor_node" Supporting multiple networks The Graph Protocol is increasing the number of networks supported for indexing rewards, and there exist many Subgraphs indexing unsupported networks which an indexer would like to process. The config.toml file allows for expressive and flexible configuration of: Multiple networks Multiple providers per network (this can allow splitting of load across providers, and can also allow for configuration of full nodes as well as archive nodes, with Graph Node preferring cheaper providers if a given workload allows). Additional provider details, such as features, authentication and the type of provider (for experimental Firehose support) The [chains] section controls the ethereum providers that graph-node connects to, and where blocks and other metadata for each chain are stored. The following example configures two chains, mainnet and kovan, where blocks for mainnet are stored in the vip shard and blocks for kovan are stored in the primary shard. The mainnet chain can use two different providers, whereas kovan only has one provider. 1 [chains] 2 ingestor = "block_ingestor_node" 3 [chains.mainnet] 4 shard = "vip" 5 provider = [ 6 { label = "mainnet1", url = "http://..", features = [], headers = { Authorization = "Bearer foo" } }, 7 { label = "mainnet2", url = "http://..", features = [ "archive", "traces" ] } 8 ] 9 [chains.kovan] 10 shard = "primary" 11 provider = [ { label = "kovan", url = "http://..", features = [] } ] Read more about provider configuration here ⁠ . Environment variables Graph Node supports a range of environment variables which can enable features, or change Graph Node behaviour. These are documented here ⁠ . Continuous deployment Users who are operating a scaled indexing setup with advanced configuration may benefit from managing their Graph Nodes with Kubernetes. The indexer repository has an example Kubernetes reference ⁠ Launchpad ⁠ is a toolkit for running a Graph Protocol Indexer on Kubernetes maintained by GraphOps. It provides a set of Helm charts and a CLI to manage a Graph Node deployment. Managing Graph Node Given a running Graph Node (or Graph Nodes!), the challenge is then to manage deployed Subgraphs across those nodes. Graph Node surfaces a range of tools to help with managing Subgraphs. Logging Graph Node’s logs can provide useful information for debugging and optimisation of Graph Node and specific Subgraphs. Graph Node supports different log levels via the GRAPH_LOG environment variable, with the following levels: error, warn, info, debug or trace. In addition setting GRAPH_LOG_QUERY_TIMING to gql provides more details about how GraphQL queries are running (though this will generate a large volume of logs). Monitoring & alerting Graph Node provides the metrics via Prometheus endpoint on 8040 port by default. Grafana can then be used to visualise these metrics. The indexer repository provides an example Grafana configuration ⁠ . Graphman graphman is a maintenance tool for Graph Node, helping with diagnosis and resolution of different day-to-day and exceptional tasks. The graphman command is included in the official containers, and you can docker exec into your graph-node container to run it. It requires a config.toml file. Full documentation of graphman commands is available in the Graph Node repository. See [/docs/graphman.md] ( https://github.com/graphprotocol/graph-node/blob/master/docs/graphman.md ⁠ ) in the Graph Node /docs Working with Subgraphs Indexing status API Available on port 8030/graphql by default, the indexing status API exposes a range of methods for checking indexing status for different Subgraphs, checking proofs of indexing, inspecting Subgraph features and more. The full schema is available here ⁠ . Indexing performance There are three separate parts of the indexing process: Fetching events of interest from the provider Processing events in order with the appropriate handlers (this can involve calling the chain for state, and fetching data from the store) Writing the resulting data to the store These stages are pipelined (i.e. they can be executed in parallel), but they are dependent on one another. Where Subgraphs are slow to index, the underlying cause will depend on the specific Subgraph. Common causes of indexing slowness: Time taken to find relevant events from the chain (call handlers in particular can be slow, given the reliance on trace_filter ) Making large numbers of eth_calls as part of handlers A large amount of store interaction during execution A large amount of data to save to the store A large number of events to process Slow database connection time, for crowded nodes The provider itself falling behind the chain head Slowness in fetching new receipts at the chain head from the provider Subgraph indexing metrics can help diagnose the root cause of indexing slowness. In some cases, the problem lies with the Subgraph itself, but in others, improved network providers, reduced database contention and other configuration improvements can markedly improve indexing performance. Failed Subgraphs During indexing Subgraphs might fail, if they encounter data that is unexpected, some component not working as expected, or if there is some bug in the event handlers or configuration. There are two general types of failure: Deterministic failures: these are failures which will not be resolved with retries Non-deterministic failures: these might be down to issues with the provider, or some unexpected Graph Node error. When a non-deterministic failure occurs, Graph Node will retry the failing handlers, backing off over time. In some cases a failure might be resolvable by the indexer (for example if the error is a result of not having the right kind of provider, adding the required provider will allow indexing to continue). However in others, a change in the Subgraph code is required. Deterministic failures are considered “final”, with a Proof of Indexing generated for the failing block, while non-deterministic failures are not, as the Subgraph may manage to “unfail” and continue indexing. In some cases, the non-deterministic label is incorrect, and the Subgraph will never overcome the error; such failures should be reported as issues on the Graph Node repository. Block and call cache Graph Node caches certain data in the store in order to save refetching from the provider. Blocks are ca
프로젝트로 돌아가기