mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-22 19:39:22 +00:00
Removed unnecessary lock
This commit is contained in:
parent
3554adf0c1
commit
f79be1b343
4 changed files with 20 additions and 27 deletions
|
@ -615,7 +615,7 @@ void P2PServer::load_peer_list()
|
|||
|
||||
void P2PServer::load_monerod_peer_list()
|
||||
{
|
||||
const Params::Host host = m_pool->current_host();
|
||||
const Params::Host& host = m_pool->current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "/get_peer_list", host.m_rpcLogin, m_socks5Proxy,
|
||||
[this](const char* data, size_t size, double)
|
||||
|
@ -1184,7 +1184,7 @@ void P2PServer::check_host()
|
|||
uint32_t counter = 5;
|
||||
for (const PoolBlock* b = side_chain.chainTip(); b && (b->m_txinGenHeight >= height + 2); b = side_chain.find_block(b->m_parent)) {
|
||||
if (--counter == 0) {
|
||||
const Params::Host host = m_pool->current_host();
|
||||
const Params::Host& host = m_pool->current_host();
|
||||
LOGERR(1, host.m_displayName << " seems to be stuck, reconnecting");
|
||||
m_pool->reconnect_to_host();
|
||||
return;
|
||||
|
@ -1197,7 +1197,7 @@ void P2PServer::check_host()
|
|||
// If there were no ZMQ messages in the last 5 minutes, then the node is probably stuck
|
||||
if (cur_time >= last_active + 300) {
|
||||
const uint64_t dt = static_cast<uint64_t>(cur_time - last_active);
|
||||
const Params::Host host = m_pool->current_host();
|
||||
const Params::Host& host = m_pool->current_host();
|
||||
LOGERR(1, "no ZMQ messages received from " << host.m_displayName << " in the last " << dt << " seconds, check your monerod/p2pool/network/firewall setup!!!");
|
||||
m_pool->reconnect_to_host();
|
||||
}
|
||||
|
|
|
@ -75,7 +75,6 @@ p2pool::p2pool(int argc, char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
m_currentHost = p->m_hosts.front();
|
||||
m_currentHostIndex = 0;
|
||||
|
||||
m_hostPing.resize(p->m_hosts.size());
|
||||
|
@ -126,7 +125,6 @@ p2pool::p2pool(int argc, char* argv[])
|
|||
}
|
||||
m_reconnectToHostAsync.data = this;
|
||||
|
||||
uv_rwlock_init_checked(&m_currentHostLock);
|
||||
uv_rwlock_init_checked(&m_mainchainLock);
|
||||
uv_rwlock_init_checked(&m_minerDataLock);
|
||||
uv_rwlock_init_checked(&m_ZMQReaderLock);
|
||||
|
@ -186,7 +184,6 @@ p2pool::~p2pool()
|
|||
}
|
||||
#endif
|
||||
|
||||
uv_rwlock_destroy(&m_currentHostLock);
|
||||
uv_rwlock_destroy(&m_mainchainLock);
|
||||
uv_rwlock_destroy(&m_minerDataLock);
|
||||
uv_rwlock_destroy(&m_ZMQReaderLock);
|
||||
|
@ -225,7 +222,7 @@ void p2pool::update_host_ping(const std::string& display_name, double ping)
|
|||
|
||||
void p2pool::print_hosts() const
|
||||
{
|
||||
const Params::Host host = current_host();
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
for (size_t i = 0, n = m_params->m_hosts.size(); i < n; ++i) {
|
||||
const Params::Host& h = m_params->m_hosts[i];
|
||||
|
@ -344,7 +341,7 @@ void p2pool::handle_miner_data(MinerData& data)
|
|||
m_updateSeed = true;
|
||||
update_median_timestamp();
|
||||
|
||||
const Params::Host host = current_host();
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
LOGINFO(2,
|
||||
"new miner data\n---------------------------------------------------------------------------------------------------------------" <<
|
||||
|
@ -629,7 +626,7 @@ void p2pool::submit_block() const
|
|||
}
|
||||
request.append("\"]}");
|
||||
|
||||
const Params::Host host = current_host();
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, request, host.m_rpcLogin, m_params->m_socks5Proxy,
|
||||
[height, diff, template_id, nonce, extra_nonce, sidechain_id, is_external](const char* data, size_t size, double)
|
||||
|
@ -742,7 +739,7 @@ void p2pool::download_block_headers(uint64_t current_height)
|
|||
char buf[log::Stream::BUF_SIZE + 1] = {};
|
||||
log::Stream s(buf);
|
||||
|
||||
const Params::Host host = current_host();
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
// First download 2 RandomX seeds
|
||||
const uint64_t seed_heights[2] = { prev_seed_height, seed_height };
|
||||
|
@ -905,7 +902,7 @@ void p2pool::stratum_on_block()
|
|||
|
||||
void p2pool::get_info()
|
||||
{
|
||||
const Params::Host host = current_host();
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_info\"}", host.m_rpcLogin, m_params->m_socks5Proxy,
|
||||
[this](const char* data, size_t size, double)
|
||||
|
@ -1021,7 +1018,7 @@ void p2pool::parse_get_info_rpc(const char* data, size_t size)
|
|||
|
||||
void p2pool::get_version()
|
||||
{
|
||||
const Params::Host host = current_host();
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_version\"}", host.m_rpcLogin, m_params->m_socks5Proxy,
|
||||
[this](const char* data, size_t size, double)
|
||||
|
@ -1098,7 +1095,7 @@ void p2pool::get_miner_data(bool retry)
|
|||
}
|
||||
m_getMinerDataPending = true;
|
||||
|
||||
const Params::Host host = current_host();
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_miner_data\"}", host.m_rpcLogin, m_params->m_socks5Proxy,
|
||||
[this, host](const char* data, size_t size, double tcp_ping)
|
||||
|
@ -1625,12 +1622,10 @@ bool p2pool::zmq_running() const
|
|||
return m_ZMQReader && m_ZMQReader->is_running();
|
||||
}
|
||||
|
||||
Params::Host p2pool::switch_host()
|
||||
const Params::Host& p2pool::switch_host()
|
||||
{
|
||||
WriteLock lock(m_currentHostLock);
|
||||
|
||||
m_currentHost = m_params->m_hosts[++m_currentHostIndex % m_params->m_hosts.size()];
|
||||
return m_currentHost;
|
||||
const std::vector<Params::Host>& v = m_params->m_hosts;
|
||||
return v[++m_currentHostIndex % v.size()];
|
||||
}
|
||||
|
||||
void p2pool::reconnect_to_host()
|
||||
|
@ -1645,7 +1640,7 @@ void p2pool::reconnect_to_host()
|
|||
return;
|
||||
}
|
||||
|
||||
const Params::Host new_host = switch_host();
|
||||
const Params::Host& new_host = switch_host();
|
||||
|
||||
WriteLock lock(m_ZMQReaderLock);
|
||||
|
||||
|
|
12
src/p2pool.h
12
src/p2pool.h
|
@ -50,10 +50,10 @@ public:
|
|||
BlockTemplate& block_template() { return *m_blockTemplate; }
|
||||
SideChain& side_chain() { return *m_sideChain; }
|
||||
|
||||
FORCEINLINE Params::Host current_host() const
|
||||
FORCEINLINE const Params::Host& current_host() const
|
||||
{
|
||||
ReadLock lock(m_currentHostLock);
|
||||
return m_currentHost;
|
||||
const std::vector<Params::Host>& v = m_params->m_hosts;
|
||||
return v[m_currentHostIndex % v.size()];
|
||||
}
|
||||
|
||||
void update_host_ping(const std::string& display_name, double ping);
|
||||
|
@ -114,7 +114,7 @@ private:
|
|||
p2pool(const p2pool&) = delete;
|
||||
p2pool(p2pool&&) = delete;
|
||||
|
||||
Params::Host switch_host();
|
||||
const Params::Host& switch_host();
|
||||
|
||||
static void on_submit_block(uv_async_t* async) { reinterpret_cast<p2pool*>(async->data)->submit_block(); }
|
||||
static void on_update_block_template(uv_async_t* async) { reinterpret_cast<p2pool*>(async->data)->update_block_template(); }
|
||||
|
@ -128,9 +128,7 @@ private:
|
|||
const Params* m_params;
|
||||
std::vector<double> m_hostPing;
|
||||
|
||||
mutable uv_rwlock_t m_currentHostLock;
|
||||
Params::Host m_currentHost;
|
||||
uint32_t m_currentHostIndex;
|
||||
std::atomic<uint32_t> m_currentHostIndex;
|
||||
|
||||
p2pool_api* m_api;
|
||||
SideChain* m_sideChain;
|
||||
|
|
|
@ -447,7 +447,7 @@ bool RandomX_Hasher_RPC::calculate(const void* data_ptr, size_t size, uint64_t h
|
|||
volatile bool done = false;
|
||||
|
||||
const Params& params = m_pool->params();
|
||||
const Params::Host host = m_pool->current_host();
|
||||
const Params::Host& host = m_pool->current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, params.m_socks5Proxy,
|
||||
[&result, &h](const char* data, size_t size, double)
|
||||
|
|
Loading…
Reference in a new issue