Skip to content
Open
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@
*.lib
*.a
makefile
Makefile

beamMiner
beamMiner.exe

beam-opencl-miner
beam-opencl-miner.exe

CMakeFiles/
CMakeCache.txt
cmake_install.cmake
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ before_script:
after_success:
# deploy using ftp server
- BUILDS_SERVER_PATH=${BUILD_SERVER}/files/$TRAVIS_BRANCH/$(date +%Y.%m.%d)/$BUILD_TYPE/$OS_FOLDER
- tar -cvzf opencl-miner-$BEAM_VERSION.tar.gz --directory=$HOME/build/BeamMW/opencl-miner beam-opencl-miner equihash_150_5.cl
- tar -cvzf opencl-miner-$BEAM_VERSION.tar.gz --directory=$HOME/build/BeamMW/opencl-miner beam-opencl-miner

# upload binaries to FTP
- curl --retry 3 --ftp-create-dirs -T opencl-miner-$BEAM_VERSION.tar.gz $BUILDS_SERVER_PATH/
Expand Down
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
find_package(Boost REQUIRED COMPONENTS system date_time regex thread)

set(OPENSSL_USE_STATIC_LIBS TRUE)

find_package(Boost REQUIRED COMPONENTS system date_time thread)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
Expand All @@ -33,10 +36,7 @@ endif()


find_package(OpenSSL REQUIRED)
if( OpenSSL_FOUND )
if (UNIX)
set(OPENSSL_USE_STATIC_LIBS TRUE)
endif()
if( OpenSSL_FOUND )
link_directories(${OPENSSL_LIBRARIES})
include_directories(${OPENSSL_INCLUDE_DIR})
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
Expand Down Expand Up @@ -76,6 +76,7 @@ target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/clH
if(UNIX)
find_package(Threads)
target_link_libraries(${TARGET_NAME} Threads::Threads)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
endif()

