Paweł Bylica
8 years ago
57 changed files with 419 additions and 4605 deletions
@ -0,0 +1,18 @@ |
|||
[bumpversion] |
|||
current_version = 0.11.0.dev0 |
|||
commit = True |
|||
tag = True |
|||
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<prerel>rc|\.dev)(?P<prerelver>\d+))? |
|||
serialize = |
|||
{major}.{minor}.{patch}{prerel}{prerelver} |
|||
{major}.{minor}.{patch} |
|||
|
|||
[bumpversion:part:prerel] |
|||
optional_value = rel |
|||
values = |
|||
.dev |
|||
rc |
|||
rel |
|||
|
|||
[bumpversion:file:CMakeLists.txt] |
|||
|
@ -1 +1 @@ |
|||
hunter_config(CURL VERSION ${HUNTER_CURL_VERSION} CMAKE_ARGS HTTP_ONLY=ON) |
|||
hunter_config(CURL VERSION ${HUNTER_CURL_VERSION} CMAKE_ARGS HTTP_ONLY=ON CMAKE_USE_OPENSSL=OFF CMAKE_USE_LIBSSH2=OFF) |
@ -0,0 +1,2 @@ |
|||
$env:ethminer_version="@PROJECT_VERSION@" |
|||
$env:ethminer_version_is_prerelease="@PROJECT_VERSION_IS_PRERELEASE@" |
@ -0,0 +1,2 @@ |
|||
ETHMINER_VERSION='@PROJECT_VERSION@' |
|||
ETHMINER_VERSION_IS_PRERELEASE='@PROJECT_VERSION_IS_PRERELEASE@' |
File diff suppressed because it is too large
@ -1,39 +0,0 @@ |
|||
REM get stuff! |
|||
if not exist download mkdir download |
|||
if not exist install mkdir install |
|||
if not exist install\windows mkdir install\windows |
|||
|
|||
set eth_server=https://build.ethdev.com/builds/windows-precompiled |
|||
|
|||
call :download boost 1.55.0 |
|||
call :download cryptopp 5.6.2 |
|||
call :download curl 7.4.2 |
|||
call :download jsoncpp 1.6.2 |
|||
call :download json-rpc-cpp 0.5.0 |
|||
call :download leveldb 1.2 |
|||
call :download microhttpd 0.9.2 |
|||
call :download OpenCL_ICD 1 |
|||
|
|||
goto :EOF |
|||
|
|||
:download |
|||
|
|||
set eth_name=%1 |
|||
set eth_version=%2 |
|||
|
|||
cd download |
|||
|
|||
if not exist %eth_name%-%eth_version%-x64.tar.gz ( |
|||
for /f "tokens=2 delims={}" %%g in ('bitsadmin /create %eth_name%-%eth_version%-x64.tar.gz') do ( |
|||
bitsadmin /transfer {%%g} /download /priority normal %eth_server%/%eth_name%-%eth_version%-x64.tar.gz %cd%\%eth_name%-%eth_version%-x64.tar.gz |
|||
bitsadmin /cancel {%%g} |
|||
) |
|||
) |
|||
if not exist %eth_name%-%eth_version% cmake -E tar -zxvf %eth_name%-%eth_version%-x64.tar.gz |
|||
cmake -E copy_directory %eth_name%-%eth_version% ..\install\windows |
|||
|
|||
cd .. |
|||
|
|||
goto :EOF |
|||
|
|||
|
@ -1,119 +0,0 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file io.c
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
#include "io.h" |
|||
#include <string.h> |
|||
#include <stdio.h> |
|||
#include <errno.h> |
|||
|
|||
enum ethash_io_rc ethash_io_prepare( |
|||
char const* dirname, |
|||
ethash_h256_t const seedhash, |
|||
FILE** output_file, |
|||
uint64_t file_size, |
|||
bool force_create |
|||
) |
|||
{ |
|||
char mutable_name[DAG_MUTABLE_NAME_MAX_SIZE]; |
|||
enum ethash_io_rc ret = ETHASH_IO_FAIL; |
|||
// reset errno before io calls
|
|||
errno = 0; |
|||
|
|||
// assert directory exists
|
|||
if (!ethash_mkdir(dirname)) { |
|||
ETHASH_CRITICAL("Could not create the ethash directory"); |
|||
goto end; |
|||
} |
|||
|
|||
ethash_io_mutable_name(ETHASH_REVISION, &seedhash, mutable_name); |
|||
char* tmpfile = ethash_io_create_filename(dirname, mutable_name, strlen(mutable_name)); |
|||
if (!tmpfile) { |
|||
ETHASH_CRITICAL("Could not create the full DAG pathname"); |
|||
goto end; |
|||
} |
|||
|
|||
FILE *f; |
|||
if (!force_create) { |
|||
// try to open the file
|
|||
f = ethash_fopen(tmpfile, "rb+"); |
|||
if (f) { |
|||
size_t found_size; |
|||
if (!ethash_file_size(f, &found_size)) { |
|||
fclose(f); |
|||
ETHASH_CRITICAL("Could not query size of DAG file: \"%s\"", tmpfile); |
|||
goto free_memo; |
|||
} |
|||
if (file_size != found_size - ETHASH_DAG_MAGIC_NUM_SIZE) { |
|||
fclose(f); |
|||
ret = ETHASH_IO_MEMO_SIZE_MISMATCH; |
|||
goto free_memo; |
|||
} |
|||
// compare the magic number, no need to care about endianess since it's local
|
|||
uint64_t magic_num; |
|||
if (fread(&magic_num, ETHASH_DAG_MAGIC_NUM_SIZE, 1, f) != 1) { |
|||
// I/O error
|
|||
fclose(f); |
|||
ETHASH_CRITICAL("Could not read from DAG file: \"%s\"", tmpfile); |
|||
ret = ETHASH_IO_MEMO_SIZE_MISMATCH; |
|||
goto free_memo; |
|||
} |
|||
if (magic_num != ETHASH_DAG_MAGIC_NUM) { |
|||
fclose(f); |
|||
ret = ETHASH_IO_MEMO_SIZE_MISMATCH; |
|||
goto free_memo; |
|||
} |
|||
ret = ETHASH_IO_MEMO_MATCH; |
|||
goto set_file; |
|||
} |
|||
} |
|||
|
|||
// file does not exist, will need to be created
|
|||
f = ethash_fopen(tmpfile, "wb+"); |
|||
if (!f) { |
|||
ETHASH_CRITICAL("Could not create DAG file: \"%s\"", tmpfile); |
|||
goto free_memo; |
|||
} |
|||
// make sure it's of the proper size
|
|||
if (fseek(f, (long int)(file_size + ETHASH_DAG_MAGIC_NUM_SIZE - 1), SEEK_SET) != 0) { |
|||
fclose(f); |
|||
ETHASH_CRITICAL("Could not seek to the end of DAG file: \"%s\". Insufficient space?", tmpfile); |
|||
goto free_memo; |
|||
} |
|||
if (fputc('\n', f) == EOF) { |
|||
fclose(f); |
|||
ETHASH_CRITICAL("Could not write in the end of DAG file: \"%s\". Insufficient space?", tmpfile); |
|||
goto free_memo; |
|||
} |
|||
if (fflush(f) != 0) { |
|||
fclose(f); |
|||
ETHASH_CRITICAL("Could not flush at end of DAG file: \"%s\". Insufficient space?", tmpfile); |
|||
goto free_memo; |
|||
} |
|||
ret = ETHASH_IO_MEMO_MISMATCH; |
|||
goto set_file; |
|||
|
|||
ret = ETHASH_IO_MEMO_MATCH; |
|||
set_file: |
|||
*output_file = f; |
|||
free_memo: |
|||
free(tmpfile); |
|||
end: |
|||
return ret; |
|||
} |
@ -1,202 +0,0 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file io.h
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
#pragma once |
|||
#include <stdlib.h> |
|||
#include <stdint.h> |
|||
#include <stdbool.h> |
|||
#include <stdio.h> |
|||
#ifdef __cplusplus |
|||
#define __STDC_FORMAT_MACROS 1 |
|||
#endif |
|||
#include <inttypes.h> |
|||
#include "endian.h" |
|||
#include "ethash.h" |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
// Maximum size for mutable part of DAG file name
|
|||
// 6 is for "full-R", the suffix of the filename
|
|||
// 10 is for maximum number of digits of a uint32_t (for REVISION)
|
|||
// 1 is for - and 16 is for the first 16 hex digits for first 8 bytes of
|
|||
// the seedhash and last 1 is for the null terminating character
|
|||
// Reference: https://github.com/ethereum/wiki/wiki/Ethash-DAG
|
|||
#define DAG_MUTABLE_NAME_MAX_SIZE (6 + 10 + 1 + 16 + 1) |
|||
/// Possible return values of @see ethash_io_prepare
|
|||
enum ethash_io_rc { |
|||
ETHASH_IO_FAIL = 0, ///< There has been an IO failure
|
|||
ETHASH_IO_MEMO_SIZE_MISMATCH, ///< DAG with revision/hash match, but file size was wrong.
|
|||
ETHASH_IO_MEMO_MISMATCH, ///< The DAG file did not exist or there was revision/hash mismatch
|
|||
ETHASH_IO_MEMO_MATCH, ///< DAG file existed and revision/hash matched. No need to do anything
|
|||
}; |
|||
|
|||
// small hack for windows. I don't feel I should use va_args and forward just
|
|||
// to have this one function properly cross-platform abstracted
|
|||
#if defined(_WIN32) && !defined(__GNUC__) |
|||
#define snprintf(...) sprintf_s(__VA_ARGS__) |
|||
#endif |
|||
|
|||
/**
|
|||
* Logs a critical error in important parts of ethash. Should mostly help |
|||
* figure out what kind of problem (I/O, memory e.t.c.) causes a NULL |
|||
* ethash_full_t |
|||
*/ |
|||
#ifdef ETHASH_PRINT_CRITICAL_OUTPUT |
|||
#define ETHASH_CRITICAL(...) \ |
|||
do \ |
|||
{ \ |
|||
printf("ETHASH CRITICAL ERROR: "__VA_ARGS__); \ |
|||
printf("\n"); \ |
|||
fflush(stdout); \ |
|||
} while (0) |
|||
#else |
|||
#define ETHASH_CRITICAL(...) |
|||
#endif |
|||
|
|||
/**
|
|||
* Prepares io for ethash |
|||
* |
|||
* Create the DAG directory and the DAG file if they don't exist. |
|||
* |
|||
* @param[in] dirname A null terminated c-string of the path of the ethash |
|||
* data directory. If it does not exist it's created. |
|||
* @param[in] seedhash The seedhash of the current block number, used in the |
|||
* naming of the file as can be seen from the spec at: |
|||
* https://github.com/ethereum/wiki/wiki/Ethash-DAG
|
|||
* @param[out] output_file If there was no failure then this will point to an open |
|||
* file descriptor. User is responsible for closing it. |
|||
* In the case of memo match then the file is open on read |
|||
* mode, while on the case of mismatch a new file is created |
|||
* on write mode |
|||
* @param[in] file_size The size that the DAG file should have on disk |
|||
* @param[out] force_create If true then there is no check to see if the file |
|||
* already exists |
|||
* @return For possible return values @see enum ethash_io_rc |
|||
*/ |
|||
enum ethash_io_rc ethash_io_prepare( |
|||
char const* dirname, |
|||
ethash_h256_t const seedhash, |
|||
FILE** output_file, |
|||
uint64_t file_size, |
|||
bool force_create |
|||
); |
|||
|
|||
/**
|
|||
* An fopen wrapper for no-warnings crossplatform fopen. |
|||
* |
|||
* Msvc compiler considers fopen to be insecure and suggests to use their |
|||
* alternative. This is a wrapper for this alternative. Another way is to |
|||
* #define _CRT_SECURE_NO_WARNINGS, but disabling all security warnings does |
|||
* not sound like a good idea. |
|||
* |
|||
* @param file_name The path to the file to open |
|||
* @param mode Opening mode. Check fopen() |
|||
* @return The FILE* or NULL in failure |
|||
*/ |
|||
FILE* ethash_fopen(char const* file_name, char const* mode); |
|||
|
|||
/**
|
|||
* An strncat wrapper for no-warnings crossplatform strncat. |
|||
* |
|||
* Msvc compiler considers strncat to be insecure and suggests to use their |
|||
* alternative. This is a wrapper for this alternative. Another way is to |
|||
* #define _CRT_SECURE_NO_WARNINGS, but disabling all security warnings does |
|||
* not sound like a good idea. |
|||
* |
|||
* @param des Destination buffer |
|||
* @param dest_size Maximum size of the destination buffer. This is the |
|||
* extra argument for the MSVC secure strncat |
|||
* @param src Souce buffer |
|||
* @param count Number of bytes to copy from source |
|||
* @return If all is well returns the dest buffer. If there is an |
|||
* error returns NULL |
|||
*/ |
|||
char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count); |
|||
|
|||
/**
|
|||
* A cross-platform mkdir wrapper to create a directory or assert it's there |
|||
* |
|||
* @param dirname The full path of the directory to create |
|||
* @return true if the directory was created or if it already |
|||
* existed |
|||
*/ |
|||
bool ethash_mkdir(char const* dirname); |
|||
|
|||
/**
|
|||
* Get a file's size |
|||
* |
|||
* @param[in] f The open file stream whose size to get |
|||
* @param[out] size Pass a size_t by reference to contain the file size |
|||
* @return true in success and false if there was a failure |
|||
*/ |
|||
bool ethash_file_size(FILE* f, size_t* ret_size); |
|||
|
|||
/**
|
|||
* Get a file descriptor number from a FILE stream |
|||
* |
|||
* @param f The file stream whose fd to get |
|||
* @return Platform specific fd handler |
|||
*/ |
|||
int ethash_fileno(FILE* f); |
|||
|
|||
/**
|
|||
* Create the filename for the DAG. |
|||
* |
|||
* @param dirname The directory name in which the DAG file should reside |
|||
* If it does not end with a directory separator it is appended. |
|||
* @param filename The actual name of the file |
|||
* @param filename_length The length of the filename in bytes |
|||
* @return A char* containing the full name. User must deallocate. |
|||
*/ |
|||
char* ethash_io_create_filename( |
|||
char const* dirname, |
|||
char const* filename, |
|||
size_t filename_length |
|||
); |
|||
|
|||
/**
|
|||
* Gets the default directory name for the DAG depending on the system |
|||
* |
|||
* The spec defining this directory is here: https://github.com/ethereum/wiki/wiki/Ethash-DAG
|
|||
* |
|||
* @param[out] strbuf A string buffer of sufficient size to keep the |
|||
* null termninated string of the directory name |
|||
* @param[in] buffsize Size of @a strbuf in bytes |
|||
* @return true for success and false otherwise |
|||
*/ |
|||
bool ethash_get_default_dirname(char* strbuf, size_t buffsize); |
|||
|
|||
static inline bool ethash_io_mutable_name( |
|||
uint32_t revision, |
|||
ethash_h256_t const* seed_hash, |
|||
char* output |
|||
) |
|||
{ |
|||
uint64_t hash = *((uint64_t*)seed_hash); |
|||
#if LITTLE_ENDIAN == BYTE_ORDER |
|||
hash = ethash_swap_u64(hash); |
|||
#endif |
|||
return snprintf(output, DAG_MUTABLE_NAME_MAX_SIZE, "full-R%u-%016" PRIx64, revision, hash) >= 0; |
|||
} |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -1,111 +0,0 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file io_posix.c
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include "io.h" |
|||
#include <sys/types.h> |
|||
#include <sys/stat.h> |
|||
#include <errno.h> |
|||
#include <libgen.h> |
|||
#include <stdio.h> |
|||
#include <unistd.h> |
|||
#include <stdlib.h> |
|||
#include <pwd.h> |
|||
|
|||
FILE* ethash_fopen(char const* file_name, char const* mode) |
|||
{ |
|||
return fopen(file_name, mode); |
|||
} |
|||
|
|||
char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) |
|||
{ |
|||
return strlen(dest) + count + 1 <= dest_size ? strncat(dest, src, count) : NULL; |
|||
} |
|||
|
|||
bool ethash_mkdir(char const* dirname) |
|||
{ |
|||
int rc = mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); |
|||
return rc != -1 || errno == EEXIST; |
|||
} |
|||
|
|||
int ethash_fileno(FILE *f) |
|||
{ |
|||
return fileno(f); |
|||
} |
|||
|
|||
char* ethash_io_create_filename( |
|||
char const* dirname, |
|||
char const* filename, |
|||
size_t filename_length |
|||
) |
|||
{ |
|||
size_t dirlen = strlen(dirname); |
|||
size_t dest_size = dirlen + filename_length + 1; |
|||
if (dirname[dirlen] != '/') { |
|||
dest_size += 1; |
|||
} |
|||
char* name = malloc(dest_size); |
|||
if (!name) { |
|||
return NULL; |
|||
} |
|||
|
|||
name[0] = '\0'; |
|||
ethash_strncat(name, dest_size, dirname, dirlen); |
|||
if (dirname[dirlen] != '/') { |
|||
ethash_strncat(name, dest_size, "/", 1); |
|||
} |
|||
ethash_strncat(name, dest_size, filename, filename_length); |
|||
return name; |
|||
} |
|||
|
|||
bool ethash_file_size(FILE* f, size_t* ret_size) |
|||
{ |
|||
struct stat st; |
|||
int fd; |
|||
if ((fd = fileno(f)) == -1 || fstat(fd, &st) != 0) { |
|||
return false; |
|||
} |
|||
*ret_size = st.st_size; |
|||
return true; |
|||
} |
|||
|
|||
bool ethash_get_default_dirname(char* strbuf, size_t buffsize) |
|||
{ |
|||
static const char dir_suffix[] = ".ethash/"; |
|||
strbuf[0] = '\0'; |
|||
char* home_dir = getenv("HOME"); |
|||
if (!home_dir || strlen(home_dir) == 0) |
|||
{ |
|||
struct passwd* pwd = getpwuid(getuid()); |
|||
if (pwd) |
|||
home_dir = pwd->pw_dir; |
|||
} |
|||
|
|||
size_t len = strlen(home_dir); |
|||
if (!ethash_strncat(strbuf, buffsize, home_dir, len)) { |
|||
return false; |
|||
} |
|||
if (home_dir[len] != '/') { |
|||
if (!ethash_strncat(strbuf, buffsize, "/", 1)) { |
|||
return false; |
|||
} |
|||
} |
|||
return ethash_strncat(strbuf, buffsize, dir_suffix, sizeof(dir_suffix)); |
|||
} |
@ -1,100 +0,0 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file io_win32.c
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include "io.h" |
|||
#include <direct.h> |
|||
#include <errno.h> |
|||
#include <stdio.h> |
|||
#include <sys/stat.h> |
|||
#include <sys/types.h> |
|||
#include <shlobj.h> |
|||
|
|||
FILE* ethash_fopen(char const* file_name, char const* mode) |
|||
{ |
|||
FILE* f; |
|||
return fopen_s(&f, file_name, mode) == 0 ? f : NULL; |
|||
} |
|||
|
|||
char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) |
|||
{ |
|||
return strncat_s(dest, dest_size, src, count) == 0 ? dest : NULL; |
|||
} |
|||
|
|||
bool ethash_mkdir(char const* dirname) |
|||
{ |
|||
int rc = _mkdir(dirname); |
|||
return rc != -1 || errno == EEXIST; |
|||
} |
|||
|
|||
int ethash_fileno(FILE* f) |
|||
{ |
|||
return _fileno(f); |
|||
} |
|||
|
|||
char* ethash_io_create_filename( |
|||
char const* dirname, |
|||
char const* filename, |
|||
size_t filename_length |
|||
) |
|||
{ |
|||
size_t dirlen = strlen(dirname); |
|||
size_t dest_size = dirlen + filename_length + 1; |
|||
if (dirname[dirlen] != '\\' || dirname[dirlen] != '/') { |
|||
dest_size += 1; |
|||
} |
|||
char* name = malloc(dest_size); |
|||
if (!name) { |
|||
return NULL; |
|||
} |
|||
|
|||
name[0] = '\0'; |
|||
ethash_strncat(name, dest_size, dirname, dirlen); |
|||
if (dirname[dirlen] != '\\' || dirname[dirlen] != '/') { |
|||
ethash_strncat(name, dest_size, "\\", 1); |
|||
} |
|||
ethash_strncat(name, dest_size, filename, filename_length); |
|||
return name; |
|||
} |
|||
|
|||
bool ethash_file_size(FILE* f, size_t* ret_size) |
|||
{ |
|||
struct _stat st; |
|||
int fd; |
|||
if ((fd = _fileno(f)) == -1 || _fstat(fd, &st) != 0) { |
|||
return false; |
|||
} |
|||
*ret_size = st.st_size; |
|||
return true; |
|||
} |
|||
|
|||
bool ethash_get_default_dirname(char* strbuf, size_t buffsize) |
|||
{ |
|||
static const char dir_suffix[] = "Ethash\\"; |
|||
strbuf[0] = '\0'; |
|||
if (!SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, (CHAR*)strbuf))) { |
|||
return false; |
|||
} |
|||
if (!ethash_strncat(strbuf, buffsize, "\\", 1)) { |
|||
return false; |
|||
} |
|||
|
|||
return ethash_strncat(strbuf, buffsize, dir_suffix, sizeof(dir_suffix)); |
|||
} |
@ -1,47 +0,0 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file mmap.h
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
#pragma once |
|||
#if defined(__MINGW32__) || defined(_WIN32) |
|||
#include <sys/types.h> |
|||
|
|||
#define PROT_READ 0x1 |
|||
#define PROT_WRITE 0x2 |
|||
/* This flag is only available in WinXP+ */ |
|||
#ifdef FILE_MAP_EXECUTE |
|||
#define PROT_EXEC 0x4 |
|||
#else |
|||
#define PROT_EXEC 0x0 |
|||
#define FILE_MAP_EXECUTE 0 |
|||
#endif |
|||
|
|||
#define MAP_SHARED 0x01 |
|||
#define MAP_PRIVATE 0x02 |
|||
#define MAP_ANONYMOUS 0x20 |
|||
#define MAP_ANON MAP_ANONYMOUS |
|||
#define MAP_FAILED ((void *) -1) |
|||
|
|||
void* mmap(void* start, size_t length, int prot, int flags, int fd, off_t offset); |
|||
void munmap(void* addr, size_t length); |
|||
#else // posix, yay! ^_^
|
|||
#include <sys/mman.h> |
|||
#endif |
|||
|
|||
|
@ -1,84 +0,0 @@ |
|||
/* mmap() replacement for Windows
|
|||
* |
|||
* Author: Mike Frysinger <vapier@gentoo.org> |
|||
* Placed into the public domain |
|||
*/ |
|||
|
|||
/* References:
|
|||
* CreateFileMapping: http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx
|
|||
* CloseHandle: http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx
|
|||
* MapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx
|
|||
* UnmapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx
|
|||
*/ |
|||
|
|||
#include <io.h> |
|||
#include <windows.h> |
|||
#include "mmap.h" |
|||
|
|||
#ifdef __USE_FILE_OFFSET64 |
|||
# define DWORD_HI(x) (x >> 32) |
|||
# define DWORD_LO(x) ((x) & 0xffffffff) |
|||
#else |
|||
# define DWORD_HI(x) (0) |
|||
# define DWORD_LO(x) (x) |
|||
#endif |
|||
|
|||
void* mmap(void* start, size_t length, int prot, int flags, int fd, off_t offset) |
|||
{ |
|||
if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) |
|||
return MAP_FAILED; |
|||
if (fd == -1) { |
|||
if (!(flags & MAP_ANON) || offset) |
|||
return MAP_FAILED; |
|||
} else if (flags & MAP_ANON) |
|||
return MAP_FAILED; |
|||
|
|||
DWORD flProtect; |
|||
if (prot & PROT_WRITE) { |
|||
if (prot & PROT_EXEC) |
|||
flProtect = PAGE_EXECUTE_READWRITE; |
|||
else |
|||
flProtect = PAGE_READWRITE; |
|||
} else if (prot & PROT_EXEC) { |
|||
if (prot & PROT_READ) |
|||
flProtect = PAGE_EXECUTE_READ; |
|||
else if (prot & PROT_EXEC) |
|||
flProtect = PAGE_EXECUTE; |
|||
} else |
|||
flProtect = PAGE_READONLY; |
|||
|
|||
off_t end = length + offset; |
|||
HANDLE mmap_fd, h; |
|||
if (fd == -1) |
|||
mmap_fd = INVALID_HANDLE_VALUE; |
|||
else |
|||
mmap_fd = (HANDLE)_get_osfhandle(fd); |
|||
h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL); |
|||
if (h == NULL) |
|||
return MAP_FAILED; |
|||
|
|||
DWORD dwDesiredAccess; |
|||
if (prot & PROT_WRITE) |
|||
dwDesiredAccess = FILE_MAP_WRITE; |
|||
else |
|||
dwDesiredAccess = FILE_MAP_READ; |
|||
if (prot & PROT_EXEC) |
|||
dwDesiredAccess |= FILE_MAP_EXECUTE; |
|||
if (flags & MAP_PRIVATE) |
|||
dwDesiredAccess |= FILE_MAP_COPY; |
|||
void *ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length); |
|||
if (ret == NULL) { |
|||
ret = MAP_FAILED; |
|||
} |
|||
// since we are handling the file ourselves with fd, close the Windows Handle here
|
|||
CloseHandle(h); |
|||
return ret; |
|||
} |
|||
|
|||
void munmap(void* addr, size_t length) |
|||
{ |
|||
UnmapViewOfFile(addr); |
|||
} |
|||
|
|||
#undef DWORD_HI |
|||
#undef DWORD_LO |
@ -1,37 +0,0 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
/** @file sha3.cpp
|
|||
* @author Tim Hughes <tim@twistedfury.com> |
|||
* @date 2015 |
|||
*/ |
|||
#include <stdint.h> |
|||
#include <cryptopp/sha3.h> |
|||
|
|||
extern "C" { |
|||
struct ethash_h256; |
|||
typedef struct ethash_h256 ethash_h256_t; |
|||
void SHA3_256(ethash_h256_t const* ret, uint8_t const* data, size_t size) |
|||
{ |
|||
CryptoPP::SHA3_256().CalculateDigest((uint8_t*)ret, data, size); |
|||
} |
|||
|
|||
void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size) |
|||
{ |
|||
CryptoPP::SHA3_512().CalculateDigest(ret, data, size); |
|||
} |
|||
} |
@ -1,18 +0,0 @@ |
|||
#pragma once |
|||
|
|||
#include "compiler.h" |
|||
#include <stdint.h> |
|||
#include <stdlib.h> |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
struct ethash_h256; |
|||
|
|||
void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t size); |
|||
void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -1,41 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file util.c
|
|||
* @author Tim Hughes <tim@twistedfury.com> |
|||
* @date 2015 |
|||
*/ |
|||
#include <stdarg.h> |
|||
#include <stdio.h> |
|||
#include "util.h" |
|||
|
|||
#ifdef _MSC_VER |
|||
|
|||
// foward declare without all of Windows.h
|
|||
__declspec(dllimport) void __stdcall OutputDebugStringA(const char* lpOutputString); |
|||
|
|||
void debugf(const char *str, ...) |
|||
{ |
|||
va_list args; |
|||
va_start(args, str); |
|||
|
|||
char buf[1<<16]; |
|||
_vsnprintf_s(buf, sizeof(buf), sizeof(buf), str, args); |
|||
buf[sizeof(buf)-1] = '\0'; |
|||
OutputDebugStringA(buf); |
|||
} |
|||
|
|||
#endif |
@ -1,47 +0,0 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file util.h
|
|||
* @author Tim Hughes <tim@twistedfury.com> |
|||
* @date 2015 |
|||
*/ |
|||
#pragma once |
|||
#include <stdint.h> |
|||
#include "compiler.h" |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
#ifdef _MSC_VER |
|||
void debugf(char const* str, ...); |
|||
#else |
|||
#define debugf printf |
|||
#endif |
|||
|
|||
static inline uint32_t min_u32(uint32_t a, uint32_t b) |
|||
{ |
|||
return a < b ? a : b; |
|||
} |
|||
|
|||
static inline uint32_t clamp_u32(uint32_t x, uint32_t min_, uint32_t max_) |
|||
{ |
|||
return x < min_ ? min_ : (x > max_ ? max_ : x); |
|||
} |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -1,38 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file util.c
|
|||
* @author Tim Hughes <tim@twistedfury.com> |
|||
* @date 2015 |
|||
*/ |
|||
#include <stdarg.h> |
|||
#include <stdio.h> |
|||
#include "util.h" |
|||
|
|||
|
|||
// foward declare without all of Windows.h
|
|||
__declspec(dllimport) void __stdcall OutputDebugStringA(char const* lpOutputString); |
|||
|
|||
void debugf(char const* str, ...) |
|||
{ |
|||
va_list args; |
|||
va_start(args, str); |
|||
|
|||
char buf[1<<16]; |
|||
_vsnprintf_s(buf, sizeof(buf), sizeof(buf), str, args); |
|||
buf[sizeof(buf)-1] = '\0'; |
|||
OutputDebugStringA(buf); |
|||
} |
@ -0,0 +1,121 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file BlockInfo.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <libdevcore/Common.h> |
|||
#include <libdevcore/RLP.h> |
|||
#include <libdevcore/SHA3.h> |
|||
#include "Exceptions.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
/// An Ethereum address: 20 bytes.
|
|||
using Address = h160; |
|||
|
|||
/// The log bloom's size (2048-bit).
|
|||
using LogBloom = h2048; |
|||
|
|||
using Nonce = h64; |
|||
|
|||
using BlockNumber = unsigned; |
|||
|
|||
|
|||
/** @brief Encapsulation of a block header.
|
|||
* Class to contain all of a block header's data. It is able to parse a block header and populate |
|||
* from some given RLP block serialisation with the static fromHeader(), through the method |
|||
* populateFromHeader(). This will conduct a minimal level of verification. In this case extra |
|||
* verification can be performed through verifyInternals() and verifyParent(). |
|||
* |
|||
* The object may also be populated from an entire block through the explicit |
|||
* constructor BlockInfo(bytesConstRef) and manually with the populate() method. These will |
|||
* conduct verification of the header against the other information in the block. |
|||
* |
|||
* The object may be populated with a template given a parent BlockInfo object with the |
|||
* populateFromParent() method. The genesis block info may be retrieved with genesis() and the |
|||
* corresponding RLP block created with createGenesisBlock(). |
|||
* |
|||
* The difficulty and gas-limit derivations may be calculated with the calculateDifficulty() |
|||
* and calculateGasLimit() and the object serialised to RLP with streamRLP. To determine the |
|||
* header hash without the nonce (for mining), the method headerHash(WithoutNonce) is provided. |
|||
* |
|||
* The default constructor creates an empty object, which can be tested against with the boolean |
|||
* conversion operator. |
|||
*/ |
|||
class BlockHeader |
|||
{ |
|||
public: |
|||
static const unsigned BasicFields = 13; |
|||
|
|||
BlockHeader() = default; |
|||
explicit BlockHeader(bytesConstRef _data); |
|||
explicit BlockHeader(bytes const& _data): BlockHeader(&_data) {} |
|||
|
|||
static RLP extractHeader(bytesConstRef _block); |
|||
|
|||
explicit operator bool() const { return m_timestamp != Invalid256; } |
|||
|
|||
h256 const& boundary() const; |
|||
|
|||
void setNumber(u256 const& _v) { m_number = _v; noteDirty(); } |
|||
void setDifficulty(u256 const& _v) { m_difficulty = _v; noteDirty(); } |
|||
|
|||
u256 const& number() const { return m_number; } |
|||
|
|||
/// sha3 of the header only.
|
|||
h256 const& hashWithout() const; |
|||
|
|||
void noteDirty() const { m_hashWithout = m_boundary = h256(); } |
|||
|
|||
h256 const& seedHash() const; |
|||
Nonce const& nonce() const { return m_nonce; } |
|||
|
|||
private: |
|||
void populateFromHeader(RLP const& _header); |
|||
void streamRLPFields(RLPStream& _s) const; |
|||
|
|||
h256 m_parentHash; |
|||
h256 m_sha3Uncles; |
|||
Address m_coinbaseAddress; |
|||
h256 m_stateRoot; |
|||
h256 m_transactionsRoot; |
|||
h256 m_receiptsRoot; |
|||
LogBloom m_logBloom; |
|||
u256 m_number; |
|||
u256 m_gasLimit; |
|||
u256 m_gasUsed; |
|||
u256 m_timestamp = Invalid256; |
|||
bytes m_extraData; |
|||
|
|||
u256 m_difficulty; |
|||
|
|||
mutable h256 m_hashWithout; ///< SHA3 hash of the block header! Not serialised.
|
|||
mutable h256 m_boundary; ///< 2^256 / difficulty
|
|||
|
|||
Nonce m_nonce; |
|||
mutable h256 m_seedHash; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -1,225 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file BlockInfo.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <libdevcore/Common.h> |
|||
#include <libdevcore/RLP.h> |
|||
#include <libdevcore/SHA3.h> |
|||
#include "Common.h" |
|||
#include "Exceptions.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
enum IncludeProof |
|||
{ |
|||
WithoutProof = 0, |
|||
WithProof = 1 |
|||
}; |
|||
|
|||
enum Strictness |
|||
{ |
|||
CheckEverything, |
|||
JustSeal, |
|||
QuickNonce, |
|||
IgnoreSeal, |
|||
CheckNothing |
|||
}; |
|||
|
|||
enum BlockDataType |
|||
{ |
|||
HeaderData, |
|||
BlockData |
|||
}; |
|||
|
|||
DEV_SIMPLE_EXCEPTION(NoHashRecorded); |
|||
DEV_SIMPLE_EXCEPTION(GenesisBlockCannotBeCalculated); |
|||
|
|||
/** @brief Encapsulation of a block header.
|
|||
* Class to contain all of a block header's data. It is able to parse a block header and populate |
|||
* from some given RLP block serialisation with the static fromHeader(), through the method |
|||
* populateFromHeader(). This will conduct a minimal level of verification. In this case extra |
|||
* verification can be performed through verifyInternals() and verifyParent(). |
|||
* |
|||
* The object may also be populated from an entire block through the explicit |
|||
* constructor BlockInfo(bytesConstRef) and manually with the populate() method. These will |
|||
* conduct verification of the header against the other information in the block. |
|||
* |
|||
* The object may be populated with a template given a parent BlockInfo object with the |
|||
* populateFromParent() method. The genesis block info may be retrieved with genesis() and the |
|||
* corresponding RLP block created with createGenesisBlock(). |
|||
* |
|||
* The difficulty and gas-limit derivations may be calculated with the calculateDifficulty() |
|||
* and calculateGasLimit() and the object serialised to RLP with streamRLP. To determine the |
|||
* header hash without the nonce (for mining), the method headerHash(WithoutNonce) is provided. |
|||
* |
|||
* The default constructor creates an empty object, which can be tested against with the boolean |
|||
* conversion operator. |
|||
*/ |
|||
class BlockInfo |
|||
{ |
|||
public: |
|||
static const unsigned BasicFields = 13; |
|||
|
|||
BlockInfo(); |
|||
explicit BlockInfo(bytesConstRef _data, Strictness _s = CheckEverything, h256 const& _hashWith = h256(), BlockDataType _bdt = BlockData); |
|||
explicit BlockInfo(bytes const& _data, Strictness _s = CheckEverything, h256 const& _hashWith = h256(), BlockDataType _bdt = BlockData): BlockInfo(&_data, _s, _hashWith, _bdt) {} |
|||
|
|||
static RLP extractHeader(bytesConstRef _block); |
|||
|
|||
explicit operator bool() const { return m_timestamp != Invalid256; } |
|||
|
|||
bool operator==(BlockInfo const& _cmp) const |
|||
{ |
|||
return m_parentHash == _cmp.parentHash() && |
|||
m_sha3Uncles == _cmp.sha3Uncles() && |
|||
m_coinbaseAddress == _cmp.beneficiary() && |
|||
m_stateRoot == _cmp.stateRoot() && |
|||
m_transactionsRoot == _cmp.transactionsRoot() && |
|||
m_receiptsRoot == _cmp.receiptsRoot() && |
|||
m_logBloom == _cmp.logBloom() && |
|||
m_difficulty == _cmp.difficulty() && |
|||
m_number == _cmp.number() && |
|||
m_gasLimit == _cmp.gasLimit() && |
|||
m_gasUsed == _cmp.gasUsed() && |
|||
m_timestamp == _cmp.timestamp() && |
|||
m_extraData == _cmp.extraData(); |
|||
} |
|||
bool operator!=(BlockInfo const& _cmp) const { return !operator==(_cmp); } |
|||
|
|||
h256 const& boundary() const; |
|||
|
|||
h256 const& parentHash() const { return m_parentHash; } |
|||
h256 const& sha3Uncles() const { return m_sha3Uncles; } |
|||
|
|||
void setNumber(u256 const& _v) { m_number = _v; noteDirty(); } |
|||
void setDifficulty(u256 const& _v) { m_difficulty = _v; noteDirty(); } |
|||
|
|||
Address const& beneficiary() const { return m_coinbaseAddress; } |
|||
h256 const& stateRoot() const { return m_stateRoot; } |
|||
h256 const& transactionsRoot() const { return m_transactionsRoot; } |
|||
h256 const& receiptsRoot() const { return m_receiptsRoot; } |
|||
LogBloom const& logBloom() const { return m_logBloom; } |
|||
u256 const& number() const { return m_number; } |
|||
u256 const& gasLimit() const { return m_gasLimit; } |
|||
u256 const& gasUsed() const { return m_gasUsed; } |
|||
u256 const& timestamp() const { return m_timestamp; } |
|||
bytes const& extraData() const { return m_extraData; } |
|||
|
|||
u256 const& difficulty() const { return m_difficulty; } // TODO: pull out into BlockHeader
|
|||
|
|||
/// sha3 of the header only.
|
|||
h256 const& hashWithout() const; |
|||
h256 const& hash() const { if (m_hash) return m_hash; BOOST_THROW_EXCEPTION(NoHashRecorded()); } |
|||
|
|||
void clear(); |
|||
void noteDirty() const { m_hashWithout = m_boundary = m_hash = h256(); } |
|||
|
|||
protected: |
|||
void populateFromHeader(RLP const& _header, Strictness _s = IgnoreSeal); |
|||
void streamRLPFields(RLPStream& _s) const; |
|||
|
|||
mutable h256 m_hash; ///< SHA3 hash of the block header! Not serialised.
|
|||
|
|||
h256 m_parentHash; |
|||
h256 m_sha3Uncles; |
|||
Address m_coinbaseAddress; |
|||
h256 m_stateRoot; |
|||
h256 m_transactionsRoot; |
|||
h256 m_receiptsRoot; |
|||
LogBloom m_logBloom; |
|||
u256 m_number; |
|||
u256 m_gasLimit; |
|||
u256 m_gasUsed; |
|||
u256 m_timestamp = Invalid256; |
|||
bytes m_extraData; |
|||
|
|||
u256 m_difficulty; // TODO: pull out into BlockHeader
|
|||
|
|||
private: |
|||
mutable h256 m_hashWithout; ///< SHA3 hash of the block header! Not serialised.
|
|||
mutable h256 m_boundary; ///< 2^256 / difficulty
|
|||
}; |
|||
|
|||
template <class BlockInfoSub> |
|||
class BlockHeaderPolished: public BlockInfoSub |
|||
{ |
|||
public: |
|||
BlockHeaderPolished() {} |
|||
BlockHeaderPolished(BlockInfo const& _bi): BlockInfoSub(_bi) {} |
|||
explicit BlockHeaderPolished(bytes const& _data, Strictness _s = IgnoreSeal, h256 const& _h = h256(), BlockDataType _bdt = BlockData) { populate(&_data, _s, _h, _bdt); } |
|||
explicit BlockHeaderPolished(bytesConstRef _data, Strictness _s = IgnoreSeal, h256 const& _h = h256(), BlockDataType _bdt = BlockData) { populate(_data, _s, _h, _bdt); } |
|||
|
|||
// deprecated for public API - use constructor.
|
|||
// TODO: make private.
|
|||
void populate(bytesConstRef _data, Strictness _s, h256 const& _h = h256(), BlockDataType _bdt = BlockData) |
|||
{ |
|||
populateFromHeader(_bdt == BlockData ? BlockInfo::extractHeader(_data) : RLP(_data), _s, _h); |
|||
} |
|||
|
|||
// deprecated for public API - use constructor.
|
|||
// TODO: make private.
|
|||
void populateFromHeader(RLP const& _header, Strictness _s = IgnoreSeal, h256 const& _h = h256()) |
|||
{ |
|||
BlockInfo::m_hash = _h; |
|||
if (_h) |
|||
assert(_h == dev::sha3(_header.data())); |
|||
else |
|||
BlockInfo::m_hash = dev::sha3(_header.data()); |
|||
|
|||
if (_header.itemCount() != BlockInfo::BasicFields + BlockInfoSub::SealFields) |
|||
BOOST_THROW_EXCEPTION(InvalidBlockHeaderItemCount()); |
|||
|
|||
BlockInfo::populateFromHeader(_header, _s); |
|||
BlockInfoSub::populateFromHeader(_header, _s); |
|||
} |
|||
|
|||
void clear() { BlockInfo::clear(); BlockInfoSub::clear(); BlockInfoSub::noteDirty(); } |
|||
void noteDirty() const { BlockInfo::noteDirty(); BlockInfoSub::noteDirty(); } |
|||
|
|||
h256 headerHash(IncludeProof _i = WithProof) const |
|||
{ |
|||
RLPStream s; |
|||
streamRLP(s, _i); |
|||
return sha3(s.out()); |
|||
} |
|||
|
|||
h256 const& hash() const |
|||
{ |
|||
if (!BlockInfo::m_hash) |
|||
BlockInfo::m_hash = headerHash(WithProof); |
|||
return BlockInfo::m_hash; |
|||
} |
|||
|
|||
void streamRLP(RLPStream& _s, IncludeProof _i = WithProof) const |
|||
{ |
|||
_s.appendList(BlockInfo::BasicFields + (_i == WithProof ? BlockInfoSub::SealFields : 0)); |
|||
BlockInfo::streamRLPFields(_s); |
|||
if (_i == WithProof) |
|||
BlockInfoSub::streamRLPFields(_s); |
|||
} |
|||
}; |
|||
|
|||
} |
|||
} |
@ -1,18 +1,16 @@ |
|||
file(GLOB SOURCES "*.cpp") |
|||
file(GLOB HEADERS "*.h") |
|||
|
|||
include_directories(BEFORE ..) |
|||
|
|||
if (ETHASHCUDA) |
|||
include_directories(${CUDA_INCLUDE_DIRS}) |
|||
endif () |
|||
include_directories(BEFORE ..) |
|||
|
|||
add_library(ethcore ${SOURCES} ${HEADERS}) |
|||
target_link_libraries(ethcore ethash devcore) |
|||
|
|||
if (ETHASHCL) |
|||
if(ETHASHCL) |
|||
target_link_libraries(ethcore ethash-cl) |
|||
endif () |
|||
if (ETHASHCUDA) |
|||
endif() |
|||
if(ETHASHCUDA) |
|||
target_include_directories(ethcore PRIVATE ${CUDA_INCLUDE_DIRS}) |
|||
target_link_libraries(ethcore ethash-cuda) |
|||
endif () |
|||
endif() |
|||
|
@ -1,66 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file Common.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* |
|||
* Ethereum-specific data structures & algorithms. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <functional> |
|||
#include <libdevcore/Common.h> |
|||
#include <libdevcore/Exceptions.h> |
|||
#include <libdevcore/FixedHash.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
/// An Ethereum address: 20 bytes.
|
|||
/// @NOTE This is not endian-specific; it's just a bunch of bytes.
|
|||
using Address = h160; |
|||
|
|||
DEV_SIMPLE_EXCEPTION(InvalidAddress); |
|||
|
|||
/// The log bloom's size (2048-bit).
|
|||
using LogBloom = h2048; |
|||
|
|||
/// Many log blooms.
|
|||
using LogBlooms = std::vector<LogBloom>; |
|||
|
|||
using Nonce = h64; |
|||
|
|||
using BlockNumber = unsigned; |
|||
|
|||
// TODO: move back into a mining subsystem and have it be accessible from Sealant only via a dynamic_cast.
|
|||
/**
|
|||
* @brief Describes the progress of a mining operation. |
|||
*/ |
|||
struct WorkingProgress |
|||
{ |
|||
// MiningProgress& operator+=(MiningProgress const& _mp) { hashes += _mp.hashes; ms = std::max(ms, _mp.ms); return *this; }
|
|||
uint64_t hashes = 0; ///< Total number of hashes computed.
|
|||
uint64_t ms = 0; ///< Total number of milliseconds of mining thus far.
|
|||
uint64_t rate() const { return ms == 0 ? 0 : hashes * 1000 / ms; } |
|||
}; |
|||
|
|||
} |
|||
} |
@ -1,38 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file Ethash.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "Ethash.h" |
|||
#include "EthashAux.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
h256 const& Ethash::BlockHeaderRaw::seedHash() const |
|||
{ |
|||
if (!m_seedHash) |
|||
m_seedHash = EthashAux::seedHash((unsigned)m_number); |
|||
return m_seedHash; |
|||
} |
|||
|
|||
} |
|||
} |
@ -1,78 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file Ethash.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* |
|||
* A proof of work algorithm. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <chrono> |
|||
#include <thread> |
|||
#include <cstdint> |
|||
#include "Common.h" |
|||
#include "Miner.h" |
|||
#include "Farm.h" |
|||
|
|||
class ethash_cl_miner; |
|||
class ethash_cuda_miner; |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
class RLP; |
|||
class RLPStream; |
|||
|
|||
namespace eth |
|||
{ |
|||
|
|||
class BlockInfo; |
|||
class EthashCLHook; |
|||
class EthashCUDAHook; |
|||
|
|||
class Ethash |
|||
{ |
|||
public: |
|||
using Nonce = h64; |
|||
|
|||
class BlockHeaderRaw: public BlockInfo |
|||
{ |
|||
friend class EthashSealEngine; |
|||
|
|||
public: |
|||
h256 const& seedHash() const; |
|||
Nonce const& nonce() const { return m_nonce; } |
|||
|
|||
protected: |
|||
BlockHeaderRaw() = default; |
|||
BlockHeaderRaw(BlockInfo const& _bi): BlockInfo(_bi) {} |
|||
|
|||
void clear() { m_mixHash = h256(); m_nonce = Nonce(); } |
|||
|
|||
private: |
|||
Nonce m_nonce; |
|||
h256 m_mixHash; |
|||
|
|||
mutable h256 m_seedHash; |
|||
}; |
|||
using BlockHeader = BlockHeaderPolished<BlockHeaderRaw>; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -1,54 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file EthashSealEngine.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* |
|||
* Determines the PoW algorithm. |
|||
*/ |
|||
|
|||
#include "EthashSealEngine.h" |
|||
#include "EthashGPUMiner.h" |
|||
#include "EthashCUDAMiner.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace eth; |
|||
|
|||
EthashSealEngine::EthashSealEngine() |
|||
{ |
|||
map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers; |
|||
#if ETH_ETHASHCL |
|||
sealers["opencl"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; |
|||
#endif |
|||
#if ETH_ETHASHCUDA |
|||
sealers["cuda"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; |
|||
#endif |
|||
m_farm.setSealers(sealers); |
|||
} |
|||
|
|||
strings EthashSealEngine::sealers() const |
|||
{ |
|||
return { |
|||
"cpu" |
|||
#if ETH_ETHASHCL |
|||
, "opencl" |
|||
#endif |
|||
#if ETH_ETHASHCUDA |
|||
, "cuda" |
|||
#endif |
|||
}; |
|||
} |
@ -1,48 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file EthashSealEngine.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* |
|||
* Determines the PoW algorithm. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Ethash.h" |
|||
#include "EthashAux.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
class EthashSealEngine |
|||
{ |
|||
friend class Ethash; |
|||
|
|||
public: |
|||
EthashSealEngine(); |
|||
|
|||
strings sealers() const; |
|||
|
|||
private: |
|||
eth::GenericFarm<EthashProofOfWork> m_farm; |
|||
}; |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue