|
91 | 91 | #include <impl/dash/stratum/work_source.hpp> // dash::stratum::DASHWorkSource — concrete core::stratum::IWorkSource |
92 | 92 | #include <impl/dash/mint_runloop.hpp> // dash::mint — run-loop share minting (slice 3/3) |
93 | 93 | #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) |
94 | 95 | #include <core/web_server.hpp> // core::WebServer — the EXISTING c2pool dashboard (same wiring main_ltc.cpp uses) |
95 | 96 | #include <impl/dash/enhanced_node.hpp> // dash::EnhancedDashNode — core::IMiningNode the WebServer ctor takes |
96 | 97 | #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, |
590 | 591 |
|
591 | 592 | // ── Real, non-negotiable node identity ──────────────────────────── |
592 | 593 | 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 | + } |
593 | 646 | #ifdef C2POOL_VERSION |
594 | 647 | mi->set_pool_version("c2pool/" C2POOL_VERSION); |
595 | 648 | #endif |
@@ -1412,14 +1465,24 @@ int run_node(bool testnet, const std::string& rpc_endpoint, |
1412 | 1465 | [ws](uint32_t height, const uint256& block_hash, |
1413 | 1466 | const std::string& miner, bool reached_network) { |
1414 | 1467 | 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 | + } |
1415 | 1478 | mi->record_found_block( |
1416 | 1479 | height, block_hash, |
1417 | 1480 | static_cast<uint64_t>(std::time(nullptr)), |
1418 | 1481 | "DASH", miner, block_hash.GetHex(), |
1419 | 1482 | mi->get_network_difficulty(), |
1420 | 1483 | /*share_difficulty=*/0.0, |
1421 | | - /*pool_hashrate=*/0.0, |
1422 | | - /*subsidy=*/0); |
| 1484 | + pool_hr, |
| 1485 | + subsidy); |
1423 | 1486 | if (!reached_network) |
1424 | 1487 | LOG_WARNING << "[DASH] recorded found block height=" |
1425 | 1488 | << height << " that reached NO network sink"; |
|
0 commit comments