From 4691e077e2a69a375d85a84c9a5ca12c018afe53 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Jun 2013 22:27:34 +0200 Subject: [PATCH] Ensure no old blocks shares are counter for new ones When finding more than a single block between runs it added shares to a new block from a previous one. Properly fetch the last highest share ID from the database prior to scanning for shares assigned to a block. Fixes #124 --- cronjobs/findblock.php | 6 +++++- public/include/classes/block.class.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index 64d32914..2f978eed 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -87,7 +87,11 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { continue; } // Fetch share information - $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; + if (!$iPreviousShareId = $block->getLastShareId()) { + $iPreviousShareId = 0; + verbose("\nUnable to find highest share ID found so far\n"); + verbose("If this is your first block, this is normal\n\n"); + } $iRoundShares = $share->getRoundShares($iPreviousShareId, $iCurrentUpstreamId); // Store new information diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index aad32c08..743ce67e 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -43,6 +43,18 @@ class Block { return false; } + /** + * Get our last, highest share ID inserted for a block + * @param none + * @return int data Share ID + **/ + public function getLastShareId() { + $stmt = $this->mysqli->prepare("SELECT MAX(share_id) AS share_id FROM $this->table LIMIT 1"); + if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_object()->share_id; + return false; + } + /** * Fetch all unaccounted blocks * @param order string Sort order, default ASC