Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to sub query #848

Merged
merged 42 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6f9b9a2
improve root docker compose
marc-aurele-besner Sep 11, 2024
89a5392
add leaderboard sub_query
marc-aurele-besner Sep 11, 2024
11a7636
add staking sub_query (no logic)
marc-aurele-besner Sep 11, 2024
6f0049d
add accounts sub query
marc-aurele-besner Sep 12, 2024
14ccb8b
add all staking logic (except epoch)
marc-aurele-besner Sep 12, 2024
76ecd7c
add consensus (missing much of the logic)
marc-aurele-besner Sep 12, 2024
56d5c47
add more sub query staking logic
marc-aurele-besner Sep 13, 2024
d6535d9
improve multi-indexers setup
marc-aurele-besner Sep 13, 2024
3a93ed1
move toward multi networks indexers setup
marc-aurele-besner Sep 13, 2024
94ba8e4
improve multi-networks multi-indexers setup
marc-aurele-besner Sep 13, 2024
45c6163
remove individual docker setup in favor of main multi-table setup
marc-aurele-besner Sep 13, 2024
b2353c4
re-org code-workspace for new indexers setup
marc-aurele-besner Sep 13, 2024
ecab2d6
fix docker compose
marc-aurele-besner Sep 13, 2024
64cac58
add hasura metadata
marc-aurele-besner Sep 13, 2024
967fe0c
improve leaderboard data
marc-aurele-besner Sep 16, 2024
2ad0d5c
add base of testnet rewards subquery
marc-aurele-besner Sep 16, 2024
a06491f
add static data
marc-aurele-besner Sep 16, 2024
1b6db86
add needed env in docker compose
marc-aurele-besner Sep 16, 2024
deaa812
add new env
marc-aurele-besner Sep 16, 2024
045c782
improve docker compose
marc-aurele-besner Sep 16, 2024
222279e
add missing mapping
marc-aurele-besner Sep 16, 2024
b68d83d
improve project building flow
marc-aurele-besner Sep 16, 2024
2e8fdb4
fix path
marc-aurele-besner Sep 16, 2024
89cb2ea
improve docker compose
marc-aurele-besner Sep 16, 2024
a7bdbc8
improve hasura metadata
marc-aurele-besner Sep 16, 2024
d25d96c
change hasura image to apply metadata
marc-aurele-besner Sep 16, 2024
e59ea03
add logging to loki
DaMandal0rian Sep 16, 2024
6dd9c1d
fix bootstrap path issue
marc-aurele-besner Sep 16, 2024
10d7825
improve testnet reward 3g sub query logic
marc-aurele-besner Sep 18, 2024
fc1184d
modify schema to fit with sub query orm constraint
marc-aurele-besner Sep 18, 2024
afbce71
split docker compose with a prod override
marc-aurele-besner Sep 18, 2024
65658d7
fix command typo
marc-aurele-besner Sep 18, 2024
4c7b145
add metadata for 3g tables
marc-aurele-besner Sep 18, 2024
7aab340
improve testnet 3g logic
marc-aurele-besner Sep 18, 2024
238a50a
improve ids
marc-aurele-besner Sep 18, 2024
bf27c99
update schema
marc-aurele-besner Sep 18, 2024
b0c3120
improve logic
marc-aurele-besner Sep 18, 2024
c4a2c38
adding back some more logs
marc-aurele-besner Sep 18, 2024
b8beb9a
improve 3g metadata/permission
marc-aurele-besner Sep 19, 2024
1b89e4d
improve 3h metadata and permission
marc-aurele-besner Sep 19, 2024
a8ca8ac
detach docker after start for prod
marc-aurele-besner Sep 19, 2024
0584eb7
improve docker setup
marc-aurele-besner Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
DB_USER=postgres
DB_DATABASE=postgres
DB_PASSWORD=postgres
DB_PORT=5432
DB_HOST=postgres

