p2pool: submit block from the main thread only

pull/5/head
SChernykh 3 years ago
parent 8f93adf7a1
commit a38a7be73f

@ -44,6 +44,7 @@ p2pool::p2pool(int argc, char* argv[])
: m_stopped(false)
, m_params(new Params(argc, argv))
, m_updateSeed(true)
, m_submitBlockData{}
{
if (!m_params->m_wallet.valid()) {
LOGERR(1, "Invalid wallet address. Try \"p2pool --help\".");
@ -59,7 +60,14 @@ p2pool::p2pool(int argc, char* argv[])
LOGWARN(1, "Mining to a stagenet wallet address");
}
int err = uv_async_init(uv_default_loop_checked(), &m_blockTemplateAsync, on_update_block_template);
int err = uv_async_init(uv_default_loop_checked(), &m_submitBlockAsync, on_submit_block);
if (err) {
LOGERR(1, "uv_async_init failed, error " << uv_err_name(err));
panic();
}
m_submitBlockAsync.data = this;
err = uv_async_init(uv_default_loop_checked(), &m_blockTemplateAsync, on_update_block_template);
if (err) {
LOGERR(1, "uv_async_init failed, error " << uv_err_name(err));
panic();
@ -86,6 +94,7 @@ p2pool::p2pool(int argc, char* argv[])
p2pool::~p2pool()
{
uv_close(reinterpret_cast<uv_handle_t*>(&m_submitBlockAsync), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&m_blockTemplateAsync), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&m_stopAsync), nullptr);
uv_rwlock_destroy(&m_mainchainLock);
@ -245,8 +254,22 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra)
}
}
void p2pool::submit_block(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce) const
void p2pool::submit_block_async(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce)
{
m_submitBlockData = { template_id, nonce, extra_nonce };
const int err = uv_async_send(&m_submitBlockAsync);
if (err) {
LOGERR(1, "uv_async_send failed, error " << uv_err_name(err));
}
}
void p2pool::submit_block() const
{
const uint32_t template_id = m_submitBlockData.template_id;
uint32_t nonce = m_submitBlockData.nonce;
uint32_t extra_nonce = m_submitBlockData.extra_nonce;
const uint64_t height = m_blockTemplate->height();
const difficulty_type diff = m_blockTemplate->difficulty();
LOGINFO(0, "submit_block: height = " << height << ", template id = " << template_id << ", nonce = " << nonce << ", extra_nonce = " << extra_nonce);

@ -60,7 +60,7 @@ public:
virtual void handle_miner_data(MinerData& data) override;
virtual void handle_chain_main(ChainMain& data, const char* extra) override;
void submit_block(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce) const;
void submit_block_async(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce);
void submit_sidechain_block(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce);
void update_block_template_async();
@ -74,9 +74,12 @@ private:
p2pool(const p2pool&) = delete;
p2pool(p2pool&&) = delete;
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(); }
static void on_stop(uv_async_t*) {}
void submit_block() const;
bool m_stopped;
Params* m_params;
@ -110,6 +113,13 @@ private:
ConsoleCommands* m_consoleCommands;
struct {
uint32_t template_id;
uint32_t nonce;
uint32_t extra_nonce;
} m_submitBlockData;
uv_async_t m_submitBlockAsync;
uv_async_t m_blockTemplateAsync;
uv_async_t m_stopAsync;
};

@ -410,7 +410,7 @@ void StratumServer::on_share_found(uv_work_t* req)
// First check if we found a mainnet block
if (difficulty.check_pow(pow_hash)) {
pool->submit_block(share->m_templateId, share->m_nonce, share->m_extraNonce);
pool->submit_block_async(share->m_templateId, share->m_nonce, share->m_extraNonce);
block.update_tx_keys();
}

Loading…
Cancel
Save