Merge pull request #941 from mempool/simon/hide-early-difficulty-adjustment

Handle recent difficulty adjustment estimate gracefully
This commit is contained in:
wiz 2021-11-17 19:29:48 +09:00 committed by GitHub
commit 5b9ae2eaf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 17 deletions

View File

@ -724,14 +724,16 @@ class Routes {
const nextRetargetHeight = blockHeight + remainingBlocks;
let difficultyChange = 0;
if (blocksInEpoch > 0) {
difficultyChange = (600 / (diff / blocksInEpoch ) - 1) * 100;
}
if (difficultyChange > 300) {
difficultyChange = 300;
}
if (difficultyChange < -75) {
difficultyChange = -75;
if (remainingBlocks < 1870) {
if (blocksInEpoch > 0) {
difficultyChange = (600 / (diff / blocksInEpoch ) - 1) * 100;
}
if (difficultyChange > 300) {
difficultyChange = 300;
}
if (difficultyChange < -75) {
difficultyChange = -75;
}
}
const timeAvgDiff = difficultyChange * 0.1;

View File

@ -242,7 +242,7 @@
</div>
<div class="item">
<h5 class="card-title" i18n="difficulty-box.estimate">Estimate</h5>
<div class="card-text" [ngStyle]="{'color': epochData.colorAdjustments}">
<div *ngIf="epochData.remainingBlocks < 1870; else recentlyAdjusted" class="card-text" [ngStyle]="{'color': epochData.colorAdjustments}">
<span *ngIf="epochData.change > 0; else arrowDownDifficulty" >
<fa-icon class="retarget-sign" [icon]="['fas', 'caret-up']" [fixedWidth]="true"></fa-icon>
</span>
@ -252,6 +252,9 @@
{{ epochData.change | absolute | number: '1.2-2' }}
<span class="symbol">%</span>
</div>
<ng-template #recentlyAdjusted>
<div class="card-text">&#8212;</div>
</ng-template>
<div class="symbol">
<span i18n="difficulty-box.previous">Previous</span>:
<span [ngStyle]="{'color': epochData.colorPreviousAdjustments}">

View File

@ -144,14 +144,16 @@ export class DashboardComponent implements OnInit {
const newDifficultyHeight = block.height + remainingBlocks;
let change = 0;
if (blocksInEpoch > 0) {
change = (600 / (diff / blocksInEpoch ) - 1) * 100;
}
if (change > 300) {
change = 300;
}
if (change < -75) {
change = -75;
if (remainingBlocks < 1870) {
if (blocksInEpoch > 0) {
change = (600 / (diff / blocksInEpoch ) - 1) * 100;
}
if (change > 300) {
change = 300;
}
if (change < -75) {
change = -75;
}
}
const timeAvgDiff = change * 0.1;