X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=contrib%2Fchash%2Fchash.php;h=fe490dbba2018f3dc85aade908aaf42c27e136bf;hp=7101f3dcdeefffdb4af5f9b353193c123b8476e7;hb=6abb05749348fe89e45c9a69cfec0c3e50040358;hpb=d6831f8cd303201fdc04a1eff9554d126096bfeb diff --git a/contrib/chash/chash.php b/contrib/chash/chash.php index 7101f3dc..fe490dbb 100644 --- a/contrib/chash/chash.php +++ b/contrib/chash/chash.php @@ -241,8 +241,9 @@ $totalBlocks = 0; $nonce = 1 / mt_rand(); while (TRUE) { - // Init hash-per-block counter + // Init hash-per-block counter and hashrate $hashesPerBlock = 0; + $hashrate = 0; // Wait for BLOCK_SIZE iterations (= found hashes). This is one block $timeBlock = microtime(TRUE); @@ -321,6 +322,12 @@ while (TRUE) { //print ('calculateSumFromHash(modulaHash)=' . calculateSumFromHash($modulaHash) . PHP_EOL); //print ('calculateSumFromHash(nonceHash)=' . calculateSumFromHash($nonceHash) . PHP_EOL); + // Is the hash rate unset? + if ($hashrate == 0) { + // Then calculate it again + $hashrate = 1 / $timeBlock * $iter * 2 + 2; + } // END - if + // Calculate reward $reward = abs($timeBlock - $timeBadHashes) / $hashrate * $hashesPerBlock / BLOCK_SIZE * 1000; print ('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $hashesPerBlock .',reward=' . $reward . PHP_EOL); @@ -330,8 +337,8 @@ while (TRUE) { $totalBlocks++; $hashesPerBlock = 0; - // Calculate next hash from both hashes - $modulaHash = doubleHashString(modulaHash($nonceHash, $modulaHash)); + // Use nonceHash as next modula hash + $modulaHash = $nonceHash; // Calculate new nonce $nonce = calculateNonce($nonce);