From 4b336c73b1a34d8cacc576600aa167880172edf2 Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Mon, 23 Mar 2026 18:44:54 +0100 Subject: [PATCH] Make difficulty trend correction asymmetric --- src/cryptonote_config.h | 3 ++- src/cryptonote_core/blockchain.cpp | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 9a14c5e..9f1b922 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -301,7 +301,8 @@ #define DIFFICULTY_TREND_OLDER_WINDOW 15 #define DIFFICULTY_TREND_SMOOTHING_NUM 3 #define DIFFICULTY_TREND_SMOOTHING_DEN 10 -#define DIFFICULTY_TREND_MAX_ADJUST_PERCENT 5 +#define DIFFICULTY_TREND_MAX_UP_PERCENT 3 +#define DIFFICULTY_TREND_MAX_DOWN_PERCENT 10 //The limit is enough for the mandatory transaction content with 16 outputs (547 bytes), //a custom tag (1 byte) and up to 32 bytes of custom data for each recipient. diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 33cfd3e..a8fe152 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -191,11 +191,12 @@ namespace int64_t adjust_scaled = 10000 + (deviation * DIFFICULTY_TREND_SMOOTHING_NUM) / DIFFICULTY_TREND_SMOOTHING_DEN; - const int64_t max_adjust = DIFFICULTY_TREND_MAX_ADJUST_PERCENT * 100; - if (adjust_scaled > 10000 + max_adjust) - adjust_scaled = 10000 + max_adjust; - if (adjust_scaled < 10000 - max_adjust) - adjust_scaled = 10000 - max_adjust; + const int64_t max_adjust_up = DIFFICULTY_TREND_MAX_UP_PERCENT * 100; + const int64_t max_adjust_down = DIFFICULTY_TREND_MAX_DOWN_PERCENT * 100; + if (adjust_scaled > 10000 + max_adjust_up) + adjust_scaled = 10000 + max_adjust_up; + if (adjust_scaled < 10000 - max_adjust_down) + adjust_scaled = 10000 - max_adjust_down; cryptonote::difficulty_type adjusted = (calculated_difficulty * adjust_scaled) / 10000; if (adjusted < 1)