Merge pull request #3886 from mempool/mononaut/hotfix-undefined-cpfp-cluster

Hotfix for undefined cpfp cluster bug
This commit is contained in:
wiz 2023-06-23 19:08:27 +09:00 committed by GitHub
commit e88cf70719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -224,7 +224,12 @@ class BitcoinRoutes {
} else { } else {
let cpfpInfo; let cpfpInfo;
if (config.DATABASE.ENABLED) { if (config.DATABASE.ENABLED) {
try {
cpfpInfo = await transactionRepository.$getCpfpInfo(req.params.txId); cpfpInfo = await transactionRepository.$getCpfpInfo(req.params.txId);
} catch (e) {
res.status(500).send('failed to get CPFP info');
return;
}
} }
if (cpfpInfo) { if (cpfpInfo) {
res.json(cpfpInfo); res.json(cpfpInfo);

View File

@ -78,14 +78,6 @@ class CpfpRepository {
const maxChunk = 100; const maxChunk = 100;
let chunkIndex = 0; 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 // insert clusters in batches of up to 100 rows
while (chunkIndex < clusterValues.length) { while (chunkIndex < clusterValues.length) {
const chunk = clusterValues.slice(chunkIndex, chunkIndex + maxChunk); const chunk = clusterValues.slice(chunkIndex, chunkIndex + maxChunk);
@ -103,6 +95,15 @@ class CpfpRepository {
); );
chunkIndex += maxChunk; 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; return true;
} catch (e: any) { } catch (e: any) {
logger.err(`Cannot save cpfp clusters into db. Reason: ` + (e instanceof Error ? e.message : e)); logger.err(`Cannot save cpfp clusters into db. Reason: ` + (e instanceof Error ? e.message : e));
@ -120,8 +121,8 @@ class CpfpRepository {
[clusterRoot] [clusterRoot]
); );
const cluster = clusterRows[0]; const cluster = clusterRows[0];
cluster.effectiveFeePerVsize = cluster.fee_rate;
if (cluster?.txs) { if (cluster?.txs) {
cluster.effectiveFeePerVsize = cluster.fee_rate;
cluster.txs = this.unpack(cluster.txs); cluster.txs = this.unpack(cluster.txs);
return cluster; return cluster;
} }