Merge pull request #981 from Fredyy90/next

3 small improvments
This commit is contained in:
Sebastian Grewe 2013-12-17 00:10:09 -08:00
commit 405fd3d9e0
14 changed files with 349 additions and 11 deletions

11
.gitignore vendored
View File

@ -1,8 +1,17 @@
# Local Config
/public/include/config/global.inc.php
# Templates
/public/templates/compile/*.php
/public/templates/cache/*.php
# Logs
/cronjobs/logs/*.txt
/cronjobs/logs/*.txt.*.gz
/public/templates/cache/*.php
# Test configs
public/include/config/global.inc.scrypt.php
public/include/config/global.inc.sha.php
# IDE Settings
/.idea/*

126
cronjobs/run-maintenance.sh Normal file
View File

@ -0,0 +1,126 @@
#!/bin/bash
#########################
# #
# Configuration Options #
# #
#########################
# PHP Detections, if this fails hard code it
PHP_BIN=$( which php )
# List of cruns to execute
CRONS="tickerupdate.php notifications.php statistics.php archive_cleanup.php"
# Output additional runtime information
VERBOSE="1"
# Base path for PIDFILE, (full path).
BASEPATH="/tmp"
# Subfolder for PIDFILE, so it's path will be unique in a multipool server.
# Path relative to BASEPATH.
# Eg. SUBFOLDER="LTC"
SUBFOLDER=""
################################################################
# #
# You probably don't need to change anything beyond this point #
# #
################################################################
# Mac OS detection
OS=`uname`
case "$OS" in
Darwin) READLINK=$( which greadlink ) ;;
*) READLINK=$( which readlink ) ;;
esac
if [[ ! -x $READLINK ]]; then
echo "readlink not found, please install first";
exit 1;
fi
# My own name
ME=$( basename $0 )
# Overwrite some settings via command line arguments
while getopts "hfvp:d:" opt; do
case "$opt" in
h|\?)
echo "Usage: $0 [-v] [-p PHP_BINARY] [-d SUBFOLDER]";
exit 0
;;
v) VERBOSE=1 ;;
f) PHP_OPTS="$PHP_OPTS -f";;
p) PHP_BIN=$OPTARG ;;
d) SUBFOLDER=$OPTARG ;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Path to PID file, needs to be writable by user running this
PIDFILE="${BASEPATH}/${SUBFOLDER}/${ME}.pid"
# Clean PIDFILE path
PIDFILE=$($READLINK -m "$PIDFILE")
# Create folders recursively if necessary
if ! $(mkdir -p $( dirname $PIDFILE)); then
echo "Error creating PIDFILE path: $( dirname $PIDFILE )"
exit 1
fi
# Find scripts path
if [[ -L $0 ]]; then
CRONHOME=$( dirname $( $READLINK $0 ) )
else
CRONHOME=$( dirname $0 )
fi
# Change working director to CRONHOME
if ! cd $CRONHOME 2>/dev/null; then
echo "Unable to change to working directory \$CRONHOME: $CRONHOME"
exit 1
fi
# Confiuration checks
if [[ -z $PHP_BIN || ! -x $PHP_BIN ]]; then
echo "Unable to locate you php binary."
exit 1
fi
if [[ ! -e 'shared.inc.php' ]]; then
echo "Not in cronjobs folder, please ensure \$CRONHOME is set!"
exit 1
fi
# Our PID of this shell
PID=$$
if [[ -e $PIDFILE ]]; then
echo "Cron seems to be running already"
RUNPID=$( cat $PIDFILE )
if ps fax | grep -q "^\<$RUNPID\>"; then
echo "Process found in process table, aborting"
exit 1
else
echo "Process $RUNPID not found. Plese remove $PIDFILE if process is indeed dead."
exit 1
fi
fi
# Write our PID file
echo $PID > $PIDFILE
for cron in $CRONS; do
[[ $VERBOSE == 1 ]] && echo "Running $cron, check logfile for details"
$PHP_BIN $cron $PHP_OPTS
done
# Remove pidfile
rm -f $PIDFILE

126
cronjobs/run-payout.sh Normal file
View File

@ -0,0 +1,126 @@
#!/bin/bash
#########################
# #
# Configuration Options #
# #
#########################
# PHP Detections, if this fails hard code it
PHP_BIN=$( which php )
# List of cruns to execute
CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php"
# Output additional runtime information
VERBOSE="1"
# Base path for PIDFILE, (full path).
BASEPATH="/tmp"
# Subfolder for PIDFILE, so it's path will be unique in a multipool server.
# Path relative to BASEPATH.
# Eg. SUBFOLDER="LTC"
SUBFOLDER=""
################################################################
# #
# You probably don't need to change anything beyond this point #
# #
################################################################
# Mac OS detection
OS=`uname`
case "$OS" in
Darwin) READLINK=$( which greadlink ) ;;
*) READLINK=$( which readlink ) ;;
esac
if [[ ! -x $READLINK ]]; then
echo "readlink not found, please install first";
exit 1;
fi
# My own name
ME=$( basename $0 )
# Overwrite some settings via command line arguments
while getopts "hfvp:d:" opt; do
case "$opt" in
h|\?)
echo "Usage: $0 [-v] [-p PHP_BINARY] [-d SUBFOLDER]";
exit 0
;;
v) VERBOSE=1 ;;
f) PHP_OPTS="$PHP_OPTS -f";;
p) PHP_BIN=$OPTARG ;;
d) SUBFOLDER=$OPTARG ;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Path to PID file, needs to be writable by user running this
PIDFILE="${BASEPATH}/${SUBFOLDER}/${ME}.pid"
# Clean PIDFILE path
PIDFILE=$($READLINK -m "$PIDFILE")
# Create folders recursively if necessary
if ! $(mkdir -p $( dirname $PIDFILE)); then
echo "Error creating PIDFILE path: $( dirname $PIDFILE )"
exit 1
fi
# Find scripts path
if [[ -L $0 ]]; then
CRONHOME=$( dirname $( $READLINK $0 ) )
else
CRONHOME=$( dirname $0 )
fi
# Change working director to CRONHOME
if ! cd $CRONHOME 2>/dev/null; then
echo "Unable to change to working directory \$CRONHOME: $CRONHOME"
exit 1
fi
# Confiuration checks
if [[ -z $PHP_BIN || ! -x $PHP_BIN ]]; then
echo "Unable to locate you php binary."
exit 1
fi
if [[ ! -e 'shared.inc.php' ]]; then
echo "Not in cronjobs folder, please ensure \$CRONHOME is set!"
exit 1
fi
# Our PID of this shell
PID=$$
if [[ -e $PIDFILE ]]; then
echo "Cron seems to be running already"
RUNPID=$( cat $PIDFILE )
if ps fax | grep -q "^\<$RUNPID\>"; then
echo "Process found in process table, aborting"
exit 1
else
echo "Process $RUNPID not found. Plese remove $PIDFILE if process is indeed dead."
exit 1
fi
fi
# Write our PID file
echo $PID > $PIDFILE
for cron in $CRONS; do
[[ $VERBOSE == 1 ]] && echo "Running $cron, check logfile for details"
$PHP_BIN $cron $PHP_OPTS
done
# Remove pidfile
rm -f $PIDFILE

View File

@ -800,6 +800,41 @@ class Statistics extends Base {
public function getEstimatedShares($dDiff) {
return round((POW(2, (32 - $this->config['target_bits'])) * $dDiff) / pow(2, ($this->config['difficulty'] - 16)));
}
/**
* Get the Expected Time per Block in the whole Network in seconde
* @return seconds double Seconds per Block
*/
public function getNetworkExpectedTimePerBlock(){
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
if ($this->bitcoin->can_connect() === true) {
$dNetworkHashrate = $this->bitcoin->getnetworkhashps();
$dDifficulty = $this->bitcoin->getdifficulty();
} else {
$dNetworkHashrate = 0;
$dDifficulty = 1;
}
return pow(2, 32) * $dDifficulty / $dNetworkHashrate;
}
/**
* Get the Expected next Difficulty
* @return difficulty double Next difficulty
*/
public function getExpectedNextDifficulty(){
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
if ($this->bitcoin->can_connect() === true) {
$dDifficulty = $this->bitcoin->getdifficulty();
} else {
$dDifficulty = 1;
}
return round($dDifficulty * $this->config['cointarget'] / $this->getNetworkExpectedTimePerBlock(), 8);
}
}
$statistics = new Statistics();
@ -810,6 +845,7 @@ $statistics->setUser($user);
$statistics->setBlock($block);
$statistics->setMemcache($memcache);
$statistics->setConfig($config);
$statistics->setBitcoin($bitcoin);
$statistics->setErrorCodes($aErrorCodes);
?>

