Skip to content

fix(subgraph): use deployments.json as source of truth for addresses#406

Open
nijoe1 wants to merge 1 commit intoFilOzone:mainfrom
nijoe1:fix/subgraph-use-deployments-json
Open

fix(subgraph): use deployments.json as source of truth for addresses#406
nijoe1 wants to merge 1 commit intoFilOzone:mainfrom
nijoe1:fix/subgraph-use-deployments-json

Conversation

@nijoe1
Copy link

@nijoe1 nijoe1 commented Jan 30, 2026

  • Refactor generate-constants.js and generate-config.js to read contract
  • addresses from service_contracts/deployments.json instead of the manual
  • config/network.json. This ensures subgraph configuration stays in sync when contracts are redeployed.

cc: @BigLep @rjan90 @rvagg

 - Refactor generate-constants.js and generate-config.js to read contract
 - addresses from service_contracts/deployments.json instead of the manual
 - config/network.json. This ensures subgraph configuration stays in sync
when contracts are redeployed.
Copilot AI review requested due to automatic review settings January 30, 2026 16:16
@FilOzzy FilOzzy added this to FOC Jan 30, 2026
@github-project-automation github-project-automation bot moved this to 📌 Triage in FOC Jan 30, 2026
@rjan90 rjan90 moved this from 📌 Triage to 🐱 Todo in FOC Jan 30, 2026
@rjan90 rjan90 moved this from 🐱 Todo to 🔎 Awaiting review in FOC Jan 30, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the subgraph configuration system to use service_contracts/deployments.json as the source of truth for contract addresses instead of the manually maintained config/network.json. This ensures the subgraph configuration automatically stays synchronized when contracts are redeployed.

Changes:

  • Refactored config-loader.js to read from service_contracts/deployments.json with chain ID-based lookups
  • Added mapping layer to convert deployment keys (e.g., PDP_VERIFIER_PROXY_ADDRESS) to template keys (e.g., PDPVerifier)
  • Implemented optional start block override mechanism via config/start-blocks.json
  • Updated console output and template comments to reflect the new data source

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
subgraph/templates/constants.template.ts Updated comment to indicate deployments.json as the source
subgraph/scripts/utils/config-loader.js Complete refactor to load from deployments.json with chain ID mapping, added ABI loading utilities
subgraph/scripts/generate-constants.js Updated error message and added source confirmation log
subgraph/scripts/generate-config.js Added source confirmation log

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +187 to 210
function loadAbi(contractName) {
const abiPath = getAbiPath(contractName);

try {
const content = fs.readFileSync(abiPath, "utf8");
return JSON.parse(content);
} catch (error) {
if (error.code === "ENOENT") {
console.error(`Error: ABI file not found at: ${abiPath}`);
console.error(
`Please ensure service_contracts/abi/${contractName}.abi.json exists.`
);
process.exit(1);
}
if (error instanceof SyntaxError) {
console.error(`Error: Invalid JSON in ABI file: ${abiPath}`);
console.error(`JSON Error: ${error.message}`);
} else {
console.error(`Error reading ABI file: ${abiPath}`);
console.error(`File Error: ${error.message}`);
}
process.exit(1);
}
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loadAbi function expects ABI files to be named using the template key format (e.g., "USDFCToken.abi.json"), but the actual ABI file for the USDFCToken contract is named "FilecoinPayV1.abi.json" in the service_contracts/abi directory. While this function is currently not used in the codebase, it could cause runtime errors if someone tries to call loadAbi("USDFCToken") in the future.

Consider either:

  1. Documenting that loadAbi should use the actual contract names (e.g., "FilecoinPayV1") rather than the template keys
  2. Creating a mapping from template keys to actual ABI file names
  3. Ensuring ABI files are named consistently with the template keys

Copilot uses AI. Check for mistakes.
Comment on lines +151 to +155
const startBlock =
startBlockOverrides?.[templateKey] ||
defaultStartBlocks[templateKey] ||
0;

Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback value of 0 for startBlock (line 154) means the subgraph will start indexing from the genesis block if no override or default is provided. This could result in inefficient indexing for contracts deployed much later. Consider logging a warning when falling back to 0, or making it a more reasonable default value based on known deployment timing.

For reference, mainnet (chain ID 314) launched at block 0 in 2021, and calibration (chain ID 314159) also starts at block 0. Having a fallback of 0 means potentially scanning millions of blocks before reaching the actual contract deployments.

Suggested change
const startBlock =
startBlockOverrides?.[templateKey] ||
defaultStartBlocks[templateKey] ||
0;
let startBlock;
if (
startBlockOverrides &&
Object.prototype.hasOwnProperty.call(startBlockOverrides, templateKey)
) {
startBlock = startBlockOverrides[templateKey];
} else if (
defaultStartBlocks &&
Object.prototype.hasOwnProperty.call(defaultStartBlocks, templateKey)
) {
startBlock = defaultStartBlocks[templateKey];
} else {
console.warn(
`Warning: No startBlock configured for '${templateKey}' on network '${network}' (chain ID ${chainId}); falling back to 0. ` +
"This may cause slow indexing if the contract was deployed well after genesis."
);
startBlock = 0;
}

Copilot uses AI. Check for mistakes.
Comment on lines +135 to +136
const config = {
name: NETWORK_NAMES[network],
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a network is added to NETWORK_CHAIN_IDS but not to NETWORK_NAMES, the config object will have name: undefined, which could cause issues with template rendering. Consider adding validation to ensure both mappings are in sync, or consolidating them into a single data structure.

For example:

const NETWORK_CONFIG = {
  mainnet: { chainId: "314", subgraphName: "filecoin" },
  calibration: { chainId: "314159", subgraphName: "filecoin-testnet" }
};

This would make it impossible to have mismatched entries.

Copilot uses AI. Check for mistakes.
@BigLep
Copy link
Contributor

BigLep commented Jan 30, 2026

Meta: I'm trying to understand who uses/cares about this subgraph: https://filecoinproject.slack.com/archives/C08TVNKJV7C/p1767914301013149

@rvagg
Copy link
Collaborator

rvagg commented Feb 2, 2026

We're also pulling out the subgraph retriever from the sdk here since we've as yet had no signal of its use and it's awkward to maintain (cause we don't have a testing path for it and none of us use it): FilOzone/synapse-sdk#575
Could be put back in, but would need a proper owner who cared about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting review

Development

Successfully merging this pull request may close these issues.

4 participants