From 17ec0c7559824b667d0848188e8223e7b7ee90de Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 28 Apr 2015 18:07:10 +0200 Subject: [PATCH] ethash_get_seedhash() now returns the seedhash value - plus removing const from PoD. --- ethash.h | 28 ++++++++++++++-------------- internal.c | 20 ++++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/ethash.h b/ethash.h index 83d4d569a..ea94fd762 100644 --- a/ethash.h +++ b/ethash.h @@ -68,11 +68,11 @@ typedef struct ethash_return_value { /** * Allocate and initialize a new ethash_light handler * - * @param block_number The block number for which to create the handler - * @return Newly allocated ethash_light handler or NULL in case of - * ERRNOMEM or invalid parameters used for @ref ethash_compute_cache_nodes() + * @param block_number The block number for which to create the handler + * @return Newly allocated ethash_light handler or NULL in case of + * ERRNOMEM or invalid parameters used for @ref ethash_compute_cache_nodes() */ -ethash_light_t ethash_light_new(uint64_t const block_number); +ethash_light_t ethash_light_new(uint64_t block_number); /** * Frees a previously allocated ethash_light handler * @param light The light handler to free @@ -89,19 +89,19 @@ void ethash_light_delete(ethash_light_t light); ethash_return_value_t ethash_light_compute( ethash_light_t light, const ethash_h256_t header_hash, - uint64_t const nonce + uint64_t nonce ); /** * Allocate and initialize a new ethash_full handler * - * @param dirname The light handler containing the cache. - * @param callback A callback function with signature of @ref ethash_callback_t - * It accepts an unsigned with which a progress of DAG calculation - * can be displayed. If all goes well the callback should return 0. - * If a non-zero value is returned then DAG generation will stop. - * @return Newly allocated ethash_full handler or NULL in case of - * ERRNOMEM or invalid parameters used for @ref ethash_compute_full_data() + * @param light The light handler containing the cache. + * @param callback A callback function with signature of @ref ethash_callback_t + * It accepts an unsigned with which a progress of DAG calculation + * can be displayed. If all goes well the callback should return 0. + * If a non-zero value is returned then DAG generation will stop. + * @return Newly allocated ethash_full handler or NULL in case of + * ERRNOMEM or invalid parameters used for @ref ethash_compute_full_data() */ ethash_full_t ethash_full_new(ethash_light_t light, ethash_callback_t callback); @@ -121,7 +121,7 @@ void ethash_full_delete(ethash_full_t full); ethash_return_value_t ethash_full_compute( ethash_full_t full, ethash_h256_t const header_hash, - uint64_t const nonce + uint64_t nonce ); /** * Get a pointer to the full DAG data @@ -135,7 +135,7 @@ uint64_t ethash_full_dag_size(ethash_full_t full); /** * Calculate the seedhash for a given block number */ -void ethash_get_seedhash(ethash_h256_t *seedhash, uint64_t const block_number); +ethash_h256_t ethash_get_seedhash(uint64_t block_number); #ifdef __cplusplus } diff --git a/internal.c b/internal.c index c52ca773c..9e6d3a9eb 100644 --- a/internal.c +++ b/internal.c @@ -263,12 +263,14 @@ void ethash_quick_hash( SHA3_256(return_hash, buf, 64 + 32); } -void ethash_get_seedhash(ethash_h256_t* seedhash, uint64_t const block_number) +ethash_h256_t ethash_get_seedhash(uint64_t block_number) { - ethash_h256_reset(seedhash); + ethash_h256_t ret; + ethash_h256_reset(&ret); const uint32_t epochs = block_number / ETHASH_EPOCH_LENGTH; for (uint32_t i = 0; i < epochs; ++i) - SHA3_256(seedhash, (uint8_t*)seedhash, 32); + SHA3_256(&ret, (uint8_t*)&ret, 32); + return ret; } int ethash_quick_check_difficulty( @@ -309,11 +311,10 @@ fail_free_light: return NULL; } -ethash_light_t ethash_light_new(uint64_t const block_number) +ethash_light_t ethash_light_new(uint64_t block_number) { - ethash_h256_t seedhash; + ethash_h256_t seedhash = ethash_get_seedhash(block_number); ethash_light_t ret; - ethash_get_seedhash(&seedhash, block_number); ret = ethash_light_new_internal(ethash_get_cachesize(block_number), &seedhash); ret->block_number = block_number; return ret; @@ -332,7 +333,7 @@ bool ethash_light_compute_internal( ethash_light_t light, uint64_t full_size, const ethash_h256_t header_hash, - uint64_t const nonce + uint64_t nonce ) { return ethash_hash( @@ -440,8 +441,7 @@ ethash_full_t ethash_full_new(ethash_light_t light, ethash_callback_t callback) return NULL; } uint64_t full_size = ethash_get_datasize(light->block_number); - ethash_h256_t seedhash; - ethash_get_seedhash(&seedhash, light->block_number); + ethash_h256_t seedhash = ethash_get_seedhash(light->block_number); return ethash_full_new_internal(strbuf, &seedhash, full_size, light, callback); } @@ -458,7 +458,7 @@ void ethash_full_delete(ethash_full_t full) ethash_return_value_t ethash_full_compute( ethash_full_t full, ethash_h256_t const header_hash, - uint64_t const nonce + uint64_t nonce ) { ethash_return_value_t ret;