Don't increment nonce after block was found, some other improvements, nonce increment...
authorRoland Haeder <roland@mxchange.org>
Mon, 21 Apr 2014 16:29:03 +0000 (18:29 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 21 Apr 2014 16:29:03 +0000 (18:29 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
contrib/chash/chash.php

index fe490dbba2018f3dc85aade908aaf42c27e136bf..d41a45ba213a2cbd755410665b568e7466a14eb5 100644 (file)
@@ -3,7 +3,7 @@ error_reporting(E_ALL | E_STRICT);
 
 define('HASH_ALGO', MHASH_RIPEMD320);
 define('BLOCK_SIZE', 1000);
 
 define('HASH_ALGO', MHASH_RIPEMD320);
 define('BLOCK_SIZE', 1000);
-define('NONCE_INCREMENT', 0.1);
+define('NONCE_INCREMENT', 1.0);
 define('START_TIME', microtime(TRUE));
 
 /**
 define('START_TIME', microtime(TRUE));
 
 /**
@@ -181,6 +181,17 @@ function calculateNonce ($nonce) {
        return $newNonce;
 }
 
        return $newNonce;
 }
 
+/**
+ * Calculates current block
+ *
+ * @return     $blockSize      Block size
+ * @todo       This needs improvement
+ */
+function getBlockSize () {
+       // For now only a constant block size
+       return BLOCK_SIZE;
+}
+
 /*
  * Calculate "genesis" hashes, please note that these "genesis strings" are now
  * known to the public as you can read them here in source code and therefore I
 /*
  * Calculate "genesis" hashes, please note that these "genesis strings" are now
  * known to the public as you can read them here in source code and therefore I
@@ -252,7 +263,7 @@ while (TRUE) {
        // Time waited for a good block again (no iteration)
        $timeBadHashes = 0;
 
        // Time waited for a good block again (no iteration)
        $timeBadHashes = 0;
 
-       while ($hashesPerBlock <= BLOCK_SIZE) {
+       while ($hashesPerBlock <= getBlockSize()) {
                // Init counter
                $iter = 0;
 
                // Init counter
                $iter = 0;
 
@@ -329,7 +340,7 @@ while (TRUE) {
        } // END - if
 
        // Calculate reward
        } // END - if
 
        // Calculate reward
-       $reward = abs($timeBlock - $timeBadHashes) / $hashrate * $hashesPerBlock / BLOCK_SIZE * 1000;
+       $reward = abs($timeBlock - $timeBadHashes) / $hashrate * $hashesPerBlock / getBlockSize() * 1000;
        print ('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $hashesPerBlock .',reward=' . $reward . PHP_EOL);
 
        // Block completed
        print ('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $hashesPerBlock .',reward=' . $reward . PHP_EOL);
 
        // Block completed
@@ -340,14 +351,11 @@ while (TRUE) {
        // Use nonceHash as next modula hash
        $modulaHash = $nonceHash;
 
        // Use nonceHash as next modula hash
        $modulaHash = $nonceHash;
 
-       // Calculate new nonce
-       $nonce = calculateNonce($nonce);
-
        // Add reward to total
        $totalReward += $reward;
 
        // Calculate average block value
        // Add reward to total
        $totalReward += $reward;
 
        // Calculate average block value
-       $blockValue = $totalReward / $totalBlocks * $totalHashes / (BLOCK_SIZE * $totalBlocks);
+       $blockValue = $totalReward / $totalBlocks * $totalHashes / (getBlockSize() * $totalBlocks);
 
        // Calculate reward per hour (= 3600 seconds)
        $rewardPerHour = $totalReward / abs(microtime(TRUE) - START_TIME) * 3600;
 
        // Calculate reward per hour (= 3600 seconds)
        $rewardPerHour = $totalReward / abs(microtime(TRUE) - START_TIME) * 3600;