From adf3f5df196502cd613bd43e1a927ae682b41f67 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Wed, 3 Apr 2024 10:58:35 +0200 Subject: [PATCH] Use 500k starting difficulty for autodiff --- src/stratum_server.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stratum_server.cpp b/src/stratum_server.cpp index 73f8548..958912a 100644 --- a/src/stratum_server.cpp +++ b/src/stratum_server.cpp @@ -33,6 +33,8 @@ static constexpr uint64_t AUTO_DIFF_TARGET_TIME = 30; // Use short target format (4 bytes) for diff <= 4 million static constexpr uint64_t TARGET_4_BYTES_LIMIT = std::numeric_limits::max() / 4000001; +static constexpr uint64_t AUTODIFF_START = std::numeric_limits::max() / 500001; + static constexpr int32_t BAD_SHARE_POINTS = -5; static constexpr int32_t GOOD_SHARE_POINTS = 1; static constexpr int32_t BAN_THRESHOLD_POINTS = -15; @@ -271,7 +273,7 @@ bool StratumServer::on_login(StratumClient* client, uint32_t id, const char* log } else if (m_autoDiff) { // Limit autodiff to 4000000 for maximum compatibility - target = std::max(target, TARGET_4_BYTES_LIMIT); + target = std::max(std::max(target, AUTODIFF_START), TARGET_4_BYTES_LIMIT); } if (get_custom_user(login, client->m_customUser)) { @@ -764,7 +766,9 @@ void StratumServer::on_blobs_ready() target = std::max(target, client->m_autoDiff.target()); } else { - // Not enough shares from the client yet, cut diff in half every 16 seconds + // Not enough shares from the client yet, start with 500k diff and cut diff in half every 16 seconds + target = std::max(target, AUTODIFF_START); + const uint64_t num_halvings = (cur_time - client->m_connectedTime) / 16; constexpr uint64_t max_target = (std::numeric_limits::max() / MIN_DIFF) + 1; for (uint64_t i = 0; (i < num_halvings) && (target < max_target); ++i) {