Skip to content
Snippets Groups Projects
Commit 1b4f0dd5 authored by fireice-uk's avatar fireice-uk
Browse files

Giveup limit

parent 433db191
No related branches found
No related tags found
No related merge requests found
......@@ -110,9 +110,12 @@
* call_timeout - How long should we wait for a response from the server before we assume it is dead and drop the connection.
* retry_time - How long should we wait before another connection attempt.
* Both values are in seconds.
* giveup_limit - Limit how many times we try to reconnect to the pool. Zero means no limit. Note that stak miners
* don't mine while the connection is lost, so your computer's power usage goes down to idle.
*/
"call_timeout" : 10,
"retry_time" : 10,
"giveup_limit" : 0,
/*
* Output control.
......
......@@ -96,8 +96,17 @@ void executor::ex_clock_thd()
void executor::sched_reconnect()
{
iReconnectAttempts++;
size_t iLimit = jconf::inst()->GetGiveUpLimit();
if(iLimit != 0 && iReconnectAttempts > iLimit)
{
printer::inst()->print_msg(L0, "Give up limit reached. Exitting.");
exit(0);
}
long long unsigned int rt = jconf::inst()->GetNetRetry();
printer::inst()->print_msg(L1, "Pool connection lost. Waiting %lld s before retry.", rt);
printer::inst()->print_msg(L1, "Pool connection lost. Waiting %lld s before retry (attempt %llu).",
rt, int_port(iReconnectAttempts));
auto work = minethd::miner_work();
minethd::switch_work(work);
......@@ -178,7 +187,10 @@ void executor::on_sock_ready(size_t pool_id)
}
}
else
{
iReconnectAttempts = 0;
reset_stats();
}
}
void executor::on_sock_error(size_t pool_id, std::string&& sError)
......
......@@ -81,6 +81,8 @@ private:
std::promise<void> httpReady;
std::mutex httpMutex;
size_t iReconnectAttempts = 0;
struct sck_error_log
{
std::chrono::system_clock::time_point time;
......
......@@ -38,7 +38,8 @@ using namespace rapidjson;
* This enum needs to match index in oConfigValues, otherwise we will get a runtime error
*/
enum configEnum { iCpuThreadNum, aCpuThreadsConf, sUseSlowMem, bNiceHashMode, bTlsMode, bTlsSecureAlgo, sTlsFingerprint,
sPoolAddr, sWalletAddr, sPoolPwd, iCallTimeout, iNetRetry, iVerboseLevel, iAutohashTime, iHttpdPort, bPreferIpv4 };
sPoolAddr, sWalletAddr, sPoolPwd, iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, iAutohashTime, iHttpdPort,
bPreferIpv4 };
struct configVal {
configEnum iName;
......@@ -60,6 +61,7 @@ configVal oConfigValues[] = {
{ sPoolPwd, "pool_password", kStringType },
{ iCallTimeout, "call_timeout", kNumberType },
{ iNetRetry, "retry_time", kNumberType },
{ iGiveUpLimit, "giveup_limit", kNumberType },
{ iVerboseLevel, "verbose_level", kNumberType },
{ iAutohashTime, "h_print_time", kNumberType },
{ iHttpdPort, "httpd_port", kNumberType },
......@@ -207,6 +209,11 @@ uint64_t jconf::GetNetRetry()
return prv->configValues[iNetRetry]->GetUint64();
}
uint64_t jconf::GetGiveUpLimit()
{
return prv->configValues[iGiveUpLimit]->GetUint64();
}
uint64_t jconf::GetVerboseLevel()
{
return prv->configValues[iVerboseLevel]->GetUint64();
......@@ -378,10 +385,12 @@ bool jconf::parse_config(const char* sFilename)
return false;
}
if(!prv->configValues[iCallTimeout]->IsUint64() || !prv->configValues[iNetRetry]->IsUint64())
if(!prv->configValues[iCallTimeout]->IsUint64() ||
!prv->configValues[iNetRetry]->IsUint64() ||
!prv->configValues[iGiveUpLimit]->IsUint64())
{
printer::inst()->print_msg(L0,
"Invalid config file. call_timeout and retry_time need to be positive integers.");
"Invalid config file. call_timeout, retry_time and giveup_limit need to be positive integers.");
return false;
}
......
......@@ -45,6 +45,7 @@ public:
uint64_t GetCallTimeout();
uint64_t GetNetRetry();
uint64_t GetGiveUpLimit();
uint16_t GetHttpdPort();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment