Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
10 changes: 7 additions & 3 deletions sdk/packages/indexer/docker/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
- --log-level=${LOG_LEVEL:-info}
- --store-cache-async=false
- --store-cache-threshold=1

healthcheck:
test: ["CMD", "curl", "-f", "http://subquery-node-hyperbridge-gargantua-local:3000/ready"]
interval: 3s
Expand Down Expand Up @@ -72,7 +73,7 @@ services:
# retries: 10

subquery-node-bsc-chapel-local:
image: polytopelabs/subql-node-ethereum:latest
image: subquerynetwork/subql-node-ethereum:v6.5.0
restart: always
environment:
DB_USER: ${DB_USER}
Expand Down Expand Up @@ -103,14 +104,15 @@ services:
- --block-confirmations=0
- --store-cache-async=false
- --store-cache-threshold=1

healthcheck:
test: ["CMD", "curl", "-f", "http://subquery-node-bsc-chapel-local:3000/ready"]
interval: 3s
timeout: 5s
retries: 10

subquery-node-base-sepolia-local:
image: polytopelabs/subql-node-ethereum:latest
image: subquerynetwork/subql-node-ethereum:v6.5.0
restart: always
environment:
DB_USER: ${DB_USER}
Expand Down Expand Up @@ -141,14 +143,15 @@ services:
- --block-confirmations=0
- --store-cache-async=false
- --store-cache-threshold=1

healthcheck:
test: ["CMD", "curl", "-f", "http://subquery-node-base-sepolia-local:3000/ready"]
interval: 3s
timeout: 5s
retries: 10

subquery-node-polygon-amoy-local:
image: polytopelabs/subql-node-ethereum:latest
image: subquerynetwork/subql-node-ethereum:v6.5.0
restart: always
environment:
DB_USER: ${DB_USER}
Expand Down Expand Up @@ -176,6 +179,7 @@ services:
- --log-level=${LOG_LEVEL:-info}
- --store-cache-async=false
- --store-cache-threshold=1

healthcheck:
test: ["CMD", "curl", "-f", "http://subquery-node-polygon-amoy-local:3000/ready"]
interval: 3s
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/indexer/scripts/generate-compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fileURLToPath } from "node:url"
import Handlebars from "handlebars"
import { getEnv, getValidChains } from "../src/configs"

const EVM_IMAGE = "polytopelabs/subql-node-ethereum:latest"
const EVM_IMAGE = "subquerynetwork/subql-node-ethereum:v6.5.0"
const SUBSTRATE_IMAGE = "subquerynetwork/subql-node-substrate:v5.9.1"

