Skip to content

Commit d35893d

Browse files
fireice-ukpsychocrypt
authored andcommitted
Multi-pool final version (fireice-uk#90)
* Multi-pool first draft * Fix wspace from new IDE * Better TLS error message * Fix TLS bug * Don't put dev pool on stats + pool change-back * bug fixes * Error message work * fix win build * add per-pool nicehash setting * Fix bugs * rm debug msg * Multipool guided setup * Support TLS and Nicehash in config * prelim jconf changes * final multipool changes * increase default retry_time to 30, fix mac erro * rm debug dev pool settings * Fix another source of connect runaway
1 parent b3237ba commit d35893d

13 files changed

+723
-391
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ config-debug.txt
1313

1414
# merge original backup files
1515
*.orig
16+
17+
# KDevelop files
18+
.kdev4/
19+
xmr-stak.kdev4

xmrstak/backend/cpu/jconf.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class jconf
3131
bool GetThreadConfig(size_t id, thd_cfg &cfg);
3232
bool NeedsAutoconf();
3333

34-
35-
36-
3734
private:
3835
jconf();
3936
static jconf* oInst;

xmrstak/backend/globalStates.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <atomic>
88

9+
constexpr static size_t invalid_pool_id = (-1);
910

1011
namespace xmrstak
1112
{
@@ -15,7 +16,7 @@ struct pool_data
1516
uint32_t iSavedNonce;
1617
size_t pool_id;
1718

18-
pool_data() : iSavedNonce(0), pool_id(0)
19+
pool_data() : iSavedNonce(0), pool_id(invalid_pool_id)
1920
{
2021
}
2122
};
@@ -46,7 +47,7 @@ struct globalStates
4647
std::atomic<uint64_t> iConsumeCnt;
4748
std::atomic<uint32_t> iGlobalNonce;
4849
uint64_t iThreadCount;
49-
size_t pool_id;
50+
size_t pool_id = invalid_pool_id;
5051

5152
private:
5253
globalStates() : iThreadCount(0)

xmrstak/cli/cli-miner.cpp

+165-55
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
#include <openssl/err.h>
5050
#endif
5151

52-
5352
#ifdef _WIN32
5453
# define strcasecmp _stricmp
5554
#endif // _WIN32
@@ -90,6 +89,170 @@ void help()
9089
cout<<"Brought to by fireice_uk and psychocrypt under GPLv3."<<endl;
9190
}
9291

