From 58a8441ead8f2c2aaadcd4d4b9eac184ed62d67d Mon Sep 17 00:00:00 2001 From: r4sas Date: Fri, 23 Nov 2018 15:40:03 +0000 Subject: [PATCH] changes --- CMakeLists.txt | 15 +-- cmake/macros/FindGMP.cmake | 113 +++++++++++++++--- db/create.sql | 6 +- src/server/poolserver/CMakeLists.txt | 1 + src/server/poolserver/Main.cpp | 10 +- src/server/poolserver/Stratum/Client.cpp | 2 +- src/server/poolserver/Stratum/Client.h | 14 +-- .../poolserver/Stratum/ShareLimiter.cpp | 12 +- src/server/poolserver/poolserver.cfg.dist | 91 ++++++++++---- src/server/shared/Gostcoin/Gostcoin.h | 3 +- src/server/shared/Logging/Log.cpp | 4 +- 11 files changed, 200 insertions(+), 71 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0729664..088819f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,6 @@ -# Project name! -project(PoolServer) - -# CMake policies -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required ( VERSION 2.8.12 ) +cmake_policy( VERSION 2.8.12 ) +project( "PoolServer" ) # Set macros set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/macros") @@ -25,10 +23,10 @@ set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) set(Boost_ALL_DYN_LINK ON) -SET(Boost_ADDITIONAL_VERSIONS "1.49" "1.49.0") +SET(Boost_ADDITIONAL_VERSIONS "1.62" "1.62.0") # Boost -find_package(Boost 1.49 COMPONENTS thread chrono program_options date_time system REQUIRED) +find_package(Boost 1.62 COMPONENTS thread chrono program_options date_time system REQUIRED) message(status "** Boost Include: ${Boost_INCLUDE_DIR}") message(status "** Boost Libraries: ${Boost_LIBRARY_DIRS}") message(status "** Boost Libraries: ${Boost_LIBRARIES}") @@ -44,6 +42,9 @@ find_package(GMP REQUIRED) # OpenSSL find_package(OpenSSL REQUIRED) +# pthreads +find_package(Threads) + # Print options include(cmake/showoptions.cmake) diff --git a/cmake/macros/FindGMP.cmake b/cmake/macros/FindGMP.cmake index a489f08..13655f7 100644 --- a/cmake/macros/FindGMP.cmake +++ b/cmake/macros/FindGMP.cmake @@ -1,23 +1,102 @@ -# Try to find the GMP librairies -# GMP_FOUND - system has GMP lib -# GMP_INCLUDE_DIR - the GMP include directory -# GMP_LIBRARIES - Libraries needed to use GMP -# Copyright (c) 2006, Laurent Montel, +# .. cmake_module:: +# +# Find the GNU MULTI-Precision Bignum (GMP) library +# and the corresponding C++ bindings GMPxx +# +# You may set the following variables to modify the +# behaviour of this module: +# +# :ref:`GMP_ROOT` +# Path list to search for GMP and GMPxx +# +# Sets the following variables: +# +# :code:`GMP_FOUND` +# True if the GMP library, the GMPxx headers and +# the GMPxx library were found. +# +# .. cmake_variable:: GMP_ROOT +# +# You may set this variable to have :ref:`FindGMP` look +# for the gmp and gmpxx packages in the given path before +# inspecting system paths. # -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -if (GMP_INCLUDE_DIR AND GMP_LIBRARIES) - # Already in cache, be silent - set(GMP_FIND_QUIETLY TRUE) -endif (GMP_INCLUDE_DIR AND GMP_LIBRARIES) -find_path(GMP_INCLUDE_DIR NAMES gmp.h ) -find_library(GMP_LIBRARIES NAMES gmp libgmp ) -find_library(GMPXX_LIBRARIES NAMES gmpxx libgmpxx ) -MESSAGE(STATUS "GMP libs: " ${GMP_LIBRARIES} " " ${GMPXX_LIBRARIES} ) +# search for location of header gmpxx.h", only at positions given by the user +find_path(GMPXX_INCLUDE_DIR + NAMES "gmpxx.h" + PATHS ${GMP_PREFIX} ${GMP_ROOT} + PATH_SUFFIXES include + NO_DEFAULT_PATH) +# try default paths now +find_path(GMPXX_INCLUDE_DIR + NAMES "gmpxx.h") +# check if header is accepted +include(CMakePushCheckState) +cmake_push_check_state() +set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${GMPXX_INCLUDE_DIR}) +include(CheckIncludeFileCXX) +check_include_file_cxx("gmpxx.h" GMP_HEADER_WORKS) + +# look for library gmp, only at positions given by the user +find_library(GMP_LIB + NAMES gmp libgmp + PATHS ${GMP_PREFIX} ${GMP_ROOT} "/usr/lib/x86_64-linux-gnu" + PATH_SUFFIXES lib lib64 + NO_DEFAULT_PATH + DOC "GNU GMP library") +# try default paths now +find_library(GMP_LIB + NAMES libgmp gmp) + +# look for library gmpxx, only at positions given by the user +find_library(GMPXX_LIB + NAMES gmpxx libgmpxx + PATHS ${GMP_PREFIX} ${GMP_ROOT} "/usr/lib/x86_64-linux-gnu" + PATH_SUFFIXES lib lib64 + NO_DEFAULT_PATH + DOC "GNU GMPXX library") +# try default paths now +find_library(GMPXX_LIB + NAMES libgmpxx gmpxx) + +# check if library works +if(GMP_LIB AND GMPXX_LIB) + include(CheckSymbolExists) + check_library_exists(${GMP_LIB} __gmpz_abs "" GMPXX_LIB_WORKS) +endif(GMP_LIB AND GMPXX_LIB) +cmake_pop_check_state() + +# behave like a CMake module is supposed to behave include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMP DEFAULT_MSG GMP_INCLUDE_DIR GMP_LIBRARIES) +find_package_handle_standard_args( + "GMP" + DEFAULT_MSG + GMPXX_INCLUDE_DIR GMP_LIB GMPXX_LIB GMP_HEADER_WORKS GMPXX_LIB_WORKS +) + +mark_as_advanced(GMP_LIB GMPXX_LIB GMPXX_INCLUDE_DIR) + +# if GMPxx headers, GMP library, and GMPxx library are found, store results +if(GMP_FOUND) + set(GMP_INCLUDE_DIRS ${GMPXX_INCLUDE_DIR}) + set(GMP_LIBRARIES ${GMP_LIB} ${GMPXX_LIB}) + set(GMP_COMPILE_FLAGS "-DENABLE_GMP=1") + # log result + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining location of GMP, GMPxx succeeded:\n" + "Include directory: ${GMP_INCLUDE_DIRS}\n" + "Library directory: ${GMP_LIBRARIES}\n\n") +else() + # log errornous result + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining location of GMP, GMPxx failed:\n" + "Include directory: ${GMPXX_INCLUDE_DIR}\n" + "gmp library directory: ${GMP_LIB}\n" + "gmpxx library directory: ${GMPXX_LIB}\n\n") +endif() -mark_as_advanced(GMP_INCLUDE_DIR GMP_LIBRARIES) +# set HAVE_GMP for config.h +set(HAVE_GMP ${GMP_FOUND}) diff --git a/db/create.sql b/db/create.sql index 7b6f7d2..d58040a 100644 --- a/db/create.sql +++ b/db/create.sql @@ -1,10 +1,10 @@ DROP TABLE IF EXISTS `pool_worker`; -CREATE TABLE IF NOT EXISTS `pool_worker` +CREATE TABLE IF NOT EXISTS `pool_worker` ( `id` INT(255) NOT NULL AUTO_INCREMENT, `username` VARCHAR(50) DEFAULT NULL, `password` VARCHAR(50) DEFAULT NULL, - `mindiff` int(10) unsigned NOT NULL DEFAULT '1', + `mindiff` int(10) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`) ) ENGINE = InnoDB; @@ -16,7 +16,7 @@ CREATE TABLE `shares` ( `username` varchar(120) NOT NULL, `our_result` tinyint(1) NOT NULL DEFAULT '0', `upstream_result` tinyint(1) NOT NULL DEFAULT '0', - `reason` varchar(50) DEFAULT NULL, + `reason` varchar(50) DEFAULT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `difficulty` int(10) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`) diff --git a/src/server/poolserver/CMakeLists.txt b/src/server/poolserver/CMakeLists.txt index f2123cb..37912f0 100644 --- a/src/server/poolserver/CMakeLists.txt +++ b/src/server/poolserver/CMakeLists.txt @@ -47,6 +47,7 @@ target_link_libraries(poolserver ${GMP_LIBRARIES} ${GMPXX_LIBRARIES} ${OPENSSL_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ) # Install diff --git a/src/server/poolserver/Main.cpp b/src/server/poolserver/Main.cpp index 197d310..50c6397 100644 --- a/src/server/poolserver/Main.cpp +++ b/src/server/poolserver/Main.cpp @@ -43,18 +43,18 @@ bool InitConfig(int argc, char *argv[]) // Stratum descStratum.add_options() - ("StratumHost,sh", boost::program_options::value()->default_value("0.0.0.0"), "Bind IP for stratum") + ("StratumHost", boost::program_options::value()->default_value("0.0.0.0"), "Bind IP for stratum") ("StratumRedirectHost", boost::program_options::value()->default_value("0.0.0.0"), "Where to redirect getwork requests") - ("StratumPort,sp", boost::program_options::value()->default_value(3333), "Stratum server port") + ("StratumPort", boost::program_options::value()->default_value(3333), "Stratum server port") ("StratumBlockCheckTime", boost::program_options::value()->default_value(2000), "Time between block checks in ms") ("RetargetInterval", boost::program_options::value()->default_value(20), "Time between difficulty checks in seconds") ("RetargetSharesThreshold", boost::program_options::value()->default_value(20), "Number of shares in retarget interval to trigger a difficulty check") ("RetargetTimeBuffer", boost::program_options::value()->default_value(60*5), "Buffer of shares to keep (in seconds)") ("RetargetTimePerShare", boost::program_options::value()->default_value(4), "Target in seconds between shares") ("RetargetVariance", boost::program_options::value()->default_value(40), "Maximum allowed variance in percent before difficulty change") - ("RetargetStartingDiff", boost::program_options::value()->default_value(2), "Difficulty at which new miner starts") - ("RetargetMinDiff", boost::program_options::value()->default_value(1), "Minimum difficulty (also starting difficulty)") - ("RetargetMaxDiff", boost::program_options::value()->default_value(1000000), "Maximum difficulty we can reach") + ("RetargetStartingDiff", boost::program_options::value()->default_value(0.001), "Difficulty at which new miner starts") + ("RetargetMinDiff", boost::program_options::value()->default_value(0.0001), "Minimum difficulty (also starting difficulty)") + ("RetargetMaxDiff", boost::program_options::value()->default_value(1000.0), "Maximum difficulty we can reach") ; // Logging diff --git a/src/server/poolserver/Stratum/Client.cpp b/src/server/poolserver/Stratum/Client.cpp index 7d6e129..b765f67 100644 --- a/src/server/poolserver/Stratum/Client.cpp +++ b/src/server/poolserver/Stratum/Client.cpp @@ -309,7 +309,7 @@ namespace Stratum _workers.insert(username); MySQL::Field* fields = result->FetchRow(); - _minDiff = fields[1].Get(); + _minDiff = fields[1].Get(); if (_diff < _minDiff) SetDifficulty(_minDiff); diff --git a/src/server/poolserver/Stratum/Client.h b/src/server/poolserver/Stratum/Client.h index 74498a0..ae67cc9 100644 --- a/src/server/poolserver/Stratum/Client.h +++ b/src/server/poolserver/Stratum/Client.h @@ -27,8 +27,8 @@ namespace Stratum public: Client(Server* server, asio::io_service& io_service, uint64 id) : _io_service(io_service), _server(server), _socket(io_service), _ioStrand(io_service), _id(id), _subscribed(false), _jobid(0), _shareLimiter(this) { - _diff = sConfig.Get("RetargetStartingDiff"); - _minDiff = sConfig.Get("RetargetMinDiff"); + _diff = sConfig.Get("RetargetStartingDiff"); + _minDiff = sConfig.Get("RetargetMinDiff"); } ~Client() @@ -100,11 +100,11 @@ namespace Stratum } // Worker difficulty - uint64 GetDifficulty() + double GetDifficulty() { return _diff; } - void SetDifficulty(uint64 diff, bool resendJob = false) + void SetDifficulty(double diff, bool resendJob = false) { if (diff < _minDiff) diff = _minDiff; @@ -116,7 +116,7 @@ namespace Stratum // Send difficulty update JSON params; - params.Add(double(_diff)/100); // diff 1 = 0.01 + params.Add(double(_diff)); JSON msg; msg["id"]; @@ -189,8 +189,8 @@ namespace Stratum uint32 _jobid; // Share limiting - uint64 _diff; - uint64 _minDiff; + double _diff; + double _minDiff; ShareLimiter _shareLimiter; }; diff --git a/src/server/poolserver/Stratum/ShareLimiter.cpp b/src/server/poolserver/Stratum/ShareLimiter.cpp index d1084eb..c216d12 100644 --- a/src/server/poolserver/Stratum/ShareLimiter.cpp +++ b/src/server/poolserver/Stratum/ShareLimiter.cpp @@ -46,16 +46,16 @@ namespace Stratum double hashrate = (MEGAHASHCONST*totalWeighted)/interval; // Calculate new diff - uint64 newDiff = (hashrate * sConfig.Get("RetargetTimePerShare")) / MEGAHASHCONST; + double newDiff = (hashrate * sConfig.Get("RetargetTimePerShare")) / MEGAHASHCONST; // Check Limits - if (newDiff < sConfig.Get("RetargetMinDiff")) - newDiff = sConfig.Get("RetargetMinDiff"); - if (newDiff > sConfig.Get("RetargetMaxDiff")) - newDiff = sConfig.Get("RetargetMaxDiff"); + if (newDiff < sConfig.Get("RetargetMinDiff")) + newDiff = sConfig.Get("RetargetMinDiff"); + if (newDiff > sConfig.Get("RetargetMaxDiff")) + newDiff = sConfig.Get("RetargetMaxDiff"); // Calculate variance in % - uint32 variance = abs(((newDiff - _client->GetDifficulty()) * 100) / _client->GetDifficulty()); + double variance = abs(((newDiff - _client->GetDifficulty()) * 100) / _client->GetDifficulty()); sLog.Debug(LOG_STRATUM, "Miner new diff: %u Variance: %u%% Hashrate: %f MH/s", newDiff, variance, hashrate); diff --git a/src/server/poolserver/poolserver.cfg.dist b/src/server/poolserver/poolserver.cfg.dist index 3d75dee..676e5c9 100644 --- a/src/server/poolserver/poolserver.cfg.dist +++ b/src/server/poolserver/poolserver.cfg.dist @@ -27,22 +27,34 @@ # - Line breaks should be at column 100. ################################################################################################### -[Server Configuration] +#[Server Configuration] ################################################################################################### # SERVER CONFIGURATION # -# MinDiffTime -# Description: Minimum diff time (ms) in main server loop. -# Important: Lowering this value increases cpu load but new packets are processed faster -# Default: 100 -MinDiffTime=100 +## How many threads to use +#ServerThreads=2 + +## Address to send coins to +#MiningAddress = + +## Bitcoin RPC login credentials +BitcoinRPC = 127.0.0.1;9376;gostcoinrpc;rpcpassword + +## Minimum share count to upload to database +#ShareUploadMinCount=2 + +## How many shares to upload in one query +#ShareUploadBulkCount=50 + +## How often to upload shares +#ShareUploadInterval=3 # ################################################################################################### -[Stratum Configuration] +#[Stratum Configuration] ################################################################################################### # STRATUM CONFIGURATION @@ -51,19 +63,49 @@ MinDiffTime=100 # Description: Bind stratum to IP/Hostname # Default: "0.0.0.0" - (Bind to all IPs on the system) -StratumHost="0.0.0.0" +StratumHost = 0.0.0.0 # # StratumPort # Description: Stratum Port # Default: 3333 -StratumPort=3333 +StratumPort = 3333 + +## Where to redirect getwork requests +#StratumRedirectHost="" + +## Time between block checks in ms +#StratumBlockCheckTime=2000 + +## Time between difficulty checks in seconds +RetargetInterval=20 + +## Number of shares in retarget interval to trigger a difficulty check +#RetargetSharesThreshold=20 + +## Buffer of shares to keep (in seconds) +#RetargetTimeBuffer=180 + +## Target in seconds between shares +#RetargetTimePerShare=10 + +## Maximum allowed variance in percent before difficulty change +#RetargetVariance=40 + +## Difficulty at which new miner starts +RetargetStartingDiff = 0.001 + +## Minimum difficulty (also starting difficulty) +RetargetMinDiff = 0.00001 + +## Maximum difficulty we can reach +RetargetMaxDiff = 100.0 # ################################################################################################### -[Logging Configuration] +#[Logging Configuration] ################################################################################################### # LOGGING CONFIGURATION @@ -74,7 +116,7 @@ StratumPort=3333 # Example: "/var/log" # Default: "../etc" - (Save log file next to executable) -LogFilePath="../etc" +LogFilePath = ../etc # # LogConsoleLevel @@ -87,7 +129,7 @@ LogFilePath="../etc" # 4 - (Debug|Set apropriate Log...DebugMask for debug output) LogConsoleLevel=4 -LogFileLevel=4 +LogFileLevel=2 # # LogConsoleDebugMask @@ -99,13 +141,13 @@ LogFileLevel=4 # 2 - (LOG_SERVER) # 4 - (LOG_DATABASE) -LogConsoleDebugMask=0 +LogConsoleDebugMask=7 LogFileDebugMask=0 # ################################################################################################### -[Database Configuration] +#[Database Configuration] ################################################################################################### # DATABASE CONFIGURATION @@ -116,12 +158,12 @@ LogFileDebugMask=0 # Example: "mysql" # Default: "." - (Save log file next to executable) -DatabaseDriver="mysql" +DatabaseDriver = mysql # ################################################################################################### -[MySQL Configuration] +#[MySQL Configuration] ################################################################################################### # MYSQL CONFIGURATION @@ -130,35 +172,42 @@ DatabaseDriver="mysql" # Description: IP/Hostname of MySQL Server # Default: "127.0.0.1" - (Connect to localhost) -MySQLHost="127.0.0.1" +MySQLHost = 127.0.0.1 # # MySQLPort # Description: MySQL Server Port # Default: 3306 - (Default MySQL Server Port) -MySQLPort=3306 +MySQLPort = 3306 # # MySQLUser # Description: MySQL Server Username # Default: "" - (No Username) -MySQLUser="root" +MySQLUser = # # MySQLPass # Description: MySQL Server Password # Default: "" - (No Password) -MySQLPass="" +MySQLPass = # # MySQLDatabase # Description: Name of MySQL Database # Default: "poolserver" -MySQLDatabase="poolserver" +MySQLDatabase = poolserver + +## MySQL Sync Threads to Create +#MySQLSyncThreads = 2 + +## MySQL Async Threads to Create +#MySQLAsyncThreads = 2 # ################################################################################################### + diff --git a/src/server/shared/Gostcoin/Gostcoin.h b/src/server/shared/Gostcoin/Gostcoin.h index afb0e21..7b187e2 100644 --- a/src/server/shared/Gostcoin/Gostcoin.h +++ b/src/server/shared/Gostcoin/Gostcoin.h @@ -12,8 +12,7 @@ namespace Gostcoin { inline BigInt TargetToDiff(BigInt val) { - // we consider diff=1 as 0.01 - static BigInt c("0x0000ffff00000000000000000000000000000000000000000000000000000000"); + static BigInt c("0x00000000ffff0000000000000000000000000000000000000000000000000000"); return (c / val); } diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index a2af123..deae993 100644 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -99,12 +99,12 @@ void Log::Write(LogLevel level, LogType type, std::string msg) case LOG_LEVEL_DEBUG: if (sConfig.Get("LogConsoleLevel") >= level) { uint32_t debugmask = sConfig.Get("LogConsoleDebugMask"); - if (debugmask & uint32_t(pow(2, type))) + if (debugmask & uint32_t(pow(2, (int)type))) std::cout << timestamp << " [DEBUG] " << msg << std::endl; } if (sConfig.Get("LogFileLevel") >= level) { uint32_t debugmask = sConfig.Get("LogFileDebugMask"); - if (debugmask & uint32_t(pow(2, type))) + if (debugmask & uint32_t(pow(2, (int)type))) AppendFile(timestamp + " [DEBUG] " + msg); } break;