Skip to content

Horizon support #1117

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ yalc.lock
.idea/
.envrc
.vscode

# local-network override mode files
tap-contracts.json
config/config.yaml
239 changes: 136 additions & 103 deletions README.md

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@
"lerna": "6.1.0"
},
"resolutions": {
"ethers": "5.7.0",
"ethers": "6.13.7",
"sequelize": "6.33.0",
"@ethersproject/bignumber": "5.7.0",
"@ethersproject/providers": "5.7.0",
"@urql/core": "3.1.0",
"@urql/exchange-execute": "2.1.0",
"punycode": "2.3.1",
"uri-js": "4.2.2"
},
"overrides": {
"ethers": "5.7.0",
"ethers": "6.13.7",
"sequelize": "6.33.0",
"@ethersproject/bignumber": "5.7.0",
"@ethersproject/providers": "5.7.0",
"@urql/core": "3.1.0",
"@urql/exchange-execute": "2.1.0",
"graphql": "16.8.0"
Expand Down
1 change: 1 addition & 0 deletions packages/indexer-agent/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/', '/dist/', '.yalc'],
transformIgnorePatterns: ['!node_modules/'],
globals: {
__DATABASE__: {
host:
Expand Down
10 changes: 4 additions & 6 deletions packages/indexer-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
"graph-indexer-agent": "bin/graph-indexer-agent"
},
"dependencies": {
"@graphprotocol/common-ts": "2.0.11",
"@graphprotocol/common-ts": "3.0.1",
"@graphprotocol/indexer-common": "^0.23.5",
"@thi.ng/heaps": "^1.3.1",
"axios": "0.26.1",
"bs58": "5.0.0",
"delay": "^5.0.0",
"ethers": "5.7.0",
"ethers": "6.13.7",
"evt": "1.9.12",
"global": "4.4.0",
"graphql": "16.8.0",
Expand Down Expand Up @@ -80,10 +80,8 @@
"typescript": "5.2.2"
},
"resolutions": {
"ethers": "5.7.0",
"sequelize": "6.33.0",
"@ethersproject/bignumber": "5.7.0",
"@ethersproject/providers": "5.7.0"
"ethers": "6.13.7",
"sequelize": "6.33.0"
},
"gitHead": "972ab96774007b2aee15b1da169d2ff4be9f9d27"
}
3 changes: 1 addition & 2 deletions packages/indexer-agent/src/__tests__/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
MultiNetworks,
loadTestYamlConfig,
} from '@graphprotocol/indexer-common'
import { BigNumber } from 'ethers'
import { Sequelize } from 'sequelize'

