Skip to content

Commit

Permalink
historical timestamp and db store (#298)
Browse files Browse the repository at this point in the history
* historical timestamp and db store

* fix inject
  • Loading branch information
yoozo authored Nov 26, 2024
1 parent 9a1cce4 commit 8081427
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 220 deletions.
3 changes: 3 additions & 0 deletions packages/common-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Bump `@subql/common` dependency

## [5.0.5] - 2024-10-23
### Changed
- Bump `@subql/common` dependency
Expand Down
2 changes: 1 addition & 1 deletion packages/common-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@protobufs/google": "^0.0.10",
"@protobufs/ibc": "^0.1.0",
"@protobufs/tendermint": "^0.0.10",
"@subql/common": "^5.1.4",
"@subql/common": "^5.2.1",
"@subql/types-cosmos": "workspace:*",
"@subql/x-cosmology-telescope": "^1.4.14",
"fs-extra": "^11.1.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Support for historical indexing by timestamp as well as block height
- Add an `--enable-cache` flag, allowing you to choose between DB or cache for IO operations.

## [4.1.4] - 2024-10-23
### Changed
- Bump `@subql/common` dependency
Expand Down
4 changes: 2 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"@nestjs/event-emitter": "^2.0.0",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^5.1.4",
"@subql/common": "^5.2.1",
"@subql/common-cosmos": "workspace:*",
"@subql/node-core": "^14.1.6",
"@subql/node-core": "^15.0.2",
"@subql/types-cosmos": "workspace:*",
"lodash": "^4.17.21",
"protobufjs": "^6.11.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import {
NodeConfig,
StoreCacheService,
IStoreModelProvider,
StoreService,
IProjectService,
PoiSyncService,
Expand Down Expand Up @@ -38,7 +38,7 @@ export class BlockDispatcherService
@Inject('IProjectUpgradeService')
projectUpgradeService: IProjectUpgradeService,
storeService: StoreService,
storeCacheService: StoreCacheService,
@Inject('IStoreModelProvider') storeModelProvider: IStoreModelProvider,
poiSyncService: PoiSyncService,
@Inject('ISubqueryProject') project: SubqueryProject,
) {
Expand All @@ -48,7 +48,7 @@ export class BlockDispatcherService
projectService,
projectUpgradeService,
storeService,
storeCacheService,
storeModelProvider,
poiSyncService,
project,
apiService.fetchBlocks.bind(apiService),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
NodeConfig,
StoreService,
PoiSyncService,
StoreCacheService,
IStoreModelProvider,
IProjectService,
WorkerBlockDispatcher,
ConnectionPoolStateManager,
Expand All @@ -24,6 +24,7 @@ import { DynamicDsService } from '../dynamic-ds.service';
import { BlockContent } from '../types';
import { UnfinalizedBlocksService } from '../unfinalizedBlocks.service';
import { IIndexerWorker } from '../worker/worker';
import { FetchBlockResponse } from '../worker/worker.service';

type IndexerWorker = IIndexerWorker & {
terminate: () => Promise<number>;
Expand All @@ -43,7 +44,7 @@ export class WorkerBlockDispatcherService
projectUpgadeService: IProjectUpgradeService,
cacheService: InMemoryCacheService,
storeService: StoreService,
storeCacheService: StoreCacheService,
@Inject('IStoreModelProvider') storeModelProvider: IStoreModelProvider,
poiSyncService: PoiSyncService,
@Inject('ISubqueryProject') project: SubqueryProject,
dynamicDsService: DynamicDsService,
Expand All @@ -57,7 +58,7 @@ export class WorkerBlockDispatcherService
projectService,
projectUpgadeService,
storeService,
storeCacheService,
storeModelProvider,
poiSyncService,
project,
() =>
Expand Down Expand Up @@ -92,9 +93,9 @@ export class WorkerBlockDispatcherService
protected async fetchBlock(
worker: IndexerWorker,
height: number,
): Promise<void> {
): Promise<FetchBlockResponse> {
// const start = new Date();
await worker.fetchBlock(height, 0 /* Value is not used with cosmos*/);
return worker.fetchBlock(height, 0 /* Value is not used with cosmos*/);
// const end = new Date();

// const waitTime = end.getTime() - start.getTime();
Expand Down
10 changes: 5 additions & 5 deletions packages/node/src/indexer/fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
StoreService,
PoiSyncService,
NodeConfig,
StoreCacheService,
IStoreModelProvider,
ConnectionPoolStateManager,
IProjectUpgradeService,
InMemoryCacheService,
Expand Down Expand Up @@ -55,7 +55,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
indexerManager: IndexerManager,
cacheService: InMemoryCacheService,
storeService: StoreService,
storeCacheService: StoreCacheService,
storeModelProvider: IStoreModelProvider,
poiSyncService: PoiSyncService,
project: SubqueryProject,
dynamicDsService: DynamicDsService,
Expand All @@ -71,7 +71,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
projectUpgradeService,
cacheService,
storeService,
storeCacheService,
storeModelProvider,
poiSyncService,
project,
dynamicDsService,
Expand All @@ -87,7 +87,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
projectService,
projectUpgradeService,
storeService,
storeCacheService,
storeModelProvider,
poiSyncService,
project,
),
Expand All @@ -100,7 +100,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
IndexerManager,
InMemoryCacheService,
StoreService,
StoreCacheService,
'IStoreModelProvider',
PoiSyncService,
'ISubqueryProject',
DynamicDsService,
Expand Down
6 changes: 3 additions & 3 deletions packages/node/src/indexer/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
BaseFetchService,
getModulos,
Header,
StoreCacheService,
IStoreModelProvider,
} from '@subql/node-core';
import * as CosmosUtil from '../utils/cosmos';
import { cosmosBlockToHeader } from '../utils/cosmos';
Expand Down Expand Up @@ -44,7 +44,7 @@ export class FetchService extends BaseFetchService<
unfinalizedBlocksService: UnfinalizedBlocksService,
eventEmitter: EventEmitter2,
schedulerRegistry: SchedulerRegistry,
storeCacheService: StoreCacheService,
@Inject('IStoreModelProvider') storeModelProvider: IStoreModelProvider,
) {
super(
nodeConfig,
Expand All @@ -54,7 +54,7 @@ export class FetchService extends BaseFetchService<
eventEmitter,
schedulerRegistry,
unfinalizedBlocksService,
storeCacheService,
storeModelProvider,
);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/node/src/indexer/unfinalizedBlocks.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { Injectable } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import {
BaseUnfinalizedBlocksService,
Header,
NodeConfig,
StoreCacheService,
IStoreModelProvider,
mainThreadOnly,
} from '@subql/node-core';
import { cosmosBlockToHeader } from '../utils/cosmos';
Expand All @@ -18,9 +18,9 @@ export class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<Block
constructor(
private readonly apiService: ApiService,
nodeConfig: NodeConfig,
storeCache: StoreCacheService,
@Inject('IStoreModelProvider') storeModelProvider: IStoreModelProvider,
) {
super(nodeConfig, storeCache);
super(nodeConfig, storeModelProvider);
}

@mainThreadOnly()
Expand All @@ -34,7 +34,7 @@ export class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<Block
}

