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 for block skipping on workers #82

Merged
merged 2 commits into from
Nov 13, 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
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updates to match changes in `@subql/node-core` (#83)
- Dictionary service to use dictionary registry
- Use yargs from node core
### Fixed
- Unable to skip unavailable blocks on workers (#82)

## [3.3.0] - 2023-11-06
### Added
Expand Down
17 changes: 7 additions & 10 deletions packages/node/src/indexer/worker/worker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@ import {
ProcessBlockResponse,
BaseWorkerService,
IProjectUpgradeService,
BlockUnavailableError,
} from '@subql/node-core';

import { NearDatasource } from '@subql/types-near';
import { ApiService } from '../api.service';
import { IndexerManager } from '../indexer.manager';
import { BlockContent } from '../types';

export type FetchBlockResponse = { parentHash: string } | undefined;

class BlockUnavailableError extends Error {
constructor(message: string) {
super(message);
this.name = 'BlockUnavailableError';
}
}

@Injectable()
export class WorkerService extends BaseWorkerService<
BlockContent,
Expand All @@ -49,17 +44,19 @@ export class WorkerService extends BaseWorkerService<
const [block] = await this.apiService.fetchBlocks([heights]);
return block;
}
protected toBlockResponse(block: BlockContent): { parentHash: string } {
protected toBlockResponse(block: BlockContent): {
parentHash: string | undefined;
} {
return {
parentHash: block.block.header.prev_hash,
parentHash: block?.block.header.prev_hash,
};
}
protected async processFetchedBlock(
block: BlockContent,
dataSources: NearDatasource[],
): Promise<ProcessBlockResponse> {
if (block === null) {
throw new BlockUnavailableError(`Block is unavailable in the chain`);
throw new BlockUnavailableError();
}
return this.indexerManager.indexBlock(block, dataSources);
}
Expand Down
Loading