Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Io handled by ethash #11

Merged
merged 6 commits into from
Mar 30, 2015
Merged

Conversation

LefterisJP
Copy link
Contributor

  • Work in progress
  • For clarity and for future extendability have 2 different source files that are conditionally compiled depending on being in Windows or not for the function that makes calls to OS dependent functions.
  • I created these 2 functions that are intended to be used by the clients by looking at how the C++ client writes the DAG in the disk.
    • One would call ethash_io_prepare() first to make sure the directory exists and check if the memo file's contents match with the current block hash.
    • If there is a mismatch then you would call ethash_io_write() which would compute the full data just like ethash_prep_full() would, write it to the disk along with the memo file and also return them.

Have not yet tried to use it from the C++ client but need to first see if the PR will build in Windows.

@LefterisJP LefterisJP force-pushed the io_handled_by_ethash branch from 78a9796 to a08150c Compare March 25, 2015 13:16
@gavofyork
Copy link
Contributor

  • take seedhash into the creation rather than block number (which contains additional useless information).
  • this is all fine, but ultimately it should be a completely opaque interface and look after memory management - at present we have:
void ethash_prep_full(void *full, ethash_params const *params, void const *cache);
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);

these should become:

typedef void(*Callback)(unsigned);
void* ethash_new_full(ethash_params const* params, void const* cache, const uint8_t seed[32]), CallBack c);
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);
void ethash_delete_full(void const* full);

ethash_new_full should handle caching opaquely and call the Callback 100 times passing 0..99 as the argument.

Before, it was up to the caller to allocate the memory required, passing it in as a void*. Now it should be allocated by ethash_new_full and deallocated by ethash_delete_full.

ethash_compute_full should act as it did before.

May be worth splitting it up into two PRs - integrating memory management separately.

@LefterisJP
Copy link
Contributor Author

I typedefed uint8_t[32] as a blockhash_t. For now it's only in io.h but this should go all over the codebase. It's much more readable and we also get free typechecking this way.

@gavofyork
Copy link
Contributor

new API spec:

typedef void(*Callback)(unsigned);
typedef void const* ethash_full_t;
ethash_full_t ethash_new_full(ethash_params const* params, void const* cache, const uint8_t seed[32]), CallBack c);
void ethash_compute_full(ethash_return_value *ret, ethash_full_t full, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce);
void ethash_delete_full(ethash_full_t full);

char info_buffer[DAG_MEMO_BYTESIZE];
ethash_blockhash_t seedhash;

p.cache_size = ethash_get_cachesize(block_number);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces or tabs, not both :)

@gavofyork
Copy link
Contributor

newer API spec:

typedef int(*Callback)(unsigned);
typedef void const* ethash_full_t;
ethash_full_t ethash_new_full(ethash_params const* params, void const* cache, const uint8_t seed[32]), CallBack c);
void ethash_compute_full(ethash_return_value *ret, ethash_full_t full, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce);
void ethash_delete_full(ethash_full_t full);

non-zero return from Callback means "cancel DAG creation" - this should cause an immediate return of ethash_new_full with 0.

an object of type ethash_full_t may be tested for validity with != 0

Example usage:

int callback(unsigned _progress)
{
  printf("\rGenerating DAG. %d%% done...", _progress);
  return 0;
}
void main()
{
  ethash_params p;
  uint8_t const* cache;
  uint8_t seed[32];
  // TODO: populate p, seed, cache
  ethash_full_t dag = ethash_new_full(&p, cache, seed, &callback);
  if (!dag)
  {
    printf("Failed generating DAG :-(\n");
    exit(-1);
  }
  printf("DAG Generated OK!\n");

  uint8_t headerHash[32];
  // TODO: populate headerHash
  uint64_t nonce = time(0);
  ethash_return_value ret;
  for (; !isWinner(ret); nonce++)
    ethash_compute_full(&ret, dag, &p, headerHash, nonce);
  printf("Got winner! nonce is %d\n", nonce);
  ethash_delete_full(dag);
}

@LefterisJP LefterisJP force-pushed the io_handled_by_ethash branch 12 times, most recently from 418b533 to 368a397 Compare March 26, 2015 14:53
@@ -1,5 +1,7 @@
IF( NOT Boost_FOUND )
find_package(Boost COMPONENTS unit_test_framework)
find_package(Boost COMPONENTS system)
find_package(Boost COMPONENTS filesystem)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better way:

find_package(Boost 1.54.0 REQUIRED COMPONENTS unit_test_framework system filesystem)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be BOOST 1.48.0 since this is only for testing and C++11 and is not the same as the rest of the codebase. Basically boost 1.48.0 is the max we can get in travis-CI so this is kind of a limitation :(

@LefterisJP
Copy link
Contributor Author

rebased

- DAG and memo file creation will now be taken care of in libethash
  itself.

- To that end we crete a very minimal IO module for ethash.

- Depending on the target system io_posix or io_win32 will be used.

- Implemented ethash_io_prepare() for posix
- adding ethash_io_write() function

- only ethash_io_prepare() invoke system dependent functions so it's the
  only one going in system specific source files.
- Also typedefing a blockhash (uint8_t[32]) as an ethash_blockhash_t
- adding back the tests for ethash_io
- adding back the travis configuration changes
- minor changes to make everything work
LefterisJP added a commit that referenced this pull request Mar 30, 2015
@LefterisJP LefterisJP merged commit b85604c into ethereum:master Mar 30, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants