mirror of
https://github.com/mempool/mempool.git
synced 2025-02-23 14:40:38 +01:00
Remove buggy tx vout value fetching and improve performances
This commit is contained in:
parent
5287490894
commit
7fdf95ad34
1 changed files with 8 additions and 19 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { existsSync, promises } from 'fs';
|
import { existsSync, promises } from 'fs';
|
||||||
|
import bitcoinApiFactory from '../../../api/bitcoin/bitcoin-api-factory';
|
||||||
import bitcoinClient from '../../../api/bitcoin/bitcoin-client';
|
import bitcoinClient from '../../../api/bitcoin/bitcoin-client';
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import DB from '../../../database';
|
import DB from '../../../database';
|
||||||
|
@ -79,26 +80,10 @@ class FundingTxFetcher {
|
||||||
const outputIdx = parts[2];
|
const outputIdx = parts[2];
|
||||||
|
|
||||||
let block = this.blocksCache[blockHeight];
|
let block = this.blocksCache[blockHeight];
|
||||||
// Check if we have the block in the `blocks_summaries` table to avoid calling core
|
|
||||||
if (!block) {
|
|
||||||
const [rows] = await DB.query(`
|
|
||||||
SELECT UNIX_TIMESTAMP(blocks.blockTimestamp) AS time, blocks_summaries.transactions AS tx
|
|
||||||
FROM blocks_summaries
|
|
||||||
JOIN blocks ON blocks.hash = blocks_summaries.id
|
|
||||||
WHERE blocks_summaries.height = ${blockHeight}
|
|
||||||
`);
|
|
||||||
block = rows[0] ?? null;
|
|
||||||
if (block) {
|
|
||||||
block.tx = JSON.parse(block.tx);
|
|
||||||
if (block.tx.length === 0) {
|
|
||||||
block = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Fetch it from core
|
// Fetch it from core
|
||||||
if (!block) {
|
if (!block) {
|
||||||
const blockHash = await bitcoinClient.getBlockHash(parseInt(blockHeight, 10));
|
const blockHash = await bitcoinClient.getBlockHash(parseInt(blockHeight, 10));
|
||||||
block = await bitcoinClient.getBlock(blockHash, 2);
|
block = await bitcoinClient.getBlock(blockHash, 1);
|
||||||
}
|
}
|
||||||
this.blocksCache[block.height] = block;
|
this.blocksCache[block.height] = block;
|
||||||
|
|
||||||
|
@ -109,10 +94,14 @@ class FundingTxFetcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const txid = block.tx[txIdx];
|
||||||
|
const rawTx = await bitcoinClient.getRawTransaction(txid);
|
||||||
|
const tx = await bitcoinClient.decodeRawTransaction(rawTx);
|
||||||
|
|
||||||
this.fundingTxCache[channelId] = {
|
this.fundingTxCache[channelId] = {
|
||||||
timestamp: block.time,
|
timestamp: block.time,
|
||||||
txid: block.tx[txIdx].txid,
|
txid: txid,
|
||||||
value: block.tx[txIdx].value / 100000000 ?? block.tx[txIdx].vout[outputIdx].value,
|
value: tx.vout[outputIdx].value,
|
||||||
};
|
};
|
||||||
|
|
||||||
++this.channelNewlyProcessed;
|
++this.channelNewlyProcessed;
|
||||||
|
|
Loading…
Add table
Reference in a new issue