From fd0cbd448be5bb19417cd2f236f967956f1f7b05 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 21 Feb 2020 01:31:22 +0700 Subject: [PATCH] Use "extra_nonce" for daemon client. --- src/base/net/stratum/DaemonClient.cpp | 6 +++--- src/base/net/stratum/DaemonClient.h | 4 ++-- src/base/tools/Buffer.cpp | 30 +++++++++++++++++++++++++-- src/base/tools/Buffer.h | 6 ++++-- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index 11e8256a7..8e89c5477 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -5,9 +5,9 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh * Copyright 2019 Howard Chu - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -285,7 +285,7 @@ int64_t xmrig::DaemonClient::getBlockTemplate() Value params(kObjectType); params.AddMember("wallet_address", m_user.toJSON(), allocator); - params.AddMember("reserve_size", 8, allocator); + params.AddMember("extra_nonce", Buffer::randomBytes(8).toHex().toJSON(doc), allocator); JsonRequest::create(doc, m_sequence, "getblocktemplate", params); diff --git a/src/base/net/stratum/DaemonClient.h b/src/base/net/stratum/DaemonClient.h index e819c07d6..8e36b8fb2 100644 --- a/src/base/net/stratum/DaemonClient.h +++ b/src/base/net/stratum/DaemonClient.h @@ -5,9 +5,9 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh * Copyright 2019 Howard Chu - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/base/tools/Buffer.cpp b/src/base/tools/Buffer.cpp index 982f9d369..e260b7a5b 100644 --- a/src/base/tools/Buffer.cpp +++ b/src/base/tools/Buffer.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,19 @@ #include "base/tools/Buffer.h" +#include + + +namespace xmrig { + + +static std::random_device randomDevice; +static std::mt19937 randomEngine(randomDevice()); + + +} // namespace xmrig + + static inline uint8_t hf_hex2bin(uint8_t c, bool &err) { if (c >= '0' && c <= '9') { @@ -121,6 +134,19 @@ xmrig::Buffer xmrig::Buffer::allocUnsafe(size_t size) } +xmrig::Buffer xmrig::Buffer::randomBytes(const size_t size) +{ + Buffer buf(size); + std::uniform_int_distribution<> dis(0, 255); + + for (size_t i = 0; i < size; ++i) { + buf.m_data[i] = static_cast(dis(randomEngine)); + } + + return buf; +} + + bool xmrig::Buffer::fromHex(const uint8_t *in, size_t size, uint8_t *out) { bool error = false; diff --git a/src/base/tools/Buffer.h b/src/base/tools/Buffer.h index 363e4697e..33b186c01 100644 --- a/src/base/tools/Buffer.h +++ b/src/base/tools/Buffer.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -61,6 +61,8 @@ public: static Buffer allocUnsafe(size_t size); + static Buffer randomBytes(const size_t size); + static inline Buffer alloc(size_t size) { return Buffer(size); }