Skip to content

Commit

Permalink
Http Broadcast server for stats added (#22)
Browse files Browse the repository at this point in the history
* Added http server to query miner stats

* Rework CMake (#21)

* Add build scripts and Building.md

* Use CPMAddPackage for Boost if we cannot find it locally

* Build on all branches

* Call --dero-test

* System update is slow. Stop doing it.

* Cleanup

* Fix a few build warnings

* Add --xelis-test to GH workflow

* Use Boost 1.85 if OS packages weren't found

---------

Co-authored-by: Tritonn204 <tritonn204@gmail.com>

* Corrected my merge conflict resolution in CMakeLists

---------

Co-authored-by: dirkerdero <126991543+dirkerdero@users.noreply.github.com>
  • Loading branch information
Tritonn204 and dirkerdero authored Apr 30, 2024
1 parent a3763ba commit b122910
Show file tree
Hide file tree
Showing 14 changed files with 283 additions and 127 deletions.
26 changes: 11 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build Tnn-miner on Ubuntu 22.04
on:
push:
branches:
- '*dev*'
- '*'
tags:
- "v*.*.*"

Expand All @@ -19,7 +19,8 @@ jobs:
sudo update-alternatives --list clang
sudo update-alternatives --list clang++
sudo update-alternatives --get-selections
sudo apt update && sudo apt upgrade -y
sudo apt update
#sudo apt upgrade -y
- name: 'Setup pre-reqs'
run: |
sudo apt install git wget build-essential cmake clang libssl-dev libudns-dev libfmt-dev libc++-dev
Expand Down Expand Up @@ -49,30 +50,25 @@ jobs:
sudo update-alternatives --display clang
clang --version
clang++ --version
- name: 'Compile boost'
run: |
wget -q https://github.com/boostorg/boost/releases/download/boost-1.82.0/boost-1.82.0.tar.gz
tar -xf boost-1.82.0.tar.gz
cd boost-1.82.0/
./bootstrap.sh --with-toolset=clang
./b2 clean
./b2 toolset=clang cxxflags=-std=c++20 -stdlib=libc++ linkflags=-stdlib=libc++ link=static
- name: 'Compile Tnn-miner'
run: |
mkdir build
cd build
cmake ..
make -j$(nproc)
tar -zcvf ../tnn-miner.tar.gz Tnn-miner
tar -cvf ../tnn-miner.tar Tnn-miner
- name: 'Archive tnn-miner.tar.gz'
uses: actions/upload-artifact@v4
with:
name: tnn-miner.tar.gz
path: ./tnn-miner.tar.gz
name: tnn-miner.tar
path: ./tnn-miner.tar
retention-days: 5
- name: 'Test Tnn-miner'
- name: 'Dero Test'
run: |
./build/Tnn-miner --dero-test
- name: 'Xelis Test'
run: |
./build/Tnn-miner --test
./build/Tnn-miner --xelis-test
- name: 'Release'
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
/build
/tests
/boost-1.82.0/**
/.cache

# Xelis rust resources
/src/xelis-hash/**.rs
Expand Down
76 changes: 56 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fstack-protector")
set (CMAKE_STANDARD_REQUIRED TRUE)
set (CMAKE_CXX_STANDARD 23)



enable_language(ASM)

include(CMakePrintHelpers)

if(WIN32)
include_directories(
"C:/mingw64/include"
Expand All @@ -55,7 +55,19 @@ endif()

include_directories(${CUDAToolkit_INCLUDE_DIRS})

set(CPM_DOWNLOAD_VERSION 0.34.0)
# download CPM.cmake
file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.38.3/CPM.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
EXPECTED_HASH SHA256=cc155ce02e7945e7b8967ddfaff0b050e958a723ef7aad3766d368940cb15494
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)

# This stores downloaded dependencies so we do not need to re-download them
set(CPM_SOURCE_CACHE "${PROJECT_SOURCE_DIR}/.cache/CPM")

set(CPM_DOWNLOAD_VERSION 0.39.0)

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
Expand Down Expand Up @@ -86,32 +98,56 @@ execute_process(COMMAND ${LSB_RELEASE_EXEC} -cs
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if("${LSB_RELEASE_CODENAME_SHORT}" STREQUAL "jammy")
set(Boost_NO_SYSTEM_PATHS TRUE)
if (Boost_NO_SYSTEM_PATHS)
set(Boost_NO_BOOST_CMAKE TRUE)
set(BOOST_ROOT "${PROJECT_SOURCE_DIR}/boost-1.82.0")
set(BOOST_INCLUDE_DIRS "${BOOST_ROOT}")
set(BOOST_LIBRARY_DIRS "${BOOST_ROOT}/libs")
endif (Boost_NO_SYSTEM_PATHS)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_NO_WARN_NEW_VERSIONS ON)
find_package(Boost 1.80 REQUIRED
find_package(Boost 1.80 COMPONENTS
chrono
context
json
thread
atomic
program_options
)
if(Boost_FOUND)
message("OS-provided Boost found")
set(TNN_BOOST_INCLUDES ${Boost_INCLUDE_DIRS})
else()
message("Boost not found. Using CPM to add it")
CPMAddPackage(
NAME Boost
VERSION 1.85.0
URL https://github.com/boostorg/boost/releases/download/boost-1.85.0/boost-1.85.0-cmake.tar.xz
URL_HASH SHA256=0a9cc56ceae46986f5f4d43fe0311d90cf6d2fa9028258a95cab49ffdacf92ad
OPTIONS "Boost_ENABLE_CMAKE ON" "BOOST_INCLUDE_LIBRARIES chrono\\\;context\\\;json\\\;thread\\\;atomic\\\;program_options" # Note the escapes!
# Maintain build compatibility between find_package and CMakeLists.txt variants
)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(Boost_ADDED)
file(GLOB files "${Boost_SOURCE_DIR}/libs/*/include")
foreach(filename ${files})
include_directories(${filename})
endforeach()

file(GLOB files "${Boost_SOURCE_DIR}/libs/*/*/include")
foreach(filename ${files})
include_directories(${filename})
endforeach()
else()
message(FATAL_ERROR "Boost was neither found nor added.")
endif()

set(TNN_BOOST_INCLUDES ${Boost_SOURCE_DIR})
endif()

set(BOOST_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
# This is universal regardless of how wheter we compiled or found Boost
set(TNN_BOOST_LIBS Boost::chrono Boost::context Boost::json Boost::thread Boost::atomic Boost::program_options)

#cmake_print_variables(TNN_BOOST_INCLUDES)
#cmake_print_variables(TNN_BOOST_LIBS)

include_directories(
${PROJECT_SOURCE_DIR}/include
Expand All @@ -122,7 +158,8 @@ include_directories(
"${PROJECT_SOURCE_DIR}/src/xelis-hash/"
"${PROJECT_SOURCE_DIR}/src/xatum/"
"${PROJECT_SOURCE_DIR}/src/miner/"
"${BOOST_INCLUDE_DIRS}"
"${TNN_BOOST_INCLUDES}"
"${PROJECT_SOURCE_DIR}/src/broadcast/"
)

set(ASM_SOURCES
Expand All @@ -139,14 +176,14 @@ file(GLOB all_SRCS
"${PROJECT_SOURCE_DIR}/src/astrobwtv3/*.c"
"${PROJECT_SOURCE_DIR}/src/xelis-hash/*.cpp"
"${PROJECT_SOURCE_DIR}/src/xelis-hash/*.c"
"${PROJECT_SOURCE_DIR}/src/broadcast/*.cpp"
"${ASM_SOURCES}"
# "${PROJECT_SOURCE_DIR}/src/astrobwtv3/*.cu"
# "${PROJECT_SOURCE_DIR}/src/astrobwtv3/*.cuh"
"${PROJECT_SOURCE_DIR}/src/miner/*.cpp"
"${PROJECT_SOURCE_DIR}/src/miner/*.c"
)

add_definitions(${GTK3_CFLAGS_OTHER})
add_executable(${PROJECT_NAME} ${all_SRCS})

if(WIN32)
Expand All @@ -155,5 +192,4 @@ endif()
if(UNIX)
target_link_libraries(${PROJECT_NAME} udns pthread)
endif()
target_link_libraries(${PROJECT_NAME} Threads::Threads nlohmann_json::nlohmann_json ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)

target_link_libraries(${PROJECT_NAME} Threads::Threads nlohmann_json::nlohmann_json ${TNN_BOOST_LIBS} OpenSSL::SSL OpenSSL::Crypto)
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@
- UDNS (UNIX only. sudo apt-get install libudns-dev)
- FMT (header only)

**For Ubuntu 22.04:**
Install development dependencies
**Building the easy way**
Use the prereqs.sh scripts (one-time only)
```
sudo apt install git wget build-essential cmake clang libssl-dev libudns-dev libfmt-dev libc++-dev
# Checkout tnn-miner got from github
git clone https://github.com/Tritonn204/tnn-miner.git
cd tnn-miner
./scripts/prereqs.sh
```
Then build!
```
./scripts/build.sh
```

Download and compile Boost 1.82. This is a one-time thing.
-- Newer versions of Boost exist, but there's some issue linking program_options
**For Ubuntu 24.04:**
Install development dependencies for Ubuntu 22.04 below, but also install the Boost dev libraries
```
wget https://github.com/boostorg/boost/releases/download/boost-1.82.0/boost-1.82.0.tar.gz
tar -xf boost-1.82.0.tar.gz
cd boost-1.82.0/
./bootstrap.sh --with-toolset=clang
./b2 clean
./b2 toolset=clang cxxflags=-std=c++20 -stdlib=libc++ linkflags=-stdlib=libc++ link=static
sudo apt install libboost1.83-all-dev
```
Proceed with Tnn-miner build

**For Ubuntu 22.04:**
Install development dependencies
```
sudo apt install git wget build-essential cmake clang libssl-dev libudns-dev libfmt-dev libc++-dev lld
# Checkout tnn-miner got from github
git clone https://github.com/Tritonn204/tnn-miner.git
cd tnn-miner
mkdir build
cd build
cmake ..
Expand Down
33 changes: 0 additions & 33 deletions cmake/CPM.cmake

This file was deleted.

5 changes: 4 additions & 1 deletion include/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#include <vector>
#include <string>
#include <algorithm>
#include <boost/program_options.hpp>

#if defined(__linux__)
#include <sys/ioctl.h>
#endif

namespace po = boost::program_options; // from <boost/program_options.hpp>

const char *versionString = "v0.3.1";
const char *versionString = "0.3.1";
const char *consoleLine = " TNN-MINER ";
const char *TNN = R"(
Expand Down Expand Up @@ -127,6 +129,7 @@ inline po::options_description get_prog_opts()
("help", "produce help message")
("dero", "Will mine Dero")
("xelis", "Will mine Xelis")
("broadcast", "Creates an http server to query miner stats")
("testnet", "Adjusts in-house parameters to mine on testnets")
("daemon-address", po::value<std::string>(), "Node/pool URL or IP address to mine to") // todo: parse out port and/or wss:// or ws://
("port", po::value<int>(), "The port used to connect to the node")
Expand Down
20 changes: 20 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

ret=0

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ROOT_DIR=$( cd -- "$( dirname -- "${SCRIPT_DIR}" )" &> /dev/null && pwd )

mkdir build
pushd build
cmake ..
ret=$?
if [[ "$ret" != "0" ]]; then
rm -rf ./*
cmake ..
fi
make -j $(nproc)
ret=$?
popd

exit $ret
12 changes: 12 additions & 0 deletions scripts/prereqs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ROOT_DIR=$( cd -- "$( dirname -- "${SCRIPT_DIR}" )" &> /dev/null && pwd )

if [[ -f /etc/lsb-release ]]; then
source /etc/lsb-release
sudo apt install git wget build-essential cmake clang libssl-dev libudns-dev libfmt-dev libc++-dev lld
if [[ "$DISTRIB_CODENAME" == "noble" ]]; then
sudo apt install libboost1.83-all-dev
fi
fi
4 changes: 2 additions & 2 deletions src/astrobwtv3/astrobwtv3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ __m256i _mm256_mul_epi8(__m256i x, __m256i y) {

__m256i _mm256_sllv_epi8(__m256i a, __m256i count) {
__m256i mask_hi = _mm256_set1_epi32(0xFF00FF00);
__m256i multiplier_lut = _mm256_set_epi8(0,0,0,0, 0,0,0,0, 128,64,32,16, 8,4,2,1, 0,0,0,0, 0,0,0,0, 128,64,32,16, 8,4,2,1);
__m256i multiplier_lut = _mm256_set_epi8(0,0,0,0, 0,0,0,0, 0x80,0x40,0x20,0x10, 0x08,0x04,0x02,0x01, 0,0,0,0, 0,0,0,0, 0x80,0x40,0x20,0x10, 0x08,0x04,0x02,0x01);

__m256i count_sat = _mm256_min_epu8(count, _mm256_set1_epi8(8)); /* AVX shift counts are not masked. So a_i << n_i = 0 for n_i >= 8. count_sat is always less than 9.*/
__m256i multiplier = _mm256_shuffle_epi8(multiplier_lut, count_sat); /* Select the right multiplication factor in the lookup table. */
Expand All @@ -194,7 +194,7 @@ __m256i _mm256_sllv_epi8(__m256i a, __m256i count) {

__m256i _mm256_srlv_epi8(__m256i a, __m256i count) {
__m256i mask_hi = _mm256_set1_epi32(0xFF00FF00);
__m256i multiplier_lut = _mm256_set_epi8(0,0,0,0, 0,0,0,0, 1,2,4,8, 16,32,64,128, 0,0,0,0, 0,0,0,0, 1,2,4,8, 16,32,64,128);
__m256i multiplier_lut = _mm256_set_epi8(0,0,0,0, 0,0,0,0, 0x01,0x02,0x04,0x08, 0x10,0x20,0x40,0x80, 0,0,0,0, 0,0,0,0, 0x01,0x02,0x04,0x08, 0x10,0x20,0x40,0x80);

__m256i count_sat = _mm256_min_epu8(count, _mm256_set1_epi8(8)); /* AVX shift counts are not masked. So a_i >> n_i = 0 for n_i >= 8. count_sat is always less than 9.*/
__m256i multiplier = _mm256_shuffle_epi8(multiplier_lut, count_sat); /* Select the right multiplication factor in the lookup table. */
Expand Down
Loading

0 comments on commit b122910

Please sign in to comment.