Skip to content

Commit 66e0167

Browse files
authored
Merge pull request #836 from frstrtr/dashboard/dash-found-block-value-persistence
dash(web): real found-block value + persistence — kill tenant-visible value=0
2 parents 3fc1213 + 362d0ea commit 66e0167

1 file changed

Lines changed: 65 additions & 2 deletions

File tree

src/c2pool/main_dash.cpp

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#include <impl/dash/stratum/work_source.hpp> // dash::stratum::DASHWorkSource — concrete core::stratum::IWorkSource
9292
#include <impl/dash/mint_runloop.hpp> // dash::mint — run-loop share minting (slice 3/3)
9393
#include <impl/dash/share_messages.hpp> // dash::validate_message_data — operator message-blob validation (EMIT side, mirrors main_ltc.cpp)
94+
#include <c2pool/storage/found_block_store.hpp> // FoundBlockStore/Record + LevelDBStore (persistence, main_ltc parity)
9495
#include <core/web_server.hpp> // core::WebServer — the EXISTING c2pool dashboard (same wiring main_ltc.cpp uses)
9596
#include <impl/dash/enhanced_node.hpp> // dash::EnhancedDashNode — core::IMiningNode the WebServer ctor takes
9697
#include <impl/dash/share_messages.hpp> // dash::unpack_share_messages — signed transitional-blob DISPLAY+VERIFY feed
@@ -590,6 +591,58 @@ int run_node(bool testnet, const std::string& rpc_endpoint,
590591

591592
// ── Real, non-negotiable node identity ────────────────────────────
592593
mi->set_coin_label("DASH");
594+
595+
// --- Persistent found-block storage (DASH) ---
596+
// Parity with main_ltc.cpp:1977 — won DASH blocks survive node
597+
// restarts on the dashboard /recent_blocks + history cards instead of
598+
// vanishing every bounce. Dedicated LevelDB under the per-net data
599+
// dir. Persistence/display only; touches no share/consensus path.
600+
{
601+
std::string fblk_db_path = (core::filesystem::config_path()
602+
/ net_subdir / "found_blocks_db").string();
603+
auto fblk_leveldb = std::make_shared<core::LevelDBStore>(
604+
fblk_db_path, core::LevelDBOptions{});
605+
if (fblk_leveldb->open()) {
606+
auto fblk_store = std::make_shared<c2pool::storage::FoundBlockStore>(*fblk_leveldb);
607+
using MI = core::MiningInterface;
608+
mi->set_found_block_persistence(
609+
[fblk_store, fblk_leveldb](const MI::FoundBlock& blk) -> bool {
610+
c2pool::storage::FoundBlockRecord rec;
611+
rec.chain = blk.chain;
612+
rec.height = blk.height;
613+
rec.block_hash = blk.hash;
614+
rec.timestamp = blk.ts;
615+
rec.status = static_cast<uint8_t>(blk.status);
616+
rec.check_count = blk.check_count;
617+
rec.confirmations = blk.confirmations;
618+
rec.last_checked = static_cast<uint64_t>(std::time(nullptr));
619+
return fblk_store->store(rec);
620+
},
621+
[fblk_store, fblk_leveldb]() -> std::vector<MI::FoundBlock> {
622+
auto records = fblk_store->load_all();
623+
std::vector<MI::FoundBlock> result;
624+
result.reserve(records.size());
625+
for (const auto& rec : records) {
626+
MI::FoundBlock blk;
627+
blk.height = rec.height;
628+
blk.hash = rec.block_hash;
629+
blk.ts = rec.timestamp;
630+
blk.status = static_cast<MI::BlockStatus>(rec.status);
631+
blk.check_count = rec.check_count;
632+
blk.chain = rec.chain;
633+
blk.confirmations = rec.confirmations;
634+
result.push_back(std::move(blk));
635+
}
636+
return result;
637+
}
638+
);
639+
mi->load_persisted_found_blocks();
640+
LOG_INFO << "[Pool] DASH found-block persistence enabled at " << fblk_db_path;
641+
} else {
642+
LOG_WARNING << "[Pool] DASH found-block persistence DISABLED (LevelDB open failed at "
643+
<< fblk_db_path << ")";
644+
}
645+
}
593646
#ifdef C2POOL_VERSION
594647
mi->set_pool_version("c2pool/" C2POOL_VERSION);
595648
#endif
@@ -1412,14 +1465,24 @@ int run_node(bool testnet, const std::string& rpc_endpoint,
14121465
[ws](uint32_t height, const uint256& block_hash,
14131466
const std::string& miner, bool reached_network) {
14141467
auto* mi = ws->get_mining_interface();
1468+
// Enrich the recorded win with the block reward + real pool
1469+
// hashrate so the dashboard shows a truthful value instead of
1470+
// 0 (main_ltc.cpp:2988 parity). Display only.
1471+
double pool_hr = mi->get_local_hashrate();
1472+
uint64_t subsidy = 0;
1473+
{
1474+
auto tmpl = mi->get_current_work_template();
1475+
if (!tmpl.is_null() && tmpl.contains("coinbasevalue"))
1476+
subsidy = tmpl["coinbasevalue"].get<uint64_t>();
1477+
}
14151478
mi->record_found_block(
14161479
height, block_hash,
14171480
static_cast<uint64_t>(std::time(nullptr)),
14181481
"DASH", miner, block_hash.GetHex(),
14191482
mi->get_network_difficulty(),
14201483
/*share_difficulty=*/0.0,
1421-
/*pool_hashrate=*/0.0,
1422-
/*subsidy=*/0);
1484+
pool_hr,
1485+
subsidy);
14231486
if (!reached_network)
14241487
LOG_WARNING << "[DASH] recorded found block height="
14251488
<< height << " that reached NO network sink";

0 commit comments

Comments
 (0)