From d534c42c4708b2160bf2e9a735b54ea67a5e8b71 Mon Sep 17 00:00:00 2001 From: softsimon Date: Wed, 17 Nov 2021 13:05:14 +0400 Subject: [PATCH] Handle recent difficulty adjustment estimate gracefully fixes #927 --- backend/src/routes.ts | 18 ++++++++++-------- .../src/app/dashboard/dashboard.component.html | 5 ++++- .../src/app/dashboard/dashboard.component.ts | 18 ++++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/backend/src/routes.ts b/backend/src/routes.ts index fd53f4765..11502c839 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -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; diff --git a/frontend/src/app/dashboard/dashboard.component.html b/frontend/src/app/dashboard/dashboard.component.html index 72d71b8ad..002f3c702 100644 --- a/frontend/src/app/dashboard/dashboard.component.html +++ b/frontend/src/app/dashboard/dashboard.component.html @@ -242,7 +242,7 @@
Estimate
-
+
@@ -252,6 +252,9 @@ {{ epochData.change | absolute | number: '1.2-2' }} %
+ +
+
Previous: diff --git a/frontend/src/app/dashboard/dashboard.component.ts b/frontend/src/app/dashboard/dashboard.component.ts index f76438942..dad5b4a9f 100644 --- a/frontend/src/app/dashboard/dashboard.component.ts +++ b/frontend/src/app/dashboard/dashboard.component.ts @@ -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;