X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=contrib%2Fchash%2Fchash.php;h=4911ba57036e2c22603c4abe0ccb738e22bd968d;hb=08a0c865dd2c8ee0b6dbf96f4f07e9ee0ce0f02b;hp=e04f03a472c17ff65968f9b9a3a6d0d249b7a186;hpb=05df7f70f0502385f1d80a027afa4792bfb372a9;p=core.git diff --git a/contrib/chash/chash.php b/contrib/chash/chash.php index e04f03a4..4911ba57 100644 --- a/contrib/chash/chash.php +++ b/contrib/chash/chash.php @@ -169,7 +169,7 @@ while (true) { // Reset timer $timeDisplay = microtime(true); $GLOBALS['iteration_second'] = 0; - } // END - if + } // Time spend from last flush $testTime = abs(microtime(true) - $GLOBALS['time_flush']); @@ -178,7 +178,7 @@ while (true) { if ($testTime >= $GLOBALS['flush_file_time']) { // Flush check-point file flushCheckPointFile($GLOBALS['current_hash']); - } // END - if + } // Time spend from last found block $testTime = abs(microtime(true) - $GLOBALS['found_time']); @@ -200,7 +200,7 @@ while (true) { if (!isset($hash['root_hash'])) { // Bad file die('INCONSISTENCY: hash=' . print_r($hash, true)); - } // END - if + } if (isset($rootHashes[$hash['root_hash']])) { // Count up @@ -209,23 +209,21 @@ while (true) { // First entry found $rootHashes[$hash['root_hash']] = 1; } - } // END - foreach - } // END - foreach + } + } // Find best root hash $bestRootHash = ''; $bestRootCount = 0; foreach ($rootHashes as $hash => $count) { - // Debug message - //* NOISY-DEBUG: */ print ('hash=' . $hash . ',count=' . $count . ',bestRootHash=' . $bestRootHash . ',bestRootCount=' . $bestRootCount . PHP_EOL); - // Is a better one found? + //* NOISY-DEBUG: */ print ('hash=' . $hash . ',count=' . $count . ',bestRootHash=' . $bestRootHash . ',bestRootCount=' . $bestRootCount . PHP_EOL); if ($count > $bestRootCount) { // Remember it $bestRootHash = $hash; $bestRootCount = $count; - } // END - if - } // END - foreach + } + } // Output message print ('bestRootHash=' . $bestRootHash . ',bestRootCount=' . $bestRootCount . PHP_EOL); @@ -249,10 +247,10 @@ while (true) { // Abort search break; - } // END - if - } // END - for - } // END - foreach - } // END - if + } + } + } + } // Next round $GLOBALS['iteration']++; @@ -261,27 +259,28 @@ while (true) { //* NOISY-DEBUG: */ print('nonceHash=' . $nonceHash . PHP_EOL); //* NOISY-DEBUG: */ print('sumNonce=' . $sumNonce . PHP_EOL); //* NOISY-DEBUG: */ print('sumGenesis=' . $GLOBALS['sum_genesis'] . PHP_EOL); - } // END - while + } // If the iteration is zero, then no hash is found if ($GLOBALS['iteration'] == 0) { // Bad hash found $timeBadHashes += abs(microtime(true) - $timeHash); - // And next round - //* NOISY-DEBUG: */ print('BAD:nonce=' . $GLOBALS['nonce'] . PHP_EOL); - // Nothing found, so calculate new nonce + //* NOISY-DEBUG: */ print('BAD:nonce=' . $GLOBALS['nonce'] . PHP_EOL); calculateNonce(); continue; - } // END - if + } // Add amount of hashes per block (multiple-hash) $GLOBALS['hashes_block'] += $GLOBALS['iteration'] * $GLOBALS['hash_cycles'] + $GLOBALS['hash_cycles']; // Push found hash addFoundHash($nonceHash); - } // END - while + } + + // Flush check-point file + flushCheckPointFile($GLOBALS['current_hash']); // Time taken for one $timeBlock = abs(microtime(true) - $timeBlock); @@ -290,8 +289,8 @@ while (true) { $reward = abs($timeBlock - $timeBadHashes) / max(1, $hashRate) * $GLOBALS['hashes_block'] / max(1, $GLOBALS['block_size']) * 1000; print('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $GLOBALS['hashes_block'] .',reward=' . $reward . PHP_EOL); - // Double difficulty - $GLOBALS['difficulty'] = $GLOBALS['difficulty'] * 2; + // Increase difficulty + $GLOBALS['difficulty'] = $GLOBALS['difficulty']++; // Block completed $GLOBALS['total_hashes'] += $GLOBALS['hashes_block']; @@ -314,4 +313,4 @@ while (true) { $rewardPerHour = $GLOBALS['total_reward'] / abs(microtime(true) - START_TIME) * 3600; print ('totalReward=' . $GLOBALS['total_reward'] . ',blockValue=' . $blockValue . ',rewardPerHour=' . $rewardPerHour . PHP_EOL); -} // END - while +}