Added check-point file.
[core.git] / contrib / chash / chash.php
index 6705b960e81887b67cc17d2974c6599fb32a26c8..1059641f1345c946dd61b17c4c99fde63e7ff554 100644 (file)
@@ -5,6 +5,7 @@ define('HASH_ALGO', MHASH_RIPEMD320);
 define('BLOCK_SIZE', 100);
 define('NONCE_INCREMENT', 0.0000000000000001);
 define('START_TIME', microtime(TRUE));
+define('CHECK_POINT', 'chash.pos');
 
 // Found hashes
 $foundHashes = array();
@@ -240,9 +241,27 @@ $totalReward = 0;
 $totalHashes = 0;
 $totalBlocks = 0;
 
-// Create nonce (small)
-$nonce = 1 / mt_rand();
+// Is the check point there?
+if (is_readable(CHECK_POINT)) {
+       // Then load it
+       $checkPoint = file_get_contents(CHECK_POINT);
 
+       // Explode it
+       $data = explode(':', $checkPoint);
+
+       // 1st element is nonce, 2nd hash
+       $nonce = $data[0];
+       $modulaHash = $data[1];
+} else {
+       // Create nonce (small)
+       $nonce = 1 / mt_rand();
+}
+
+// Output again
+print ('modulaHash=' . $modulaHash . PHP_EOL);
+print ('nonce=' . $nonce . PHP_EOL);
+
+// Start "mining"
 while (TRUE) {
        // Init hash-per-block counter and hashrate
        $hashesPerBlock = 0;
@@ -322,7 +341,10 @@ while (TRUE) {
                array_push($foundHashes, $nonceHash);
 
                // Found hash:
-               print ('FOUND: nonceHash=' . $nonceHash .',nonce=' . $nonce . ',iter=' . $iter . PHP_EOL);
+               print ('FOUND: nonceHash=' . $nonceHash . ',nonce=' . $nonce . ',iter=' . $iter . PHP_EOL);
+
+               // Write check-point
+               file_put_contents(CHECK_POINT, $nonce . ':' . $nonceHash);
 
                // Use nonceHash as next modula hash
                $modulaHash = $nonceHash;