Skip to content

Commit

Permalink
Fix dict last buffered (#336)
Browse files Browse the repository at this point in the history
* Fix empty block result returning undefined

* Improve test

* Update changelog
  • Loading branch information
stwiname authored Aug 15, 2024
1 parent 2131765 commit 244e7d0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Empty dictionary v2 response resulting in all blocks within that range being indexed (#336)

## [5.1.0] - 2024-08-02
### Added
Expand Down
32 changes: 32 additions & 0 deletions packages/node/src/indexer/dictionary/v2/ethDictionaryV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,38 @@ describe('eth dictionary v2', () => {
// Uncomment this when not null filter supported
// expect(logs.filter(l => !l.topics[3]).length).toEqual(6) // There are 6 events with no topic3
}, 100000);

it('returns a lastBufferedHeight if there are no block results', async () => {
const ds: SubqlRuntimeDatasource = {
kind: EthereumDatasourceKind.Runtime,
assets: new Map(),
options: {
abi: 'erc20',
address: '0x30baa3ba9d7089fd8d020a994db75d14cf7ec83b',
},
startBlock: 18723210,
mapping: {
file: '',
handlers: [
{
handler: 'handleLog',
kind: EthereumHandlerKind.Event,
filter: {
topics: ['Transfer(address, address, uint256)'],
},
},
],
},
};

const dsMap = makeBlockHeightMap([ds]);
ethDictionaryV2.updateQueriesMap(dsMap);

const res = await ethDictionaryV2.getData(18723210, 18733210, 100);

expect(res?.batchBlocks.length).toEqual(0);
expect(res?.lastBufferedHeight).toEqual(18733210);
});
});

describe('buildDictionaryV2QueryEntry', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/node/src/indexer/dictionary/v2/ethDictionaryV2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { BigNumber } from '@ethersproject/bignumber';
import {
NodeConfig,
DictionaryV2,
Expand Down Expand Up @@ -285,7 +286,10 @@ export class EthDictionaryV2 extends DictionaryV2<
).map((b) => rawBlockToEthBlock(b, this.api));

if (!blocks.length) {
return undefined;
return {
batchBlocks: [],
lastBufferedHeight: undefined, // This will get set to the request end block in the base class.
} as any;
}
return {
batchBlocks: blocks,
Expand Down

0 comments on commit 244e7d0

Please sign in to comment.