EthashAux.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 1883 Thomas Edison - All Rights Reserved
  2. * You may use, distribute and modify this code under the
  3. * terms of the GPLv3 license, which unfortunately won't be
  4. * written for another century.
  5. *
  6. * You should have received a copy of the LICENSE file with
  7. * this file.
  8. */
  9. #pragma once
  10. #include <libdev/Common.h>
  11. #include <libdev/Exceptions.h>
  12. #include <libdev/Worker.h>
  13. #include <ethash/ethash.hpp>
  14. namespace dev {
  15. namespace eth {
  16. struct Result {
  17. h256 value;
  18. h256 mixHash;
  19. };
  20. class EthashAux {
  21. public:
  22. static Result eval(int epoch, h256 const& _headerHash, uint64_t _nonce) noexcept;
  23. };
  24. struct EpochContext {
  25. int epochNumber;
  26. int lightNumItems;
  27. size_t lightSize;
  28. ethash_hash512* lightCache = nullptr;
  29. int dagNumItems;
  30. uint64_t dagSize;
  31. };
  32. struct WorkPackage {
  33. WorkPackage() = default;
  34. explicit operator bool() const { return header != h256(); }
  35. std::string job; // Job identifier can be anything. Not necessarily a hash
  36. h256 boundary;
  37. h256 header; ///< When h256() means "pause until notified a new work package is available".
  38. h256 seed;
  39. int epoch = -1;
  40. int block = -1;
  41. uint64_t startNonce = 0;
  42. uint16_t exSizeBytes = 0;
  43. double difficulty = 0;
  44. };
  45. struct Solution {
  46. uint64_t nonce; // Solution found nonce
  47. h256 mixHash; // Mix hash
  48. WorkPackage work; // WorkPackage this solution refers to
  49. std::chrono::steady_clock::time_point tstamp; // Timestamp of found solution
  50. unsigned midx; // Originating miner Id
  51. };
  52. } // namespace eth
  53. } // namespace dev