From 09a727c00d678438d6e8f5747f274d92189c1bb9 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 24 Jan 2024 12:18:42 +0000 Subject: [PATCH] Fix more Goggles indexing bugs --- backend/src/api/blocks.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 348c44b78..21818dc62 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -611,7 +611,7 @@ class Blocks { if (unclassifiedBlocks[height]) { const blockHash = unclassifiedBlocks[height]; // fetch transactions - txs = (await bitcoinApi.$getTxsForBlock(blockHash)).map(tx => transactionUtils.extendTransaction(tx)); + txs = (await bitcoinApi.$getTxsForBlock(blockHash)).map(tx => transactionUtils.extendTransaction(tx)) || []; // add CPFP const cpfpSummary = Common.calculateCpfp(height, txs, true); // classify @@ -622,7 +622,7 @@ class Blocks { // classify template const blockHash = unclassifiedTemplates[height]; const template = await BlocksSummariesRepository.$getTemplate(blockHash); - const alreadyClassified = template?.transactions.reduce((classified, tx) => (classified || tx.flags > 0), false); + const alreadyClassified = template?.transactions?.reduce((classified, tx) => (classified || tx.flags > 0), false); let classifiedTemplate = template?.transactions || []; if (!alreadyClassified) { const templateTxs: (TransactionExtended | TransactionClassified)[] = []; @@ -641,7 +641,7 @@ class Blocks { } templateTxs.push(tx || templateTx); } - const cpfpSummary = Common.calculateCpfp(height, txs?.filter(tx => tx.effectiveFeePerVsize != null) as TransactionExtended[], true); + const cpfpSummary = Common.calculateCpfp(height, templateTxs?.filter(tx => tx['effectiveFeePerVsize'] != null) as TransactionExtended[], true); // classify const { transactions: classifiedTxs } = this.summarizeBlockTransactions(blockHash, cpfpSummary.transactions); const classifiedTxMap: { [txid: string]: TransactionClassified } = {}; @@ -662,8 +662,10 @@ class Blocks { } // timing & logging - indexedThisRun++; - indexedTotal++; + if (unclassifiedBlocks[height] || unclassifiedTemplates[height]) { + indexedThisRun++; + indexedTotal++; + } const elapsedSeconds = (Date.now() - timer) / 1000; if (elapsedSeconds > 5) { const perSecond = indexedThisRun / elapsedSeconds;