Skip to content

Commit

Permalink
service: Validate operator wallet on startup
Browse files Browse the repository at this point in the history
- Also add new IndexerError variant for failure to connect to contracts
  • Loading branch information
fordN committed Nov 17, 2023
1 parent 5683508 commit ebfcb63
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/indexer-common/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export enum IndexerErrorCode {
IE072 = 'IE072',
IE073 = 'IE073',
IE074 = 'IE074',
IE075 = 'IE075',
}

export const INDEXER_ERROR_MESSAGES: Record<IndexerErrorCode, string> = {
Expand Down Expand Up @@ -163,6 +164,7 @@ export const INDEXER_ERROR_MESSAGES: Record<IndexerErrorCode, string> = {
IE072: 'Failed to execute batch tx (contract: staking)',
IE073: 'Failed to query subgraph features from indexing statuses endpoint',
IE074: 'Failed to deploy subgraph: network not supported',
IE075: 'Failed to connect to network contracts',
}

export type IndexerErrorCause = unknown
Expand Down
47 changes: 42 additions & 5 deletions packages/indexer-service/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
createLogger,
createMetrics,
createMetricsServer,
NetworkContracts,
SubgraphDeploymentID,
toAddress,
} from '@graphprotocol/common-ts'
Expand All @@ -32,6 +33,7 @@ import { createServer } from '../server'
import { QueryProcessor } from '../queries'
import { ensureAttestationSigners, monitorEligibleAllocations } from '../allocations'
import { AllocationReceiptManager } from '../query-fees'
import pRetry from 'p-retry'

export default {
command: 'start',
Expand Down Expand Up @@ -333,7 +335,7 @@ export default {
chainId: networkIdentifier.chainId,
})

let contracts = undefined
let contracts: NetworkContracts | undefined = undefined
try {
contracts = await connectContracts(
networkProvider,
Expand All @@ -343,11 +345,8 @@ export default {
} catch (error) {
logger.error(
`Failed to connect to contracts, please ensure you are using the intended Ethereum Network`,
{
error,
},
)
throw error
throw indexerError(IndexerErrorCode.IE075, error)
}

logger.info('Successfully connected to contracts', {
Expand Down Expand Up @@ -377,6 +376,44 @@ export default {
operator: address.toString(),
})

// Validate the operator wallet matches the operator set for the indexer
const isOperator = await pRetry(
async () =>
contracts!.staking.isOperator(
wallet.address.toString(),
indexerAddress.toString(),
),
{
retries: 10,
maxTimeout: 10000,
onFailedAttempt: err => {
logger.warn(
`contracts.staking.isOperator(${wallet.address.toString()}, ${indexerAddress.toString()}) failed`,
{
attempt: err.attemptNumber,
retriesLeft: err.retriesLeft,
err: err.message,
},
)
},
} as pRetry.Options,
)

if (isOperator == false) {
logger.error(
'Operator wallet is not allowed for indexer, please see attached debug suggestions',
{
debugSuggestion1: 'verify that operator wallet is set for indexer account',
debugSuggestion2:
'verify that service and agent are both using correct operator wallet mnemonic',
},
)
throw indexerError(
IndexerErrorCode.IE034,
`contracts.staking.isOperator returned 'False'`,
)
}

// Monitor indexer allocations that we may receive traffic for
const allocations = monitorEligibleAllocations({
indexer: indexerAddress,
Expand Down

0 comments on commit ebfcb63

Please sign in to comment.