DB_CONSENSUS=consensus
DB_LEADERBOARD=leaderboard
DB_STAKING=staking
GEMINI_3H_RPC="wss://rpc-squids.gemini-3h.subspace.network/ws"
GEMINI_3G_RPC="wss://rpc-0.gemini-3g.subspace.network/ws"

HASURA_GRAPHQL_ADMIN_SECRET=helloworld
GEMINI_3H_CHAIN_ID="0x0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34"
GEMINI_3G_CHAIN_ID="0x418040fc282f5e5ddd432c46d05297636f6f75ce68d66499ff4cbda69ccd180b"

DB_GEMINI_3H_CONSENSUS=gemini_3h_consensus
DB_GEMINI_3H_ACCOUNTS=gemini_3h_accounts
DB_GEMINI_3H_LEADERBOARD=gemini_3h_leaderboard
DB_GEMINI_3H_STAKING=gemini_3h_staking
DB_GEMINI_3H_TESTNET_REWARDS=gemini_3h_testnet_rewards

DB_GEMINI_3G_TESTNET_REWARDS=gemini_3g_testnet_rewards

HASURA_GRAPHQL_ADMIN_SECRET=helloworld

HASURA_GRAPHQL_ENABLE_CONSOLE=false
HASURA_GRAPHQL_JWT_SECRET='{ "type": "HS256", "key": "<jwt-secret>" }'
HASURA_GRAPHQL_CORS_DOMAIN="*"
8 changes: 4 additions & 4 deletions .vscode/astral.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"path": "../indexers"
},
{
"name": "indexer - Staking Squid",
"path": "../indexers/staking-squid"
"name": "indexer - Gemini 3H",
"path": "../indexers/gemini-3h"
},
{
"name": "indexer - Leaderboard Squid",
"path": "../indexers/leaderboard-squid"
"name": "indexer - Gemini 3G",
"path": "../indexers/gemini-3g"
}
],
"settings": {
Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,38 @@ You can also find the instructions for setting up the Squid backend and Health c

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

### Multi-Network Indexers Setup

To set up the multi-network indexers, follow these steps:

1. **Navigate to the indexers directory:**

```bash
cd indexers
```

2. **Install the dependencies:**

```bash
yarn
```

3. **Build the indexers:**

```bash
yarn build
```

4. **Start the PostgreSQL database with multiple tables, Hasura, and various Subquery nodes using Docker Compose:**

From the root directory, run:

```bash
docker compose up
```

This command will initialize a PostgreSQL database configured with multiple tables, launch the Hasura GraphQL engine, and start multiple Subquery nodes to index all networks. This setup provides all the necessary data for different sections of the explorer, ensuring a comprehensive indexing solution for the application.

## Contributing

We welcome contributions to this project. If you are interested in enhancing the features of the app or fixing bugs, please follow these steps:
Expand Down
53 changes: 53 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: "3"

volumes:
db_data: {}

services:
postgres:
volumes:
- db_data:/var/lib/postgresql/data
- type: bind
source: /home/ubuntu/postgresql/conf/postgresql.conf
target: /etc/postgresql/postgresql.conf
read_only: true
logging:
driver: loki
options:
loki-url: "https://logging.subspace.network/loki/api/v1/push"

hasura_engine:
logging:
driver: loki
options:
loki-url: "https://logging.subspace.network/loki/api/v1/push"

gemini_3h_accounts-subquery-node:
logging:
driver: loki
options:
loki-url: "https://logging.subspace.network/loki/api/v1/push"

gemini_3h_consensus-subquery-node:
logging:
driver: loki
options:
loki-url: "https://logging.subspace.network/loki/api/v1/push"

gemini_3h_leaderboard-subquery-node:
logging:
driver: loki
options:
loki-url: "https://logging.subspace.network/loki/api/v1/push"

gemini_3h_staking-subquery-node:
logging:
driver: loki
options:
loki-url: "https://logging.subspace.network/loki/api/v1/push"

gemini_3g_testnet_rewards-subquery-node:
logging:
driver: loki
options:
loki-url: "https://logging.subspace.network/loki/api/v1/push"
229 changes: 212 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,230 @@
version: "3"
version: "3.8"

services:
db:
container_name: explorer-db
image: postgres:14
# Postgres Database
postgres:
container_name: postgres
image: postgres:16-alpine
environment:
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
ports:
- "${DB_PORT}:${DB_PORT}"
volumes:
- ./indexers/db/docker-entrypoint-initdb.d/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

graphql-engine:
# Hasura GraphQL Engine
hasura_engine:
container_name: explorer-graphql
image: hasura/graphql-engine:v2.40.0
image: hasura/graphql-engine:v2.40.0.cli-migrations-v3
depends_on:
- "db"
- "postgres"
restart: always
environment:
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:${DB_PORT}/${DB_CONSENSUS}
HASURA_GRAPHQL_CONSENSUS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:${DB_PORT}/${DB_CONSENSUS}
HASURA_GRAPHQL_LEADERBOARD_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:${DB_PORT}/${DB_LEADERBOARD}
HASURA_GRAPHQL_STAKING_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:${DB_PORT}/${DB_STAKING}
HASURA_GRAPHQL_ENABLE_CONSOLE: "false"
HASURA_GRAPHQL_DEV_MODE: "true"
# HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET}
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: user
# Essential Environment Variables
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_CONSENSUS}
HASURA_GRAPHQL_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_CONSENSUS} # Main database connection
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET} # Admin access secret
HASURA_GRAPHQL_JWT_SECRET: ${HASURA_GRAPHQL_JWT_SECRET} # JWT authentication secret

