Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit c572dde

Browse files
committedSep 14, 2018
Use singleton pattern to access Poolmanager and Farm
1 parent f4b246b commit c572dde

File tree

6 files changed

+105
-97
lines changed

6 files changed

+105
-97
lines changed
 

‎ethminer/main.cpp

+24-25
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ using namespace dev;
4545
using namespace dev::eth;
4646

4747
boost::asio::io_service g_io_service; // The IO service itself
48-
dev::eth::Farm* g_farm;
49-
dev::eth::PoolManager* g_mgr;
48+
Farm* Farm::m_this = nullptr;
5049

5150
struct MiningChannel : public LogChannel
5251
{
@@ -776,7 +775,7 @@ class MinerCLI
776775
genesis.setNumber(m_benchmarkBlock);
777776
genesis.setDifficulty(u256(1) << 64);
778777

779-
g_farm = new Farm(m_show_hwmonitors, m_show_power);
778+
new Farm(m_show_hwmonitors, m_show_power);
780779
map<string, Farm::SealerDescriptor> sealers;
781780
#if ETH_ETHASHCL
782781
sealers["opencl"] = Farm::SealerDescriptor{&CLMiner::instances,
@@ -786,13 +785,13 @@ class MinerCLI
786785
sealers["cuda"] = Farm::SealerDescriptor{&CUDAMiner::instances,
787786
[](FarmFace& _farm, unsigned _index) { return new CUDAMiner(_farm, _index); }};
788787
#endif
789-
g_farm->setSealers(sealers);
790-
g_farm->onSolutionFound([&](Solution, unsigned const& miner_index) {
788+
Farm::f().setSealers(sealers);
789+
Farm::f().onSolutionFound([&](Solution, unsigned const& miner_index) {
791790
(void)miner_index;
792791
return false;
793792
});
794793

795-
g_farm->setTStartTStop(m_tstart, m_tstop);
794+
Farm::f().setTStartTStop(m_tstart, m_tstop);
796795

797796
string platformInfo = _m == MinerType::CL ? "CL" : "CUDA";
798797
cout << "Benchmarking on platform: " << platformInfo << endl;
@@ -801,9 +800,9 @@ class MinerCLI
801800
// genesis.prep();
802801

803802
if (_m == MinerType::CL)
804-
g_farm->start("opencl", false);
803+
Farm::f().start("opencl", false);
805804
else if (_m == MinerType::CUDA)
806-
g_farm->start("cuda", false);
805+
Farm::f().start("cuda", false);
807806

808807
WorkPackage current = WorkPackage(genesis);
809808

@@ -816,14 +815,14 @@ class MinerCLI
816815
{
817816
current.header = h256::random();
818817
current.boundary = genesis.boundary();
819-
g_farm->setWork(current);
818+
Farm::f().setWork(current);
820819
if (!i)
821820
cout << "Warming up..." << endl;
822821
else
823822
cout << "Trial " << i << "... " << flush << endl;
824823
this_thread::sleep_for(chrono::seconds(i ? _trialDuration : _warmupDuration));
825824

826-
auto mp = g_farm->miningProgress();
825+
auto mp = Farm::f().miningProgress();
827826
if (!i)
828827
continue;
829828
auto rate = uint64_t(mp.hashRate);
@@ -889,26 +888,26 @@ class MinerCLI
889888
}
890889

891890
// sealers, m_minerType
892-
g_farm = new Farm(m_show_hwmonitors, m_show_power);
893-
g_farm->setSealers(sealers);
891+
new Farm(m_show_hwmonitors, m_show_power);
892+
Farm::f().setSealers(sealers);
894893

895-
g_mgr = new PoolManager(client, m_minerType, m_maxFarmRetries, m_failovertimeout);
894+
new PoolManager(client, m_minerType, m_maxFarmRetries, m_failovertimeout);
896895

897-
g_farm->setTStartTStop(m_tstart, m_tstop);
896+
Farm::f().setTStartTStop(m_tstart, m_tstop);
898897

899898
// If we are in simulation mode we add a fake connection
900899
if (m_mode == OperationMode::Simulation)
901900
{
902901
URI con(URI("http://-:0"));
903-
g_mgr->clearConnections();
904-
g_mgr->addConnection(con);
902+
PoolManager::p().clearConnections();
903+
PoolManager::p().addConnection(con);
905904
}
906905
else
907906
{
908907
for (auto conn : m_endpoints)
909908
{
910909
cnote << "Configured pool " << conn.Host() + ":" + to_string(conn.Port());
911-
g_mgr->addConnection(conn);
910+
PoolManager::p().addConnection(conn);
912911
}
913912
}
914913

@@ -922,12 +921,12 @@ class MinerCLI
922921
#endif
923922

924923
// Start PoolManager
925-
g_mgr->start();
924+
PoolManager::p().start();
926925

927926
unsigned interval = m_displayInterval;
928927

929928
// Run CLI in loop
930-
while (g_running && g_mgr->isRunning())
929+
while (g_running && PoolManager::p().isRunning())
931930
{
932931
// Wait at the beginning of the loop to give some time
933932
// services to start properly. Otherwise we get a "not-connected"
@@ -938,23 +937,23 @@ class MinerCLI
938937
interval -= 2;
939938
continue;
940939
}
941-
if (g_mgr->isConnected())
940+
if (PoolManager::p().isConnected())
942941
{
943-
auto solstats = g_farm->getSolutionStats();
942+
auto solstats = Farm::f().getSolutionStats();
944943
{
945944
ostringstream os;
946-
os << g_farm->miningProgress() << ' ';
945+
os << Farm::f().miningProgress() << ' ';
947946
if (!(g_logOptions & LOG_PER_GPU))
948947
os << solstats << ' ';
949-
os << g_farm->farmLaunchedFormatted();
948+
os << Farm::f().farmLaunchedFormatted();
950949
minelog << os.str();
951950
}
952951

953952
if (g_logOptions & LOG_PER_GPU)
954953
{
955954
ostringstream statdetails;
956955
statdetails << "Solutions " << solstats << ' ';
957-
for (size_t i = 0; i < g_farm->getMiners().size(); i++)
956+
for (size_t i = 0; i < Farm::f().getMiners().size(); i++)
958957
{
959958
if (i) statdetails << " ";
960959
statdetails << "gpu" << i << ":" << solstats.getString(i);
@@ -980,7 +979,7 @@ class MinerCLI
980979

981980
#endif
982981

983-
g_mgr->stop();
982+
PoolManager::p().stop();
984983
stop_io_service();
985984

986985
cnote << "Terminated!";

‎libapicore/ApiServer.cpp

+42-42
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
447447
// Gives nonce scrambler a new range
448448
cnote << "Miner Shuffle requested";
449449
jResponse["result"] = true;
450-
g_farm->shuffle();
450+
Farm::f().shuffle();
451451
}
452452

453453
else if (_method == "miner_ping")
@@ -465,7 +465,7 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
465465
return;
466466
cnote << "Miner Restart requested";
467467
jResponse["result"] = true;
468-
g_farm->restart_async();
468+
Farm::f().restart_async();
469469
}
470470

471471
else if (_method == "miner_reboot")
@@ -474,13 +474,13 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
474474
return;
475475
cnote << "Miner reboot requested";
476476

477-
jResponse["result"] = g_farm->reboot({{"api_miner_reboot"}});
477+
jResponse["result"] = Farm::f().reboot({{"api_miner_reboot"}});
478478
}
479479

480480
else if (_method == "miner_getconnections")
481481
{
482482
// Returns a list of configured pools
483-
jResponse["result"] = g_mgr->getConnectionsJson();
483+
jResponse["result"] = PoolManager::p().getConnectionsJson();
484484
}
485485

486486
else if (_method == "miner_addconnection")
@@ -513,7 +513,7 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
513513
}
514514

515515
// Check other pools already present share the same scheme family (stratum or getwork)
516-
Json::Value pools = g_mgr->getConnectionsJson();
516+
Json::Value pools = PoolManager::p().getConnectionsJson();
517517
for (Json::Value::ArrayIndex i = 0; i != pools.size(); i++)
518518
{
519519
dev::URI poolUri = pools[i]["uri"].asString();
@@ -527,7 +527,7 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
527527
}
528528

529529
// If everything ok then add this new uri
530-
g_mgr->addConnection(uri);
530+
PoolManager::p().addConnection(uri);
531531
jResponse["result"] = true;
532532
}
533533
catch (...)
@@ -550,15 +550,15 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
550550
if (!getRequestValue("index", index, jRequestParams, false, jResponse))
551551
return;
552552

553-
Json::Value pools = g_mgr->getConnectionsJson();
553+
Json::Value pools = PoolManager::p().getConnectionsJson();
554554
if (index >= pools.size())
555555
{
556556
jResponse["error"]["code"] = -422;
557557
jResponse["error"]["message"] = "Index out of bounds";
558558
return;
559559
}
560560

561-
g_mgr->setActiveConnection(index);
561+
PoolManager::p().setActiveConnection(index);
562562
jResponse["result"] = true;
563563
}
564564

@@ -575,7 +575,7 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
575575
if (!getRequestValue("index", index, jRequestParams, false, jResponse))
576576
return;
577577

578-
Json::Value pools = g_mgr->getConnectionsJson();
578+
Json::Value pools = PoolManager::p().getConnectionsJson();
579579
if (index >= pools.size())
580580
{
581581
jResponse["error"]["code"] = -422;
@@ -589,13 +589,13 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
589589
return;
590590
}
591591

592-
g_mgr->removeConnection(index);
592+
PoolManager::p().removeConnection(index);
593593
jResponse["result"] = true;
594594
}
595595

