Skip to content

Commit

Permalink
Support latest subquery image for alt layers
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslopezf committed Dec 4, 2024
1 parent 5c7dc44 commit d7c912c
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 5,311 deletions.
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. Note: For easier testing, ensure the URL has SSL enabled.
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
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
22 changes: 0 additions & 22 deletions subq-indexer/scripts/replace_endpoint.sh

This file was deleted.

59 changes: 34 additions & 25 deletions subq-indexer/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ interface BlockWithLogs {
}

export async function handleLog(blockWithLogs: BlockWithLogs): Promise<void> {
logger.info(`Processing block: ${blockWithLogs.number}`);
try {
logger.info(`Processing block: ${blockWithLogs.number}`);
// Handle single log
if (!blockWithLogs.number) {
await processLog(blockWithLogs as unknown as EthereumLog);
return;
}

for (const logItem of blockWithLogs.logs) {
let log: EthereumLog;

if (typeof logItem === 'string') {
try {
log = JSON.parse(logItem);
Expand All @@ -23,30 +28,34 @@ export async function handleLog(blockWithLogs: BlockWithLogs): Promise<void> {
log = logItem;
}

logger.info(`Processing log: ${log.transactionHash} in block ${log.blockNumber}`);

if (!log.transactionHash || log.blockNumber == null) {
logger.warn(`Log with missing fields: ${JSON.stringify(log)}`);
continue; // Skip this log but continue with the next ones
}

const logRecord = Log.create({
id: `${log.transactionHash}-${log.logIndex}`,
address: log.address,
topics: log.topics,
data: log.data,
blockNumber: BigInt(log.blockNumber),
transactionHash: log.transactionHash,
transactionIndex: BigInt(log.transactionIndex || 0),
blockHash: log.blockHash,
logIndex: BigInt(log.logIndex || 0),
removed: log.removed || false,
});

await logRecord.save();
logger.info(`Log saved successfully: ${logRecord.id}`);
await processLog(log);
}
} catch (error) {
logger.error(`Error processing logs for block ${blockWithLogs.number}: ${error}`);
logger.error(`Error processing logs: ${error}`);
}
}

async function processLog(log: EthereumLog): Promise<void> {
logger.info(`Processing log: ${log.transactionHash} in block ${log.blockNumber}`);

if (!log.transactionHash || log.blockNumber == null) {
logger.warn(`Log with missing fields: ${JSON.stringify(log)}`);
return; // Skip this log but continue with the next ones
}

const logRecord = Log.create({
id: `${log.transactionHash}-${log.logIndex}`,
address: log.address,
topics: log.topics,
data: log.data,
blockNumber: BigInt(log.blockNumber),
transactionHash: log.transactionHash,
transactionIndex: BigInt(log.transactionIndex || 0),
blockHash: log.blockHash,
logIndex: BigInt(log.logIndex || 0),
removed: log.removed || false,
});

await logRecord.save();
logger.info(`Log saved successfully: ${logRecord.id}`);
}
Loading

0 comments on commit d7c912c

Please sign in to comment.