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 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 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 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/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)."
"; 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

"; } diff --git a/blocks_functions.php b/blocks_functions.php index 01d9317..16256bc 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); @@ -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").""; @@ -122,7 +123,7 @@ function block_table_row($row,$isodd) { $address = substr($fulladdress,0,10)."..."; } else { $fulladdress = ""; - $address = "(Unknown user)"; + $address = "(Unknown user)"; } $blocks_row .= "".$address.""; 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 f1378c5..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); @@ -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/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/instant_livedata.php b/instant_livedata.php index fa5eebb..e9c8da9 100644 --- a/instant_livedata.php +++ b/instant_livedata.php @@ -21,14 +21,53 @@ # 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"); + $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?! $instantjsondec = json_decode($livedata,true); + switch (json_last_error()) { + case JSON_ERROR_NONE: + 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"]; @@ -38,12 +77,14 @@ $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++) { + // 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 != "") { @@ -67,13 +108,22 @@ # 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;"; - $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); - $netdiff = $row["network_difficulty"]; + $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); + + $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); $tempid = $row["orig_id"]; $temptime = $row["time"]; $temptime2 = $row["satime"]; @@ -82,10 +132,10 @@ 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'"; + $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; @@ -132,8 +182,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; @@ -170,10 +220,22 @@ $datanew = 1; $sql = "select pg_advisory_unlock(1000002) as l"; $result = pg_exec($link, $sql); $row = pg_fetch_array($result, 0); + } // nodata in shares } } - 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}"; 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/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/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) "; 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/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 } 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/updateblocksv2.php b/updateblocksv2.php index 255b84b..2886f17 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);"; +$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); $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 ); ?> diff --git a/updateshares.php b/updateshares.php index 614fa8b..11a91d0 100755 --- a/updateshares.php +++ b/updateshares.php @@ -23,22 +23,41 @@ $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); -$row = pg_fetch_array($result, 0); -$firstsharetime = $row["fst"]; + +if(pg_num_rows($result) > 0){ + $row = pg_fetch_array($result, 0); + $firstsharetime = $row["fst"]; +}else{ + $firstsharetime='2014-04-04 00:18:45+08'; +} + +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 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, ((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) 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) at time zone 'UTC' < '$latestsharetime' and server=$serverid group by ttime, server, users.id;"; $result = pg_exec($link, $sql); unlink( LOCK_FILE ); 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..aaa35ed 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 ""; @@ -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"]; } diff --git a/utils.php b/utils.php index c024a98..a3f47a3 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"); @@ -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); @@ -270,7 +277,10 @@ function get_user_id_from_address($link, $addr) { return $user_id; } else { $bits = hex2bits(\Bitcoin::addressToHash160($addr)); - $sql = "select id from public.users where keyhash='$bits' order by id asc limit 1"; + #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 username='$addr' order by id asc limit 1"; $result = pg_exec($link, $sql); $numrows = pg_numrows($result); if ($numrows > 0) { @@ -317,8 +327,8 @@ function get_nickname($link, $user_id) { } } - if ($nickname == "No nickname") { - $nickname = ""; + if ($nickname == "No nickname") { + $nickname = ""; } return $nickname;