# Console and Development Mode
HASURA_GRAPHQL_ENABLE_CONSOLE: ${HASURA_GRAPHQL_ENABLE_CONSOLE} # Disable console in production
HASURA_GRAPHQL_DEV_MODE: "true" # Disable development mode features

# Role and CORS Settings
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: user # Default role for unauthenticated users
HASURA_GRAPHQL_CORS_DOMAIN: ${HASURA_GRAPHQL_CORS_DOMAIN} # Allowed domains for CORS
HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES: "true"

# Performance and Connection Settings
HASURA_GRAPHQL_MAX_CONNECTIONS: 100 # Maximum number of database connections
HASURA_GRAPHQL_STRIPES: 2 # Number of connection pool stripes
HASURA_GRAPHQL_CONNECTIONS_PER_STRIPE: 50 # Connections per stripe
HASURA_GRAPHQL_IDLE_TIMEOUT: 180 # Idle connection timeout in seconds
HASURA_GRAPHQL_TIMEOUT: 60 # Request timeout in seconds

# Logging Settings
HASURA_GRAPHQL_LOG_LEVEL: "warn" # Log verbosity level
HASURA_GRAPHQL_ENABLED_LOG_TYPES: "startup,http-log,webhook-log,websocket-log,query-log" # Enabled log types

# Security and Authorization
HASURA_GRAPHQL_ENABLE_ALLOWLIST: "true" # Enable query allowlisting

# Gemini 3H Databases
HASURA_GRAPHQL_GEMINI_3H_CONSENSUS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_CONSENSUS}
HASURA_GRAPHQL_GEMINI_3H_ACCOUNTS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_ACCOUNTS}
HASURA_GRAPHQL_GEMINI_3H_LEADERBOARD_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_LEADERBOARD}
HASURA_GRAPHQL_GEMINI_3H_STAKING_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_STAKING}
HASURA_GRAPHQL_GEMINI_3H_TESTNET_REWARDS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_TESTNET_REWARDS}

# Gemini 3G Database
HASURA_GRAPHQL_GEMINI_3G_TESTNET_REWARDS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3G_TESTNET_REWARDS}

# Hasura Migrations and Metadata
HASURA_GRAPHQL_MIGRATIONS_DIR: /hasura-migrations
HASURA_GRAPHQL_METADATA_DIR: /hasura-metadata
ports:
- "8080:8080"
volumes:
- ./indexers/db/migrations:/hasura-migrations
- ./indexers/db/metadata:/hasura-metadata
command:
- graphql-engine
- serve
- serve

