Generalise the code for solving a block to enable block solve detection with scrypt mining.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/cgminer.c b/cgminer.c
index 33ff829..cd563ed 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2138,13 +2138,9 @@ void clear_logwin(void)
}
#endif
-/* regenerate the full work->hash value and also return true if it's a block */
-bool regeneratehash(const struct work *work)
+/* Returns true if the regenerated work->hash solves a block */
+static bool solves_block(const struct work *work)
{
- uint32_t *data32 = (uint32_t *)(work->data);
- unsigned char swap[80];
- uint32_t *swap32 = (uint32_t *)swap;
- unsigned char hash1[32];
uint32_t *hash32 = (uint32_t *)(work->hash);
uint32_t difficulty = 0;
uint32_t diffbytes = 0;
@@ -2153,10 +2149,6 @@ bool regeneratehash(const struct work *work)
int diffshift = 0;
int i;
- flip80(swap32, data32);
- sha2(swap, 80, hash1);
- sha2(hash1, 32, (unsigned char *)(work->hash));
-
difficulty = swab32(*((uint32_t *)(work->data + 72)));
diffbytes = ((difficulty >> 24) & 0xff) - 3;
@@ -3072,16 +3064,26 @@ static bool stale_work(struct work *work, bool share)
return false;
}
+static void regen_hash(struct work *work)
+{
+ uint32_t *data32 = (uint32_t *)(work->data);
+ unsigned char swap[80];
+ uint32_t *swap32 = (uint32_t *)swap;
+ unsigned char hash1[32];
+
+ flip80(swap32, data32);
+ sha2(swap, 80, hash1);
+ sha2(hash1, 32, (unsigned char *)(work->hash));
+}
+
static void check_solve(struct work *work)
{
if (opt_scrypt)
scrypt_outputhash(work);
- else {
-#ifndef MIPSEB
- /* This segfaults on openwrt */
- work->block = regeneratehash(work);
-#endif
- }
+ else
+ regen_hash(work);
+
+ work->block = solves_block(work);
if (unlikely(work->block)) {
work->pool->solved++;
found_blocks++;