bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 18쪽 중 3쪽
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
.
Indexer service (
indexer-service-rs
)
- Handles all required external communications with the network. Shares cost models and indexing statuses, passes query requests from gateways on to a Graph Node, and manages query payments via
GraphTally
.
TAP agent (
indexer-tap-agent
)
- Aggregates GraphTally receipts into RAVs (Receipt Aggregate Vouchers) and reconciles redemptions. Exactly one instance should run per indexer.
Indexer agent
- Facilitates the Indexers interactions onchain including registering on the network, managing Subgraph deployments to its Graph Node/s, and managing allocations.
Prometheus metrics server
- The Graph Node and Indexer components log their metrics to the metrics server.
Note: To support agile scaling, it is recommended that query and indexing concerns are separated between different sets of nodes: query nodes and index nodes.
Ports overview
Important
: Be careful about exposing ports publicly -
administration ports
should be kept locked down. This includes the the Graph Node JSON-RPC and the Indexer management endpoints detailed below.
Graph Node
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
-
Indexer Service (
indexer-service-rs
)
Port
Purpose
Routes
CLI Argument
Environment Variable
7600
GraphQL HTTP server
(for paid Subgraph queries)
/subgraphs/id/…
/status
/healthz
/cost
/info
—config
-
7300
Prometheus metrics
/metrics
-
-
Indexer Agent
Port
Purpose
Routes
CLI Argument
Environment Variable
8000
Indexer management API
/
—indexer-management-port
INDEXER_AGENT_INDEXER_MANAGEMENT_PORT
Setup server infrastructure using Terraform on Google Cloud
Note: Indexers can alternatively use AWS, Microsoft Azure, or Alibaba.
Install prerequisites
Google Cloud SDK
Kubectl command line tool
Terraform
Create a Google Cloud Project
Clone or navigate to the
Indexer repository
.
Navigate to the
./terraform
directory, this is where all commands should be executed.
1
cd terraform
Authenticate with Google Cloud and create a new project.
1
gcloud auth login
2
project=<PROJECT_NAME>
3
gcloud projects create --enable-cloud-apis $project
Use the Google Cloud Console’s billing page to enable billing for the new project.
Create a Google Cloud configuration.
1
proj_id=$(gcloud projects list --format='get(project_id)' --filter="name=$project")
2
gcloud config configurations create $project
3
gcloud config set project "$proj_id"
4
gcloud config set compute/region us-central1
5
gcloud config set compute/zone us-central1-a
Enable required Google Cloud APIs.
1
gcloud services enable compute.googleapis.com
2
gcloud services enable container.googleapis.com
3
gcloud services enable servicenetworking.googleapis.com
4
gcloud services enable sqladmin.googleapis.com
Create a service account.
1
svc_name=<SERVICE_ACCOUNT_NAME>
2
gcloud iam service-accounts create $svc_name \
3
--description="Service account for Terraform" \
4
--display-name="$svc_name"
5
gcloud iam service-accounts list
6
# Get the email of the service account from the list
7
svc=$(gcloud iam service-accounts list --format='get(email)'
8
--filter="displayName=$svc_name")
9
gcloud iam service-accounts keys create .gcloud-credentials.json \
10
--iam-account="$svc"
11
gcloud projects add-iam-policy-binding $proj_id \
12
--member serviceAccount:$svc \
13
--role roles/editor
Enable peering between database and Kubernetes cluster that will be created in the next step.
1
gcloud compute addresses create google-managed-services-default \
2
--prefix-length=20 \
3
--purpose=VPC_PEERING \
4
--network default \
5
--global \
6
--description 'IP Range for peer networks.'
7
gcloud services vpc-peerings connect \
8
--network=default \
9
--ranges=google-managed-services-default
Create minimal terraform configuration file (update as needed).
1
indexer=<INDEXER_NAME>
2
cat > terraform.tfvars <<EOF
3
project = "$proj_id"
4
indexer = "$indexer"
5
database_password = "<database password>"
6
EOF
Use Terraform to create infrastructure
Before running any commands, read through
variables.tf
and create a file
terraform.tfvars
in this directory (or modify the one we created in the last step). For each variable where you want to override the default, or where you need to set a value, enter a setting into
terraform.tfvars
.
Run the following commands to create the infrastructure.
1
# Install required plugins
2
terraform init
3
4
# View plan for resources to be created
5
terraform plan
6
7
# Create the resources (expect it to take up to 30 minutes)
8
terraform apply
Download credentials for the new cluster into
~/.kube/config
and set it as your default context.
1
gcloud container clusters get-credentials $indexer
2
kubectl config use-context $(kubectl config get-contexts --output='name'
3
| grep $indexer)
Creating the Kubernetes components for the Indexer
Copy the directory
k8s/overlays
to a new directory
$dir,
and adjust the
bases
entry in
$dir/kustomization.yaml
so that it points to the directory
k8s/base
.
Read through all the files in
$dir
and adjust any values as indicated in the comments.
Deploy all resources with
kubectl apply -k $dir
.
Graph Node
Graph Node
is an open source Rust implementation that event sources the Ethereum Mainnet blockchain to deterministically update a data store that can be queried via the GraphQL endpoint. Developers use Subgraphs to define their schema, and a set of mappings for transforming the data sourced from the blockchain and the Graph Node handles syncing the entire chain, monitoring for new blocks, and serving it via a GraphQL endpoint.
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 libpg-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 using Docker
Prerequisites
Ethereum node
- By default, the docker compose setup will use mainnet:
http://host.docker.internal:8545
to connect to the Ethereum node on your host machine. You can replace this network name and url by updating
docker-compose.yaml
.
Setup
Clone Graph Node and navigate to the Docker directory:
1
git clone https://github.com/graphprotocol/graph-node
2
cd graph-node/docker
For linux users only - Use the host IP address instead of
host.docker.internal
in the
docker-compose.yaml
using the included script:
1
./setup.sh
Start a local Graph Node that will connect to your Ethereum endpoint:
1
docker-compose up
Indexer components
To successfully participate in the network requires almost constant monitoring and interaction, so we’ve built a suite of applications for facilitating an Indexers network participation. There are four Indexer components:
Indexer agent
- The agent monitors the network and the Indexer’s own infrastructure and manages which Subgraph deployments are indexed and allocated towards onchain and how much is allocated towards each.
indexer-service-rs
- The only component that needs to be exposed externally, the service passes on Subgraph queries to the graph node, validates
GraphTally
receipts, and shares important decision making information to clients like the gateways.
indexer-tap-agent
- Aggregates GraphTally receipts into RAVs and manages receipt-to-payment lifecycle. Run exactly one instance per indexer.
Indexer CLI
- The command line interface for managing the Indexer agent. It allows Indexers to manage cost models, manual allocations, actions queue, and indexing rules.
Getting started
The Indexer agent,
indexer-service-rs
, and
indexer-tap-agent
should be co-located with your Graph Node infrastructure. There are many ways to set up virtual execution environments for your Indexer components; here we’ll explain how to run them using docker or via kubernetes on the Google Cloud Kubernetes Engine. If these setup examples do not translate well to your infrastructure there will likely be a community guide to reference, come say hi on
Discord
! Remember to
stake in the protocol
before starting up your Indexer components!
Indexer agent (from NPM)
1
npm install -g @graphprotocol/indexer-agent
2
3
# Indexer CLI is a plugin for Graph CLI, so both need to be installed:
4
npm install -g @graphprotocol/graph-cli
5
npm install -g @graphprotocol/indexer-cli
6
7
# Indexer agent
8
graph-indexer-agent start ...
9
10
# Indexer CLI
11
#Forward the port of your agent pod if using Kubernetes
12
kubectl port-forward pod/POD_ID 18000:8000
13
graph indexer connect http://localhost:18000/
14
graph indexer ...
indexer-service-rs
and
indexer-tap-agent
(Docker)
The
indexer-service-rs
and
indexer-tap-agent
are Rust applications distributed as Docker images. See the
GraphTally guide
for detailed configuration.
1
docker pull ghcr.io/graphprotocol/indexer-service-rs:latest
2
docker pull ghcr.io/graphprotocol/indexer-tap-agent:latest
Run both services with a shared TOML configuration file:
1
# indexer-service-rs (horizontally scalable)
2
docker run -p 7600:7600 -v ./config.toml:/config.toml \
3
ghcr.io/graphprotocol/indexer-service-rs:latest --config /config.toml
4
5
# indexer-tap-agent (run exactly one instance)
6
docker run -v ./config.toml:/config.toml \
7
ghcr.io/graphprotocol/indexer-tap-agent:latest --config /config.toml
NOTE
: After starting the containers, the indexer service should be accessible at
http://localhost:7600
and the Indexer agent should be exposing the Indexer management API at
http://localhost:18000/
.
Using K8s and Terraform
See the
Setup Server Infrastructure Using Terraform on Google Cloud
section
Usage
NOTE
: All runtime configuration variables may be applied either as parameters to the command on startup or using environment variables of the format
COMPONENT_NAME_VARIABLE_NAME
(ex.
INDEXER_AGENT_ETHEREUM
).
Indexer agent
1
graph-indexer-agent start \
2
--ethereum <MAINNET_ETH_ENDPOINT> \
3
--ethereum-network mainnet \
4
--mnemonic <MNEMONIC> \
5
--indexer-address <INDEXER_ADDRESS> \
6
--graph-node-query-endpoint http://localhost:8000/ \
7
--graph-node-status-endpoint http://localhost:8030/graphql \
8
--graph-node-admin-endpoint http://localhost:8020/ \
9
--public-indexer-url http://localhost:7600/ \
10
--indexer-geo-coordinates <YOUR_COORDINATES> \
11
--index-node-ids default \
12
--indexer-management-port 18000 \
13
--metrics-port 7040 \
14
--network-subgraph-endpoint http://query-node-0:8000/subgraphs/id/QmUzRg2HHMpbgf6Q4VHKNDbtBEJnyp5JWCh2gUX9AV6jXv \
15
--default-allocation-amount 100 \
16
--register true \
17
--inject-dai true \
18
--postgres-host localhost \
19
--postgres-port 5432 \
20
--postgres-username <DB_USERNAME> \
21
--postgres-password <DB_PASSWORD> \
22
--postgres-database indexer \
23
--allocation-management auto \
24
| pino-pretty
indexer-service-rs
and
indexer-tap-agent
Both
indexer-service-rs
and
indexer-tap-agent
are configured using a shared TOML file. See the
GraphTally guide
for detailed configuration and deployment instructions.
1
# Run indexer-service-rs
2
indexer-service-rs --config /path/to/config.toml
3
4
# Run indexer-tap-agent (exactly one instance)
5
indexer-tap-agent --config /path/to/config.toml
Indexer CLI
The Indexer CLI is a plugin for
@graphprotocol/graph-cli
accessible in the terminal at
graph indexer
.
1
graph indexer connect http://localhost:18000
2
graph indexer status
Indexer management using Indexer CLI
The suggested tool for interacting with the
Indexer Management API
is the
Indexer CLI
, an extension to the
Graph CLI
. The Indexer agent needs input from an Indexer in order to autonomously interact with the network on the behalf of the Indexer. The mechanism for defining Indexer agent behavior are
allocation management
mode and
indexing rules
. Under auto mode, an Indexer can use
indexing rules
to apply their specific strategy for picking Subgraphs to index and serve queries for. Rules are managed via a GraphQL API served by the agent and known as the Indexer Management API. Under manual mode, an Indexer can create allocation actions using
actions queue
and explicitly approve them before they get executed. Under oversight mode,
indexing rules
are used to populate
actions queue
and also require explicit approval for execution.
Usage
The
Indexer CLI
connects to the Indexer agent, typically through port-forwarding, so the CLI does not need to run on the same server or cluster. To help you get started, and to provide some context, the CLI will briefly be described here.
graph indexer connect <url>
- Connect to the Indexer management API. Typically the connection to the server is opened via port forwarding, so the CLI can be easily operated remotely. (Example:
kubectl port-forward pod/<indexer-agent-pod> 8000:8000
)
graph indexer rules get [options] <deployment-id> [<key1> ...]
- Get one or more indexing rules using
all
as the
<deployment-id>
to get all rules, or
global
to get the global defaults. An additional argument
--merged
can be used to specify that deployment specific rules are merged with the global rule. This is how they are applied in the Indexer agent.
graph indexer rules set [options] <deployment-id> <key1> <value1> ...
- Set one or more indexing rules.
graph indexer rules start [options] <deployment-id>
- Start indexing a Subgraph deployment if available and set its
decisionBasis
to
always
, so the Indexer agent will always choose to index it. If the global rule is set to always then all available Subgraphs on the network will be indexed.
graph indexer rules stop [options] <deployment-id>
- Stop indexing a deployment and set its
decisionBasis
to never, so it will skip this deployment when deciding on deployments to index.
graph indexer rules maybe [options] <deployment-id>
— Set the
decisionBasis
for a deployment to
rules
, so that the Indexer agent will use indexing rules to decide whether to index this deployment.
graph indexer actions get [options] <action-id>
- Fetch one or more actions using
all
or leave
action-id
empty to get all actions. An additional argument
--status
can be used to print out all actions of a certain status.
graph indexer action queue allocate <deployment-id> <allocation-amount>
- Queue allocation action
graph indexer action queue reallocate <deployment-id> <allocation-id> <allocationAmount>
- Queue reallocate action
graph indexer action queue unallocate <deployment-id> <allocation-id>
- Queue unallocate action
graph indexer actions cancel [<action-id> ...]
- Cancel all action in the queue if id is unspecified, otherwise cancel array of id with space as separator
graph indexer actions approve [<action-id> ...]
- Approve multiple actions for execution
graph indexer actions execute approve
- Force the worker to execute approved actions immediately
All commands which display rules in the output can choose between the supported output formats (
table
,
yaml
, and
json
) using the
-output
argument.
Indexing rules
Indexing rules can either be applied as global defaults or for specific Subgraph deployments using their IDs. The
deployment
and
decisionBasis
fields are mandatory, while all other fields are optional. When an indexing rule has
rules
as the
decisionBasis
, then the Indexer agent will compare non-null threshold values on that rule with values fetched from the network for the corresponding deployment. If the Subgraph deployment has values above (or below) any of the thresholds it will be chosen for indexing.
For example, if the global rule has a
minStake
of
5
(GRT), any Subgraph deployment which has more than 5 (GRT) of stake allocated to it will be indexed. Threshold rules include
maxAllocationPercentage
,
minSignal
,
maxSignal
,
minStake
, and
minAverageQueryFees
.
Data model:
1
type IndexingRule {
2
identifier: string
3
identifierType: IdentifierType
4
decisionBasis: IndexingDecisionBasis!
5
allocationAmount: number | null
6
allocationLifetime: number | null
7
autoRenewal: boolean
8
parallelAllocations: number | null
9
maxAllocationPercentage: number | null
10
minSignal: string | null
11
maxSignal: string | null
12
minStake: string | null
13
minAverageQueryFees: string | null
14
custom: string | null
15
requireSupported: boolean | null
16
}
17
18
IdentifierType {
19
deployment
20
subgraph
21
group
22
}
23
24
IndexingDecisionBasis {
25
rules
26
never
27
always
28
offchain
29
}
Example usage of indexing rule:
1
graph indexer rules offchain QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK
2
3
graph indexer rules set QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK decisionBasis always allocationAmount 123321 allocationLifetime 14 autoRenewal false requireSupported false
4
5
graph indexer rules stop QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK
6
7
graph indexer rules delete QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK
Actions queue CLI
The indexer-cli provides an
actions
module for manually working with the action queue. It uses the
Graphql API
hosted by the indexer management server to interact with the actions queue.
The action execution worker will only grab items from the queue to execute if they have
ActionStatus = approved
. In the recommended path actions are added to the queue with ActionStatus = queued, so they must then be approved in order to be executed onchain. The general flow will look like:
Action added to the queue by the 3rd party optimizer tool or indexer-cli user
Indexer can use the
indexer-cli
to view all queued actions
Indexer (or other software) can approve or cancel actions in the queue using the
indexer-cli
. The approve and cancel commands take an array of action ids as input.
The execution worker regularly polls the queue for approved actions. It will grab the
approved
actions from the queue, attempt to execute them, and update the values in the db depending on the status of execution to
success
or
failed
.
If an action is successful the worker will ensure that there is an indexing rule present that tells the agent how to manage the allocation moving forward, useful when taking manual actions while the agent is in
auto
or
oversight
mode.
The indexer can monitor the action queue to see a history of action execution and if needed re-approve and update action items if they failed execution. The action queue provides a history of all actions queued and taken.
Data model:
1
Type ActionInput {
2
status: ActionStatus
3
type: ActionType
4
deploymentID: string | null
5
allocationID: string | null
6
amount: string | null
7
poi: string | null
8
force: boolean | null
9
source: string
10
reason: string | null
11
priority: number | null
12
}
13
14
ActionStatus {
15
queued
16
approved
17
pending
18
success
19
failed
20
canceled
21
}
22
23
ActionType {
24
allocate
25
unallocate
26
reallocate
27
collect
28
}
Example usage fro프로젝트로 돌아가기