]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 7 May 2018 00:36:57 +0000 (02:36 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 7 May 2018 00:36:57 +0000 (02:36 +0200)
- fix for division-by-zero
- also algo was to "happy" finding new hashes

Signed-off-by: Roland Häder <roland@mxchange.org>
contrib/chash/chash.php
contrib/chash/lib/functions.php

index fe08cd3466e55fbde567c8e92ad87602cc81dc63..90dff03e1953754feadd0c1d3a3e99a2d6464b01 100644 (file)
@@ -61,8 +61,8 @@ if (is_readable(CHECK_POINT)) {
 $gensisHashes = array(
        // A famous quote from Deus Ex 2 - Invisible War
        multiplehashString('"Informations must be free." - AI Helios from Deus Ex'),
 $gensisHashes = array(
        // A famous quote from Deus Ex 2 - Invisible War
        multiplehashString('"Informations must be free." - AI Helios from Deus Ex'),
-       // My name + URL of my first StatusNet instance
-       multipleHashString('Roland Haeder, https://status.mxchange.org'),
+       // My name + URL of my GNUSocial instance
+       multipleHashString('Roland Haeder, https://social.mxchange.org'),
        // A famous quote from Linus Torwalds
        multipleHashString('"Software is like sex. Its better when its free." - Linus Torwalds'),
        // Well ...
        // A famous quote from Linus Torwalds
        multipleHashString('"Software is like sex. Its better when its free." - Linus Torwalds'),
        // Well ...
@@ -88,10 +88,10 @@ $genesisBlock = array(
 
 // Calulcate final "genesis" hash
 $genesisHash = hashString(
 
 // Calulcate final "genesis" hash
 $genesisHash = hashString(
+       $genesisBlock[3] .
        $genesisBlock[0] .
        $genesisBlock[2] .
        $genesisBlock[0] .
        $genesisBlock[2] .
-       $genesisBlock[1] .
-       $genesisBlock[3]
+       $genesisBlock[1]
 );
 
 // Get all elements to get the last part out
 );
 
 // Get all elements to get the last part out
@@ -122,7 +122,7 @@ print ('difficulty=' . $GLOBALS['difficulty'] . PHP_EOL);
 while (true) {
        // Init hash-per-block counter and hashrate
        $GLOBALS['hashes_block'] = 0;
 while (true) {
        // Init hash-per-block counter and hashrate
        $GLOBALS['hashes_block'] = 0;
-       $hashrate = 0;
+       $hashRate = 1;
 
        // Wait for block_size iterations (= found hashes). This is one block
        $timeBlock   = microtime(true);
 
        // Wait for block_size iterations (= found hashes). This is one block
        $timeBlock   = microtime(true);
@@ -159,12 +159,12 @@ while (true) {
                        $testTime = abs(microtime(true) - $timeDisplay);
 
                        // Calculate hashrate/sec
                        $testTime = abs(microtime(true) - $timeDisplay);
 
                        // Calculate hashrate/sec
-                       $hashrate = 1 / $testTime * $GLOBALS['iteration_second'] * $GLOBALS['hash_cycles'];
+                       $hashRate = 1 / $testTime * $GLOBALS['iteration_second'] * $GLOBALS['hash_cycles'];
 
                        // Only every second
                        if ($testTime >= 1) {
                                // Display hash rate
 
                        // Only every second
                        if ($testTime >= 1) {
                                // Display hash rate
-                               print ('hashrate=' . round($hashrate) . ' hashes/sec,iterSecond=' . $GLOBALS['iteration_second'] . ' iterations/sec,difficulty=' . $GLOBALS['difficulty'] . PHP_EOL);
+                               print ('hashrate=' . round($hashRate) . ' hashes/sec,iterSecond=' . $GLOBALS['iteration_second'] . ' iterations/sec,difficulty=' . $GLOBALS['difficulty'] . PHP_EOL);
 
                                // Reset timer
                                $timeDisplay = microtime(true);
 
                                // Reset timer
                                $timeDisplay = microtime(true);
@@ -287,8 +287,8 @@ while (true) {
        $timeBlock = abs(microtime(true) - $timeBlock);
 
        // Calculate reward
        $timeBlock = abs(microtime(true) - $timeBlock);
 
        // Calculate reward
-       $reward = abs($timeBlock - $timeBadHashes) / $hashrate * $GLOBALS['hashes_block'] / $GLOBALS['block_size'] * 1000;
-       print ('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $GLOBALS['hashes_block'] .',reward=' . $reward . PHP_EOL);
+       $reward = abs($timeBlock - $timeBadHashes) / $hashRate * $GLOBALS['hashes_block'] / $GLOBALS['block_size'] * 1000;
+       print('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $GLOBALS['hashes_block'] .',reward=' . $reward . PHP_EOL);
 
        // Double difficulty
        $GLOBALS['difficulty'] = $GLOBALS['difficulty'] * 2;
 
        // Double difficulty
        $GLOBALS['difficulty'] = $GLOBALS['difficulty'] * 2;
index b6bbc079d40e9b8f363ddd60a5855beb504515c0..8401a1084772b08252b2376aa54e03cbf44bf66d 100644 (file)
@@ -137,7 +137,7 @@ function addFoundHash ($hash) {
  * @return     void
  */
 function initNonce () {
  * @return     void
  */
 function initNonce () {
-       $GLOBALS['nonce'] = 1 / (mt_rand() ^ pi());
+       $GLOBALS['nonce'] = 1 / (mt_rand() ^ (1 / pi()));
        print (__FUNCTION__ . ': nonce=' . $GLOBALS['nonce'] . PHP_EOL);
 }
 
        print (__FUNCTION__ . ': nonce=' . $GLOBALS['nonce'] . PHP_EOL);
 }