From 42bfa6f30080ea620a2d3b59f8491eb348f1f3f0 Mon Sep 17 00:00:00 2001 From: natsoni Date: Sun, 22 Jun 2025 18:15:19 +0200 Subject: [PATCH] Use actual block weight instead of assumed full block weight in median fee calculation --- backend/src/api/common.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/src/api/common.ts b/backend/src/api/common.ts index 80542edb4..290548ee2 100644 --- a/backend/src/api/common.ts +++ b/backend/src/api/common.ts @@ -900,9 +900,11 @@ export class Common { let medianWeight = 0; // calculate the "medianFee" as the average fee rate of the middle 0.25% weight units of transactions - const halfWidth = config.MEMPOOL.BLOCK_WEIGHT_UNITS / 800; - const leftBound = Math.floor((config.MEMPOOL.BLOCK_WEIGHT_UNITS / 2) - halfWidth); - const rightBound = Math.ceil((config.MEMPOOL.BLOCK_WEIGHT_UNITS / 2) + halfWidth); + // Also ensure we use actual block weight rather than assuming full block + const effectiveBlockWeight = transactions.reduce((sum, tx) => sum + tx.weight, 0); + const halfWidth = effectiveBlockWeight / 800; + const leftBound = Math.floor((effectiveBlockWeight / 2) - halfWidth); + const rightBound = Math.ceil((effectiveBlockWeight / 2) + halfWidth); for (let i = 0; i < sortedTxs.length && weightCount < rightBound; i++) { const left = weightCount; const right = weightCount + sortedTxs[i].weight;