Browse Source

changes

master
R4SAS 6 years ago
parent
commit
58a8441ead
  1. 15
      CMakeLists.txt
  2. 113
      cmake/macros/FindGMP.cmake
  3. 1
      src/server/poolserver/CMakeLists.txt
  4. 10
      src/server/poolserver/Main.cpp
  5. 2
      src/server/poolserver/Stratum/Client.cpp
  6. 14
      src/server/poolserver/Stratum/Client.h
  7. 12
      src/server/poolserver/Stratum/ShareLimiter.cpp
  8. 91
      src/server/poolserver/poolserver.cfg.dist
  9. 3
      src/server/shared/Gostcoin/Gostcoin.h
  10. 4
      src/server/shared/Logging/Log.cpp

15
CMakeLists.txt

@ -1,8 +1,6 @@
# Project name! cmake_minimum_required ( VERSION 2.8.12 )
project(PoolServer) cmake_policy( VERSION 2.8.12 )
project( "PoolServer" )
# CMake policies
cmake_minimum_required(VERSION 2.6)
# Set macros # Set macros
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/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_USE_STATIC_RUNTIME OFF)
set(Boost_ALL_DYN_LINK ON) 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 # 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 Include: ${Boost_INCLUDE_DIR}")
message(status "** Boost Libraries: ${Boost_LIBRARY_DIRS}") message(status "** Boost Libraries: ${Boost_LIBRARY_DIRS}")
message(status "** Boost Libraries: ${Boost_LIBRARIES}") message(status "** Boost Libraries: ${Boost_LIBRARIES}")
@ -44,6 +42,9 @@ find_package(GMP REQUIRED)
# OpenSSL # OpenSSL
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
# pthreads
find_package(Threads)
# Print options # Print options
include(cmake/showoptions.cmake) include(cmake/showoptions.cmake)

113
cmake/macros/FindGMP.cmake

@ -1,23 +1,102 @@
# Try to find the GMP librairies # .. cmake_module::
# GMP_FOUND - system has GMP lib #
# GMP_INCLUDE_DIR - the GMP include directory # Find the GNU MULTI-Precision Bignum (GMP) library
# GMP_LIBRARIES - Libraries needed to use GMP # and the corresponding C++ bindings GMPxx
# Copyright (c) 2006, Laurent Montel, <montel@kde.org> #
# 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 ) # search for location of header gmpxx.h", only at positions given by the user
find_library(GMP_LIBRARIES NAMES gmp libgmp ) find_path(GMPXX_INCLUDE_DIR
find_library(GMPXX_LIBRARIES NAMES gmpxx libgmpxx ) NAMES "gmpxx.h"
MESSAGE(STATUS "GMP libs: " ${GMP_LIBRARIES} " " ${GMPXX_LIBRARIES} ) 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) 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})

1
src/server/poolserver/CMakeLists.txt

@ -47,6 +47,7 @@ target_link_libraries(poolserver
${GMP_LIBRARIES} ${GMP_LIBRARIES}
${GMPXX_LIBRARIES} ${GMPXX_LIBRARIES}
${OPENSSL_LIBRARIES} ${OPENSSL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
) )
# Install # Install

10
src/server/poolserver/Main.cpp

@ -43,18 +43,18 @@ bool InitConfig(int argc, char *argv[])
// Stratum // Stratum
descStratum.add_options() descStratum.add_options()
("StratumHost,sh", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Bind IP for stratum") ("StratumHost", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Bind IP for stratum")
("StratumRedirectHost", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Where to redirect getwork requests") ("StratumRedirectHost", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Where to redirect getwork requests")
("StratumPort,sp", boost::program_options::value<uint16_t>()->default_value(3333), "Stratum server port") ("StratumPort", boost::program_options::value<uint16_t>()->default_value(3333), "Stratum server port")
("StratumBlockCheckTime", boost::program_options::value<uint32>()->default_value(2000), "Time between block checks in ms") ("StratumBlockCheckTime", boost::program_options::value<uint32>()->default_value(2000), "Time between block checks in ms")
("RetargetInterval", boost::program_options::value<uint32>()->default_value(20), "Time between difficulty checks in seconds") ("RetargetInterval", boost::program_options::value<uint32>()->default_value(20), "Time between difficulty checks in seconds")
("RetargetSharesThreshold", boost::program_options::value<uint32>()->default_value(20), "Number of shares in retarget interval to trigger a difficulty check") ("RetargetSharesThreshold", boost::program_options::value<uint32>()->default_value(20), "Number of shares in retarget interval to trigger a difficulty check")
("RetargetTimeBuffer", boost::program_options::value<uint32>()->default_value(60*5), "Buffer of shares to keep (in seconds)") ("RetargetTimeBuffer", boost::program_options::value<uint32>()->default_value(60*5), "Buffer of shares to keep (in seconds)")
("RetargetTimePerShare", boost::program_options::value<double>()->default_value(4), "Target in seconds between shares") ("RetargetTimePerShare", boost::program_options::value<double>()->default_value(4), "Target in seconds between shares")
("RetargetVariance", boost::program_options::value<uint32>()->default_value(40), "Maximum allowed variance in percent before difficulty change") ("RetargetVariance", boost::program_options::value<uint32>()->default_value(40), "Maximum allowed variance in percent before difficulty change")
("RetargetStartingDiff", boost::program_options::value<uint32>()->default_value(2), "Difficulty at which new miner starts") ("RetargetStartingDiff", boost::program_options::value<double>()->default_value(0.001), "Difficulty at which new miner starts")
("RetargetMinDiff", boost::program_options::value<uint32>()->default_value(1), "Minimum difficulty (also starting difficulty)") ("RetargetMinDiff", boost::program_options::value<double>()->default_value(0.0001), "Minimum difficulty (also starting difficulty)")
("RetargetMaxDiff", boost::program_options::value<uint32>()->default_value(1000000), "Maximum difficulty we can reach") ("RetargetMaxDiff", boost::program_options::value<double>()->default_value(1000.0), "Maximum difficulty we can reach")
; ;
// Logging // Logging

