Continued with chash:
authorRoland Häder <roland@mxchange.org>
Sun, 15 Nov 2020 02:04:56 +0000 (03:04 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 15 Nov 2020 02:04:56 +0000 (03:04 +0100)
- hashing was to fast, commented out very noisy debug lines
- also flushing was to often now, now every 10 seconds and on finding a new block

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

index e04f03a472c17ff65968f9b9a3a6d0d249b7a186..4dfc6075e2c180dc72857f80840b5c8fc5bf3845 100644 (file)
@@ -283,6 +283,9 @@ while (true) {
                addFoundHash($nonceHash);
        } // END - while
 
+       // Flush check-point file
+       flushCheckPointFile($GLOBALS['current_hash']);
+
        // Time taken for one
        $timeBlock = abs(microtime(true) - $timeBlock);
 
@@ -290,8 +293,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'];
index c4a9433b22ec3de9a6f7f0aa1a07e6bb59c7757c..666d4000dd2fc04f7992bed0f648263bc2e10299 100644 (file)
@@ -88,18 +88,33 @@ function flushCheckPointFile ($hash) {
        // Flush data
        file_put_contents(
                CHECKPOINT_FILE,
-               $GLOBALS['total_blocks'] . '|' .
-               $GLOBALS['total_reward'] . '|' .
-               $GLOBALS['total_hashes'] . '|' .
-               $GLOBALS['total_found'] . '|' .
-               $GLOBALS['total_restarts'] . '|' .
-               $GLOBALS['hash_cycles'] . '|' .
-               $GLOBALS['salt'] . '|' .
-               $GLOBALS['difficulty'] . '|' .
-               base64_encode((float) $GLOBALS['nonce']) . '|' .
-               $hash . '|' .
-               $GLOBALS['root_hash'] . '|' .
-               base64_encode(gzcompress(json_encode($GLOBALS['found_hashes'])))
+               //        0  1  2  3  4  5  6  7  8  9 10 11
+               sprintf('%d|%s|%d|%d|%d|%d|%s|%d|%s|%s|%s|%s',
+                       // 0
+                       $GLOBALS['total_blocks'],
+                       // 1
+                       $GLOBALS['total_reward'],
+                       // 2
+                       $GLOBALS['total_hashes'],
+                       // 3
+                       $GLOBALS['total_found'],
+                       // 4
+                       $GLOBALS['total_restarts'],
+                       // 5
+                       $GLOBALS['hash_cycles'],
+                       // 6
+                       $GLOBALS['salt'],
+                       // 7
+                       $GLOBALS['difficulty'],
+                       // 8
+                       base64_encode((float) $GLOBALS['nonce']),
+                       // 9
+                       $hash,
+                       // 10
+                       $GLOBALS['root_hash'],
+                       // 11
+                       base64_encode(gzcompress(json_encode($GLOBALS['found_hashes'])))
+               )
        );
 
        // Set time
@@ -129,13 +144,10 @@ function addFoundHash ($hash) {
        ]);
 
        // Found hash:
-       print ('FOUND: hash=' . $hash . ',nonce=' . $GLOBALS['nonce'] . ',total_found=' . $GLOBALS['total_found'] . PHP_EOL);
+       //* NOISY-DEBUG: */ print ('FOUND: hash=' . $hash . ',nonce=' . $GLOBALS['nonce'] . ',total_found=' . $GLOBALS['total_found'] . PHP_EOL);
 
        // Set time as a new hash was found
        $GLOBALS['found_time'] = microtime(true);
-
-       // Flush check-point file after new hash is found
-       flushCheckPointFile($hash);
 }
 
 /**
@@ -193,7 +205,7 @@ function loadCheckpointFile () {
                $GLOBALS['difficulty']     = $data[7];
                $GLOBALS['nonce']          = (float) base64_decode($data[8]);
                $GLOBALS['current_hash']   = $data[9];
-               $GLOBALS['root_hash']      = $data[9];
+               $GLOBALS['root_hash']      = $data[10];
                $GLOBALS['found_hashes']   = json_decode(gzuncompress(base64_decode($data[11])), TRUE);
        } // END - if
 }