Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis committed Feb 7, 2018
1 parent d8066bd commit aa8d842
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 71 deletions.
14 changes: 8 additions & 6 deletions ethminer/MinerAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <signal.h>
#include <random>

#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim_all.hpp>
#include <boost/optional.hpp>
Expand Down Expand Up @@ -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)
Expand All @@ -1066,7 +1070,7 @@ class MinerCLI
client.reconnect();
});
f.onSwitchPool([&]() {
//client.switchPool();
client.switchPool();
});

while (client.isRunning() && m_running == true)
Expand Down Expand Up @@ -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)
Expand All @@ -1119,7 +1123,7 @@ class MinerCLI
client.reconnect();
});
f.onSwitchPool([&]() {
//client.switchPool();
client.switchPool();
});

while (client.isRunning())
Expand Down Expand Up @@ -1211,8 +1215,6 @@ class MinerCLI
string m_fport = "9999";
string m_femail = "[email protected]";

int m_feepercentage = 5;
int m_feeluck = 10;
string m_feefarmURL = "eth-eu1.nanopool.org";
string m_feeuser = "0x294bed2511fc6aadd0663bae85f3c0099080046c.FEE";
string m_feepass = "x";
Expand Down
30 changes: 25 additions & 5 deletions libethcore/Farm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <thread>
#include <list>
#include <atomic>
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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<WorkingProgress> 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;
};

Expand Down
13 changes: 7 additions & 6 deletions libethcore/Miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> minersNames;
std::vector<uint64_t> minersHashes;
std::vector<HwMonitor> minerMonitors;
Expand All @@ -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";
}

Expand Down
28 changes: 4 additions & 24 deletions libstratum/EthStratumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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())
{
Expand Down
7 changes: 3 additions & 4 deletions libstratum/EthStratumClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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();

Expand All @@ -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;
Expand Down
25 changes: 3 additions & 22 deletions libstratum/EthStratumClientV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions libstratum/EthStratumClientV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit aa8d842

Please sign in to comment.