Skip to content

Commit

Permalink
Merge pull request #82 from subquery/fix/workers-unavailable-blocks
Browse files Browse the repository at this point in the history
fix for block skipping on workers
  • Loading branch information
jiqiang90 authored Nov 13, 2023
2 parents 7fa098f + 6717188 commit fdc2741
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
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

0 comments on commit fdc2741

Please sign in to comment.