forked from arionum/pool
-
Notifications
You must be signed in to change notification settings - Fork 2
/
poolsanity.php
executable file
·109 lines (93 loc) · 3.56 KB
/
poolsanity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
################# PID SYSTEM #################
$script_name = __FILE__;
$scripta = explode('/', $script_name);
$script_name = $scripta[count($scripta) - 1];
if (empty($script_name)) {
exit;
}
$pid112 = '/var/run/'.$script_name.'.pid';
$pid_exists = file_exists($pid112);
$pid_time = 0;
if ($pid_exists) {
$pid_time = filemtime($pid112);
if (time() - $pid_time > 3600) {
system("rm -rf $pid112");
}
die("\n\n### RUNNING ### -- PID: $pid112\n\n");
}
system("touch $pid112");
function shut_down()
{
global $pid112;
system("rm -rf $pid112");
echo "\n# ShutDown #\n";
}
register_shutdown_function('shut_down');
###############################################
date_default_timezone_set('Europe/Budapest');
//$datetime_akt = date('Y.m.d H:i:s', time());
require_once __DIR__.'/db.php';
set_time_limit(0);
if (PHP_SAPI !== 'cli') {
die('This should only be run as cli');
}
if ($pool_config['pool_degradation']==null) {die('Degradation rate not set in config');}
$current = 0;
$ticks = 0;
while (1) {
$ticks++;
//$ck = $aro->single('SELECT height FROM blocks ORDER by height DESC LIMIT 1');
$ck = $aro->single('SELECT MAX(height) FROM blocks');
//if ($ck !== $current && $ck) {
if ($ck !== $current) {
$current = $ck;
$db->run('UPDATE miners SET historic=historic+shares-historic*:dr, shares=0,bestdl=1000000', [':dr' => $pool_config['pool_degradation']]);
$db->run('TRUNCATE table nonces');
$r=$db->run("SELECT * FROM miners WHERE historic>0");
$total_hr=0;
$total_gpu=0;
foreach($r as $x){
$thr=$db->row("SELECT SUM(hashrate) as cpu, SUM(gpuhr) as gpu FROM workers WHERE miner=:m AND updated>UNIX_TIMESTAMP()-3600",array(":m"=>$x['id']));
if($x['historic']/$thr['cpu']<2||$x['historic']/$thr['gpu']<2) {
$thr['cpu']=0;
$thr['gpu']=0;
echo "$x[id] [$x[historic]] -> ".$x['historic']/$thr[cpu]."\n";
}
$total_hr+=$thr['cpu'];
$total_gpu+=$thr['gpu'];
}
echo "Total hr: $total_hr\n";
$db->run("UPDATE info SET val=:thr WHERE id='total_hash_rate'",array(":thr"=>$total_hr));
$db->run("UPDATE info SET val=:thr WHERE id='total_gpu_hr'",array(":thr"=>$total_gpu));
}
$max_dl = ($current % 2) ? $pool_config['max_deadline_gpu'] : $pool_config['max_deadline'];
$cache_file = __DIR__."/cache/info.txt";
$f = file_get_contents($pool_config['node_url'].'/mine.php?q=info');
$g = json_decode($f, true);
$res = [
'difficulty' => $g['data']['difficulty'],
'block' => $g['data']['block'],
'height' => $g['data']['height'],
'public_key' => $pool_config['public_key'],
'limit' => $max_dl,
'recommendation' => $g['data']['recommendation'],
'argon_mem' => $g['data']['argon_mem'],
'argon_threads' => $g['data']['argon_threads'],
'argon_time' => $g['data']['argon_time'],
];
$datetime_akt = date('Y.m.d H:i:s', time());
$fin = json_encode(['status' => 'ok', 'data' => $res, 'coin' => 'arionum', 'lastupdate' => $datetime_akt]);
echo "\n$fin\n";
file_put_contents($cache_file, $fin);
sleep(2);
//refresh PID
$pid_exists = file_exists($pid112);
$pid_time = 0;
if ($pid_exists) {
$pid_time = filemtime($pid112);
}
if (time() - $pid_time > 60) {
system("touch $pid112");
}
}