diff --git a/backend/src/api/bitcoin/bitcoin.routes.ts b/backend/src/api/bitcoin/bitcoin.routes.ts index 0a343c376..c31fe1a09 100644 --- a/backend/src/api/bitcoin/bitcoin.routes.ts +++ b/backend/src/api/bitcoin/bitcoin.routes.ts @@ -224,7 +224,12 @@ class BitcoinRoutes { } else { let cpfpInfo; if (config.DATABASE.ENABLED) { - cpfpInfo = await transactionRepository.$getCpfpInfo(req.params.txId); + try { + cpfpInfo = await transactionRepository.$getCpfpInfo(req.params.txId); + } catch (e) { + res.status(500).send('failed to get CPFP info'); + return; + } } if (cpfpInfo) { res.json(cpfpInfo); diff --git a/backend/src/repositories/CpfpRepository.ts b/backend/src/repositories/CpfpRepository.ts index e712e6009..90ba2ac80 100644 --- a/backend/src/repositories/CpfpRepository.ts +++ b/backend/src/repositories/CpfpRepository.ts @@ -78,14 +78,6 @@ class CpfpRepository { const maxChunk = 100; let chunkIndex = 0; - // insert transactions in batches of up to 100 rows - while (chunkIndex < txs.length) { - const chunk = txs.slice(chunkIndex, chunkIndex + maxChunk); - await transactionRepository.$batchSetCluster(chunk); - chunkIndex += maxChunk; - } - - chunkIndex = 0; // insert clusters in batches of up to 100 rows while (chunkIndex < clusterValues.length) { const chunk = clusterValues.slice(chunkIndex, chunkIndex + maxChunk); @@ -103,6 +95,15 @@ class CpfpRepository { ); chunkIndex += maxChunk; } + + chunkIndex = 0; + // insert transactions in batches of up to 100 rows + while (chunkIndex < txs.length) { + const chunk = txs.slice(chunkIndex, chunkIndex + maxChunk); + await transactionRepository.$batchSetCluster(chunk); + chunkIndex += maxChunk; + } + return true; } catch (e: any) { logger.err(`Cannot save cpfp clusters into db. Reason: ` + (e instanceof Error ? e.message : e)); @@ -120,8 +121,8 @@ class CpfpRepository { [clusterRoot] ); const cluster = clusterRows[0]; - cluster.effectiveFeePerVsize = cluster.fee_rate; if (cluster?.txs) { + cluster.effectiveFeePerVsize = cluster.fee_rate; cluster.txs = this.unpack(cluster.txs); return cluster; }