Browse Source

Introducing get_seedhash

cl-refactor
Matthew Wampler-Doty 10 years ago
parent
commit
fa9e13139f
  1. 7
      ethash.h
  2. 7
      internal.c

7
ethash.h

@ -68,26 +68,31 @@ void ethash_mkcache(ethash_cache *cache, ethash_params const *params, const uint
void ethash_compute_full_data(void *mem, ethash_params const *params, ethash_cache const *cache); void ethash_compute_full_data(void *mem, ethash_params const *params, ethash_cache const *cache);
void ethash_full(ethash_return_value *ret, void const *full_mem, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce); void ethash_full(ethash_return_value *ret, void const *full_mem, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce);
void ethash_light(ethash_return_value *ret, ethash_cache const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce); void ethash_light(ethash_return_value *ret, ethash_cache const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce);
void ethash_get_seedhash(uint8_t seedhash[32], const uint32_t block_number);
static inline void ethash_prep_light(void *cache, ethash_params const *params, const uint8_t seed[32]) { static inline void ethash_prep_light(void *cache, ethash_params const *params, const uint8_t seed[32]) {
ethash_cache c; ethash_cache c;
c.mem = cache; c.mem = cache;
ethash_mkcache(&c, params, seed); ethash_mkcache(&c, params, seed);
} }
static inline void ethash_compute_light(ethash_return_value *ret, void const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) { static inline void ethash_compute_light(ethash_return_value *ret, void const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) {
ethash_cache c; ethash_cache c;
c.mem = (void *) cache; c.mem = (void *) cache;
ethash_light(ret, &c, params, header_hash, nonce); ethash_light(ret, &c, params, header_hash, nonce);
} }
static inline void ethash_prep_full(void *full, ethash_params const *params, void const *cache) { static inline void ethash_prep_full(void *full, ethash_params const *params, void const *cache) {
ethash_cache c; ethash_cache c;
c.mem = (void *) cache; c.mem = (void *) cache;
ethash_compute_full_data(full, params, &c); ethash_compute_full_data(full, params, &c);
} }
static inline void ethash_compute_full(ethash_return_value *ret, void const *full, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) { static inline void ethash_compute_full(ethash_return_value *ret, void const *full, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) {
ethash_full(ret, full, params, header_hash, nonce); ethash_full(ret, full, params, header_hash, nonce);
} }
// Returns if hash is less than or equal to difficulty
static inline int ethash_check_difficulty( static inline int ethash_check_difficulty(
const uint8_t hash[32], const uint8_t hash[32],
const uint8_t difficulty[32]) { const uint8_t difficulty[32]) {
@ -96,7 +101,7 @@ static inline int ethash_check_difficulty(
if (hash[i] == difficulty[i]) continue; if (hash[i] == difficulty[i]) continue;
return hash[i] < difficulty[i]; return hash[i] < difficulty[i];
} }
return 0; return 1;
} }
int ethash_quick_check_difficulty( int ethash_quick_check_difficulty(

7
internal.c

@ -273,6 +273,13 @@ void ethash_quick_hash(
SHA3_256(return_hash, buf, 64 + 32); SHA3_256(return_hash, buf, 64 + 32);
} }
void ethash_get_seedhash(uint8_t seedhash[32], const uint32_t block_number) {
memset(seedhash,0,32);
const uint32_t epochs = block_number / EPOCH_LENGTH;
for (uint32_t i = 0 ; i < epochs ; ++i)
SHA3_256(seedhash, seedhash, 32);
}
int ethash_quick_check_difficulty( int ethash_quick_check_difficulty(
const uint8_t header_hash[32], const uint8_t header_hash[32],
const uint64_t nonce, const uint64_t nonce,

Loading…
Cancel
Save