From 86e2973bd512ad45ed558ca93c78a083f2ef4ee6 Mon Sep 17 00:00:00 2001 From: hackyminer Date: Sat, 24 Nov 2018 21:58:44 +0900 Subject: [PATCH] stash fix (DO NOT MERGE) temporally fixed golang wrapper --- ethash.go | 6 +++--- ethashc.go | 1 + src/libethash/ethash.h | 18 +++++++++++++++++- src/libethash/internal.h | 17 +---------------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/ethash.go b/ethash.go index 837a16c1..4831b60e 100644 --- a/ethash.go +++ b/ethash.go @@ -103,8 +103,8 @@ func freeCache(cache *cache) { cache.ptr = nil } -func (cache *cache) compute(dagSize uint64, hash common.Hash, nonce uint64) (ok bool, mixDigest, result common.Hash) { - ret := C.ethash_light_compute_internal(cache.ptr, C.uint64_t(dagSize), hashToH256(hash), C.uint64_t(nonce)) +func (cache *cache) compute(dagSize uint64, hash common.Hash, nonce uint64, block_number uint64) (ok bool, mixDigest, result common.Hash) { + ret := C.progpow_light_compute_internal(cache.ptr, C.uint64_t(dagSize), hashToH256(hash), C.uint64_t(nonce), C.uint64_t(block_number)) // Make sure cache is live until after the C call. // This is important because a GC might happen and execute // the finalizer before the call completes. @@ -151,7 +151,7 @@ func (l *Light) Verify(block Block) bool { dagSize = dagSizeForTesting } // Recompute the hash using the cache. - ok, mixDigest, result := cache.compute(uint64(dagSize), block.HashNoNonce(), block.Nonce()) + ok, mixDigest, result := cache.compute(uint64(dagSize), block.HashNoNonce(), block.Nonce(), blockNum) if !ok { return false } diff --git a/ethashc.go b/ethashc.go index 1d2ba161..63b51f41 100644 --- a/ethashc.go +++ b/ethashc.go @@ -33,6 +33,7 @@ package ethash #cgo LDFLAGS: -lm #include "src/libethash/internal.c" +#include "src/libethash/progpow-internal.c" #include "src/libethash/sha3.c" #include "src/libethash/io.c" diff --git a/src/libethash/ethash.h b/src/libethash/ethash.h index d050b426..04e87395 100644 --- a/src/libethash/ethash.h +++ b/src/libethash/ethash.h @@ -137,7 +137,23 @@ ethash_return_value_t ethash_full_compute( ); /** - * Calculate the full client data + * Calculate the light client data of the ProgPow + * + * @param light The light client handler + * @param header_hash The header hash to pack into the mix + * @param nonce The nonce to pack into the mix + * @param block_number The block_number + * @return an object of ethash_return_value_t holding the return values + */ +ethash_return_value_t progpow_light_compute( + ethash_light_t light, + ethash_h256_t const header_hash, + uint64_t nonce, + uint64_t block_number +); + +/** + * Calculate the full client data of the ProgPoW * * @param full The full client handler * @param header_hash The header hash to pack into the mix diff --git a/src/libethash/internal.h b/src/libethash/internal.h index 484764f4..9938a542 100644 --- a/src/libethash/internal.h +++ b/src/libethash/internal.h @@ -122,22 +122,7 @@ uint32_t progpowMath(uint32_t a, uint32_t b, uint32_t r); void merge(uint32_t *a, uint32_t b, uint32_t r); /** - * Calculate the light client data - * - * @param light The light client handler - * @param header_hash The header hash to pack into the mix - * @param nonce The nonce to pack into the mix - * @return an object of ethash_return_value_t holding the return values - */ -ethash_return_value_t progpow_light_compute( - ethash_light_t light, - ethash_h256_t const header_hash, - uint64_t nonce, - uint64_t block_number -); - -/** - * Calculate the light client data. Internal version. + * Calculate the light client data of the ProgPow. Internal version. * * @param light The light client handler * @param full_size The size of the full data in bytes.