mirror of
https://github.com/mempool/mempool.git
synced 2025-02-24 22:58:30 +01:00
disable block audits unless indexing is enabled
This commit is contained in:
parent
968d7b827b
commit
6d28259515
2 changed files with 42 additions and 42 deletions
|
@ -4,9 +4,12 @@ import { BlockExtended, TransactionExtended, MempoolBlockWithTransactions } from
|
||||||
const PROPAGATION_MARGIN = 180; // in seconds, time since a transaction is first seen after which it is assumed to have propagated to all miners
|
const PROPAGATION_MARGIN = 180; // in seconds, time since a transaction is first seen after which it is assumed to have propagated to all miners
|
||||||
|
|
||||||
class Audit {
|
class Audit {
|
||||||
auditBlock(block: BlockExtended, txIds: string[], transactions: TransactionExtended[],
|
auditBlock(transactions: TransactionExtended[], projectedBlocks: MempoolBlockWithTransactions[], mempool: { [txId: string]: TransactionExtended })
|
||||||
projectedBlocks: MempoolBlockWithTransactions[], mempool: { [txId: string]: TransactionExtended },
|
: { censored: string[], added: string[], score: number } {
|
||||||
): { censored: string[], added: string[], score: number } {
|
if (!projectedBlocks?.[0]?.transactionIds || !mempool) {
|
||||||
|
return { censored: [], added: [], score: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
const matches: string[] = []; // present in both mined block and template
|
const matches: string[] = []; // present in both mined block and template
|
||||||
const added: string[] = []; // present in mined block, not in template
|
const added: string[] = []; // present in mined block, not in template
|
||||||
const fresh: string[] = []; // missing, but firstSeen within PROPAGATION_MARGIN
|
const fresh: string[] = []; // missing, but firstSeen within PROPAGATION_MARGIN
|
||||||
|
|
|
@ -250,8 +250,6 @@ class WebsocketHandler {
|
||||||
throw new Error('WebSocket.Server is not set');
|
throw new Error('WebSocket.Server is not set');
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("mempool changed!");
|
|
||||||
|
|
||||||
mempoolBlocks.updateMempoolBlocks(newMempool);
|
mempoolBlocks.updateMempoolBlocks(newMempool);
|
||||||
const mBlocks = mempoolBlocks.getMempoolBlocks();
|
const mBlocks = mempoolBlocks.getMempoolBlocks();
|
||||||
const mBlockDeltas = mempoolBlocks.getMempoolBlockDeltas();
|
const mBlockDeltas = mempoolBlocks.getMempoolBlockDeltas();
|
||||||
|
@ -417,55 +415,54 @@ class WebsocketHandler {
|
||||||
let mBlockDeltas: undefined | MempoolBlockDelta[];
|
let mBlockDeltas: undefined | MempoolBlockDelta[];
|
||||||
let matchRate = 0;
|
let matchRate = 0;
|
||||||
const _memPool = memPool.getMempool();
|
const _memPool = memPool.getMempool();
|
||||||
const mempoolCopy = cloneMempool(_memPool);
|
|
||||||
|
|
||||||
const projectedBlocks = mempoolBlocks.makeBlockTemplates(mempoolCopy, 2);
|
if (Common.indexingEnabled()) {
|
||||||
|
const mempoolCopy = cloneMempool(_memPool);
|
||||||
|
const projectedBlocks = mempoolBlocks.makeBlockTemplates(mempoolCopy, 2);
|
||||||
|
|
||||||
if (projectedBlocks[0]) {
|
const { censored, added, score } = Audit.auditBlock(transactions, projectedBlocks, mempoolCopy);
|
||||||
const { censored, added, score } = Audit.auditBlock(block, txIds, transactions, projectedBlocks, mempoolCopy);
|
|
||||||
matchRate = Math.round(score * 100 * 100) / 100;
|
matchRate = Math.round(score * 100 * 100) / 100;
|
||||||
|
|
||||||
// Update mempool to remove transactions included in the new block
|
const stripped = projectedBlocks[0]?.transactions ? projectedBlocks[0].transactions.map((tx) => {
|
||||||
for (const txId of txIds) {
|
return {
|
||||||
delete _memPool[txId];
|
txid: tx.txid,
|
||||||
}
|
vsize: tx.vsize,
|
||||||
|
fee: tx.fee ? Math.round(tx.fee) : 0,
|
||||||
|
value: tx.value,
|
||||||
|
};
|
||||||
|
}) : [];
|
||||||
|
|
||||||
mempoolBlocks.updateMempoolBlocks(_memPool);
|
BlocksSummariesRepository.$saveSummary({
|
||||||
mBlocks = mempoolBlocks.getMempoolBlocks();
|
height: block.height,
|
||||||
mBlockDeltas = mempoolBlocks.getMempoolBlockDeltas();
|
template: {
|
||||||
|
id: block.id,
|
||||||
|
transactions: stripped
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (Common.indexingEnabled()) {
|
BlocksAuditsRepository.$saveAudit({
|
||||||
const stripped = projectedBlocks[0].transactions.map((tx) => {
|
time: block.timestamp,
|
||||||
return {
|
height: block.height,
|
||||||
txid: tx.txid,
|
hash: block.id,
|
||||||
vsize: tx.vsize,
|
addedTxs: added,
|
||||||
fee: tx.fee ? Math.round(tx.fee) : 0,
|
missingTxs: censored,
|
||||||
value: tx.value,
|
matchRate: matchRate,
|
||||||
};
|
});
|
||||||
});
|
|
||||||
BlocksSummariesRepository.$saveSummary({
|
|
||||||
height: block.height,
|
|
||||||
template: {
|
|
||||||
id: block.id,
|
|
||||||
transactions: stripped
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
BlocksAuditsRepository.$saveAudit({
|
if (block.extras) {
|
||||||
time: block.timestamp,
|
block.extras.matchRate = matchRate;
|
||||||
height: block.height,
|
|
||||||
hash: block.id,
|
|
||||||
addedTxs: added,
|
|
||||||
missingTxs: censored,
|
|
||||||
matchRate: matchRate,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block.extras) {
|
// Update mempool to remove transactions included in the new block
|
||||||
block.extras.matchRate = matchRate;
|
for (const txId of txIds) {
|
||||||
|
delete _memPool[txId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mempoolBlocks.updateMempoolBlocks(_memPool);
|
||||||
|
mBlocks = mempoolBlocks.getMempoolBlocks();
|
||||||
|
mBlockDeltas = mempoolBlocks.getMempoolBlockDeltas();
|
||||||
|
|
||||||
const da = difficultyAdjustment.getDifficultyAdjustment();
|
const da = difficultyAdjustment.getDifficultyAdjustment();
|
||||||
const fees = feeApi.getRecommendedFee();
|
const fees = feeApi.getRecommendedFee();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue