Add all found hashes as "block hashes".
authorRoland Häder <haeder@hmmdeutschland.de>
Mon, 28 Apr 2014 09:50:14 +0000 (11:50 +0200)
committerRoland Häder <haeder@hmmdeutschland.de>
Mon, 28 Apr 2014 09:50:14 +0000 (11:50 +0200)
Signed-off-by: Roland Häder <haeder@hmmdeutschland.de>
contrib/chash/chash.php

index 7401dfe6d6a95916ddd48856f79dfffd7710fd6f..eb55f6c00c0b5c8953618495f80047dca5ef5965 100644 (file)
@@ -6,6 +6,9 @@ define('BLOCK_SIZE', 100);
 define('NONCE_INCREMENT', 0.0000000001);
 define('START_TIME', microtime(TRUE));
 
+// Found hashes
+$foundHashes = array();
+
 /**
  * Continued-hashing
  *
@@ -252,7 +255,7 @@ while (TRUE) {
        // Time waited for a good block again (no iteration)
        $timeBadHashes = 0;
 
-       while ($hashesPerBlock <= BLOCK_SIZE) {
+       while (count($foundHashes) <= BLOCK_SIZE) {
                // Create hash from modulaHash ("genesis hash") and nonce
                $nonceHash = doubleHashString($modulaHash . $nonce);
 
@@ -303,19 +306,20 @@ while (TRUE) {
 
                // If the iteration is zero, then no hash is found
                if ($iter == 0) {
-                       // Bad block found
+                       // Bad hash found
                        $timeBadHashes += abs(microtime(TRUE) - $timeHash);
 
                        // And next round
-                       //print('bad:nonce=' . $nonce . PHP_EOL);
+                       //print('BAD:nonce=' . $nonce . PHP_EOL);
 
                        // Nothing found, so calculate new nonce
                        $nonce = calculateNonce($nonce);
                        continue;
                } // END - if
 
-               // Add amount of hashes to block (double-hash)
+               // Add amount of hashes per block (double-hash)
                $hashesPerBlock += $iter * 2 + 2;
+               array_push($foundHashes, $nonceHash);
 
                // Found hash:
                print ('FOUND: nonceHash=' . $nonceHash .',iter=' . $iter . PHP_EOL);
@@ -326,17 +330,16 @@ while (TRUE) {
 
        // Time taken for one block
        $timeBlock = abs(microtime(TRUE) - $timeBlock);
-       //print ('calculateSumFromHash(modulaHash)=' . calculateSumFromHash($modulaHash) . PHP_EOL);
-       //print ('calculateSumFromHash(nonceHash)=' . calculateSumFromHash($nonceHash) . PHP_EOL);
 
        // Calculate reward
        $reward = abs($timeBlock - $timeBadHashes) / $hashrate * $hashesPerBlock / BLOCK_SIZE * 1000;
-       //print ('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $hashesPerBlock .',reward=' . $reward . PHP_EOL);
+       print ('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $hashesPerBlock .',reward=' . $reward . PHP_EOL);
 
        // Block completed
        $totalHashes += $hashesPerBlock;
        $totalBlocks++;
        $hashesPerBlock = 0;
+       $foundHashes = array();
 
        // Calculate new nonce
        $nonce = calculateNonce($nonce);