Skip to content

Commit 9fbfacc

Browse files
authored
feat: support split address books (#1119)
1 parent db6b450 commit 9fbfacc

File tree

4 files changed

+74
-24
lines changed

4 files changed

+74
-24
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@ yalc.lock
120120
.idea/
121121
.envrc
122122
.vscode
123+
124+
# local-network override mode files
125+
tap-contracts.json
126+
config/config.yaml

packages/indexer-agent/src/commands/start.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,13 @@ export const start = {
246246
default: 100,
247247
group: 'Query Fees',
248248
})
249-
.option('address-book', {
250-
description: 'Graph contracts address book file path',
249+
.option('horizon-address-book', {
250+
description: 'Graph Horizon contracts address book file path',
251+
type: 'string',
252+
required: false,
253+
})
254+
.option('subgraph-service-address-book', {
255+
description: 'Subgraph Service contracts address book file path',
251256
type: 'string',
252257
required: false,
253258
})
@@ -443,8 +448,9 @@ export async function createNetworkSpecification(
443448
transactionMonitoring,
444449
subgraphs,
445450
networkProvider,
446-
addressBook: argv.addressBook,
447-
tapAddressBook,
451+
horizonAddressBook: argv.horizonAddressBook,
452+
subgraphServiceAddressBook: argv.subgraphServiceAddressBook,
453+
tapAddressBook: tapAddressBook,
448454
})
449455
} catch (parsingError) {
450456
displayZodParsingError(parsingError)

packages/indexer-common/src/network-specification.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ export const NetworkSpecification = z
175175
transactionMonitoring: TransactionMonitoring,
176176
subgraphs: ProtocolSubgraphs,
177177
networkProvider: NetworkProvider,
178-
addressBook: z.string().optional(),
178+
horizonAddressBook: z.string().optional(),
179+
subgraphServiceAddressBook: z.string().optional(),
179180
tapAddressBook: TapContracts.optional(),
180181
allocationSyncInterval: positiveNumber().default(120000),
181182
})

packages/indexer-common/src/network.ts

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ export class Network {
134134
deployment:
135135
networkSubgraphDeploymentId !== undefined
136136
? {
137-
graphNode,
138-
deployment: networkSubgraphDeploymentId,
139-
}
137+
graphNode,
138+
deployment: networkSubgraphDeploymentId,
139+
}
140140
: undefined,
141141
subgraphFreshnessChecker: networkSubgraphFreshnessChecker,
142142
})
@@ -160,9 +160,9 @@ export class Network {
160160
deployment:
161161
tapSubgraphDeploymentId !== undefined
162162
? {
163-
graphNode,
164-
deployment: tapSubgraphDeploymentId,
165-
}
163+
graphNode,
164+
deployment: tapSubgraphDeploymentId,
165+
}
166166
: undefined,
167167
endpoint: specification.subgraphs.tapSubgraph!.url,
168168
subgraphFreshnessChecker: tapSubgraphFreshnessChecker,
@@ -191,7 +191,8 @@ export class Network {
191191
wallet,
192192
specification.networkIdentifier,
193193
logger,
194-
specification.addressBook,
194+
specification.horizonAddressBook,
195+
specification.subgraphServiceAddressBook,
195196
)
196197

197198
// * -----------------------------------------------------------------------
@@ -215,9 +216,9 @@ export class Network {
215216
deployment:
216217
epochSubgraphDeploymentId !== undefined
217218
? {
218-
graphNode,
219-
deployment: epochSubgraphDeploymentId,
220-
}
219+
graphNode,
220+
deployment: epochSubgraphDeploymentId,
221+
}
221222
: undefined,
222223
endpoint: specification.subgraphs.epochSubgraph.url,
223224
subgraphFreshnessChecker: epochSubgraphFreshnessChecker,
@@ -556,7 +557,8 @@ async function connectToProtocolContracts(
556557
wallet: HDNodeWallet,
557558
networkIdentifier: string,
558559
logger: Logger,
559-
addressBook?: string,
560+
horizonAddressBook?: string,
561+
subgraphServiceAddressBook?: string
560562
): Promise<GraphHorizonContracts & SubgraphServiceContracts> {
561563
const numericNetworkId = parseInt(networkIdentifier.split(':')[1])
562564

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

568570
logger.info(`Connect to contracts`, {
569571
network: networkIdentifier,
572+
horizonAddressBook,
573+
subgraphServiceAddressBook,
570574
})
571575

572576
let contracts: GraphHorizonContracts & SubgraphServiceContracts
573577
try {
574-
const horizonContracts = connectGraphHorizon(numericNetworkId, wallet, addressBook)
578+
const horizonContracts = connectGraphHorizon(numericNetworkId, wallet, horizonAddressBook)
575579
const subgraphServiceContracts = connectSubgraphService(
576580
numericNetworkId,
577581
wallet,
578-
addressBook,
582+
subgraphServiceAddressBook,
579583
)
580584
contracts = {
581585
...horizonContracts,
@@ -587,15 +591,50 @@ async function connectToProtocolContracts(
587591
logger.error(errorMessage, { error, networkIdentifier, numericNetworkId })
588592
throw new Error(`${errorMessage} Error: ${error}`)
589593
}
590-
logger.info(`Successfully connected to contracts`, {
591-
curation: contracts.L2Curation.target,
592-
disputeManager: contracts.DisputeManager.target,
594+
595+
596+
// Ensure we are connected to all required contracts
597+
const requiredContracts = [
598+
'EpochManager',
599+
'RewardsManager',
600+
'HorizonStaking',
601+
'GraphTallyCollector',
602+
'PaymentsEscrow',
603+
'SubgraphService',
604+
]
605+
606+
// Before horizon we need the LegacyServiceRegistry contract as well
607+
const isHorizon = await contracts.HorizonStaking.getMaxThawingPeriod()
608+
.then((maxThawingPeriod) => maxThawingPeriod > 0)
609+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
610+
.catch((_) => false)
611+
if (!isHorizon) {
612+
requiredContracts.push('LegacyServiceRegistry')
613+
}
614+
615+
const missingContracts = requiredContracts.filter(
616+
(contract) => !(contract in contracts),
617+
)
618+
if (missingContracts.length > 0) {
619+
logger.fatal(`Missing required contracts`, {
620+
err: indexerError(IndexerErrorCode.IE075),
621+
missingContracts: missingContracts,
622+
})
623+
process.exit(1)
624+
}
625+
626+
627+
// Only list contracts that are used by the indexer
628+
logger.info(`Successfully connected to Horizon contracts`, {
593629
epochManager: contracts.EpochManager.target,
594-
gns: contracts.L2GNS.target,
595630
rewardsManager: contracts.RewardsManager.target,
596-
serviceRegistry: contracts.LegacyServiceRegistry.target,
597631
staking: contracts.HorizonStaking.target,
598-
token: contracts.GraphToken.target,
632+
graphTallyCollector: contracts.GraphTallyCollector.target,
633+
graphPaymentsEscrow: contracts.PaymentsEscrow.target,
634+
})
635+
logger.info(`Successfully connected to Subgraph Service contracts`, {
636+
...(isHorizon ? {} : { legacyServiceRegistry: contracts.LegacyServiceRegistry.target }),
637+
subgraphService: contracts.SubgraphService.target,
599638
})
600639
return contracts
601640
}

0 commit comments

Comments
 (0)