Skip to content

Commit

Permalink
service: minor updates for the new protocolNetwork field
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Aug 7, 2023
1 parent f8b7c70 commit 713411b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
4 changes: 3 additions & 1 deletion packages/indexer-service/src/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export interface MonitorEligibleAllocationsOptions {
logger: Logger
networkSubgraph: NetworkSubgraph
interval: number
protocolNetwork: string
}

export const monitorEligibleAllocations = ({
indexer,
logger: parentLogger,
networkSubgraph,
protocolNetwork,
interval,
}: MonitorEligibleAllocationsOptions): Eventual<Allocation[]> => {
const logger = parentLogger.child({ component: 'AllocationMonitor' })
Expand Down Expand Up @@ -128,7 +130,7 @@ export const monitorEligibleAllocations = ({
return [
...result.data.indexer.activeAllocations,
...result.data.indexer.recentlyClosedAllocations,
].map(parseGraphQLAllocation)
].map(x => parseGraphQLAllocation(x, protocolNetwork))
} catch (err) {
logger.warn(`Failed to query indexer allocations, keeping existing`, {
allocations: currentAllocations.map(allocation => allocation.id),
Expand Down
61 changes: 40 additions & 21 deletions packages/indexer-service/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import {
defineQueryFeeModels,
indexerError,
IndexerErrorCode,
IndexingStatusResolver,
GraphNode,
Network,
NetworkSubgraph,
registerIndexerErrorMetrics,
resolveChainId,
validateProviderNetworkIdentifier,
} from '@graphprotocol/indexer-common'

import { createServer } from '../server'
Expand All @@ -36,7 +38,9 @@ export default {
describe: 'Start the service',
builder: (yargs: Argv): Argv => {
return yargs
.option('ethereum', {
.option('network-provider', {
//TODO:FIXME: uptrade this field as we did for Agent
alias: 'ethereum',
description: 'Ethereum node or provider URL',
type: 'string',
required: true,
Expand Down Expand Up @@ -177,6 +181,7 @@ export default {
if (!argv['network-subgraph-endpoint'] && !argv['network-subgraph-deployment']) {
return `At least one of --network-subgraph-endpoint and --network-subgraph-deployment must be provided`
}

return true
})
.config({
Expand Down Expand Up @@ -273,18 +278,23 @@ export default {
logger.info('Successfully connected to database')

logger.info(`Connect to network subgraph`)
const indexingStatusResolver = new IndexingStatusResolver({
const graphNode = new GraphNode(
logger,
statusEndpoint: argv.graphNodeStatusEndpoint,
})
// We use a fake Graph Node admin endpoint here because we don't
// want the Indexer Service to perform management actions on
// Graph Node.
'http://fake-graph-node-admin-endpoint',
argv.graphNodeQueryEndpoint,
argv.graphNodeStatusEndpoint,
argv.indexNodeIds,
)
const networkSubgraph = await NetworkSubgraph.create({
logger,
endpoint: argv.networkSubgraphEndpoint,
deployment: argv.networkSubgraphDeployment
? {
indexingStatusResolver,
graphNode,
deployment: new SubgraphDeploymentID(argv.networkSubgraphDeployment),
graphNodeQueryEndpoint: argv.graphNodeQueryEndpoint,
}
: undefined,
})
Expand All @@ -293,19 +303,32 @@ export default {
const networkProvider = await Network.provider(
logger,
metrics,
argv.ethereum,
'_',
argv.networkProvider,
argv.ethereumPollingInterval,
)
const network = await networkProvider.getNetwork()
const networkIdentifier = await networkProvider.getNetwork()
const protocolNetwork = resolveChainId(networkIdentifier.chainId)

// If the network subgraph deployment is present, validate if the `chainId` we get from our
// provider is consistent.
if (argv.networkSubgraphDeployment) {
validateProviderNetworkIdentifier(
protocolNetwork,
argv.networkSubgraphDeployment,
graphNode,
logger,
)
}

logger.info('Connect to contracts', {
network: network.name,
chainId: network.chainId,
network: networkIdentifier.name,
chainId: networkIdentifier.chainId,
})

let contracts = undefined
try {
contracts = await connectContracts(networkProvider, network.chainId)
contracts = await connectContracts(networkProvider, networkIdentifier.chainId)
} catch (error) {
logger.error(
`Failed to connect to contracts, please ensure you are using the intended Ethereum Network`,
Expand All @@ -332,6 +355,7 @@ export default {
queryFeeModels,
logger,
toAddress(argv.clientSignerAddress),
protocolNetwork,
)

// Ensure the address is checksummed
Expand All @@ -347,6 +371,7 @@ export default {
indexer: indexerAddress,
logger,
networkSubgraph,
protocolNetwork,
interval: argv.allocationSyncingInterval,
})

Expand All @@ -355,7 +380,7 @@ export default {
logger,
allocations,
wallet,
chainId: network.chainId,
chainId: networkIdentifier.chainId,
disputeManagerAddress: contracts.disputeManager.address,
})

Expand All @@ -371,12 +396,8 @@ export default {

const indexerManagementClient = await createIndexerManagementClient({
models,
address,
contracts,
indexingStatusResolver,
graphNode,
indexNodeIDs: ['node_1'], // This is just a dummy since the indexer-service doesn't manage deployments,
deploymentManagementEndpoint: argv.graphNodeStatusEndpoint,
networkSubgraph,
logger,
defaults: {
// This is just a dummy, since we're never writing to the management
Expand All @@ -385,9 +406,7 @@ export default {
allocationAmount: BigNumber.from('0'),
},
},
features: {
injectDai: true,
},
multiNetworks: undefined,
})

// Spin up a basic webserver
Expand Down
6 changes: 6 additions & 0 deletions packages/indexer-service/src/query-fees/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@ export class AllocationReceiptManager implements ReceiptManager {
private readonly _cache: Map<string, Readonly<AllocationReceiptAttributes>> = new Map()
private readonly _flushQueue: string[] = []
private readonly _allocationReceiptVerifier: NativeSignatureVerifier
private readonly protocolNetwork: string

constructor(
sequelize: Sequelize,
queryFeeModels: QueryFeeModels,
logger: Logger,
clientSignerAddress: Address,
protocolNetwork: string,
) {
logger = logger.child({ component: 'ReceiptManager' })

this._sequelize = sequelize
this._queryFeeModels = queryFeeModels
this._allocationReceiptVerifier = new NativeSignatureVerifier(clientSignerAddress)
this.protocolNetwork = protocolNetwork

timer(30_000).pipe(async () => {
try {
Expand Down Expand Up @@ -114,6 +117,7 @@ export class AllocationReceiptManager implements ReceiptManager {
allocation: receipt.allocation,
fees: receipt.fees.toString(),
signature,
protocolNetwork: this.protocolNetwork,
})

return receipt
Expand Down Expand Up @@ -147,6 +151,7 @@ export class AllocationReceiptManager implements ReceiptManager {
this._queryFeeModels,
receipt.allocation,
transaction,
this.protocolNetwork,
)
if (isNewSummary) {
await summary.save()
Expand All @@ -160,6 +165,7 @@ export class AllocationReceiptManager implements ReceiptManager {
allocation: receipt.allocation,
signature: receipt.signature,
fees: receipt.fees,
protocolNetwork: this.protocolNetwork,
},
transaction,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const setup = async () => {
models = defineIndexerManagementModels(sequelize)
address = '0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1'
contracts = await connectContracts(getTestProvider('goerli'), 5)
await sequelize.sync({ force: true })
sequelize = await sequelize.sync({ force: true })
const statusEndpoint = 'http://localhost:8030/graphql'
indexingStatusResolver = new IndexingStatusResolver({
logger: logger,
Expand Down

0 comments on commit 713411b

Please sign in to comment.