Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix getBestBlockHeight miss unfinalizedBlocks arg #215

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/node/src/ethereum/api.connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ export class EthereumApiConnection
blockConfirmations: number,
fetchBlocksBatches: GetFetchFunc,
eventEmitter: EventEmitter2,
unfinalizedBlocks: boolean,
): Promise<EthereumApiConnection> {
const api = new EthereumApi(endpoint, blockConfirmations, eventEmitter);
const api = new EthereumApi(
endpoint,
blockConfirmations,
eventEmitter,
unfinalizedBlocks,
);

await api.init();

Expand Down
7 changes: 6 additions & 1 deletion packages/node/src/ethereum/api.ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -226,7 +227,11 @@ export class EthereumApi implements ApiWrapper {
async getBestBlockHeight(): Promise<number> {
// 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;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/node/src/ethereum/api.service.ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) => {
Expand Down
Loading