// Setup paths
Expand Down
1 change: 1 addition & 0 deletions sdk/packages/indexer/src/configs/config-local.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"chainId": "97",
"startBlock": 44742412,
"stateMachineId": "EVM-97",
"unfinalizedBlocks": false,
"contracts": {
"ethereumHost": "0x8Aa0Dea6D675d785A882967Bf38183f6117C09b7",
"handlerV1": "0xb45A4078A2D0B036C324A0046C2845aD59e769F6",
Expand Down
3 changes: 2 additions & 1 deletion sdk/packages/indexer/src/configs/config-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"chainId": "1",
"startBlock": 21099382,
"stateMachineId": "EVM-1",
"blockConfirmations": 2,
"blockConfirmations": 5,
"contracts": {
"ethereumHost": "0x792A6236AF69787C40cF76b69B4c8c7B28c4cA20",
"erc6160ext20": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
Expand Down Expand Up @@ -112,6 +112,7 @@
"chainId": "100",
"startBlock": 36816861,
"stateMachineId": "EVM-100",
"blockConfirmations": 5,
"contracts": {
"ethereumHost": "0x50c236247447B9d4Ee0561054ee596fbDa7791b1",
"erc6160ext20": "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d",
Expand Down
1 change: 1 addition & 0 deletions sdk/packages/indexer/src/configs/config-testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"chainId": "10200",
"startBlock": 12294845,
"stateMachineId": "EVM-10200",
"blockConfirmations": 5,
"contracts": {
"ethereumHost": "0x58A41B89F4871725E5D898d98eF4BF917601c5eB",
"handlerV1": "0x01b40De26Ba4C63c17A6f4Ed2cF96927C280B029",
Expand Down
59 changes: 59 additions & 0 deletions sdk/packages/indexer/src/configs/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,65 @@ type ResponseStatusMetadata @entity {
createdAt: Date! @index
}

"""
Temporary storage for status metadata when the parent entity (Request, Response, GetRequest)
has not yet been created due to multichain indexing race conditions.
Once the parent entity is created, pending entries are flushed to the real status metadata tables.
"""
type PendingStatusMetadata @entity {
id: ID!

"""
The commitment of the parent entity
"""
commitment: String! @index

"""
The type of parent entity: RequestV2, ResponseV2, or GetRequestV2
"""
entityType: String! @index

"""
The status of the request/response/order
"""
status: String!

"""
The chain on which the event occurred
"""
chain: String!

"""
The timestamp of the event
"""
timestamp: BigInt!

"""
The number of the block in which the event occurred
"""
blockNumber: String!

"""
The hash of the block in which the event occurred
"""
blockHash: String!

"""
The hash of the transaction in which the event occurred
"""
transactionHash: String!

"""
The filler of the order (only for order status metadata)
"""
filler: String

"""
The timestamp when this record was created
"""
createdAt: Date!
}

"""
Reward points earned by participants in the hyperbridge protocol
"""
Expand Down
67 changes: 57 additions & 10 deletions sdk/packages/indexer/src/services/getRequest.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { GetRequestV2, GetRequestStatusMetadata, Status } from "@/configs/src/types"
import { GetRequestV2, GetRequestStatusMetadata, PendingStatusMetadata, Status } from "@/configs/src/types"
import { ethers } from "ethers"
import { solidityKeccak256 } from "ethers/lib/utils"
import { timestampToDate } from "@/utils/date.helpers"

const ENTITY_TYPE = "GetRequestV2"

export interface IGetRequestArgs {
id: string
source?: string
Expand Down Expand Up @@ -88,6 +90,8 @@ export class GetRequestService {
id: getRequest.id,
})}`,
)

await this.flushPendingStatuses(id)
} else {
if (source !== undefined) getRequest.source = source
if (dest !== undefined) getRequest.dest = dest
Expand Down Expand Up @@ -119,6 +123,7 @@ export class GetRequestService {
/**
* Update the status of a get request
* Also adds a new entry to the get request status metadata
* If the get request doesn't exist, stores in PendingStatusMetadata until the entity is created
*/
static async updateStatus(args: IUpdateGetRequestStatusArgs): Promise<void> {
const { commitment, blockNumber, blockHash, blockTimestamp, status, transactionHash, chain } = args
Expand All @@ -131,19 +136,29 @@ export class GetRequestService {
})}`,
)

let getRequest = await this.createOrUpdate({
id: commitment
})
let getRequest = await GetRequestV2.get(commitment)

await getRequest.save()
if (!getRequest) {
logger.warn(
`GetRequestV2 not found for commitment ${commitment}, storing in PendingStatusMetadata for status ${status}`,
)

logger.info(
`Created new get request while attempting get request update with details ${JSON.stringify({
let pending = PendingStatusMetadata.create({
id: `${commitment}.${ENTITY_TYPE}.${status}`,
commitment,
transactionHash,
entityType: ENTITY_TYPE,
status,
})}`,
)
chain,
timestamp: blockTimestamp,
blockNumber,
blockHash,
transactionHash,
createdAt: timestampToDate(blockTimestamp),
})

await pending.save()
return
}

let getRequestStatusMetadata = GetRequestStatusMetadata.create({
id: `${commitment}.${status}`,
Expand All @@ -160,6 +175,38 @@ export class GetRequestService {
await getRequestStatusMetadata.save()
}

/**
* Flush any pending status metadata entries for a get request that was just created
*/
static async flushPendingStatuses(commitment: string): Promise<void> {
const pendingStatuses = await PendingStatusMetadata.getByCommitment(commitment, {
limit: 10,
})

const matching = pendingStatuses.filter((p) => p.entityType === ENTITY_TYPE)

for (const pending of matching) {
let statusMetadata = GetRequestStatusMetadata.create({
id: `${commitment}.${pending.status}`,
requestId: commitment,
status: pending.status as Status,
chain: pending.chain,
timestamp: pending.timestamp,
blockNumber: pending.blockNumber,
blockHash: pending.blockHash,
transactionHash: pending.transactionHash,
createdAt: pending.createdAt,
})

await statusMetadata.save()
await PendingStatusMetadata.remove(pending.id)

logger.info(
`Flushed pending status ${pending.status} for GetRequestV2 ${commitment}`,
)
}
}

/**
* Compute the getRequest commitment matching the solidity `encode` function for GetRequestEvent
*/
Expand Down
Loading
Loading