Skip to content

feat: support split address books #1119

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

Merged
merged 1 commit into from
May 22, 2025
Merged
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
14 changes: 10 additions & 4 deletions packages/indexer-agent/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,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 Down Expand Up @@ -443,8 +448,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
3 changes: 2 additions & 1 deletion packages/indexer-common/src/network-specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export const NetworkSpecification = z
transactionMonitoring: TransactionMonitoring,
subgraphs: ProtocolSubgraphs,
networkProvider: NetworkProvider,
addressBook: z.string().optional(),
horizonAddressBook: z.string().optional(),
subgraphServiceAddressBook: z.string().optional(),
tapAddressBook: TapContracts.optional(),
allocationSyncInterval: positiveNumber().default(120000),
})
Expand Down
77 changes: 58 additions & 19 deletions packages/indexer-common/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ export class Network {
deployment:
networkSubgraphDeploymentId !== undefined
? {
graphNode,
deployment: networkSubgraphDeploymentId,
}
graphNode,
deployment: networkSubgraphDeploymentId,
}
: undefined,
subgraphFreshnessChecker: networkSubgraphFreshnessChecker,
})
Expand All @@ -160,9 +160,9 @@ export class Network {
deployment:
tapSubgraphDeploymentId !== undefined
? {
graphNode,
deployment: tapSubgraphDeploymentId,
}
graphNode,
deployment: tapSubgraphDeploymentId,
}
: undefined,
endpoint: specification.subgraphs.tapSubgraph!.url,
subgraphFreshnessChecker: tapSubgraphFreshnessChecker,
Expand Down Expand Up @@ -191,7 +191,8 @@ export class Network {
wallet,
specification.networkIdentifier,
logger,
specification.addressBook,
specification.horizonAddressBook,
specification.subgraphServiceAddressBook,
)

// * -----------------------------------------------------------------------
Expand All @@ -215,9 +216,9 @@ export class Network {
deployment:
epochSubgraphDeploymentId !== undefined
? {
graphNode,
deployment: epochSubgraphDeploymentId,
}
graphNode,
deployment: epochSubgraphDeploymentId,
}
: undefined,
endpoint: specification.subgraphs.epochSubgraph.url,
subgraphFreshnessChecker: epochSubgraphFreshnessChecker,
Expand Down Expand Up @@ -556,7 +557,8 @@ async function connectToProtocolContracts(
wallet: HDNodeWallet,
networkIdentifier: string,
logger: Logger,
addressBook?: string,
horizonAddressBook?: string,
subgraphServiceAddressBook?: string
): Promise<GraphHorizonContracts & SubgraphServiceContracts> {
const numericNetworkId = parseInt(networkIdentifier.split(':')[1])

Expand All @@ -567,15 +569,17 @@ async function connectToProtocolContracts(

logger.info(`Connect to contracts`, {
network: networkIdentifier,
horizonAddressBook,
subgraphServiceAddressBook,
})

let contracts: GraphHorizonContracts & SubgraphServiceContracts
try {
const horizonContracts = connectGraphHorizon(numericNetworkId, wallet, addressBook)
const horizonContracts = connectGraphHorizon(numericNetworkId, wallet, horizonAddressBook)
const subgraphServiceContracts = connectSubgraphService(
numericNetworkId,
wallet,
addressBook,
subgraphServiceAddressBook,
)
contracts = {
...horizonContracts,
Expand All @@ -587,15 +591,50 @@ async function connectToProtocolContracts(
logger.error(errorMessage, { error, networkIdentifier, numericNetworkId })
throw new Error(`${errorMessage} Error: ${error}`)
}
logger.info(`Successfully connected to contracts`, {
curation: contracts.L2Curation.target,
disputeManager: contracts.DisputeManager.target,


// Ensure we are connected to all required contracts
const requiredContracts = [
'EpochManager',
'RewardsManager',
'HorizonStaking',
'GraphTallyCollector',
'PaymentsEscrow',
'SubgraphService',
]

// Before horizon we need the LegacyServiceRegistry contract as well
const isHorizon = await contracts.HorizonStaking.getMaxThawingPeriod()
.then((maxThawingPeriod) => maxThawingPeriod > 0)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch((_) => false)
if (!isHorizon) {
requiredContracts.push('LegacyServiceRegistry')
}

const missingContracts = requiredContracts.filter(
(contract) => !(contract in contracts),
)
if (missingContracts.length > 0) {
logger.fatal(`Missing required contracts`, {
err: indexerError(IndexerErrorCode.IE075),
missingContracts: missingContracts,
})
process.exit(1)
}


// Only list contracts that are used by the indexer
logger.info(`Successfully connected to Horizon contracts`, {
epochManager: contracts.EpochManager.target,
gns: contracts.L2GNS.target,
rewardsManager: contracts.RewardsManager.target,
serviceRegistry: contracts.LegacyServiceRegistry.target,
staking: contracts.HorizonStaking.target,
token: contracts.GraphToken.target,
graphTallyCollector: contracts.GraphTallyCollector.target,
graphPaymentsEscrow: contracts.PaymentsEscrow.target,
})
logger.info(`Successfully connected to Subgraph Service contracts`, {
...(isHorizon ? {} : { legacyServiceRegistry: contracts.LegacyServiceRegistry.target }),
subgraphService: contracts.SubgraphService.target,
})
return contracts
}
Loading