diff --git a/packages/node/src/indexer/api.service.ts b/packages/node/src/indexer/api.service.ts index ab772344c0..ff570d26fc 100644 --- a/packages/node/src/indexer/api.service.ts +++ b/packages/node/src/indexer/api.service.ts @@ -17,10 +17,16 @@ import { SubqueryProject } from '../configure/SubqueryProject'; import { ApiAt } from './types'; import { HttpProvider } from './x-provider/http'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { version: packageVersion } = require('../../package.json'); + const NOT_SUPPORT = (name: string) => () => { throw new Error(`${name}() is not supported`); }; +// https://github.com/polkadot-js/api/blob/12750bc83d8d7f01957896a80a7ba948ba3690b7/packages/rpc-provider/src/ws/index.ts#L43 +const RETRY_DELAY = 2_500; + const logger = getLogger('api'); @Injectable() @@ -28,7 +34,6 @@ export class ApiService implements OnApplicationShutdown { private api: ApiPromise; private currentBlockHash: string; private currentBlockNumber: number; - private currentRuntimeVersion: RuntimeVersion; private apiOption: ApiOptions; networkMeta: NetworkMetadataPayload; @@ -53,10 +58,14 @@ export class ApiService implements OnApplicationShutdown { let provider: WsProvider | HttpProvider; let throwOnConnect = false; + + const headers = { + 'User-Agent': `SubQuery-Node ${packageVersion}`, + }; if (network.endpoint.startsWith('ws')) { - provider = new WsProvider(network.endpoint); + provider = new WsProvider(network.endpoint, RETRY_DELAY, headers); } else if (network.endpoint.startsWith('http')) { - provider = new HttpProvider(network.endpoint); + provider = new HttpProvider(network.endpoint, headers); throwOnConnect = true; }