Skip to content

Commit e166e74

Browse files
committed
all: ensure we don't pause an allocation if auto-grafting - bump patch to 0.24.1
1 parent 38d7df0 commit e166e74

File tree

11 files changed

+103
-18
lines changed

11 files changed

+103
-18
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Tests require:
131131
```
132132

133133
## Current State
134-
- Version: v0.24.0
134+
- Version: v0.24.1
135135
- Active branch: release-v0.24
136136
- Main branch: main
137137
- Uncommitted changes in docs/ and config/

docs/auto-graft.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ After each dependency reaches its target block, it's automatically paused to:
170170
- Save computational resources
171171
- Ensure data consistency
172172

173+
Auto-graft will check for active allocations before pausing a dependency. If a subgraph has an active allocation (meaning it's still serving queries), it will NOT be automatically paused to prevent service disruption. This ensures that customers can continue querying subgraphs that are actively allocated.
174+
175+
*Note: This allocation check was introduced in v0.24.1*
176+
173177
## Monitoring Auto-Graft
174178

175179
### Key Log Messages

docs/networks/arbitrum-sepolia.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ The Graph Network's testnet is on Arbitrum Sepolia (eip155:421614). Sepolia netw
77
| Component | Release |
88
| ------------------ | ------------------------------------------------------------------------------------ |
99
| contracts | [5.3.3](https://github.com/graphprotocol/contracts/releases/tag/v5.3.3) |
10-
| indexer-agent | [0.24.0](https://github.com/graphprotocol/indexer/releases/tag/v0.24.0) |
11-
| indexer-cli | [0.24.0](https://github.com/graphprotocol/indexer/releases/tag/v0.24.0) |
10+
| indexer-agent | [0.24.1](https://github.com/graphprotocol/indexer/releases/tag/v0.24.1) |
11+
| indexer-cli | [0.24.1](https://github.com/graphprotocol/indexer/releases/tag/v0.24.1) |
1212
| indexer-service-rs | [1.0.0](https://github.com/graphprotocol/indexer-rs/releases/tag/v1.0.0) |
1313
| tap-agent | [1.0.0](https://github.com/graphprotocol/indexer-rs/releases/tag/v1.0.0) |
1414
| graph-node | [0.35.1](https://github.com/graphprotocol/graph-node/releases/tag/v0.35.1) |

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
],
55
"npmClient": "yarn",
66
"useWorkspaces": true,
7-
"version": "0.24.0"
7+
"version": "0.24.1"
88
}

packages/indexer-agent/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/indexer-agent",
3-
"version": "0.24.0",
3+
"version": "0.24.1",
44
"description": "Indexer agent",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -30,7 +30,7 @@
3030
},
3131
"dependencies": {
3232
"@graphprotocol/common-ts": "2.0.11",
33-
"@graphprotocol/indexer-common": "^0.24.0",
33+
"@graphprotocol/indexer-common": "^0.24.1",
3434
"@thi.ng/heaps": "^1.3.1",
3535
"axios": "0.26.1",
3636
"bs58": "5.0.0",

packages/indexer-agent/src/agent.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Metrics,
77
SubgraphDeploymentID,
88
timer,
9+
NetworkContracts,
910
} from '@graphprotocol/common-ts'
1011
import {
1112
ActivationCriteria,
@@ -1256,13 +1257,19 @@ export class Agent {
12561257
}
12571258

12581259
// TODO: After indexer-service deprecation: Move to be an initialization check inside Network.create()
1259-
async ensureSubgraphIndexing(deployment: string, networkIdentifier: string) {
1260+
async ensureSubgraphIndexing(
1261+
deployment: string,
1262+
networkIdentifier: string,
1263+
contracts?: NetworkContracts,
1264+
) {
12601265
try {
12611266
// TODO: Check both the local deployment and the external subgraph endpoint
12621267
// Make sure the subgraph is being indexed
12631268
await this.graphNode.ensure(
12641269
`indexer-agent/${deployment.slice(-10)}`,
12651270
new SubgraphDeploymentID(deployment),
1271+
undefined, // currentAssignments
1272+
contracts,
12661273
)
12671274

12681275
// Validate if the Network Subgraph belongs to the current provider's network.
@@ -1288,6 +1295,7 @@ export class Agent {
12881295
await this.ensureSubgraphIndexing(
12891296
network.specification.subgraphs.networkSubgraph.deployment,
12901297
network.specification.networkIdentifier,
1298+
network.contracts,
12911299
)
12921300
}
12931301
// Epoch subgraph
@@ -1297,13 +1305,15 @@ export class Agent {
12971305
await this.ensureSubgraphIndexing(
12981306
network.specification.subgraphs.epochSubgraph.deployment,
12991307
network.specification.networkIdentifier,
1308+
network.contracts,
13001309
)
13011310
}
13021311
// TAP subgraph
13031312
if (network.specification.subgraphs.tapSubgraph?.deployment !== undefined) {
13041313
await this.ensureSubgraphIndexing(
13051314
network.specification.subgraphs.tapSubgraph.deployment,
13061315
network.specification.networkIdentifier,
1316+
network.contracts,
13071317
)
13081318
}
13091319
}

packages/indexer-cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/indexer-cli",
3-
"version": "0.24.0",
3+
"version": "0.24.1",
44
"description": "Indexer CLI for The Graph Network",
55
"main": "./dist/cli.js",
66
"files": [
@@ -27,7 +27,7 @@
2727
},
2828
"dependencies": {
2929
"@graphprotocol/common-ts": "2.0.11",
30-
"@graphprotocol/indexer-common": "^0.24.0",
30+
"@graphprotocol/indexer-common": "^0.24.1",
3131
"@iarna/toml": "2.2.5",
3232
"@thi.ng/iterators": "5.1.74",
3333
"@urql/core": "3.1.0",

packages/indexer-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/indexer-common",
3-
"version": "0.24.0",
3+
"version": "0.24.1",
44
"description": "Common library for Graph Protocol indexer components",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

packages/indexer-common/src/graph-node.ts

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import gql from 'graphql-tag'
22
import jayson, { Client as RpcClient } from 'jayson/promise'
3-
import { Logger, SubgraphDeploymentID } from '@graphprotocol/common-ts'
3+
import { Logger, SubgraphDeploymentID, NetworkContracts } from '@graphprotocol/common-ts'
44
import { Client, createClient } from '@urql/core'
55
import {
66
INDEXER_ERROR_MESSAGES,
@@ -665,6 +665,7 @@ export class GraphNode {
665665
name: string,
666666
deployment: SubgraphDeploymentID,
667667
currentAssignments?: SubgraphDeploymentAssignment[],
668+
contracts?: NetworkContracts,
668669
): Promise<void> {
669670
this.logger.debug('Ensure subgraph deployment is syncing', {
670671
name,
@@ -693,7 +694,12 @@ export class GraphNode {
693694
await this.resume(deployment)
694695
} else {
695696
// Subgraph deployment not found
696-
await this.autoGraftDeployDependencies(deployment, deploymentAssignments, name)
697+
await this.autoGraftDeployDependencies(
698+
deployment,
699+
deploymentAssignments,
700+
name,
701+
contracts,
702+
)
697703

698704
// Create and deploy the subgraph
699705
this.logger.debug(
@@ -732,6 +738,7 @@ export class GraphNode {
732738
deployment: SubgraphDeploymentID,
733739
deploymentAssignments: SubgraphDeploymentAssignment[],
734740
name: string,
741+
contracts?: NetworkContracts,
735742
) {
736743
this.logger.debug('Auto graft deploy subgraph dependencies')
737744
const { network: subgraphChainName } = await this.subgraphFeatures(deployment)
@@ -805,6 +812,7 @@ export class GraphNode {
805812
dependency.block,
806813
dependency.base,
807814
subgraphChainName,
815+
contracts,
808816
)
809817
}
810818
}
@@ -820,6 +828,7 @@ export class GraphNode {
820828
blockHeight: number,
821829
subgraphDeployment: SubgraphDeploymentID,
822830
chainName: string | null,
831+
contracts?: NetworkContracts,
823832
): Promise<void> {
824833
async function waitForMs(ms: number) {
825834
return new Promise((resolve) => setTimeout(resolve, ms))
@@ -912,12 +921,71 @@ export class GraphNode {
912921
// Is the graftBaseBlock within the range of the earliest and head of the chain?
913922
if (chain.latestBlock && chain.latestBlock.number >= blockHeight) {
914923
if (!deployed[0].paused) {
915-
this.logger.debug(`Subgraph synced to block! Pausing as requirement is met.`, {
916-
subgraph: subgraphDeployment.ipfsHash,
917-
indexingStatus,
918-
})
919-
// pause the subgraph to prevent further indexing
920-
await this.pause(subgraphDeployment)
924+
// Check if there's an active allocation before pausing
925+
let hasActiveAllocation = false
926+
let checkFailed = false
927+
928+
// If contracts are provided, check for active allocations
929+
if (contracts) {
930+
try {
931+
// Check if any allocations exist for this subgraph deployment
932+
const filter = contracts.staking.filters.AllocationCreated(
933+
null, // indexer (any)
934+
subgraphDeployment.bytes32, // subgraphDeploymentID
935+
)
936+
const events = await contracts.staking.queryFilter(filter)
937+
938+
// Check each allocation to see if it's still active
939+
for (const event of events) {
940+
const allocationId = event.args?.allocationID
941+
if (allocationId) {
942+
const state = await contracts.staking.getAllocationState(allocationId)
943+
// State 1 means Active allocation
944+
if (state === 1) {
945+
hasActiveAllocation = true
946+
break
947+
}
948+
}
949+
}
950+
951+
if (hasActiveAllocation) {
952+
this.logger.warn(`Subgraph has active allocation, not going to pause`, {
953+
subgraph: subgraphDeployment.ipfsHash,
954+
blockHeight,
955+
indexingStatus,
956+
})
957+
}
958+
} catch (error) {
959+
checkFailed = true
960+
this.logger.error(`Failed to check allocation state, not going to pause`, {
961+
subgraph: subgraphDeployment.ipfsHash,
962+
error,
963+
})
964+
}
965+
} else {
966+
// No contracts provided, skip pause for safety
967+
this.logger.warn(
968+
`No contracts provided to check allocation state, not going to pause`,
969+
{
970+
subgraph: subgraphDeployment.ipfsHash,
971+
blockHeight,
972+
},
973+
)
974+
checkFailed = true
975+
}
976+
977+
// Only pause if we successfully checked and found no active allocations
978+
if (!hasActiveAllocation && !checkFailed) {
979+
this.logger.debug(
980+
`Subgraph synced to block! Pausing as requirement is met.`,
981+
{
982+
subgraph: subgraphDeployment.ipfsHash,
983+
indexingStatus,
984+
},
985+
)
986+
// pause the subgraph to prevent further indexing
987+
await this.pause(subgraphDeployment)
988+
}
921989
} else {
922990
this.logger.debug(`Subgraph already paused and synced to block.`, {
923991
subgraph: subgraphDeployment.ipfsHash,

packages/indexer-common/src/indexer-management/allocations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ export class AllocationManager {
433433
`indexer-agent/${action.deploymentID!.slice(-10)}`,
434434
new SubgraphDeploymentID(action.deploymentID!),
435435
currentAssignments,
436+
this.network.contracts,
436437
),
437438
{
438439
stopOnError: false,

0 commit comments

Comments
 (0)