Skip to content
This repository was archived by the owner on Oct 21, 2019. It is now read-only.

Commit f9e9ce6

Browse files
author
nicehashdev
committed
NiceHash modifications
- Added support for EthereumStratum/1.0.0 - Added speed&DAGprogress reporting
1 parent 5737c17 commit f9e9ce6

13 files changed

Lines changed: 188 additions & 40 deletions

BuildInfo.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#define ETH_PROJECT_VERSION "@PROJECT_VERSION@-genoil-@GENOIL_VERSION@"
3+
#define ETH_PROJECT_VERSION "@PROJECT_VERSION@-genoil-@GENOIL_VERSION@-NiceHash-@NICEHASH_VERSION@"
44
#define ETH_COMMIT_HASH @ETH_COMMIT_HASH@
55
#define ETH_CLEAN_REPO @ETH_CLEAN_REPO@
66
#define ETH_BUILD_TYPE @ETH_BUILD_TYPE@

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.12)
33

44
set(PROJECT_VERSION "0.9.41")
55
set(GENOIL_VERSION "1.0.8")
6+
set(NICEHASH_VERSION "1.0.0")
67
if (${CMAKE_VERSION} VERSION_GREATER 3.0)
78
cmake_policy(SET CMP0042 OLD) # fix MACOSX_RPATH
89
cmake_policy(SET CMP0048 NEW) # allow VERSION argument in project()
@@ -172,7 +173,7 @@ function(createBuildInfo)
172173
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
173174
COMMAND ${CMAKE_COMMAND} -DETH_SOURCE_DIR="${CMAKE_SOURCE_DIR}" -DETH_DST_DIR="${CMAKE_BINARY_DIR}"
174175
-DETH_BUILD_TYPE="${_cmake_build_type}" -DETH_BUILD_PLATFORM="${ETH_BUILD_PLATFORM}"
175-
-DPROJECT_VERSION="${PROJECT_VERSION}" -DGENOIL_VERSION="${GENOIL_VERSION}" -DETH_FATDB="${FATDB}"
176+
-DPROJECT_VERSION="${PROJECT_VERSION}" -DGENOIL_VERSION="${GENOIL_VERSION}" -DNICEHASH_VERSION="${NICEHASH_VERSION}" -DETH_FATDB="${FATDB}"
176177
-P "${ETH_SCRIPTS_DIR}/buildinfo.cmake"
177178
)
178179
include_directories(${CMAKE_CURRENT_BINARY_DIR})

ethminer/MinerAux.h

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ struct MiningChannel: public LogChannel
9696
};
9797
#define minelog clog(MiningChannel)
9898

99+
struct ReportStruct
100+
{
101+
double speed;
102+
unsigned int DAGprogress;
103+
};
104+
99105
class MinerCLI
100106
{
101107
public:
@@ -109,7 +115,12 @@ class MinerCLI
109115
Stratum
110116
};
111117

112-
MinerCLI(OperationMode _mode = OperationMode::None): mode(_mode) {}
118+
MinerCLI(OperationMode _mode = OperationMode::None): mode(_mode)
119+
{
120+
m_speedReportSocket = new boost::asio::ip::udp::socket(m_io_service, boost::asio::ip::udp::v4());
121+
boost::asio::socket_base::non_blocking_io command(true);
122+
m_speedReportSocket->io_control(command);
123+
}
113124

114125
bool interpretOption(int& i, int argc, char** argv)
115126
{
@@ -223,6 +234,10 @@ class MinerCLI
223234
{
224235
m_worktimeout = atoi(argv[++i]);
225236
}
237+
else if ((arg == "--report-port") && i + 1 < argc)
238+
{
239+
m_speedReportPort = atoi(argv[++i]);
240+
}
226241

227242
#endif
228243
#if ETH_ETHASHCL || !ETH_TRUE
@@ -352,8 +367,8 @@ class MinerCLI
352367
cerr << "Bad " << arg << " option: " << argv[i] << endl;
353368
BOOST_THROW_EXCEPTION(BadArgument());
354369
}
355-
else if (arg == "-C" || arg == "--cpu")
356-
m_minerType = MinerType::CPU;
370+
//else if (arg == "-C" || arg == "--cpu")
371+
// m_minerType = MinerType::CPU;
357372
else if (arg == "-G" || arg == "--opencl")
358373
m_minerType = MinerType::CL;
359374
else if (arg == "-U" || arg == "--cuda")
@@ -624,7 +639,7 @@ class MinerCLI
624639
<< " bench - like old, but keep epoch 0 for benchmarking" << endl
625640
<< " all - erase all DAG files. After deleting all files, setting changes to none." << endl
626641
<< "Mining configuration:" << endl
627-
<< " -C,--cpu When mining, use the CPU." << endl
642+
//<< " -C,--cpu When mining, use the CPU." << endl
628643
<< " -G,--opencl When mining use the GPU via OpenCL." << endl
629644
<< " -U,--cuda When mining use the GPU via CUDA." << endl
630645
<< " --opencl-platform <n> When mining using -G/--opencl use OpenCL platform n (default: 0)." << endl
@@ -651,6 +666,7 @@ class MinerCLI
651666
<< " sync - Instruct CUDA to block the CPU thread on a synchronization primitive when waiting for the results from the device." << endl
652667
<< " --cuda-devices <0 1 ..n> Select which CUDA GPUs to mine on. Default is to use all" << endl
653668
#endif
669+
<< " --report-port Speed reporting port (used by NiceHash Miner)" << endl
654670
;
655671
}
656672

