Skip to content

Commit c605ef0

Browse files
committed
dgb: delegate heartbeat_log diagnostics arithmetic to SSOT headers
Rewire the three open-coded arithmetic sites in NodeImpl::heartbeat_log onto the already-landed fenced SSOTs, eliminating the drift risk the SSOT headers were lifted to close (#389 pool_efficiency, #390 etb): - stale_prop -> dgb::compute_stale_prop() - real_pool_hs -> dgb::compute_real_pool_hashrate() - etb_secs -> dgb::compute_expected_time_to_block() Byte-identical by construction: each call reproduces the exact inline expression (same guards, same div-by-~0 floor at stale_prop>=0.999, same 1e18 average-attempts overflow sentinel). Operator-facing diagnostics only; consensus-neutral, no value semantics changed. Math is already pinned against the p2pool-dgb-scrypt oracle by the #389/#390 SSOT KATs. Per-coin isolation: src/impl/dgb/ only.
1 parent 31937e8 commit c605ef0

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/impl/dgb/node.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <sharechain/prepared_list.hpp>
88
#include <impl/dgb/get_shares_walk.hpp>
99
#include <impl/dgb/download_stops.hpp>
10+
#include <impl/dgb/pool_efficiency.hpp>
11+
#include <impl/dgb/expected_time_to_block.hpp>
1012

1113
#include <algorithm>
1214
#include <filesystem>
@@ -1718,8 +1720,7 @@ void NodeImpl::heartbeat_log()
17181720
}
17191721
}
17201722
}
1721-
double stale_prop = total_recent > 0
1722-
? static_cast<double>(orphan_count + doa_count) / total_recent : 0.0;
1723+
double stale_prop = dgb::compute_stale_prop(orphan_count, doa_count, total_recent);
17231724

17241725
{
17251726
std::ostringstream shares_line;
@@ -1763,8 +1764,7 @@ void NodeImpl::heartbeat_log()
17631764
std::min(height - 1, static_cast<int>(m_tracker.m_params->target_lookbehind)),
17641765
/*min_work=*/false);
17651766
double pool_hs = static_cast<double>(aps.GetLow64());
1766-
double real_pool_hs = (stale_prop < 0.999 && pool_hs > 0)
1767-
? pool_hs / (1.0 - stale_prop) : pool_hs;
1767+
double real_pool_hs = dgb::compute_real_pool_hashrate(pool_hs, stale_prop);
17681768
double etb_secs = 0;
17691769
uint32_t block_bits = 0;
17701770
if (!m_best_share_hash.IsNull() && m_tracker.chain.contains(m_best_share_hash)) {
@@ -1775,9 +1775,10 @@ void NodeImpl::heartbeat_log()
17751775
if (real_pool_hs > 0 && block_bits != 0) {
17761776
auto block_target = chain::bits_to_target(block_bits);
17771777
auto block_aps = chain::target_to_average_attempts(block_target);
1778-
etb_secs = static_cast<double>(block_aps.GetLow64()) / real_pool_hs;
1779-
if (block_aps.IsNull() && !block_target.IsNull())
1780-
etb_secs = 1e18;
1778+
etb_secs = dgb::compute_expected_time_to_block(
1779+
static_cast<double>(block_aps.GetLow64()), real_pool_hs,
1780+
/*average_attempts_overflowed=*/block_aps.IsNull(),
1781+
/*block_target_nonzero=*/!block_target.IsNull());
17811782
}
17821783
LOG_INFO << " Pool: " << format_hashrate(real_pool_hs)
17831784
<< " Stale rate: " << std::fixed << std::setprecision(1)

0 commit comments

Comments
 (0)