596596
else if (_method == "miner_getscramblerinfo")
597597
{
598-
jResponse["result"] = g_farm->get_nonce_scrambler_json();
598+
jResponse["result"] = Farm::f().get_nonce_scrambler_json();
599599
}
600600

601601
else if (_method == "miner_setscramblerinfo")
@@ -608,8 +608,8 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
608608
return;
609609

610610
bool any_value_provided = false;
611-
uint64_t nonce = g_farm->get_nonce_scrambler();
612-
unsigned exp = g_farm->get_segment_width();
611+
uint64_t nonce = Farm::f().get_nonce_scrambler();
612+
unsigned exp = Farm::f().get_segment_width();
613613

614614
if (!getRequestValue("noncescrambler", nonce, jRequestParams, true, jResponse))
615615
return;
@@ -630,8 +630,8 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
630630
exp = 10; // Not below
631631
if (exp > 50)
632632
exp = 40; // Not above
633-
g_farm->set_nonce_scrambler(nonce);
634-
g_farm->set_nonce_segment_width(exp);
633+
Farm::f().set_nonce_scrambler(nonce);
634+
Farm::f().set_nonce_segment_width(exp);
635635
jResponse["result"] = true;
636636
}
637637

@@ -652,15 +652,15 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
652652
if (!getRequestValue("pause", pause, jRequestParams, false, jResponse))
653653
return;
654654