@@ -662,11 +678,22 @@ class MinerCLI
662678
{
663679
h256 seedHash = EthashAux::seedHash(_n);
664680
cout << "Initializing DAG for epoch beginning #" << (_n / 30000 * 30000) << " (seedhash " << seedHash.abridged() << "). This will take a while." << endl;
665-
EthashAux::full(seedHash, true);
681+
EthashAux::full(seedHash, true, [&](unsigned _pc) {
682+
cout << "\rCreating DAG. " << _pc << "% done..." << flush;
683+
reportDAGprogress(_pc);
684+
return 0;
685+
});
666686
exit(0);
667687
}
668688

669-
689+
void reportDAGprogress(unsigned _pc)
690+
{
691+
ReportStruct rs;
692+
rs.DAGprogress = _pc;
693+
rs.speed = 0;
694+
boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string("127.0.0.1"), m_speedReportPort);
695+
m_speedReportSocket->send_to(boost::asio::buffer((void*)&rs, (size_t)sizeof(ReportStruct)), endpoint);
696+
}
670697

671698
void doBenchmark(MinerType _m, bool _phoneHome, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5)
672699
{
@@ -1049,23 +1076,64 @@ class MinerCLI
10491076
client.submit(sol);
10501077
return false;
10511078
});
1079+
1080+
boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string("127.0.0.1"), m_speedReportPort);
10521081

1082+
#define WORKINGPROGRESS_BACKLOG_SIZE 32
1083+
#define REPORT_DELAY 4
1084+
WorkingProgress wplist[WORKINGPROGRESS_BACKLOG_SIZE];
1085+
int wplist_index = 0;
1086+
bool first = false;
1087+
//int wplist_filled = 0;
1088+
10531089
while (client.isRunning())
10541090
{
10551091
auto mp = f.miningProgress();
1092+
if (!first) first = true; // for some reason, first ms is huge...
1093+
else
1094+
{
1095+
wplist[wplist_index].hashes = mp.hashes;
1096+
wplist[wplist_index].ms = mp.ms;
1097+
wplist_index = (wplist_index + 1) % WORKINGPROGRESS_BACKLOG_SIZE;
1098+
//wplist_filled = (wplist_filled == WORKINGPROGRESS_BACKLOG_SIZE) ? wplist_filled : (wplist_filled + 1);
1099+
mp.hashes = 0;
1100+
mp.ms = 0;
1101+
for (int i = 0; i != WORKINGPROGRESS_BACKLOG_SIZE; ++i)
1102+
{
1103+
mp.hashes += wplist[i].hashes;
1104+
mp.ms += wplist[i].ms;
1105+
}
1106+
1107+
if (wplist_index % REPORT_DELAY == 0)
1108+
{
1109+
ReportStruct rs;
1110+
rs.speed = 0;
1111+
if (mp.ms > 0)
1112+
rs.speed = (double)mp.hashes / (mp.ms * 1000);
1113+
rs.DAGprogress = 100;
1114+
m_speedReportSocket->send_to(boost::asio::buffer((void*)&rs, sizeof(ReportStruct)), endpoint);
1115+
}
1116+
}
1117+
10561118
f.resetMiningProgress();
10571119
if (client.isConnected())
10581120
{
10591121
if (client.current())
1060-
minelog << "Mining on PoWhash" << "#"+(client.currentHeaderHash().hex().substr(0,8)) << ": " << mp << f.getSolutionStats();
1122+
minelog << "Mining on PoWhash" << "#" + (client.currentHeaderHash().hex().substr(0, 8)) << ": " << mp << f.getSolutionStats();
10611123
else if (client.waitState() == MINER_WAIT_STATE_WORK)
10621124
minelog << "Waiting for work package...";
10631125
}
10641126
this_thread::sleep_for(chrono::milliseconds(m_farmRecheckPeriod));
10651127
}
1128+
1129+
delete m_speedReportSocket;
10661130
}
10671131
#endif
10681132

1133+
uint16_t m_speedReportPort = 37450;
1134+
boost::asio::ip::udp::socket* m_speedReportSocket;
1135+
boost::asio::io_service m_io_service;
1136+
10691137
/// Operating mode.
10701138
OperationMode mode;
10711139
DAGEraseMode m_eraseMode = DAGEraseMode::None;

ethminer/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ int main(int argc, char** argv)
7070
{
7171
cout << "Genoil's ethminer " << ETH_PROJECT_VERSION << endl;
7272
cout << "=====================================================================" << endl;
73+
cout << "Modified by NiceHash with better&correct stratum" << endl;
7374
cout << "Forked from github.com/ethereum/cpp-ethereum" << endl;
7475
cout << "CUDA kernel ported from Tim Hughes' OpenCL kernel" << endl;
7576
cout << "With contributions from nerdralph, RoBiK, tpruvot and sp_ " << endl << endl;

libethash-cl/ethash_cl_miner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ typedef struct
471471
unsigned buf;
472472
} pending_batch;
473473

