Skip to content

Commit 280516b

Browse files
committed
Fix stale sharechain view: walk from tallest chain head instead of verified best
Both /sharechain/stats and /sharechain/window were walking from best_share_hash() (verified chain tip), which lags during sync. Now finds tallest chain head so the grid stays current.
1 parent 7929f23 commit 280516b

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/c2pool/c2pool_refactored.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,14 @@ int main(int argc, char* argv[]) {
10441044
web_server.get_mining_interface()->set_sharechain_stats_fn([&p2p_node]() {
10451045
nlohmann::json result;
10461046
auto& chain = p2p_node->tracker().chain;
1047-
auto best = p2p_node->best_share_hash();
1047+
1048+
// Use tallest chain head (not verified best) so stats stay current during sync
1049+
uint256 best;
1050+
int32_t best_height = -1;
1051+
for (const auto& [head_hash, tail_hash] : chain.get_heads()) {
1052+
auto h = chain.get_height(head_hash);
1053+
if (h > best_height) { best = head_hash; best_height = h; }
1054+
}
10481055

10491056
result["total_shares"] = static_cast<int>(chain.size());
10501057
result["fork_count"] = static_cast<int>(chain.get_heads().size());
@@ -1133,7 +1140,14 @@ int main(int argc, char* argv[]) {
11331140
nlohmann::json result;
11341141
auto& chain = p2p_node->tracker().chain;
11351142
auto& verified = p2p_node->tracker().verified;
1136-
auto best = p2p_node->best_share_hash();
1143+
1144+
// Use tallest chain head (not verified best) so the grid stays current during sync
1145+
uint256 best;
1146+
int32_t best_height = -1;
1147+
for (const auto& [head_hash, tail_hash] : chain.get_heads()) {
1148+
auto h = chain.get_height(head_hash);
1149+
if (h > best_height) { best = head_hash; best_height = h; }
1150+
}
11371151

11381152
result["best_hash"] = best.IsNull() ? "" : best.GetHex();
11391153
result["chain_length"] = static_cast<int>(chain.size());

0 commit comments

Comments
 (0)