2
src/server/poolserver/Stratum/Client.cpp

@ -309,7 +309,7 @@ namespace Stratum
_workers.insert(username); _workers.insert(username);
MySQL::Field* fields = result->FetchRow(); MySQL::Field* fields = result->FetchRow();
_minDiff = fields[1].Get<uint32>(); _minDiff = fields[1].Get<double>();
if (_diff < _minDiff) if (_diff < _minDiff)
SetDifficulty(_minDiff); SetDifficulty(_minDiff);

14
src/server/poolserver/Stratum/Client.h

@ -27,8 +27,8 @@ namespace Stratum
public: 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) 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<uint32>("RetargetStartingDiff"); _diff = sConfig.Get<double>("RetargetStartingDiff");
_minDiff = sConfig.Get<uint32>("RetargetMinDiff"); _minDiff = sConfig.Get<double>("RetargetMinDiff");
} }
~Client() ~Client()
@ -100,11 +100,11 @@ namespace Stratum
} }
// Worker difficulty // Worker difficulty
uint64 GetDifficulty() double GetDifficulty()
{ {
return _diff; return _diff;
} }
void SetDifficulty(uint64 diff, bool resendJob = false) void SetDifficulty(double diff, bool resendJob = false)
{ {
if (diff < _minDiff) if (diff < _minDiff)
diff = _minDiff; diff = _minDiff;
@ -116,7 +116,7 @@ namespace Stratum
// Send difficulty update // Send difficulty update
JSON params; JSON params;
params.Add(double(_diff)/100); // diff 1 = 0.01 params.Add(double(_diff));
JSON msg; JSON msg;
msg["id"]; msg["id"];
@ -189,8 +189,8 @@ namespace Stratum
uint32 _jobid; uint32 _jobid;
// Share limiting // Share limiting
uint64 _diff; double _diff;
uint64 _minDiff; double _minDiff;
ShareLimiter _shareLimiter; ShareLimiter _shareLimiter;
}; };

12
src/server/poolserver/Stratum/ShareLimiter.cpp

@ -46,16 +46,16 @@ namespace Stratum
double hashrate = (MEGAHASHCONST*totalWeighted)/interval; double hashrate = (MEGAHASHCONST*totalWeighted)/interval;
// Calculate new diff // Calculate new diff
uint64 newDiff = (hashrate * sConfig.Get<double>("RetargetTimePerShare")) / MEGAHASHCONST; double newDiff = (hashrate * sConfig.Get<double>("RetargetTimePerShare")) / MEGAHASHCONST;
// Check Limits // Check Limits
if (newDiff < sConfig.Get<uint32>("RetargetMinDiff")) if (newDiff < sConfig.Get<double>("RetargetMinDiff"))
newDiff = sConfig.Get<uint32>("RetargetMinDiff"); newDiff = sConfig.Get<double>("RetargetMinDiff");
if (newDiff > sConfig.Get<uint32>("RetargetMaxDiff")) if (newDiff > sConfig.Get<double>("RetargetMaxDiff"))
newDiff = sConfig.Get<uint32>("RetargetMaxDiff"); newDiff = sConfig.Get<double>("RetargetMaxDiff");
// Calculate variance in % // 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); sLog.Debug(LOG_STRATUM, "Miner new diff: %u Variance: %u%% Hashrate: %f MH/s", newDiff, variance, hashrate);

91
src/server/poolserver/poolserver.cfg.dist

