From 631a6e4d26d49829587bbde77629471f05ede4c0 Mon Sep 17 00:00:00 2001 From: encorehu Date: Fri, 4 Apr 2014 16:49:19 +0800 Subject: [PATCH 01/28] fix function encode doesnot exist; add $schemaname to function --- instant_livedata.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/instant_livedata.php b/instant_livedata.php index fa5eebb..2b0b70f 100644 --- a/instant_livedata.php +++ b/instant_livedata.php @@ -21,6 +21,8 @@ # in case we're in a function.... include("config.php"); + if (isset($argv[2])) { $nocache = 1; } else { $nocache = 0; } + if (!isset($link)) { $link = pg_pconnect("dbname=$psqldb user=$psqluser password='$psqlpass' host=$psqlhost"); } $livedata = get_stats_cache($link, 5, "livedata.json"); @@ -67,13 +69,15 @@ # get latest network difficulty from latest accepted share's "bits" field - $sql = "select id,(pow(10,((29-hex_to_int(substr(encode(solution,'hex'),145,2)))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where server=$serverid and our_result=true order by id desc limit 1;"; + $sql = "select id,(pow(10,((29-$psqlschema.hex_to_int(substr(encode(solution,'hex'),145,2)::varchar))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / $psqlschema.hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where server=$serverid and our_result=true order by id desc limit 1;"; + //echo $sql; $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); $netdiff = $row["network_difficulty"]; # Get the share id of the last valid block we've found - $sql = "select * from (select orig_id,time from stats_blocks where server=$serverid and confirmations > 0 order by time desc limit 1) as a, (select time+'675 seconds'::interval as satime from stats_shareagg where server=$serverid order by time desc limit 1) as b;"; - $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); + $sql = "select * from (select orig_id,time from $psqlschema.stats_blocks where server=$serverid and confirmations > 0 order by time desc limit 1) as a, (select time+'675 seconds'::interval as satime from $psqlschema.stats_shareagg where server=$serverid order by time desc limit 1) as b;"; + $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); + echo $row; $tempid = $row["orig_id"]; $temptime = $row["time"]; $temptime2 = $row["satime"]; @@ -132,8 +136,8 @@ if($cppsrbjsondec = apc_fetch('cppsrb_json_inst')) { $hashrate256 = $cppsrbjsondec[""]["shares"][256] * 16777216; } else { - if (filemtime("/var/lib/eligius/$serverid/cppsrb.json") > (time()-600)) { - $cppsrbjson = file_get_contents("/var/lib/eligius/$serverid/cppsrb.json"); + if (filemtime("$pooldatadir/$serverid/cppsrb.json") > (time()-600)) { + $cppsrbjson = file_get_contents("$pooldatadir/$serverid/cppsrb.json"); $cppsrbjsondec = json_decode($cppsrbjson, true); apc_store('cppsrb_json_inst', $cppsrbjsondec, 60); $hashrate256 = $cppsrbjsondec[""]["shares"][256] * 16777216; From 300f06122c0db7602e1d7df139536c0f1e4ee35d Mon Sep 17 00:00:00 2001 From: encorehu Date: Fri, 4 Apr 2014 16:50:47 +0800 Subject: [PATCH 02/28] /var/lib/eligius --> $pooldatadir --- hashrate.php | 2 +- lib.userstat.php | 4 ++-- payoutqueue.php | 10 +++++----- updatebalancesv2.php | 2 +- updatetxndata.php | 6 +++--- userstats.php | 18 +++++++++--------- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/hashrate.php b/hashrate.php index f1378c5..14d5aef 100644 --- a/hashrate.php +++ b/hashrate.php @@ -59,7 +59,7 @@ function get_hashrate_stats(&$link, $givenuser, $user_id) # instant hashrates from CPPSRB if($cppsrbjsondec = apc_fetch('cppsrb_json')) { } else { - $cppsrbjson = file_get_contents("/var/lib/eligius/$serverid/cppsrb.json"); + $cppsrbjson = file_get_contents("$pooldatadir/$serverid/cppsrb.json"); $cppsrbjsondec = json_decode($cppsrbjson, true); apc_store('cppsrb_json', $cppsrbjsondec, 60); } diff --git a/lib.userstat.php b/lib.userstat.php index 4a1835a..a424836 100644 --- a/lib.userstat.php +++ b/lib.userstat.php @@ -21,7 +21,7 @@ function getAllBalances() { if($balanacesjsondec = apc_fetch('balance')) { } else { - $balance = file_get_contents("/var/lib/eligius/$serverid/balances.json"); + $balance = file_get_contents("$pooldatadir/$serverid/balances.json"); $balanacesjsondec = json_decode($balance, true); // Store Cache for 10 minutes apc_store('balance', $balanacesjsondec, 600); @@ -34,7 +34,7 @@ function getAllBalancesSM() { if($balanacesjsondecSM = apc_fetch('balance_smpps')) { } else { - $balanacesjsonSM = file_get_contents("/var/lib/eligius/$serverid/smpps_lastblock.json"); + $balanacesjsonSM = file_get_contents("$pooldatadir/$serverid/smpps_lastblock.json"); $balanacesjsondecSM = json_decode($balanacesjsonSM,true); // Store Cache forever (10 days) apc_store('balance_smpps', $balanacesjsondecSM, 864000); diff --git a/payoutqueue.php b/payoutqueue.php index 8cc1c4f..6febc94 100644 --- a/payoutqueue.php +++ b/payoutqueue.php @@ -10,14 +10,14 @@ // Try Cache First if($payout = apc_fetch('payout')) { } else { - $payout = file("/var/lib/eligius/$serverid/payout_queue.txt", FILE_IGNORE_NEW_LINES); + $payout = file("$pooldatadir/$serverid/payout_queue.txt", FILE_IGNORE_NEW_LINES); // Store Cache for 10 minutes apc_store('payout', $payout, 600); } // Try Cache First if($balance = apc_fetch('balance')) { } else { - $balance = file_get_contents("/var/lib/eligius/$serverid/balances.json"); + $balance = file_get_contents("$pooldatadir/$serverid/balances.json"); $balance = json_decode($balance, true); // Store Cache for 10 minutes apc_store('balance', $balance, 600); @@ -32,15 +32,15 @@ $lt10tbcc = 0; foreach($payout as $key) { $value = $balance[$key]; - if ($value['balance'] < 1048576) { + if ($value['balance'] < 1048576) { $lt10tbc += $value['balance']; $lt10tbcc++; - $value['balance'] = 0; + $value['balance'] = 0; } while($value['balance'] > 0) { if ($total+$value['balance'] > 2500000000) { $maxbal = 2500000000 - $total; - $qt .= " $paynum$key ".prettyDuration(time()-$value['oldest'])." ".prettySatoshis($maxbal)." "; + $qt .= " $paynum$key ".prettyDuration(time()-$value['oldest'])." ".prettySatoshis($maxbal)." "; if ($oddeven) { $oe = " class=\"oddblockconfirmed\""; $oddeven = 0; } else { $oe = " class=\"blockconfirmed\""; $oddeven = 1; } $qt .= "--- BLOCK BOUNDARY--- "; if ($oddeven) { $oe = " class=\"oddblockconfirmed\""; $oddeven = 0; } else { $oe = " class=\"blockconfirmed\""; $oddeven = 1; } diff --git a/updatebalancesv2.php b/updatebalancesv2.php index 1ef8828..8b558e4 100755 --- a/updatebalancesv2.php +++ b/updatebalancesv2.php @@ -32,7 +32,7 @@ $serverid = 7; # TODO: fix mostly hardcoded path -$bal = file_get_contents("/var/lib/eligius/$serverid/balances.json"); +$bal = file_get_contents("$pooldatadir/$serverid/balances.json"); $balj = json_decode($bal,true); diff --git a/updatetxndata.php b/updatetxndata.php index e116da3..782c286 100755 --- a/updatetxndata.php +++ b/updatetxndata.php @@ -21,8 +21,8 @@ $doanyway = 0; if (isset($argv[1])) { $doanyway = 1; } -$blockjsondec = json_decode(file_get_contents("/var/lib/eligius/$serverid/blocks/latest.json"),true); -$lastblock = substr(readlink("/var/lib/eligius/$serverid/blocks/latest.json"),0,-5); +$blockjsondec = json_decode(file_get_contents("$pooldatadir/$serverid/blocks/latest.json"),true); +$lastblock = substr(readlink("$pooldatadir/$serverid/blocks/latest.json"),0,-5); $link = pg_Connect("dbname=$psqldb user=$psqluser password='$psqlpass' host=$psqlhost", PGSQL_CONNECT_FORCE_NEW ); @@ -152,7 +152,7 @@ print "\n"; $lastblock = $blockjsondec[""]["mylastblk"]; if (strlen($lastblock) < 64) { print "Error. No last block!?\n"; exit; } - $blockjsondec = json_decode(file_get_contents("/var/lib/eligius/$serverid/blocks/".($lastblock).".json"),true); + $blockjsondec = json_decode(file_get_contents("$pooldatadir/$serverid/blocks/".($lastblock).".json"),true); } diff --git a/userstats.php b/userstats.php index af7bd4f..2d476d5 100644 --- a/userstats.php +++ b/userstats.php @@ -71,7 +71,7 @@ if($balanacesjsondec = apc_fetch('balance')) { } else { - $balance = file_get_contents("/var/lib/eligius/$serverid/balances.json"); + $balance = file_get_contents("$pooldatadir/$serverid/balances.json"); $balanacesjsondec = json_decode($balance, true); // Store Cache for 10 minutes apc_store('balance', $balanacesjsondec, 600); @@ -126,7 +126,7 @@ if($balanacesjsondecSM = apc_fetch('balance_smpps')) { } else { - $balanacesjsonSM = file_get_contents("/var/lib/eligius/$serverid/smpps_lastblock.json"); + $balanacesjsonSM = file_get_contents("$pooldatadir/$serverid/smpps_lastblock.json"); $balanacesjsondecSM = json_decode($balanacesjsonSM,true); // Store Cache forever (10 days) apc_store('balance_smpps', $balanacesjsondecSM, 864000); @@ -135,7 +135,7 @@ if (isset($mybalSM)) { # SMPPS credit needed to be halved for the pool to be statistically viable - $smppsec = $mybalSM["credit"]; + $smppsec = $mybalSM["credit"]; $smppshalf = $mybalSM["credit"]/2; $smppsec -= $smppshalf; } else { @@ -317,8 +317,8 @@ $t = $row["ctime"]; $as = $row["accepted_shares"]; $rs = $row["rejected_shares"]; - if (!isset($wstat[$wid])) { - $wstat[$wid] = array(); + if (!isset($wstat[$wid])) { + $wstat[$wid] = array(); for($x=0;$x<3;$x++) { $wstat[$wid][$x] = array(); $wstat[$wid][$x][1] = 0; @@ -333,7 +333,7 @@ $wstat[$wid][1][2] += $rs; if ($t > $t225) { $wstat[$wid][2][1] += $as; - $wstat[$wid][2][2] += $rs; + $wstat[$wid][2][2] += $rs; } } } @@ -402,7 +402,7 @@ var blockUpdateA = 0; var blockUpdateB = 0; - g2 = new Dygraph(document.getElementById(\"ugraphdiv2\"),\"$givenuser?cmd=hashgraph&start=0&back=$secondsback&res=1\",{ + g2 = new Dygraph(document.getElementById(\"ugraphdiv2\"),\"$givenuser?cmd=hashgraph&start=0&back=$secondsback&res=1\",{ strokeWidth: 1.5, fillGraph: true, '675 second': { color: '#408000' }, @@ -432,7 +432,7 @@ var mrindex = 0; var mrhidden = 1; g3 = new Dygraph( - document.getElementById(\"ugraphdiv3\"),\"$givenuser?cmd=balancegraph&start=0&back=$secondsback&res=1\",{ + document.getElementById(\"ugraphdiv3\"),\"$givenuser?cmd=balancegraph&start=0&back=$secondsback&res=1\",{ strokeWidth: 2.25, fillGraph: true, labelsDivStyles: { border: '1px solid black' }, @@ -526,7 +526,7 @@ print "
Estimated Position in Payout Queue
"; if ($payoutqueue = apc_fetch('wizstats_payoutqueuetxt')) { } else { - $payoutqueue = file_get_contents("/var/lib/eligius/$serverid/payout_queue.txt"); + $payoutqueue = file_get_contents("$pooldatadir/$serverid/payout_queue.txt"); apc_store('wizstats_payoutqueuetxt', $payoutqueue, 600); } print ""; From c031cce921b2e5139ea6ef3a98122ec78bb33b66 Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:22:04 +0800 Subject: [PATCH 03/28] when there is no data, many bugs displayed!!!! --- instant_livedata.php | 62 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/instant_livedata.php b/instant_livedata.php index 2b0b70f..ddca9b9 100644 --- a/instant_livedata.php +++ b/instant_livedata.php @@ -25,12 +25,37 @@ if (!isset($link)) { $link = pg_pconnect("dbname=$psqldb user=$psqluser password='$psqlpass' host=$psqlhost"); } - $livedata = get_stats_cache($link, 5, "livedata.json"); + $livedata = get_stats_cache($link, 5, "livedata.json"); // 30secends will expires, see below. + + // if $livedata not empty and $nocache is 0. means use cache. if (($livedata != "") && (!$nocache)) { # we can parse it faster maybe?! $instantjsondec = json_decode($livedata,true); + switch (json_last_error()) { + case JSON_ERROR_NONE: + echo ' - No errors'; + break; + case JSON_ERROR_DEPTH: + echo ' - Maximum stack depth exceeded'; + break; + case JSON_ERROR_STATE_MISMATCH: + echo ' - Underflow or the modes mismatch'; + break; + case JSON_ERROR_CTRL_CHAR: + echo ' - Unexpected control character found'; + break; + case JSON_ERROR_SYNTAX: + echo ' - Syntax error, malformed JSON'; + break; + case JSON_ERROR_UTF8: + echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'; + break; + default: + echo ' - Unknown error'; + break; + } $phash = $instantjsondec["hashratepretty"]; $roundduration = $instantjsondec["roundduration"]; $sharesperunit = $instantjsondec["sharesperunit"]; @@ -40,10 +65,10 @@ $latestconfirms = $instantjsondec["lastconfirms"]; $datanew = 0; } else { - - $sql = "select pg_try_advisory_lock(1000002) as l"; + $sql = "select pg_try_advisory_lock(1000002) as l"; // return true or false, "t", or "f" $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); $lock = $row["l"]; + if ($lock == "f") { for($t=0;$t<15;$t++) { sleep(2); @@ -71,13 +96,21 @@ # get latest network difficulty from latest accepted share's "bits" field $sql = "select id,(pow(10,((29-$psqlschema.hex_to_int(substr(encode(solution,'hex'),145,2)::varchar))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / $psqlschema.hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where server=$serverid and our_result=true order by id desc limit 1;"; //echo $sql; - $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); - $netdiff = $row["network_difficulty"]; + $result = pg_exec($link, $sql); + + $row = pg_fetch_array($result, 0); + $netdiff = $row["network_difficulty"]; # Get the share id of the last valid block we've found $sql = "select * from (select orig_id,time from $psqlschema.stats_blocks where server=$serverid and confirmations > 0 order by time desc limit 1) as a, (select time+'675 seconds'::interval as satime from $psqlschema.stats_shareagg where server=$serverid order by time desc limit 1) as b;"; - $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); - echo $row; + $result = pg_exec($link, $sql); + + if(pg_num_rows($result) == 0){ + echo "Query didn't return anything"; + //exit; + } + + $row = pg_fetch_array($result, 0); $tempid = $row["orig_id"]; $temptime = $row["time"]; $temptime2 = $row["satime"]; @@ -86,7 +119,7 @@ if ((!($livedataspeedup = apc_fetch("livedata.json - share count from $tempid"))) || ($nocache)){ # no boost for this block yet, lets make it! # this is kind of a kludge, bit should be close enough for the instastats... - $sql = "select (select sum(pow(2,targetmask-32)) from shares where server=$serverid and our_result=true and time > '$temptime' and time < to_timestamp(((date_part('epoch', '$temptime'::timestamp without time zone)::integer / 675) * 675)+675))+(select coalesce(sum(accepted_shares),0) from stats_shareagg where time >= to_timestamp(((date_part('epoch', '$temptime'::timestamp without time zone)::integer / 675) * 675)+675) and server=$serverid)+(select coalesce(sum(pow(2,targetmask-32)),0) from shares where server=$serverid and our_result=true and time > '$temptime2' and time > to_timestamp(((date_part('epoch', '$temptime'::timestamp without time zone)::integer / 675) * 675)+675)) as instcount, (select id from shares where server=$serverid order by id desc limit 1) as latest_id;"; + $sql = "select (select sum(pow(2,targetmask-32)) from shares where server=$serverid and our_result=true and time > '$temptime' and time < to_timestamp(((date_part('epoch', '$temptime'::timestamp without time zone)::integer / 675) * 675)+675))+(select coalesce(sum(accepted_shares),0) from $psqlschema.stats_shareagg where time >= to_timestamp(((date_part('epoch', '$temptime'::timestamp without time zone)::integer / 675) * 675)+675) and server=$serverid)+(select coalesce(sum(pow(2,targetmask-32)),0) from shares where server=$serverid and our_result=true and time > '$temptime2' and time > to_timestamp(((date_part('epoch', '$temptime'::timestamp without time zone)::integer / 675) * 675)+675)) as instcount, (select id from shares where server=$serverid order by id desc limit 1) as latest_id;"; if ($nocache) { print $sql; } $sqlescape = pg_escape_string($link, $sql); $sqlcheck = "select count(*) as check from pg_stat_activity where current_query='$sqlescape'"; @@ -177,7 +210,18 @@ } } - if (!($roundshares > 0)) { $roundshares = 0; } + //if (!($roundshares > 0)) { $roundshares = 0; } + // pay attention to below lines!!!!! debug use! + if (!($roundshares > 0)) { $roundshares = 1; } + + if(!$sharesperunit)$sharesperunit=1; + if(!$blockheight)$blockheight=1; + if(!$latestconfirms)$latestconfirms=0; + if(!$latestconfirms)$latestconfirms=0; + if(!$roundduration)$roundduration=1; + if(!$netdiff)$netdiff=1; + + $tline = "{\"sharesperunit\":$sharesperunit,\"roundsharecount\":$roundshares,\"lastblockheight\":$blockheight,\"lastconfirms\":$latestconfirms,\"roundduration\":$roundduration,\"hashratepretty\":\"$phash\",\"network_difficulty\":$netdiff}"; From f34f877c48160fdb05b1e246dd0798645686f252 Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:29:30 +0800 Subject: [PATCH 04/28] line ends whitespaces striped, modify static json folder to var --- api.php | 8 ++++---- bot.php | 4 ++-- hashrate.php | 2 +- index.php | 11 +++++------ instant.php | 2 +- instantscripts.php | 9 ++++----- mystats.php | 10 +++++----- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/api.php b/api.php index 456998e..9f4f095 100644 --- a/api.php +++ b/api.php @@ -66,11 +66,11 @@ } } if ($format == "text") { header("Content-type: text/plain"); } -if ($format == "csv") { +if ($format == "csv") { if (isset($_GET["csvastext"])) { - header("Content-type: text/plain"); + header("Content-type: text/plain"); } else { - header("Content-type: text/csv"); + header("Content-type: text/csv"); header('Content-Disposition: attachment;filename='.$cmd.'.csv'); } } @@ -198,7 +198,7 @@ $givenuser = "entirepool"; if($cppsrbjsondec = apc_fetch('cppsrb_json')) { } else { - $cppsrbjson = file_get_contents("/var/lib/eligius/$serverid/cppsrb.json"); + $cppsrbjson = file_get_contents("$pooldatadir/$serverid/cppsrb.json"); $cppsrbjsondec = json_decode($cppsrbjson, true); apc_store('cppsrb_json', $cppsrbjsondec, 60); } diff --git a/bot.php b/bot.php index 1a2ee78..0e60dc6 100644 --- a/bot.php +++ b/bot.php @@ -49,7 +49,7 @@ if (isset($_GET["poolhashrate"])) { if($cppsrbjsondec = apc_fetch('cppsrb_json')) { } else { - $cppsrbjson = file_get_contents("/var/lib/eligius/$serverid/cppsrb.json"); + $cppsrbjson = file_get_contents("$pooldatadir/$serverid/cppsrb.json"); $cppsrbjsondec = json_decode($cppsrbjson, true); apc_store('cppsrb_json', $cppsrbjsondec, 60); } @@ -86,7 +86,7 @@ if($cppsrbjsondec = apc_fetch('cppsrb_json')) { } else { - $cppsrbjson = file_get_contents("/var/lib/eligius/$serverid/cppsrb.json"); + $cppsrbjson = file_get_contents("$pooldatadir/$serverid/cppsrb.json"); $cppsrbjsondec = json_decode($cppsrbjson, true); apc_store('cppsrb_json', $cppsrbjsondec, 60); } diff --git a/hashrate.php b/hashrate.php index 14d5aef..f3e4a24 100644 --- a/hashrate.php +++ b/hashrate.php @@ -15,7 +15,7 @@ function add_interval_stats(&$set, $interval, $interval_name, $hashrate, $shares function get_hashrate_stats(&$link, $givenuser, $user_id) { - global $psqlschema, $serverid; + global $psqlschema, $pooldatadir, $serverid; $worker_data = get_worker_data_from_user_id($link, $user_id); $wherein = get_wherein_list_from_worker_data($worker_data); diff --git a/index.php b/index.php index 2cfbc07..58230af 100644 --- a/index.php +++ b/index.php @@ -18,7 +18,6 @@ require_once "includes.php"; #$bodytags = "onLoad=\"initShares();\""; $ldmain = "-main"; - print_stats_top(); $announce = file_get_contents("announce.txt"); @@ -118,16 +117,16 @@ function formatValue(v) {

Top Miners (3 hr rate) (Full)

-

Current network difficulty:
-Current maximum PPS at this difficulty: diff --git a/instant.php b/instant.php index bf175ef..b36022c 100644 --- a/instant.php +++ b/instant.php @@ -59,7 +59,7 @@ exit(); } - $result = pg_execute($link, $prepname, array($cleanvar)); + $result = pg_execute($link, $prepname, array($cleanvar)); $row = pg_fetch_array($result, 0); $dbid = $row["blockid"]; if (isset($_GET["cclass"])) { $cclass = $_GET["cclass"]; } else { $cclass = ""; } diff --git a/instantscripts.php b/instantscripts.php index c04cd9f..55e10f2 100644 --- a/instantscripts.php +++ b/instantscripts.php @@ -31,7 +31,6 @@ $polltimer = 60000; $fullpolltimer = 601000; - print " var intCountShares = $roundshares; var intSharesPerUnit = ($sharesperunit) * 0.02; @@ -95,7 +94,7 @@ function(data){ prettyHashrate = data.hashratepretty; networkDifficulty = data.network_difficulty; networkDifficulty1000 = networkDifficulty * 1000; - + dom_livehashrate.data = prettyHashrate; }); @@ -158,10 +157,10 @@ function initShares() dom_liveluck = document.getElementById('liveluck').childNodes[0]; dom_roundtime = document.getElementById('roundtime').childNodes[0]; dom_sharecounter = document.getElementById('sharecounter').childNodes[0]; - + updateSharesData(); updatePerSecond(); - countShares(); + countShares(); "; if ($main) { print " @@ -190,7 +189,7 @@ function updateBlockTable(timercall) "; if ($main) { print " - $('#blocklisttable tr').each(function(index, elem) { + $('#blocklisttable tr').each(function(index, elem) { if (index>0) { if (\$(elem).attr('id').substring(0,8) == 'blockrow') { var confcell = 'null'; diff --git a/mystats.php b/mystats.php index d72ffa0..2f8bc1a 100644 --- a/mystats.php +++ b/mystats.php @@ -78,7 +78,7 @@ ?>

No address sent for My Stats page


- @@ -121,7 +121,7 @@ if (substr($msg,0,strlen($msghead)) != $msghead) { print "Invalid Message! "; $validate = 0; - } + } $msgdate = substr($msg,strlen($msghead),19); @@ -171,9 +171,9 @@ if ($donatesum < 0) { $donatesum = 0; } $donatesum = "$donatesum%"; - if (($validate) && isset($msgvars_array["Minimum_Work_Diff"]) && ( (filter_var($msgvars_array["Minimum_Work_Diff"], FILTER_VALIDATE_INT) === FALSE) || - ($msgvars_array["Minimum_Work_Diff"] < 1) || - ($msgvars_array["Minimum_Work_Diff"] > 65536) || + if (($validate) && isset($msgvars_array["Minimum_Work_Diff"]) && ( (filter_var($msgvars_array["Minimum_Work_Diff"], FILTER_VALIDATE_INT) === FALSE) || + ($msgvars_array["Minimum_Work_Diff"] < 1) || + ($msgvars_array["Minimum_Work_Diff"] > 65536) || (($msgvars_array["Minimum_Work_Diff"] & ($msgvars_array["Minimum_Work_Diff"]-1)) != 0))) { $validate = 0; print "Invalid minimum difficulty! (Valid values are powers of two: 1,2,4,8,16,32,etc) "; From 79f59009ce7bbec3ff2cc26eb552bfbb210855ad Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:34:00 +0800 Subject: [PATCH 05/28] whitespaces striped --- utils.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/utils.php b/utils.php index c024a98..55eab05 100644 --- a/utils.php +++ b/utils.php @@ -186,7 +186,7 @@ function update_stats_cache($link, $type, $hash, $data, $expireseconds) { } // src: stackoverflow -function format_time($t,$f=':') // t = seconds, f = separator +function format_time($t,$f=':') // t = seconds, f = separator { return sprintf("%02d%s%02d%s%02d", floor($t/3600), $f, ($t/60)%60, $f, $t%60); } @@ -227,7 +227,7 @@ function get_wherein_list_from_worker_data($worker_data) { function get_worker_data_from_user_id($link, $user_id) { - # assume $user_id is the first user_id in the database + # assume $user_id is the first user_id in the database # set a reasonable limit on worker count $query_hash = "wizstats_workerlist ".hash("sha256", "workerlist for id $user_id"); @@ -270,6 +270,8 @@ function get_user_id_from_address($link, $addr) { return $user_id; } else { $bits = hex2bits(\Bitcoin::addressToHash160($addr)); + #echo $bits; + # maybe hint that keyhash is bytea? $sql = "select id from public.users where keyhash='$bits' order by id asc limit 1"; $result = pg_exec($link, $sql); $numrows = pg_numrows($result); @@ -317,8 +319,8 @@ function get_nickname($link, $user_id) { } } - if ($nickname == "No nickname") { - $nickname = ""; + if ($nickname == "No nickname") { + $nickname = ""; } return $nickname; From 0bbbaea559b19d672962f2023a4673c07145664b Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:36:07 +0800 Subject: [PATCH 06/28] keyhas-->username, if no data, or even if we dont know how to generate keyhash, we failted --- utils.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils.php b/utils.php index 55eab05..3844426 100644 --- a/utils.php +++ b/utils.php @@ -272,7 +272,8 @@ function get_user_id_from_address($link, $addr) { $bits = hex2bits(\Bitcoin::addressToHash160($addr)); #echo $bits; # maybe hint that keyhash is bytea? - $sql = "select id from public.users where keyhash='$bits' order by id asc limit 1"; + //$sql = "select id from public.users where keyhash='$bits' order by id asc limit 1"; + $sql = "select id from public.users where username='$addr' order by id asc limit 1"; $result = pg_exec($link, $sql); $numrows = pg_numrows($result); if ($numrows > 0) { From 06bfbba2b4df1b057d9982d8d1c3222681d88209 Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:39:22 +0800 Subject: [PATCH 07/28] add default $firstsharetime, $latestsharetime, when there is nodata, without this, will failed. --- updateshares.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/updateshares.php b/updateshares.php index 614fa8b..128d9bb 100755 --- a/updateshares.php +++ b/updateshares.php @@ -30,8 +30,20 @@ $sql = "select to_timestamp(((date_part('epoch', (select time from wizkid057.stats_shareagg order by time desc limit 1))::integer / 675::integer) * 675::integer)+675::integer) as fst"; $result = pg_exec($link, $sql); -$row = pg_fetch_array($result, 0); -$firstsharetime = $row["fst"]; + +if(pg_num_rows($result) > 0){ + $row = pg_fetch_array($result, 0); + $firstsharetime = $row["fst"]; + echo '$firstsharetime',$firstsharetime; +}else{ + $firstsharetime='2014-04-04 00:18:45+08'; + echo '$firstsharetime default ',$firstsharetime; +} + +if($firstsharetime==''){$firstsharetime='2014-04-04 00:18:45+08';} + +//echo '$latestsharetime',$latestsharetime; +//echo '$firstsharetime',$firstsharetime; # All the work for this is done by postgresql, which is nice, under this query $sql = "INSERT INTO $psqlschema.stats_shareagg (server, time, user_id, accepted_shares, rejected_shares, blocks_found, hashrate) From d3ed9cf6516634a35d7306b3186f36bf922f0e75 Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:41:27 +0800 Subject: [PATCH 08/28] add usernames from shares to users table, before we select data from shares and get user_id from users table again, wtf! --- updateshares.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/updateshares.php b/updateshares.php index 128d9bb..fa8c0c5 100755 --- a/updateshares.php +++ b/updateshares.php @@ -46,6 +46,9 @@ //echo '$firstsharetime',$firstsharetime; # All the work for this is done by postgresql, which is nice, under this query +$sql = "insert into public.users(username) select distinct username from public.shares where username not in (select username from public.users);"; +$result = pg_exec($link, $sql); + $sql = "INSERT INTO $psqlschema.stats_shareagg (server, time, user_id, accepted_shares, rejected_shares, blocks_found, hashrate) select server, to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) AS ttime, user_id, 0+SUM(((our_result::integer) * pow(2,(targetmask-32)))) as acceptedshares, COUNT(*)-SUM(our_result::integer) as rejectedshares, SUM(upstream_result::integer) as blocksfound, From cd9469684e41d04484b7a03a3551300c82f23a1c Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:43:21 +0800 Subject: [PATCH 09/28] add announce.txt --- announce.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 announce.txt diff --git a/announce.txt b/announce.txt new file mode 100644 index 0000000..2344f7d --- /dev/null +++ b/announce.txt @@ -0,0 +1 @@ +Welcome to use wizstats, created by wizkid057. https://github.com/wizkid057/wizstats \ No newline at end of file From d403ea079151396101a3864f70d1b6e5a4605e10 Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:47:08 +0800 Subject: [PATCH 10/28] select users.id as user_id from users table, i didnt know how to select user_id form shares, @wizkid057 didnot give us the shares table schema, if add user_id field to shares table, the eloipool pool server will not fill this field, so i use this method to fix user_id is null or empty. --- updateshares.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/updateshares.php b/updateshares.php index fa8c0c5..95612d4 100755 --- a/updateshares.php +++ b/updateshares.php @@ -54,6 +54,12 @@ 0+SUM(((our_result::integer) * pow(2,(targetmask-32)))) as acceptedshares, COUNT(*)-SUM(our_result::integer) as rejectedshares, SUM(upstream_result::integer) as blocksfound, ((SUM(((our_result::integer) * pow(2,(targetmask-32)))) * 4294967296) / 675) AS hashrate from public.shares where time > '$firstsharetime' and to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) < '$latestsharetime' and server=$serverid group by ttime, server, user_id;"; + +$sql = "INSERT INTO $psqlschema.stats_shareagg (server, time, user_id, accepted_shares, rejected_shares, blocks_found, hashrate) +select server, to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) AS ttime, users.id as user_id, +0+SUM(our_result::integer) as acceptedshares, COUNT(*)-SUM(our_result::integer) as rejectedshares, SUM(upstream_result::integer) as blocksfound, +((SUM(our_result::integer) * POW(2, 32)) / 675) AS hashrate +from public.shares left join users on shares.username=users.username where time > '$firstsharetime' and to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) < '$latestsharetime' and server=$serverid group by ttime, server, users.id;"; $result = pg_exec($link, $sql); unlink( LOCK_FILE ); From 7ff0c09ecb483036f85bbf10bf2895139204ce4c Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:51:12 +0800 Subject: [PATCH 11/28] strip whitespaces at line ends --- updateblocksv2.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/updateblocksv2.php b/updateblocksv2.php index 255b84b..cea41b1 100755 --- a/updateblocksv2.php +++ b/updateblocksv2.php @@ -18,13 +18,14 @@ require_once 'includes.php'; -if( isLocked() ) die( "Already running.\n" ); +if( isLocked() ) die( "Already running.\n" ); $link = pg_Connect("dbname=$psqldb user=$psqluser password='$psqlpass' host=$psqlhost", PGSQL_CONNECT_FORCE_NEW ); $link2 = pg_Connect("dbname=$psqldb user=$psqluser password='$psqlpass' host=$psqlhost", PGSQL_CONNECT_FORCE_NEW ); ### OPTIMIZE THIS TO KNOW WHEN THE LAST BLOCK WAS?! $sql = "INSERT INTO $psqlschema.stats_blocks (server, orig_id, time, user_id, solution, network_difficulty) select server, id, time, user_id, solution, (pow(10,((29-hex_to_int(substr(encode(solution,'hex'),145,2)))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where upstream_result=true and solution NOT IN (select solution from $psqlschema.stats_blocks);"; + $result = pg_exec($link, $sql); $sql = "select * from $psqlschema.stats_blocks where (confirmations < 120 and confirmations > 0) or (blockhash IS NULL) or ((acceptedshares is null or roundstart is null) and (confirmations > 0)) or (confirmations < 120 and time > NOW()-'1 day'::interval) order by time asc"; @@ -183,7 +184,7 @@ if ($rightrejects > 0) { $sql = "update $psqlschema.stats_blocks set rightrejects=$rightrejects where id=$id"; $result2 = pg_exec($link2, $sql); - } + } } @@ -193,6 +194,6 @@ $sql = "delete from $psqlschema.stats_blocks using $psqlschema.stats_blocks sb2 where $psqlschema.stats_blocks.blockhash = sb2.blockhash AND $psqlschema.stats_blocks.id < sb2.id;"; $result = pg_exec($link, $sql); -unlink( LOCK_FILE ); +unlink( LOCK_FILE ); ?> From 1b1d179043ba8d42f855929e5ee3fa011c992647 Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:51:36 +0800 Subject: [PATCH 12/28] if no addr specified, do nothing --- blockinfo.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/blockinfo.php b/blockinfo.php index 489cdbd..91aa15b 100644 --- a/blockinfo.php +++ b/blockinfo.php @@ -2,6 +2,14 @@ require_once 'includes.php'; +if (!isset($_SERVER['PATH_INFO'])) { + print_stats_top(); + print "
Error: No blockhash specified in URL path Please try again.
"; + print_stats_bottom(); + exit; +} + + print_stats_top(); $blockhash = substr($_SERVER["PATH_INFO"],1,64); @@ -149,10 +157,10 @@ if ($block["height"] >= 261279) { # TODO: Make compliant with reward halving - $fees = $total - 2500000000; + $fees = $total - 2500000000; $rf = 0; - if ($fees > 500000000) { - $fees = 500000000; + if ($fees > 500000000) { + $fees = 500000000; $rf = 1; } print "
Block transactions fees put towards share log: ".prettySatoshis($fees)."
"; From f4f9d237aa0b75b9d380b3c85fbe4225d8f4eaaf Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 20:53:09 +0800 Subject: [PATCH 13/28] fix function hex_to_int does not exists, and select user_id from users, which is users.id. --- updateblocksv2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updateblocksv2.php b/updateblocksv2.php index cea41b1..2886f17 100755 --- a/updateblocksv2.php +++ b/updateblocksv2.php @@ -24,7 +24,7 @@ $link2 = pg_Connect("dbname=$psqldb user=$psqluser password='$psqlpass' host=$psqlhost", PGSQL_CONNECT_FORCE_NEW ); ### OPTIMIZE THIS TO KNOW WHEN THE LAST BLOCK WAS?! -$sql = "INSERT INTO $psqlschema.stats_blocks (server, orig_id, time, user_id, solution, network_difficulty) select server, id, time, user_id, solution, (pow(10,((29-hex_to_int(substr(encode(solution,'hex'),145,2)))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where upstream_result=true and solution NOT IN (select solution from $psqlschema.stats_blocks);"; +$sql = "INSERT INTO $psqlschema.stats_blocks (server, orig_id, time, user_id, solution, network_difficulty) select shares.server, shares.id, shares.time, users.id as user_id, shares.solution, (pow(10,((29-$psqlschema.hex_to_int(substr(encode(shares.solution,'hex'),145,2)))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / $psqlschema.hex_to_int(substr(encode(shares.solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares left join users on shares.username= users.username where upstream_result=true and solution NOT IN (select solution from $psqlschema.stats_blocks);"; $result = pg_exec($link, $sql); From b42c321459e6c6f7d631a842d41ffeea5de9de31 Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 21:24:45 +0800 Subject: [PATCH 14/28] add some startup empty files for server id =7, from luke-jr's website. --- 7/balances.json | 1 + 7/balances.json.smpps | 1 + 7/coinbase.txt | 4 ++++ 7/cppsrb.json | 1 + 7/current_block.json | 1 + 7/payout_queue.txt | 0 7/smpps_lastblock.json | 1 + 7 files changed, 9 insertions(+) create mode 100644 7/balances.json create mode 100644 7/balances.json.smpps create mode 100644 7/coinbase.txt create mode 100644 7/cppsrb.json create mode 100644 7/current_block.json create mode 100644 7/payout_queue.txt create mode 100644 7/smpps_lastblock.json diff --git a/7/balances.json b/7/balances.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/7/balances.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/7/balances.json.smpps b/7/balances.json.smpps new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/7/balances.json.smpps @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/7/coinbase.txt b/7/coinbase.txt new file mode 100644 index 0000000..a49181f --- /dev/null +++ b/7/coinbase.txt @@ -0,0 +1,4 @@ +0 +# 0 BTC to 0 address(es) (0 for 0 given by CPPSRB) +# CPPSRB provided prevblockhash of +# eloipool provided prevblockhash of diff --git a/7/cppsrb.json b/7/cppsrb.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/7/cppsrb.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/7/current_block.json b/7/current_block.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/7/current_block.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/7/payout_queue.txt b/7/payout_queue.txt new file mode 100644 index 0000000..e69de29 diff --git a/7/smpps_lastblock.json b/7/smpps_lastblock.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/7/smpps_lastblock.json @@ -0,0 +1 @@ +{} \ No newline at end of file From 04040f3abb0d933b6a0c9abe89fb3a799dc050c3 Mon Sep 17 00:00:00 2001 From: encorehu Date: Mon, 7 Apr 2014 23:35:59 +0800 Subject: [PATCH 15/28] [for postgresql 9.2 or later]fix Query failed: ERROR: column "current_query" does not exist LINE 1: ...ect count(*) as check from pg_stat_activity where current_qu... ^ in instant_livedata.php on line 127 --- instant_livedata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instant_livedata.php b/instant_livedata.php index ddca9b9..c47ae93 100644 --- a/instant_livedata.php +++ b/instant_livedata.php @@ -122,7 +122,7 @@ $sql = "select (select sum(pow(2,targetmask-32)) from shares where server=$serverid and our_result=true and time > '$temptime' and time < to_timestamp(((date_part('epoch', '$temptime'::timestamp without time zone)::integer / 675) * 675)+675))+(select coalesce(sum(accepted_shares),0) from $psqlschema.stats_shareagg where time >= to_timestamp(((date_part('epoch', '$temptime'::timestamp without time zone)::integer / 675) * 675)+675) and server=$serverid)+(select coalesce(sum(pow(2,targetmask-32)),0) from shares where server=$serverid and our_result=true and time > '$temptime2' and time > to_timestamp(((date_part('epoch', '$temptime'::timestamp without time zone)::integer / 675) * 675)+675)) as instcount, (select id from shares where server=$serverid order by id desc limit 1) as latest_id;"; if ($nocache) { print $sql; } $sqlescape = pg_escape_string($link, $sql); - $sqlcheck = "select count(*) as check from pg_stat_activity where current_query='$sqlescape'"; + $sqlcheck = "select count(*) as check from pg_stat_activity where query='$sqlescape'"; $result = pg_exec($link, $sqlcheck); $row = pg_fetch_array($result, 0); $runningqueries = $row["check"]; $fetch = 1; From 72ab8f6611c4fa6caaee976732d60f4befc025d5 Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 10:16:35 +0800 Subject: [PATCH 16/28] remove json error none output --- instant_livedata.php | 1 - 1 file changed, 1 deletion(-) diff --git a/instant_livedata.php b/instant_livedata.php index c47ae93..5ae6165 100644 --- a/instant_livedata.php +++ b/instant_livedata.php @@ -35,7 +35,6 @@ switch (json_last_error()) { case JSON_ERROR_NONE: - echo ' - No errors'; break; case JSON_ERROR_DEPTH: echo ' - Maximum stack depth exceeded'; From c0cc1a176fa988a548c8a9425279152e6699ba18 Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 10:49:54 +0800 Subject: [PATCH 17/28] if nodata in shares, do not set $tline --- instant_livedata.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/instant_livedata.php b/instant_livedata.php index 5ae6165..08f44e1 100644 --- a/instant_livedata.php +++ b/instant_livedata.php @@ -96,6 +96,11 @@ $sql = "select id,(pow(10,((29-$psqlschema.hex_to_int(substr(encode(solution,'hex'),145,2)::varchar))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / $psqlschema.hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where server=$serverid and our_result=true order by id desc limit 1;"; //echo $sql; $result = pg_exec($link, $sql); + if(pg_num_rows($result) == 0){ + # Error! there is nodata in shares table + $tline = "{\"error\":\"Could not retrieve live stats, No data in shares table\"}\n"; + } else { + $row = pg_fetch_array($result, 0); @@ -103,12 +108,6 @@ # Get the share id of the last valid block we've found $sql = "select * from (select orig_id,time from $psqlschema.stats_blocks where server=$serverid and confirmations > 0 order by time desc limit 1) as a, (select time+'675 seconds'::interval as satime from $psqlschema.stats_shareagg where server=$serverid order by time desc limit 1) as b;"; $result = pg_exec($link, $sql); - - if(pg_num_rows($result) == 0){ - echo "Query didn't return anything"; - //exit; - } - $row = pg_fetch_array($result, 0); $tempid = $row["orig_id"]; $temptime = $row["time"]; @@ -206,6 +205,7 @@ $datanew = 1; $sql = "select pg_advisory_unlock(1000002) as l"; $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); + } // nodata in shares } } From a70b8b517084eeff7ffe20e94c3420787184fe6e Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 11:06:41 +0800 Subject: [PATCH 18/28] if nodata, set default values --- instant_livedata.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/instant_livedata.php b/instant_livedata.php index 08f44e1..e9c8da9 100644 --- a/instant_livedata.php +++ b/instant_livedata.php @@ -27,6 +27,19 @@ $livedata = get_stats_cache($link, 5, "livedata.json"); // 30secends will expires, see below. + # if nodata in database, set default values, to fix many Notice: Undefined variable... + # the risk is may cause something wrong, may the calculate is not right + $roundshares = 0; + $sharesperunit=1; + $blockheight=1; + $latestconfirms=0; + $latestconfirms=0; + $roundduration=1; + $netdiff=1; + + $datanew = 0; + $phash = ""; + // if $livedata not empty and $nocache is 0. means use cache. if (($livedata != "") && (!$nocache)) { # we can parse it faster maybe?! @@ -70,6 +83,8 @@ if ($lock == "f") { for($t=0;$t<15;$t++) { + // this will cost 30 seconds, if max_execution_time = 30 + // in php.ini, this loop will failed sleep(2); $livedata = get_stats_cache($link, 5, "livedata.json"); if ($livedata != "") { From 6db9e519808845b83cf3b57d766fc2a23b04345a Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 11:15:49 +0800 Subject: [PATCH 19/28] catch nodata in shats_shareagg table error --- topcontributors.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/topcontributors.php b/topcontributors.php index 6294c6b..cb78b59 100644 --- a/topcontributors.php +++ b/topcontributors.php @@ -42,7 +42,12 @@ # get total pool hashrate $sql = "select to_timestamp((date_part('epoch', (time))::integer / 675::integer)::integer * 675::integer)-'3 hours'::interval as stime from $psqlschema.stats_shareagg where server=$serverid group by server,time order by time desc limit 1"; - $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); + $result = pg_exec($link, $sql); + if(pg_num_rows($result) == 0){ + echo "there is no data in ".$psqlschema."stats_shareagg"; + } else { + + $row = pg_fetch_array($result, 0); $stime = $row["stime"]; $sql = "select (sum(accepted_shares)*pow(2,32))/10800 as avghash from $psqlschema.stats_shareagg where server=$serverid and time > '$stime'::timestamp without time zone"; @@ -50,6 +55,7 @@ $poolhashrate3hr = $row["avghash"]; + $sql = "select (sum(accepted_shares)*pow(2,32))/10800 as avghash, sum(accepted_shares) as sharecount, keyhash, min(users.id) as user_id from $psqlschema.stats_shareagg left join users on user_id=users.id where server=$serverid and time > '$stime'::timestamp without time zone and accepted_shares > 0 group by keyhash order by avghash desc $minilimit;"; $result = pg_exec($link, $sql); $numrows = pg_numrows($result); @@ -95,7 +101,9 @@ } $pdata .= ""; set_stats_cache($link, 20, $cachehash, $pdata, 675); + print $pdata; + } # nodata in stats_shareagg } From 2dd97f23031169deda965f1c4f06362e64c748fa Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 14:22:27 +0800 Subject: [PATCH 20/28] strip whitespaces --- blocks_functions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/blocks_functions.php b/blocks_functions.php index 01d9317..ce1f3e5 100644 --- a/blocks_functions.php +++ b/blocks_functions.php @@ -66,13 +66,13 @@ function block_table_row($row,$isodd) { $dbid = $row["blockid"]; - if ($row["confirmations"] == 0) { - $blocks_row .= ""; + if ($row["confirmations"] == 0) { + $blocks_row .= ""; } - else if ($row["confirmations"] >= 120) { - $blocks_row .= ""; + else if ($row["confirmations"] >= 120) { + $blocks_row .= ""; } - else { + else { $rowcolour = $isodd ? array(0xd3, 0xeb, 0xe3) : array(0xeb, 0xed, 0xe9); $uccolour = array(0xff, 0x7f, 0); $rowcolour = blend_colours($uccolour, $rowcolour, $row["confirmations"] / 120); @@ -122,7 +122,7 @@ function block_table_row($row,$isodd) { $address = substr($fulladdress,0,10)."..."; } else { $fulladdress = ""; - $address = "(Unknown user)"; + $address = "(Unknown user)"; } $blocks_row .= "".$address.""; From 9bd2b0288c9e9606269593fbd8888352471d19a0 Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 14:23:15 +0800 Subject: [PATCH 21/28] if unset $row["duration"], Notice: Undefined variable: hashratenum in blocks_functions.php on line 112 --- blocks_functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/blocks_functions.php b/blocks_functions.php index ce1f3e5..16256bc 100644 --- a/blocks_functions.php +++ b/blocks_functions.php @@ -102,6 +102,7 @@ function block_table_row($row,$isodd) { } else { $blocks_row .= "n/a"; $hashrate = "n/a"; + $hashratenum = 0; } $blocks_row .= "".($row["acceptedshares"]>0?number_format($row["acceptedshares"]):"n/a").""; From 9e08fade236d1d23be3e214fa412b084c41f1bb9 Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 16:28:32 +0800 Subject: [PATCH 22/28] limit blocks for debug --- blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks.php b/blocks.php index 5060ffe..b1e50a4 100644 --- a/blocks.php +++ b/blocks.php @@ -46,7 +46,7 @@ if (isset($blocklimit)) { $blim = "limit $blocklimit"; } else { - $blim = ""; + $blim = "limit 10"; print "Click on a header item to sort the list

"; } From a946f5366f47faa7e5f5455a94e9c2611167ef73 Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 21:02:47 +0800 Subject: [PATCH 23/28] update .gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 30347c4..1f8cd7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ config.php old/ *.old - +*.prj +*.pui +*.doc +*.cmd From c7ec4adc6670338c29853fb723c0f1ef91582c37 Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 21:22:35 +0800 Subject: [PATCH 24/28] Query failed: ERROR: function hex_to_int(text) does not exist LINE 1: select id,(pow(10,((29-hex_to_int(substr(encode(solution,'he... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. in userstats.php on line 570 --- userstats.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/userstats.php b/userstats.php index 2d476d5..aaa35ed 100644 --- a/userstats.php +++ b/userstats.php @@ -566,7 +566,7 @@ } if ($u16avghash > 0) { - $sql = "select id,(pow(10,((29-hex_to_int(substr(encode(solution,'hex'),145,2)))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where server=$serverid and our_result=true order by id desc limit 1;"; + $sql = "select id,(pow(10,((29-$psqlschema.hex_to_int(substr(encode(solution,'hex'),145,2)))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / $psqlschema.hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where server=$serverid and our_result=true order by id desc limit 1;"; $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); $netdiff = $row["network_difficulty"]; @@ -618,7 +618,7 @@ if ($u16avghash > 0) { if (!isset($netdiff)) { - $sql = "select id,(pow(10,((29-hex_to_int(substr(encode(solution,'hex'),145,2)))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where server=$serverid and our_result=true order by id desc limit 1;"; + $sql = "select id,(pow(10,((29-$psqlschema.hex_to_int(substr(encode(solution,'hex'),145,2)))::double precision*2.4082399653118495617099111577959::double precision)+log( (65535::double precision / $psqlschema.hex_to_int(substr(encode(solution,'hex'),147,6)))::double precision )::double precision))::double precision as network_difficulty from shares where server=$serverid and our_result=true order by id desc limit 1;"; $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); $netdiff = $row["network_difficulty"]; } From 30c2f8939f5657d22786cc401a932993e0da4881 Mon Sep 17 00:00:00 2001 From: encorehu Date: Tue, 8 Apr 2014 21:32:40 +0800 Subject: [PATCH 25/28] debug get_worker_data_from_user_id, workername --- utils.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/utils.php b/utils.php index 3844426..a3f47a3 100644 --- a/utils.php +++ b/utils.php @@ -236,19 +236,26 @@ function get_worker_data_from_user_id($link, $user_id) { return $worker_data; } else { - $sql = "select * from public.users where keyhash=(select keyhash from public.users where id=$user_id) order by id asc limit 128"; + //$sql = "select * from public.users where keyhash=(select keyhash from public.users where id=$user_id) order by id asc limit 128"; + $sql = "select * from public.users where id=$user_id order by id asc limit 128"; $result = pg_exec($link, $sql); $numrows = pg_numrows($result); if ($numrows > 0) { + echo '$numrows:',$numrows,'
'; # should always be at least 1... $worker_data = array(); for($ri=0;$ri<$numrows;$ri++) { $row = pg_fetch_array($result, $ri); - if (strlen($row["workername"]) > 0) { - $wname = $row["workername"]; + $username = $row["username"]; + $warray=explode("_", $username, 2); + if (count($warray) > 1) { + list($username,$wname) = $warray; } else { $wname = "default"; } + if(strlen($wname) == 0){ + $wname = "default"; + } $worker_data[$row["id"]] = $wname; } apc_store($query_hash, $worker_data, 300); From 1b7ca0804032dd4a432f173f4d72f1f0a91d25ed Mon Sep 17 00:00:00 2001 From: encorehu Date: Wed, 9 Apr 2014 18:12:39 +0800 Subject: [PATCH 26/28] to_timestamp() returns a TIMESTAMP WITH TIME ZONE, which not compared to stats_sharesagg.time(time without time zone) --- updateshares.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/updateshares.php b/updateshares.php index 95612d4..ca6d66f 100755 --- a/updateshares.php +++ b/updateshares.php @@ -34,16 +34,14 @@ if(pg_num_rows($result) > 0){ $row = pg_fetch_array($result, 0); $firstsharetime = $row["fst"]; - echo '$firstsharetime',$firstsharetime; }else{ $firstsharetime='2014-04-04 00:18:45+08'; - echo '$firstsharetime default ',$firstsharetime; } if($firstsharetime==''){$firstsharetime='2014-04-04 00:18:45+08';} -//echo '$latestsharetime',$latestsharetime; -//echo '$firstsharetime',$firstsharetime; +echo '$latestsharetime',$latestsharetime; +echo '$firstsharetime',$firstsharetime; # All the work for this is done by postgresql, which is nice, under this query $sql = "insert into public.users(username) select distinct username from public.shares where username not in (select username from public.users);"; @@ -56,7 +54,7 @@ from public.shares where time > '$firstsharetime' and to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) < '$latestsharetime' and server=$serverid group by ttime, server, user_id;"; $sql = "INSERT INTO $psqlschema.stats_shareagg (server, time, user_id, accepted_shares, rejected_shares, blocks_found, hashrate) -select server, to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) AS ttime, users.id as user_id, +select server, to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer)::timestamp without time zone AS ttime, users.id as user_id, 0+SUM(our_result::integer) as acceptedshares, COUNT(*)-SUM(our_result::integer) as rejectedshares, SUM(upstream_result::integer) as blocksfound, ((SUM(our_result::integer) * POW(2, 32)) / 675) AS hashrate from public.shares left join users on shares.username=users.username where time > '$firstsharetime' and to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) < '$latestsharetime' and server=$serverid group by ttime, server, users.id;"; From 206adad69277f42aa02c5f650d49ceb861cbe30b Mon Sep 17 00:00:00 2001 From: encorehu Date: Thu, 10 Apr 2014 11:17:24 +0800 Subject: [PATCH 27/28] fix timezone of to_timestamp function --- updateshares.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/updateshares.php b/updateshares.php index ca6d66f..aa01165 100755 --- a/updateshares.php +++ b/updateshares.php @@ -23,12 +23,12 @@ $link = pg_Connect("dbname=$psqldb user=$psqluser password='$psqlpass' host=$psqlhost", PGSQL_CONNECT_FORCE_NEW ); -$sql = "select to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) as lst from public.shares where server=$serverid order by id desc limit 1"; +$sql = "select to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) at time zone 'UTC' as lst from public.shares where server=$serverid order by id desc limit 1"; $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); $latestsharetime = $row["lst"]; -$sql = "select to_timestamp(((date_part('epoch', (select time from wizkid057.stats_shareagg order by time desc limit 1))::integer / 675::integer) * 675::integer)+675::integer) as fst"; +$sql = "select to_timestamp(((date_part('epoch', (select time from wizkid057.stats_shareagg order by time desc limit 1))::integer / 675::integer) * 675::integer)+675::integer) at time zone 'UTC' as fst"; $result = pg_exec($link, $sql); if(pg_num_rows($result) > 0){ From 5fc5904c66b870eaa78cfc3928f240a2a22e8ef4 Mon Sep 17 00:00:00 2001 From: encorehu Date: Thu, 10 Apr 2014 17:53:58 +0800 Subject: [PATCH 28/28] to_timestamp()::timestamp without time zone ->to_timestamp() at time zone 'UTC' --- updateshares.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/updateshares.php b/updateshares.php index aa01165..11a91d0 100755 --- a/updateshares.php +++ b/updateshares.php @@ -54,10 +54,10 @@ from public.shares where time > '$firstsharetime' and to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) < '$latestsharetime' and server=$serverid group by ttime, server, user_id;"; $sql = "INSERT INTO $psqlschema.stats_shareagg (server, time, user_id, accepted_shares, rejected_shares, blocks_found, hashrate) -select server, to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer)::timestamp without time zone AS ttime, users.id as user_id, +select server, to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) at time zone 'UTC' AS ttime, users.id as user_id, 0+SUM(our_result::integer) as acceptedshares, COUNT(*)-SUM(our_result::integer) as rejectedshares, SUM(upstream_result::integer) as blocksfound, ((SUM(our_result::integer) * POW(2, 32)) / 675) AS hashrate -from public.shares left join users on shares.username=users.username where time > '$firstsharetime' and to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) < '$latestsharetime' and server=$serverid group by ttime, server, users.id;"; +from public.shares left join users on shares.username=users.username where time > '$firstsharetime' and to_timestamp((date_part('epoch', time)::integer / 675::integer) * 675::integer) at time zone 'UTC' < '$latestsharetime' and server=$serverid group by ttime, server, users.id;"; $result = pg_exec($link, $sql); unlink( LOCK_FILE );