View File

@ -104,9 +104,12 @@ if ($iEstShares > 0 && $aRoundShares['valid'] > 0) {
$dEstPercent = 0;
}
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
// Output JSON format
$data = array(
'raw' => array( 'personal' => array( 'hashrate' => $dPersonalHashrate ), 'pool' => array( 'hashrate' => $dPoolHashrate ), 'network' => array( 'hashrate' => $dNetworkHashrate / 1000 ) ),
'raw' => array( 'personal' => array( 'hashrate' => $dPersonalHashrate ), 'pool' => array( 'hashrate' => $dPoolHashrate ), 'network' => array( 'hashrate' => $dNetworkHashrate / 1000, 'esttimeperblock' => $dExpectedTimePerBlock, 'nextdifficulty' => $dEstNextDifficulty ) ),
'personal' => array (
'hashrate' => $dPersonalHashrateAdjusted, 'sharerate' => $dPersonalSharerate, 'sharedifficulty' => $dPersonalShareDifficulty,
'shares' => array('valid' => $aUserRoundShares['valid'], 'invalid' => $aUserRoundShares['invalid'], 'invalid_percent' => $dUserInvalidPercent, 'unpaid' => $dUnpaidShares ),
@ -123,7 +126,7 @@ $data = array(
'target_bits' => $config['difficulty']
),
'system' => array( 'load' => sys_getloadavg() ),
'network' => array( 'hashrate' => $dNetworkHashrateAdjusted, 'difficulty' => $dDifficulty, 'block' => $iBlock ),
'network' => array( 'hashrate' => $dNetworkHashrateAdjusted, 'difficulty' => $dDifficulty, 'block' => $iBlock, 'esttimeperblock' => round($dExpectedTimePerBlock ,2), 'nextdifficulty' => $dEstNextDifficulty ),
);
echo $api->get_json($data);

View File

@ -35,11 +35,14 @@ if ($user->isAuthenticated()) {
// Avoid confusion, ensure our nethash isn't higher than poolhash
if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate;
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
// Make it available in Smarty
$smarty->assign('DISABLED_DASHBOARD', $setting->getValue('disable_dashboard'));
$smarty->assign('DISABLED_DASHBOARD_API', $setting->getValue('disable_dashboard_api'));
$smarty->assign('ESTIMATES', array('shares' => $iEstShares, 'percent' => $dEstPercent));
$smarty->assign('NETWORK', array('difficulty' => $dDifficulty, 'block' => $iBlock));
$smarty->assign('NETWORK', array('difficulty' => $dDifficulty, 'block' => $iBlock, 'EstNextDifficulty' => $dEstNextDifficulty, 'EstTimePerBlock' => $dExpectedTimePerBlock));
$smarty->assign('INTERVAL', $interval / 60);
$smarty->assign('CONTENT', 'default.tpl');
}

View File

@ -8,10 +8,12 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
// Fetch data from wallet
if ($bitcoin->can_connect() === true){
$dDifficulty = $bitcoin->getdifficulty();
$dNetworkHashrate = $bitcoin->getnetworkhashps();
$iBlock = $bitcoin->getblockcount();
is_int($iBlock) && $iBlock > 0 ? $sBlockHash = $bitcoin->query('getblockhash', $iBlock) : $sBlockHash = '';
} else {
$dDifficulty = 1;
$dNetworkHashrate = 1;
$iBlock = 0;
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
}
@ -50,6 +52,9 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$dEstPercent = 0;
}
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
// Propagate content our template
$smarty->assign("ESTTIME", $iEstTime);
$smarty->assign("TIMESINCELAST", $dTimeSinceLast);
@ -59,7 +64,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$smarty->assign("CONTRIBHASHES", $aContributorsHashes);
$smarty->assign("CURRENTBLOCK", $iBlock);
$smarty->assign("CURRENTBLOCKHASH", @$sBlockHash);
$smarty->assign('NETWORK', array('difficulty' => $dDifficulty, 'block' => $iBlock));
$smarty->assign('NETWORK', array('difficulty' => $dDifficulty, 'block' => $iBlock, 'EstNextDifficulty' => $dEstNextDifficulty, 'EstTimePerBlock' => $dExpectedTimePerBlock));
$smarty->assign('ESTIMATES', array('shares' => $iEstShares, 'percent' => $dEstPercent));
if (count($aBlockData) > 0) {
$smarty->assign("LASTBLOCK", $aBlockData['height']);

View File

@ -30,11 +30,19 @@
{if ! $GLOBAL.website.chaininfo.disabled}
<tr>
<td class="leftheader">Current Difficulty</td>
<td colspan="4"><a href="{$GLOBAL.website.chaininfo.url}" target="_new"><font size="2">{$DIFFICULTY}</font></a></td>
<td colspan="4"><a href="{$GLOBAL.website.chaininfo.url}" target="_new">{$DIFFICULTY}</a></td>
</tr>
<tr>
<td class="leftheader">Est. Next Difficulty</td>
<td colspan="4"><a href="{$GLOBAL.website.chaininfo.url}" target="_new">{$NETWORK.EstNextDifficulty}</a></td>
</tr>
{/if}
<tr>
<td class="leftheader">Est. Avg. Time per Round</td>
<td class="leftheader">Est. Avg. Time per Round (Network)</td>
<td colspan="4">{$NETWORK.ExpectedTimePerBlock|seconds_to_words}</td>
</tr>
<tr>
<td class="leftheader">Est. Avg. Time per Round (Pool)</td>
<td colspan="4">{$ESTTIME|seconds_to_words}</td>
</tr>
<tr>

View File

@ -35,7 +35,7 @@
<fieldset>
<label>Automatic Payout Threshold</label>
<font size="1">{$GLOBAL.config.ap_threshold.min}-{$GLOBAL.config.ap_threshold.max} {$GLOBAL.config.currency}. Set to '0' for no auto payout.</font>
<input type="text" name="payoutThreshold" value="{$smarty.request.payoutThreshold|default:$GLOBAL.userdata.ap_threshold|escape}" size="5" maxlength="5" />
<input type="text" name="payoutThreshold" value="{$smarty.request.payoutThreshold|default:$GLOBAL.userdata.ap_threshold|escape}" size="{$GLOBAL.config.ap_threshold.max|strlen}" maxlength="{$GLOBAL.config.ap_threshold.max|strlen}" />
</fieldset>
<fieldset>
<label>Anonymous Account</label>

View File

@ -21,7 +21,7 @@
{if $SETTINGS.$TAB[setting].type == 'select'}
{html_options name="data[{$SETTINGS.$TAB[setting].name}]" options=$SETTINGS.$TAB[setting].options selected=$SETTINGS.$TAB[setting].value|default:$SETTINGS.$TAB[setting].default}
{else if $SETTINGS.$TAB[setting].type == 'text'}
<input type="text" size="{$SETTINGS.$TAB[setting].size}" name="data[{$SETTINGS.$TAB[setting].name}]" value="{$SETTINGS.$TAB[setting].value|default:$SETTINGS.$TAB[setting].default}" />
<input type="text" size="{$SETTINGS.$TAB[setting].size}" name="data[{$SETTINGS.$TAB[setting].name}]" value="{$SETTINGS.$TAB[setting].value|default:$SETTINGS.$TAB[setting].default|escape:"html"}" />
{else if $SETTINGS.$TAB[setting].type == 'textarea'}
<textarea name="data[{$SETTINGS.$TAB[setting].name}]" cols="{$SETTINGS.$TAB[setting].size|default:"1"}" rows="{$SETTINGS.$TAB[setting].height|default:"1"}">{$SETTINGS.$TAB[setting].value|default:$SETTINGS.$TAB[setting].default}</textarea>
{else}

View File

@ -140,6 +140,8 @@ $(document).ready(function(){
$('#b-pvalid').html(data.getdashboarddata.data.pool.shares.valid);
$('#b-pivalid').html(data.getdashboarddata.data.pool.shares.invalid + " (" + data.getdashboarddata.data.pool.shares.invalid_percent + "%)" );
$('#b-diff').html(data.getdashboarddata.data.network.difficulty);
$('#b-nextdiff').html(data.getdashboarddata.data.network.nextdifficulty);
$('#b-esttimeperblock').html(data.getdashboarddata.data.network.esttimeperblock + " seconds"); // <- this needs some nicer format
$('#b-nblock').html(data.getdashboarddata.data.network.block);
$('#b-target').html(data.getdashboarddata.data.pool.shares.estimated + " (done: " + data.getdashboarddata.data.pool.shares.progress + "%)" );
{/literal}{if $GLOBAL.config.payout_system != 'pps'}{literal }

View File

@ -5,6 +5,14 @@
<td><b>Difficulty</b></td>
<td id="b-diff" class="right">{$NETWORK.difficulty}</td>
</tr>
<tr>
<td><b>Est Next Difficulty</b></td>
<td id="b-nextdiff" class="right">{$NETWORK.EstNextDifficulty}</td>
</tr>
<tr>
<td><b>Est. Avg. Time per Block</b></td>
<td id="b-esttimeperblock" class="right">{$NETWORK.EstTimePerBlock|seconds_to_words}</td>
</tr>
<tr>
<td><b>Current Block</b></td>
<td id="b-nblock" class="right">{$NETWORK.block}</td>

View File

@ -24,7 +24,19 @@
{/if}
</tr>
<tr>
<th align="left">Est. Avg. Time per Round</td>
<th align="left">Est. Next Difficulty</td>
{if ! $GLOBAL.website.chaininfo.disabled}
<td><a href="{$GLOBAL.website.chaininfo.url}" target="_new"><font size="2"><span id="b-diff">{$NETWORK.EstNextDifficulty}</span></font></a></td>
{else}
<td><font size="2"><span id="b-diff">{$NETWORK.EstNextDifficulty}</span></font></td>
{/if}
</tr>
<tr>
<th align="left">Est. Avg. Time per Round (Network)</td>
<td><font size="2"><span id="b-diff">{$NETWORK.EstTimePerBlock|seconds_to_words}</span></font></td>
</tr>
<tr>
<th align="left">Est. Avg. Time per Round (Pool)</td>
<td>{$ESTTIME|seconds_to_words}</td>
</tr>
<tr>

View File

@ -215,7 +215,7 @@ CREATE TABLE IF NOT EXISTS `transactions` (
KEY `archived` (`archived`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `templates` (
CREATE TABLE IF NOT EXISTS `templates` (
`template` varchar(255) NOT NULL,
`active` tinyint(1) NOT NULL DEFAULT 0,
`content` mediumtext,