From 440ca027a2fba59347929c5ccd11af3cb3840d46 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 21 Jul 2013 08:12:40 +0200 Subject: [PATCH 1/2] Fixing PPLNS target calculation on blockavg This will fix #492 with PPLNS targets not taking the blocks in proper order. --- public/include/classes/block.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index 711ed0b5..c08f89d6 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -109,7 +109,7 @@ class Block { * @return data float Float value of average shares **/ public function getAvgBlockShares($limit=10) { - $stmt = $this->mysqli->prepare("SELECT AVG(shares) AS average FROM $this->table LIMIT ?"); + $stmt = $this->mysqli->prepare("SELECT AVG(shares) AS average FROM $this->table ORDER BY height DESC LIMIT ?"); if ($this->checkStmt($stmt) && $stmt->bind_param('i', $limit) && $stmt->execute() && $result = $stmt->get_result()) return (float)$result->fetch_object()->average; return false; From c94c1be7be64d4d2416741361f9d95810f63475a Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 21 Jul 2013 08:35:57 +0200 Subject: [PATCH 2/2] Using proper SQL query by @CaptainAK Proposed fix did not work, using proper Query now. Thank @CaptainAK for the fix! Fixes #492 --- public/include/classes/block.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index c08f89d6..8ce985d1 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -108,8 +108,8 @@ class Block { * @param limit int Maximum blocks to check * @return data float Float value of average shares **/ - public function getAvgBlockShares($limit=10) { - $stmt = $this->mysqli->prepare("SELECT AVG(shares) AS average FROM $this->table ORDER BY height DESC LIMIT ?"); + public function getAvgBlockShares($limit=1) { + $stmt = $this->mysqli->prepare("SELECT AVG(x.shares) AS average FROM (SELECT shares FROM $this->table ORDER BY height DESC LIMIT ?) AS x"); if ($this->checkStmt($stmt) && $stmt->bind_param('i', $limit) && $stmt->execute() && $result = $stmt->get_result()) return (float)$result->fetch_object()->average; return false;