Add recommended fee percentile config (#394)

This commit is contained in:
andrewtoth
2021-03-18 05:52:46 +00:00
committed by GitHub
parent baa75b77a7
commit ac4588cdab
4 changed files with 13 additions and 2 deletions

View File

@@ -12,6 +12,13 @@ export class Common {
return medianNr;
}
static percentile(numbers: number[], percentile: number) {
if (percentile === 50) return this.median(numbers);
const index = Math.ceil(numbers.length * (100 - percentile) * 1e-2);
if (index < 0 || index > numbers.length - 1) return 0;
return numbers[index];
}
static getFeesInRange(transactions: TransactionExtended[], rangeLength: number) {
const arr = [transactions[transactions.length - 1].feePerVsize];
const chunk = 1 / (rangeLength - 1);

View File

@@ -1,5 +1,6 @@
import { MempoolBlock, TransactionExtended, MempoolBlockWithTransactions } from '../mempool.interfaces';
import { Common } from './common';
import config from '../config';
class MempoolBlocks {
private static DEFAULT_PROJECTED_BLOCKS_AMOUNT = 8;
@@ -76,7 +77,7 @@ class MempoolBlocks {
blockVSize: blockVSize,
nTx: transactions.length,
totalFees: transactions.reduce((acc, cur) => acc + cur.fee, 0),
medianFee: Common.median(transactions.map((tx) => tx.feePerVsize)),
medianFee: Common.percentile(transactions.map((tx) => tx.feePerVsize), config.MEMPOOL.RECOMMENDED_FEE_PERCENTILE),
feeRange: Common.getFeesInRange(transactions, rangeLength),
transactionIds: transactions.map((tx) => tx.txid),
};