@mainThreadOnly()
protected async getHeaderForHeight(height: number): Promise<Header> {
async getHeaderForHeight(height: number): Promise<Header> {
return Promise.resolve(cosmosBlockToHeader(height));
}
}
10 changes: 4 additions & 6 deletions packages/node/src/indexer/worker/worker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {
BaseWorkerService,
IProjectUpgradeService,
IBlock,
Header,
} from '@subql/node-core';
import { CosmosDatasource } from '@subql/types-cosmos';
import { cosmosBlockToHeader } from '../../utils/cosmos';
import { ApiService } from '../api.service';
import { IndexerManager } from '../indexer.manager';
import { BlockContent } from '../types';

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

export type WorkerStatusResponse = {
threadId: number;
Expand Down Expand Up @@ -58,9 +58,7 @@ export class WorkerService extends BaseWorkerService<
}

protected toBlockResponse(block: BlockContent): FetchBlockResponse {
return {
parentHash: block.block.header.lastBlockId?.hash.toString(),
};
return cosmosBlockToHeader(block.block.header.height);
}

protected async processFetchedBlock(
Expand Down
12 changes: 9 additions & 3 deletions packages/node/src/subcommands/reindex.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
// SPDX-License-Identifier: GPL-3.0

import { Module } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';
import { SchedulerRegistry } from '@nestjs/schedule';
import {
DbModule,
ForceCleanService,
ReindexService,
StoreCacheService,
StoreService,
PoiService,
storeModelFactory,
NodeConfig,
} from '@subql/node-core';
import { Sequelize } from '@subql/x-sequelize';
import { ConfigureModule } from '../configure/configure.module';
import { ApiService } from '../indexer/api.service';
import { DsProcessorService } from '../indexer/ds-processor.service';
Expand All @@ -20,7 +22,11 @@ import { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service';

@Module({
providers: [
StoreCacheService,
{
provide: 'IStoreModelProvider',
useFactory: storeModelFactory,
inject: [NodeConfig, EventEmitter2, SchedulerRegistry, Sequelize],
},
StoreService,
ReindexService,
PoiService,
Expand Down
9 changes: 7 additions & 2 deletions packages/node/src/subcommands/testing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import {
NodeConfig,
PoiService,
PoiSyncService,
StoreCacheService,
StoreService,
TestRunner,
SandboxService,
storeModelFactory,
} from '@subql/node-core';
import { Sequelize } from '@subql/x-sequelize';
import { ConfigureModule } from '../configure/configure.module';
import { ApiService } from '../indexer/api.service';
import { DsProcessorService } from '../indexer/ds-processor.service';
Expand All @@ -29,7 +30,11 @@ import { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service';
providers: [
InMemoryCacheService,
StoreService,
StoreCacheService,
{
provide: 'IStoreModelProvider',
useFactory: storeModelFactory,
inject: [NodeConfig, EventEmitter2, SchedulerRegistry, Sequelize],
},
EventEmitter2,
PoiService,
PoiSyncService,
Expand Down
Loading

0 comments on commit 8081427

Please sign in to comment.