655-
WorkingProgress p = g_farm->miningProgress();
655+
WorkingProgress p = Farm::f().miningProgress();
656656
if (index >= p.miningIsPaused.size())
657657
{
658658
jResponse["error"]["code"] = -422;
659659
jResponse["error"]["message"] = "Index out of bounds";
660660
return;
661661
}
662662

663-
auto const& miner = g_farm->getMiner(index);
663+
auto const& miner = Farm::f().getMiner(index);
664664
if (miner)
665665
{
666666
if (pause)
@@ -794,10 +794,10 @@ void ApiConnection::onSendSocketDataCompleted(const boost::system::error_code& e
794794
Json::Value ApiConnection::getMinerStat1()
795795
{
796796
auto runningTime = std::chrono::duration_cast<std::chrono::minutes>(
797-
steady_clock::now() - g_farm->farmLaunched());
798-
auto connection = g_mgr->getActiveConnectionCopy();
799-
SolutionStats s = g_farm->getSolutionStats();
800-
WorkingProgress p = g_farm->miningProgress();
797+
steady_clock::now() - Farm::f().farmLaunched());
798+
auto connection = PoolManager::p().getActiveConnectionCopy();
799+
SolutionStats s = Farm::f().getSolutionStats();
800+
WorkingProgress p = Farm::f().miningProgress();
801801

802802
ostringstream totalMhEth;
803803
ostringstream totalMhDcr;
@@ -857,10 +857,10 @@ Json::Value ApiConnection::getMinerStatHR()
857857
{
858858
// TODO:give key-value format
859859
auto runningTime = std::chrono::duration_cast<std::chrono::minutes>(
860-
steady_clock::now() - g_farm->farmLaunched());
861-
auto connection = g_mgr->getActiveConnectionCopy();
862-
SolutionStats s = g_farm->getSolutionStats();
863-
WorkingProgress p = g_farm->miningProgress();
860+
steady_clock::now() - Farm::f().farmLaunched());
861+
auto connection = PoolManager::p().getActiveConnectionCopy();
862+
SolutionStats s = Farm::f().getSolutionStats();
863+
WorkingProgress p = Farm::f().miningProgress();
864864

865865
ostringstream version;
866866
ostringstream runtime;
@@ -928,7 +928,7 @@ Json::Value ApiConnection::getMinerStatDetailPerMiner(
928928
const WorkingProgress& p, const SolutionStats& s, size_t index)
929929
{
930930
Json::Value jRes;
931-
auto const& miner = g_farm->getMiner(index);
931+
auto const& miner = Farm::f().getMiner(index);
932932

933933
jRes["index"] = (unsigned)index;
934934

@@ -977,8 +977,8 @@ Json::Value ApiConnection::getMinerStatDetailPerMiner(
977977
}
978978

979979
/* Nonce infos */
980-
auto segment_width = g_farm->get_segment_width();
981-
uint64_t gpustartnonce = g_farm->get_nonce_scrambler() + ((uint64_t)index << segment_width);
980+
auto segment_width = Farm::f().get_segment_width();
981+
uint64_t gpustartnonce = Farm::f().get_nonce_scrambler() + ((uint64_t)index << segment_width);
982982
jRes["nonce_start"] = gpustartnonce;
983983
jRes["nonce_stop"] = uint64_t(gpustartnonce + (1LL << segment_width));
984984

@@ -998,11 +998,11 @@ Json::Value ApiConnection::getMinerStatDetailPerMiner(
998998
Json::Value ApiConnection::getMinerStatDetail()
999999
{
10001000
auto runningTime = std::chrono::duration_cast<std::chrono::minutes>(
1001-
std::chrono::steady_clock::now() - g_farm->farmLaunched());
1001+
std::chrono::steady_clock::now() - Farm::f().farmLaunched());
10021002

1003-
SolutionStats s = g_farm->getSolutionStats();
1004-
WorkingProgress p = g_farm->miningProgress();
1005-
WorkPackage w = g_farm->work();
1003+
SolutionStats s = Farm::f().getSolutionStats();
1004+
WorkingProgress p = Farm::f().miningProgress();
1005+
WorkPackage w = Farm::f().work();
10061006

10071007
// ostringstream version;
10081008
Json::Value gpus;
@@ -1021,27 +1021,27 @@ Json::Value ApiConnection::getMinerStatDetail()
10211021
}
10221022

10231023
/* connection info */
1024-
auto connection = g_mgr->getActiveConnectionCopy();
1024+
auto connection = PoolManager::p().getActiveConnectionCopy();
10251025
Json::Value jconnection;
10261026
jconnection["uri"] = connection.String();
1027-
// jconnection["endpoint"] = g_mgr->getClient()->ActiveEndPoint();
1028-
jconnection["isconnected"] = g_mgr->isConnected();
1029-
jconnection["switched"] = g_mgr->getConnectionSwitches();
1027+
// jconnection["endpoint"] = PoolManager::p().getClient()->ActiveEndPoint();
1028+
jconnection["isconnected"] = PoolManager::p().isConnected();
1029+
jconnection["switched"] = PoolManager::p().getConnectionSwitches();
10301030
jRes["connection"] = jconnection;
10311031

10321032
/* Pool info */
1033-
jRes["difficulty"] = g_mgr->getCurrentDifficulty();
1033+
jRes["difficulty"] = PoolManager::p().getCurrentDifficulty();
10341034
if (w)
10351035
jRes["epoch"] = w.epoch;
10361036
else
10371037
jRes["epoch"] = Json::Value::null;
1038-
jRes["epoch_changes"] = g_mgr->getEpochChanges();
1038+
jRes["epoch_changes"] = PoolManager::p().getEpochChanges();
10391039

10401040
/* basic setup */
1041-
auto tstop = g_farm->get_tstop();
1041+
auto tstop = Farm::f().get_tstop();
10421042
if (tstop)
10431043
{
1044-
jRes["tstart"] = g_farm->get_tstart();
1044+
jRes["tstart"] = Farm::f().get_tstart();
10451045
jRes["tstop"] = tstop;
10461046
}
10471047
else
@@ -1050,9 +1050,9 @@ Json::Value ApiConnection::getMinerStatDetail()
10501050
}
10511051

10521052
/* gpu related info */
1053-
if (g_farm->getMiners().size())
1053+
if (Farm::f().getMiners().size())
10541054
{
1055-
for (size_t i = 0; i < g_farm->getMiners().size(); i++)
1055+
for (size_t i = 0; i < Farm::f().getMiners().size(); i++)
10561056
{
10571057
jRes["gpus"].append(getMinerStatDetailPerMiner(p, s, i));
10581058
}

‎libapicore/httpServer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void httpServer::tableHeader(stringstream& ss)
2828
{
2929
char hostName[HOST_NAME_MAX + 1];
3030
gethostname(hostName, HOST_NAME_MAX + 1);
31-
string l = g_farm->farmLaunchedFormatted();
31+
string l = Farm::f().farmLaunchedFormatted();
3232
ss << "<!doctype html>"
3333
"<html lang=en>"
3434
"<head>"
@@ -62,7 +62,7 @@ void httpServer::tableHeader(stringstream& ss)
6262
"<tr class=bg-header1>"
6363
"<th colspan=6>"
6464
<< ethminer_get_buildinfo()->project_name_with_version << " on " << hostName << " - " << l
65-
<< "<br>Pool: " << g_mgr->getActiveConnectionCopy().Host()
65+
<< "<br>Pool: " << PoolManager::p().getActiveConnectionCopy().Host()
6666
<< "</th>"
6767
"</tr>"
6868
"<tr class=bg-header0>"
@@ -80,8 +80,8 @@ void httpServer::tableHeader(stringstream& ss)
8080
void httpServer::getstat1(stringstream& ss)
8181
{
8282
using namespace std::chrono;
83-
WorkingProgress p = g_farm->miningProgress();
84-
SolutionStats s = g_farm->getSolutionStats();
83+
WorkingProgress p = Farm::f().miningProgress();
84+
SolutionStats s = Farm::f().getSolutionStats();
8585
tableHeader(ss);
8686
ss << "<tbody>";
8787
double hashSum = 0.0;

‎libethcore/Farm.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Farm : public FarmFace
6868

6969
Farm(bool hwmon, bool pwron) : m_io_strand(g_io_service), m_collectTimer(g_io_service)
7070
{
71+
m_this = this;
7172
m_hwmon = hwmon;
7273
m_pwron = pwron;
7374

@@ -111,6 +112,8 @@ class Farm : public FarmFace
111112
m_collectTimer.cancel();
112113
}
113114

115+
static Farm& f() { return *m_this; }
116+
114117
/**
115118
* @brief Randomizes the nonce scrambler
116119
*/
@@ -561,9 +564,10 @@ class Farm : public FarmFace
561564
#if defined(__linux)
562565
wrap_amdsysfs_handle* sysfsh = nullptr;
563566
#endif
567+
568+
static Farm* m_this;
564569
};
565570

566571
} // namespace eth
567572
} // namespace dev
568573

569-
extern dev::eth::Farm* g_farm;

‎libpoolprotocols/PoolManager.cpp

+27-24
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ using namespace std;
66
using namespace dev;
77
using namespace eth;
88

9+
PoolManager* PoolManager::m_this = nullptr;
10+
911
PoolManager::PoolManager(
1012
PoolClient* client, MinerType const& minerType, unsigned maxTries, unsigned failoverTimeout)
1113
: m_io_strand(g_io_service), m_failovertimer(g_io_service), m_minerType(minerType)
1214
{
15+
m_this = this;
1316
p_client = client;
1417
m_maxConnectionAttempts = maxTries;
1518
m_failoverTimeout = failoverTimeout;
@@ -37,17 +40,17 @@ PoolManager::PoolManager(
3740
}
3841
}
3942

40-
if (!g_farm->isMining())
43+
if (!Farm::f().isMining())
4144
{
4245
cnote << "Spinning up miners...";
4346
if (m_minerType == MinerType::CL)
44-
g_farm->start("opencl", false);
47+
Farm::f().start("opencl", false);
4548
else if (m_minerType == MinerType::CUDA)
46-
g_farm->start("cuda", false);
49+
Farm::f().start("cuda", false);
4750
else if (m_minerType == MinerType::Mixed)
4851
{
49-
g_farm->start("cuda", false);
50-
g_farm->start("opencl", true);
52+
Farm::f().start("cuda", false);
53+
Farm::f().start("opencl", true);
5154
}
5255
}
5356
});
@@ -86,7 +89,7 @@ PoolManager::PoolManager(
8689
m_epochChanges.fetch_add(1, std::memory_order_relaxed);
8790
}
8891

