-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathstart.ts
801 lines (756 loc) · 27.7 KB
/
start.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
import path from 'path'
import axios from 'axios'
import { Argv } from 'yargs'
import { SequelizeStorage, Umzug } from 'umzug'
import {
createMetrics,
connectDatabase,
createMetricsServer,
formatGRT,
Logger,
SubgraphDeploymentID,
} from '@graphprotocol/common-ts'
import {
common_init,
createIndexerManagementClient,
createIndexerManagementServer,
defineIndexerManagementModels,
defineQueryFeeModels,
GraphNode,
indexerError,
IndexerErrorCode,
Network,
Operator,
registerIndexerErrorMetrics,
resolveChainId,
specification as spec,
} from '@graphprotocol/indexer-common'
import { Agent } from '../agent'
import { createSyncingServer } from '../syncing-server'
import { injectCommonStartupOptions } from './common-options'
import { BigNumber } from 'ethers'
import { displayZodParsingError } from '@graphprotocol/indexer-common'
import { readFileSync } from 'fs'
import { AgentConfigs } from '../types'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type AgentOptions = { [key: string]: any } & Argv['argv']
const DEFAULT_SUBGRAPH_MAX_BLOCK_DISTANCE = 1000
const SUGGESTED_SUBGRAPH_MAX_BLOCK_DISTANCE_ON_L2 =
50 + DEFAULT_SUBGRAPH_MAX_BLOCK_DISTANCE
const DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS = 5_000
// NOTE: This is run only in single-network mode
export const start = {
command: 'start',
describe: 'Start the agent',
builder: (args: Argv): Argv => {
const updatedArgs = injectCommonStartupOptions(args)
return updatedArgs
.option('network-specifications-directory', {
alias: 'dir',
description:
'Path to a directory containing network specification files',
type: 'string',
required: false,
})
.option('network-provider', {
alias: 'ethereum',
description: 'Ethereum node or provider URL',
array: false,
type: 'string',
required: true,
group: 'Ethereum',
})
.option('ethereum-polling-interval', {
description: 'Polling interval for the Ethereum provider (ms)',
type: 'number',
default: 4000,
group: 'Ethereum',
})
.option('gas-increase-timeout', {
description:
'Time (in seconds) after which transactions will be resubmitted with a higher gas price',
type: 'number',
default: 240,
group: 'Ethereum',
})
.option('gas-increase-factor', {
description:
'Factor by which gas prices are increased when resubmitting transactions',
type: 'number',
default: 1.2,
group: 'Ethereum',
})
.option('gas-price-max', {
description: 'The maximum gas price (gwei) to use for transactions',
type: 'number',
default: 100,
deprecated: true,
group: 'Ethereum',
})
.option('base-fee-per-gas-max', {
description:
'The maximum base fee per gas (gwei) to use for transactions, for legacy transactions this will be treated as the max gas price',
type: 'number',
required: false,
group: 'Ethereum',
})
.option('transaction-attempts', {
description:
'The maximum number of transaction attempts (Use 0 for unlimited)',
type: 'number',
default: 0,
group: 'Ethereum',
})
.option('mnemonic', {
description: 'Mnemonic for the operator wallet',
type: 'string',
required: true,
group: 'Ethereum',
})
.option('indexer-address', {
description: 'Ethereum address of the indexer',
type: 'string',
required: true,
group: 'Ethereum',
})
.option('public-indexer-url', {
description: 'Indexer endpoint for receiving requests from the network',
type: 'string',
required: true,
group: 'Indexer Infrastructure',
})
.options('indexer-geo-coordinates', {
description: `Coordinates describing the Indexer's location using latitude and longitude`,
type: 'string',
nargs: 2,
default: ['31.780715', '-41.179504'],
group: 'Indexer Infrastructure',
coerce: function (
coordinates: string | [string, string],
): [number, number] {
if (typeof coordinates === 'string') {
// When this value is set in an enviromnent variable, yarns passes
// it as a single string.
// Yargs should have passed 2 arguments to this functions, so we
// expect this array has two elements
return coordinates.split(' ').map(parseFloat) as [number, number]
}
// When this value is set in the command line, yargs passes it as an
// array of two strings.
return coordinates.map(parseFloat) as [number, number]
},
})
.option('network-subgraph-deployment', {
description: 'Network subgraph deployment (for local hosting)',
array: false,
type: 'string',
group: 'Network Subgraph',
})
.option('network-subgraph-endpoint', {
description: 'Endpoint to query the network subgraph from',
array: false,
type: 'string',
group: 'Network Subgraph',
})
.option('tap-subgraph-deployment', {
description: 'TAP subgraph deployment (for local hosting)',
array: false,
type: 'string',
group: 'TAP Subgraph',
})
.option('tap-subgraph-endpoint', {
description: 'Endpoint to query the tap subgraph from',
array: false,
type: 'string',
group: 'TAP Subgraph',
})
.option('allocate-on-network-subgraph', {
description: 'Whether to allocate to the network subgraph',
type: 'boolean',
default: false,
group: 'Network Subgraph',
})
.option('epoch-subgraph-deployment', {
description: 'Epoch subgraph deployment (for local hosting)',
array: false,
type: 'string',
group: 'Network Subgraph',
})
.option('epoch-subgraph-endpoint', {
description: 'Endpoint to query the epoch block oracle subgraph from',
array: false,
type: 'string',
required: true,
group: 'Protocol',
})
.option('subgraph-max-block-distance', {
description:
'How many blocks subgraphs are allowed to stay behind chain head',
type: 'number',
default: DEFAULT_SUBGRAPH_MAX_BLOCK_DISTANCE,
group: 'Protocol',
})
.option('subgraph-freshness-sleep-milliseconds', {
description:
'How long to wait before retrying subgraph query if it is not fresh',
type: 'number',
default: DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS,
group: 'Protocol',
})
.option('default-allocation-amount', {
description:
'Default amount of GRT to allocate to a subgraph deployment',
type: 'number',
default: 0.01,
required: false,
group: 'Protocol',
})
.option('restake-rewards', {
description: `Restake claimed indexer rewards, if set to 'false' rewards will be returned to the wallet`,
type: 'boolean',
default: true,
group: 'Indexer Infrastructure',
})
.option('rebate-claim-threshold', {
description: `Minimum value of rebate for a single allocation (in GRT) in order for it to be included in a batch rebate claim on-chain`,
type: 'number',
default: 1, // This value (the marginal gain of a claim in GRT), should always exceed the marginal cost of a claim (in ETH gas)
group: 'Query Fees',
})
.option('rebate-claim-batch-threshold', {
description: `Minimum total value of all rebates in an batch (in GRT) before the batch is claimed on-chain`,
type: 'number',
default: 5,
group: 'Query Fees',
})
.option('rebate-claim-max-batch-size', {
description: `Maximum number of rebates inside a batch. Upper bound is constrained by available system memory, and by the block gas limit`,
type: 'number',
default: 100,
group: 'Query Fees',
})
.option('voucher-redemption-threshold', {
description: `Minimum value of rebate for a single allocation (in GRT) in order for it to be included in a batch rebate claim on-chain`,
type: 'number',
default: 1, // This value (the marginal gain of a claim in GRT), should always exceed the marginal cost of a claim (in ETH gas)
group: 'Query Fees',
})
.option('voucher-redemption-batch-threshold', {
description: `Minimum total value of all rebates in an batch (in GRT) before the batch is claimed on-chain`,
type: 'number',
default: 5,
group: 'Query Fees',
})
.option('voucher-redemption-max-batch-size', {
description: `Maximum number of rebates inside a batch. Upper bound is constrained by available system memory, and by the block gas limit`,
type: 'number',
default: 100,
group: 'Query Fees',
})
.option('address-book', {
description: 'Graph contracts address book file path',
type: 'string',
required: false,
})
.option('tap-address-book', {
description: 'TAP contracts address book file path',
type: 'string',
required: false,
})
.option('chain-finalize-time', {
description: 'The time in seconds that the chain finalizes blocks',
type: 'number',
default: 3600,
})
.option('register', {
description: 'Whether to register the indexer on chain',
type: 'boolean',
default: true,
group: 'Protocol',
})
.option('poi-disputable-epochs', {
description:
'The number of epochs in the past to look for potential POI disputes',
type: 'number',
default: 1,
group: 'Disputes',
})
.option('poi-dispute-monitoring', {
description: 'Monitor the network for potential POI disputes',
type: 'boolean',
default: false,
group: 'Disputes',
})
.option('gateway-endpoint', {
description: 'Gateway endpoint base URL',
alias: 'collect-receipts-endpoint',
type: 'string',
array: false,
required: true,
group: 'Query Fees',
})
.option('allocation-management', {
description:
'Indexer agent allocation management automation mode (auto|manual) ',
type: 'string',
required: false,
default: 'auto',
group: 'Indexer Infrastructure',
})
.option('auto-allocation-min-batch-size', {
description: `Minimum number of allocation transactions inside a batch for auto allocation management. No obvious upperbound, with default of 1`,
type: 'number',
default: 1,
group: 'Indexer Infrastructure',
})
.option('enable-dips', {
description: 'Whether to enable Indexing Fees (DIPs)',
type: 'boolean',
default: false,
group: 'Indexing Fees ("DIPs")',
})
.option('dipper-endpoint', {
description: 'Gateway endpoint for DIPs receipts',
type: 'string',
array: false,
required: false,
group: 'Indexing Fees ("DIPs")',
})
.option('dips-allocation-amount', {
description: 'Amount of GRT to allocate for DIPs',
type: 'number',
default: 1,
required: false,
group: 'Indexing Fees ("DIPs")',
})
.check(argv => {
if (
!argv['network-subgraph-endpoint'] &&
!argv['network-subgraph-deployment']
) {
return 'At least one of --network-subgraph-endpoint and --network-subgraph-deployment must be provided'
}
if (argv['indexer-geo-coordinates']) {
const [geo1, geo2] = argv['indexer-geo-coordinates']
if (!+geo1 || !+geo2) {
return 'Invalid --indexer-geo-coordinates provided. Must be of format e.g.: 31.780715 -41.179504'
}
}
if (argv['gas-increase-timeout']) {
if (argv['gas-increase-timeout'] < 30) {
return 'Invalid --gas-increase-timeout provided. Must be at least 30 seconds'
}
}
if (argv['gas-increase-factor'] <= 1.0) {
return 'Invalid --gas-increase-factor provided. Must be > 1.0'
}
if (
!Number.isInteger(argv['rebate-claim-max-batch-size']) ||
argv['rebate-claim-max-batch-size'] <= 0
) {
return 'Invalid --rebate-claim-max-batch-size provided. Must be > 0 and an integer.'
}
if (argv['enable-dips'] && !argv['dipper-endpoint']) {
return 'Invalid --dipper-endpoint provided. Must be provided when --enable-dips is true.'
}
return true
})
},
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
handler: (_argv: any) => {},
}
export async function createNetworkSpecification(
argv: AgentOptions,
logger: Logger,
): Promise<spec.NetworkSpecification> {
const gateway = {
url: argv.gatewayEndpoint,
}
const indexerOptions = {
address: argv.indexerAddress,
mnemonic: argv.mnemonic,
url: argv.publicIndexerUrl,
geoCoordinates: argv.indexerGeoCoordinates,
restakeRewards: argv.restakeRewards,
rebateClaimThreshold: argv.rebateClaimThreshold,
rebateClaimBatchThreshold: argv.rebateClaimBatchThreshold,
rebateClaimMaxBatchSize: argv.rebateClaimMaxBatchSize,
poiDisputeMonitoring: argv.poiDisputeMonitoring,
poiDisputableEpochs: argv.poiDisputableEpochs,
defaultAllocationAmount: argv.defaultAllocationAmount,
voucherRedemptionThreshold: argv.voucherRedemptionThreshold,
voucherRedemptionBatchThreshold: argv.voucherRedemptionBatchThreshold,
voucherRedemptionMaxBatchSize: argv.voucherRedemptionMaxBatchSize,
allocationManagementMode: argv.allocationManagement,
autoAllocationMinBatchSize: argv.autoAllocationMinBatchSize,
allocateOnNetworkSubgraph: argv.allocateOnNetworkSubgraph,
register: argv.register,
finalityTime: argv.chainFinalizeTime,
enableDips: argv.enableDips,
dipperEndpoint: argv.dipperEndpoint,
dipsAllocationAmount: argv.dipsAllocationAmount,
dipsEpochsMargin: argv.dipsEpochsMargin,
}
const transactionMonitoring = {
gasIncreaseTimeout: argv.gasIncreaseTimeout,
gasIncreaseFactor: argv.gasIncreaseFactor,
gasPriceMax: argv.gasPriceMax,
baseFeePerGasMax: argv.baseFeeGasMax,
maxTransactionAttempts: argv.maxTransactionAttempts,
}
const subgraphs = {
maxBlockDistance: argv.subgraphMaxBlockDistance,
freshnessSleepMilliseconds: argv.subgraphFreshnessSleepMilliseconds,
networkSubgraph: {
deployment: argv.networkSubgraphDeployment,
url: argv.networkSubgraphEndpoint,
},
epochSubgraph: {
deployment: argv.epochSubgraphDeployment,
url: argv.epochSubgraphEndpoint,
},
tapSubgraph: {
deployment: argv.tapSubgraphDeployment,
url: argv.tapSubgraphEndpoint,
},
}
const networkProvider = {
url: argv.networkProvider,
pollingInterval: argv.ethereumPollingInterval,
}
// Since we can't infer the network identifier, we must ask the configured
// JSON RPC provider for its `chainID`.
const chainId = await fetchChainId(networkProvider.url)
const networkIdentifier = resolveChainId(chainId)
// Warn about inappropriate max block distance for subgraph threshold checks for given networks.
if (networkIdentifier.startsWith('eip155:42161')) {
// Arbitrum-One and Arbitrum-Goerli
if (
subgraphs.maxBlockDistance <= SUGGESTED_SUBGRAPH_MAX_BLOCK_DISTANCE_ON_L2
) {
logger.warn(
`Consider increasing 'subgraph-max-block-distance' for Arbitrum networks`,
{
problem:
'A low subgraph freshness threshold might cause the Agent to discard too many subgraph queries in fast-paced networks.',
hint: `Increase the 'subgraph-max-block-distance' parameter to a value that accomodates for block and indexing speeds.`,
configuredValue: subgraphs.maxBlockDistance,
},
)
}
if (
subgraphs.freshnessSleepMilliseconds <=
DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS
) {
logger.warn(
`Consider increasing 'subgraph-freshness-sleep-milliseconds' for Arbitrum networks`,
{
problem:
'A short subgraph freshness wait time might be insufficient for the subgraph to sync with fast-paced networks.',
hint: `Increase the 'subgraph-freshness-sleep-milliseconds' parameter to a value that accomodates for block and indexing speeds.`,
configuredValue: subgraphs.freshnessSleepMilliseconds,
},
)
}
}
const tapAddressBook = loadFile(argv.tapAddressBook)
try {
return spec.NetworkSpecification.parse({
networkIdentifier,
gateway,
indexerOptions,
transactionMonitoring,
subgraphs,
networkProvider,
addressBook: argv.addressBook,
tapAddressBook,
})
} catch (parsingError) {
displayZodParsingError(parsingError)
process.exit(1)
}
}
function loadFile(path: string | undefined): unknown | undefined {
const obj = path ? JSON.parse(readFileSync(path).toString()) : undefined
return obj
}
export async function run(
argv: AgentOptions,
networkSpecification: spec.NetworkSpecification,
logger: Logger,
): Promise<void> {
await common_init(logger)
// --------------------------------------------------------------------------------
// * Configure event listeners for unhandled promise rejections and uncaught
// exceptions.
// --------------------------------------------------------------------------------
process.on('unhandledRejection', err => {
logger.warn(`Unhandled promise rejection`, {
err: indexerError(IndexerErrorCode.IE035, err),
})
})
process.on('uncaughtException', err => {
logger.warn(`Uncaught exception`, {
err: indexerError(IndexerErrorCode.IE036, err),
})
})
// --------------------------------------------------------------------------------
// * Metrics Server
// --------------------------------------------------------------------------------
const metrics = createMetrics()
createMetricsServer({
logger: logger.child({ component: 'MetricsServer' }),
registry: metrics.registry,
port: argv.metricsPort,
})
// Register indexer error metrics so we can track any errors that happen
// inside the agent
registerIndexerErrorMetrics(metrics)
// --------------------------------------------------------------------------------
// * Graph Node
// ---------------------------------------------------------------- ----------------
const graphNode = new GraphNode(
logger,
argv.graphNodeAdminEndpoint,
argv.graphNodeQueryEndpoint,
argv.graphNodeStatusEndpoint,
)
// --------------------------------------------------------------------------------
// * Database - Connection
// --------------------------------------------------------------------------------
logger.info('Connect to database', {
host: argv.postgresHost,
port: argv.postgresPort,
database: argv.postgresDatabase,
poolMax: argv.postgresPoolSize,
})
const sequelize = await connectDatabase({
logging: undefined,
host: argv.postgresHost,
port: argv.postgresPort,
username: argv.postgresUsername,
password: argv.postgresPassword,
database: argv.postgresDatabase,
sslEnabled: argv.postgresSslEnabled,
poolMin: 0,
poolMax: argv.postgresPoolSize,
})
logger.info('Successfully connected to database')
// --------------------------------------------------------------------------------
// * Database - Migrations
// --------------------------------------------------------------------------------
logger.info(`Run database migrations`)
// If the application is being executed using ts-node __dirname may be in /src rather than /dist
const migrations_path = __dirname.includes('dist')
? path.join(__dirname, '..', 'db', 'migrations', '*.js')
: path.join(__dirname, '..', '..', 'dist', 'db', 'migrations', '*.js')
try {
const umzug = new Umzug({
migrations: {
glob: migrations_path,
},
context: {
queryInterface: sequelize.getQueryInterface(),
logger,
graphNodeAdminEndpoint: argv.graphNodeAdminEndpoint,
networkSpecifications: [networkSpecification],
graphNode: graphNode,
},
storage: new SequelizeStorage({ sequelize }),
logger: console,
})
const pending = await umzug.pending()
const executed = await umzug.executed()
logger.debug(`Migrations status`, { pending, executed })
await umzug.up()
} catch (err) {
logger.fatal(`Failed to run database migrations`, {
err: indexerError(IndexerErrorCode.IE001, err),
})
process.exit(1)
}
logger.info(`Successfully ran database migrations`)
// --------------------------------------------------------------------------------
// * Database - Sync Models
// --------------------------------------------------------------------------------
logger.info(`Sync database models`)
const managementModels = defineIndexerManagementModels(sequelize)
const queryFeeModels = defineQueryFeeModels(sequelize)
await sequelize.sync()
logger.info(`Successfully synced database models`)
// --------------------------------------------------------------------------------
// * Networks
// --------------------------------------------------------------------------------
logger.info('Connect to network', {
networks: networkSpecification.networkIdentifier,
})
const network = await Network.create(
logger,
networkSpecification,
managementModels,
queryFeeModels,
graphNode,
metrics,
)
// --------------------------------------------------------------------------------
// * Indexer Management (GraphQL) Server
// --------------------------------------------------------------------------------
const indexerManagementClient = await createIndexerManagementClient({
models: managementModels,
graphNode,
logger,
defaults: {
globalIndexingRule: {
// TODO: Update this, there will be defaults per network
allocationAmount: BigNumber.from(100),
parallelAllocations: 1,
},
},
network,
})
// --------------------------------------------------------------------------------
// * Indexer Management Server
// --------------------------------------------------------------------------------
logger.info('Launch indexer management API server', {
port: argv.indexerManagementPort,
})
await createIndexerManagementServer({
logger,
client: indexerManagementClient,
port: argv.indexerManagementPort,
})
logger.info(`Successfully launched indexer management API server`)
// --------------------------------------------------------------------------------
// * Syncing Server
// --------------------------------------------------------------------------------
logger.info(`Launch syncing server`)
await createSyncingServer({
logger,
networkSubgraph: network.networkSubgraph,
port: argv.syncingPort,
})
logger.info(`Successfully launched syncing server`)
// --------------------------------------------------------------------------------
// * Operator
// --------------------------------------------------------------------------------
const operator = new Operator(
logger,
indexerManagementClient,
networkSpecification,
)
// --------------------------------------------------------------------------------
// * The Agent itself
// --------------------------------------------------------------------------------
const agentConfigs: AgentConfigs = {
logger,
metrics,
graphNode,
operator,
indexerManagement: indexerManagementClient,
network,
deploymentManagement: argv.deploymentManagement,
autoMigrationSupport: argv.enableAutoMigrationSupport,
offchainSubgraphs: argv.offchainSubgraphs.map(
(s: string) => new SubgraphDeploymentID(s),
),
pollingInterval: argv.pollingInterval,
}
const agent = new Agent(agentConfigs)
await agent.start()
}
// Review CLI arguments, emit non-interrupting warnings about expected behavior.
// Perform this check immediately after parsing the command line arguments.
// Ideally, this check could be made inside yargs.check, but we can't access a Logger
// instance in that context.
export function reviewArgumentsForWarnings(argv: AgentOptions, logger: Logger) {
const {
gasIncreaseTimeout,
gasIncreaseFactor,
rebateClaimThreshold,
voucherRedemptionThreshold,
rebateClaimMaxBatchSize,
voucherRedemptionMaxBatchSize,
collectReceiptsEndpoint,
} = argv
logger.debug('Reviewing Indexer Agent configuration')
const advisedGasIncreaseTimeout = 90000
const advisedGasIncreaseFactor = 1.5
const advisedRebateClaimMaxBatchSize = 200
const advisedVoucherRedemptionMaxBatchSize = 200
if (collectReceiptsEndpoint) {
logger.warn(
"The option '--collect-receipts-endpoint' is deprecated. " +
"Please use the option '--gateway-endpoint' to inform the Gateway base URL.",
)
}
if (gasIncreaseTimeout < advisedGasIncreaseTimeout) {
logger.warn(
`Gas increase timeout is set to less than ${
gasIncreaseTimeout / 1000
} seconds. This may lead to high gas usage`,
{ gasIncreaseTimeout: gasIncreaseTimeout / 1000.0 },
)
}
if (gasIncreaseFactor > advisedGasIncreaseTimeout) {
logger.warn(
`Gas increase factor is set to > ${advisedGasIncreaseFactor}. ` +
'This may lead to high gas usage',
{ gasIncreaseFactor: gasIncreaseFactor },
)
}
if (rebateClaimThreshold < voucherRedemptionThreshold) {
logger.warn(
'Rebate single minimum claim value is less than voucher minimum redemption value, ' +
'but claims depend on redemptions',
{
voucherRedemptionThreshold: formatGRT(voucherRedemptionThreshold),
rebateClaimThreshold: formatGRT(rebateClaimThreshold),
},
)
}
if (rebateClaimThreshold === 0) {
logger.warn(
`Minimum query fee rebate value is 0 GRT, which may lead to claiming unprofitable rebates`,
)
}
if (rebateClaimMaxBatchSize > advisedRebateClaimMaxBatchSize) {
logger.warn(
`Setting the max batch size for rebate claims to more than ${advisedRebateClaimMaxBatchSize}` +
'may result in batches that are too large to fit into a block',
{ rebateClaimMaxBatchSize: rebateClaimMaxBatchSize },
)
}
if (voucherRedemptionThreshold == 0) {
logger.warn(
`Minimum voucher redemption value is 0 GRT, which may lead to redeeming unprofitable vouchers`,
)
}
if (voucherRedemptionMaxBatchSize > advisedVoucherRedemptionMaxBatchSize) {
logger.warn(
`Setting the max batch size for voucher redemptions to more than ${advisedVoucherRedemptionMaxBatchSize} ` +
'may result in batches that are too large to fit into a block',
{ voucherRedemptionMaxBatchSize: voucherRedemptionMaxBatchSize },
)
}
}
// Retrieves the network identifier in contexts where we haven't yet instantiated the JSON
// RPC Provider, which has additional and more complex dependencies.
async function fetchChainId(url: string): Promise<number> {
const payload = {
jsonrpc: '2.0',
id: 0,
method: 'eth_chainId',
}
try {
const response = await axios.post(url, payload)
if (response.status !== 200) {
throw `HTTP ${response.status}`
}
if (!response.data || !response.data.result) {
throw `Received invalid response body from provider: ${response.data}`
}
return parseInt(response.data.result, 16)
} catch (error) {
throw new Error(`Failed to fetch chainID from provider: ${error}`)
}
}