From 037f472f8c82e2ee40750379f9db074e69cd860b Mon Sep 17 00:00:00 2001 From: softsimon Date: Sat, 31 Jul 2021 17:30:35 +0300 Subject: [PATCH] Make Block Weight Unit configurable in frontend+backend. --- backend/mempool-config.sample.json | 3 ++- backend/src/api/mempool-blocks.ts | 2 +- backend/src/config.ts | 2 ++ frontend/mempool-frontend-config.sample.json | 1 + frontend/src/app/components/footer/footer.component.ts | 2 +- .../components/mempool-block/mempool-block.component.html | 2 +- .../app/components/mempool-block/mempool-block.component.ts | 4 ++-- .../components/mempool-blocks/mempool-blocks.component.html | 4 ++-- .../components/mempool-blocks/mempool-blocks.component.ts | 6 +++--- .../app/components/mempool-graph/mempool-graph.component.ts | 2 +- frontend/src/app/dashboard/dashboard.component.ts | 2 +- frontend/src/app/services/state.service.ts | 5 +++++ 12 files changed, 22 insertions(+), 13 deletions(-) diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index bf0e15056..781f90698 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -8,7 +8,8 @@ "POLL_RATE_MS": 2000, "CACHE_DIR": "./cache", "CLEAR_PROTECTION_MINUTES": 20, - "RECOMMENDED_FEE_PERCENTILE": 50 + "RECOMMENDED_FEE_PERCENTILE": 50, + "BLOCK_WEIGHT_UNITS": 4000000 }, "CORE_RPC": { "HOST": "127.0.0.1", diff --git a/backend/src/api/mempool-blocks.ts b/backend/src/api/mempool-blocks.ts index a9c91103d..592da2877 100644 --- a/backend/src/api/mempool-blocks.ts +++ b/backend/src/api/mempool-blocks.ts @@ -76,7 +76,7 @@ class MempoolBlocks { let blockSize = 0; let transactions: TransactionExtended[] = []; transactionsSorted.forEach((tx) => { - if (blockVSize + tx.vsize <= 1000000 || mempoolBlocks.length === MempoolBlocks.DEFAULT_PROJECTED_BLOCKS_AMOUNT - 1) { + if (blockVSize + tx.weight <= config.MEMPOOL.BLOCK_WEIGHT_UNITS || mempoolBlocks.length === MempoolBlocks.DEFAULT_PROJECTED_BLOCKS_AMOUNT - 1) { blockVSize += tx.vsize; blockSize += tx.size; transactions.push(tx); diff --git a/backend/src/config.ts b/backend/src/config.ts index 4a2e4f588..ee811979c 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -11,6 +11,7 @@ interface IConfig { CACHE_DIR: string; CLEAR_PROTECTION_MINUTES: number; RECOMMENDED_FEE_PERCENTILE: number; + BLOCK_WEIGHT_UNITS: number; }; ESPLORA: { REST_API_URL: string; @@ -69,6 +70,7 @@ const defaults: IConfig = { 'CACHE_DIR': './cache', 'CLEAR_PROTECTION_MINUTES': 20, 'RECOMMENDED_FEE_PERCENTILE': 50, + 'BLOCK_WEIGHT_UNITS': 4000000, }, 'ESPLORA': { 'REST_API_URL': 'http://127.0.0.1:3000', diff --git a/frontend/mempool-frontend-config.sample.json b/frontend/mempool-frontend-config.sample.json index c737a2538..a5c9d1c07 100644 --- a/frontend/mempool-frontend-config.sample.json +++ b/frontend/mempool-frontend-config.sample.json @@ -9,5 +9,6 @@ "NGINX_PROTOCOL": "http", "NGINX_HOSTNAME": "127.0.0.1", "NGINX_PORT": "80", + "BLOCK_WEIGHT_UNITS": 4000000, "BASE_MODULE": "mempool" } diff --git a/frontend/src/app/components/footer/footer.component.ts b/frontend/src/app/components/footer/footer.component.ts index adfeece6a..17ecd78d8 100644 --- a/frontend/src/app/components/footer/footer.component.ts +++ b/frontend/src/app/components/footer/footer.component.ts @@ -64,7 +64,7 @@ export class FooterComponent implements OnInit { return { size: size, - blocks: Math.ceil(vsize / 1000000) + blocks: Math.ceil(vsize / this.stateService.blockVSize) }; }) ); diff --git a/frontend/src/app/components/mempool-block/mempool-block.component.html b/frontend/src/app/components/mempool-block/mempool-block.component.html index dfafb9241..744058614 100644 --- a/frontend/src/app/components/mempool-block/mempool-block.component.html +++ b/frontend/src/app/components/mempool-block/mempool-block.component.html @@ -32,7 +32,7 @@ Size
-
+
diff --git a/frontend/src/app/components/mempool-block/mempool-block.component.ts b/frontend/src/app/components/mempool-block/mempool-block.component.ts index 2e9365298..ead56736c 100644 --- a/frontend/src/app/components/mempool-block/mempool-block.component.ts +++ b/frontend/src/app/components/mempool-block/mempool-block.component.ts @@ -21,7 +21,7 @@ export class MempoolBlockComponent implements OnInit, OnDestroy { constructor( private route: ActivatedRoute, - private stateService: StateService, + public stateService: StateService, private seoService: SeoService, private websocketService: WebsocketService, ) { } @@ -66,7 +66,7 @@ export class MempoolBlockComponent implements OnInit, OnDestroy { } getOrdinal(mempoolBlock: MempoolBlock): string { - const blocksInBlock = Math.ceil(mempoolBlock.blockVSize / 1000000); + const blocksInBlock = Math.ceil(mempoolBlock.blockVSize / this.stateService.blockVSize); if (this.mempoolBlockIndex === 0) { return $localize`:@@mempool-block.next.block:Next block`; } else if (this.mempoolBlockIndex === this.stateService.env.KEEP_BLOCKS_AMOUNT - 1 && blocksInBlock > 1) { diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html index 4ffef5c91..97f47432f 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html @@ -16,7 +16,7 @@ {{ i }} transaction {{ i }} transactions -
+
@@ -26,7 +26,7 @@
- () + () {{ i }} blocks
diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts index 7846b9b71..607bcce61 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts @@ -44,7 +44,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { constructor( private router: Router, - private stateService: StateService, + public stateService: StateService, private cd: ChangeDetectorRef, ) { } @@ -202,7 +202,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { } getStyleForMempoolBlock(mempoolBlock: MempoolBlock, index: number) { - const emptyBackgroundSpacePercentage = Math.max(100 - mempoolBlock.blockVSize / 1000000 * 100, 0); + const emptyBackgroundSpacePercentage = Math.max(100 - mempoolBlock.blockVSize / this.stateService.blockVSize * 100, 0); const usedBlockSpace = 100 - emptyBackgroundSpacePercentage; const backgroundGradients = [`repeating-linear-gradient(to right, #554b45, #554b45 ${emptyBackgroundSpacePercentage}%`]; const gradientColors = []; @@ -262,7 +262,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { const chunkPositionOffset = blockLocation * feeRangeChunkSize; const feePosition = feeRangeChunkSize * feeRangeIndex + chunkPositionOffset; - const blockedFilledPercentage = (block.blockVSize > 1000000 ? 1000000 : block.blockVSize) / 1000000; + const blockedFilledPercentage = (block.blockVSize > this.stateService.blockVSize ? this.stateService.blockVSize : block.blockVSize) / this.stateService.blockVSize; const arrowRightPosition = txInBlockIndex * (this.blockWidth + this.blockPadding) + ((1 - feePosition) * blockedFilledPercentage * this.blockWidth); diff --git a/frontend/src/app/components/mempool-graph/mempool-graph.component.ts b/frontend/src/app/components/mempool-graph/mempool-graph.component.ts index 46d11d6f1..b227c9884 100644 --- a/frontend/src/app/components/mempool-graph/mempool-graph.component.ts +++ b/frontend/src/app/components/mempool-graph/mempool-graph.component.ts @@ -74,7 +74,7 @@ export class MempoolGraphComponent implements OnInit, OnChanges { labelInterpolationFnc: (value: number): any => this.vbytesPipe.transform(value, 2, 'vB', 'MvB', true), offset: this.showLegend ? 160 : 60, }, - plugins: this.inverted ? [Chartist.plugins.ctTargetLine({ value: 1000000 })] : [] + plugins: this.inverted ? [Chartist.plugins.ctTargetLine({ value: this.stateService.blockVSize })] : [] }; if (this.showLegend) { diff --git a/frontend/src/app/dashboard/dashboard.component.ts b/frontend/src/app/dashboard/dashboard.component.ts index f6424cc62..ab84f75b9 100644 --- a/frontend/src/app/dashboard/dashboard.component.ts +++ b/frontend/src/app/dashboard/dashboard.component.ts @@ -207,7 +207,7 @@ export class DashboardComponent implements OnInit { return { size: size, - blocks: Math.ceil(vsize / 1000000) + blocks: Math.ceil(vsize / this.stateService.blockVSize) }; }) ); diff --git a/frontend/src/app/services/state.service.ts b/frontend/src/app/services/state.service.ts index e66cc915a..00934ba5f 100644 --- a/frontend/src/app/services/state.service.ts +++ b/frontend/src/app/services/state.service.ts @@ -28,6 +28,7 @@ export interface Env { NGINX_PROTOCOL?: string; NGINX_HOSTNAME?: string; NGINX_PORT?: string; + BLOCK_WEIGHT_UNITS: number; GIT_COMMIT_HASH: string; PACKAGE_JSON_VERSION: string; } @@ -45,6 +46,7 @@ const defaultEnv: Env = { 'NGINX_PROTOCOL': 'http', 'NGINX_HOSTNAME': '127.0.0.1', 'NGINX_PORT': '80', + 'BLOCK_WEIGHT_UNITS': 4000000, 'GIT_COMMIT_HASH': '', 'PACKAGE_JSON_VERSION': '', }; @@ -55,6 +57,7 @@ const defaultEnv: Env = { export class StateService { isBrowser: boolean = isPlatformBrowser(this.platformId); network = ''; + blockVSize: number; env: Env; latestBlockHeight = 0; @@ -113,6 +116,8 @@ export class StateService { this.network = this.env.BASE_MODULE; this.networkChanged$.next(this.env.BASE_MODULE); } + + this.blockVSize = this.env.BLOCK_WEIGHT_UNITS / 4; } setNetworkBasedonUrl(url: string) {