Skip to content

Commit c2cd4a4

Browse files
committed
Add p2pool-style periodic heartbeat: shares, stale rate, peers, RSS
Matches p2pool's status output format: P2Pool: 898 shares in chain (923 verified/923 total) Peers: 2 Shares: 100 (13 orphan, 0 dead) Stale rate: ~1.8% heads=1 rss=21MB Counts orphan/DOA shares in the last 100 shares from best chain tip. Logged every think() cycle (~10-30 seconds).
1 parent eedbbab commit c2cd4a4

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

src/impl/ltc/node.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <algorithm>
1010
#include <fstream>
11+
#include <iomanip>
1112
#include <random>
1213

1314
// Helper: read current RSS from /proc/self/status (Linux only)
@@ -860,11 +861,37 @@ void NodeImpl::run_think()
860861
if (m_think_running.exchange(true))
861862
return;
862863

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+
}
868895

869896
// Capture block_rel_height fn by value for thread safety
870897
auto block_rel_height = m_block_rel_height_fn

0 commit comments

Comments
 (0)