92+
bool read_yes_no(const char* str)
93+
{
94+
std::string tmp;
95+
do
96+
{
97+
std::cout << str << std::endl;
98+
std::cin >> tmp;
99+
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
100+
}
101+
while(tmp != "y" && tmp != "n" && tmp != "yes" && tmp != "no");
102+
103+
return tmp == "y" || tmp == "yes";
104+
}
105+
106+
inline const char* bool_to_str(bool v)
107+
{
108+
return v ? "true" : "false";
109+
}
110+
111+
std::string get_multipool_entry(bool& final)
112+
{
113+
std::cout<<std::endl<<"- Next Pool:"<<std::endl<<std::endl;
114+
115+
std::string pool;
116+
if(xmrstak::params::inst().currency == "monero")
117+
std::cout<<"- Pool address: e.g. pool.usxmrpool.com:3333"<<std::endl;
118+
else
119+
std::cout<<"- Pool address: e.g. mine.aeon-pool.com:5555"<<std::endl;
120+
std::cin >> pool;
121+
122+
std::string userName;
123+
std::cout<<"- Username (wallet address or pool login):"<<std::endl;
124+
std::cin >> userName;
125+
126+
std::string passwd;
127+
std::cin.clear(); std::cin.ignore(INT_MAX,'\n');
128+
std::cout<<"- Password (mostly empty or x):"<<std::endl;
129+
getline(std::cin, passwd);
130+
131+
bool tls = read_yes_no("- Does this pool port support TLS/SSL? Use no if unknown. (y/N)");
132+
bool nicehash = read_yes_no("- Do you want to use nicehash on this pool? (y/n)");
133+
134+
int64_t pool_weight;
135+
std::cout << "- Please enter a weight for this pool: "<<std::endl;
136+
while(!(std::cin >> pool_weight) || pool_weight <= 0)
137+
{
138+
std::cin.clear();
139+
std::cin.ignore(INT_MAX, '\n');
140+
std::cout << "Invalid weight. Try 1, 10, 100, etc:" << std::endl;
141+
}
142+
143+
final = !read_yes_no("- Do you want to add another pool? (y/n)");
144+
145+
return "\t{\"pool_address\" : \"" + pool +"\", \"wallet_address\" : \"" + userName + "\", \"pool_password\" : \"" +
146+
passwd + "\", \"use_nicehash\" : " + bool_to_str(nicehash) + ", \"use_tls\" : " + bool_to_str(tls) +
147+
", \"tls_fingerprint\" : \"\", \"pool_weight\" : " + std::to_string(pool_weight) + " },\n";
148+
}
149+
150+
void do_guided_config(bool userSetPasswd)
151+
{
152+
using namespace xmrstak;
153+
154+
// load the template of the backend config into a char variable
155+
const char *tpl =
156+
#include "../config.tpl"
157+
;
158+
159+
configEditor configTpl{};
160+
configTpl.set(std::string(tpl));
161+
std::cout<<"Please enter:"<<std::endl;
162+
auto& currency = params::inst().currency;
163+
if(currency.empty())
164+
{
165+
std::string tmp;
166+
#if defined(CONF_NO_AEON)
167+
tmp = "monero";
168+
#elif defined(CONF_NO_MONERO)
169+
tmp = "aeon";
170+
#endif
171+
while(tmp != "monero" && tmp != "aeon")
172+
{
173+
std::cout<<"- Currency: 'monero' or 'aeon'"<<std::endl;
174+
std::cin >> tmp;
175+
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
176+
}
177+
currency = tmp;
178+
}
179+
180+
auto& pool = params::inst().poolURL;
181+
bool userSetPool = true;
182+
if(pool.empty())
183+
{
184+
userSetPool = false;
185+
if(currency == "monero")
186+
std::cout<<"- Pool address: e.g. pool.usxmrpool.com:3333"<<std::endl;
187+
else
188+
std::cout<<"- Pool address: e.g. mine.aeon-pool.com:5555"<<std::endl;
189+
std::cin >> pool;
190+
}
191+
192+
auto& userName = params::inst().poolUsername;
193+
if(userName.empty())
194+
{
195+
std::cout<<"- Username (wallet address or pool login):"<<std::endl;
196+
std::cin >> userName;
197+
}
198+
199+
auto& passwd = params::inst().poolPasswd;
200+
if(passwd.empty() && (!userSetPasswd))
201+
{
202+
// clear everything from stdin to allow an empty password
203+
std::cin.clear(); std::cin.ignore(INT_MAX,'\n');
204+
std::cout<<"- Password (mostly empty or x):"<<std::endl;
205+
getline(std::cin, passwd);
206+
}
207+
208+
bool tls = read_yes_no("- Does this pool port support TLS/SSL? Use no if unknown. (y/N)");
209+
bool nicehash = read_yes_no("- Do you want to use nicehash on this pool? (y/n)");
210+
211+
bool multipool;
212+
if(!userSetPool)
213+
multipool = read_yes_no("- Do you want to use multiple pools? (y/n)");
214+
else
215+
multipool = false;
216+
217+
int64_t pool_weight;
218+
if(multipool)
219+
{
220+
std::cout << "Pool weight is a number telling the miner how important the pool is." << std::endl;
221+
std::cout << "Miner will mine mostly at the pool with the highest weight, unless the pool fails." << std::endl;
222+
std::cout << "Weight must be an integer larger than 0." << std::endl;
223+
std::cout << "- Please enter a weight for this pool: "<<std::endl;
224+
225+
while(!(std::cin >> pool_weight) || pool_weight <= 0)
226+
{
227+
std::cin.clear();
228+
std::cin.ignore(INT_MAX, '\n');
229+
std::cout << "Invalid weight. Try 1, 10, 100, etc:" << std::endl;
230+
}
231+
}
232+
else
233+
pool_weight = 1;
234+
235+
std::string pool_table;
236+
pool_table += "\t{\"pool_address\" : \"" + pool +"\", \"wallet_address\" : \"" + userName + "\", \"pool_password\" : \"" +
237+
passwd + "\", \"use_nicehash\" : " + bool_to_str(nicehash) + ", \"use_tls\" : " + bool_to_str(tls) +
238+
", \"tls_fingerprint\" : \"\", \"pool_weight\" : " + std::to_string(pool_weight) + " },\n";
239+
240+
if(multipool)
241+
{
242+
bool final;
243+
do
244+
{
245+
pool_table += get_multipool_entry(final);
246+
}
247+
while(!final);
248+
}
249+
250+
configTpl.replace("POOLCONF", pool_table);
251+
configTpl.replace("CURRENCY", currency);
252+
configTpl.write(params::inst().configFile);
253+
std::cout<<"Configuration stored in file '"<<params::inst().configFile<<"'"<<std::endl;
254+
}
255+
93256
int main(int argc, char *argv[])
94257
{
95258
#ifndef CONF_NO_TLS
@@ -244,60 +407,7 @@ int main(int argc, char *argv[])
244407

245408
// check if we need a guided start
246409
if(!configEditor::file_exist(params::inst().configFile))
247-
{
248-
// load the template of the backend config into a char variable
249-
const char *tpl =
250-
#include "../config.tpl"
251-
;
252-
configEditor configTpl{};
253-
configTpl.set(std::string(tpl));
254-
std::cout<<"Please enter:"<<std::endl;
255-
auto& currency = params::inst().currency;
256-
if(currency.empty())
257-
{
258-
std::string tmp;
259-
#if defined(CONF_NO_AEON)
260-
tmp = "monero";
261-
#elif defined(CONF_NO_MONERO)
262-
tmp = "aeon";
263-
#endif
264-
while(!xmrstak::strcmp_i(tmp, "monero") && !xmrstak::strcmp_i(tmp, "aeon"))
265-
{
266-
std::cout<<"- currency: 'monero' or 'aeon'"<<std::endl;
267-
std::cin >> tmp;
268-
}
269-
currency = tmp;
270-
}
271-
auto& pool = params::inst().poolURL;
272-
if(pool.empty())
273-
{
274-
if(xmrstak::strcmp_i(currency, "monero"))
275-
std::cout<<"- pool address: e.g. pool.usxmrpool.com:3333"<<std::endl;
276-
else
277-
std::cout<<"- pool address: e.g. mine.aeon-pool.com:5555"<<std::endl;
278-
std::cin >> pool;
279-
}
280-
auto& userName = params::inst().poolUsername;
281-
if(userName.empty())
282-
{
283-
std::cout<<"- user name (wallet address or pool login):"<<std::endl;
284-
std::cin >> userName;
285-
}
286-
auto& passwd = params::inst().poolPasswd;
287-
if(passwd.empty() && (!userSetPasswd))
288-
{
289-
// clear everything from stdin to allow an empty password
290-
std::cin.clear(); std::cin.ignore(INT_MAX,'\n');
291-
std::cout<<"- password (mostly empty or x):"<<std::endl;
292-
getline(std::cin, passwd);
293-
}
294-
configTpl.replace("POOLURL", pool);
295-
configTpl.replace("POOLUSER", userName);
296-
configTpl.replace("POOLPASSWD", passwd);
297-
configTpl.replace("CURRENCY", currency);
298-
configTpl.write(params::inst().configFile);
299-
std::cout<<"Configuration stored in file '"<<params::inst().configFile<<"'"<<std::endl;
300-
}
410+
do_guided_config(userSetPasswd);
301411

302412
if(!jconf::inst()->parse_config(params::inst().configFile.c_str()))
303413
{

xmrstak/config.tpl

+14-21
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
R"===(
22
/*
3-
* pool_address - Pool address should be in the form "pool.supportxmr.com:3333". Only stratum pools are supported.
4-
* wallet_address - Your wallet, or pool login.
5-
* pool_password - Can be empty in most cases or "x".
3+
* pool_address - Pool address should be in the form "pool.supportxmr.com:3333". Only stratum pools are supported.
4+
* wallet_address - Your wallet, or pool login.
5+
* pool_password - Can be empty in most cases or "x".
6+
* use_nicehash - Limit the nonce to 3 bytes as required by nicehash.
7+
* use_tls - This option will make us connect using Transport Layer Security.
8+
* tls_fingerprint - Server's SHA256 fingerprint. If this string is non-empty then we will check the server's cert against it.
9+
* pool_weight - Pool weight is a number telling the miner how important the pool is. Miner will mine mostly at the pool
10+
* with the highest weight, unless the pool fails. Weight must be an integer larger than 0.
611
*
712
* We feature pools up to 1MH/s. For a more complete list see M5M400's pool list at www.moneropools.com
813
*/
9-
"pool_address" : "POOLURL",
10-
"wallet_address" : "POOLUSER",
11-
"pool_password" : "POOLPASSWD",
14+
"pool_list" :
15+
[
16+
POOLCONF],
1217

1318
/*
1419
* currency to mine
@@ -31,7 +36,7 @@ R"===(
3136
* don't mine while the connection is lost, so your computer's power usage goes down to idle.
3237
*/
3338
"call_timeout" : 10,
34-
"retry_time" : 10,
39+
"retry_time" : 30,
3540
"giveup_limit" : 0,
3641

3742
/*
@@ -110,26 +115,14 @@ R"===(
110115
*/
111116
"use_slow_memory" : "warn",
112117

113-
/*
114-
* NiceHash mode
115-
* nicehash_nonce - Limit the nonce to 3 bytes as required by nicehash. This cuts all the safety margins, and
116-
* if a block isn't found within 30 minutes then you might run into nonce collisions. Number
117-
* of threads in this mode is hard-limited to 32.
118-
*/
119-
"nicehash_nonce" : false,
120-
121118
/*
122119
* TLS Settings
123120
* If you need real security, make sure tls_secure_algo is enabled (otherwise MITM attack can downgrade encryption
124121
* to trivially breakable stuff like DES and MD5), and verify the server's fingerprint through a trusted channel.
125122
*
126-
* use_tls - This option will make us connect using Transport Layer Security.
127123
* tls_secure_algo - Use only secure algorithms. This will make us quit with an error if we can't negotiate a secure algo.
128-
* tls_fingerprint - Server's SHA256 fingerprint. If this string is non-empty then we will check the server's cert against it.
129124
*/
130-
"use_tls" : false,
131125
"tls_secure_algo" : true,
132-
"tls_fingerprint" : "",
133126

134127
/*
135128
* Daemon mode
@@ -145,7 +138,7 @@ R"===(
145138
* each output line immediately. This can cause delays when running in background.
146139
* Set this option to true to flush stdout after each line, so it can be read immediately.
147140
*/
148-
"flush_stdout" : false,
141+
"flush_stdout" : false,
149142

150143
/*
151144
* Output file
@@ -172,4 +165,4 @@ R"===(
172165
"prefer_ipv4" : true,
173166

174167
)==="
175-
168+

0 commit comments

Comments
 (0)