From dd70d2106792d3e5e8d0a18ca1d5d45835239301 Mon Sep 17 00:00:00 2001 From: bz888 Date: Mon, 15 Apr 2024 11:01:35 +0800 Subject: [PATCH] add listener on fetch block --- packages/node/src/indexer/api.service.ts | 9 ++++++++- packages/node/src/utils/kyve/kyve.ts | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/node/src/indexer/api.service.ts b/packages/node/src/indexer/api.service.ts index 2e2079dc5..877523800 100644 --- a/packages/node/src/indexer/api.service.ts +++ b/packages/node/src/indexer/api.service.ts @@ -117,6 +117,10 @@ export class ApiService this.nodeConfig.kyveChainId, this.project.fileCacheDir, ); + + this.eventEmitter.on('block_processing_height', (block) => { + console.log('block_processing_height', block); + }); } return this; @@ -129,7 +133,10 @@ export class ApiService ): Promise[]> { try { if (this.kyveApi) { - return this.kyveApi.fetchBlocksBatches(this.registry, heights); + const v = await this.kyveApi.fetchBlocksBatches(this.registry, heights); + // listen for processingblock, if it is + + return v; } else { throw new Error('No kyve connection'); } diff --git a/packages/node/src/utils/kyve/kyve.ts b/packages/node/src/utils/kyve/kyve.ts index 4fef4c640..493ea8fe6 100644 --- a/packages/node/src/utils/kyve/kyve.ts +++ b/packages/node/src/utils/kyve/kyve.ts @@ -255,6 +255,8 @@ export class KyveApi { .on('error', reject) .pipe(writeStream) .on('finish', resolve); + }).catch((e) => { + throw e; // to ensure an on stack error is thrown }); await fs.promises.chmod(bundleFilePath, 0o444); @@ -281,7 +283,8 @@ export class KyveApi { } // todo unsure when to clear the file cache - private async clearFileCache(height: number): Promise { + async clearFileCache(height: number, clearBuffer: number): Promise { + // add listener const bundleToRemove = this.cachedBundleDetails.filter( (b) => parseDecimal(b.from_key) > height, );