From 03255dd07783da80bc796d68c65664717e196278 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Mon, 1 Apr 2024 08:42:23 +0000 Subject: [PATCH] Improve marginal fee rate detection --- backend/src/api/audit.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/api/audit.ts b/backend/src/api/audit.ts index 8fa8cbdb1..fb0d05baa 100644 --- a/backend/src/api/audit.ts +++ b/backend/src/api/audit.ts @@ -83,11 +83,13 @@ class Audit { const tx = mempool[txid]; if (tx) { const fits = (tx.weight - displacedWeightRemaining) < 4000; - const feeMatches = tx.effectiveFeePerVsize >= lastFeeRate; + // 0.005 margin of error for any remaining vsize rounding issues + const feeMatches = tx.effectiveFeePerVsize >= (lastFeeRate - 0.005); if (fits || feeMatches) { isDisplaced[txid] = true; if (fits) { - lastFeeRate = Math.min(lastFeeRate, tx.effectiveFeePerVsize); + // (tx.effectiveFeePerVsize * tx.vsize) / Math.ceil(tx.vsize) attempts to correct for vsize rounding in the simple non-CPFP case + lastFeeRate = Math.min(lastFeeRate, (tx.effectiveFeePerVsize * tx.vsize) / Math.ceil(tx.vsize)); } if (tx.firstSeen == null || (now - (tx?.firstSeen || 0)) > PROPAGATION_MARGIN) { displacedWeightRemaining -= tx.weight;