Browse Source

ethash_get_seedhash() now returns the seedhash value

- plus removing const from PoD.
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
17ec0c7559
  1. 10
      ethash.h
  2. 20
      internal.c

10
ethash.h

@ -72,7 +72,7 @@ typedef struct ethash_return_value {
* @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,13 +89,13 @@ 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 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.
@ -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
}

20
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;

Loading…
Cancel
Save