Browse Source

ethash_io_prepare takes seedhash as an argument

- Also typedefing a blockhash (uint8_t[32]) as an ethash_blockhash_t
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
ab389898bd
  1. 4
      io.c
  2. 10
      io.h
  3. 4
      io_posix.c
  4. 4
      io_win32.c

4
io.c

@ -60,6 +60,7 @@ bool ethash_io_write(char const *dirname,
{
ethash_params p;
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);
@ -74,7 +75,8 @@ bool ethash_io_write(char const *dirname,
goto fail_free;
}
ethash_io_serialize_info(REVISION, block_number, info_buffer);
ethash_get_seedhash((uint8_t*)&seedhash, block_number);
ethash_io_serialize_info(REVISION, seedhash, info_buffer);
if (!ethash_io_write_file(dirname, PASS_ARR(DAG_MEMO_NAME), info_buffer, DAG_MEMO_BYTESIZE)) {
goto fail_free;
}

10
io.h

@ -28,6 +28,8 @@
extern "C" {
#endif
typedef struct ethash_blockhash { uint8_t b[32]; } ethash_blockhash_t;
static const char DAG_FILE_NAME[] = "full";
static const char DAG_MEMO_NAME[] = "full.info";
static const unsigned int DAG_MEMO_BYTESIZE = 36;
@ -47,10 +49,10 @@ enum ethash_io_rc {
*
* @param dirname A null terminated c-string of the path of the ethash
* data directory. If it does not exist it's created.
* @param block_number The current block number. Used in seedhash calculation.
* @param seedhash The seedhash of the current block number
* @return For possible return values @see enum ethash_io_rc
*/
enum ethash_io_rc ethash_io_prepare(char const *dirname, uint32_t block_number);
enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seedhash);
/**
* Fully computes data and writes it to the file on disk.
*
@ -80,12 +82,12 @@ bool ethash_io_write(char const *dirname,
size_t *data_size);
static inline void ethash_io_serialize_info(uint32_t revision,
uint32_t block_number,
ethash_blockhash_t seed_hash,
char *output)
{
// if .info is only consumed locally we don't really care about endianess
memcpy(output, &revision, 4);
ethash_get_seedhash((uint8_t*)(output + 4), block_number);
memcpy(output + 4, &seed_hash, 32);
}
static inline char *ethash_io_create_filename(char const *dirname,

4
io_posix.c

@ -27,7 +27,7 @@
#include <stdio.h>
#include <unistd.h>
enum ethash_io_rc ethash_io_prepare(char const *dirname, uint32_t block_number)
enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seedhash)
{
char read_buffer[DAG_MEMO_BYTESIZE];
char expect_buffer[DAG_MEMO_BYTESIZE];
@ -56,7 +56,7 @@ enum ethash_io_rc ethash_io_prepare(char const *dirname, uint32_t block_number)
goto close;
}
ethash_io_serialize_info(REVISION, block_number, expect_buffer);
ethash_io_serialize_info(REVISION, seedhash, expect_buffer);
if (memcmp(read_buffer, expect_buffer, DAG_MEMO_BYTESIZE) != 0) {
// we have different memo contents so delete the memo file
if (unlink(memofile) != 0) {

4
io_win32.c

@ -24,7 +24,7 @@
#include <errno.h>
#include <stdio.h>
enum ethash_io_rc ethash_io_prepare(char const *dirname, uint32_t block_number)
enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seedhash)
{
char read_buffer[DAG_MEMO_BYTESIZE];
char expect_buffer[DAG_MEMO_BYTESIZE];
@ -53,7 +53,7 @@ enum ethash_io_rc ethash_io_prepare(char const *dirname, uint32_t block_number)
goto close;
}
ethash_io_serialize_info(REVISION, block_number, expect_buffer);
ethash_io_serialize_info(REVISION, seedhash, expect_buffer);
if (memcmp(read_buffer, expect_buffer, DAG_MEMO_BYTESIZE) != 0) {
// we have different memo contents so delete the memo file
if (_unlink(memofile) != 0) {

Loading…
Cancel
Save