# Gemini 3H Subquery Nodes
gemini_3h_accounts-subquery-node:
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
CHAIN_ID: "0x0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34"
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3H_ACCOUNTS}
DB_HOST: ${DB_HOST}
DB_PORT: 5432
volumes:
- ./indexers/gemini-3h/accounts:/gemini-3h/accounts
command:
- ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests
- -f=/gemini-3h/accounts
- --db-schema=${DB_GEMINI_3H_ACCOUNTS}
- --workers=4
- --unsafe
- --batch-size=30
- --unfinalized-blocks=true
healthcheck:
test: ["CMD", "curl", "-f", "http://accounts-subquery-node:3000/ready"]
interval: 3s
timeout: 5s
retries: 10

gemini_3h_consensus-subquery-node:
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
CHAIN_ID: "0x0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34"
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3H_CONSENSUS}
DB_HOST: ${DB_HOST}
DB_PORT: 5432
volumes:
- ./indexers/gemini-3h/consensus:/gemini-3h/consensus
command:
- ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests
- -f=/gemini-3h/consensus
- --db-schema=${DB_GEMINI_3H_CONSENSUS}
- --workers=4
- --unsafe
- --batch-size=30
- --unfinalized-blocks=true
healthcheck:
test: ["CMD", "curl", "-f", "http://consensus-subquery-node:3000/ready"]
interval: 3s
timeout: 5s
retries: 10

gemini_3h_leaderboard-subquery-node:
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
CHAIN_ID: "0x0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34"
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3H_LEADERBOARD}
DB_HOST: ${DB_HOST}
DB_PORT: 5432
volumes:
- ./indexers/gemini-3h/leaderboard:/gemini-3h/leaderboard
command:
- ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests
- -f=/gemini-3h/leaderboard
- --db-schema=${DB_GEMINI_3H_LEADERBOARD}
- --workers=4
- --unsafe
- --batch-size=30
- --unfinalized-blocks=true
healthcheck:
test: ["CMD", "curl", "-f", "http://leaderboard-subquery-node:3000/ready"]
interval: 3s
timeout: 5s
retries: 10

gemini_3h_staking-subquery-node:
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
CHAIN_ID: "0x0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34"
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3H_STAKING}
DB_HOST: ${DB_HOST}
DB_PORT: 5432
volumes:
- ./indexers/gemini-3h/staking:/gemini-3h/staking
command:
- ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests
- -f=/gemini-3h/staking
- --db-schema=${DB_GEMINI_3H_STAKING}
- --workers=4
- --unsafe
- --batch-size=30
- --unfinalized-blocks=true
healthcheck:
test: ["CMD", "curl", "-f", "http://staking-subquery-node:3000/ready"]
interval: 3s
timeout: 5s
retries: 10

gemini_3g_testnet_rewards-subquery-node:
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3G_RPC}
CHAIN_ID: "0x418040fc282f5e5ddd432c46d05297636f6f75ce68d66499ff4cbda69ccd180b"
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3G_TESTNET_REWARDS}
DB_HOST: ${DB_HOST}
DB_PORT: 5432
volumes:
- ./indexers/gemini-3g/testnet-rewards:/gemini-3g/testnet-rewards
command:
- ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests
- -f=/gemini-3g/testnet-rewards
- --db-schema=${DB_GEMINI_3G_TESTNET_REWARDS}
- --workers=4
- --unsafe
- --batch-size=30
- --unfinalized-blocks=true
healthcheck:
test: ["CMD", "curl", "-f", "http://staking-subquery-node:3000/ready"]
interval: 3s
timeout: 5s
retries: 10
1 change: 1 addition & 0 deletions indexers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions indexers/db/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HASURA_GRAPHQL_ADMIN_SECRET=helloworld
1 change: 1 addition & 0 deletions indexers/db/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/data
Loading
Loading