-
Notifications
You must be signed in to change notification settings - Fork 352
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
Endblock feature #2064
Endblock feature #2064
Changes from 13 commits
61c0d1e
8d9c2f7
4ad8eb9
2d4b3c5
ade0b95
ac38a69
3738f4d
badd853
45ded83
82b8566
d163c34
5c3142b
36d630c
c9967bc
68201ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,167 @@ | ||||||||||
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors | ||||||||||
// SPDX-License-Identifier: GPL-3.0 | ||||||||||
|
||||||||||
import {NodeConfig} from '../configure'; | ||||||||||
import {BaseDsProcessorService} from './ds-processor.service'; | ||||||||||
import {DynamicDsService} from './dynamic-ds.service'; | ||||||||||
import {BaseProjectService} from './project.service'; | ||||||||||
import {ISubqueryProject} from './types'; | ||||||||||
|
||||||||||
class TestProjectService extends BaseProjectService<any, any> { | ||||||||||
packageVersion = '1.0.0'; | ||||||||||
|
||||||||||
async getBlockTimestamp(height: number): Promise<Date> { | ||||||||||
return Promise.resolve(new Date()); | ||||||||||
} | ||||||||||
|
||||||||||
onProjectChange(project: any): void { | ||||||||||
return; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
describe('BaseProjectService', () => { | ||||||||||
guplersaxanoid marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
let service: TestProjectService; | ||||||||||
|
||||||||||
beforeEach(() => { | ||||||||||
service = new TestProjectService( | ||||||||||
null as unknown as BaseDsProcessorService, | ||||||||||
null as unknown as any, | ||||||||||
null as unknown as any, | ||||||||||
null as unknown as any, | ||||||||||
null as unknown as any, | ||||||||||
{dataSources: []} as unknown as ISubqueryProject<any>, | ||||||||||
null as unknown as any, | ||||||||||
null as unknown as any, | ||||||||||
{unsafe: false} as unknown as NodeConfig, | ||||||||||
{getDynamicDatasources: jest.fn()} as unknown as DynamicDsService<any>, | ||||||||||
null as unknown as any, | ||||||||||
null as unknown as any | ||||||||||
); | ||||||||||
}); | ||||||||||
|
||||||||||
it('hasDataSourcesAfterHeight', async () => { | ||||||||||
service.getDataSources = jest.fn().mockResolvedValue([{endBlock: 100}, {endBlock: 200}, {endBlock: 300}]); | ||||||||||
|
||||||||||
const result = await service.hasDataSourcesAfterHeight(150); | ||||||||||
expect(result).toBe(true); | ||||||||||
}); | ||||||||||
|
||||||||||
it('hasDataSourcesAfterHeight - undefined endBlock', async () => { | ||||||||||
service.getDataSources = jest.fn().mockResolvedValue([{endBlock: 100}, {endBlock: undefined}]); | ||||||||||
|
||||||||||
const result = await service.hasDataSourcesAfterHeight(150); | ||||||||||
expect(result).toBe(true); | ||||||||||
}); | ||||||||||
|
||||||||||
it('getDataSources', async () => { | ||||||||||
(service as any).project.dataSources = [ | ||||||||||
{startBlock: 100, endBlock: 200}, | ||||||||||
{startBlock: 1, endBlock: 100}, | ||||||||||
]; | ||||||||||
(service as any).dynamicDsService.getDynamicDatasources = jest | ||||||||||
.fn() | ||||||||||
.mockResolvedValue([{startBlock: 150, endBlock: 250}]); | ||||||||||
|
||||||||||
const result = await service.getDataSources(175); | ||||||||||
expect(result).toEqual([ | ||||||||||
{startBlock: 100, endBlock: 200}, | ||||||||||
{startBlock: 150, endBlock: 250}, | ||||||||||
]); | ||||||||||
}); | ||||||||||
|
||||||||||
describe('getDatasourceMap', () => { | ||||||||||
it('should add endBlock heights correctly', () => { | ||||||||||
(service as any).dynamicDsService.dynamicDatasources = []; | ||||||||||
(service as any).projectUpgradeService = { | ||||||||||
projects: [ | ||||||||||
[ | ||||||||||
1, | ||||||||||
{ | ||||||||||
dataSources: [ | ||||||||||
{startBlock: 1, endBlock: 300}, | ||||||||||
{startBlock: 10, endBlock: 20}, | ||||||||||
{startBlock: 1, endBlock: 100}, | ||||||||||
{startBlock: 50, endBlock: 200}, | ||||||||||
{startBlock: 500}, | ||||||||||
], | ||||||||||
}, | ||||||||||
], | ||||||||||
], | ||||||||||
} as any; | ||||||||||
|
||||||||||
const result = service.getDataSourcesMap(); | ||||||||||
expect(result.getAll()).toEqual( | ||||||||||
new Map([ | ||||||||||
[ | ||||||||||
1, | ||||||||||
[ | ||||||||||
{startBlock: 1, endBlock: 300}, | ||||||||||
{startBlock: 1, endBlock: 100}, | ||||||||||
], | ||||||||||
], | ||||||||||
[ | ||||||||||
10, | ||||||||||
[ | ||||||||||
{startBlock: 1, endBlock: 300}, | ||||||||||
{startBlock: 1, endBlock: 100}, | ||||||||||
{startBlock: 10, endBlock: 20}, | ||||||||||
], | ||||||||||
], | ||||||||||
[ | ||||||||||
21, | ||||||||||
[ | ||||||||||
{startBlock: 1, endBlock: 300}, | ||||||||||
{startBlock: 1, endBlock: 100}, | ||||||||||
], | ||||||||||
], | ||||||||||
[ | ||||||||||
50, | ||||||||||
[ | ||||||||||
{startBlock: 1, endBlock: 300}, | ||||||||||
{startBlock: 1, endBlock: 100}, | ||||||||||
{startBlock: 50, endBlock: 200}, | ||||||||||
], | ||||||||||
], | ||||||||||
[ | ||||||||||
101, | ||||||||||
[ | ||||||||||
{startBlock: 1, endBlock: 300}, | ||||||||||
{startBlock: 50, endBlock: 200}, | ||||||||||
], | ||||||||||
], | ||||||||||
[201, [{startBlock: 1, endBlock: 300}]], | ||||||||||
[301, []], | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this can happen then the indexer will exit because of subql/packages/node-core/src/indexer/blockDispatcher/base-block-dispatcher.ts Lines 212 to 215 in 5c3142b
We either need to support this correctly in the fetch service when enqueuing blocks or throw an error if this happens There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If no datasources are available to index a specific blockheight we throw this error: should we change this behaviour to somehow skip blocks that has no datasources? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that happens too late on having to index to that height to see the error. I think we can skip blocks, its should be relatively easy to do |
||||||||||
[500, [{startBlock: 500}]], | ||||||||||
]) | ||||||||||
); | ||||||||||
}); | ||||||||||
|
||||||||||
it('should contain datasources from current project only', () => { | ||||||||||
(service as any).dynamicDsService.dynamicDatasources = []; | ||||||||||
(service as any).projectUpgradeService = { | ||||||||||
projects: [ | ||||||||||
[ | ||||||||||
1, | ||||||||||
{ | ||||||||||
dataSources: [{startBlock: 1}, {startBlock: 200}], | ||||||||||
}, | ||||||||||
], | ||||||||||
[ | ||||||||||
100, | ||||||||||
{ | ||||||||||
dataSources: [{startBlock: 100}], | ||||||||||
}, | ||||||||||
], | ||||||||||
], | ||||||||||
} as any; | ||||||||||
|
||||||||||
const result = service.getDataSourcesMap(); | ||||||||||
expect(result.getAll()).toEqual( | ||||||||||
new Map([ | ||||||||||
[1, [{startBlock: 1}]], | ||||||||||
[100, [{startBlock: 100}]], | ||||||||||
]) | ||||||||||
); | ||||||||||
}); | ||||||||||
}); | ||||||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is right. What happens if we run into bypassblocks at the next height?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can do this check with datasources map to make sure we are not exiting prematurely