|
8 | 8 |
|
9 | 9 | #include <algorithm> |
10 | 10 | #include <fstream> |
| 11 | +#include <iomanip> |
11 | 12 | #include <random> |
12 | 13 |
|
13 | 14 | // Helper: read current RSS from /proc/self/status (Linux only) |
@@ -860,11 +861,37 @@ void NodeImpl::run_think() |
860 | 861 | if (m_think_running.exchange(true)) |
861 | 862 | return; |
862 | 863 |
|
863 | | - LOG_INFO << "P2Pool: " << m_tracker.chain.size() << " shares in chain (" |
864 | | - << m_tracker.verified.size() << " verified/" |
865 | | - << m_tracker.chain.size() << " total) Peers: " |
866 | | - << m_peers.size() << " heads=" << m_tracker.chain.get_heads().size() |
867 | | - << " rss=" << get_rss_mb() << "MB"; |
| 864 | + // p2pool-style periodic heartbeat |
| 865 | + { |
| 866 | + auto chain_sz = m_tracker.chain.size(); |
| 867 | + auto verified = m_tracker.verified.size(); |
| 868 | + auto peers = m_peers.size(); |
| 869 | + |
| 870 | + LOG_INFO << "P2Pool: " << chain_sz << " shares in chain (" |
| 871 | + << verified << " verified/" << chain_sz << " total) Peers: " |
| 872 | + << peers; |
| 873 | + |
| 874 | + // Stale rate: count orphan/DOA shares in recent chain |
| 875 | + int orphan_count = 0, doa_count = 0, total_recent = 0; |
| 876 | + if (!m_best_share_hash.IsNull() && m_tracker.chain.contains(m_best_share_hash)) { |
| 877 | + uint256 cur = m_best_share_hash; |
| 878 | + int window = std::min(static_cast<int>(chain_sz), 100); |
| 879 | + for (int i = 0; i < window && !cur.IsNull() && m_tracker.chain.contains(cur); ++i) { |
| 880 | + m_tracker.chain.get(cur).share.invoke([&](auto* s) { |
| 881 | + if (s->m_stale_info == ltc::StaleInfo::orphan) ++orphan_count; |
| 882 | + else if (s->m_stale_info == ltc::StaleInfo::doa) ++doa_count; |
| 883 | + cur = s->m_prev_hash; |
| 884 | + }); |
| 885 | + ++total_recent; |
| 886 | + } |
| 887 | + } |
| 888 | + double stale_pct = total_recent > 0 ? 100.0 * (orphan_count + doa_count) / total_recent : 0.0; |
| 889 | + LOG_INFO << " Shares: " << total_recent << " (" << orphan_count << " orphan, " |
| 890 | + << doa_count << " dead) Stale rate: ~" |
| 891 | + << std::fixed << std::setprecision(1) << stale_pct << "%" |
| 892 | + << " heads=" << m_tracker.chain.get_heads().size() |
| 893 | + << " rss=" << get_rss_mb() << "MB"; |
| 894 | + } |
868 | 895 |
|
869 | 896 | // Capture block_rel_height fn by value for thread safety |
870 | 897 | auto block_rel_height = m_block_rel_height_fn |
|
0 commit comments