474-
void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook& hook)
474+
void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook& hook, uint64_t startn)
475475
{
476476
try
477477
{
@@ -497,8 +497,9 @@ void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook
497497
m_searchKernel.setArg(4, target);
498498

499499
unsigned buf = 0;
500-
random_device engine;
501-
uint64_t start_nonce = uniform_int_distribution<uint64_t>()(engine);
500+
//random_device engine;
501+
//uint64_t start_nonce = uniform_int_distribution<uint64_t>()(engine);
502+
uint64_t start_nonce = startn;
502503
for (;; start_nonce += m_globalWorkSize)
503504
{
504505
// supply output buffer to kernel

libethash-cl/ethash_cl_miner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ethash_cl_miner
5858
unsigned _deviceId = 0
5959
);
6060
void finish();
61-
void search(uint8_t const* _header, uint64_t _target, search_hook& _hook);
61+
void search(uint8_t const* _header, uint64_t _target, search_hook& _hook, uint64_t startn);
6262

6363
/* -- default values -- */
6464
/// Default value of the local work size. Also known as workgroup size.

libethash-cuda/ethash_cuda_miner.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ bool ethash_cuda_miner::init(uint8_t const* _dag, uint64_t _dagSize, unsigned _d
251251
}
252252
}
253253

254-
void ethash_cuda_miner::search(uint8_t const* header, uint64_t target, search_hook& hook)
254+
void ethash_cuda_miner::search(uint8_t const* header, uint64_t target, search_hook& hook, uint64_t startn)
255255
{
256256
bool initialize = false;
257257
bool exit = false;
@@ -269,13 +269,20 @@ void ethash_cuda_miner::search(uint8_t const* header, uint64_t target, search_ho
269269
}
270270
if (initialize)
271271
{
272-
random_device engine;
273-
m_current_nonce = uniform_int_distribution<uint64_t>()(engine);
272+
//random_device engine;
273+
//m_current_nonce = uniform_int_distribution<uint64_t>()(engine);
274+
m_starting_nonce = 0;
274275
m_current_index = 0;
275276
CUDA_SAFE_CALL(cudaDeviceSynchronize());
276277
for (unsigned int i = 0; i < s_numStreams; i++)
277278
m_search_buf[i][0] = 0;
278279
}
280+
if (m_starting_nonce != startn)
281+
{
282+
// reset nonce counter
283+
m_starting_nonce = startn;
284+
m_current_nonce = m_starting_nonce;
285+
}
279286
uint64_t batch_size = s_gridSize * s_blockSize;
280287
for (; !exit; m_current_index++, m_current_nonce += batch_size)
281288
{

libethash-cuda/ethash_cuda_miner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ethash_cuda_miner
4040
unsigned _deviceId = 0
4141
);
4242
void finish();
43-
void search(uint8_t const* header, uint64_t target, search_hook& hook);
43+
void search(uint8_t const* header, uint64_t target, search_hook& hook, uint64_t startn);
4444

4545
/* -- default values -- */
4646
/// Default value of the block size. Also known as workgroup size.
@@ -54,6 +54,7 @@ class ethash_cuda_miner
5454
hash32_t m_current_header;
5555
uint64_t m_current_target;
5656
uint64_t m_current_nonce;
57+
uint64_t m_starting_nonce;
5758
uint64_t m_current_index;
5859

5960
volatile uint32_t ** m_search_buf;

libethcore/EthashAux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ struct EthashProofOfWork
6363
h256 boundary;
6464
h256 headerHash; ///< When h256() means "pause until notified a new work package is available".
6565
h256 seedHash;
66+
uint64_t startNonce;
67+
int exSizeBits;
6668
};
6769

6870
static const WorkPackage NullWorkPackage;

libethcore/EthashCUDAMiner.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
3131
#include <thread>
3232
#include <chrono>
3333
#include <libethash-cuda/ethash_cuda_miner.h>
34+
#include <libethash/endian.h>
3435
using namespace std;
3536
using namespace dev;
3637
using namespace eth;
@@ -180,7 +181,11 @@ void EthashCUDAMiner::workLoop()
180181
}
181182

182183
uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192);
183-
m_miner->search(w.headerHash.data(), upper64OfBoundary, *m_hook);
184+
uint64_t startn = w.startNonce | ((uint64_t)index() << (64 - 4 - w.exSizeBits)); // this can support up to 16 devices
185+
uint64_t swapped = ethash_swap_u64(startn);
186+
Nonce startN((byte const*)&swapped, h64::ConstructFromPointerType::ConstructFromPointer);
187+
cnote << "starting nonce is " << startN.hex();
188+
m_miner->search(w.headerHash.data(), upper64OfBoundary, *m_hook, startn);
184189
}
185190
catch (std::runtime_error const& _e)
186191
{

0 commit comments

Comments
 (0)