Dev:Build a Nexus Mining Pool

From Nexus Wiki
Jump to navigation Jump to search

Pool for Nexus Hash and Prime channels: https://github.com/Nexusoft/Mining-Pool

Set Up NexusWebUI

Instructions for Ubuntu 20.04

NexusWebUI

Replace requirments.txt with the following (Python 3.12):

apply_defaults==0.1.6
asgiref==3.8.1
attrs==24.2.0
bson==0.5.10
certifi==2024.8.30
cffi==1.17.1
charset-normalizer==3.3.2
click==8.1.7
cryptography==43.0.1
Django==5.1.1
django-tables2==2.7.0
Faker==30.1.0
greenlet==3.1.1
grpcio==1.66.2
gunicorn==23.0.0
idna==3.10
importlib_metadata==8.5.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
numpy==2.1.2
packaging==24.1
pandas==2.2.3
protobuf==5.28.2
pybson==0.5.9
pycparser==2.22
pyrsistent==0.20.0
python-dateutil==2.9.0.post0
python-decouple==3.8
pytz==2024.2
PyYAML==6.0.2
referencing==0.35.1
requests==2.32.3
rpds-py==0.20.0
setuptools==75.1.0
six==1.16.0
SQLAlchemy==2.0.35
sqlparse==0.5.1
text-unidecode==1.3
typing_extensions==4.12.2
tzdata==2024.2
urllib3==2.2.3
zipp==3.20.2

Run the following commands for basic UI setup:

sudo apt install -y cmake make python3.8-venv
git clone https://github.com/Nexusoft/Mining-Pool.git
cd Mining-Pool/NexusWebUI
python3 -m venv ./venv
source venv/bin/activate
pip install -r requirements.txt

.env:

SECRET_KEY=88888888888888888888888888888888
ALLOWED_HOSTS=localhost,127.0.0.1,hashpool.nexus-wiki.org
POOL_IP=127.0.0.1
POOL_PORT=50000
POOL_HOST=hashpool.nexus-wiki.org
POOL_USER=<user>
POOL_PWD=<pass>
mkdir logs
python3 manage.py migrate
python3 manage.py runserver 0.0.0.0:80

gunicorn test:

source venv/bin/activate
gunicorn --bind 0.0.0.0:80 NexusWebUI.wsgi

gunicorn setup:

sudo nano /etc/systemd/system/gunicorn.socket
[Unit]
Description=Gunicorn socket for Django project
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
sudo nano /etc/systemd/system/gunicorn.service
[Unit]
Description=Gunicorn service for Django project
Requires=gunicorn.socket
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/Projects/GitHub/Mining-Pool/NexusWebUI
ExecStart=/root/Projects/GitHub/Mining-Pool/NexusWebUI/venv/bin/gunicorn \
--access-logfile - \
--error-logfile - \
--bind unix:/run/gunicorn.sock \
NexusWebUI.wsgi:application
[Install]
WantedBy=multi-user.target
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
sudo systemctl status gunicorn.socket

nginx setup:

sudo apt install -y nginx
sudo nano /etc/nginx/sites-available/NexusWebUI
server {
    listen 80;
    server_name hashpool.nexus-wiki.org;

    location = /favicon.ico { access_log off; log_not_found off; }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}
sudo ln -s /etc/nginx/sites-available/NexusWebUI /etc/nginx/sites-enabled
nginx -t
sudo systemctl restart nginx

certbot setup

sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx

Mining-Pool Setup

sudo apt-get install -y libssl-dev libsqlite3-dev sqlite3

update CMakeLists.txt to link openssl

cmake_minimum_required(VERSION 3.19)

