From fc0af50ab57bc1f5d04977cf1b2e17cf2c953433 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Thu, 19 Jan 2023 11:09:03 -0600 Subject: [PATCH] Fix bugged mempool block gradients --- backend/src/api/common.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/src/api/common.ts b/backend/src/api/common.ts index f0c5c6b88..29dad1a5d 100644 --- a/backend/src/api/common.ts +++ b/backend/src/api/common.ts @@ -35,16 +35,25 @@ export class Common { } static getFeesInRange(transactions: TransactionExtended[], rangeLength: number) { - const arr = [transactions[transactions.length - 1].effectiveFeePerVsize]; + const filtered: TransactionExtended[] = []; + let lastValidRate = Infinity; + // filter out anomalous fee rates to ensure monotonic range + for (const tx of transactions) { + if (tx.effectiveFeePerVsize <= lastValidRate) { + filtered.push(tx); + lastValidRate = tx.effectiveFeePerVsize; + } + } + const arr = [filtered[filtered.length - 1].effectiveFeePerVsize]; const chunk = 1 / (rangeLength - 1); let itemsToAdd = rangeLength - 2; while (itemsToAdd > 0) { - arr.push(transactions[Math.floor(transactions.length * chunk * itemsToAdd)].effectiveFeePerVsize); + arr.push(filtered[Math.floor(filtered.length * chunk * itemsToAdd)].effectiveFeePerVsize); itemsToAdd--; } - arr.push(transactions[0].effectiveFeePerVsize); + arr.push(filtered[0].effectiveFeePerVsize); return arr; }