mirror of
https://github.com/mempool/mempool.git
synced 2025-02-22 22:25:34 +01:00
Amount of projected blocks is now a config.
This commit is contained in:
parent
8dd58db42a
commit
76f8af9048
3 changed files with 31 additions and 35 deletions
|
@ -13,6 +13,7 @@
|
|||
"CHAT_SSL_CHAIN": "",
|
||||
"MEMPOOL_REFRESH_RATE_MS": 500,
|
||||
"INITIAL_BLOCK_AMOUNT": 8,
|
||||
"DEFAULT_PROJECTED_BLOCKS_AMOUNT": 3,
|
||||
"KEEP_BLOCK_AMOUNT": 24,
|
||||
"BITCOIN_NODE_HOST": "localhost",
|
||||
"BITCOIN_NODE_PORT": 18332,
|
||||
|
|
|
@ -1,29 +1,13 @@
|
|||
const config = require('../../mempool-config.json');
|
||||
import { ITransaction, IProjectedBlock, IMempool, IProjectedBlockInternal } from '../interfaces';
|
||||
|
||||
class ProjectedBlocks {
|
||||
private projectedBlocks: IProjectedBlockInternal[] = [];
|
||||
private transactionsSorted: ITransaction[] = [];
|
||||
|
||||
constructor() {}
|
||||
|
||||
public getProjectedBlocks(txId?: string): IProjectedBlock[] {
|
||||
return this.projectedBlocks.map((projectedBlock) => {
|
||||
return {
|
||||
blockSize: projectedBlock.blockSize,
|
||||
blockWeight: projectedBlock.blockWeight,
|
||||
nTx: projectedBlock.nTx,
|
||||
minFee: projectedBlock.minFee,
|
||||
maxFee: projectedBlock.maxFee,
|
||||
minWeightFee: projectedBlock.minWeightFee,
|
||||
maxWeightFee: projectedBlock.maxWeightFee,
|
||||
medianFee: projectedBlock.medianFee,
|
||||
fees: projectedBlock.fees,
|
||||
hasMytx: txId ? projectedBlock.txIds.some((tx) => tx === txId) : false
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public getProjectedBlockFeesForBlock(index: number) {
|
||||
const projectedBlock = this.projectedBlocks[index];
|
||||
const projectedBlock = this.getProjectedBlocksInternal()[index];
|
||||
|
||||
if (!projectedBlock) {
|
||||
throw new Error('No projected block for that index');
|
||||
|
@ -42,20 +26,34 @@ class ProjectedBlocks {
|
|||
memPoolArray.push(latestMempool[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!memPoolArray.length) {
|
||||
this.projectedBlocks = [];
|
||||
}
|
||||
|
||||
memPoolArray.sort((a, b) => b.feePerWeightUnit - a.feePerWeightUnit);
|
||||
const memPoolArrayFiltered = memPoolArray.filter((tx) => tx.feePerWeightUnit);
|
||||
const projectedBlocks: any = [];
|
||||
this.transactionsSorted = memPoolArray.filter((tx) => tx.feePerWeightUnit);
|
||||
}
|
||||
|
||||
public getProjectedBlocks(txId?: string, numberOfBlocks: number = config.DEFAULT_PROJECTED_BLOCKS_AMOUNT): IProjectedBlock[] {
|
||||
return this.getProjectedBlocksInternal(numberOfBlocks).map((projectedBlock) => {
|
||||
return {
|
||||
blockSize: projectedBlock.blockSize,
|
||||
blockWeight: projectedBlock.blockWeight,
|
||||
nTx: projectedBlock.nTx,
|
||||
minFee: projectedBlock.minFee,
|
||||
maxFee: projectedBlock.maxFee,
|
||||
minWeightFee: projectedBlock.minWeightFee,
|
||||
maxWeightFee: projectedBlock.maxWeightFee,
|
||||
medianFee: projectedBlock.medianFee,
|
||||
fees: projectedBlock.fees,
|
||||
hasMytx: txId ? projectedBlock.txIds.some((tx) => tx === txId) : false
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private getProjectedBlocksInternal(numberOfBlocks: number = config.DEFAULT_PROJECTED_BLOCKS_AMOUNT): IProjectedBlockInternal[] {
|
||||
const projectedBlocks: IProjectedBlockInternal[] = [];
|
||||
let blockWeight = 0;
|
||||
let blockSize = 0;
|
||||
let transactions: ITransaction[] = [];
|
||||
memPoolArrayFiltered.forEach((tx) => {
|
||||
if (blockWeight + tx.vsize * 4 < 4000000 || projectedBlocks.length === 3) {
|
||||
this.transactionsSorted.forEach((tx) => {
|
||||
if (blockWeight + tx.vsize * 4 < 4000000 || projectedBlocks.length === numberOfBlocks) {
|
||||
blockWeight += tx.vsize * 4;
|
||||
blockSize += tx.size;
|
||||
transactions.push(tx);
|
||||
|
@ -69,7 +67,7 @@ class ProjectedBlocks {
|
|||
if (transactions.length) {
|
||||
projectedBlocks.push(this.dataToProjectedBlock(transactions, blockSize, blockWeight));
|
||||
}
|
||||
this.projectedBlocks = projectedBlocks;
|
||||
return projectedBlocks;
|
||||
}
|
||||
|
||||
private dataToProjectedBlock(transactions: ITransaction[], blockSize: number, blockWeight: number): IProjectedBlockInternal {
|
||||
|
|
|
@ -44,7 +44,9 @@ export class ApiService {
|
|||
this.memPoolService.blocks$.next(response.block);
|
||||
}
|
||||
|
||||
if (response.projectedBlocks) {
|
||||
if (response.projectedBlocks && response.projectedBlocks.length) {
|
||||
const mempoolWeight = response.projectedBlocks.map((block: any) => block.blockWeight).reduce((a: any, b: any) => a + b);
|
||||
this.memPoolService.mempoolWeight$.next(mempoolWeight);
|
||||
this.memPoolService.projectedBlocks$.next(response.projectedBlocks);
|
||||
}
|
||||
|
||||
|
@ -60,11 +62,6 @@ export class ApiService {
|
|||
this.memPoolService.conversions$.next(response.conversions);
|
||||
}
|
||||
|
||||
if (response.projectedBlocks) {
|
||||
const mempoolWeight = response.projectedBlocks.map((block: any) => block.blockWeight).reduce((a: any, b: any) => a + b);
|
||||
this.memPoolService.mempoolWeight$.next(mempoolWeight);
|
||||
}
|
||||
|
||||
if (response['track-tx']) {
|
||||
let txTrackingEnabled;
|
||||
let txTrackingBlockHeight;
|
||||
|
|
Loading…
Add table
Reference in a new issue