From c605ef0c202fb5ff7feead6157c49c4fdc650e68 Mon Sep 17 00:00:00 2001 From: frstrtr Date: Wed, 24 Jun 2026 04:43:48 +0000 Subject: [PATCH] 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. --- src/impl/dgb/node.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/impl/dgb/node.cpp b/src/impl/dgb/node.cpp index 16c69d34e..8740c89ad 100644 --- a/src/impl/dgb/node.cpp +++ b/src/impl/dgb/node.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -1718,8 +1720,7 @@ void NodeImpl::heartbeat_log() } } } - double stale_prop = total_recent > 0 - ? static_cast(orphan_count + doa_count) / total_recent : 0.0; + double stale_prop = dgb::compute_stale_prop(orphan_count, doa_count, total_recent); { std::ostringstream shares_line; @@ -1763,8 +1764,7 @@ void NodeImpl::heartbeat_log() std::min(height - 1, static_cast(m_tracker.m_params->target_lookbehind)), /*min_work=*/false); double pool_hs = static_cast(aps.GetLow64()); - double real_pool_hs = (stale_prop < 0.999 && pool_hs > 0) - ? pool_hs / (1.0 - stale_prop) : pool_hs; + double real_pool_hs = dgb::compute_real_pool_hashrate(pool_hs, stale_prop); double etb_secs = 0; uint32_t block_bits = 0; if (!m_best_share_hash.IsNull() && m_tracker.chain.contains(m_best_share_hash)) { @@ -1775,9 +1775,10 @@ void NodeImpl::heartbeat_log() if (real_pool_hs > 0 && block_bits != 0) { auto block_target = chain::bits_to_target(block_bits); auto block_aps = chain::target_to_average_attempts(block_target); - etb_secs = static_cast(block_aps.GetLow64()) / real_pool_hs; - if (block_aps.IsNull() && !block_target.IsNull()) - etb_secs = 1e18; + etb_secs = dgb::compute_expected_time_to_block( + static_cast(block_aps.GetLow64()), real_pool_hs, + /*average_attempts_overflowed=*/block_aps.IsNull(), + /*block_target_nonzero=*/!block_target.IsNull()); } LOG_INFO << " Pool: " << format_hashrate(real_pool_hs) << " Stale rate: " << std::fixed << std::setprecision(1)