Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqiang90 committed Oct 10, 2023
1 parent 5854c89 commit 380bfa6
Show file tree
Hide file tree
Showing 17 changed files with 779 additions and 542 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {IndexerEvent, PoiEvent} from '../../events';
import {getLogger} from '../../logger';
import {IQueue, mainThreadOnly} from '../../utils';
import {DynamicDsService} from '../dynamic-ds.service';
import {PoiBlock, PoiService} from '../poi';
import {PoiBlock, PoiService, PoiSyncService} from '../poi';
import {SmartBatchService} from '../smartBatch.service';
import {StoreService} from '../store.service';
import {StoreCacheService} from '../storeCache';
Expand Down Expand Up @@ -62,6 +62,7 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS> implements IBloc
protected storeService: StoreService,
private storeCacheService: StoreCacheService,
private poiService: PoiService,
private poiSyncService: PoiSyncService,
protected dynamicDsService: DynamicDsService<any>
) {}

Expand Down Expand Up @@ -169,21 +170,21 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS> implements IBloc

if (reindexBlockHeight !== null && reindexBlockHeight !== undefined) {
if (this.nodeConfig.proofOfIndex) {
await this.poiService.stopSync();
await this.poiSyncService.stopSync();
this.poiSyncService.clear();
}
await this.rewind(reindexBlockHeight);
this.setLatestProcessedHeight(reindexBlockHeight);
// Bring poi sync back to sync again.
// Bring poi sync service back to sync again.
if (this.nodeConfig.proofOfIndex) {
await this.poiService.syncLatestSyncedPoiFromDb();
void this.poiService.syncPoi();
void this.poiSyncService.syncPoi();
}
return;
} else {
this.updateStoreMetadata(height);

const operationHash = this.storeService.getOperationMerkleRoot();
await this.createPOI(height, blockHash, operationHash);
this.createPOI(height, blockHash, operationHash);

if (dynamicDsCreated) {
await this.onDynamicDsCreated(height);
Expand All @@ -209,8 +210,15 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS> implements IBloc
}
}

// First creation of POI
private async createPOI(height: number, blockHash: string, operationHash: Uint8Array): Promise<void> {
/**
* If index a block generate store operation, this will create a POI
* and this createdPoi will be upsert into CachedPoi
* @param height
* @param blockHash
* @param operationHash
* @private
*/
private createPOI(height: number, blockHash: string, operationHash: Uint8Array): void {
if (!this.nodeConfig.proofOfIndex) {
return;
}
Expand All @@ -225,8 +233,6 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS> implements IBloc
height,
timestamp: Date.now(),
});

await this.poiService.ensureGenesisPoi(height);
}

@mainThreadOnly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {isMainThread} from 'worker_threads';
import {Inject, OnApplicationShutdown} from '@nestjs/common';
import {EventEmitter2} from '@nestjs/event-emitter';
import {Interval} from '@nestjs/schedule';
import {PoiSyncService} from '@subql/node-core/indexer';
import {last} from 'lodash';
import {NodeConfig} from '../../configure';
import {IProjectUpgradeService} from '../../configure/ProjectUpgrade.service';
Expand Down Expand Up @@ -52,6 +53,7 @@ export abstract class BlockDispatcher<B, DS>
storeService: StoreService,
storeCacheService: StoreCacheService,
poiService: PoiService,
poiSyncService: PoiSyncService,
project: ISubqueryProject,
dynamicDsService: DynamicDsService<DS>,
fetchBlocksBatches: BatchBlockFetcher<B>
Expand All @@ -67,6 +69,7 @@ export abstract class BlockDispatcher<B, DS>
storeService,
storeCacheService,
poiService,
poiSyncService,
dynamicDsService
);
this.processQueue = new AutoQueue(nodeConfig.batchSize * 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {EventEmitter2} from '@nestjs/event-emitter';
import {IProjectUpgradeService, NodeConfig} from '../../configure';
import {DynamicDsService} from '../dynamic-ds.service';
import {PoiService} from '../poi';
import {PoiService, PoiSyncService} from '../poi';
import {SmartBatchService} from '../smartBatch.service';
import {StoreService} from '../store.service';
import {StoreCacheService} from '../storeCache';
Expand Down Expand Up @@ -36,6 +36,7 @@ describe('WorkerBlockDispatcher', () => {
null as unknown as StoreService,
null as unknown as StoreCacheService,
null as unknown as PoiService,
null as unknown as PoiSyncService,
null as unknown as ISubqueryProject,
null as unknown as DynamicDsService<any>,
null as unknown as () => Promise<any>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import assert from 'assert';
import {OnApplicationShutdown} from '@nestjs/common';
import {EventEmitter2} from '@nestjs/event-emitter';
import {Interval} from '@nestjs/schedule';
import {PoiSyncService} from '@subql/node-core/indexer';
import {last} from 'lodash';
import {NodeConfig} from '../../configure';
import {IProjectUpgradeService} from '../../configure/ProjectUpgrade.service';
Expand Down Expand Up @@ -55,6 +56,7 @@ export abstract class WorkerBlockDispatcher<DS, W extends Worker>
storeService: StoreService,
storeCacheService: StoreCacheService,
poiService: PoiService,
poiSyncService: PoiSyncService,
project: ISubqueryProject,
dynamicDsService: DynamicDsService<DS>,
private createIndexerWorker: () => Promise<W>
Expand All @@ -70,6 +72,7 @@ export abstract class WorkerBlockDispatcher<DS, W extends Worker>
storeService,
storeCacheService,
poiService,
poiSyncService,
dynamicDsService
);
// initAutoQueue will assert that workers is set. unfortunately we cant do anything before the super call
Expand Down
1 change: 1 addition & 0 deletions packages/node-core/src/indexer/poi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

export * from './poiModel';
export * from './poi.service';
export * from './poiSync.service';
export * from './PoiBlock';
Loading

0 comments on commit 380bfa6

Please sign in to comment.