From 53730920e3571a954a1956f41886cb693800d334 Mon Sep 17 00:00:00 2001 From: softsimon Date: Sat, 14 Aug 2021 03:24:31 +0300 Subject: [PATCH] Bugfix: Mempool block sizes were mixing up vsize and weight. --- backend/src/api/mempool-blocks.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/api/mempool-blocks.ts b/backend/src/api/mempool-blocks.ts index 92da3eab9..0eeacbbbb 100644 --- a/backend/src/api/mempool-blocks.ts +++ b/backend/src/api/mempool-blocks.ts @@ -71,29 +71,29 @@ class MempoolBlocks { private calculateMempoolBlocks(transactionsSorted: TransactionExtended[]): MempoolBlockWithTransactions[] { const mempoolBlocks: MempoolBlockWithTransactions[] = []; - let blockVSize = 0; + let blockWeight = 0; let blockSize = 0; let transactions: TransactionExtended[] = []; transactionsSorted.forEach((tx) => { - if (blockVSize + tx.weight <= config.MEMPOOL.BLOCK_WEIGHT_UNITS || mempoolBlocks.length === config.MEMPOOL.MEMPOOL_BLOCKS_AMOUNT) { - blockVSize += tx.vsize; + if (blockWeight + tx.weight <= config.MEMPOOL.BLOCK_WEIGHT_UNITS || mempoolBlocks.length === config.MEMPOOL.MEMPOOL_BLOCKS_AMOUNT) { + blockWeight += tx.weight; blockSize += tx.size; transactions.push(tx); } else { - mempoolBlocks.push(this.dataToMempoolBlocks(transactions, blockSize, blockVSize, mempoolBlocks.length)); - blockVSize = tx.vsize; + mempoolBlocks.push(this.dataToMempoolBlocks(transactions, blockSize, blockWeight, mempoolBlocks.length)); + blockWeight = tx.weight; blockSize = tx.size; transactions = [tx]; } }); if (transactions.length) { - mempoolBlocks.push(this.dataToMempoolBlocks(transactions, blockSize, blockVSize, mempoolBlocks.length)); + mempoolBlocks.push(this.dataToMempoolBlocks(transactions, blockSize, blockWeight, mempoolBlocks.length)); } return mempoolBlocks; } private dataToMempoolBlocks(transactions: TransactionExtended[], - blockSize: number, blockVSize: number, blocksIndex: number): MempoolBlockWithTransactions { + blockSize: number, blockWeight: number, blocksIndex: number): MempoolBlockWithTransactions { let rangeLength = 4; if (blocksIndex === 0) { rangeLength = 8; @@ -105,7 +105,7 @@ class MempoolBlocks { } return { blockSize: blockSize, - blockVSize: blockVSize, + blockVSize: blockWeight / 4, nTx: transactions.length, totalFees: transactions.reduce((acc, cur) => acc + cur.fee, 0), medianFee: Common.percentile(transactions.map((tx) => tx.effectiveFeePerVsize), config.MEMPOOL.RECOMMENDED_FEE_PERCENTILE),