Continued with chash:
[core.git] / contrib / chash / chash.php
index 90dff03e1953754feadd0c1d3a3e99a2d6464b01..ed583d9946b113fb9faf42b40e779696cfc919b4 100644 (file)
@@ -6,7 +6,7 @@ require 'lib/functions.php';
 require 'lib/scrypt.php';
 
 define('START_TIME'            , microtime(true));
-define('CHECK_POINT'           , 'chash.pos');
+define('CHECKPOINT_FILE'           , 'chash.pos');
 
 // Hashes needed to complete a "block"
 $GLOBALS['block_size']          = 100;
@@ -34,7 +34,7 @@ $GLOBALS['salt'] = Scrypt::generateSalt();
 $GLOBALS['difficulty'] = 2;
 
 // Found hashes
-$GLOBALS['found_hashes'] = array(0 => array());
+$GLOBALS['found_hashes'] = array([]);
 
 /**
  * Continued-hashing
@@ -45,7 +45,7 @@ $GLOBALS['found_hashes'] = array(0 => array());
  */
 
 // Is the check point there?
-if (is_readable(CHECK_POINT)) {
+if (is_readable(CHECKPOINT_FILE)) {
        // Load it
        loadCheckpointFile();
 } else {
@@ -193,7 +193,7 @@ while (true) {
                                print('total_restarts=' . $GLOBALS['total_restarts'] . ' - Restarting ...');
 
                                // Count all root (genesis) hashes
-                               $rootHashes = array();
+                               $rootHashes = [];
                                foreach ($GLOBALS['found_hashes'] as $block) {
                                        // "Walk" through all blocks
                                        foreach ($block as $hash) {
@@ -287,7 +287,7 @@ while (true) {
        $timeBlock = abs(microtime(true) - $timeBlock);
 
        // Calculate reward
-       $reward = abs($timeBlock - $timeBadHashes) / $hashRate * $GLOBALS['hashes_block'] / $GLOBALS['block_size'] * 1000;
+       $reward = abs($timeBlock - $timeBadHashes) / $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
@@ -299,7 +299,7 @@ while (true) {
        $GLOBALS['hashes_block'] = 0;
 
        // Init next block
-       $GLOBALS['found_hashes'][$GLOBALS['total_blocks']] = array();
+       $GLOBALS['found_hashes'][$GLOBALS['total_blocks']] = [];
 
        // Calculate new nonce
        calculateNonce();