@subql/node-ethereum 3.3.5 → 3.3.6-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/ethereum/api.connection.d.ts +1 -1
- package/dist/ethereum/api.connection.js +2 -2
- package/dist/ethereum/api.connection.js.map +1 -1
- package/dist/ethereum/api.ethereum.d.ts +2 -1
- package/dist/ethereum/api.ethereum.js +7 -2
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.js +1 -1
- package/dist/ethereum/api.service.ethereum.js.map +1 -1
- package/package.json +3 -2
|
@@ -10,7 +10,7 @@ export declare class EthereumApiConnection implements IApiConnectionSpecific<Eth
|
|
|
10
10
|
private fetchBlocksBatches;
|
|
11
11
|
readonly networkMeta: NetworkMetadataPayload;
|
|
12
12
|
constructor(unsafeApi: EthereumApi, fetchBlocksBatches: GetFetchFunc);
|
|
13
|
-
static create(endpoint: string, blockConfirmations: number, fetchBlocksBatches: GetFetchFunc, eventEmitter: EventEmitter2): Promise<EthereumApiConnection>;
|
|
13
|
+
static create(endpoint: string, blockConfirmations: number, fetchBlocksBatches: GetFetchFunc, eventEmitter: EventEmitter2, unfinalizedBlocks: boolean): Promise<EthereumApiConnection>;
|
|
14
14
|
safeApi(height: number): SafeEthProvider;
|
|
15
15
|
apiConnect(): Promise<void>;
|
|
16
16
|
apiDisconnect(): Promise<void>;
|
|
@@ -16,8 +16,8 @@ class EthereumApiConnection {
|
|
|
16
16
|
genesisHash: unsafeApi.getGenesisHash(),
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
static async create(endpoint, blockConfirmations, fetchBlocksBatches, eventEmitter) {
|
|
20
|
-
const api = new api_ethereum_1.EthereumApi(endpoint, blockConfirmations, eventEmitter);
|
|
19
|
+
static async create(endpoint, blockConfirmations, fetchBlocksBatches, eventEmitter, unfinalizedBlocks) {
|
|
20
|
+
const api = new api_ethereum_1.EthereumApi(endpoint, blockConfirmations, eventEmitter, unfinalizedBlocks);
|
|
21
21
|
await api.init();
|
|
22
22
|
return new EthereumApiConnection(api, fetchBlocksBatches);
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/ethereum/api.connection.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,gDAS0B;AAE1B,iDAA6C;AAU7C,MAAa,qBAAqB;IAUhC,YACS,SAAsB,EACrB,kBAAgC;QADjC,cAAS,GAAT,SAAS,CAAa;QACrB,uBAAkB,GAAlB,kBAAkB,CAAc;
|
|
1
|
+
{"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/ethereum/api.connection.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,gDAS0B;AAE1B,iDAA6C;AAU7C,MAAa,qBAAqB;IAUhC,YACS,SAAsB,EACrB,kBAAgC;QADjC,cAAS,GAAT,SAAS,CAAa;QACrB,uBAAkB,GAAlB,kBAAkB,CAAc;QA+C1C,gBAAW,GAAG,qBAAqB,CAAC,WAAW,CAAC;QA7C9C,IAAI,CAAC,WAAW,GAAG;YACjB,KAAK,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE;YACxC,QAAQ,EAAE,SAAS,CAAC,WAAW,EAAE;YACjC,WAAW,EAAE,SAAS,CAAC,cAAc,EAAE;SACxC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,QAAgB,EAChB,kBAA0B,EAC1B,kBAAgC,EAChC,YAA2B,EAC3B,iBAA0B;QAE1B,MAAM,GAAG,GAAG,IAAI,0BAAW,CACzB,QAAQ,EACR,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,CAClB,CAAC;QAEF,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAEjB,OAAO,IAAI,qBAAqB,CAAC,GAAG,EAAE,k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sDAgFC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiConnectionError,\n ApiErrorType,\n DisconnectionError,\n LargeResponseError,\n NetworkMetadataPayload,\n RateLimitError,\n TimeoutError,\n IApiConnectionSpecific,\n} from '@subql/node-core';\nimport { EthereumBlock, LightEthereumBlock } from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport SafeEthProvider from './safe-api';\n\nexport type FetchFunc =\n | ((api: EthereumApi, batch: number[]) => Promise<EthereumBlock[]>)\n | ((api: EthereumApi, batch: number[]) => Promise<LightEthereumBlock[]>);\n\n// We use a function to get the fetch function because it can change depending on the skipBlocks feature\nexport type GetFetchFunc = () => FetchFunc;\n\nexport class EthereumApiConnection\n implements\n IApiConnectionSpecific<\n EthereumApi,\n SafeEthProvider,\n EthereumBlock[] | LightEthereumBlock[]\n >\n{\n readonly networkMeta: NetworkMetadataPayload;\n\n constructor(\n public unsafeApi: EthereumApi,\n private fetchBlocksBatches: GetFetchFunc,\n ) {\n this.networkMeta = {\n chain: unsafeApi.getChainId().toString(),\n specName: unsafeApi.getSpecName(),\n genesisHash: unsafeApi.getGenesisHash(),\n };\n }\n\n static async create(\n endpoint: string,\n blockConfirmations: number,\n fetchBlocksBatches: GetFetchFunc,\n eventEmitter: EventEmitter2,\n unfinalizedBlocks: boolean,\n ): Promise<EthereumApiConnection> {\n const api = new EthereumApi(\n endpoint,\n blockConfirmations,\n eventEmitter,\n unfinalizedBlocks,\n );\n\n await api.init();\n\n return new EthereumApiConnection(api, fetchBlocksBatches);\n }\n\n safeApi(height: number): SafeEthProvider {\n throw new Error(`Not Implemented`);\n }\n\n async apiConnect(): Promise<void> {\n await this.unsafeApi.connect();\n }\n\n async apiDisconnect(): Promise<void> {\n await this.unsafeApi.disconnect();\n }\n\n async fetchBlocks(\n heights: number[],\n ): Promise<EthereumBlock[] | LightEthereumBlock[]> {\n const blocks = await this.fetchBlocksBatches()(this.unsafeApi, heights);\n return blocks;\n }\n\n handleError = EthereumApiConnection.handleError;\n\n static handleError(e: Error): ApiConnectionError {\n let formatted_error: ApiConnectionError;\n if (e.message.startsWith(`No response received from RPC endpoint in`)) {\n formatted_error = new TimeoutError(e);\n } else if (e.message.startsWith(`disconnected from `)) {\n formatted_error = new DisconnectionError(e);\n } else if (e.message.startsWith(`Rate Limited at endpoint`)) {\n formatted_error = new RateLimitError(e);\n } else if (e.message.includes(`Exceeded max limit of`)) {\n formatted_error = new LargeResponseError(e);\n } else {\n formatted_error = new ApiConnectionError(\n e.name,\n e.message,\n ApiErrorType.Default,\n );\n }\n return formatted_error;\n }\n}\n"]}
|
|
@@ -6,6 +6,7 @@ export declare class EthereumApi implements ApiWrapper {
|
|
|
6
6
|
private endpoint;
|
|
7
7
|
private blockConfirmations;
|
|
8
8
|
private eventEmitter;
|
|
9
|
+
private unfinalizedBlocks;
|
|
9
10
|
private client;
|
|
10
11
|
private nonBatchClient?;
|
|
11
12
|
private genesisBlock;
|
|
@@ -18,7 +19,7 @@ export declare class EthereumApi implements ApiWrapper {
|
|
|
18
19
|
* @param {number} blockConfirmations - Used to determine how many blocks behind the head a block is considered finalized. Not used if the network has a concrete finalization mechanism.
|
|
19
20
|
* @param {object} eventEmitter - Used to monitor the number of RPC requests
|
|
20
21
|
*/
|
|
21
|
-
constructor(endpoint: string, blockConfirmations: number, eventEmitter: EventEmitter2);
|
|
22
|
+
constructor(endpoint: string, blockConfirmations: number, eventEmitter: EventEmitter2, unfinalizedBlocks?: boolean);
|
|
22
23
|
init(): Promise<void>;
|
|
23
24
|
private getSupportsTag;
|
|
24
25
|
private injectClient;
|
|
@@ -63,10 +63,11 @@ class EthereumApi {
|
|
|
63
63
|
* @param {number} blockConfirmations - Used to determine how many blocks behind the head a block is considered finalized. Not used if the network has a concrete finalization mechanism.
|
|
64
64
|
* @param {object} eventEmitter - Used to monitor the number of RPC requests
|
|
65
65
|
*/
|
|
66
|
-
constructor(endpoint, blockConfirmations, eventEmitter) {
|
|
66
|
+
constructor(endpoint, blockConfirmations, eventEmitter, unfinalizedBlocks = false) {
|
|
67
67
|
this.endpoint = endpoint;
|
|
68
68
|
this.blockConfirmations = blockConfirmations;
|
|
69
69
|
this.eventEmitter = eventEmitter;
|
|
70
|
+
this.unfinalizedBlocks = unfinalizedBlocks;
|
|
70
71
|
this.contractInterfaces = {};
|
|
71
72
|
// Ethereum POS
|
|
72
73
|
this.supportsFinalization = true;
|
|
@@ -169,7 +170,11 @@ class EthereumApi {
|
|
|
169
170
|
}
|
|
170
171
|
async getBestBlockHeight() {
|
|
171
172
|
// Cronos "safe" tag doesn't currently work as indended
|
|
172
|
-
const tag = this.
|
|
173
|
+
const tag = !this.unfinalizedBlocks &&
|
|
174
|
+
this.supportsFinalization &&
|
|
175
|
+
this.chainId !== 25
|
|
176
|
+
? 'safe'
|
|
177
|
+
: 'latest';
|
|
173
178
|
return (await this.client.getBlock(tag)).number;
|
|
174
179
|
}
|
|
175
180
|
getRuntimeChain() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,4CAA+C;AAO/C,wDAA6D;AAE7D,gDAAsD;AAWtD,wEAA+C;AAC/C,4CAA0D;AAC1D,8CAAkD;AAClD,6FAAsF;AACtF,iFAA2E;AAC3E,qEAAgE;AAChE,8EAAwE;AACxE,kEAA6D;AAE7D,0DAAyC;AACzC,qDAK0B;AAE1B,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,cAAc,CAAC,CAAC;AAEzC,KAAK,UA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D,CAAyC,CAAC;YAE7C,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC;YAExB,OAAO,WAAW,CAAC;SACpB;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO;QACX,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,MAAM,YAAY,6BAAiB,EAAE;YAC5C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;SACnD;IACH,CAAC;IAED,WAAW,CAAC,CAAQ;QAClB,IAAI,CAAC,CAAS,aAAT,CAAC,uBAAD,CAAC,CAAU,MAAM,MAAK,GAAG,EAAE;YAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5C,OAAO,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;SAC3D;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AApWD,kCAoWC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n BlockTag,\n Provider,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n LightEthereumBlock,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { CeloJsonRpcBatchProvider } from './ethers/celo/celo-json-rpc-batch-provider';\nimport { CeloJsonRpcProvider } from './ethers/celo/celo-json-rpc-provider';\nimport { CeloWsProvider } from './ethers/celo/celo-ws-provider';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: SubqlRuntimeDatasource,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nfunction getHttpAgents() {\n // By default Nodejs doesn't cache DNS lookups\n // https://httptoolkit.com/blog/configuring-nodejs-dns/\n const lookup = new CacheableLookup();\n\n const options: http.AgentOptions = {\n keepAlive: true,\n /*, maxSockets: 100*/\n };\n\n const httpAgent = new http.Agent(options);\n const httpsAgent = new https.Agent(options);\n\n lookup.install(httpAgent);\n lookup.install(httpsAgent);\n\n return {\n http: httpAgent,\n https: httpsAgent,\n };\n}\n\nexport class EthereumApi implements ApiWrapper {\n private client: JsonRpcProvider;\n\n // This is used within the sandbox when HTTP is used\n private nonBatchClient?: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n private name: string;\n\n // Ethereum POS\n private supportsFinalization = true;\n\n /**\n * @param {string} endpoint - The endpoint of the RPC provider\n * @param {number} blockConfirmations - Used to determine how many blocks behind the head a block is considered finalized. Not used if the network has a concrete finalization mechanism.\n * @param {object} eventEmitter - Used to monitor the number of RPC requests\n */\n constructor(\n private endpoint: string,\n private blockConfirmations: number,\n private eventEmitter: EventEmitter2,\n ) {\n const { hostname, protocol, searchParams } = new URL(endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: getHttpAgents(),\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n this.nonBatchClient = new JsonRpcProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.injectClient();\n\n const network = await this.client.getNetwork();\n\n //celo\n if (network.chainId === 42220) {\n if (this.client instanceof WebSocketProvider) {\n this.client = new CeloWsProvider(this.client.connection.url);\n } else {\n this.client = new CeloJsonRpcBatchProvider(this.client.connection);\n this.nonBatchClient = new CeloJsonRpcProvider(this.client.connection);\n }\n }\n\n try {\n const [genesisBlock, supportsFinalization, supportsSafe] =\n await Promise.all([\n this.client.getBlock('earliest'),\n this.getSupportsTag('finalized'),\n this.getSupportsTag('safe'),\n ]);\n\n this.genesisBlock = genesisBlock;\n this.supportsFinalization = supportsFinalization && supportsSafe;\n this.chainId = network.chainId;\n this.name = network.name;\n } catch (e) {\n if ((e as Error).message.startsWith('Invalid response')) {\n this.client = this.nonBatchClient;\n\n logger.warn(\n `The RPC Node at ${this.endpoint} cannot process batch requests. ` +\n `Switching to non-batch mode for subsequent requests. Please consider checking if batch processing is supported on the RPC node.`,\n );\n\n return this.init();\n }\n\n throw e;\n }\n }\n\n private async getSupportsTag(tag: BlockTag): Promise<boolean> {\n try {\n // We set the timeout here because theres a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n const result = await timeout(this.client.getBlock(tag), 2);\n\n return true;\n } catch (e) {\n logger.info(`Chain doesnt support ${tag} tag`);\n return false;\n }\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n\n const block = await this.client.getBlock(height);\n // The finalized block could sometimes fail to fetch,\n // due to some nodes on the network falling behind the synced node.\n if (!block) {\n throw new Error(`get finalized block \"${height}\" failed `);\n }\n return block;\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n // Cronos \"safe\" tag doesn't currently work as indended\n const tag =\n this.supportsFinalization && this.chainId !== 25 ? 'safe' : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n if (!rawBlock) {\n throw new Error(`Failed to fetch block ${num}`);\n }\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n\n async fetchBlock(blockNumber: number): Promise<EthereumBlock> {\n try {\n const block = await this.getBlockPromise(blockNumber, true);\n const logsRaw = await this.client.getLogs({ blockHash: block.hash });\n\n block.logs = logsRaw.map((l) => formatLog(l, block));\n block.transactions = block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) =>\n formatReceipt(r, block),\n ),\n logs: block.logs.filter((l) => l.transactionHash === tx.hash),\n }));\n\n this.eventEmitter.emit('fetchBlock');\n return block;\n } catch (e) {\n throw this.handleError(e);\n }\n }\n\n private async fetchLightBlock(\n blockNumber: number,\n ): Promise<LightEthereumBlock> {\n const block = await this.getBlockPromise(blockNumber, false);\n const logs = await this.client.getLogs({ blockHash: block.hash });\n\n return {\n ...block,\n logs: logs.map((l) => formatLog(l, block)),\n };\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlock[]> {\n return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num)));\n }\n\n async fetchBlocksLight(\n bufferBlocks: number[],\n ): Promise<LightEthereumBlock[]> {\n console.log('FETCH BLOCKS LIGHT');\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchLightBlock(num)),\n );\n }\n\n get api(): Provider {\n return this.client;\n }\n\n getSafeApi(blockHeight: number): SafeEthProvider {\n // We cannot use a batch http client because OnF don't support routing historical queries in batches to an archive nodes\n const client =\n this.client instanceof WebSocketProvider\n ? this.client\n : this.nonBatchClient;\n\n return new SafeEthProvider(client, blockHeight);\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog | LightEthereumLog,\n ds: SubqlRuntimeDatasource,\n ): Promise<\n EthereumLog | LightEthereumLog | EthereumLog<T> | LightEthereumLog<T>\n > {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n\n log.args = iface?.parseLog(log).args as T;\n\n return log;\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: SubqlRuntimeDatasource,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n\n transaction.logs =\n transaction.logs &&\n ((await Promise.all(\n transaction.logs.map(async (log) => this.parseLog(log, ds)),\n )) as Array<EthereumLog | EthereumLog<T>>);\n\n transaction.args = args;\n\n return transaction;\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Ethereum API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n async disconnect(): Promise<void> {\n if (this.client instanceof WebSocketProvider) {\n await this.client.destroy();\n } else {\n logger.warn('Disconnect called on HTTP provider');\n }\n }\n\n handleError(e: Error): Error {\n if ((e as any)?.status === 429) {\n const { hostname } = new URL(this.endpoint);\n return new Error(`Rate Limited at endpoint: ${hostname}`);\n }\n\n return e;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,4CAA+C;AAO/C,wDAA6D;AAE7D,gDAAsD;AAWtD,wEAA+C;AAC/C,4CAA0D;AAC1D,8CAAkD;AAClD,6FAAsF;AACtF,iFAA2E;AAC3E,qEAAgE;AAChE,8EAAwE;AACxE,kEAA6D;AAE7D,0DAAyC;AACzC,qDAK0B;AAE1B,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,cAAc,CAAC,CAAC;AAEzC,KAAK,UAAU,UAAU,CACvB,EAA0B;IAE1B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE;QACd,OAAO,EAAE,CAAC;KACX;IACD,MAAM,GAAG,GAA2B,EAAE,CAAC;IAEvC,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE;QACxD,IAAI;YACF,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,Y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B;IACH,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO;QACX,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,MAAM,YAAY,6BAAiB,EAAE;YAC5C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;SACnD;IACH,CAAC;IAED,WAAW,CAAC,CAAQ;QAClB,IAAI,CAAC,CAAS,aAAT,CAAC,uBAAD,CAAC,CAAU,MAAM,MAAK,GAAG,EAAE;YAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5C,OAAO,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;SAC3D;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAzWD,kCAyWC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n BlockTag,\n Provider,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n LightEthereumBlock,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { CeloJsonRpcBatchProvider } from './ethers/celo/celo-json-rpc-batch-provider';\nimport { CeloJsonRpcProvider } from './ethers/celo/celo-json-rpc-provider';\nimport { CeloWsProvider } from './ethers/celo/celo-ws-provider';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: SubqlRuntimeDatasource,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nfunction getHttpAgents() {\n // By default Nodejs doesn't cache DNS lookups\n // https://httptoolkit.com/blog/configuring-nodejs-dns/\n const lookup = new CacheableLookup();\n\n const options: http.AgentOptions = {\n keepAlive: true,\n /*, maxSockets: 100*/\n };\n\n const httpAgent = new http.Agent(options);\n const httpsAgent = new https.Agent(options);\n\n lookup.install(httpAgent);\n lookup.install(httpsAgent);\n\n return {\n http: httpAgent,\n https: httpsAgent,\n };\n}\n\nexport class EthereumApi implements ApiWrapper {\n private client: JsonRpcProvider;\n\n // This is used within the sandbox when HTTP is used\n private nonBatchClient?: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n private name: string;\n\n // Ethereum POS\n private supportsFinalization = true;\n\n /**\n * @param {string} endpoint - The endpoint of the RPC provider\n * @param {number} blockConfirmations - Used to determine how many blocks behind the head a block is considered finalized. Not used if the network has a concrete finalization mechanism.\n * @param {object} eventEmitter - Used to monitor the number of RPC requests\n */\n constructor(\n private endpoint: string,\n private blockConfirmations: number,\n private eventEmitter: EventEmitter2,\n private unfinalizedBlocks = false,\n ) {\n const { hostname, protocol, searchParams } = new URL(endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: getHttpAgents(),\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n this.nonBatchClient = new JsonRpcProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.injectClient();\n\n const network = await this.client.getNetwork();\n\n //celo\n if (network.chainId === 42220) {\n if (this.client instanceof WebSocketProvider) {\n this.client = new CeloWsProvider(this.client.connection.url);\n } else {\n this.client = new CeloJsonRpcBatchProvider(this.client.connection);\n this.nonBatchClient = new CeloJsonRpcProvider(this.client.connection);\n }\n }\n\n try {\n const [genesisBlock, supportsFinalization, supportsSafe] =\n await Promise.all([\n this.client.getBlock('earliest'),\n this.getSupportsTag('finalized'),\n this.getSupportsTag('safe'),\n ]);\n\n this.genesisBlock = genesisBlock;\n this.supportsFinalization = supportsFinalization && supportsSafe;\n this.chainId = network.chainId;\n this.name = network.name;\n } catch (e) {\n if ((e as Error).message.startsWith('Invalid response')) {\n this.client = this.nonBatchClient;\n\n logger.warn(\n `The RPC Node at ${this.endpoint} cannot process batch requests. ` +\n `Switching to non-batch mode for subsequent requests. Please consider checking if batch processing is supported on the RPC node.`,\n );\n\n return this.init();\n }\n\n throw e;\n }\n }\n\n private async getSupportsTag(tag: BlockTag): Promise<boolean> {\n try {\n // We set the timeout here because theres a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n const result = await timeout(this.client.getBlock(tag), 2);\n\n return true;\n } catch (e) {\n logger.info(`Chain doesnt support ${tag} tag`);\n return false;\n }\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n\n const block = await this.client.getBlock(height);\n // The finalized block could sometimes fail to fetch,\n // due to some nodes on the network falling behind the synced node.\n if (!block) {\n throw new Error(`get finalized block \"${height}\" failed `);\n }\n return block;\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n // Cronos \"safe\" tag doesn't currently work as indended\n const tag =\n !this.unfinalizedBlocks &&\n this.supportsFinalization &&\n this.chainId !== 25\n ? 'safe'\n : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n if (!rawBlock) {\n throw new Error(`Failed to fetch block ${num}`);\n }\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n\n async fetchBlock(blockNumber: number): Promise<EthereumBlock> {\n try {\n const block = await this.getBlockPromise(blockNumber, true);\n const logsRaw = await this.client.getLogs({ blockHash: block.hash });\n\n block.logs = logsRaw.map((l) => formatLog(l, block));\n block.transactions = block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) =>\n formatReceipt(r, block),\n ),\n logs: block.logs.filter((l) => l.transactionHash === tx.hash),\n }));\n\n this.eventEmitter.emit('fetchBlock');\n return block;\n } catch (e) {\n throw this.handleError(e);\n }\n }\n\n private async fetchLightBlock(\n blockNumber: number,\n ): Promise<LightEthereumBlock> {\n const block = await this.getBlockPromise(blockNumber, false);\n const logs = await this.client.getLogs({ blockHash: block.hash });\n\n return {\n ...block,\n logs: logs.map((l) => formatLog(l, block)),\n };\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlock[]> {\n return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num)));\n }\n\n async fetchBlocksLight(\n bufferBlocks: number[],\n ): Promise<LightEthereumBlock[]> {\n console.log('FETCH BLOCKS LIGHT');\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchLightBlock(num)),\n );\n }\n\n get api(): Provider {\n return this.client;\n }\n\n getSafeApi(blockHeight: number): SafeEthProvider {\n // We cannot use a batch http client because OnF don't support routing historical queries in batches to an archive nodes\n const client =\n this.client instanceof WebSocketProvider\n ? this.client\n : this.nonBatchClient;\n\n return new SafeEthProvider(client, blockHeight);\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog | LightEthereumLog,\n ds: SubqlRuntimeDatasource,\n ): Promise<\n EthereumLog | LightEthereumLog | EthereumLog<T> | LightEthereumLog<T>\n > {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n\n log.args = iface?.parseLog(log).args as T;\n\n return log;\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: SubqlRuntimeDatasource,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n\n transaction.logs =\n transaction.logs &&\n ((await Promise.all(\n transaction.logs.map(async (log) => this.parseLog(log, ds)),\n )) as Array<EthereumLog | EthereumLog<T>>);\n\n transaction.args = args;\n\n return transaction;\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Ethereum API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n async disconnect(): Promise<void> {\n if (this.client instanceof WebSocketProvider) {\n await this.client.destroy();\n } else {\n logger.warn('Disconnect called on HTTP provider');\n }\n }\n\n handleError(e: Error): Error {\n if ((e as any)?.status === 429) {\n const { hostname } = new URL(this.endpoint);\n return new Error(`Rate Limited at endpoint: ${hostname}`);\n }\n\n return e;\n }\n}\n"]}
|
|
@@ -46,7 +46,7 @@ let EthereumApiService = class EthereumApiService extends node_core_1.ApiService
|
|
|
46
46
|
if (this.nodeConfig.primaryNetworkEndpoint) {
|
|
47
47
|
endpoints.push(this.nodeConfig.primaryNetworkEndpoint);
|
|
48
48
|
}
|
|
49
|
-
await this.createConnections(network, (endpoint) => api_connection_1.EthereumApiConnection.create(endpoint, this.nodeConfig.blockConfirmations, this.fetchBlocksBatches, this.eventEmitter),
|
|
49
|
+
await this.createConnections(network, (endpoint) => api_connection_1.EthereumApiConnection.create(endpoint, this.nodeConfig.blockConfirmations, this.fetchBlocksBatches, this.eventEmitter, this.nodeConfig.unfinalizedBlocks),
|
|
50
50
|
//eslint-disable-next-line @typescript-eslint/require-await
|
|
51
51
|
async (connection) => {
|
|
52
52
|
const api = connection.unsafeApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.service.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AACtD,gDAM0B;AAE1B,wDAA6D;AAC7D,kEAA+D;AAC/D,8CAAuD;AACvD,qDAI0B;AAI1B,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,sBAIvC;IAKC,YACsC,OAAwB,EAC5D,qBAAmE,EACnE,YAA2B,EAC3B,UAAsB;QAEtB,KAAK,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;QALP,YA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,CAAC;YACvC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,QAAQ,EAAE;YAC7B,IAAI,CAAC,mBAAmB,GAAG,IAAA,wBAAY,EACrC,SAAS,EACT,eAAe,EACf,oBAAoB,CACrB,CAAC;SACH;aAAM;YACL,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;CACF,CAAA;AAnLY,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAWR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAAkB,iCAAe;QACrC,iCAAqB;QAC9B,6BAAa;QACf,sBAAU;GAbb,kBAAkB,CAmL9B;AAnLY,gDAAkB","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n NodeConfig,\n profilerWrap,\n} from '@subql/node-core';\nimport { EthereumBlock, EthereumNetworkConfig, LightEthereumBlock } from '@subql/types-ethereum';\nimport { EthereumNodeConfig } from '../configure/NodeConfig';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { isOnlyEventHandlers } from '../utils/project';\nimport {\n EthereumApiConnection,\n FetchFunc,\n GetFetchFunc,\n} from './api.connection';\nimport { EthereumApi } from './api.ethereum';\nimport SafeEthProvider from './safe-api';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class EthereumApiService extends ApiService<\n EthereumApi,\n SafeEthProvider,\n EthereumBlock[] | LightEthereumBlock[]\n> {\n private fetchBlocksFunction: FetchFunc;\n private fetchBlocksBatches: GetFetchFunc = () => this.fetchBlocksFunction;\n private nodeConfig: EthereumNodeConfig;\n\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<EthereumApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) {\n super(connectionPoolService, eventEmitter);\n this.nodeConfig = new EthereumNodeConfig(nodeConfig);\n\n this.updateBlockFetching();\n }\n\n async init(): Promise<EthereumApiService> {\n let network: EthereumNetworkConfig;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n const endpoints = Array.isArray(network.endpoint)\n ? network.endpoint\n : [network.endpoint];\n\n if (this.nodeConfig.primaryNetworkEndpoint) {\n endpoints.push(this.nodeConfig.primaryNetworkEndpoint);\n }\n\n await this.createConnections(\n network,\n (endpoint) =>\n EthereumApiConnection.create(\n endpoint,\n this.nodeConfig.blockConfirmations,\n this.fetchBlocksBatches,\n this.eventEmitter,\n ),\n //eslint-disable-next-line @typescript-eslint/require-await\n async (connection: EthereumApiConnection) => {\n const api = connection.unsafeApi;\n return api.getChainId().toString();\n },\n );\n\n return this;\n }\n\n protected metadataMismatchError(\n metadata: string,\n expected: string,\n actual: string,\n ): Error {\n return Error(\n `Value of ${metadata} does not match across all endpoints. Please check that your endpoints are for the same network.\\n\n Expected: ${expected}\n Actual: ${actual}`,\n );\n }\n\n get api(): EthereumApi {\n return this.unsafeApi;\n }\n\n safeApi(height: number): SafeEthProvider {\n const maxRetries = 5;\n\n const retryErrorCodes = [\n 'UNKNOWN_ERROR',\n 'NOT_IMPLEMENTED',\n 'NETWORK_ERROR',\n 'SERVER_ERROR',\n 'TIMEOUT',\n 'BAD_DATA',\n 'CANCELLED',\n ];\n\n const handler: ProxyHandler<SafeEthProvider> = {\n get: (target, prop, receiver) => {\n const originalMethod = target[prop as keyof SafeEthProvider];\n if (typeof originalMethod === 'function') {\n return async (...args: any[]) => {\n let retries = 0;\n let currentApi = target;\n let throwingError: Error;\n\n while (retries < maxRetries) {\n try {\n return await originalMethod.apply(currentApi, args);\n } catch (error: any) {\n // other than retryErrorCodes, other errors does not have anything to do with network request, retrying would not change its outcome\n if (!retryErrorCodes.includes(error?.code)) {\n throw error;\n }\n\n logger.warn(\n `Request failed with api at height ${height} (retry ${retries}): ${error.message}`,\n );\n throwingError = error;\n currentApi = this.unsafeApi.getSafeApi(height);\n retries++;\n }\n }\n\n logger.error(\n `Maximum retries (${maxRetries}) exceeded for api at height ${height}`,\n );\n throw throwingError;\n };\n }\n return Reflect.get(target, prop, receiver);\n },\n };\n\n return new Proxy(this.unsafeApi.getSafeApi(height), handler);\n }\n\n private async fetchFullBlocksBatch(\n api: EthereumApi,\n batch: number[],\n ): Promise<EthereumBlock[]> {\n return api.fetchBlocks(batch);\n }\n\n private async fetchLightBlocksBatch(\n api: EthereumApi,\n batch: number[],\n ): Promise<LightEthereumBlock[]> {\n return api.fetchBlocksLight(batch);\n }\n\n updateBlockFetching(): void {\n const onlyEventHandlers = isOnlyEventHandlers(this.project);\n const skipTransactions =\n this.nodeConfig.skipTransactions && onlyEventHandlers;\n\n if (this.nodeConfig.skipTransactions) {\n if (onlyEventHandlers) {\n logger.info(\n 'skipTransactions is enabled, only events and block headers will be fetched.',\n );\n } else {\n logger.info(\n `skipTransactions is disabled, the project contains handlers that aren't event handlers.`,\n );\n }\n } else {\n if (onlyEventHandlers) {\n logger.warn(\n 'skipTransactions is disabled, the project contains only event handlers, it could be enabled to improve indexing performance.',\n );\n } else {\n logger.info(`skipTransactions is disabled.`);\n }\n }\n\n const fetchFunc = skipTransactions\n ? this.fetchLightBlocksBatch.bind(this)\n : this.fetchFullBlocksBatch.bind(this);\n\n if (this.nodeConfig?.profiler) {\n this.fetchBlocksFunction = profilerWrap(\n fetchFunc,\n 'SubstrateUtil',\n 'fetchBlocksBatches',\n );\n } else {\n this.fetchBlocksFunction = fetchFunc;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.service.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;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,iBAAiB,EAAE;gBACrB,MAAM,CAAC,IAAI,CACT,6EAA6E,CAC9E,CAAC;aACH;iBAAM;gBACL,MAAM,CAAC,IAAI,CACT,yFAAyF,CAC1F,CAAC;aACH;SACF;aAAM;YACL,IAAI,iBAAiB,EAAE;gBACrB,MAAM,CAAC,IAAI,CACT,8HAA8H,CAC/H,CAAC;aACH;iBAAM;gBACL,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;aAC9C;SACF;QAED,MAAM,SAAS,GAAG,gBAAgB;YAChC,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;YACvC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,QAAQ,EAAE;YAC7B,IAAI,CAAC,mBAAmB,GAAG,IAAA,wBAAY,EACrC,SAAS,EACT,eAAe,EACf,oBAAoB,CACrB,CAAC;SACH;aAAM;YACL,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;CACF,CAAA;AApLY,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAWR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAAkB,iCAAe;QACrC,iCAAqB;QAC9B,6BAAa;QACf,sBAAU;GAbb,kBAAkB,CAoL9B;AApLY,gDAAkB","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n NodeConfig,\n profilerWrap,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumNetworkConfig,\n LightEthereumBlock,\n} from '@subql/types-ethereum';\nimport { EthereumNodeConfig } from '../configure/NodeConfig';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { isOnlyEventHandlers } from '../utils/project';\nimport {\n EthereumApiConnection,\n FetchFunc,\n GetFetchFunc,\n} from './api.connection';\nimport { EthereumApi } from './api.ethereum';\nimport SafeEthProvider from './safe-api';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class EthereumApiService extends ApiService<\n EthereumApi,\n SafeEthProvider,\n EthereumBlock[] | LightEthereumBlock[]\n> {\n private fetchBlocksFunction: FetchFunc;\n private fetchBlocksBatches: GetFetchFunc = () => this.fetchBlocksFunction;\n private nodeConfig: EthereumNodeConfig;\n\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<EthereumApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) {\n super(connectionPoolService, eventEmitter);\n this.nodeConfig = new EthereumNodeConfig(nodeConfig);\n\n this.updateBlockFetching();\n }\n\n async init(): Promise<EthereumApiService> {\n let network: EthereumNetworkConfig;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n const endpoints = Array.isArray(network.endpoint)\n ? network.endpoint\n : [network.endpoint];\n\n if (this.nodeConfig.primaryNetworkEndpoint) {\n endpoints.push(this.nodeConfig.primaryNetworkEndpoint);\n }\n\n await this.createConnections(\n network,\n (endpoint) =>\n EthereumApiConnection.create(\n endpoint,\n this.nodeConfig.blockConfirmations,\n this.fetchBlocksBatches,\n this.eventEmitter,\n this.nodeConfig.unfinalizedBlocks,\n ),\n //eslint-disable-next-line @typescript-eslint/require-await\n async (connection: EthereumApiConnection) => {\n const api = connection.unsafeApi;\n return api.getChainId().toString();\n },\n );\n\n return this;\n }\n\n protected metadataMismatchError(\n metadata: string,\n expected: string,\n actual: string,\n ): Error {\n return Error(\n `Value of ${metadata} does not match across all endpoints. Please check that your endpoints are for the same network.\\n\n Expected: ${expected}\n Actual: ${actual}`,\n );\n }\n\n get api(): EthereumApi {\n return this.unsafeApi;\n }\n\n safeApi(height: number): SafeEthProvider {\n const maxRetries = 5;\n\n const retryErrorCodes = [\n 'UNKNOWN_ERROR',\n 'NOT_IMPLEMENTED',\n 'NETWORK_ERROR',\n 'SERVER_ERROR',\n 'TIMEOUT',\n 'BAD_DATA',\n 'CANCELLED',\n ];\n\n const handler: ProxyHandler<SafeEthProvider> = {\n get: (target, prop, receiver) => {\n const originalMethod = target[prop as keyof SafeEthProvider];\n if (typeof originalMethod === 'function') {\n return async (...args: any[]) => {\n let retries = 0;\n let currentApi = target;\n let throwingError: Error;\n\n while (retries < maxRetries) {\n try {\n return await originalMethod.apply(currentApi, args);\n } catch (error: any) {\n // other than retryErrorCodes, other errors does not have anything to do with network request, retrying would not change its outcome\n if (!retryErrorCodes.includes(error?.code)) {\n throw error;\n }\n\n logger.warn(\n `Request failed with api at height ${height} (retry ${retries}): ${error.message}`,\n );\n throwingError = error;\n currentApi = this.unsafeApi.getSafeApi(height);\n retries++;\n }\n }\n\n logger.error(\n `Maximum retries (${maxRetries}) exceeded for api at height ${height}`,\n );\n throw throwingError;\n };\n }\n return Reflect.get(target, prop, receiver);\n },\n };\n\n return new Proxy(this.unsafeApi.getSafeApi(height), handler);\n }\n\n private async fetchFullBlocksBatch(\n api: EthereumApi,\n batch: number[],\n ): Promise<EthereumBlock[]> {\n return api.fetchBlocks(batch);\n }\n\n private async fetchLightBlocksBatch(\n api: EthereumApi,\n batch: number[],\n ): Promise<LightEthereumBlock[]> {\n return api.fetchBlocksLight(batch);\n }\n\n updateBlockFetching(): void {\n const onlyEventHandlers = isOnlyEventHandlers(this.project);\n const skipTransactions =\n this.nodeConfig.skipTransactions && onlyEventHandlers;\n\n if (this.nodeConfig.skipTransactions) {\n if (onlyEventHandlers) {\n logger.info(\n 'skipTransactions is enabled, only events and block headers will be fetched.',\n );\n } else {\n logger.info(\n `skipTransactions is disabled, the project contains handlers that aren't event handlers.`,\n );\n }\n } else {\n if (onlyEventHandlers) {\n logger.warn(\n 'skipTransactions is disabled, the project contains only event handlers, it could be enabled to improve indexing performance.',\n );\n } else {\n logger.info(`skipTransactions is disabled.`);\n }\n }\n\n const fetchFunc = skipTransactions\n ? this.fetchLightBlocksBatch.bind(this)\n : this.fetchFullBlocksBatch.bind(this);\n\n if (this.nodeConfig?.profiler) {\n this.fetchBlocksFunction = profilerWrap(\n fetchFunc,\n 'SubstrateUtil',\n 'fetchBlocksBatches',\n );\n } else {\n this.fetchBlocksFunction = fetchFunc;\n }\n }\n}\n"]}
|
package/package.json
CHANGED