From 49529627f8b20029e83c2d8b48e58544cd4f5913 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Thu, 11 May 2023 11:18:58 -0600 Subject: [PATCH] Fix difficulty adjustment calculation --- backend/src/api/difficulty-adjustment.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/api/difficulty-adjustment.ts b/backend/src/api/difficulty-adjustment.ts index 3e953e4c8..1f37d8be9 100644 --- a/backend/src/api/difficulty-adjustment.ts +++ b/backend/src/api/difficulty-adjustment.ts @@ -34,11 +34,12 @@ export function calcDifficultyAdjustment( const remainingBlocks = EPOCH_BLOCK_LENGTH - blocksInEpoch; const nextRetargetHeight = (blockHeight >= 0) ? blockHeight + remainingBlocks : 0; const expectedBlocks = diffSeconds / BLOCK_SECONDS_TARGET; + const actualTimespan = (blocksInEpoch === 2015 ? latestBlockTimestamp : nowSeconds) - DATime; let difficultyChange = 0; let timeAvgSecs = blocksInEpoch ? diffSeconds / blocksInEpoch : BLOCK_SECONDS_TARGET; - difficultyChange = (BLOCK_SECONDS_TARGET / timeAvgSecs - 1) * 100; + difficultyChange = (BLOCK_SECONDS_TARGET / (actualTimespan / (blocksInEpoch + 1)) - 1) * 100; // Max increase is x4 (+300%) if (difficultyChange > 300) { difficultyChange = 300;