Skip to content

Commit

Permalink
Add support for safe/finalized blocks and support latest subquery ima…
Browse files Browse the repository at this point in the history
…ge (#4)

* Support last version of subquery

* linting issues

* Support latest subquery image for alt layers

* delete unnecessary file
  • Loading branch information
lucaslopezf authored Dec 4, 2024
1 parent 3fc1339 commit 1e2661c
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 5,387 deletions.
72 changes: 0 additions & 72 deletions .github/workflows/publish-subq-indexer.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/setup-and-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ This guide provides instructions for setting up and deploying the ICP-EVM Proxy
cd ../subq-indexer
```

Edit `project.yaml` and update the URL of the deployed EVM Adapter Proxy.
After the build, edit `project.yaml` and update the URL of the deployed EVM Adapter Proxy. Note: For easier testing, ensure the URL has SSL enabled.

```shell
npm install
Expand Down
12 changes: 8 additions & 4 deletions evm-adapter-proxy/internal/routers/evm/eth_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import (
"github.com/aviate-labs/agent-go/candid/idl"
)

// Block tag constants for EVM block references
const (
latestParam = "latest"
BlockTagLatest = "latest"
BlockTagSafe = "safe"
BlockTagFinalized = "finalized"
)

// EthChainID implements the eth_chainId RPC method
Expand Down Expand Up @@ -96,7 +99,8 @@ func (r *evmRouter) EthGetBlockByNumber(request JSONRPCRequest) (interface{}, er

var blockNumber string
var err error
if strings.EqualFold(blockNumberHex, latestParam) {
switch blockNumberHex {
case BlockTagLatest, BlockTagSafe, BlockTagFinalized:
latestBlockHex, err := r.EthBlockNumber(JSONRPCRequest{})
if err != nil {
return nil, fmt.Errorf("failed to get latest block number: %w", err)
Expand Down Expand Up @@ -270,15 +274,15 @@ func extractBlockRange(filter map[string]interface{}) (uint64, uint64, error) {
return fromBlock, toBlock, nil
}

// parseBlockParam parses a block parameter which can be a number or "latest"
// parseBlockParam parses a block parameter which can be a number or block tag
func parseBlockParam(blockParam interface{}, defaultValue uint64) (uint64, error) {
if blockParam == nil {
return defaultValue, nil
}

switch v := blockParam.(type) {
case string:
if v == "latest" {
if v == BlockTagLatest || v == BlockTagSafe || v == BlockTagFinalized {
return defaultValue, nil
}
return strconv.ParseUint(v, 0, 64)
Expand Down
7 changes: 0 additions & 7 deletions subq-indexer/.earthlyignore

This file was deleted.

1 change: 1 addition & 0 deletions subq-indexer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules/
dist/

# lock files
yarn.lock
package-lock.json

# Compiled Java class files
Expand Down
88 changes: 0 additions & 88 deletions subq-indexer/Earthfile

This file was deleted.

2 changes: 1 addition & 1 deletion subq-indexer/abis/erc20.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,4 @@
"name": "Transfer",
"type": "event"
}
]
]
23 changes: 14 additions & 9 deletions subq-indexer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@ services:
interval: 5s
timeout: 5s
retries: 5

subquery-node:
image: zondax/subql-node-ethereum:v3.5.3
image: onfinality/subql-node-ethereum:latest
depends_on:
"postgres":
condition: service_healthy
restart: always
restart: unless-stopped
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
ENDPOINT_URL: https://<proxy_url>/rpc/v1
CHAIN_ID: 314160
START_BLOCK: 1
volumes:
- ./:/app
entrypoint: "/bin/sh"
command:
- -c
- "cd /app && sh ./scripts/replace_endpoint.sh && /usr/local/lib/node_modules/@subql/node-ethereum/bin/run -f=/app --db-schema=app --workers=1 --batch-size=2 --unfinalized-blocks=false --log-level=trace --block-confirmations=0 --all-events"
- ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests
- -f=/app
- --db-schema=app
- --workers=1
- --batch-size=2
- --unfinalized-blocks=true
- --log-level=trace
- --block-confirmations=0
- --all-events

healthcheck:
test: [ "CMD", "curl", "-f", "http://subquery-node:3000/ready" ]
Expand All @@ -45,7 +49,7 @@ services:
retries: 10

graphql-engine:
image: subquerynetwork/subql-query:latest
image: onfinality/subql-query:latest
ports:
- 3000:3000
depends_on:
Expand All @@ -63,3 +67,4 @@ services:
command:
- --name=app
- --playground
- --indexer=http://subquery-node:3000
46 changes: 0 additions & 46 deletions subq-indexer/earthly-dockerfile/Dockerfile

This file was deleted.

13 changes: 0 additions & 13 deletions subq-indexer/earthly-dockerfile/Earthfile

This file was deleted.

15 changes: 12 additions & 3 deletions subq-indexer/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import {
EthereumHandlerKind,
} from "@subql/types-ethereum";

import * as dotenv from 'dotenv';
import path from 'path';

const mode = process.env.NODE_ENV || 'production';

// Load the appropriate .env file
const dotenvPath = path.resolve(__dirname, `.env${mode !== 'production' ? `.${mode}` : ''}`);
dotenv.config({ path: dotenvPath });

// Can expand the Datasource processor types via the generic param
const project: EthereumProject = {
specVersion: "1.0.0",
Expand All @@ -29,7 +38,7 @@ const project: EthereumProject = {
* chainId is the EVM Chain ID, for Altlayer OP Demo Testnet this is 20240219
* https://chainlist.org/chain/20240219
*/
chainId: "CHAIN_ID_ENV_VAR_REF",
chainId: process.env.CHAIN_ID!,
/**
* These endpoint(s) should be public non-pruned archive node
* We recommend providing more than one endpoint for improved reliability, performance, and uptime
Expand All @@ -38,13 +47,13 @@ const project: EthereumProject = {
* If you use a rate limited endpoint, adjust the --batch-size and --workers parameters
* These settings can be found in your docker-compose.yaml, they will slow indexing but prevent your project being rate limited
*/
endpoint: ["ENDPOINT_URL_ENV_VAR_REF"],
endpoint: process.env.ENDPOINT!?.split(',') as string[] | string,
},
dataSources: [
{
kind: EthereumDatasourceKind.Runtime,
// Block height at which the smart contract was deployed
startBlock: -1,
startBlock: 1,
options: {
abi: "erc20",
},
Expand Down
Loading

0 comments on commit 1e2661c

Please sign in to comment.