if(MSVC)
Expand All @@ -88,3 +89,6 @@ endif()
target_link_libraries(${TARGET_NAME} OpenCL::OpenCL)
target_link_libraries(${TARGET_NAME} ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
target_link_libraries(${TARGET_NAME} ${Boost_LIBRARIES})
if(UNIX)
target_link_libraries(${TARGET_NAME} -ldl)
endif()
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ before_build:
- cmd: set PATH=%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin;%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp;%PATH%
#- cmd: git clone --depth=1 https://github.com/BeamMW/libs.git c:/beam-libs
#- cmd: git clone --depth=1 https://github.com/nesbox/qt5-static-win.git c:/beam-libs/qt5-static-win
- cmd: cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=%BUILD_CONFIG%
- cmd: cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=%BUILD_CONFIG% .

build_script:
- cmake --build . --parallel --config %BUILD_CONFIG%
Expand All @@ -34,7 +34,7 @@ after_build:

set BEAM_VERSION=1.0.%BEAM_VERSION_REVISION%

7z a c:/projects/opencl-miner/%BUILD_CONFIG%/opencl-miner-%BEAM_VERSION%.zip c:/projects/opencl-miner/%BUILD_CONFIG%/beam-opencl-miner.exe c:/projects/opencl-miner/equihash_150_5.cl
7z a c:/projects/opencl-miner/%BUILD_CONFIG%/opencl-miner-%BEAM_VERSION%.zip c:/projects/opencl-miner/%BUILD_CONFIG%/beam-opencl-miner.exe

copy c:\projects\opencl-miner\%BUILD_CONFIG%\opencl-miner-%BEAM_VERSION%.zip c:\projects\opencl-miner\opencl-miner-%BEAM_VERSION%.zip

Expand All @@ -61,9 +61,9 @@ artifacts:
deploy:
provider: S3
access_key_id:
secure: J8+/d4TSbhxiaFlDQopFzKbfLPvUy1rMUJlAgnfbBNE=
secure: c7t4F6CxylXQf77OIgif/9mJzb7b0VMWg+Jtpe14dmY=
secret_access_key:
secure: sqF9zdsuUm/k9QzY46s250MZJamHjKrwBCAPbinBA/iOJlgLsHC7lq1F5pTr/B+U
secure: 2hi98QLQZulcRMk40ODSwKfGnIUaHGbqkHcyUutpe742XWZilKix4ZmZ3fRePe1A
bucket: builds.beam.mw
region: us-west-2
unzip: false
Expand Down
39 changes: 33 additions & 6 deletions beamStratum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void beamStratum::writeHandler(const boost::system::error_code& err) {

// Called by main() function, starts the stratum client thread
void beamStratum::startWorking(){
t_start = time(NULL);
std::thread (&beamStratum::connect,this).detach();
}

Expand Down Expand Up @@ -95,7 +96,7 @@ void beamStratum::connect() {
// Once the physical connection is there start a TLS handshake
void beamStratum::handleConnect(const boost::system::error_code& err, tcp::resolver::iterator endpoint_iterator) {
if (!err) {
cout << "Connected to node. Starting TLS handshake." << endl;
cout << "Node connection: ok" << endl;

// The connection was successful. Do the TLS handshake
socket->async_handshake(boost::asio::ssl::stream_base::client,boost::bind(&beamStratum::handleHandshake, this, boost::asio::placeholders::error));
Expand Down Expand Up @@ -125,7 +126,7 @@ void beamStratum::handleHandshake(const boost::system::error_code& error) {
boost::asio::async_read_until(*socket, responseBuffer, "\n",
boost::bind(&beamStratum::readStratum, this, boost::asio::placeholders::error));

cout << "TLS Handshake sucess" << endl;
cout << "TLS Handshake: ok" << endl;

// The connection was successful. Send the login request
std::stringstream json;
Expand Down Expand Up @@ -184,16 +185,22 @@ void beamStratum::readStratum(const boost::system::error_code& err) {
} else {
poolNonce.clear();
}

if (jsonTree.count("forkheight") > 0) {
forkHeight = jsonTree.get<uint64_t>("forkheight");
}
} else {
cout << "Error: Login at node not accepted. Closing miner." << endl;
exit(0);
}
} else { // A share reply
int32_t code = jsonTree.get<int32_t>("code");
if (code == 1) {
cout << "Solution for work id " << jsonTree.get<string>("id") << "accepted" << endl;
cout << "Solution for work id " << jsonTree.get<string>("id") << " accepted" << endl;
sharesAcc++;
} else {
cout << "Warning: Solution for work id " << jsonTree.get<string>("id") << "not accepted" << endl;
cout << "Warning: Solution for work id " << jsonTree.get<string>("id") << " rejected" << endl;
sharesRej++;
}
}
}
Expand All @@ -211,9 +218,24 @@ void beamStratum::readStratum(const boost::system::error_code& err) {
// Get the target difficulty
uint32_t stratDiff = jsonTree.get<uint32_t>("difficulty");
powDiff = beam::Difficulty(stratDiff);

// Nicehash support
if (jsonTree.count("nonceprefix") > 0) {
string poolNonceStr = jsonTree.get<string>("nonceprefix");
poolNonce = parseHex(poolNonceStr);
}

// Block Height for fork detection
if (jsonTree.count("height") > 0) {
blockHeight = jsonTree.get<uint64_t>("height");
if (blockHeight == forkHeight) cout << "-= PoW fork height reached. Switching algorithm =-" << endl;
}


updateMutex.unlock();

cout << "New work received with id " << workId << " at difficulty " << powDiff.ToFloat() << endl;
cout << "New job: " << workId << " Difficulty: " << std::fixed << std::setprecision(0) << powDiff.ToFloat() << endl;
cout << "Solutions (Accepted/Rejected): " << sharesAcc << " / " << sharesRej << " Uptime: " << (int)(t_current-t_start) << " sec" << endl;
}

// Cancel a running job
Expand All @@ -225,12 +247,13 @@ void beamStratum::readStratum(const boost::system::error_code& err) {
if (id == workId) workId = -1;
updateMutex.unlock();
}
t_current = time(NULL);
}



} catch(const pt::ptree_error &e) {
cout << "Json parse error: " << e.what() << endl;
cout << "Json parse error when reading Stratum node: " << e.what() << endl;
}

// Prepare to continue reading
Expand Down Expand Up @@ -265,6 +288,10 @@ void beamStratum::getWork(WorkDescription& wd, uint8_t* dataOut) {

wd.workId = workId;
wd.powDiff = powDiff;

uint64_t limit = numeric_limits<uint64_t>::max();
wd.forceBeamHashI = (blockHeight < limit) && (forkHeight < limit) && (blockHeight < forkHeight);

memcpy(dataOut, serverWork.data(), 32);

updateMutex.unlock();
Expand Down
9 changes: 9 additions & 0 deletions beamStratum.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class beamStratum {
std::atomic<uint64_t> nonce;
beam::Difficulty powDiff;
std::vector<uint8_t> poolNonce;
// Stat
uint64_t sharesAcc = 0;
uint64_t sharesRej = 0;
time_t t_start, t_current;

//Stratum sending subsystem
bool activeWrite = false;
Expand All @@ -80,12 +84,17 @@ class beamStratum {
static bool testSolution(const beam::Difficulty&, const std::vector<uint32_t>&, std::vector<uint8_t>&);
void submitSolution(int64_t, uint64_t, const std::vector<uint8_t>&);

// Fork Information
uint64_t blockHeight = numeric_limits<uint64_t>::max();
uint64_t forkHeight = numeric_limits<uint64_t>::max();

public:
beamStratum(string, string, string, bool);
void startWorking();

struct WorkDescription
{
bool forceBeamHashI;
int64_t workId;
uint64_t nonce;
beam::Difficulty powDiff;
Expand Down
Loading