Skip to content

Commit 2679d30

Browse files
committed
common: work on auto-graft-sync
1 parent a999aaf commit 2679d30

File tree

11 files changed

+382
-135
lines changed

11 files changed

+382
-135
lines changed

docs/networks/arbitrum-sepolia.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ testnet (for now) are Mainnet subgraphs. This means:
5656
| `INDEXER_AGENT_EPOCH_SUBGRAPH_ENDPOINT` | `--epoch-subgraph-endpoint` | `https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/BhnsdeZihU4SuokxZMLF4FQBVJ3jgtZf6v51gHvz3bSS` |
5757
| `INDEXER_AGENT_TAP_SUBGRAPH_DEPLOYMENT` | `--tap-subgraph-deployment` | `QmUiLdbsk6c51UMdcNBxsP3KadJpkmp6a3k2NCprR4ZFeM` |
5858
| `INDEXER_AGENT_TAP_SUBGRAPH_ENDPOINT` | `--tap-subgraph-endpoint` | `https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/7ubx365MiqBH5iUz6XWXWT8PTof5BVAyEzdb8m17RvbD` |
59-
| `INDEXER_AGENT_IPFS_ENDPOINT` | `--ipfs-endpoint` | `https://ipfs.io/` |
59+
| `INDEXER_AGENT_IPFS_ENDPOINT` | `--ipfs-endpoint` | `https://ipfs.network.thegraph.com` |
6060

