Skip to content

Commit

Permalink
Debug option for solution validation and avg hashrate stats
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralvarez committed Oct 24, 2016
1 parent 3ba1ba3 commit 4ae4d28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/libzogminer/gpusolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "gpusolver.h"

#define DEBUG

GPUSolver::GPUSolver() {

/* Notes
Expand Down Expand Up @@ -112,7 +114,15 @@ bool GPUSolver::GPUSolve200_9(const eh_HashState& base_state,

auto d = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t);
auto milis = std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
std::cout << "Kernel run took " << milis << " ms. (" << 1000.f*n_sol/milis << " H/s)" << std::endl;
if(!counter) {
sum = 1000.f*n_sol/milis;
} else {
sum += 1000.f*n_sol/milis;
}

avg = sum/++counter;

std::cout << "Kernel run took " << milis << " ms. (" << avg << " H/s)" << std::endl;

size_t checkedSols = 0;
for (size_t s = 0; s < n_sol; ++s) {
Expand All @@ -123,17 +133,16 @@ bool GPUSolver::GPUSolve200_9(const eh_HashState& base_state,
index_vector[i] = indices[s * PROOFSIZE + i];
}
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
#ifdef DEBUG
bool isValid;
EhIsValidSolution(200, 9, base_state, sol_char, isValid);
std::cout << "is valid: " << isValid << '\n';
if (isValid) {
// If we find a POW solution, do not try other solutions
// because they become invalid as we created a new block in blockchain.
std::cout << "Valid solution found!" << std::endl;
return true;
if (!isValid) {
//If we find invalid solution bail, it cannot be a valid POW
std::cout << "Invalid solution found!" << std::endl;
return false;
}

#endif
if (validBlock(sol_char)) {
// If we find a POW solution, do not try other solutions
// because they become invalid as we created a new block in blockchain.
Expand Down
4 changes: 4 additions & 0 deletions src/libzogminer/gpusolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class GPUSolver {
static const uint32_t PROOFSIZE = 1 << EK;
//TODO 20?
uint32_t indices[20*PROOFSIZE];
//Avg
uint32_t counter = 0;
float sum = 0.f;
float avg = 0.f;

bool GPUSolve200_9(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
Expand Down

0 comments on commit 4ae4d28

Please sign in to comment.