89-
g_farm->setWork(wp);
92+
Farm::f().setWork(wp);
9093
});
9194

9295
p_client->onSolutionAccepted([&](bool const& stale,
@@ -97,7 +100,7 @@ PoolManager::PoolManager(
97100
<< " " << m_lastConnectedHost + p_client->ActiveEndPoint();
98101
cnote << EthLime "**Accepted" EthReset << (stale ? EthYellow "(stale)" EthReset : "")
99102
<< ss.str();
100-
g_farm->acceptedSolution(stale, miner_index);
103+
Farm::f().acceptedSolution(stale, miner_index);
101104
});
102105

103106
p_client->onSolutionRejected([&](bool const& stale,
@@ -108,10 +111,10 @@ PoolManager::PoolManager(
108111
<< " " << m_lastConnectedHost + p_client->ActiveEndPoint();
109112
cwarn << EthRed "**Rejected" EthReset << (stale ? EthYellow "(stale)" EthReset : "")
110113
<< ss.str();
111-
g_farm->rejectedSolution(miner_index);
114+
Farm::f().rejectedSolution(miner_index);
112115
});
113116

114-
g_farm->onSolutionFound([&](const Solution& sol, unsigned const& miner_index) {
117+
Farm::f().onSolutionFound([&](const Solution& sol, unsigned const& miner_index) {
115118
// Solution should passthrough only if client is
116119
// properly connected. Otherwise we'll have the bad behavior
117120
// to log nonce submission but receive no response
@@ -134,25 +137,25 @@ PoolManager::PoolManager(
134137

135138
return false;
136139
});
137-
g_farm->onMinerRestart([&]() {
140+
Farm::f().onMinerRestart([&]() {
138141
dev::setThreadName("main");
139142
cnote << "Restart miners...";
140143

141-
if (g_farm->isMining())
144+
if (Farm::f().isMining())
142145
{
143146
cnote << "Shutting down miners...";
144-
g_farm->stop();
147+
Farm::f().stop();
145148
}
146149

147150
cnote << "Spinning up miners...";
148151
if (m_minerType == MinerType::CL)
149-
g_farm->start("opencl", false);
152+
Farm::f().start("opencl", false);
150153
else if (m_minerType == MinerType::CUDA)
151-
g_farm->start("cuda", false);
154+
Farm::f().start("cuda", false);
152155
else if (m_minerType == MinerType::Mixed)
153156
{
154-
g_farm->start("cuda", false);
155-
g_farm->start("opencl", true);
157+
Farm::f().start("cuda", false);
158+
Farm::f().start("opencl", true);
156159
}
157160
});
158161
}
@@ -169,10 +172,10 @@ void PoolManager::stop()
169172
if (p_client->isConnected())
170173
p_client->disconnect();
171174

172-
if (g_farm->isMining())
175+
if (Farm::f().isMining())
173176
{
174177
cnote << "Shutting down miners...";
175-
g_farm->stop();
178+
Farm::f().stop();
176179
}
177180
}
178181
}
@@ -245,10 +248,10 @@ void PoolManager::workLoop()
245248
cnote << "No more connections to try. Exiting...";
246249

247250
// Stop mining if applicable
248-
if (g_farm->isMining())
251+
if (Farm::f().isMining())
249252
{
250253
cnote << "Shutting down miners...";
251-
g_farm->stop();
254+
Farm::f().stop();
252255
}
253256

254257
m_running.store(false, std::memory_order_relaxed);
@@ -262,7 +265,7 @@ void PoolManager::workLoop()
262265

263266
if (m_hashrateReportingTimePassed > m_hashrateReportingTime)
264267
{
265-
auto mp = g_farm->miningProgress();
268+
auto mp = Farm::f().miningProgress();
266269
std::string h = toHex(toCompactBigEndian(uint64_t(mp.hashRate), 1));
267270
std::string res = h[0] != '0' ? h : h.substr(1);
268271

@@ -384,14 +387,14 @@ void PoolManager::check_failover_timeout(const boost::system::error_code& ec)
384387

385388
void PoolManager::suspendMining()
386389
{
387-
if (!g_farm->isMining())
390+
if (!Farm::f().isMining())
388391
return;
389392

390-
WorkPackage wp = g_farm->work();
393+
WorkPackage wp = Farm::f().work();
391394
if (!wp)
392395
return;
393396

394-
g_farm->setWork({}); /* suspend by setting empty work package */
397+
Farm::f().setWork({}); /* suspend by setting empty work package */
395398
cnote << "Suspend mining due connection change...";
396399
}
397400

‎libpoolprotocols/PoolManager.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class PoolManager
2222
public:
2323
PoolManager(PoolClient* client, MinerType const& minerType, unsigned maxTries,
2424
unsigned failovertimeout);
25+
static PoolManager& p() { return *m_this; }
2526
void addConnection(URI& conn);
2627
void clearConnections();
2728
Json::Value getConnectionsJson();
@@ -70,9 +71,10 @@ class PoolManager
7071
int m_lastEpoch = 0;
7172
std::atomic<unsigned> m_epochChanges = {0};
7273
double m_lastDifficulty = 0.0;
74+
75+
static PoolManager* m_this;
7376
};
7477

7578
} // namespace eth
7679
} // namespace dev
7780

78-
extern dev::eth::PoolManager* g_mgr;

0 commit comments

Comments
 (0)
This repository has been archived.