Browse Source

Recovering lost commit after rebase

- adding back the tests for ethash_io
- adding back the travis configuration changes
- minor changes to make everything work
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
68f20ca817
  1. 19
      io.c
  2. 10
      io.h

19
io.c

@ -53,36 +53,31 @@ free_name:
} }
bool ethash_io_write(char const *dirname, bool ethash_io_write(char const *dirname,
uint32_t block_number, ethash_params const* params,
ethash_blockhash_t seedhash,
void const* cache, void const* cache,
uint8_t **data, uint8_t **data,
size_t *data_size) size_t *data_size)
{ {
ethash_params p;
char info_buffer[DAG_MEMO_BYTESIZE]; char info_buffer[DAG_MEMO_BYTESIZE];
ethash_blockhash_t seedhash;
p.cache_size = ethash_get_cachesize(block_number);
p.full_size = ethash_get_datasize(block_number);
// allocate the bytes // allocate the bytes
uint8_t *temp_data_ptr = malloc(p.full_size); uint8_t *temp_data_ptr = malloc(params->full_size);
if (!*temp_data_ptr) { if (!temp_data_ptr) {
goto end; goto end;
} }
ethash_prep_full(temp_data_ptr, &p, cache); ethash_compute_full_data(temp_data_ptr, params, cache);
if (!ethash_io_write_file(dirname, PASS_ARR(DAG_FILE_NAME), temp_data_ptr, p.full_size)) { if (!ethash_io_write_file(dirname, PASS_ARR(DAG_FILE_NAME), temp_data_ptr, params->full_size)) {
goto fail_free; goto fail_free;
} }
ethash_get_seedhash((uint8_t*)&seedhash, block_number);
ethash_io_serialize_info(REVISION, seedhash, info_buffer); ethash_io_serialize_info(REVISION, seedhash, info_buffer);
if (!ethash_io_write_file(dirname, PASS_ARR(DAG_MEMO_NAME), info_buffer, DAG_MEMO_BYTESIZE)) { if (!ethash_io_write_file(dirname, PASS_ARR(DAG_MEMO_NAME), info_buffer, DAG_MEMO_BYTESIZE)) {
goto fail_free; goto fail_free;
} }
*data = temp_data_ptr; *data = temp_data_ptr;
*data_size = p.full_size; *data_size = params->full_size;
return true; return true;
fail_free: fail_free:

10
io.h

@ -62,7 +62,9 @@ enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seed
* *
* @param[in] dirname A null terminated c-string of the path of the ethash * @param[in] dirname A null terminated c-string of the path of the ethash
* data directory. Has to exist. * data directory. Has to exist.
* @param[in] block_number The current block number. * @param[in] params An ethash_params object containing the full size
* and the cache size
* @param[in] seedhash The seedhash of the current block number
* @param[in] cache The cache data. Would have usually been calulated by * @param[in] cache The cache data. Would have usually been calulated by
* @see ethash_prep_light(). * @see ethash_prep_light().
* @param[out] data Pass a pointer to uint8_t by reference here. If the * @param[out] data Pass a pointer to uint8_t by reference here. If the
@ -76,7 +78,8 @@ enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seed
* @return True for success and false in case of failure. * @return True for success and false in case of failure.
*/ */
bool ethash_io_write(char const *dirname, bool ethash_io_write(char const *dirname,
uint32_t block_number, ethash_params const* params,
ethash_blockhash_t seedhash,
void const* cache, void const* cache,
uint8_t **data, uint8_t **data,
size_t *data_size); size_t *data_size);
@ -94,7 +97,8 @@ static inline char *ethash_io_create_filename(char const *dirname,
char const* filename, char const* filename,
size_t filename_length) size_t filename_length)
{ {
char *name = malloc(strlen(dirname) + filename_length); // in C the cast is not needed, but a C++ compiler will complain for invalid conversion
char *name = (char*)malloc(strlen(dirname) + filename_length);
if (!name) { if (!name) {
return NULL; return NULL;
} }

Loading…
Cancel
Save