Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit c5f99f5

Browse files
committedMay 30, 2017
Drop evaluation by full DAG
1 parent 8e417c2 commit c5f99f5

21 files changed

+22
-1435
lines changed
 

‎ethminer/MinerAux.h

-10
Original file line numberDiff line numberDiff line change
@@ -596,15 +596,6 @@ class MinerCLI
596596
MinerType minerType() const { return m_minerType; }
597597

598598
private:
599-
void doInitDAG(unsigned _n)
600-
{
601-
h256 seedHash = EthashAux::seedHash(_n);
602-
cout << "Initializing DAG for epoch beginning #" << (_n / 30000 * 30000) << " (seedhash " << seedHash.abridged() << "). This will take a while." << endl;
603-
EthashAux::full(seedHash, true);
604-
exit(0);
605-
}
606-
607-
608599

609600
void doBenchmark(MinerType _m, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5)
610601
{
@@ -787,7 +778,6 @@ class MinerCLI
787778
f.start("cuda", false);
788779
EthashProofOfWork::WorkPackage current, previous;
789780
std::mutex x_current;
790-
EthashAux::FullType dag;
791781
while (m_running)
792782
try
793783
{

‎libdevcore/Common.h

-6
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,8 @@
4040
#include <boost/multiprecision/cpp_int.hpp>
4141
#include "vector_ref.h"
4242

43-
// CryptoPP defines byte in the global namespace, so must we.
4443
using byte = uint8_t;
4544

46-
#define DEV_IGNORE_EXCEPTIONS(X) try { X; } catch (...) {}
47-
48-
#define DEV_IF_NO_ELSE(X) if(!(X)){}else
49-
#define DEV_IF_THROWS(X) try{X;}catch(...)
50-
5145
namespace dev
5246
{
5347

‎libethash-cl/ethash_cl_miner.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <random>
3434
#include <atomic>
3535
#include <sstream>
36-
#include <libethash/util.h>
3736
#include <libethash/ethash.h>
3837
#include <libethash/internal.h>
3938
#include "ethash_cl_miner.h"

‎libethash/CMakeLists.txt

+10-16
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,16 @@ if (NOT MSVC)
22
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
33
endif()
44

5-
set(FILES util.h
6-
io.c
7-
internal.c
8-
ethash.h
9-
endian.h
10-
compiler.h
11-
fnv.h
12-
data_sizes.h)
13-
14-
if (MSVC)
15-
list(APPEND FILES util_win32.c io_win32.c mmap_win32.c)
16-
else()
17-
list(APPEND FILES io_posix.c)
18-
endif()
19-
20-
list(APPEND FILES sha3.c sha3.h)
5+
set(FILES
6+
internal.c
7+
ethash.h
8+
endian.h
9+
compiler.h
10+
fnv.h
11+
data_sizes.h
12+
sha3.c
13+
sha3.h
14+
)
2115

2216
add_library(ethash ${FILES})
2317

‎libethash/ethash.h

-56
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#define ETHASH_DATASET_PARENTS 256
3838
#define ETHASH_CACHE_ROUNDS 3
3939
#define ETHASH_ACCESSES 64
40-
#define ETHASH_DAG_MAGIC_NUM_SIZE 8
41-
#define ETHASH_DAG_MAGIC_NUM 0xFEE1DEADBADDCAFE
4240

4341
#ifdef __cplusplus
4442
extern "C" {
@@ -47,19 +45,8 @@ extern "C" {
4745
/// Type of a seedhash/blockhash e.t.c.
4846
typedef struct ethash_h256 { uint8_t b[32]; } ethash_h256_t;
4947

50-
// convenience macro to statically initialize an h256_t
51-
// usage:
52-
// ethash_h256_t a = ethash_h256_static_init(1, 2, 3, ... )
53-
// have to provide all 32 values. If you don't provide all the rest
54-
// will simply be unitialized (not guranteed to be 0)
55-
#define ethash_h256_static_init(...) \
56-
{ {__VA_ARGS__} }
57-
5848
struct ethash_light;
5949
typedef struct ethash_light* ethash_light_t;
60-
struct ethash_full;
61-
typedef struct ethash_full* ethash_full_t;
62-
typedef int(*ethash_callback_t)(unsigned);
6350

6451
typedef struct ethash_return_value {
6552
ethash_h256_t result;
@@ -94,49 +81,6 @@ ethash_return_value_t ethash_light_compute(
9481
uint64_t nonce
9582
);
9683

97-
/**
98-
* Allocate and initialize a new ethash_full handler
99-
*
100-
* @param light The light handler containing the cache.
101-
* @param callback A callback function with signature of @ref ethash_callback_t
102-
* It accepts an unsigned with which a progress of DAG calculation
103-
* can be displayed. If all goes well the callback should return 0.
104-
* If a non-zero value is returned then DAG generation will stop.
105-
* Be advised. A progress value of 100 means that DAG creation is
106-
* almost complete and that this function will soon return succesfully.
107-
* It does not mean that the function has already had a succesfull return.
108-
* @return Newly allocated ethash_full handler or NULL in case of
109-
* ERRNOMEM or invalid parameters used for @ref ethash_compute_full_data()
110-
*/
111-
ethash_full_t ethash_full_new(ethash_light_t light, const char * custom_dir_name, ethash_callback_t callback);
112-
113-
/**
114-
* Frees a previously allocated ethash_full handler
115-
* @param full The light handler to free
116-
*/
117-
void ethash_full_delete(ethash_full_t full);
118-
/**
119-
* Calculate the full client data
120-
*
121-
* @param full The full client handler
122-
* @param header_hash The header hash to pack into the mix
123-
* @param nonce The nonce to pack into the mix
124-
* @return An object of ethash_return_value to hold the return value
125-
*/
126-
ethash_return_value_t ethash_full_compute(
127-
ethash_full_t full,
128-
ethash_h256_t const header_hash,
129-
uint64_t nonce
130-
);
131-
/**
132-
* Get a pointer to the full DAG data
133-
*/
134-
void const* ethash_full_dag(ethash_full_t full);
135-
/**
136-
* Get the size of the DAG data
137-
*/
138-
uint64_t ethash_full_dag_size(ethash_full_t full);
139-
14084
/**
14185
* Calculate the seedhash for a given block number
14286
*/

‎libethash/internal.c

-219
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,12 @@
2323
#include <assert.h>
2424
#include <inttypes.h>
2525
#include <stddef.h>
26-
#include <errno.h>
27-
#include <math.h>
28-
#include "mmap.h"
2926
#include "ethash.h"
3027
#include "fnv.h"
3128
#include "endian.h"
3229
#include "internal.h"
3330
#include "data_sizes.h"
34-
#include "io.h"
35-
36-
#ifdef WITH_CRYPTOPP
37-
38-
#include "sha3_cryptopp.h"
39-
40-
#else
4131
#include "sha3.h"
42-
#endif // WITH_CRYPTOPP
4332

4433
uint64_t ethash_get_datasize(uint64_t const block_number)
4534
{
@@ -142,35 +131,6 @@ void ethash_calculate_dag_item(
142131
SHA3_512(ret->bytes, ret->bytes, sizeof(node));
143132
}
144133

145-
bool ethash_compute_full_data(
146-
void* mem,
147-
uint64_t full_size,
148-
ethash_light_t const light,
149-
ethash_callback_t callback
150-
)
151-
{
152-
if (full_size % (sizeof(uint32_t) * MIX_WORDS) != 0 ||
153-
(full_size % sizeof(node)) != 0) {
154-
return false;
155-
}
156-
uint32_t const max_n = (uint32_t)(full_size / sizeof(node));
157-
node* full_nodes = mem;
158-
double const progress_change = 1.0f / max_n;
159-
double progress = 0.0f;
160-
// now compute full nodes
161-
for (uint32_t n = 0; n != max_n; ++n) {
162-
if (callback &&
163-
n % (max_n / 100) == 0 &&
164-
callback((unsigned int)(ceil(progress * 100.0f))) != 0) {
165-
166-
return false;
167-
}
168-
progress += progress_change;
169-
ethash_calculate_dag_item(&(full_nodes[n]), n, light);
170-
}
171-
return true;
172-
}
173-
174134
static bool ethash_hash(
175135
ethash_return_value_t* ret,
176136
node const* full_nodes,
@@ -254,22 +214,6 @@ static bool ethash_hash(
254214
return true;
255215
}
256216

257-
void ethash_quick_hash(
258-
ethash_h256_t* return_hash,
259-
ethash_h256_t const* header_hash,
260-
uint64_t const nonce,
261-
ethash_h256_t const* mix_hash
262-
)
263-
{
264-
uint8_t buf[64 + 32];
265-
memcpy(buf, header_hash, 32);
266-
fix_endian64_same(nonce);
267-
memcpy(&(buf[32]), &nonce, 8);
268-
SHA3_512(buf, buf, 40);
269-
memcpy(&(buf[64]), mix_hash, 32);
270-
SHA3_256(return_hash, buf, 64 + 32);
271-
}
272-
273217
ethash_h256_t ethash_get_seedhash(uint64_t block_number)
274218
{
275219
ethash_h256_t ret;
@@ -280,19 +224,6 @@ ethash_h256_t ethash_get_seedhash(uint64_t block_number)
280224
return ret;
281225
}
282226

283-
bool ethash_quick_check_difficulty(
284-
ethash_h256_t const* header_hash,
285-
uint64_t const nonce,
286-
ethash_h256_t const* mix_hash,
287-
ethash_h256_t const* boundary
288-
)
289-
{
290-
291-
ethash_h256_t return_hash;
292-
ethash_quick_hash(&return_hash, header_hash, nonce, mix_hash);
293-
return ethash_check_difficulty(&return_hash, boundary);
294-
}
295-
296227
ethash_light_t ethash_light_new_internal(uint64_t cache_size, ethash_h256_t const* seed)
297228
{
298229
struct ethash_light *ret;
@@ -359,153 +290,3 @@ ethash_return_value_t ethash_light_compute(
359290
uint64_t full_size = ethash_get_datasize(light->block_number);
360291
return ethash_light_compute_internal(light, full_size, header_hash, nonce);
361292
}
362-
363-
static bool ethash_mmap(struct ethash_full* ret, FILE* f)
364-
{
365-
int fd;
366-
char* mmapped_data;
367-
errno = 0;
368-
ret->file = f;
369-
if ((fd = ethash_fileno(ret->file)) == -1) {
370-
return false;
371-
}
372-
mmapped_data = mmap(
373-
NULL,
374-
(size_t)ret->file_size + ETHASH_DAG_MAGIC_NUM_SIZE,
375-
PROT_READ | PROT_WRITE,
376-
MAP_SHARED,
377-
fd,
378-
0
379-
);
380-
if (mmapped_data == MAP_FAILED) {
381-
return false;
382-
}
383-
ret->data = (node*)(mmapped_data + ETHASH_DAG_MAGIC_NUM_SIZE);
384-
return true;
385-
}
386-
387-
ethash_full_t ethash_full_new_internal(
388-
char const* dirname,
389-
ethash_h256_t const seed_hash,
390-
uint64_t full_size,
391-
ethash_light_t const light,
392-
ethash_callback_t callback
393-
)
394-
{
395-
struct ethash_full* ret;
396-
FILE *f = NULL;
397-
ret = calloc(sizeof(*ret), 1);
398-
if (!ret) {
399-
return NULL;
400-
}
401-
ret->file_size = (size_t)full_size;
402-
switch (ethash_io_prepare(dirname, seed_hash, &f, (size_t)full_size, false)) {
403-
case ETHASH_IO_FAIL:
404-
// ethash_io_prepare will do all ETHASH_CRITICAL() logging in fail case
405-
goto fail_free_full;
406-
case ETHASH_IO_MEMO_MATCH:
407-
if (!ethash_mmap(ret, f)) {
408-
ETHASH_CRITICAL("mmap failure()");
409-
goto fail_close_file;
410-
}
411-
return ret;
412-
case ETHASH_IO_MEMO_SIZE_MISMATCH:
413-
// if a DAG of same filename but unexpected size is found, silently force new file creation
414-
if (ethash_io_prepare(dirname, seed_hash, &f, (size_t)full_size, true) != ETHASH_IO_MEMO_MISMATCH) {
415-
ETHASH_CRITICAL("Could not recreate DAG file after finding existing DAG with unexpected size.");
416-
goto fail_free_full;
417-
}
418-
// fallthrough to the mismatch case here, DO NOT go through match
419-
case ETHASH_IO_MEMO_MISMATCH:
420-
if (!ethash_mmap(ret, f)) {
421-
ETHASH_CRITICAL("mmap failure()");
422-
goto fail_close_file;
423-
}
424-
break;
425-
}
426-
427-
if (!ethash_compute_full_data(ret->data, full_size, light, callback)) {
428-
ETHASH_CRITICAL("Failure at computing DAG data.");
429-
goto fail_free_full_data;
430-
}
431-
432-
// after the DAG has been filled then we finalize it by writting the magic number at the beginning
433-
if (fseek(f, 0, SEEK_SET) != 0) {
434-
ETHASH_CRITICAL("Could not seek to DAG file start to write magic number.");
435-
goto fail_free_full_data;
436-
}
437-
uint64_t const magic_num = ETHASH_DAG_MAGIC_NUM;
438-
if (fwrite(&magic_num, ETHASH_DAG_MAGIC_NUM_SIZE, 1, f) != 1) {
439-
ETHASH_CRITICAL("Could not write magic number to DAG's beginning.");
440-
goto fail_free_full_data;
441-
}
442-
if (fflush(f) != 0) {// make sure the magic number IS there
443-
ETHASH_CRITICAL("Could not flush memory mapped data to DAG file. Insufficient space?");
444-
goto fail_free_full_data;
445-
}
446-
return ret;
447-
448-
fail_free_full_data:
449-
// could check that munmap(..) == 0 but even if it did not can't really do anything here
450-
munmap(ret->data, (size_t)full_size);
451-
fail_close_file:
452-
fclose(ret->file);
453-
fail_free_full:
454-
free(ret);
455-
return NULL;
456-
}
457-
458-
ethash_full_t ethash_full_new(ethash_light_t light, const char * custom_dir_name, ethash_callback_t callback)
459-
{
460-
char strbuf[256];
461-
462-
if (strcmp(custom_dir_name, "") != 0)
463-
strcpy(strbuf, custom_dir_name);
464-
else
465-
if (!ethash_get_default_dirname(strbuf, 256)) {
466-
return NULL;
467-
}
468-
uint64_t full_size = ethash_get_datasize(light->block_number);
469-
ethash_h256_t seedhash = ethash_get_seedhash(light->block_number);
470-
return ethash_full_new_internal(strbuf, seedhash, full_size, light, callback);
471-
}
472-
473-
void ethash_full_delete(ethash_full_t full)
474-
{
475-
// could check that munmap(..) == 0 but even if it did not can't really do anything here
476-
munmap(full->data, (size_t)full->file_size);
477-
if (full->file) {
478-
fclose(full->file);
479-
}
480-
free(full);
481-
}
482-
483-
ethash_return_value_t ethash_full_compute(
484-
ethash_full_t full,
485-
ethash_h256_t const header_hash,
486-
uint64_t nonce
487-
)
488-
{
489-
ethash_return_value_t ret;
490-
ret.success = true;
491-
if (!ethash_hash(
492-
&ret,
493-
(node const*)full->data,
494-
NULL,
495-
full->file_size,
496-
header_hash,
497-
nonce)) {
498-
ret.success = false;
499-
}
500-
return ret;
501-
}
502-
503-
void const* ethash_full_dag(ethash_full_t full)
504-
{
505-
return full->data;
506-
}
507-
508-
uint64_t ethash_full_dag_size(ethash_full_t full)
509-
{
510-
return full->file_size;
511-
}

‎libethash/internal.h

-96
Original file line numberDiff line numberDiff line change
@@ -31,53 +31,11 @@ typedef union node {
3131

3232
} node;
3333

34-
static inline uint8_t ethash_h256_get(ethash_h256_t const* hash, unsigned int i)
35-
{
36-
return hash->b[i];
37-
}
38-
39-
static inline void ethash_h256_set(ethash_h256_t* hash, unsigned int i, uint8_t v)
40-
{
41-
hash->b[i] = v;
42-
}
43-
4434
static inline void ethash_h256_reset(ethash_h256_t* hash)
4535
{
4636
memset(hash, 0, 32);
4737
}
4838

49-
// Returns if hash is less than or equal to boundary (2^256/difficulty)
50-
static inline bool ethash_check_difficulty(
51-
ethash_h256_t const* hash,
52-
ethash_h256_t const* boundary
53-
)
54-
{
55-
// Boundary is big endian
56-
for (int i = 0; i < 32; i++) {
57-
if (ethash_h256_get(hash, i) == ethash_h256_get(boundary, i)) {
58-
continue;
59-
}
60-
return ethash_h256_get(hash, i) < ethash_h256_get(boundary, i);
61-
}
62-
return true;
63-
}
64-
65-
/**
66-
* Difficulty quick check for POW preverification
67-
*
68-
* @param header_hash The hash of the header
69-
* @param nonce The block's nonce
70-
* @param mix_hash The mix digest hash
71-
* @param boundary The boundary is defined as (2^256 / difficulty)
72-
* @return true for succesful pre-verification and false otherwise
73-
*/
74-
bool ethash_quick_check_difficulty(
75-
ethash_h256_t const* header_hash,
76-
uint64_t const nonce,
77-
ethash_h256_t const* mix_hash,
78-
ethash_h256_t const* boundary
79-
);
80-
8139
struct ethash_light {
8240
void* cache;
8341
uint64_t cache_size;
@@ -111,69 +69,15 @@ ethash_return_value_t ethash_light_compute_internal(
11169
uint64_t nonce
11270
);
11371

114-
struct ethash_full {
115-
FILE* file;
116-
uint64_t file_size;
117-
node* data;
118-
};
119-
120-
/**
121-
* Allocate and initialize a new ethash_full handler. Internal version.
122-
*
123-
* @param dirname The directory in which to put the DAG file.
124-
* @param seedhash The seed hash of the block. Used in the DAG file naming.
125-
* @param full_size The size of the full data in bytes.
126-
* @param cache A cache object to use that was allocated with @ref ethash_cache_new().
127-
* Iff this function succeeds the ethash_full_t will take memory
128-
* memory ownership of the cache and free it at deletion. If
129-
* not then the user still has to handle freeing of the cache himself.
130-
* @param callback A callback function with signature of @ref ethash_callback_t
131-
* It accepts an unsigned with which a progress of DAG calculation
132-
* can be displayed. If all goes well the callback should return 0.
133-
* If a non-zero value is returned then DAG generation will stop.
134-
* @return Newly allocated ethash_full handler or NULL in case of
135-
* ERRNOMEM or invalid parameters used for @ref ethash_compute_full_data()
136-
*/
137-
ethash_full_t ethash_full_new_internal(
138-
char const* dirname,
139-
ethash_h256_t const seed_hash,
140-
uint64_t full_size,
141-
ethash_light_t const light,
142-
ethash_callback_t callback
143-
);
144-
14572
void ethash_calculate_dag_item(
14673
node* const ret,
14774
uint32_t node_index,
14875
ethash_light_t const cache
14976
);
15077

151-
void ethash_quick_hash(
152-
ethash_h256_t* return_hash,
153-
ethash_h256_t const* header_hash,
154-
const uint64_t nonce,
155-
ethash_h256_t const* mix_hash
156-
);
157-
15878
uint64_t ethash_get_datasize(uint64_t const block_number);
15979
uint64_t ethash_get_cachesize(uint64_t const block_number);
16080

161-
/**
162-
* Compute the memory data for a full node's memory
163-
*
164-
* @param mem A pointer to an ethash full's memory
165-
* @param full_size The size of the full data in bytes
166-
* @param cache A cache object to use in the calculation
167-
* @param callback The callback function. Check @ref ethash_full_new() for details.
168-
* @return true if all went fine and false for invalid parameters
169-
*/
170-
bool ethash_compute_full_data(
171-
void* mem,
172-
uint64_t full_size,
173-
ethash_light_t const light,
174-
ethash_callback_t callback
175-
);
176-
17781
#ifdef __cplusplus
17882
}
17983
#endif

‎libethash/io.c

-119
This file was deleted.

‎libethash/io.h

-202
This file was deleted.

‎libethash/io_posix.c

-111
This file was deleted.

‎libethash/io_win32.c

-100
This file was deleted.

‎libethash/mmap.h

-47
This file was deleted.

‎libethash/mmap_win32.c

-84
This file was deleted.

‎libethash/sha3_cryptopp.cpp

-37
This file was deleted.

‎libethash/sha3_cryptopp.h

-18
This file was deleted.

‎libethash/util.c

-41
This file was deleted.

‎libethash/util.h

-47
This file was deleted.

‎libethash/util_win32.c

-38
This file was deleted.

‎libethcore/EthashAux.cpp

+9-132
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,13 @@
2020
*/
2121

2222
#include "EthashAux.h"
23-
24-
#include <boost/detail/endian.hpp>
25-
#include <chrono>
26-
#include <array>
27-
#include <thread>
28-
#include <libdevcore/Common.h>
29-
#include <libdevcore/Guards.h>
30-
#include <libdevcore/Log.h>
31-
#include <libdevcore/SHA3.h>
3223
#include <libethash/internal.h>
33-
#include <libethash/io.h>
34-
#include "BlockInfo.h"
35-
#include "Exceptions.h"
3624

3725
using namespace std;
3826
using namespace chrono;
3927
using namespace dev;
4028
using namespace eth;
4129

42-
const char* DAGChannel::name() { return EthGreen "DAG"; }
43-
44-
EthashAux* dev::eth::EthashAux::s_this = nullptr;
45-
char dev::eth::EthashAux::s_dagDirName[256] = "";
46-
47-
const unsigned EthashProofOfWork::defaultLocalWorkSize = 64;
48-
const unsigned EthashProofOfWork::defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE
49-
const unsigned EthashProofOfWork::defaultMSPerBatch = 0;
50-
const EthashProofOfWork::WorkPackage EthashProofOfWork::NullWorkPackage = EthashProofOfWork::WorkPackage();
51-
5230
h256 const& BlockHeaderRaw::seedHash() const
5331
{
5432
if (!m_seedHash)
@@ -58,14 +36,8 @@ h256 const& BlockHeaderRaw::seedHash() const
5836

5937
EthashAux* EthashAux::get()
6038
{
61-
static std::once_flag flag;
62-
std::call_once(flag, []{s_this = new EthashAux();});
63-
return s_this;
64-
}
65-
66-
char * EthashAux::dagDirName()
67-
{
68-
return s_dagDirName;
39+
static EthashAux instance;
40+
return &instance;
6941
}
7042

7143
h256 EthashAux::seedHash(unsigned _number)
@@ -82,12 +54,8 @@ h256 EthashAux::seedHash(unsigned _number)
8254
n = get()->m_seedHashes.size() - 1;
8355
}
8456
get()->m_seedHashes.resize(epoch + 1);
85-
// cdebug << "Searching for seedHash of epoch " << epoch;
8657
for (; n <= epoch; ++n, ret = sha3(ret))
87-
{
8858
get()->m_seedHashes[n] = ret;
89-
// cdebug << "Epoch" << n << "is" << ret;
90-
}
9159
}
9260
return get()->m_seedHashes[epoch];
9361
}
@@ -99,7 +67,6 @@ uint64_t EthashAux::number(h256 const& _seedHash)
9967
auto epochIter = get()->m_epochs.find(_seedHash);
10068
if (epochIter == get()->m_epochs.end())
10169
{
102-
// cdebug << "Searching for seedHash " << _seedHash;
10370
for (h256 h; h != _seedHash && epoch < 2048; ++epoch, h = sha3(h), get()->m_epochs[h] = epoch) {}
10471
if (epoch == 2048)
10572
{
@@ -140,97 +107,6 @@ bytesConstRef EthashAux::LightAllocation::data() const
140107
return bytesConstRef((byte const*)light->cache, size);
141108
}
142109

143-
EthashAux::FullAllocation::FullAllocation(ethash_light_t _light, ethash_callback_t _cb)
144-
{
145-
// cdebug << "About to call ethash_full_new...";
146-
full = ethash_full_new(_light, EthashAux::dagDirName(), _cb);
147-
// cdebug << "Called OK.";
148-
if (!full)
149-
{
150-
clog(DAGChannel) << "DAG Generation Failure. Reason: " << strerror(errno);
151-
BOOST_THROW_EXCEPTION(ExternalFunctionFailure("ethash_full_new"));
152-
}
153-
}
154-
155-
EthashAux::FullAllocation::~FullAllocation()
156-
{
157-
ethash_full_delete(full);
158-
}
159-
160-
bytesConstRef EthashAux::FullAllocation::data() const
161-
{
162-
return bytesConstRef((byte const*)ethash_full_dag(full), size());
163-
}
164-
165-
static std::function<int(unsigned)> s_dagCallback;
166-
static int dagCallbackShim(unsigned _p)
167-
{
168-
clog(DAGChannel) << "Generating DAG file. Progress: " << toString(_p) << "%";
169-
return s_dagCallback ? s_dagCallback(_p) : 0;
170-
}
171-
172-
EthashAux::FullType EthashAux::full(h256 const& _seedHash, bool _createIfMissing, function<int(unsigned)> const& _f)
173-
{
174-
FullType ret;
175-
auto l = light(_seedHash);
176-
177-
DEV_GUARDED(get()->x_fulls)
178-
if ((ret = get()->m_fulls[_seedHash].lock()))
179-
return ret;
180-
181-
if (_createIfMissing || computeFull(_seedHash, false) == 100)
182-
{
183-
s_dagCallback = _f;
184-
ret = make_shared<FullAllocation>(l->light, dagCallbackShim);
185-
186-
DEV_GUARDED(get()->x_fulls)
187-
get()->m_fulls[_seedHash] = ret;
188-
}
189-
190-
return ret;
191-
}
192-
193-
unsigned EthashAux::computeFull(h256 const& _seedHash, bool _createIfMissing)
194-
{
195-
Guard l(get()->x_fulls);
196-
uint64_t blockNumber;
197-
198-
DEV_IF_THROWS(blockNumber = EthashAux::number(_seedHash))
199-
{
200-
return 0;
201-
}
202-
203-
if (FullType ret = get()->m_fulls[_seedHash].lock())
204-
{
205-
return 100;
206-
}
207-
208-
if (_createIfMissing && (!get()->m_fullGenerator || !get()->m_fullGenerator->joinable()))
209-
{
210-
get()->m_fullProgress = 0;
211-
get()->m_generatingFullNumber = blockNumber / ETHASH_EPOCH_LENGTH * ETHASH_EPOCH_LENGTH;
212-
get()->m_fullGenerator = unique_ptr<thread>(new thread([=](){
213-
cnote << "Loading full DAG of seedhash: " << _seedHash;
214-
get()->full(_seedHash, true, [](unsigned p){ get()->m_fullProgress = p; return 0; });
215-
cnote << "Full DAG loaded";
216-
get()->m_fullProgress = 0;
217-
get()->m_generatingFullNumber = NotGenerating;
218-
}));
219-
}
220-
221-
return (get()->m_generatingFullNumber == blockNumber) ? get()->m_fullProgress : 0;
222-
}
223-
224-
225-
226-
EthashProofOfWork::Result EthashAux::FullAllocation::compute(h256 const& _headerHash, Nonce const& _nonce) const
227-
{
228-
ethash_return_value_t r = ethash_full_compute(full, *(ethash_h256_t*)_headerHash.data(), (uint64_t)(u64)_nonce);
229-
if (!r.success)
230-
BOOST_THROW_EXCEPTION(DAGCreationFailure());
231-
return EthashProofOfWork::Result{h256((uint8_t*)&r.result, h256::ConstructFromPointer), h256((uint8_t*)&r.mix_hash, h256::ConstructFromPointer)};
232-
}
233-
234110
EthashProofOfWork::Result EthashAux::LightAllocation::compute(h256 const& _headerHash, Nonce const& _nonce) const
235111
{
236112
ethash_return_value r = ethash_light_compute(light, *(ethash_h256_t*)_headerHash.data(), (uint64_t)(u64)_nonce);
@@ -239,13 +115,14 @@ EthashProofOfWork::Result EthashAux::LightAllocation::compute(h256 const& _heade
239115
return EthashProofOfWork::Result{h256((uint8_t*)&r.result, h256::ConstructFromPointer), h256((uint8_t*)&r.mix_hash, h256::ConstructFromPointer)};
240116
}
241117

242-
EthashProofOfWork::Result EthashAux::eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce)
118+
EthashProofOfWork::Result EthashAux::eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce) noexcept
243119
{
244-
DEV_GUARDED(get()->x_fulls)
245-
if (FullType dag = get()->m_fulls[_seedHash].lock())
246-
return dag->compute(_headerHash, _nonce);
247-
DEV_IF_THROWS(return EthashAux::get()->light(_seedHash)->compute(_headerHash, _nonce))
120+
try
121+
{
122+
return EthashAux::get()->light(_seedHash)->compute(_headerHash, _nonce);
123+
}
124+
catch(...)
248125
{
249-
return EthashProofOfWork::Result{ ~h256(), h256() };
126+
return EthashProofOfWork::Result{~h256(), h256()};
250127
}
251128
}

‎libethcore/EthashAux.h

+3-54
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ namespace dev
3232
namespace eth
3333
{
3434

35-
struct DAGChannel: public LogChannel { static const char* name(); static const int verbosity = 1; };
36-
3735
/// Proof of work definition for Ethash.
3836
struct EthashProofOfWork
3937
{
@@ -67,24 +65,6 @@ struct EthashProofOfWork
6765
uint64_t startNonce = 0;
6866
int exSizeBits = -1;
6967
};
70-
71-
static const WorkPackage NullWorkPackage;
72-
73-
/// Default value of the local work size. Also known as workgroup size.
74-
static const unsigned defaultLocalWorkSize;
75-
/// Default value of the global work size as a multiplier of the local work size
76-
static const unsigned defaultGlobalWorkSizeMultiplier;
77-
/// Default value of the milliseconds per global work size (per batch)
78-
static const unsigned defaultMSPerBatch;
79-
80-
};
81-
82-
enum class DAGEraseMode
83-
{
84-
None,
85-
Old,
86-
Bench,
87-
All
8868
};
8969

9070
class EthashAux
@@ -102,51 +82,20 @@ class EthashAux
10282
uint64_t size;
10383
};
10484

105-
struct FullAllocation
106-
{
107-
FullAllocation(ethash_light_t _light, ethash_callback_t _cb);
108-
~FullAllocation();
109-
EthashProofOfWork::Result compute(h256 const& _headerHash, Nonce const& _nonce) const;
110-
bytesConstRef data() const;
111-
uint64_t size() const { return ethash_full_dag_size(full); }
112-
ethash_full_t full;
113-
};
114-
11585
using LightType = std::shared_ptr<LightAllocation>;
116-
using FullType = std::shared_ptr<FullAllocation>;
11786

11887
static h256 seedHash(unsigned _number);
11988
static uint64_t number(h256 const& _seedHash);
120-
static char * dagDirName();
12189

12290
static LightType light(h256 const& _seedHash);
12391

124-
static const uint64_t NotGenerating = (uint64_t)-1;
125-
/// Kicks off generation of DAG for @a _seedHash and @returns false or @returns true if ready.
126-
static unsigned computeFull(h256 const& _seedHash, bool _createIfMissing = true);
127-
/// Information on the generation progress.
128-
static std::pair<uint64_t, unsigned> fullGeneratingProgress() { return std::make_pair(get()->m_generatingFullNumber, get()->m_fullProgress); }
129-
/// Kicks off generation of DAG for @a _blocknumber and blocks until ready; @returns result or empty pointer if not existing and _createIfMissing is false.
130-
static FullType full(h256 const& _seedHash, bool _createIfMissing = false, std::function<int(unsigned)> const& _f = std::function<int(unsigned)>());
131-
132-
133-
134-
static EthashProofOfWork::Result eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce);
92+
static EthashProofOfWork::Result eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce) noexcept;
13593

13694
private:
137-
EthashAux() {}
138-
139-
static EthashAux* s_this;
140-
static char s_dagDirName[256];
95+
EthashAux() = default;
14196

14297
Mutex x_lights;
143-
std::unordered_map<h256, std::shared_ptr<LightAllocation>> m_lights;
144-
145-
Mutex x_fulls;
146-
std::unordered_map<h256, std::weak_ptr<FullAllocation>> m_fulls;
147-
std::unique_ptr<std::thread> m_fullGenerator;
148-
uint64_t m_generatingFullNumber = NotGenerating;
149-
unsigned m_fullProgress;
98+
std::unordered_map<h256, LightType> m_lights;
15099

151100
Mutex x_epochs;
152101
std::unordered_map<h256, unsigned> m_epochs;

‎libstratum/EthStratumClientV2.h

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class EthStratumClientV2 : public Worker
7373

7474
string m_job;
7575
string m_previousJob;
76-
EthashAux::FullType m_dag;
7776

7877
boost::asio::io_service m_io_service;
7978
tcp::socket m_socket;

0 commit comments

Comments
 (0)
This repository has been archived.