From 69dc21d23258c546de5e408a0f912c9186ccb97f Mon Sep 17 00:00:00 2001 From: Mononaut Date: Mon, 19 Feb 2024 02:43:19 +0000 Subject: [PATCH] Continue other indexing tasks while Goggles classification runs --- backend/src/api/blocks.ts | 8 ++++++++ backend/src/indexer.ts | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 4ccf58645..28ca38152 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -40,6 +40,7 @@ class Blocks { private quarterEpochBlockTime: number | null = null; private newBlockCallbacks: ((block: BlockExtended, txIds: string[], transactions: TransactionExtended[]) => void)[] = []; private newAsyncBlockCallbacks: ((block: BlockExtended, txIds: string[], transactions: MempoolTransactionExtended[]) => Promise)[] = []; + private classifyingBlocks: boolean = false; private mainLoopTimeout: number = 120000; @@ -568,6 +569,11 @@ class Blocks { * [INDEXING] Index transaction classification flags for Goggles */ public async $classifyBlocks(): Promise { + if (this.classifyingBlocks) { + return; + } + this.classifyingBlocks = true; + // classification requires an esplora backend if (!Common.gogglesIndexingEnabled() || config.MEMPOOL.BACKEND !== 'esplora') { return; @@ -679,6 +685,8 @@ class Blocks { indexedThisRun = 0; } } + + this.classifyingBlocks = false; } /** diff --git a/backend/src/indexer.ts b/backend/src/indexer.ts index 90b4a59e6..dcb91d010 100644 --- a/backend/src/indexer.ts +++ b/backend/src/indexer.ts @@ -185,7 +185,8 @@ class Indexer { await blocks.$generateCPFPDatabase(); await blocks.$generateAuditStats(); await auditReplicator.$sync(); - await blocks.$classifyBlocks(); + // do not wait for classify blocks to finish + blocks.$classifyBlocks(); } catch (e) { this.indexerRunning = false; logger.err(`Indexer failed, trying again in 10 seconds. Reason: ` + (e instanceof Error ? e.message : e));