Skip to content

Commit 9ca151a

Browse files
authored
release branch for v0.25.3 (#1149)
1 parent 72409ea commit 9ca151a

16 files changed

Lines changed: 123 additions & 373 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,6 @@ yalc.lock
123123

124124
# local-network override mode files
125125
tap-contracts.json
126-
config/config.yaml
126+
config/config.yaml
127+
128+
commit-changes.sh

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.25.2",
3+
"version": "0.25.3",
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": "3.0.1",
33-
"@graphprotocol/indexer-common": "0.25.2",
33+
"@graphprotocol/indexer-common": "0.25.3",
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: 24 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
timer,
99
} from '@graphprotocol/common-ts'
1010
import {
11-
ActivationCriteria,
1211
ActionStatus,
1312
Allocation,
1413
AllocationManagementMode,
@@ -32,9 +31,6 @@ import {
3231
validateProviderNetworkIdentifier,
3332
MultiNetworks,
3433
NetworkMapped,
35-
TransferredSubgraphDeployment,
36-
networkIsL2,
37-
networkIsL1,
3834
DeploymentManagementMode,
3935
SubgraphStatus,
4036
sequentialTimerMap,
@@ -44,7 +40,6 @@ import {
4440
import PQueue from 'p-queue'
4541
import pMap from 'p-map'
4642
import pFilter from 'p-filter'
47-
import mapValues from 'lodash.mapvalues'
4843
import zip from 'lodash.zip'
4944
import { AgentConfigs, NetworkAndOperator } from './types'
5045

@@ -194,7 +189,6 @@ export class Agent {
194189
multiNetworks: MultiNetworks<NetworkAndOperator>
195190
indexerManagement: IndexerManagementClient
196191
offchainSubgraphs: SubgraphDeploymentID[]
197-
autoMigrationSupport: boolean
198192
deploymentManagement: DeploymentManagementMode
199193
pollingInterval: number
200194

@@ -208,7 +202,6 @@ export class Agent {
208202
configs.operators,
209203
)
210204
this.offchainSubgraphs = configs.offchainSubgraphs
211-
this.autoMigrationSupport = !!configs.autoMigrationSupport
212205
this.deploymentManagement = configs.deploymentManagement
213206
this.pollingInterval = configs.pollingInterval
214207
}
@@ -377,69 +370,36 @@ export class Agent {
377370
},
378371
)
379372

380-
const eligibleTransferDeployments: Eventual<
381-
NetworkMapped<TransferredSubgraphDeployment[]>
382-
> = sequentialTimerMap(
383-
{ logger, milliseconds: requestIntervalLarge },
384-
async () => {
385-
// Return early if the auto migration feature is disabled.
386-
if (!this.autoMigrationSupport) {
387-
logger.trace(
388-
'Auto Migration feature is disabled, skipping querying transferred subgraphs',
389-
)
390-
return this.multiNetworks.map(async () => [])
391-
}
392-
393-
const statuses = await this.graphNode.indexingStatus([])
394-
return this.multiNetworks.map(async ({ network }) => {
395-
const protocolNetwork = network.specification.networkIdentifier
396-
logger.trace('Fetching deployments eligible for L2 transfer', {
397-
protocolNetwork,
398-
})
399-
const transfers =
400-
await network.networkMonitor.transferredDeployments()
401-
logger.trace(
402-
`Found ${transfers.length} transferred subgraphs in the network`,
403-
{ protocolNetwork },
404-
)
405-
return transfers
406-
.map(transfer => {
407-
const status = statuses.find(
408-
status =>
409-
status.subgraphDeployment.ipfsHash == transfer.ipfsHash,
410-
)
411-
if (status) {
412-
transfer.ready = status.synced && status.health == 'healthy'
413-
}
414-
return transfer
415-
})
416-
.filter(transfer => transfer.ready == true)
417-
})
418-
},
419-
{
420-
onError: error =>
421-
logger.warn(
422-
`Failed to obtain transferred deployments, trying again later`,
423-
{ error },
424-
),
425-
},
426-
)
427-
428-
// While in the L1 -> L2 transfer period this will be an intermediate value
429-
// with the final value including transfer considerations
430-
const intermediateNetworkDeploymentAllocationDecisions: Eventual<
373+
const networkDeploymentAllocationDecisions: Eventual<
431374
NetworkMapped<AllocationDecision[]>
432375
> = join({
433376
networkDeployments,
434377
indexingRules,
435378
}).tryMap(
436-
({ indexingRules, networkDeployments }) => {
437-
return mapValues(
379+
async ({ indexingRules, networkDeployments }) => {
380+
return this.multiNetworks.mapNetworkMapped(
438381
this.multiNetworks.zip(indexingRules, networkDeployments),
439-
([indexingRules, networkDeployments]: [
440-
IndexingRuleAttributes[],
441-
SubgraphDeployment[],
442-
]) => {
382+
async (
383+
{ network }: NetworkAndOperator,
384+
[indexingRules, networkDeployments]: [
385+
IndexingRuleAttributes[],
386+
SubgraphDeployment[],
387+
],
388+
) => {
389+
// Skip evaluation entirely for networks in manual allocation mode
390+
if (
391+
network.specification.indexerOptions.allocationManagementMode ===
392+
AllocationManagementMode.MANUAL
393+
) {
394+
logger.trace(
395+
`Skipping deployment evaluation since AllocationManagementMode = 'manual'`,
396+
{
397+
protocolNetwork: network.specification.networkIdentifier,
398+
},
399+
)
400+
return []
401+
}
402+
443403
// Identify subgraph deployments on the network that are worth picking up;
444404
// these may overlap with the ones we're already indexing
445405
logger.trace('Evaluating which deployments are worth allocating to')
@@ -457,94 +417,6 @@ export class Agent {
457417
},
458418
)
459419

460-
// Update targetDeployments and networkDeplomentAllocationDecisions using transferredSubgraphDeployments data
461-
// This will be somewhat custom and will likely be yanked out later after the transfer stage is complete
462-
// Cases:
463-
// - L1 subgraph that had the transfer started: keep synced and allocated to for at least one week
464-
// post transfer.
465-
// - L2 subgraph that has been transferred:
466-
// - if already synced, allocate to it immediately using default allocation amount
467-
// - if not synced, no changes
468-
const networkDeploymentAllocationDecisions: Eventual<
469-
NetworkMapped<AllocationDecision[]>
470-
> = join({
471-
intermediateNetworkDeploymentAllocationDecisions,
472-
eligibleTransferDeployments,
473-
}).tryMap(
474-
({
475-
intermediateNetworkDeploymentAllocationDecisions,
476-
eligibleTransferDeployments,
477-
}) =>
478-
mapValues(
479-
this.multiNetworks.zip(
480-
intermediateNetworkDeploymentAllocationDecisions,
481-
eligibleTransferDeployments,
482-
),
483-
([allocationDecisions, eligibleTransferDeployments]: [
484-
AllocationDecision[],
485-
TransferredSubgraphDeployment[],
486-
]) => {
487-
logger.debug(
488-
`Found ${eligibleTransferDeployments.length} deployments eligible for transfer`,
489-
{ eligibleTransferDeployments },
490-
)
491-
const oneWeekAgo = Math.floor(Date.now() / 1_000) - 86_400 * 7
492-
return allocationDecisions.map(decision => {
493-
const matchingTransfer = eligibleTransferDeployments.find(
494-
deployment =>
495-
deployment.ipfsHash == decision.deployment.ipfsHash &&
496-
Number(deployment.startedTransferToL2At) > oneWeekAgo,
497-
)
498-
if (matchingTransfer) {
499-
logger.debug('Found a matching subgraph transfer', {
500-
matchingTransfer,
501-
})
502-
// L1 deployments being transferred need to be supported for one week post transfer
503-
// to ensure continued support.
504-
if (networkIsL1(matchingTransfer.protocolNetwork)) {
505-
decision.toAllocate = true
506-
decision.ruleMatch.activationCriteria =
507-
ActivationCriteria.L2_TRANSFER_SUPPORT
508-
logger.debug(
509-
`Allocating towards L1 subgraph deployment to support its transfer`,
510-
{
511-
subgraphDeployment: matchingTransfer,
512-
allocationDecision: decision,
513-
},
514-
)
515-
}
516-
// L2 Deployments
517-
if (
518-
networkIsL2(matchingTransfer.protocolNetwork) &&
519-
!!matchingTransfer.transferredToL2
520-
) {
521-
decision.toAllocate = true
522-
decision.ruleMatch.activationCriteria =
523-
ActivationCriteria.L2_TRANSFER_SUPPORT
524-
logger.debug(
525-
`Allocating towards transferred L2 subgraph deployment`,
526-
{
527-
subgraphDeployment: matchingTransfer,
528-
allocationDecision: decision,
529-
},
530-
)
531-
}
532-
}
533-
return decision
534-
})
535-
},
536-
),
537-
{
538-
onError: error =>
539-
logger.warn(
540-
`Failed to merge L2 transfer decisions, trying again later`,
541-
{
542-
error,
543-
},
544-
),
545-
},
546-
)
547-
548420
// let targetDeployments be an union of targetAllocations
549421
// and offchain subgraphs.
550422
const targetDeployments: Eventual<SubgraphDeploymentID[]> = join({

packages/indexer-agent/src/commands/common-options.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,6 @@ export function injectCommonStartupOptions(argv: Argv): Argv {
135135
required: true,
136136
group: 'Indexer Infrastructure',
137137
})
138-
.option('enable-auto-migration-support', {
139-
description:
140-
'Auto migrate allocations from L1 to L2 (multi-network mode must be enabled)',
141-
type: 'boolean',
142-
required: false,
143-
default: false,
144-
group: 'Indexer Infrastructure',
145-
})
146138
.option('deployment-management', {
147139
describe: 'Subgraph deployments management mode',
148140
required: false,

packages/indexer-agent/src/commands/start.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ export async function run(
688688
indexerManagement: indexerManagementClient,
689689
networks,
690690
deploymentManagement: argv.deploymentManagement,
691-
autoMigrationSupport: argv.enableAutoMigrationSupport,
692691
offchainSubgraphs: argv.offchainSubgraphs.map(
693692
(s: string) => new SubgraphDeploymentID(s),
694693
),

packages/indexer-agent/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export interface AgentConfigs {
2222
indexerManagement: IndexerManagementClient
2323
networks: Network[]
2424
deploymentManagement: DeploymentManagementMode
25-
autoMigrationSupport: boolean
2625
offchainSubgraphs: SubgraphDeploymentID[]
2726
pollingInterval: number
2827
}

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.25.2",
3+
"version": "0.25.3",
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": "3.0.1",
30-
"@graphprotocol/indexer-common": "0.25.2",
30+
"@graphprotocol/indexer-common": "0.25.3",
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.25.2",
3+
"version": "0.25.3",
44
"description": "Common library for Graph Protocol indexer components",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

packages/indexer-common/src/allocations/graph-tally-collector.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,30 @@ export class GraphTallyCollector {
236236
})
237237
this.logger.trace(`[TAPv2] RAW DATA`, { ravs, allocations })
238238

239-
const pendingRAVsToProcess = ravs
240-
.map((rav) => {
241-
const signedRav = rav.getSignedRAV()
242-
return {
239+
// Create an object for O(1) allocation lookups instead of O(n) Array.find()
240+
// This optimizes performance from O(n²) to O(n) for large datasets
241+
const allocationMap: { [key: string]: Allocation } = {}
242+
for (let i = 0; i < allocations.length; i++) {
243+
const allocation = allocations[i]
244+
allocationMap[allocation.id.toLowerCase()] = allocation
245+
}
246+
247+
const pendingRAVsToProcess: RavWithAllocation[] = []
248+
for (let i = 0; i < ravs.length; i++) {
249+
const rav = ravs[i]
250+
const signedRav = rav.getSignedRAV()
251+
const allocationId = toAddress(
252+
collectionIdToAllocationId(signedRav.rav.collectionId),
253+
).toLowerCase()
254+
const allocation = allocationMap[allocationId] // O(1) lookup
255+
if (allocation !== undefined) {
256+
pendingRAVsToProcess.push({
243257
rav: signedRav,
244-
allocation: allocations.find(
245-
(a) =>
246-
a.id ===
247-
toAddress(collectionIdToAllocationId(signedRav.rav.collectionId)),
248-
),
258+
allocation: allocation,
249259
payer: rav.payer,
250-
}
251-
})
252-
.filter((rav) => rav.allocation !== undefined) as RavWithAllocation[] // this is safe because we filter out undefined allocations
260+
})
261+
}
262+
}
253263
this.logger.trace(`[TAPv2] Pending RAVs to process`, {
254264
pendingRAVsToProcess: pendingRAVsToProcess.length,
255265
})

packages/indexer-common/src/allocations/tap-collector.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,32 @@ export class TapCollector {
216216
ravs: ravs.length,
217217
allocations: allocations.length,
218218
})
219-
return ravs
220-
.map((rav) => {
221-
const signedRav = rav.getSignedRAV()
222-
return {
219+
220+
// Create an object for O(1) allocation lookups instead of O(n) Array.find()
221+
// This optimizes performance from O(n²) to O(n) for large datasets
222+
const allocationMap: { [key: string]: Allocation } = {}
223+
for (let i = 0; i < allocations.length; i++) {
224+
const allocation = allocations[i]
225+
allocationMap[allocation.id.toLowerCase()] = allocation
226+
}
227+
228+
const results: RavWithAllocation[] = []
229+
for (let i = 0; i < ravs.length; i++) {
230+
const rav = ravs[i]
231+
const signedRav = rav.getSignedRAV()
232+
const allocationId = toAddress(
233+
signedRav.rav.allocationId.toString(),
234+
).toLowerCase()
235+
const allocation = allocationMap[allocationId] // O(1) lookup
236+
if (allocation !== undefined) {
237+
results.push({
223238
rav: signedRav,
224-
allocation: allocations.find(
225-
(a) => a.id === toAddress(signedRav.rav.allocationId.toString()),
226-
),
239+
allocation: allocation,
227240
sender: rav.senderAddress,
228-
}
229-
})
230-
.filter((rav) => rav.allocation !== undefined) as RavWithAllocation[] // this is safe because we filter out undefined allocations
241+
})
242+
}
243+
}
244+
return results
231245
},
232246
{
233247
onError: (err) =>

0 commit comments

Comments
 (0)