-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
indexer-common,indexer-agent: auto graft resolve with limit #481
base: main
Are you sure you want to change the base?
Conversation
68dd05a
to
d74033f
Compare
0608a51
to
edb1d02
Compare
edb1d02
to
87ba4f0
Compare
87ba4f0
to
2f9759a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hopeyen Thanks for this!
I'm adding these review comments as notes for when I rebase this PR due to the recent L2 changes.
@@ -126,6 +126,7 @@ const setup = async () => { | |||
await sequelize.sync({ force: true }) | |||
|
|||
const statusEndpoint = 'http://localhost:8030/graphql' | |||
const ipfsEndpoint = 'https://ipfs.network.thegraph.com' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be configurable with the current value as the default.
@@ -139,6 +140,7 @@ const setup = async () => { | |||
}) | |||
|
|||
const indexNodeIDs = ['node_1'] | |||
const autoGraftResolverLimit = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider setting this value to zero to disable the feature in tests, except when testing the feature itself.
try { | ||
this.indexer.ensure(name, deployment) | ||
} catch { | ||
this.indexer.resolveGrafting(name, deployment, 0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ensure we accurately identify and handle all potential errors here, considering that resolving grafts may introduce its own errors.
if ( | ||
!Number.isInteger(argv['auto-graft-resolver-limit']) || | ||
argv['auto-graft-resolver-limit'] < 0 | ||
) { | ||
return 'Invalid --auto-graft-resolver-limit provided. Must be >= 0 and an integer.' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could rely on yargs' coercion instead of manually implementing this validation.
https://yargs.js.org/docs/#api-reference-coercekey-fn
) { | ||
this.indexerManagement = indexerManagement | ||
this.statusResolver = statusResolver | ||
this.logger = logger | ||
this.indexerAddress = indexerAddress | ||
this.allocationManagementMode = allocationManagementMode | ||
this.autoGraftResolverLimit = autoGraftResolverLimit | ||
this.ipfsEndpoint = ipfsUrl + '/api/v0/cat?arg=' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer using the URL type when constructing URLs like this.
We get the benefit of it being checked for correctness in runtime.
// Simple fetch for subgraph manifest | ||
async subgraphManifest(targetDeployment: SubgraphDeploymentID) { | ||
const ipfsFile = await fetch(this.ipfsEndpoint + targetDeployment.ipfsHash, { | ||
method: 'POST', | ||
redirect: 'follow', | ||
}) | ||
return yaml.parse(await ipfsFile.text()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider handling IO and throwing errors with more meaningful messages here.
models, | ||
subgraphDeploymentID, | ||
indexNode, | ||
0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we set grafting depth to zero here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC the depth is set to 0 as the initialization to the recursive resolveGrafting
which should stop when depth gets incremented to the depths limit
graftStatus[0].chains[0].latestBlock && | ||
graftStatus[0].chains[0].latestBlock.number >= manifest.graft.block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd validate the array length before accessing elements by index.
} catch { | ||
throw indexerError( | ||
IndexerErrorCode.IE074, | ||
`Base deployment hasn't synced to the graft block, try again later`, | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why the error message here is the same as the one right above.
Also, we might be interested in actually catching the original error and propagating it within the IndexerError.
async stop_sync( | ||
logger: Logger, | ||
deployment: SubgraphDeploymentID, | ||
models: IndexerManagementModels, | ||
) { | ||
const neverIndexingRule = { | ||
identifier: deployment.ipfsHash, | ||
identifierType: SubgraphIdentifierType.DEPLOYMENT, | ||
decisionBasis: IndexingDecisionBasis.NEVER, | ||
} as Partial<IndexingRuleAttributes> | ||
|
||
await upsertIndexingRule(logger, models, neverIndexingRule) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure if a similar function is already defined elsewhere.
Currently, to index a subgraph deployment with grafting dependencies, indexers must manually deploy and index the graft base deployments.
To enable auto resolve feature on the indexer-agent, we add new start-up parameter
auto-graft-resolver-limit
the maximum depth of grafting dependency to automatically resolve (number, default is 0)ipfs-endpoint
the endpoint to an ipfs node to query subgraph manifest data for graft specifications before deploying a subgraphIn particular, these two parameters, along with
indexingStatusResolver
, are passed into SubgraphMangerThese 2 parameters allow indexers to control the depth of grafting dependency the agent should auto resolve. If the dependency depth is within the provided limit (inclusive), the agent start by indexing the root of the dependencies.
indexingRules
, then agent attempts the target deployment periodically.actionQueue
while the grafting dependencies aren't resolved, then indexer agent will automatically deploy the base level deployment and fails the action.indexingStatusResolver
is used to check for grafting deployment's status before trying to ensure the indexing status of the target deployment.For testing purposes I made these random subgraphs with dependencies on the testnet
Resolves #439