@ -27,22 +27,34 @@
# - Line breaks should be at column 100. # - Line breaks should be at column 100.
################################################################################################### ###################################################################################################
[Server Configuration] #[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 # STRATUM CONFIGURATION
@ -51,19 +63,49 @@ MinDiffTime=100
# Description: Bind stratum to IP/Hostname # Description: Bind stratum to IP/Hostname
# Default: "0.0.0.0" - (Bind to all IPs on the system) # Default: "0.0.0.0" - (Bind to all IPs on the system)
StratumHost="0.0.0.0" StratumHost = 0.0.0.0
# #
# StratumPort # StratumPort
# Description: Stratum Port # Description: Stratum Port
# Default: 3333 # 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 # LOGGING CONFIGURATION
@ -74,7 +116,7 @@ StratumPort=3333
# Example: "/var/log" # Example: "/var/log"
# Default: "../etc" - (Save log file next to executable) # Default: "../etc" - (Save log file next to executable)
LogFilePath="../etc" LogFilePath = ../etc
# #
# LogConsoleLevel # LogConsoleLevel
@ -87,7 +129,7 @@ LogFilePath="../etc"
# 4 - (Debug|Set apropriate Log...DebugMask for debug output) # 4 - (Debug|Set apropriate Log...DebugMask for debug output)
LogConsoleLevel=4 LogConsoleLevel=4
LogFileLevel=4 LogFileLevel=2
# #
# LogConsoleDebugMask # LogConsoleDebugMask
@ -99,13 +141,13 @@ LogFileLevel=4
# 2 - (LOG_SERVER) # 2 - (LOG_SERVER)
# 4 - (LOG_DATABASE) # 4 - (LOG_DATABASE)
LogConsoleDebugMask=0 LogConsoleDebugMask=7
LogFileDebugMask=0 LogFileDebugMask=0
# #
################################################################################################### ###################################################################################################
[Database Configuration] #[Database Configuration]
################################################################################################### ###################################################################################################
# DATABASE CONFIGURATION # DATABASE CONFIGURATION
@ -116,12 +158,12 @@ LogFileDebugMask=0
# Example: "mysql" # Example: "mysql"
# Default: "." - (Save log file next to executable) # Default: "." - (Save log file next to executable)
DatabaseDriver="mysql" DatabaseDriver = mysql
# #
################################################################################################### ###################################################################################################
[MySQL Configuration] #[MySQL Configuration]
################################################################################################### ###################################################################################################
# MYSQL CONFIGURATION # MYSQL CONFIGURATION
@ -130,35 +172,42 @@ DatabaseDriver="mysql"
# Description: IP/Hostname of MySQL Server # Description: IP/Hostname of MySQL Server
# Default: "127.0.0.1" - (Connect to localhost) # Default: "127.0.0.1" - (Connect to localhost)
MySQLHost="127.0.0.1" MySQLHost = 127.0.0.1
# #
# MySQLPort # MySQLPort
# Description: MySQL Server Port # Description: MySQL Server Port
# Default: 3306 - (Default MySQL Server Port) # Default: 3306 - (Default MySQL Server Port)
MySQLPort=3306 MySQLPort = 3306
# #
# MySQLUser # MySQLUser
# Description: MySQL Server Username # Description: MySQL Server Username
# Default: "" - (No Username) # Default: "" - (No Username)
MySQLUser="root" MySQLUser =
# #
# MySQLPass # MySQLPass
# Description: MySQL Server Password # Description: MySQL Server Password
# Default: "" - (No Password) # Default: "" - (No Password)
MySQLPass="" MySQLPass =
# #
# MySQLDatabase # MySQLDatabase
# Description: Name of MySQL Database # Description: Name of MySQL Database
# Default: "poolserver" # Default: "poolserver"
MySQLDatabase="poolserver" MySQLDatabase = poolserver
## MySQL Sync Threads to Create
#MySQLSyncThreads = 2
## MySQL Async Threads to Create
#MySQLAsyncThreads = 2
# #
################################################################################################### ###################################################################################################

3
src/server/shared/Gostcoin/Gostcoin.h

@ -12,8 +12,7 @@ namespace Gostcoin
{ {
inline BigInt TargetToDiff(BigInt val) inline BigInt TargetToDiff(BigInt val)
{ {
// we consider diff=1 as 0.01 static BigInt c("0x00000000ffff0000000000000000000000000000000000000000000000000000");
static BigInt c("0x0000ffff00000000000000000000000000000000000000000000000000000000");
return (c / val); return (c / val);
} }

4
src/server/shared/Logging/Log.cpp

@ -99,12 +99,12 @@ void Log::Write(LogLevel level, LogType type, std::string msg)
case LOG_LEVEL_DEBUG: case LOG_LEVEL_DEBUG:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level) { if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level) {
uint32_t debugmask = sConfig.Get<uint32_t>("LogConsoleDebugMask"); uint32_t debugmask = sConfig.Get<uint32_t>("LogConsoleDebugMask");
if (debugmask & uint32_t(pow(2, type))) if (debugmask & uint32_t(pow(2, (int)type)))
std::cout << timestamp << " [DEBUG] " << msg << std::endl; std::cout << timestamp << " [DEBUG] " << msg << std::endl;
} }
if (sConfig.Get<uint32_t>("LogFileLevel") >= level) { if (sConfig.Get<uint32_t>("LogFileLevel") >= level) {
uint32_t debugmask = sConfig.Get<uint32_t>("LogFileDebugMask"); uint32_t debugmask = sConfig.Get<uint32_t>("LogFileDebugMask");
if (debugmask & uint32_t(pow(2, type))) if (debugmask & uint32_t(pow(2, (int)type)))
AppendFile(timestamp + " [DEBUG] " + msg); AppendFile(timestamp + " [DEBUG] " + msg);
} }
break; break;

Loading…
Cancel
Save