mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-23 03:49:23 +00:00
Reset stratum share counters after initial sync
This commit is contained in:
parent
25e5f80a81
commit
cc6ce4a366
4 changed files with 32 additions and 8 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "intrin_portable.h"
|
||||
#include "keccak.h"
|
||||
#include "p2p_server.h"
|
||||
#include "stratum_server.h"
|
||||
#include "params.h"
|
||||
#include "json_parsers.h"
|
||||
#include <rapidjson/document.h>
|
||||
|
@ -985,7 +986,8 @@ void SideChain::verify_loop(PoolBlock* block)
|
|||
|
||||
// This block is now verified
|
||||
|
||||
if (is_longer_chain(highest_block, block)) {
|
||||
bool is_alternative;
|
||||
if (is_longer_chain(highest_block, block, is_alternative)) {
|
||||
highest_block = block;
|
||||
}
|
||||
else if (highest_block && (highest_block->m_sidechainHeight > block->m_sidechainHeight)) {
|
||||
|
@ -1330,7 +1332,8 @@ void SideChain::update_chain_tip(PoolBlock* block)
|
|||
return;
|
||||
}
|
||||
|
||||
if (is_longer_chain(m_chainTip, block)) {
|
||||
bool is_alternative;
|
||||
if (is_longer_chain(m_chainTip, block, is_alternative)) {
|
||||
difficulty_type diff;
|
||||
if (get_difficulty(block, m_difficultyData, diff)) {
|
||||
m_chainTip = block;
|
||||
|
@ -1343,6 +1346,12 @@ void SideChain::update_chain_tip(PoolBlock* block)
|
|||
block->m_wantBroadcast = true;
|
||||
if (m_pool) {
|
||||
m_pool->update_block_template_async();
|
||||
|
||||
// Reset stratum share counters when switching to an alternative chain to avoid confusion
|
||||
StratumServer* s = m_pool->stratum_server();
|
||||
if (s && is_alternative) {
|
||||
s->reset_share_counters();
|
||||
}
|
||||
}
|
||||
prune_old_blocks();
|
||||
}
|
||||
|
@ -1405,8 +1414,10 @@ PoolBlock* SideChain::get_parent(const PoolBlock* block)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool SideChain::is_longer_chain(const PoolBlock* block, const PoolBlock* candidate)
|
||||
bool SideChain::is_longer_chain(const PoolBlock* block, const PoolBlock* candidate, bool& is_alternative)
|
||||
{
|
||||
is_alternative = false;
|
||||
|
||||
if (!candidate || !candidate->m_verified || candidate->m_invalid) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1449,6 +1460,8 @@ bool SideChain::is_longer_chain(const PoolBlock* block, const PoolBlock* candida
|
|||
}
|
||||
|
||||
// They're on totally different chains. Compare total difficulties over the last m_chainWindowSize blocks
|
||||
is_alternative = true;
|
||||
|
||||
difficulty_type block_total_diff;
|
||||
difficulty_type candidate_total_diff;
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ private:
|
|||
PoolBlock* get_parent(const PoolBlock* block);
|
||||
|
||||
// Checks if "candidate" has longer (higher difficulty) chain than "block"
|
||||
bool is_longer_chain(const PoolBlock* block, const PoolBlock* candidate);
|
||||
bool is_longer_chain(const PoolBlock* block, const PoolBlock* candidate, bool& is_alternative);
|
||||
void update_depths(PoolBlock* block);
|
||||
void prune_old_blocks();
|
||||
|
||||
|
|
|
@ -439,6 +439,13 @@ void StratumServer::print_status()
|
|||
print_stratum_status();
|
||||
}
|
||||
|
||||
void StratumServer::reset_share_counters()
|
||||
{
|
||||
m_cumulativeHashesAtLastShare = 0;
|
||||
m_cumulativeFoundSharesDiff = 0.0;
|
||||
m_totalFoundShares = 0;
|
||||
}
|
||||
|
||||
void StratumServer::print_stratum_status() const
|
||||
{
|
||||
uint64_t hashes_15m, hashes_1h, hashes_24h, total_hashes;
|
||||
|
@ -473,8 +480,9 @@ void StratumServer::print_stratum_status() const
|
|||
const uint64_t hashrate_24h = (dt_24h > 0) ? (hashes_24h / dt_24h) : 0;
|
||||
|
||||
double average_effort = 0.0;
|
||||
if (m_cumulativeFoundSharesDiff > 0.0) {
|
||||
average_effort = static_cast<double>(m_cumulativeHashesAtLastShare) * 100.0 / m_cumulativeFoundSharesDiff;
|
||||
const double diff = m_cumulativeFoundSharesDiff;
|
||||
if (diff > 0.0) {
|
||||
average_effort = static_cast<double>(m_cumulativeHashesAtLastShare) * 100.0 / diff;
|
||||
}
|
||||
|
||||
LOGINFO(0, "status" <<
|
||||
|
@ -1028,8 +1036,9 @@ void StratumServer::api_update_local_stats(time_t timestamp)
|
|||
const uint64_t hashrate_24h = (dt_24h > 0) ? (hashes_24h / dt_24h) : 0;
|
||||
|
||||
double average_effort = 0.0;
|
||||
if (m_cumulativeFoundSharesDiff > 0.0) {
|
||||
average_effort = static_cast<double>(m_cumulativeHashesAtLastShare) * 100.0 / m_cumulativeFoundSharesDiff;
|
||||
const double diff = m_cumulativeFoundSharesDiff;
|
||||
if (diff > 0.0) {
|
||||
average_effort = static_cast<double>(m_cumulativeHashesAtLastShare) * 100.0 / diff;
|
||||
}
|
||||
|
||||
int shares_found = m_totalFoundShares;
|
||||
|
|
|
@ -75,6 +75,8 @@ public:
|
|||
|
||||
void print_status() override;
|
||||
|
||||
void reset_share_counters();
|
||||
|
||||
private:
|
||||
void print_stratum_status() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue