Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major upgrades and overhaul: epochs, periods, binaries, and more #19

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CODEOWNERS

This file was deleted.

4 changes: 2 additions & 2 deletions deploy_miner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../
Expand All @@ -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 ../
Expand Down
12 changes: 6 additions & 6 deletions kawpowminer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ aux_source_directory(. SRC_LIST)

include_directories(BEFORE ..)

set(EXECUTABLE kawpowminer)
set(EXECUTABLE quai-gpu-miner)

file(GLOB HEADERS "*.h")

Expand All @@ -16,23 +16,23 @@ 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)
set( ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/lib/x86_64-linux-gnu/pkgconfig" )
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 $<TARGET_PDB_FILE:kawpowminer> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
install(FILES $<TARGET_PDB_FILE:quai-gpu-miner> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
endif()
14 changes: 11 additions & 3 deletions kawpowminer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1293,19 +1298,22 @@ 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();
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;
}
Expand Down Expand Up @@ -1358,7 +1366,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;
}
Expand Down
6 changes: 3 additions & 3 deletions libethash/ethash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion libethash/ethash/ethash.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {
*/
#define ETHASH_REVISION "23"

#define ETHASH_EPOCH_LENGTH 2147483647 // (2^31) - 1
#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
Expand Down
2 changes: 1 addition & 1 deletion libethash/ethash/progpow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 2;
constexpr uint32_t num_regs = 32;
constexpr size_t num_lanes = 16;
constexpr int num_cache_accesses = 11;
Expand Down
66 changes: 66 additions & 0 deletions libethcore/Farm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,72 @@ bool Farm::spawn_file_in_bin_dir(const char* filename, const std::vector<std::st
return false;
}

void handle_signal(int signal) {
if (signal == SIGINT) {
std::cout << "Received SIGINT (Ctrl+C), killing all quai-gpu-miner processes and exiting..." << std::endl;
system("pkill -f quai-gpu-miner"); // Kill all quai-gpu-miner processes
_exit(0); // Ensure immediate exit
}
}

bool Farm::restart_process() {
signal(SIGINT, handle_signal);

std::cout << "Restarting for new epoch" << std::endl;

int result = system("pkill -f quai-gpu-miner");
if (result == -1) {
std::cerr << "Failed to execute pkill command" << std::endl;
return false;
}

usleep(100000); // Wait 100 ms

const char* executable_path = "/proc/self/exe";

std::ifstream cmdline_file("/proc/self/cmdline", std::ios::binary);
if (!cmdline_file) {
std::cerr << "Failed to open /proc/self/cmdline" << std::endl;
return false;
}

std::vector<char> cmdline((std::istreambuf_iterator<char>(cmdline_file)),
std::istreambuf_iterator<char>());
cmdline.push_back('\0'); // Ensure null termination

std::vector<char*> 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
7 changes: 7 additions & 0 deletions libethcore/Farm.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ class Farm : public FarmFace
*/
bool reboot(const std::vector<std::string>& 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.
Expand Down
6 changes: 3 additions & 3 deletions libpoolprotocols/stratum/EthStratumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -1822,7 +1821,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);
Expand Down
4 changes: 2 additions & 2 deletions libprogpow/ProgPow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>

// blocks before changing the random program
#define PROGPOW_PERIOD 2147483647 // (2^31) - 1
#define PROGPOW_PERIOD 2
// lanes that work together calculating a hash
#define PROGPOW_LANES 16
// uint32 registers per lane
Expand All @@ -20,7 +20,7 @@
// random math instructions per loop
#define PROGPOW_CNT_MATH 18

#define EPOCH_LENGTH 2147483647 // (2^31) - 1
#define EPOCH_LENGTH 4

class ProgPow
{
Expand Down