From 8dc80eadf32fb41681841cacb060e9e667bcbdd1 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 22 Nov 2023 13:10:53 +0900 Subject: [PATCH 1/2] Fix health score when mempool was empty --- backend/src/api/audit.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/api/audit.ts b/backend/src/api/audit.ts index e78b2796f..5aa04637d 100644 --- a/backend/src/api/audit.ts +++ b/backend/src/api/audit.ts @@ -144,7 +144,12 @@ class Audit { const numCensored = Object.keys(isCensored).length; const numMatches = matches.length - 1; // adjust for coinbase tx - const score = numMatches > 0 ? (numMatches / (numMatches + numCensored)) : 0; + let score = 0; + if (numMatches <= 0 && numCensored <= 0) { + score = 1; + } else if (numMatches > 0) { + score = (numMatches / (numMatches + numCensored)); + } const similarity = projectedWeight ? matchedWeight / projectedWeight : 1; return { From 75cc84467640f55dbbeaf8b7e4e4727bc012806f Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 22 Nov 2023 19:53:22 +0900 Subject: [PATCH 2/2] actually fix empty mempool health score --- backend/src/api/audit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/api/audit.ts b/backend/src/api/audit.ts index 5aa04637d..0ddfc2cc2 100644 --- a/backend/src/api/audit.ts +++ b/backend/src/api/audit.ts @@ -9,7 +9,7 @@ class Audit { auditBlock(transactions: MempoolTransactionExtended[], projectedBlocks: MempoolBlockWithTransactions[], mempool: { [txId: string]: MempoolTransactionExtended }, useAccelerations: boolean = false) : { censored: string[], added: string[], fresh: string[], sigop: string[], fullrbf: string[], accelerated: string[], score: number, similarity: number } { if (!projectedBlocks?.[0]?.transactionIds || !mempool) { - return { censored: [], added: [], fresh: [], sigop: [], fullrbf: [], accelerated: [], score: 0, similarity: 1 }; + return { censored: [], added: [], fresh: [], sigop: [], fullrbf: [], accelerated: [], score: 1, similarity: 1 }; } const matches: string[] = []; // present in both mined block and template