Skip to content

Commit ca59c76

Browse files
committed
polish
1 parent 4f6cf12 commit ca59c76

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

packages/eth-providers/src/base-provider.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,28 +1746,21 @@ export abstract class BaseProvider extends AbstractProvider {
17461746
await this._isBlockCanonical(txFromCache.blockHash, txFromCache.blockNumber)
17471747
) return txFromCache;
17481748

1749-
// make sure there is no gap between subql and cache
1750-
await this._checkSubqlHeight(this.blockCache.cachedBlockHashes.length);
1749+
await this._checkSubqlHeight();
17511750

17521751
const txFromSubql = await this.subql?.getTxReceiptByHash(txHash);
17531752
return txFromSubql
17541753
? subqlReceiptAdapter(txFromSubql)
17551754
: null;
17561755
};
17571756

1758-
_checkSubqlHeight = async (_maxMissedBlockCount: number): Promise<number> => {
1757+
// make sure there is no gap between subql and cache
1758+
_checkSubqlHeight = async (): Promise<number> => {
17591759
if (!this.subql) return;
17601760

1761-
/* ---------------
1762-
usually subql is delayed for a couple blocks
1763-
so it doesn't make sense to check too small range (less than 5 block)
1764-
this can also prevent throwing error when provider just started
1765-
--------------- */
1766-
const SUBQL_DELAYED_OK_RANGE = 5;
1767-
const maxMissedBlockCount = Math.max(SUBQL_DELAYED_OK_RANGE, _maxMissedBlockCount);
1768-
1761+
const maxMissedBlockCount = this.blockCache.cachedBlockHashes.length;
17691762
const lastProcessedHeight = await this.subql.getLastProcessedHeight();
1770-
const minSubqlHeight = await this.bestBlockNumber - maxMissedBlockCount;
1763+
const minSubqlHeight = await this.finalizedBlockNumber - maxMissedBlockCount;
17711764
if (lastProcessedHeight < minSubqlHeight) {
17721765
return logger.throwError(
17731766
'subql indexer height is less than the minimum height required',
@@ -1776,7 +1769,7 @@ export abstract class BaseProvider extends AbstractProvider {
17761769
lastProcessedHeight,
17771770
minSubqlHeight,
17781771
maxMissedBlockCount,
1779-
curHeight: await this.bestBlockNumber,
1772+
curFinalizedHeight: await this.finalizedBlockNumber,
17801773
}
17811774
);
17821775
}
@@ -1826,10 +1819,8 @@ export abstract class BaseProvider extends AbstractProvider {
18261819
};
18271820

18281821
_getSubqlMissedLogs = async (toBlock: number, filter: SanitizedLogFilter): Promise<Log[]> => {
1829-
const SUBQL_MAX_MISSED_BLOCKS = 20;
1830-
18311822
const targetBlock = await this._getMaxTargetBlock(toBlock);
1832-
const lastProcessedHeight = await this._checkSubqlHeight(SUBQL_MAX_MISSED_BLOCKS);
1823+
const lastProcessedHeight = await this._checkSubqlHeight(); // all missed logs should be in cache
18331824
const missedBlockCount = targetBlock - lastProcessedHeight;
18341825
if (missedBlockCount <= 0) return [];
18351826

@@ -1839,7 +1830,6 @@ export abstract class BaseProvider extends AbstractProvider {
18391830

18401831
await this._waitForCache(targetBlock);
18411832

1842-
// all logs should be in cache since missedBlockCount <= 20
18431833
// no need to filter by blocknumber anymore, since these logs are from missedBlocks directly
18441834
return missedBlockHashes
18451835
.map(this.blockCache.getLogsAtBlock.bind(this))

0 commit comments

Comments
 (0)