From d3fa335e2c730254375f71fce6088a755dda0ecd Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 14 Jun 2013 10:14:13 +0200 Subject: [PATCH 1/2] Ensure we are able to fetch the upstream share * If a block was found but the upstream share is not inserted, bail out * Next run should find the upstream share if it was added properly Should address #189 but maybe not a fix yet. --- cronjobs/findblock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index 0538d94c..dae9b432 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -82,9 +82,9 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $iCurrentUpstreamId = $share->getUpstreamId(); $iAccountId = $user->getUserId($share->getUpstreamFinder()); } else { - verbose("Unable to fetch blocks upstream share\n"); + verbose("Unable to fetch blocks upstream share. Aborting!\n"); verbose($share->getError() . "\n"); - continue; + exit; } // Fetch share information if (!$iPreviousShareId = $block->getLastShareId()) { From 34509051e29213e27398505342258bdbd5602790 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 18 Jun 2013 09:29:25 +0200 Subject: [PATCH 2/2] Properly detect if we did find an upstream share Avoid returning true even if no share was found. Addresses #189 --- cronjobs/findblock.php | 107 ++++++++++++------------- public/include/classes/share.class.php | 3 +- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index dae9b432..cb1e7dba 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -39,9 +39,8 @@ if ( $bitcoin->can_connect() === true ){ // Nothing to do so bail out if (empty($aTransactions['transactions'])) { - verbose("No new transactions since last block\n"); + verbose("No new RPC transactions since last block\n"); } else { - // Table header verbose("Blockhash\t\tHeight\tAmount\tConfirmations\tDiff\t\tTime\t\t\tStatus\n"); @@ -66,65 +65,65 @@ if (empty($aTransactions['transactions'])) { } } -verbose("\n\n"); +verbose("\n"); // Now with our blocks added we can scan for their upstream shares $aAllBlocks = $block->getAllUnaccounted('ASC'); if (empty($aAllBlocks)) { verbose("No new unaccounted blocks found\n"); -} +} else { + // Loop through our unaccounted blocks + verbose("\nBlock ID\tBlock Height\tShare ID\tShares\tFinder\t\t\tStatus\n"); + foreach ($aAllBlocks as $iIndex => $aBlock) { + if (empty($aBlock['share_id'])) { + // Fetch this blocks upstream ID + if ($share->setUpstream($block->getLastUpstreamId())) { + $iCurrentUpstreamId = $share->getUpstreamId(); + $iAccountId = $user->getUserId($share->getUpstreamFinder()); + } else { + verbose("\nUnable to fetch blocks upstream share. Aborting!\n"); + verbose($share->getError() . "\n"); + exit; + } + // Fetch share information + 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); -// Loop through our unaccounted blocks -verbose("Block ID\tBlock Height\tShare ID\tShares\tFinder\t\t\tStatus\n"); -foreach ($aAllBlocks as $iIndex => $aBlock) { - if (empty($aBlock['share_id'])) { - // Fetch this blocks upstream ID - if ($share->setUpstream($block->getLastUpstreamId())) { - $iCurrentUpstreamId = $share->getUpstreamId(); - $iAccountId = $user->getUserId($share->getUpstreamFinder()); - } else { - verbose("Unable to fetch blocks upstream share. Aborting!\n"); - verbose($share->getError() . "\n"); - exit; - } - // Fetch share information - 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 + $strStatus = "OK"; + if (!$block->setShareId($aBlock['id'], $iCurrentUpstreamId)) + $strStatus = "Share ID Failed"; + if (!$block->setFinder($aBlock['id'], $iAccountId)) + $strStatus = "Finder Failed"; + if (!$block->setShares($aBlock['id'], $iRoundShares)) + $strStatus = "Shares Failed"; + if ($config['block_bonus'] > 0 && !$transaction->addTransaction($iAccountId, $config['block_bonus'], 'Bonus', $aBlock['id'])) { + $strStatus = "Bonus Failed"; + } - // Store new information - $strStatus = "OK"; - if (!$block->setShareId($aBlock['id'], $iCurrentUpstreamId)) - $strStatus = "Share ID Failed"; - if (!$block->setFinder($aBlock['id'], $iAccountId)) - $strStatus = "Finder Failed"; - if (!$block->setShares($aBlock['id'], $iRoundShares)) - $strStatus = "Shares Failed"; - if ($config['block_bonus'] > 0 && !$transaction->addTransaction($iAccountId, $config['block_bonus'], 'Bonus', $aBlock['id'])) { - $strStatus = "Bonus Failed"; - } + verbose( + $aBlock['id'] . "\t\t" + . $aBlock['height'] . "\t\t" + . $iCurrentUpstreamId . "\t\t" + . $iRoundShares . "\t" + . "[$iAccountId] " . $user->getUserName($iAccountId) . "\t\t" + . $strStatus + . "\n" + ); - verbose( - $aBlock['id'] . "\t\t" - . $aBlock['height'] . "\t\t" - . $iCurrentUpstreamId . "\t\t" - . $iRoundShares . "\t" - . "[$iAccountId] " . $user->getUserName($iAccountId) . "\t\t" - . $strStatus - . "\n" - ); - - // Notify users - $aAccounts = $notification->getNotificationAccountIdByType('new_block'); - if (is_array($aAccounts)) { - foreach ($aAccounts as $account_id) { - $aMailData['height'] = $aBlock['height']; - $aMailData['subject'] = 'New Block'; - $aMailData['email'] = $user->getUserEmail($user->getUserName($account_id)); - $aMailData['shares'] = $iRoundShares; - $notification->sendNotification($account_id, 'new_block', $aMailData); + // Notify users + $aAccounts = $notification->getNotificationAccountIdByType('new_block'); + if (is_array($aAccounts)) { + foreach ($aAccounts as $account_id) { + $aMailData['height'] = $aBlock['height']; + $aMailData['subject'] = 'New Block'; + $aMailData['email'] = $user->getUserEmail($user->getUserName($account_id)); + $aMailData['shares'] = $iRoundShares; + $notification->sendNotification($account_id, 'new_block', $aMailData); + } } } } diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 1033f92c..85935a2d 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -187,7 +187,8 @@ class Share { ORDER BY id ASC LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param('i', $last) && $stmt->execute() && $result = $stmt->get_result()) { $this->oUpstream = $result->fetch_object(); - return true; + if (!empty($this->oUpstream->account) && is_int($this->oUpstream->id)) + return true; } // Catchall return false;