diff --git a/packages/node/src/ethereum/api.connection.ts b/packages/node/src/ethereum/api.connection.ts index dbdf052b4e..9ce3df3cdb 100644 --- a/packages/node/src/ethereum/api.connection.ts +++ b/packages/node/src/ethereum/api.connection.ts @@ -49,8 +49,14 @@ export class EthereumApiConnection blockConfirmations: number, fetchBlocksBatches: GetFetchFunc, eventEmitter: EventEmitter2, + unfinalizedBlocks: boolean, ): Promise { - const api = new EthereumApi(endpoint, blockConfirmations, eventEmitter); + const api = new EthereumApi( + endpoint, + blockConfirmations, + eventEmitter, + unfinalizedBlocks, + ); await api.init(); diff --git a/packages/node/src/ethereum/api.ethereum.ts b/packages/node/src/ethereum/api.ethereum.ts index 84aea68bc4..74bea7e727 100644 --- a/packages/node/src/ethereum/api.ethereum.ts +++ b/packages/node/src/ethereum/api.ethereum.ts @@ -110,6 +110,7 @@ export class EthereumApi implements ApiWrapper { private endpoint: string, private blockConfirmations: number, private eventEmitter: EventEmitter2, + private unfinalizedBlocks = false, ) { const { hostname, protocol, searchParams } = new URL(endpoint); @@ -226,7 +227,11 @@ export class EthereumApi implements ApiWrapper { async getBestBlockHeight(): Promise { // Cronos "safe" tag doesn't currently work as indended const tag = - this.supportsFinalization && this.chainId !== 25 ? 'safe' : 'latest'; + !this.unfinalizedBlocks && + this.supportsFinalization && + this.chainId !== 25 + ? 'safe' + : 'latest'; return (await this.client.getBlock(tag)).number; } diff --git a/packages/node/src/ethereum/api.service.ethereum.ts b/packages/node/src/ethereum/api.service.ethereum.ts index de73ed95a0..a4e01175bf 100644 --- a/packages/node/src/ethereum/api.service.ethereum.ts +++ b/packages/node/src/ethereum/api.service.ethereum.ts @@ -10,7 +10,11 @@ import { NodeConfig, profilerWrap, } from '@subql/node-core'; -import { EthereumBlock, EthereumNetworkConfig, LightEthereumBlock } from '@subql/types-ethereum'; +import { + EthereumBlock, + EthereumNetworkConfig, + LightEthereumBlock, +} from '@subql/types-ethereum'; import { EthereumNodeConfig } from '../configure/NodeConfig'; import { SubqueryProject } from '../configure/SubqueryProject'; import { isOnlyEventHandlers } from '../utils/project'; @@ -71,6 +75,7 @@ export class EthereumApiService extends ApiService< this.nodeConfig.blockConfirmations, this.fetchBlocksBatches, this.eventEmitter, + this.nodeConfig.unfinalizedBlocks, ), //eslint-disable-next-line @typescript-eslint/require-await async (connection: EthereumApiConnection) => {