From fc622548d23d4de88af69dffbdf04ac29ef05f82 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 21 Apr 2014 18:29:03 +0200 Subject: [PATCH] Don't increment nonce after block was found, some other improvements, nonce increment is now 1.0 . MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- contrib/chash/chash.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/contrib/chash/chash.php b/contrib/chash/chash.php index fe490dbb..d41a45ba 100644 --- a/contrib/chash/chash.php +++ b/contrib/chash/chash.php @@ -3,7 +3,7 @@ error_reporting(E_ALL | E_STRICT); define('HASH_ALGO', MHASH_RIPEMD320); define('BLOCK_SIZE', 1000); -define('NONCE_INCREMENT', 0.1); +define('NONCE_INCREMENT', 1.0); define('START_TIME', microtime(TRUE)); /** @@ -181,6 +181,17 @@ function calculateNonce ($nonce) { 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 @@ -252,7 +263,7 @@ while (TRUE) { // Time waited for a good block again (no iteration) $timeBadHashes = 0; - while ($hashesPerBlock <= BLOCK_SIZE) { + while ($hashesPerBlock <= getBlockSize()) { // Init counter $iter = 0; @@ -329,7 +340,7 @@ while (TRUE) { } // 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 @@ -340,14 +351,11 @@ while (TRUE) { // Use nonceHash as next modula hash $modulaHash = $nonceHash; - // Calculate new nonce - $nonce = calculateNonce($nonce); - // 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; -- 2.39.5