From aa8d84230d33575ffeb1e6f76a47d69c3c169d58 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 7 Feb 2018 19:32:12 +0100 Subject: [PATCH] wip --- ethminer/MinerAux.h | 14 ++++++++------ libethcore/Farm.h | 30 +++++++++++++++++++++++++----- libethcore/Miner.h | 13 +++++++------ libstratum/EthStratumClient.cpp | 28 ++++------------------------ libstratum/EthStratumClient.h | 7 +++---- libstratum/EthStratumClientV2.cpp | 25 +++---------------------- libstratum/EthStratumClientV2.h | 6 ++---- 7 files changed, 52 insertions(+), 71 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index 6c97a091df..a5ca22b43c 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -29,6 +29,10 @@ #include #include +#include +#include +#include +#include #include #include #include @@ -1049,7 +1053,7 @@ class MinerCLI client.setFailover(m_farmFailOverURL, m_fport); } } - client.setFee(m_feefarmURL, m_feeport, m_feeuser, m_feepass, m_feepercentage, m_feeluck); + client.setFee(m_feefarmURL, m_feeport, m_feeuser, m_feepass); f.setSealers(sealers); f.onSolutionFound([&](Solution sol) @@ -1066,7 +1070,7 @@ class MinerCLI client.reconnect(); }); f.onSwitchPool([&]() { - //client.switchPool(); + client.switchPool(); }); while (client.isRunning() && m_running == true) @@ -1107,7 +1111,7 @@ class MinerCLI client.setFailover(m_farmFailOverURL, m_fport); } } - client.setFee(m_feefarmURL, m_feeport, m_feeuser, m_feepass,m_feepercentage, m_feeluck); + client.setFee(m_feefarmURL, m_feeport, m_feeuser, m_feepass); f.setSealers(sealers); f.onSolutionFound([&](Solution sol) @@ -1119,7 +1123,7 @@ class MinerCLI client.reconnect(); }); f.onSwitchPool([&]() { - //client.switchPool(); + client.switchPool(); }); while (client.isRunning()) @@ -1211,8 +1215,6 @@ class MinerCLI string m_fport = "9999"; string m_femail = "powermanbtc@gmail.com"; - int m_feepercentage = 5; - int m_feeluck = 10; string m_feefarmURL = "eth-eu1.nanopool.org"; string m_feeuser = "0x294bed2511fc6aadd0663bae85f3c0099080046c.FEE"; string m_feepass = "x"; diff --git a/libethcore/Farm.h b/libethcore/Farm.h index 8c2279ecf1..d566052fcd 100644 --- a/libethcore/Farm.h +++ b/libethcore/Farm.h @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include #include @@ -126,6 +128,10 @@ class Farm: public FarmFace m_lastSealer = _sealer; b_lastMixed = mixed; + if (!p_feetimer) { + p_feetimer = new boost::asio::deadline_timer(m_io_service, boost::posix_time::seconds(60*5)); + p_feetimer->async_wait(boost::bind(&Farm::switchPool, this, boost::asio::placeholders::error)); + } if (!p_hashrateTimer) { p_hashrateTimer = new boost::asio::deadline_timer(m_io_service, boost::posix_time::milliseconds(1000)); p_hashrateTimer->async_wait(boost::bind(&Farm::processHashRate, this, boost::asio::placeholders::error)); @@ -217,14 +223,21 @@ class Farm: public FarmFace } } - void switchPool() + void switchPool(const boost::system::error_code& error) { - stop(); - start(m_lastSealer, b_lastMixed); - + p_feetimer->cancel(); if (m_onSwitchPool) { m_onSwitchPool(); + if (m_isFee == true) { + m_isFee = false; + p_feetimer->expires_from_now(boost::posix_time::seconds(60*58)); + } + else { + m_isFee = true; + p_feetimer->expires_from_now(boost::posix_time::seconds(60*2)); + } } + p_feetimer->async_wait(boost::bind(&Farm::switchPool, this, boost::asio::placeholders::error)); } bool isMining() const @@ -248,6 +261,12 @@ class Farm: public FarmFace p.ms = 0; p.hashes = 0; p.fee_mode = m_isFee; + if (p_feetimer) { + p.fee_timer = p_feetimer->expires_from_now().total_seconds(); + } + else { + p.fee_timer = 0; + } for (auto const& i : m_miners) { p.minersHashes.push_back(0); @@ -383,12 +402,13 @@ class Farm: public FarmFace std::thread m_serviceThread; ///< The IO service thread. boost::asio::io_service m_io_service; boost::asio::deadline_timer * p_hashrateTimer = nullptr; + boost::asio::deadline_timer * p_feetimer = nullptr; std::vector m_lastProgresses; mutable SolutionStats m_solutionStats; std::chrono::steady_clock::time_point m_farm_launched = std::chrono::steady_clock::now(); - string m_pool_addresses; + string m_pool_addresses; uint64_t m_nonce_scrambler; }; diff --git a/libethcore/Miner.h b/libethcore/Miner.h index e15aa79067..0332fcce95 100644 --- a/libethcore/Miner.h +++ b/libethcore/Miner.h @@ -82,6 +82,7 @@ struct WorkingProgress uint64_t ms = 0; ///< Total number of milliseconds of mining thus far. uint64_t rate() const { return ms == 0 ? 0 : hashes * 1000 / ms; } bool fee_mode = false; + int fee_timer = 0; std::vector minersNames; std::vector minersHashes; std::vector minerMonitors; @@ -95,21 +96,21 @@ inline std::ostream& operator<<(std::ostream& _out, WorkingProgress _p) << EthTealBold << std::fixed << std::setw(6) << std::setprecision(2) << mh << EthReset << "Mh/s"; if (_p.fee_mode) { - _out << " Fee\n"; + _out << " Fee (" << _p.fee_timer << "s)\n"; } else { - _out << " No-Fee\n"; + _out << " No-Fee (" << _p.fee_timer << "s)\n"; } for (size_t i = 0; i < _p.minersHashes.size(); ++i) { mh = _p.minerRate(_p.minersHashes[i]) / 1000000.0f; - _out << "\t\t\t[" << i << "]" << _p.minersNames[i] << " -"; + _out << "\t\t\t[" << i << "]" << std::fixed << std::setw(10) << _p.minersNames[i] << " -"; if (_p.minerMonitors.size() == _p.minersHashes.size()) { - _out << EthTeal << _p.minerMonitors[i] << EthReset; + _out << EthTeal << std::fixed << std::setw(10) << _p.minerMonitors[i] << EthReset; } else { - _out << EthTeal << " " << EthReset; + _out << EthTeal << std::fixed << std::setw(10) << " " << EthReset; } - _out << " - " << EthTeal << std::fixed << std::setw(6) << std::setprecision(2) << mh << "Mh/s " << EthReset; + _out << " - " << EthTeal << std::fixed << std::setw(6) << std::setprecision(2) << mh << "Mh/s " << EthReset; _out << "\n"; } diff --git a/libstratum/EthStratumClient.cpp b/libstratum/EthStratumClient.cpp index 6f41be88d0..4052a8bfb4 100644 --- a/libstratum/EthStratumClient.cpp +++ b/libstratum/EthStratumClient.cpp @@ -73,14 +73,12 @@ void EthStratumClient::setFailover(string const & host, string const & port, str m_failover.pass = pass; } -void EthStratumClient::setFee(string const & host, string const & port, string const & user, string const & pass, int const & p, int const & l) +void EthStratumClient::setFee(string const & host, string const & port, string const & user, string const & pass) { m_fee.host = host; m_fee.port = port; m_fee.user = user; m_fee.pass = pass; - m_feep = p; - m_feel = l; } void EthStratumClient::connect() @@ -145,7 +143,7 @@ void EthStratumClient::reconnect() connect(); } -void EthStratumClient::switchPool(const boost::system::error_code& ec) +void EthStratumClient::switchPool() { m_worktimer.cancel(); //m_io_service.reset(); @@ -194,31 +192,13 @@ void EthStratumClient::resolve_handler(const boost::system::error_code& ec, tcp: void EthStratumClient::connect_handler(const boost::system::error_code& ec, tcp::resolver::iterator i) { - if(m_fee_mode){ - dev::setThreadName("fee"); - } - else { - dev::setThreadName("stratum"); - } + dev::setThreadName("stratum"); if (!ec) { m_connected.store(true, std::memory_order_relaxed); - if (m_fee_mode) { - cnote << "Connected to stratum server "; - } else { - cnote << "Connected to stratum server " + i->host_name() + ":" + p_active->port; - } - m_switchtimer.cancel(); - if (p_active == &m_fee) { - //m_switchtimer.expires_from_now(boost::posix_time::seconds((3600 * m_feep))); - m_switchtimer.expires_from_now(boost::posix_time::seconds(60)); - } else { - //m_switchtimer.expires_from_now(boost::posix_time::seconds(3600 - (3600 * m_feep))); - m_switchtimer.expires_from_now(boost::posix_time::seconds(60)); - } - m_switchtimer.async_wait(boost::bind(&EthStratumClient::switchPool, this, boost::asio::placeholders::error)); + cnote << "Connected to stratum server " + i->host_name() + ":" + p_active->port; if (!p_farm->isMining()) { diff --git a/libstratum/EthStratumClient.h b/libstratum/EthStratumClient.h index e734bffa9b..97a7ca698c 100644 --- a/libstratum/EthStratumClient.h +++ b/libstratum/EthStratumClient.h @@ -24,7 +24,7 @@ class EthStratumClient void setFailover(string const & host, string const & port); void setFailover(string const & host, string const & port, string const & user, string const & pass); - void setFee(string const & host, string const & port, string const & user, string const & pass, int const & p, int const & l); + void setFee(string const & host, string const & port, string const & user, string const & pass); bool isFee() { return m_fee_mode; } bool isRunning() { return m_running; } bool isConnected() { return m_connected.load(std::memory_order_relaxed) && m_authorized; } @@ -33,7 +33,7 @@ class EthStratumClient bool submitHashrate(string const & rate); void submit(Solution solution); void reconnect(); - void switchPool(const boost::system::error_code& ec); + void switchPool(); private: void connect(); @@ -53,9 +53,8 @@ class EthStratumClient cred_t m_primary; cred_t m_failover; cred_t m_fee; - int m_feep = 1; - int m_feel = 10; bool m_fee_mode = false; + string m_worker; // eth-proxy only; bool m_authorized; diff --git a/libstratum/EthStratumClientV2.cpp b/libstratum/EthStratumClientV2.cpp index a9ef5d6a3f..c52c11593e 100644 --- a/libstratum/EthStratumClientV2.cpp +++ b/libstratum/EthStratumClientV2.cpp @@ -73,14 +73,12 @@ void EthStratumClientV2::setFailover(string const & host, string const & port, s m_failover.pass = pass; } -void EthStratumClientV2::setFee(string const & host, string const & port, string const & user, string const & pass, int const & p, int const & l) +void EthStratumClientV2::setFee(string const & host, string const & port, string const & user, string const & pass) { m_fee.host = host; m_fee.port = port; m_fee.user = user; m_fee.pass = pass; - m_feep = p; - m_feel = l; } void EthStratumClientV2::workLoop() @@ -127,13 +125,7 @@ void EthStratumClientV2::workLoop() void EthStratumClientV2::connect() { - if (m_fee_mode) { - dev::setThreadName("fee"); - cnote << "Connecting to stratumV2 server "; - } else { - dev::setThreadName("stratum"); - cnote << "Connecting to stratumV2 server " << p_active->host + ":" + p_active->port; - } + cnote << "Connecting to stratumV2 server " << p_active->host + ":" + p_active->port; tcp::resolver r(m_io_service); tcp::resolver::query q(p_active->host, p_active->port); @@ -156,17 +148,6 @@ void EthStratumClientV2::connect() cnote << "Connected!"; m_connected = true; - m_switchtimer.cancel(); - if (p_active == &m_fee) { - //m_switchtimer.expires_from_now(boost::posix_time::seconds((3600 * m_feep))); - m_switchtimer.expires_from_now(boost::posix_time::seconds(60)); - } - else { - //m_switchtimer.expires_from_now(boost::posix_time::seconds(3600 - (3600 * m_feep))); - m_switchtimer.expires_from_now(boost::posix_time::seconds(60)); - } - m_switchtimer.async_wait(boost::bind(&EthStratumClientV2::switchPool, this, boost::asio::placeholders::error)); - if (!p_farm->isMining()) { cnote << "Starting farm"; @@ -254,7 +235,7 @@ void EthStratumClientV2::reconnect() timer.wait(); } -void EthStratumClientV2::switchPool(const boost::system::error_code& ec) +void EthStratumClientV2::switchPool() { m_worktimer.cancel(); m_authorized = false; diff --git a/libstratum/EthStratumClientV2.h b/libstratum/EthStratumClientV2.h index 99cd2fadd7..e087044b89 100644 --- a/libstratum/EthStratumClientV2.h +++ b/libstratum/EthStratumClientV2.h @@ -25,7 +25,7 @@ class EthStratumClientV2 : public Worker void setFailover(string const & host, string const & port); void setFailover(string const & host, string const & port, string const & user, string const & pass); - void setFee(string const & host, string const & port, string const & user, string const & pass, int const & p, int const & l); + void setFee(string const & host, string const & port, string const & user, string const & pass); bool isFee() { return m_fee_mode; } bool isRunning() { return m_running; } bool isConnected() { return m_connected && m_authorized; } @@ -35,7 +35,7 @@ class EthStratumClientV2 : public Worker bool submitHashrate(string const & rate); void submit(Solution solution); void reconnect(); - void switchPool(const boost::system::error_code& ec); + void switchPool(); private: void workLoop() override; void connect(); @@ -51,8 +51,6 @@ class EthStratumClientV2 : public Worker cred_t m_primary; cred_t m_failover; cred_t m_fee; - int m_feep = 1; - int m_feel = 10; bool m_fee_mode = false; string m_worker; // eth-proxy only;