Skip to content

Commit e88cf70

Browse files
authored
Merge pull request mempool#3886 from mempool/mononaut/hotfix-undefined-cpfp-cluster
Hotfix for undefined cpfp cluster bug
2 parents e5efc29 + 9ff5ce0 commit e88cf70

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

backend/src/api/bitcoin/bitcoin.routes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,12 @@ class BitcoinRoutes {
224224
} else {
225225
let cpfpInfo;
226226
if (config.DATABASE.ENABLED) {
227-
cpfpInfo = await transactionRepository.$getCpfpInfo(req.params.txId);
227+
try {
228+
cpfpInfo = await transactionRepository.$getCpfpInfo(req.params.txId);
229+
} catch (e) {
230+
res.status(500).send('failed to get CPFP info');
231+
return;
232+
}
228233
}
229234
if (cpfpInfo) {
230235
res.json(cpfpInfo);

backend/src/repositories/CpfpRepository.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ class CpfpRepository {
7878

7979
const maxChunk = 100;
8080
let chunkIndex = 0;
81-
// insert transactions in batches of up to 100 rows
82-
while (chunkIndex < txs.length) {
83-
const chunk = txs.slice(chunkIndex, chunkIndex + maxChunk);
84-
await transactionRepository.$batchSetCluster(chunk);
85-
chunkIndex += maxChunk;
86-
}
87-
88-
chunkIndex = 0;
8981
// insert clusters in batches of up to 100 rows
9082
while (chunkIndex < clusterValues.length) {
9183
const chunk = clusterValues.slice(chunkIndex, chunkIndex + maxChunk);
@@ -103,6 +95,15 @@ class CpfpRepository {
10395
);
10496
chunkIndex += maxChunk;
10597
}
98+
99+
chunkIndex = 0;
100+
// insert transactions in batches of up to 100 rows
101+
while (chunkIndex < txs.length) {
102+
const chunk = txs.slice(chunkIndex, chunkIndex + maxChunk);
103+
await transactionRepository.$batchSetCluster(chunk);
104+
chunkIndex += maxChunk;
105+
}
106+
106107
return true;
107108
} catch (e: any) {
108109
logger.err(`Cannot save cpfp clusters into db. Reason: ` + (e instanceof Error ? e.message : e));
@@ -120,8 +121,8 @@ class CpfpRepository {
120121
[clusterRoot]
121122
);
122123
const cluster = clusterRows[0];
123-
cluster.effectiveFeePerVsize = cluster.fee_rate;
124124
if (cluster?.txs) {
125+
cluster.effectiveFeePerVsize = cluster.fee_rate;
125126
cluster.txs = this.unpack(cluster.txs);
126127
return cluster;
127128
}

0 commit comments

Comments
 (0)