Skip to content

Commit a2eacd5

Browse files
committed
fix: get entity count from graph node before collecting dips
1 parent 34ef522 commit a2eacd5

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,22 @@ export class GraphNode {
708708
}
709709
}
710710

711+
public async entityCount(deployments: SubgraphDeploymentID[]): Promise<number[]> {
712+
// Query the entity count for each deployment using the indexingStatuses query
713+
const query = `
714+
query entityCounts($deployments: [String!]!) {
715+
indexingStatuses(subgraphs: $deployments) {
716+
entityCount
717+
}
718+
}
719+
`
720+
const result = await this.status
721+
.query(query, { deployments: deployments.map((id) => id.ipfsHash) })
722+
.toPromise()
723+
724+
return result.data.indexingStatuses.map((status) => status.entityCount) as number[]
725+
}
726+
711727
public async proofOfIndexing(
712728
deployment: SubgraphDeploymentID,
713729
block: BlockPointer,

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,7 @@ export class AllocationManager {
107107
private network: Network,
108108
) {
109109
if (this.network.specification.indexerOptions.dipperEndpoint) {
110-
this.dipsManager = new DipsManager(
111-
this.logger,
112-
this.models,
113-
this.graphNode,
114-
this.network,
115-
this,
116-
)
110+
this.dipsManager = new DipsManager(this.logger, this.models, this.network, this)
117111
}
118112
}
119113

packages/indexer-common/src/indexing-fees/dips.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export class DipsManager {
3737
constructor(
3838
private logger: Logger,
3939
private models: IndexerManagementModels,
40-
private graphNode: GraphNode,
4140
private network: Network,
4241
private parent: AllocationManager | null,
4342
) {
@@ -157,6 +156,7 @@ export class DipsCollector {
157156
private specification: NetworkSpecification,
158157
private tapCollector: TapCollector,
159158
private wallet: Wallet,
159+
private graphNode: GraphNode,
160160
) {
161161
if (!this.specification.indexerOptions.dipperEndpoint) {
162162
throw new Error('dipperEndpoint is not set')
@@ -173,6 +173,7 @@ export class DipsCollector {
173173
specification: NetworkSpecification,
174174
tapCollector: TapCollector,
175175
wallet: Wallet,
176+
graphNode: GraphNode,
176177
) {
177178
const collector = new DipsCollector(
178179
logger,
@@ -181,6 +182,7 @@ export class DipsCollector {
181182
specification,
182183
tapCollector,
183184
wallet,
185+
graphNode,
184186
)
185187
collector.startCollectionLoop()
186188
return collector
@@ -223,7 +225,14 @@ export class DipsCollector {
223225
this.logger.error(`Agreement ${agreement.id} has no last allocation id`)
224226
return
225227
}
226-
const entityCount = 0 // TODO: get entity count from graph node
228+
const entityCounts = await this.graphNode.entityCount([
229+
new SubgraphDeploymentID(agreement.subgraph_deployment_id),
230+
])
231+
if (entityCounts.length === 0) {
232+
this.logger.error(`Agreement ${agreement.id} has no entity count`)
233+
return
234+
}
235+
const entityCount = entityCounts[0]
227236
const collection = await createSignedCollectionRequest(
228237
agreement.id,
229238
agreement.last_allocation_id,

packages/indexer-common/src/network.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ export class Network {
343343
specification,
344344
tapCollector,
345345
wallet,
346+
graphNode,
346347
)
347348
}
348349
} else {

0 commit comments

Comments
 (0)