Calculate similarity score with audit disabled
This commit is contained in:
parent
c24724dcdf
commit
25aacb5046
@ -1,4 +1,4 @@
|
|||||||
import { CpfpInfo, TransactionExtended, TransactionStripped } from '../mempool.interfaces';
|
import { CpfpInfo, MempoolBlockWithTransactions, TransactionExtended, TransactionStripped } from '../mempool.interfaces';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import { NodeSocket } from '../repositories/NodesSocketsRepository';
|
import { NodeSocket } from '../repositories/NodesSocketsRepository';
|
||||||
import { isIP } from 'net';
|
import { isIP } from 'net';
|
||||||
@ -164,6 +164,30 @@ export class Common {
|
|||||||
return parents;
|
return parents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// calculates the ratio of matched transactions to projected transactions by weight
|
||||||
|
static getSimilarity(projectedBlock: MempoolBlockWithTransactions, transactions: TransactionExtended[]): number {
|
||||||
|
let matchedWeight = 0;
|
||||||
|
let projectedWeight = 0;
|
||||||
|
const inBlock = {};
|
||||||
|
|
||||||
|
for (const tx of transactions) {
|
||||||
|
inBlock[tx.txid] = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// look for transactions that were expected in the template, but missing from the mined block
|
||||||
|
for (const tx of projectedBlock.transactions) {
|
||||||
|
if (inBlock[tx.txid]) {
|
||||||
|
matchedWeight += tx.vsize * 4;
|
||||||
|
}
|
||||||
|
projectedWeight += tx.vsize * 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
projectedWeight += transactions[0].weight;
|
||||||
|
matchedWeight += transactions[0].weight;
|
||||||
|
|
||||||
|
return projectedWeight ? matchedWeight / projectedWeight : 1;
|
||||||
|
}
|
||||||
|
|
||||||
static getSqlInterval(interval: string | null): string | null {
|
static getSqlInterval(interval: string | null): string | null {
|
||||||
switch (interval) {
|
switch (interval) {
|
||||||
case '24h': return '1 DAY';
|
case '24h': return '1 DAY';
|
||||||
|
@ -467,6 +467,9 @@ class WebsocketHandler {
|
|||||||
block.extras.similarity = similarity;
|
block.extras.similarity = similarity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (block.extras) {
|
||||||
|
const mBlocks = mempoolBlocks.getMempoolBlocksWithTransactions();
|
||||||
|
block.extras.similarity = Common.getSimilarity(mBlocks[0], transactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
const removed: string[] = [];
|
const removed: string[] = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user