Merge pull request #4842 from mempool/mononaut/halving-widget-fixes

Fix next block subsidy calculation
This commit is contained in:
softsimon 2024-03-31 18:04:57 +09:00 committed by GitHub
commit 19dcc9d62d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -97,7 +97,7 @@
<div class="difficulty-stats"> <div class="difficulty-stats">
<div class="item"> <div class="item">
<div class="card-text bigger"> <div class="card-text bigger">
<app-btc [satoshis]="312500000"></app-btc> <app-btc [satoshis]="nextSubsidy"></app-btc>
</div> </div>
<div class="symbol"> <div class="symbol">
<span i18n="difficulty-box.new-subsidy">New subsidy</span> <span i18n="difficulty-box.new-subsidy">New subsidy</span>

View File

@ -62,6 +62,7 @@ export class DifficultyComponent implements OnInit {
expectedIndex: number; expectedIndex: number;
difference: number; difference: number;
shapes: DiffShape[]; shapes: DiffShape[];
nextSubsidy: number;
tooltipPosition = { x: 0, y: 0 }; tooltipPosition = { x: 0, y: 0 };
hoverSection: DiffShape | void; 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 newEpochStart = Math.floor(this.stateService.latestBlockHeight / EPOCH_BLOCK_LENGTH) * EPOCH_BLOCK_LENGTH;
const newExpectedHeight = Math.floor(newEpochStart + da.expectedBlocks); const newExpectedHeight = Math.floor(newEpochStart + da.expectedBlocks);
this.now = new Date().getTime(); this.now = new Date().getTime();
this.nextSubsidy = getNextBlockSubsidy(maxHeight);
if (blocksUntilHalving < da.remainingBlocks && !this.userSelectedMode) { if (blocksUntilHalving < da.remainingBlocks && !this.userSelectedMode) {
this.mode = 'halving'; this.mode = 'halving';
@ -233,3 +235,16 @@ export class DifficultyComponent implements OnInit {
this.hoverSection = null; 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);
}