mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-22 19:39:22 +00:00
SideChain: submit blocks to monerod in more cases
This commit is contained in:
parent
ca976e5998
commit
0d439e7712
3 changed files with 26 additions and 6 deletions
|
@ -1004,12 +1004,7 @@ void p2pool::api_update_block_found(const ChainMain* data)
|
|||
const difficulty_type total_hashes = m_sideChain->total_hashes();
|
||||
difficulty_type diff;
|
||||
|
||||
if (data) {
|
||||
{
|
||||
ReadLock lock(m_mainchainLock);
|
||||
diff = m_mainchainByHeight[data->height].difficulty;
|
||||
}
|
||||
|
||||
if (data && get_difficulty_at_height(data->height, diff)) {
|
||||
std::ofstream f(FOUND_BLOCKS_FILE, std::ios::app);
|
||||
if (f.is_open()) {
|
||||
f << cur_time << ' ' << data->height << ' ' << data->id << ' ' << diff << ' ' << total_hashes << '\n';
|
||||
|
@ -1047,6 +1042,19 @@ void p2pool::api_update_block_found(const ChainMain* data)
|
|||
api_update_stats_mod();
|
||||
}
|
||||
|
||||
bool p2pool::get_difficulty_at_height(uint64_t height, difficulty_type& diff)
|
||||
{
|
||||
ReadLock lock(m_mainchainLock);
|
||||
|
||||
auto it = m_mainchainByHeight.find(height);
|
||||
if (it == m_mainchainByHeight.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
diff = it->second.difficulty;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void on_signal(uv_signal_t* handle, int signum)
|
||||
{
|
||||
p2pool* pool = reinterpret_cast<p2pool*>(handle->data);
|
||||
|
|
|
@ -74,6 +74,8 @@ public:
|
|||
|
||||
void api_update_block_found(const ChainMain* data);
|
||||
|
||||
bool get_difficulty_at_height(uint64_t height, difficulty_type& diff);
|
||||
|
||||
private:
|
||||
p2pool(const p2pool&) = delete;
|
||||
p2pool(p2pool&&) = delete;
|
||||
|
|
|
@ -416,6 +416,16 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_
|
|||
LOGINFO(0, log::LightGreen() << "add_external_block: block " << block.m_sidechainId << " has enough PoW for Monero network, submitting it");
|
||||
m_pool->submit_block_async(block.m_mainChainData);
|
||||
}
|
||||
else {
|
||||
difficulty_type diff;
|
||||
if (!m_pool->get_difficulty_at_height(block.m_txinGenHeight, diff)) {
|
||||
LOGWARN(3, "add_external_block: couldn't get mainchain difficulty for height = " << block.m_txinGenHeight);
|
||||
}
|
||||
else if (diff.check_pow(pow_hash)) {
|
||||
LOGINFO(0, log::LightGreen() << "add_external_block: block " << block.m_sidechainId << " has enough PoW for Monero height " << block.m_txinGenHeight << ", submitting it");
|
||||
m_pool->submit_block_async(block.m_mainChainData);
|
||||
}
|
||||
}
|
||||
|
||||
if (!block.m_difficulty.check_pow(pow_hash)) {
|
||||
LOGWARN(3, "add_external_block: not enough PoW for height = " << block.m_sidechainHeight << ", mainchain height " << block.m_txinGenHeight);
|
||||
|
|
Loading…
Reference in a new issue