From 918d98ce51a7738cb05cce0ce1d978188030e358 Mon Sep 17 00:00:00 2001 From: Hussam Date: Fri, 8 Nov 2024 11:08:00 -0600 Subject: [PATCH 1/6] Rename binaries to quai-gpu-miner for consistency --- CODEOWNERS | 1 - deploy_miner.sh | 4 ++-- kawpowminer/CMakeLists.txt | 12 ++++++------ kawpowminer/main.cpp | 6 +++--- 4 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS deleted file mode 100644 index a14ad8f..0000000 --- a/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -kawpowminer/DBusInt.h @MRZA-MRZA diff --git a/deploy_miner.sh b/deploy_miner.sh index ec09b88..d045802 100644 --- a/deploy_miner.sh +++ b/deploy_miner.sh @@ -41,7 +41,7 @@ git submodule update --init --recursive mkdir build && cd build cmake .. -DETHASHCUDA=ON -DETHASHCL=OFF cmake --build . -mkdir -p ../../output && cp kawpowminer/kawpowminer ../../output/quai-gpu-miner-nvidia +mkdir -p ../../output && cp kawpowminer/quai-gpu-miner ../../output/quai-gpu-miner-nvidia # Copy hiveos_packager for NVIDIA package cd ../ @@ -57,7 +57,7 @@ rm -rf build && mkdir build && cd build # Second build with OpenCL enabled and CUDA disabled cmake .. -DETHASHCUDA=OFF -DETHASHCL=ON cmake --build . -cp kawpowminer/kawpowminer ../../output/quai-gpu-miner-amd +cp kawpowminer/quai-gpu-miner ../../output/quai-gpu-miner-amd # Copy hiveos_packager for AMD package cd ../ diff --git a/kawpowminer/CMakeLists.txt b/kawpowminer/CMakeLists.txt index 1e2fd2e..1e4700f 100644 --- a/kawpowminer/CMakeLists.txt +++ b/kawpowminer/CMakeLists.txt @@ -4,7 +4,7 @@ aux_source_directory(. SRC_LIST) include_directories(BEFORE ..) -set(EXECUTABLE kawpowminer) +set(EXECUTABLE quai-gpu-miner) file(GLOB HEADERS "*.h") @@ -16,7 +16,7 @@ endif() hunter_add_package(CLI11) find_package(CLI11 CONFIG REQUIRED) -target_link_libraries(kawpowminer PRIVATE ethcore poolprotocols devcore kawpowminer-buildinfo CLI11::CLI11 Boost::filesystem Boost::system) +target_link_libraries(quai-gpu-miner PRIVATE ethcore poolprotocols devcore kawpowminer-buildinfo CLI11::CLI11 Boost::filesystem Boost::system) if(ETHDBUS) find_package(PkgConfig) @@ -24,15 +24,15 @@ if(ETHDBUS) pkg_check_modules(DBUS dbus-1) include_directories(${DBUS_INCLUDE_DIRS}) link_directories(${DBUS_LIBRARY_DIRS}) - target_link_libraries(kawpowminer PRIVATE ${DBUS_LIBRARIES}) + target_link_libraries(quai-gpu-miner PRIVATE ${DBUS_LIBRARIES}) endif() if(APICORE) - target_link_libraries(kawpowminer PRIVATE apicore) + target_link_libraries(quai-gpu-miner PRIVATE apicore) endif() include(GNUInstallDirs) -install(TARGETS kawpowminer DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(TARGETS quai-gpu-miner DESTINATION ${CMAKE_INSTALL_BINDIR}) if(MSVC) - install(FILES $ DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) + install(FILES $ DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) endif() diff --git a/kawpowminer/main.cpp b/kawpowminer/main.cpp index 7a9a406..3cfa1b1 100644 --- a/kawpowminer/main.cpp +++ b/kawpowminer/main.cpp @@ -1298,14 +1298,14 @@ int main(int argc, char** argv) auto* bi = kawpowminer_get_buildinfo(); cout << endl << endl - << "kawpowminer " << bi->project_version << endl + << "quai-gpu-miner " << bi->project_version << endl << "Build: " << bi->system_name << "/" << bi->build_type << "/" << bi->compiler_id << endl << endl; if (argc < 2) { cerr << "No arguments specified. " << endl - << "Try 'kawpowminer --help' to get a list of arguments." << endl + << "Try 'quai-gpu-miner --help' to get a list of arguments." << endl << endl; return 1; } @@ -1358,7 +1358,7 @@ int main(int argc, char** argv) catch (std::invalid_argument& ex1) { cerr << "Error: " << ex1.what() << endl - << "Try kawpowminer --help to get an explained list of arguments." << endl + << "Try quai-gpu-miner --help to get an explained list of arguments." << endl << endl; return 1; } From d376c66d1feef3a82fea906942d81d4c4a00583d Mon Sep 17 00:00:00 2001 From: Hussam Date: Mon, 18 Nov 2024 17:53:01 -0600 Subject: [PATCH 2/6] Automatic restart on epoch change --- kawpowminer/main.cpp | 8 +++ libethcore/Farm.cpp | 66 +++++++++++++++++++ libethcore/Farm.h | 7 ++ libpoolprotocols/stratum/EthStratumClient.cpp | 3 +- 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/kawpowminer/main.cpp b/kawpowminer/main.cpp index 3cfa1b1..b076e61 100644 --- a/kawpowminer/main.cpp +++ b/kawpowminer/main.cpp @@ -1279,6 +1279,11 @@ class MinerCLI #endif }; +void signal_handler(int signum) { + std::cout << "Signal received, terminating process group." << std::endl; + killpg(0, signum); // Send signal to all processes in the group +} + int main(int argc, char** argv) { // Return values @@ -1293,6 +1298,9 @@ int main(int argc, char** argv) // UTF-8 characters are displayed correctly in the console SetConsoleOutputCP(CP_UTF8); #endif + + setpgid(0, 0); + signal (SIGINT, signal_handler); // Always out release version auto* bi = kawpowminer_get_buildinfo(); diff --git a/libethcore/Farm.cpp b/libethcore/Farm.cpp index 2ff457f..7829df8 100644 --- a/libethcore/Farm.cpp +++ b/libethcore/Farm.cpp @@ -681,6 +681,72 @@ bool Farm::spawn_file_in_bin_dir(const char* filename, const std::vector cmdline((std::istreambuf_iterator(cmdline_file)), + std::istreambuf_iterator()); + cmdline.push_back('\0'); // Ensure null termination + + std::vector args; + char* arg = cmdline.data(); + for (size_t i = 0; i < cmdline.size() - 1; ++i) { + if (cmdline[i] == '\0') { + args.push_back(arg); + arg = &cmdline[i + 1]; + } + } + args.push_back(nullptr); + + pid_t pid = fork(); + + if (pid < 0) { + perror("fork failed"); + return false; + } + + if (pid == 0) { + setsid(); // Start a new session for the child + execv(executable_path, args.data()); + perror("exec failed"); + _exit(1); + } else { + // Wait for child to terminate to avoid orphans + int status; + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid failed"); + return false; + } + } + + return true; +} } // namespace eth } // namespace dev diff --git a/libethcore/Farm.h b/libethcore/Farm.h index 64ce3bb..56f26ce 100644 --- a/libethcore/Farm.h +++ b/libethcore/Farm.h @@ -134,6 +134,13 @@ class Farm : public FarmFace */ bool reboot(const std::vector& args); + /** + * @brief Sends signal to restart entire mining process + * + * @return false if process failed to fork or restart + */ + bool restart_process(); + /** * @brief Get information on the progress of mining this work package. * @return The progress with mining so far. diff --git a/libpoolprotocols/stratum/EthStratumClient.cpp b/libpoolprotocols/stratum/EthStratumClient.cpp index 7559b64..e8792d0 100644 --- a/libpoolprotocols/stratum/EthStratumClient.cpp +++ b/libpoolprotocols/stratum/EthStratumClient.cpp @@ -1822,7 +1822,8 @@ void EthStratumClient::onRecvSocketDataCompleted( if (m_newjobprocessed) { if (m_onWorkReceived) { if (m_epochChanged) { - Farm::f().restart(); + cwarn << "Epoch changed, restarting mining process on new DAG"; + Farm::f().restart_process(); m_epochChanged = false; } m_onWorkReceived(m_current); From 623190e74084298643692ab3d9cd8213534daad2 Mon Sep 17 00:00:00 2001 From: Hussam Date: Mon, 18 Nov 2024 17:53:13 -0600 Subject: [PATCH 3/6] Fix crash when receiving invalid extraNonce --- libpoolprotocols/stratum/EthStratumClient.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libpoolprotocols/stratum/EthStratumClient.cpp b/libpoolprotocols/stratum/EthStratumClient.cpp index e8792d0..011d204 100644 --- a/libpoolprotocols/stratum/EthStratumClient.cpp +++ b/libpoolprotocols/stratum/EthStratumClient.cpp @@ -1566,8 +1566,7 @@ void EthStratumClient::processResponse(Json::Value& responseObject) if (!processExtranonce(enonce)) { cwarn << "Disconnecting ..."; - m_io_service.post( - m_io_strand.wrap(boost::bind(&EthStratumClient::disconnect, this))); + return; } } else if (_method == "mining.set_target") { From 434854519c9ab9804a39118003ec1c30dc864738 Mon Sep 17 00:00:00 2001 From: Hussam Date: Mon, 18 Nov 2024 10:45:10 -0600 Subject: [PATCH 4/6] Growth rates 10x, epoch 1/10 --- libethash/ethash.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libethash/ethash.cpp b/libethash/ethash.cpp index f8a9bc8..97bc1e0 100644 --- a/libethash/ethash.cpp +++ b/libethash/ethash.cpp @@ -20,10 +20,10 @@ namespace ethash { // Internal constants: constexpr static int light_cache_init_size = 1 << 24; -constexpr static int light_cache_growth = 1 << 17; +constexpr static int light_cache_growth = 1 << 21; constexpr static int light_cache_rounds = 3; -constexpr static int full_dataset_init_size = 1 << 30; -constexpr static int full_dataset_growth = 1 << 23; +constexpr static unsigned long long full_dataset_init_size = 1ULL << 32; +constexpr static int full_dataset_growth = 1 << 26; constexpr static int full_dataset_item_parents = 512; // Verify constants: From 9813b8c37fde9658c9e2ed1d067109dc48d96f31 Mon Sep 17 00:00:00 2001 From: Hussam Date: Mon, 18 Nov 2024 11:28:54 -0600 Subject: [PATCH 5/6] Reset epoch and period to Mainnet parameters --- libethash/ethash/ethash.h | 2 +- libethash/ethash/progpow.hpp | 2 +- libprogpow/ProgPow.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libethash/ethash/ethash.h b/libethash/ethash/ethash.h index c0fdef6..9105a6d 100644 --- a/libethash/ethash/ethash.h +++ b/libethash/ethash/ethash.h @@ -25,7 +25,7 @@ extern "C" { */ #define ETHASH_REVISION "23" -#define ETHASH_EPOCH_LENGTH 2147483647 // (2^31) - 1 +#define ETHASH_EPOCH_LENGTH 129600 // 4320 primes per day * 30 days #define ETHASH_LIGHT_CACHE_ITEM_SIZE 64 #define ETHASH_FULL_DATASET_ITEM_SIZE 128 #define ETHASH_NUM_DATASET_ACCESSES 64 diff --git a/libethash/ethash/progpow.hpp b/libethash/ethash/progpow.hpp index 5bdbc05..56e74b7 100644 --- a/libethash/ethash/progpow.hpp +++ b/libethash/ethash/progpow.hpp @@ -19,7 +19,7 @@ using namespace ethash; // Include ethash namespace. /// https://github.com/ifdefelse/ProgPOW#change-history. constexpr auto revision = "0.9.3"; -constexpr int period_length = 2147483647; // (2^31) - 1 +constexpr int period_length = 10; constexpr uint32_t num_regs = 32; constexpr size_t num_lanes = 16; constexpr int num_cache_accesses = 11; diff --git a/libprogpow/ProgPow.h b/libprogpow/ProgPow.h index 89b722a..03feed5 100644 --- a/libprogpow/ProgPow.h +++ b/libprogpow/ProgPow.h @@ -4,7 +4,7 @@ #include // blocks before changing the random program -#define PROGPOW_PERIOD 2147483647 // (2^31) - 1 +#define PROGPOW_PERIOD 10 // lanes that work together calculating a hash #define PROGPOW_LANES 16 // uint32 registers per lane @@ -20,7 +20,7 @@ // random math instructions per loop #define PROGPOW_CNT_MATH 18 -#define EPOCH_LENGTH 2147483647 // (2^31) - 1 +#define EPOCH_LENGTH 129600 // 4320 primes per day * 30 days class ProgPow { From 232983e8d7e806e05ab831ca7d35ebaa74bddbdc Mon Sep 17 00:00:00 2001 From: Hussam Date: Fri, 6 Dec 2024 11:47:59 -0600 Subject: [PATCH 6/6] test --- libethash/ethash/ethash.h | 2 +- libethash/ethash/progpow.hpp | 2 +- libprogpow/ProgPow.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libethash/ethash/ethash.h b/libethash/ethash/ethash.h index 9105a6d..876b620 100644 --- a/libethash/ethash/ethash.h +++ b/libethash/ethash/ethash.h @@ -25,7 +25,7 @@ extern "C" { */ #define ETHASH_REVISION "23" -#define ETHASH_EPOCH_LENGTH 129600 // 4320 primes per day * 30 days +#define ETHASH_EPOCH_LENGTH 4 #define ETHASH_LIGHT_CACHE_ITEM_SIZE 64 #define ETHASH_FULL_DATASET_ITEM_SIZE 128 #define ETHASH_NUM_DATASET_ACCESSES 64 diff --git a/libethash/ethash/progpow.hpp b/libethash/ethash/progpow.hpp index 56e74b7..f3a2997 100644 --- a/libethash/ethash/progpow.hpp +++ b/libethash/ethash/progpow.hpp @@ -19,7 +19,7 @@ using namespace ethash; // Include ethash namespace. /// https://github.com/ifdefelse/ProgPOW#change-history. constexpr auto revision = "0.9.3"; -constexpr int period_length = 10; +constexpr int period_length = 2; constexpr uint32_t num_regs = 32; constexpr size_t num_lanes = 16; constexpr int num_cache_accesses = 11; diff --git a/libprogpow/ProgPow.h b/libprogpow/ProgPow.h index 03feed5..efa0649 100644 --- a/libprogpow/ProgPow.h +++ b/libprogpow/ProgPow.h @@ -4,7 +4,7 @@ #include // blocks before changing the random program -#define PROGPOW_PERIOD 10 +#define PROGPOW_PERIOD 2 // lanes that work together calculating a hash #define PROGPOW_LANES 16 // uint32 registers per lane @@ -20,7 +20,7 @@ // random math instructions per loop #define PROGPOW_CNT_MATH 18 -#define EPOCH_LENGTH 129600 // 4320 primes per day * 30 days +#define EPOCH_LENGTH 4 class ProgPow {