Skip to content

Commit

Permalink
fix getBestBlockHeight miss unfinalizedBlocks arg (#215)
Browse files Browse the repository at this point in the history
* fix getBestBlockHeight miss unfinalizedBlocks

* Update packages/node/src/ethereum/api.ethereum.ts

Co-authored-by: Scott Twiname <[email protected]>

* rollback tests

---------

Co-authored-by: Scott Twiname <[email protected]>
  • Loading branch information
jiqiang90 and stwiname authored Nov 23, 2023
1 parent 328226e commit 67589b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
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

0 comments on commit 67589b7

Please sign in to comment.