Adding configuration for blocks and mempool blocks amount.

This commit is contained in:
softsimon 2021-07-31 17:56:10 +03:00
parent 037f472f8c
commit 1908b1a5a6
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
9 changed files with 23 additions and 16 deletions

View File

@ -9,7 +9,9 @@
"CACHE_DIR": "./cache", "CACHE_DIR": "./cache",
"CLEAR_PROTECTION_MINUTES": 20, "CLEAR_PROTECTION_MINUTES": 20,
"RECOMMENDED_FEE_PERCENTILE": 50, "RECOMMENDED_FEE_PERCENTILE": 50,
"BLOCK_WEIGHT_UNITS": 4000000 "BLOCK_WEIGHT_UNITS": 4000000,
"INITIAL_BLOCKS_AMOUNT": 8,
"MEMPOOL_BLOCKS_AMOUNT": 8
}, },
"CORE_RPC": { "CORE_RPC": {
"HOST": "127.0.0.1", "HOST": "127.0.0.1",

View File

@ -8,7 +8,6 @@ import diskCache from './disk-cache';
import transactionUtils from './transaction-utils'; import transactionUtils from './transaction-utils';
class Blocks { class Blocks {
private static INITIAL_BLOCK_AMOUNT = 8;
private blocks: BlockExtended[] = []; private blocks: BlockExtended[] = [];
private currentBlockHeight = 0; private currentBlockHeight = 0;
private currentDifficulty = 0; private currentDifficulty = 0;
@ -34,14 +33,14 @@ class Blocks {
const blockHeightTip = await bitcoinApi.$getBlockHeightTip(); const blockHeightTip = await bitcoinApi.$getBlockHeightTip();
if (this.blocks.length === 0) { if (this.blocks.length === 0) {
this.currentBlockHeight = blockHeightTip - Blocks.INITIAL_BLOCK_AMOUNT; this.currentBlockHeight = blockHeightTip - config.MEMPOOL.INITIAL_BLOCKS_AMOUNT;
} else { } else {
this.currentBlockHeight = this.blocks[this.blocks.length - 1].height; this.currentBlockHeight = this.blocks[this.blocks.length - 1].height;
} }
if (blockHeightTip - this.currentBlockHeight > Blocks.INITIAL_BLOCK_AMOUNT * 2) { if (blockHeightTip - this.currentBlockHeight > config.MEMPOOL.INITIAL_BLOCKS_AMOUNT * 2) {
logger.info(`${blockHeightTip - this.currentBlockHeight} blocks since tip. Fast forwarding to the ${Blocks.INITIAL_BLOCK_AMOUNT} recent blocks`); logger.info(`${blockHeightTip - this.currentBlockHeight} blocks since tip. Fast forwarding to the ${config.MEMPOOL.INITIAL_BLOCKS_AMOUNT} recent blocks`);
this.currentBlockHeight = blockHeightTip - Blocks.INITIAL_BLOCK_AMOUNT; this.currentBlockHeight = blockHeightTip - config.MEMPOOL.INITIAL_BLOCKS_AMOUNT;
} }
if (!this.lastDifficultyAdjustmentTime) { if (!this.lastDifficultyAdjustmentTime) {
@ -114,8 +113,8 @@ class Blocks {
} }
this.blocks.push(blockExtended); this.blocks.push(blockExtended);
if (this.blocks.length > Blocks.INITIAL_BLOCK_AMOUNT * 4) { if (this.blocks.length > config.MEMPOOL.INITIAL_BLOCKS_AMOUNT * 4) {
this.blocks = this.blocks.slice(-Blocks.INITIAL_BLOCK_AMOUNT * 4); this.blocks = this.blocks.slice(-config.MEMPOOL.INITIAL_BLOCKS_AMOUNT * 4);
} }
if (this.newBlockCallbacks.length) { if (this.newBlockCallbacks.length) {

View File

@ -4,7 +4,6 @@ import { Common } from './common';
import config from '../config'; import config from '../config';
class MempoolBlocks { class MempoolBlocks {
private static DEFAULT_PROJECTED_BLOCKS_AMOUNT = 8;
private mempoolBlocks: MempoolBlockWithTransactions[] = []; private mempoolBlocks: MempoolBlockWithTransactions[] = [];
constructor() {} constructor() {}
@ -76,7 +75,7 @@ class MempoolBlocks {
let blockSize = 0; let blockSize = 0;
let transactions: TransactionExtended[] = []; let transactions: TransactionExtended[] = [];
transactionsSorted.forEach((tx) => { transactionsSorted.forEach((tx) => {
if (blockVSize + tx.weight <= config.MEMPOOL.BLOCK_WEIGHT_UNITS || mempoolBlocks.length === MempoolBlocks.DEFAULT_PROJECTED_BLOCKS_AMOUNT - 1) { if (blockVSize + tx.weight <= config.MEMPOOL.BLOCK_WEIGHT_UNITS || mempoolBlocks.length === config.MEMPOOL.MEMPOOL_BLOCKS_AMOUNT - 1) {
blockVSize += tx.vsize; blockVSize += tx.vsize;
blockSize += tx.size; blockSize += tx.size;
transactions.push(tx); transactions.push(tx);

View File

@ -90,7 +90,7 @@ class WebsocketHandler {
} }
if (parsedMessage.action === 'init') { if (parsedMessage.action === 'init') {
const _blocks = blocks.getBlocks().slice(-8); const _blocks = blocks.getBlocks().slice(-config.MEMPOOL.INITIAL_BLOCKS_AMOUNT);
if (!_blocks) { if (!_blocks) {
return; return;
} }
@ -166,7 +166,7 @@ class WebsocketHandler {
getInitData(_blocks?: BlockExtended[]) { getInitData(_blocks?: BlockExtended[]) {
if (!_blocks) { if (!_blocks) {
_blocks = blocks.getBlocks().slice(-8); _blocks = blocks.getBlocks().slice(-config.MEMPOOL.INITIAL_BLOCKS_AMOUNT);
} }
return { return {
'mempoolInfo': memPool.getMempoolInfo(), 'mempoolInfo': memPool.getMempoolInfo(),

View File

@ -12,6 +12,8 @@ interface IConfig {
CLEAR_PROTECTION_MINUTES: number; CLEAR_PROTECTION_MINUTES: number;
RECOMMENDED_FEE_PERCENTILE: number; RECOMMENDED_FEE_PERCENTILE: number;
BLOCK_WEIGHT_UNITS: number; BLOCK_WEIGHT_UNITS: number;
INITIAL_BLOCKS_AMOUNT: number;
MEMPOOL_BLOCKS_AMOUNT: number;
}; };
ESPLORA: { ESPLORA: {
REST_API_URL: string; REST_API_URL: string;
@ -71,6 +73,8 @@ const defaults: IConfig = {
'CLEAR_PROTECTION_MINUTES': 20, 'CLEAR_PROTECTION_MINUTES': 20,
'RECOMMENDED_FEE_PERCENTILE': 50, 'RECOMMENDED_FEE_PERCENTILE': 50,
'BLOCK_WEIGHT_UNITS': 4000000, 'BLOCK_WEIGHT_UNITS': 4000000,
'INITIAL_BLOCKS_AMOUNT': 8,
'MEMPOOL_BLOCKS_AMOUNT': 8,
}, },
'ESPLORA': { 'ESPLORA': {
'REST_API_URL': 'http://127.0.0.1:3000', 'REST_API_URL': 'http://127.0.0.1:3000',

View File

@ -9,6 +9,7 @@
"NGINX_PROTOCOL": "http", "NGINX_PROTOCOL": "http",
"NGINX_HOSTNAME": "127.0.0.1", "NGINX_HOSTNAME": "127.0.0.1",
"NGINX_PORT": "80", "NGINX_PORT": "80",
"MEMPOOL_BLOCKS_AMOUNT": 8,
"BLOCK_WEIGHT_UNITS": 4000000, "BLOCK_WEIGHT_UNITS": 4000000,
"BASE_MODULE": "mempool" "BASE_MODULE": "mempool"
} }

View File

@ -183,7 +183,7 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy {
} }
mountEmptyBlocks() { mountEmptyBlocks() {
const emptyBlocks = []; const emptyBlocks = [];
for (let i = 0; i < 9; i++) { for (let i = 0; i < this.stateService.env.KEEP_BLOCKS_AMOUNT; i++) {
emptyBlocks.push({ emptyBlocks.push({
id: '', id: '',
height: 0, height: 0,

View File

@ -144,7 +144,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
this.router.navigate([(this.network ? '/' + this.network : '') + '/mempool-block/', this.markIndex - 1]); this.router.navigate([(this.network ? '/' + this.network : '') + '/mempool-block/', this.markIndex - 1]);
} else { } else {
this.stateService.blocks$ this.stateService.blocks$
.pipe(take(8)) .pipe(take(this.stateService.env.MEMPOOL_BLOCKS_AMOUNT))
.subscribe(([block]) => { .subscribe(([block]) => {
if (this.stateService.latestBlockHeight === block.height) { if (this.stateService.latestBlockHeight === block.height) {
this.router.navigate([(this.network ? '/' + this.network : '') + '/block/', block.id], { state: { data: { block } }}); this.router.navigate([(this.network ? '/' + this.network : '') + '/block/', block.id], { state: { data: { block } }});
@ -275,8 +275,8 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
mountEmptyBlocks() { mountEmptyBlocks() {
const emptyBlocks = []; const emptyBlocks = [];
const numberOfBlocks = 8; const numberOfBlocks = this.stateService.env.MEMPOOL_BLOCKS_AMOUNT;
for (let i = 0; i <= numberOfBlocks; i++) { for (let i = 0; i < numberOfBlocks; i++) {
emptyBlocks.push({ emptyBlocks.push({
blockSize: 0, blockSize: 0,
blockVSize: 0, blockVSize: 0,

View File

@ -29,6 +29,7 @@ export interface Env {
NGINX_HOSTNAME?: string; NGINX_HOSTNAME?: string;
NGINX_PORT?: string; NGINX_PORT?: string;
BLOCK_WEIGHT_UNITS: number; BLOCK_WEIGHT_UNITS: number;
MEMPOOL_BLOCKS_AMOUNT: number;
GIT_COMMIT_HASH: string; GIT_COMMIT_HASH: string;
PACKAGE_JSON_VERSION: string; PACKAGE_JSON_VERSION: string;
} }
@ -47,6 +48,7 @@ const defaultEnv: Env = {
'NGINX_HOSTNAME': '127.0.0.1', 'NGINX_HOSTNAME': '127.0.0.1',
'NGINX_PORT': '80', 'NGINX_PORT': '80',
'BLOCK_WEIGHT_UNITS': 4000000, 'BLOCK_WEIGHT_UNITS': 4000000,
'MEMPOOL_BLOCKS_AMOUNT': 8,
'GIT_COMMIT_HASH': '', 'GIT_COMMIT_HASH': '',
'PACKAGE_JSON_VERSION': '', 'PACKAGE_JSON_VERSION': '',
}; };