From 9270298374364a307c195e6c8b4c7a3f33dbe7da Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sun, 31 Mar 2024 08:53:09 +0000 Subject: [PATCH] Fix next block subsidy calculation --- .../difficulty/difficulty.component.html | 2 +- .../components/difficulty/difficulty.component.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/difficulty/difficulty.component.html b/frontend/src/app/components/difficulty/difficulty.component.html index d1de5f076..ff31d4f57 100644 --- a/frontend/src/app/components/difficulty/difficulty.component.html +++ b/frontend/src/app/components/difficulty/difficulty.component.html @@ -97,7 +97,7 @@
- +
New subsidy diff --git a/frontend/src/app/components/difficulty/difficulty.component.ts b/frontend/src/app/components/difficulty/difficulty.component.ts index 13f61dc5e..a58250653 100644 --- a/frontend/src/app/components/difficulty/difficulty.component.ts +++ b/frontend/src/app/components/difficulty/difficulty.component.ts @@ -62,6 +62,7 @@ export class DifficultyComponent implements OnInit { expectedIndex: number; difference: number; shapes: DiffShape[]; + nextSubsidy: number; tooltipPosition = { x: 0, y: 0 }; hoverSection: DiffShape | void; @@ -106,6 +107,7 @@ export class DifficultyComponent implements OnInit { const newEpochStart = Math.floor(this.stateService.latestBlockHeight / EPOCH_BLOCK_LENGTH) * EPOCH_BLOCK_LENGTH; const newExpectedHeight = Math.floor(newEpochStart + da.expectedBlocks); this.now = new Date().getTime(); + this.nextSubsidy = getNextBlockSubsidy(maxHeight); if (blocksUntilHalving < da.remainingBlocks && !this.userSelectedMode) { this.mode = 'halving'; @@ -233,3 +235,16 @@ export class DifficultyComponent implements OnInit { this.hoverSection = null; } } + +function getNextBlockSubsidy(height: number): number { + const halvings = Math.floor(height / 210_000) + 1; + // Force block reward to zero when right shift is undefined. + if (halvings >= 64) { + return 0; + } + + let subsidy = BigInt(50 * 100_000_000); + // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years. + subsidy >>= BigInt(halvings); + return Number(subsidy); +} \ No newline at end of file