Skip to content

Commit b22bb49

Browse files
committed
Fix use-after-free crash + add debug logging for share loading
- Copy NetService in disconnect handlers (dangling ref → SIGSEGV) - Add watchdog timer (30s) to detect event loop stalls - Add share loading diagnostics: unique count, skip reasons (load fail, small data, duplicate)
1 parent 87f357f commit b22bb49

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

src/impl/ltc/node.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,11 @@ void NodeImpl::load_persisted_shares()
904904
auto all_hashes = m_storage->get_shares_by_height_range(0, UINT64_MAX);
905905
auto scan_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
906906
std::chrono::steady_clock::now() - t0).count();
907-
LOG_INFO << "[Pool] Height index scan: " << all_hashes.size() << " entries in " << scan_ms << "ms";
907+
{
908+
std::set<uint256> unique(all_hashes.begin(), all_hashes.end());
909+
LOG_INFO << "[Pool] Height index scan: " << all_hashes.size() << " entries ("
910+
<< unique.size() << " unique) in " << scan_ms << "ms";
911+
}
908912
if (all_hashes.empty())
909913
{
910914
LOG_INFO << "No persisted shares found in LevelDB";
@@ -925,16 +929,20 @@ void NodeImpl::load_persisted_shares()
925929

926930
const size_t to_load = total_in_db - skip;
927931
LOG_INFO << "[Pool] Loading shares from LevelDB: " << to_load << " shares to process...";
928-
int loaded = 0;
932+
int loaded = 0, skipped_contains = 0, skipped_load = 0, skipped_small = 0;
929933
for (size_t i = skip; i < total_in_db; ++i)
930934
{
931935
const auto& hash = all_hashes[i];
932936
std::vector<uint8_t> data;
933937
uint256 prev; uint64_t height, ts; uint256 work, target; bool orphan;
934-
if (!m_storage->load_share(hash, data, prev, height, ts, work, target, orphan))
938+
if (!m_storage->load_share(hash, data, prev, height, ts, work, target, orphan)) {
939+
++skipped_load;
935940
continue;
936-
if (data.size() < 8)
941+
}
942+
if (data.size() < 8) {
943+
++skipped_small;
937944
continue;
945+
}
938946

939947
try
940948
{
@@ -955,6 +963,8 @@ void NodeImpl::load_persisted_shares()
955963
LOG_INFO << "[Pool] Loading shares: " << progress << "/" << to_load
956964
<< " (" << (100 * progress / to_load) << "%)";
957965
}
966+
} else {
967+
++skipped_contains;
958968
}
959969
}
960970
catch (const std::exception& e)
@@ -965,7 +975,9 @@ void NodeImpl::load_persisted_shares()
965975
}
966976

967977
LOG_INFO << "[Pool] Loaded " << loaded << " shares from LevelDB storage"
968-
<< " (DB total: " << total_in_db << ", limit: " << keep_per_head << ")";
978+
<< " (DB total: " << total_in_db << ", limit: " << keep_per_head
979+
<< ", skipped: load=" << skipped_load << " small=" << skipped_small
980+
<< " dup=" << skipped_contains << ")";
969981

970982
// Prune old shares from LevelDB that we skipped
971983
if (skip > 0)

0 commit comments

Comments
 (0)