6161
In order to avoid collecting or claiming query fees below a certain threshold
6262
(e.g. below the cost of the two transactions), the following configuration

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ export function injectCommonStartupOptions(argv: Argv): Argv {
102102
group: 'Postgres',
103103
})
104104
.option('ipfs-endpoint', {
105-
description: 'Ipfs endpoint for querying manifests',
105+
description: 'IPFS endpoint for querying manifests.',
106106
type: 'string',
107107
required: true,
108108
group: 'Indexer Infrastructure',
109+
default: 'https://ipfs.network.thegraph.com',
109110
})
110111
.option('graph-node-query-endpoint', {
111112
description: 'Graph Node endpoint for querying subgraphs',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ export async function run(
502502
argv.graphNodeAdminEndpoint,
503503
argv.graphNodeQueryEndpoint,
504504
argv.graphNodeStatusEndpoint,
505+
argv.ipfsEndpoint,
505506
)
506507

507508
// --------------------------------------------------------------------------------
Lines changed: 110 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,150 @@
1-
import { SubgraphDeploymentID } from "@graphprotocol/common-ts";
2-
import { SubgraphDependencies, SubgraphManifestResolver } from "../graph-node";
3-
import express, { Request, Response } from "express";
4-
import { AddressInfo } from "net";
5-
import { utils } from "ethers";
6-
import { base58 } from "ethers/lib/utils";
1+
import { createLogger, SubgraphDeploymentID } from '@graphprotocol/common-ts'
2+
import { SubgraphDependencies, SubgraphManifestResolver } from '../graph-node'
3+
import express, { Request, Response } from 'express'
4+
import { AddressInfo } from 'net'
5+
import { utils } from 'ethers'
76

8-
const EXAMPLE_VALID_IPFS_HASH = "Qmd9nZKCH8UZU1pBzk7G8ECJr3jX3a2vAf3vowuTwFvrQg"
9-
const EXAMPLE_NON_MANIFEST_VALID_IPFS_HASH = "QmddQDkcHHM7mGvYrrnoGnQ1q9GdHQfbTvj2mfbyz2Q49K"
7+
const EXAMPLE_VALID_IPFS_HASH = 'Qmd9nZKCH8UZU1pBzk7G8ECJr3jX3a2vAf3vowuTwFvrQg'
8+
const EXAMPLE_NON_MANIFEST_VALID_IPFS_HASH =
9+
'QmddQDkcHHM7mGvYrrnoGnQ1q9GdHQfbTvj2mfbyz2Q49K'
1010

1111
function mockManifestHash(input: string): string {
12-
const utf8Bytes = utils.toUtf8Bytes(input)
13-
const hash = utils.keccak256(utf8Bytes) // Generate a keccak256 hash of the input
14-
return new SubgraphDeploymentID(hash).ipfsHash
12+
const utf8Bytes = utils.toUtf8Bytes(input)
13+
const hash = utils.keccak256(utf8Bytes) // Generate a keccak256 hash of the input
14+
return new SubgraphDeploymentID(hash).ipfsHash
1515
}
1616

17-
const DEP_ROOT_HASH = mockManifestHash("root")
18-
const DEP_1 = mockManifestHash("dep2")
19-
const DEP_2 = mockManifestHash("dep3")
17+
const DEP_ROOT_HASH = mockManifestHash('root')
18+
const DEP_1 = mockManifestHash('dep2')
19+
const DEP_2 = mockManifestHash('dep3')
2020

2121
describe(SubgraphManifestResolver, () => {
22-
let ipfs: SubgraphManifestResolver
23-
let app = express()
24-
let server: any
22+
let ipfs: SubgraphManifestResolver
23+
const app = express()
2524

26-
let manifestMap = new Map<string, string>()
27-
manifestMap.set(EXAMPLE_VALID_IPFS_HASH, `
25+
/* eslint-disable @typescript-eslint/no-explicit-any */
26+
let server: any
27+
28+
const manifestMap = new Map<string, string>()
29+
manifestMap.set(
30+
EXAMPLE_VALID_IPFS_HASH,
31+
`
2832
specVersion: "0.0.2"
2933
name: "test"
3034
graft:
3135
base: "test"
3236
block: 5
33-
`)
37+
`,
38+
)
3439

35-
// this example is a real world contract schema
36-
manifestMap.set(EXAMPLE_NON_MANIFEST_VALID_IPFS_HASH, `
40+
// this example is a real world contract schema
41+
manifestMap.set(
42+
EXAMPLE_NON_MANIFEST_VALID_IPFS_HASH,
43+
`
3744
{
3845
"name": "test"
3946
}
40-
`)
47+
`,
48+
)
4149

42-
manifestMap.set(DEP_ROOT_HASH, `
50+
manifestMap.set(
51+
DEP_ROOT_HASH,
52+
`
4353
specVersion: "0.0.2"
4454
name: "root"
4555
graft:
4656
base: ${DEP_1}
4757
block: 4
48-
`)
49-
manifestMap.set(DEP_1, `
58+
`,
59+
)
60+
manifestMap.set(
61+
DEP_1,
62+
`
5063
specVersion: "0.0.2"
5164
name: "dep1"
5265
graft:
5366
base: ${DEP_2}
5467
block: 5
55-
`)
56-
manifestMap.set(DEP_2, `
68+
`,
69+
)
70+
manifestMap.set(
71+
DEP_2,
72+
`
5773
specVersion: "0.0.2"
5874
name: "dep2"
59-
`)
60-
61-
beforeAll(async () => {
62-
// Mock endpoint for IPFS CID requests
63-
app.get('/ipfs/:cid', (req: Request, res: Response) => {
64-
const { cid } = req.params;
65-
// Example: Respond with different data based on the CID
66-
if (manifestMap.has(cid)) {
67-
res.send(manifestMap.get(cid));
68-
} else {
69-
res.status(404).send();
70-
}
71-
});
72-
// Start server and bind to a random port
73-
server = app.listen(0, () => {
74-
console.log(`Mock server running on ${server.address()}`)
75-
});
75+
`,
76+
)
7677

77-
const address: AddressInfo = server.address() as AddressInfo
78-
const serverAddress = `http://localhost:${address.port}`;
79-
ipfs = new SubgraphManifestResolver(serverAddress);
78+
beforeAll(async () => {
79+
// Mock endpoint for IPFS CID requests
80+
app.get('/ipfs/:cid', (req: Request, res: Response) => {
81+
const { cid } = req.params
82+
// Example: Respond with different data based on the CID
83+
if (manifestMap.has(cid)) {
84+
res.send(manifestMap.get(cid))
85+
} else {
86+
res.status(404).send()
87+
}
88+
})
89+
// Start server and bind to a random port
90+
server = app.listen(0, () => {
91+
console.log(`Mock server running on ${server.address()}`)
8092
})
8193

82-
afterAll(async () => {
83-
// Shut down the server
84-
if (server) {
85-
await new Promise<void>((resolve, reject) => {
86-
server.close((err: Error | undefined) => {
87-
if (err) {
88-
reject(err);
89-
} else {
90-
resolve();
91-
}
92-
});
93-
});
94-
console.log("Mock server shut down");
95-
}
96-
});
94+
const address: AddressInfo = server.address() as AddressInfo
95+
const serverAddress = `http://localhost:${address.port}`
96+
ipfs = new SubgraphManifestResolver(serverAddress, createLogger({ name: 'test' }))
97+
})
9798

98-
it("should fetch and parse a valid manifest", async () => {
99-
const manifest = await ipfs.resolve(new SubgraphDeploymentID(EXAMPLE_VALID_IPFS_HASH));
100-
expect(manifest).toEqual({
101-
specVersion: "0.0.2",
102-
name: "test",
103-
graft: { base: "test", block: 5 }
104-
});
105-
})
99+
afterAll(async () => {
100+
// Shut down the server
101+
if (server) {
102+
await new Promise<void>((resolve, reject) => {
103+
server.close((err: Error | undefined) => {
104+
if (err) {
105+
reject(err)
106+
} else {
107+
resolve()
108+
}
109+
})
110+
})
111+
console.log('Mock server shut down')
112+
}
113+
})
106114

107-
it("should throw an error when fetching an invalid manifest", async () => {
108-
await expect(ipfs.resolve(new SubgraphDeploymentID(EXAMPLE_NON_MANIFEST_VALID_IPFS_HASH))).rejects.toThrow();
115+
it('should fetch and parse a valid manifest', async () => {
116+
const manifest = await ipfs.resolve(new SubgraphDeploymentID(EXAMPLE_VALID_IPFS_HASH))
117+
expect(manifest).toEqual({
118+
specVersion: '0.0.2',
119+
name: 'test',
120+
graft: { base: 'test', block: 5 },
109121
})
122+
})
110123

111-
it("should throw an error when fetching a non-existent manifest", async () => {
112-
await expect(ipfs.resolve(new SubgraphDeploymentID("QmeDVcAvgYPKFCw2VCqTK3JRexHT8jkgvQ7AJ9WxhuFNM8"))).rejects.toThrow();
113-
})
124+
it('should throw an error when fetching an invalid manifest', async () => {
125+
await expect(
126+
ipfs.resolve(new SubgraphDeploymentID(EXAMPLE_NON_MANIFEST_VALID_IPFS_HASH)),
127+
).rejects.toThrow()
128+
})
114129

115-
it('should resolve dependencies', async () => {
116-
const manifest: SubgraphDependencies = await ipfs.resolveWithDependencies(new SubgraphDeploymentID(DEP_ROOT_HASH));
117-
expect(manifest).toEqual({
118-
root: new SubgraphDeploymentID(DEP_ROOT_HASH),
119-
dependencies: [
120-
{ base: new SubgraphDeploymentID(DEP_1), block: 4 },
121-
{ base: new SubgraphDeploymentID(DEP_2), block: 5 }
122-
]
123-
})
124-
})
130+
it('should throw an error when fetching a non-existent manifest', async () => {
131+
await expect(
132+
ipfs.resolve(
133+
new SubgraphDeploymentID('QmeDVcAvgYPKFCw2VCqTK3JRexHT8jkgvQ7AJ9WxhuFNM8'),
134+
),
135+
).rejects.toThrow()
136+
})
125137

138+
it('should resolve dependencies', async () => {
139+
const manifest: SubgraphDependencies = await ipfs.resolveWithDependencies(
140+
new SubgraphDeploymentID(DEP_ROOT_HASH),
141+
)
142+
expect(manifest).toEqual({
143+
root: new SubgraphDeploymentID(DEP_ROOT_HASH),
144+
dependencies: [
145+
{ base: new SubgraphDeploymentID(DEP_1), block: 4 },
146+
{ base: new SubgraphDeploymentID(DEP_2), block: 5 },
147+
],
148+
})
149+
})
126150
})

packages/indexer-common/src/allocations/__tests__/tap.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const setup = async () => {
5151
'https://test-admin-endpoint.xyz',
5252
'https://test-query-endpoint.xyz',
5353
'https://test-status-endpoint.xyz',
54+
'https://test-ipfs-endpoint.xyz',
5455
)
5556

5657
const network = await Network.create(

packages/indexer-common/src/allocations/__tests__/validate-queries.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const setup = async () => {
4444
'https://test-admin-endpoint.xyz',
4545
'https://test-query-endpoint.xyz',
4646
'https://test-status-endpoint.xyz',
47+
'https://test-ipfs-endpoint.xyz',
4748
)
4849

4950
const network = await Network.create(

0 commit comments

Comments
 (0)