project(NexusPool VERSION 1.0 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

configure_file(src/version.h.in version.h)

set(CPM_DOWNLOAD_VERSION 0.35.0) 
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
    message(STATUS "Downloading CPM.cmake")
    file(DOWNLOAD https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake ${CPM_DOWNLOAD_LOCATION})
endif()

include(${CPM_DOWNLOAD_LOCATION})

find_package(Threads REQUIRED)
# Find OpenSSL
find_package(OpenSSL REQUIRED)

#spdlog
CPMAddPackage(NAME spdlog GITHUB_REPOSITORY gabime/spdlog VERSION 1.9.2)

#nlohmann json
CPMAddPackage(NAME nlohmann_json GITHUB_REPOSITORY nlohmann/json  VERSION 3.10.5)

#ASIO
CPMAddPackage("gh:chriskohlhoff/asio#[email protected]")

# ASIO doesn't use CMake, we have to configure it manually. Extra notes for using on Windows:
#
# 1) If _WIN32_WINNT is not set, ASIO assumes _WIN32_WINNT=0x0501, i.e. Windows XP target, which is
# definitely not the platform which most users target.
#
# 2) WIN32_LEAN_AND_MEAN is defined to make Winsock2 work.
if(asio_ADDED)
  add_library(asio INTERFACE)

  target_include_directories(asio SYSTEM INTERFACE ${asio_SOURCE_DIR}/asio/include)
  target_compile_definitions(asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED)
  target_link_libraries(asio INTERFACE Threads::Threads)

  if(WIN32)
    # macro see @ https://stackoverflow.com/a/40217291/1746503
    macro(get_win32_winnt version)
      if(CMAKE_SYSTEM_VERSION)
        set(ver ${CMAKE_SYSTEM_VERSION})
        string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
        string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
        # Check for Windows 10, b/c we'll need to convert to hex 'A'.
        if("${verMajor}" MATCHES "10")
          set(verMajor "A")
          string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
        endif("${verMajor}" MATCHES "10")
        # Remove all remaining '.' characters.
        string(REPLACE "." "" ver ${ver})
        # Prepend each digit with a zero.
        string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
        set(${version} "0x${ver}")
      endif()
    endmacro()

    if(NOT DEFINED _WIN32_WINNT)
      get_win32_winnt(ver)
      set(_WIN32_WINNT ${ver})
    endif()

    message(STATUS "Set _WIN32_WINNET=${_WIN32_WINNT}")

    target_compile_definitions(asio INTERFACE _WIN32_WINNT=${_WIN32_WINNT} WIN32_LEAN_AND_MEAN)
  endif()
endif()

# Howard Hinnant's date library
CPMAddPackage(NAME date GITHUB_REPOSITORY HowardHinnant/date VERSION 3.0.1)

include_directories(${CMAKE_SOURCE_DIR}/include/)
link_directories(${CMAKE_SOURCE_DIR}/libs)

option(WITH_TESTS "Build with unit tests" OFF)

# OpenSSL
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})

if(UNIX)
    add_definitions(-DUNIX)
    find_package(SQLite3 REQUIRED)
    if (SQLITE3_FOUND)
        include_directories(${SQLITE3_INCLUDE_DIRS})
    endif (SQLITE3_FOUND)
endif()

if(WIN32)
    add_definitions(-D_WIN32_WINT=0x0601 -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS)
endif()

CPMAddPackage(NAME oatpp GITHUB_REPOSITORY  GIT_REPOSITORY https://github.com/oatpp/oatpp.git VERSION 1.3.0  GIT_TAG "1.3.0" OPTIONS "OATPP_BUILD_TESTS OFF")

# add submodules
add_subdirectory(src/chrono)
add_subdirectory(src/common)
add_subdirectory(src/network)
add_subdirectory(src/config)
add_subdirectory(src/api)
add_subdirectory(src/LLP)
add_subdirectory(src/LLC)
add_subdirectory(src/TAO)
add_subdirectory(src/persistance)
add_subdirectory(src/reward)
add_subdirectory(src/nexus_http_interface)
add_subdirectory(src/pool)

if(WITH_TESTS)
    add_subdirectory(tests)
endif()

add_executable(NexusPool 
                src/main.cpp 
                src/pool.cpp)

target_include_directories(NexusPool PUBLIC "${PROJECT_BINARY_DIR}")

target_link_libraries(NexusPool pool asio)

target_link_libraries(NexusPool Threads::Threads)

# Add the OpenSSL libraries to your target
target_link_libraries(NexusPool OpenSSL::SSL OpenSSL::Crypto) 

# find_package(Threads REQUIRED)
target_link_libraries(NexusPool OpenSSL::SSL OpenSSL::Crypto Threads::Threads) 

set_target_properties(NexusPool PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS "-a F:/Work/Nexus Project/LLL-HPP/out/build/x64-Debug/api.conf -p pool.conf")
cmake CMakeLists.txt
make

pool.conf

{
    "wallet_ip" : "127.0.0.1",
    "wallet_port" : 8080,
    "local_ip" : "127.0.0.1",
    "local_port" : 0,
    "public_ip" : "0.0.0.0",
    "miner_listen_port" : 50000,
    "mining_mode" : "HASH",
    "connection_retry_interval" : 5,
    "get_height_interval" : 2,
    "session_expiry_time" : 30,
    "legacy_mode" : false,
    "pool" :
    {
        "account" : "default",
        "pin" : "<pin>",
        "fee" : 1,
        "difficulty_divider" : 4,
        "round_duration_hours" : 24,
        "nxs_api_user" : "<user>,
        "nxs_api_pw" : "<pass>"
    },
    "enable_ddos" : true,
    "ddos" :
    {
        "ddos_rscore" : 20,
        "ddos_cscore" : 2
    },
    "logfile" : "pool.log",
    "log_level" : 2,
    "persistance" :
    {
        "type" : "sqlite",
        "file" : "nexuspool.db"
    },
    "update_block_hashes_interval" : 600,
    "get_hashrate_interval" : 300,
    "miner_notifications" : true
}