const TEST_DISPUTE_1: POIDisputeAttributes = {
Expand Down Expand Up @@ -69,7 +68,7 @@ const TEST_DISPUTE_2: POIDisputeAttributes = {

const POI_DISPUTES_CONVERTERS_FROM_GRAPHQL: Record<
keyof POIDisputeAttributes,
(x: never) => string | BigNumber | number | undefined
(x: never) => string | bigint | number | undefined
> = {
allocationID: x => x,
subgraphDeploymentID: x => x,
Expand Down
42 changes: 22 additions & 20 deletions packages/indexer-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import mapValues from 'lodash.mapvalues'
import zip from 'lodash.zip'
import { AgentConfigs, NetworkAndOperator } from './types'

type ActionReconciliationContext = [AllocationDecision[], number, number]
type ActionReconciliationContext = [AllocationDecision[], number, bigint]

const deploymentInList = (
list: SubgraphDeploymentID[],
Expand Down Expand Up @@ -233,6 +233,7 @@ export class Agent {
try {
await operator.ensureGlobalIndexingRule()
await this.ensureAllSubgraphsIndexing(network)
await network.provision()
await network.register()
} catch (err) {
this.logger.critical(
Expand Down Expand Up @@ -270,15 +271,15 @@ export class Agent {
},
)

const maxAllocationEpochs: Eventual<NetworkMapped<number>> =
const maxAllocationEpochs: Eventual<NetworkMapped<bigint>> =
sequentialTimerMap(
{ logger, milliseconds: requestIntervalLarge },
() =>
this.multiNetworks.map(({ network }) => {
logger.trace('Fetching max allocation epochs', {
protocolNetwork: network.specification.networkIdentifier,
})
return network.contracts.staking.maxAllocationEpochs()
return network.contracts.LegacyStaking.maxAllocationEpochs()
}),
{
onError: error =>
Expand All @@ -304,9 +305,9 @@ export class Agent {
await network.networkMonitor.subgraphs(subgraphRuleIds)
if (subgraphsMatchingRules.length >= 1) {
const epochLength =
await network.contracts.epochManager.epochLength()
await network.contracts.EpochManager.epochLength()
const blockPeriod = 15
const bufferPeriod = epochLength.toNumber() * blockPeriod * 100 // 100 epochs
const bufferPeriod = Number(epochLength) * blockPeriod * 100 // 100 epochs
rules = convertSubgraphBasedRulesToDeploymentBased(
rules,
subgraphsMatchingRules,
Expand Down Expand Up @@ -486,7 +487,7 @@ export class Agent {
const matchingTransfer = eligibleTransferDeployments.find(
deployment =>
deployment.ipfsHash == decision.deployment.ipfsHash &&
deployment.startedTransferToL2At.toNumber() > oneWeekAgo,
Number(deployment.startedTransferToL2At) > oneWeekAgo,
)
if (matchingTransfer) {
logger.debug('Found a matching subgraph transfer', {
Expand Down Expand Up @@ -682,7 +683,8 @@ export class Agent {
currentEpochNumber: number,
) =>
currentEpochNumber -
network.specification.indexerOptions.poiDisputableEpochs,
(network.specification.indexerOptions
.poiDisputableEpochs as number),
)

// Find disputable allocations
Expand Down Expand Up @@ -821,22 +823,22 @@ export class Agent {
await network.networkProvider.getBlock(
pool.previousEpochStartBlockHash!,
)
pool.closedAtEpochStartBlockNumber = closedAtEpochStartBlock.number
pool.closedAtEpochStartBlockNumber = closedAtEpochStartBlock!.number
pool.referencePOI = await this.graphNode.proofOfIndexing(
pool.subgraphDeployment,
{
number: closedAtEpochStartBlock.number,
hash: closedAtEpochStartBlock.hash,
number: closedAtEpochStartBlock!.number,
hash: closedAtEpochStartBlock!.hash!,
},
pool.allocationIndexer,
)
pool.previousEpochStartBlockHash = previousEpochStartBlock.hash
pool.previousEpochStartBlockNumber = previousEpochStartBlock.number
pool.previousEpochStartBlockHash = previousEpochStartBlock!.hash!
pool.previousEpochStartBlockNumber = previousEpochStartBlock!.number
pool.referencePreviousPOI = await this.graphNode.proofOfIndexing(
pool.subgraphDeployment,
{
number: previousEpochStartBlock.number,
hash: previousEpochStartBlock.hash,
number: previousEpochStartBlock!.number,
hash: previousEpochStartBlock!.hash!,
},
pool.allocationIndexer,
)
Expand Down Expand Up @@ -1006,13 +1008,13 @@ export class Agent {
activeAllocations: Allocation[],
deploymentAllocationDecision: AllocationDecision,
epoch: number,
maxAllocationEpochs: number,
maxAllocationEpochs: bigint,
network: Network,
): Promise<Allocation[]> {
const desiredAllocationLifetime = deploymentAllocationDecision.ruleMatch
.rule?.allocationLifetime
? deploymentAllocationDecision.ruleMatch.rule.allocationLifetime
: Math.max(1, maxAllocationEpochs - 1)
: Math.max(1, Number(maxAllocationEpochs) - 1)

// Identify expiring allocations
let expiredAllocations = activeAllocations.filter(
Expand All @@ -1028,8 +1030,8 @@ export class Agent {
async (allocation: Allocation) => {
try {
const onChainAllocation =
await network.contracts.staking.getAllocation(allocation.id)
return onChainAllocation.closedAtEpoch.eq('0')
await network.contracts.LegacyStaking.getAllocation(allocation.id)
return onChainAllocation.closedAtEpoch == 0n
} catch (err) {
this.logger.warn(
`Failed to cross-check allocation state with contracts; assuming it needs to be closed`,
Expand All @@ -1050,7 +1052,7 @@ export class Agent {
deploymentAllocationDecision: AllocationDecision,
activeAllocations: Allocation[],
epoch: number,
maxAllocationEpochs: number,
maxAllocationEpochs: bigint,
network: Network,
operator: Operator,
): Promise<void> {
Expand Down Expand Up @@ -1145,7 +1147,7 @@ export class Agent {
async reconcileActions(
networkDeploymentAllocationDecisions: NetworkMapped<AllocationDecision[]>,
epoch: NetworkMapped<number>,
maxAllocationEpochs: NetworkMapped<number>,
maxAllocationEpochs: NetworkMapped<bigint>,
): Promise<void> {
// --------------------------------------------------------------------------------
// Filter out networks set to `manual` allocation management mode, and ensure the
Expand Down
39 changes: 33 additions & 6 deletions packages/indexer-agent/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { createSyncingServer } from '../syncing-server'
import { injectCommonStartupOptions } from './common-options'
import pMap from 'p-map'
import { NetworkSpecification } from '@graphprotocol/indexer-common/dist/network-specification'
import { BigNumber } from 'ethers'
import { displayZodParsingError } from '@graphprotocol/indexer-common'
import { readFileSync } from 'fs'
import { AgentConfigs } from '../types'
Expand Down Expand Up @@ -100,6 +99,12 @@ export const start = {
default: 0,
group: 'Ethereum',
})
.option('confirmation-blocks', {
description: 'The number of blocks to wait for a transaction to be confirmed',
type: 'number',
default: 3,
group: 'Ethereum',
})
.option('mnemonic', {
description: 'Mnemonic for the operator wallet',
type: 'string',
Expand All @@ -112,6 +117,12 @@ export const start = {
required: true,
group: 'Ethereum',
})
.option('payments-destination', {
description:
'Address where payments are sent to. If not provided payments will be restaked.',
type: 'string',
group: 'Ethereum',
})
.option('public-indexer-url', {
description: 'Indexer endpoint for receiving requests from the network',
type: 'string',
Expand Down Expand Up @@ -247,8 +258,13 @@ export const start = {
default: 100,
group: 'Query Fees',
})
.option('address-book', {
description: 'Graph contracts address book file path',
.option('horizon-address-book', {
description: 'Graph Horizon contracts address book file path',
type: 'string',
required: false,
})
.option('subgraph-service-address-book', {
description: 'Subgraph Service contracts address book file path',
type: 'string',
required: false,
})
Expand All @@ -268,6 +284,13 @@ export const start = {
default: true,
group: 'Protocol',
})
.option('max-provision-initial-size', {
description:
'The maximum number of tokens for the initial Subgraph Service provision',
type: 'number',
default: 0,
group: 'Protocol',
})
.option('poi-disputable-epochs', {
description:
'The number of epochs in the past to look for potential POI disputes',
Expand Down Expand Up @@ -347,6 +370,7 @@ export async function createNetworkSpecification(

const indexerOptions = {
address: argv.indexerAddress,
paymentsDestination: argv.paymentsDestination,
mnemonic: argv.mnemonic,
url: argv.publicIndexerUrl,
geoCoordinates: argv.indexerGeoCoordinates,
Expand All @@ -364,6 +388,7 @@ export async function createNetworkSpecification(
autoAllocationMinBatchSize: argv.autoAllocationMinBatchSize,
allocateOnNetworkSubgraph: argv.allocateOnNetworkSubgraph,
register: argv.register,
maxProvisionInitialSize: argv.maxProvisionInitialSize,
finalityTime: argv.chainFinalizeTime,
}

Expand All @@ -373,6 +398,7 @@ export async function createNetworkSpecification(
gasPriceMax: argv.gasPriceMax,
baseFeePerGasMax: argv.baseFeeGasMax,
maxTransactionAttempts: argv.maxTransactionAttempts,
confirmationBlocks: argv.confirmationBlocks,
}

const subgraphs = {
Expand Down Expand Up @@ -444,8 +470,9 @@ export async function createNetworkSpecification(
transactionMonitoring,
subgraphs,
networkProvider,
addressBook: argv.addressBook,
tapAddressBook,
horizonAddressBook: argv.horizonAddressBook,
subgraphServiceAddressBook: argv.subgraphServiceAddressBook,
tapAddressBook: tapAddressBook,
})
} catch (parsingError) {
displayZodParsingError(parsingError)
Expand Down Expand Up @@ -601,7 +628,7 @@ export async function run(
defaults: {
globalIndexingRule: {
// TODO: Update this, there will be defaults per network
allocationAmount: BigNumber.from(100),
allocationAmount: BigInt(100),
parallelAllocations: 1,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Logger } from '@graphprotocol/common-ts'
import { utils } from 'ethers'
import { isHexString } from 'ethers'
import { QueryInterface, DataTypes } from 'sequelize'

interface MigrationContext {
Expand Down Expand Up @@ -45,7 +45,7 @@ export async function up({ context }: Context): Promise<void> {
throw new Error('Deployment ID must be a string')
}
// "0x..." and "global" is ok
if (utils.isHexString(value, 32) || value === COST_MODEL_GLOBAL) {
if (isHexString(value, 32) || value === COST_MODEL_GLOBAL) {
return
}

Expand Down
1 change: 1 addition & 0 deletions packages/indexer-cli/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
// The glob patterns Jest uses to detect test files
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
testPathIgnorePatterns: ['/node_modules/', '/dist/', '.yalc'],
transformIgnorePatterns: ['!node_modules/'],
testTimeout: 60000,
globals: {
__DATABASE__: {
Expand Down
6 changes: 3 additions & 3 deletions packages/indexer-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
"test:watch": "jest --watch --detectOpenHandles --verbose"
},
"dependencies": {
"@graphprotocol/common-ts": "2.0.11",
"@graphprotocol/common-ts": "3.0.1",
"@graphprotocol/indexer-common": "^0.23.5",
"@iarna/toml": "2.2.5",
"@thi.ng/iterators": "5.1.74",
"@urql/core": "3.1.0",
"chalk": "4.1.2",
"env-paths": "2.2.1",
"ethers": "5.7.0",
"ethers": "6.13.7",
"gluegun": "4.7.0",
"graphql-tag": "2.12.6",
"isomorphic-fetch": "3.0.0",
Expand All @@ -53,7 +53,7 @@
"typescript": "5.2.2"
},
"resolutions": {
"ethers": "5.7.0",
"ethers": "6.13.7",
"sequelize": "6.33.0"
},
"gitHead": "972ab96774007b2aee15b1da169d2ff4be9f9d27"
Expand Down
Loading
Loading