mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-22 19:39:22 +00:00
Fixed a potential deadlock
This commit is contained in:
parent
658d756120
commit
9015106ca2
1 changed files with 32 additions and 31 deletions
|
@ -346,16 +346,17 @@ void p2pool::handle_miner_data(MinerData& data)
|
||||||
cleanup_mainchain_data(data.height);
|
cleanup_mainchain_data(data.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
update_aux_data(hash());
|
|
||||||
|
|
||||||
data.tx_backlog.clear();
|
data.tx_backlog.clear();
|
||||||
data.time_received = std::chrono::high_resolution_clock::now();
|
data.time_received = std::chrono::high_resolution_clock::now();
|
||||||
{
|
{
|
||||||
WriteLock lock(m_minerDataLock);
|
WriteLock lock(m_minerDataLock);
|
||||||
|
data.aux_chains = m_minerData.aux_chains;
|
||||||
|
data.aux_nonce = m_minerData.aux_nonce;
|
||||||
m_minerData = data;
|
m_minerData = data;
|
||||||
}
|
}
|
||||||
m_updateSeed = true;
|
m_updateSeed = true;
|
||||||
update_median_timestamp();
|
update_median_timestamp();
|
||||||
|
update_aux_data(hash());
|
||||||
|
|
||||||
const Params::Host& host = current_host();
|
const Params::Host& host = current_host();
|
||||||
|
|
||||||
|
@ -506,40 +507,40 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra)
|
||||||
|
|
||||||
void p2pool::update_aux_data(const hash& chain_id)
|
void p2pool::update_aux_data(const hash& chain_id)
|
||||||
{
|
{
|
||||||
|
MinerData data;
|
||||||
|
{
|
||||||
|
ReadLock lock(m_mergeMiningClientsLock);
|
||||||
|
|
||||||
|
if (!m_mergeMiningClients.empty()) {
|
||||||
|
data.aux_chains.reserve(m_mergeMiningClients.size());
|
||||||
|
|
||||||
|
std::vector<hash> tmp;
|
||||||
|
tmp.reserve(m_mergeMiningClients.size() + 1);
|
||||||
|
|
||||||
|
for (const MergeMiningClient* c : m_mergeMiningClients) {
|
||||||
|
data.aux_chains.emplace_back(c->aux_id(), c->aux_data(), c->aux_diff());
|
||||||
|
tmp.emplace_back(c->aux_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp.emplace_back(m_sideChain->consensus_hash());
|
||||||
|
|
||||||
|
if (!find_aux_nonce(tmp, data.aux_nonce)) {
|
||||||
|
LOGERR(1, "Failed to find the aux nonce for merge mining. Merge mining will be off this round.");
|
||||||
|
data.aux_chains.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
WriteLock lock(m_minerDataLock);
|
WriteLock lock(m_minerDataLock);
|
||||||
|
|
||||||
MinerData& data = m_minerData;
|
if ((m_minerData.aux_nonce == data.aux_nonce) && (m_minerData.aux_chains == data.aux_chains)) {
|
||||||
|
|
||||||
const std::vector<AuxChainData> old_data = data.aux_chains;
|
|
||||||
data.aux_chains.clear();
|
|
||||||
|
|
||||||
{
|
|
||||||
ReadLock lock2(m_mergeMiningClientsLock);
|
|
||||||
|
|
||||||
if (!m_mergeMiningClients.empty()) {
|
|
||||||
data.aux_chains.reserve(m_mergeMiningClients.size());
|
|
||||||
|
|
||||||
std::vector<hash> tmp;
|
|
||||||
tmp.reserve(m_mergeMiningClients.size() + 1);
|
|
||||||
|
|
||||||
for (const MergeMiningClient* c : m_mergeMiningClients) {
|
|
||||||
data.aux_chains.emplace_back(c->aux_id(), c->aux_data(), c->aux_diff());
|
|
||||||
tmp.emplace_back(c->aux_id());
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp.emplace_back(m_sideChain->consensus_hash());
|
|
||||||
|
|
||||||
if (!find_aux_nonce(tmp, data.aux_nonce)) {
|
|
||||||
LOGERR(1, "Failed to find the aux nonce for merge mining. Merge mining will be off this round.");
|
|
||||||
data.aux_chains.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (old_data == data.aux_chains) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_minerData.aux_chains = data.aux_chains;
|
||||||
|
m_minerData.aux_nonce = data.aux_nonce;
|
||||||
|
LOGINFO(5, "update_aux_data: n_aux_chains = " << m_minerData.aux_chains.size() << ", aux_nonce = " << m_minerData.aux_nonce);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chain_id.empty()) {
|
if (!chain_id.empty()) {
|
||||||
|
|
Loading…
Reference in a new issue