diff options
Diffstat (limited to 'src/rpc.cpp')
| -rw-r--r-- | src/rpc.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/rpc.cpp b/src/rpc.cpp index 383769a..1aa4f9b 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp | |||
| @@ -623,6 +623,7 @@ static StatsSnapshot gStats; | |||
| 623 | static std::vector<PoolWorkerStatView> gWorkerStats; | 623 | static std::vector<PoolWorkerStatView> gWorkerStats; |
| 624 | static std::vector<PendingPayoutView> gPayoutViews; | 624 | static std::vector<PendingPayoutView> gPayoutViews; |
| 625 | static std::mutex gStatsMutex; | 625 | static std::mutex gStatsMutex; |
| 626 | static int64 gLastPoolStatusWrite = 0; | ||
| 626 | 627 | ||
| 627 | void GetPoolOperatorStats(int& authorizedMiners, int& blocksFound, uint64& roundShares, double& totalHashRate) | 628 | void GetPoolOperatorStats(int& authorizedMiners, int& blocksFound, uint64& roundShares, double& totalHashRate) |
| 628 | { | 629 | { |
| @@ -645,6 +646,82 @@ void GetPendingPayouts(std::vector<PendingPayoutView>& out) | |||
| 645 | out = gPayoutViews; | 646 | out = gPayoutViews; |
| 646 | } | 647 | } |
| 647 | 648 | ||
| 649 | static std::string PoolStatusFilePath() | ||
| 650 | { | ||
| 651 | if (!strPoolStatusFile.empty()) | ||
| 652 | return strPoolStatusFile; | ||
| 653 | return GetAppDir() + "/pool_status.json"; | ||
| 654 | } | ||
| 655 | |||
| 656 | static void WritePoolStatusJsonLocked() | ||
| 657 | { | ||
| 658 | nlohmann::json j; | ||
| 659 | j["schema"] = "bitflash-pool-status-1"; | ||
| 660 | j["network"] = "bitflash"; | ||
| 661 | j["updatedAt"] = GetTime(); | ||
| 662 | |||
| 663 | j["operator"] = { | ||
| 664 | {"name", strPoolName}, | ||
| 665 | {"btfAddress", BtfLocalAddress()}, | ||
| 666 | {"feePercent", dPoolFeePercent}, | ||
| 667 | {"dashboardUrl", strPoolDashboardUrl} | ||
| 668 | }; | ||
| 669 | |||
| 670 | j["node"] = { | ||
| 671 | {"height", nBestHeight}, | ||
| 672 | {"poolRunning", (bool)gPoolRunning}, | ||
| 673 | {"mode", nMineMode} | ||
| 674 | }; | ||
| 675 | |||
| 676 | j["pool"] = { | ||
| 677 | {"authorizedMiners", gStats.authorizedMiners}, | ||
| 678 | {"blocksFoundSession", gStats.blocksFound}, | ||
| 679 | {"roundShares", gStats.roundShares}, | ||
| 680 | {"hashRate", gStats.totalHashRate} | ||
| 681 | }; | ||
| 682 | |||
| 683 | j["workers"] = nlohmann::json::array(); | ||
| 684 | for (const PoolWorkerStatView& row : gWorkerStats) { | ||
| 685 | j["workers"].push_back({ | ||
| 686 | {"address", row.address}, | ||
| 687 | {"worker", row.worker}, | ||
| 688 | {"totalShares", row.totalShares}, | ||
| 689 | {"roundShares", row.roundShares}, | ||
| 690 | {"lastSeen", row.lastSeen}, | ||
| 691 | {"hashRate", row.hashRate} | ||
| 692 | }); | ||
| 693 | } | ||
| 694 | |||
| 695 | j["pendingPayouts"] = nlohmann::json::array(); | ||
| 696 | for (const PendingPayoutView& row : gPayoutViews) { | ||
| 697 | j["pendingPayouts"].push_back({ | ||
| 698 | {"matureAtHeight", row.matureAtHeight}, | ||
| 699 | {"recipients", row.recipients}, | ||
| 700 | {"totalAmountSatoshis", row.totalAmount}, | ||
| 701 | {"totalAmountBtf", FormatMoney(row.totalAmount)} | ||
| 702 | }); | ||
| 703 | } | ||
| 704 | |||
| 705 | std::string path = PoolStatusFilePath(); | ||
| 706 | std::string tmp = path + ".tmp"; | ||
| 707 | FILE* f = fopen(tmp.c_str(), "w"); | ||
| 708 | if (!f) { | ||
| 709 | LogPrint("pool", "[pool] WARNING: could not write status file %s\n", tmp.c_str()); | ||
| 710 | return; | ||
| 711 | } | ||
| 712 | std::string s = j.dump(2); | ||
| 713 | fwrite(s.c_str(), 1, s.size(), f); | ||
| 714 | if (fclose(f) != 0) { | ||
| 715 | LogPrint("pool", "[pool] WARNING: could not close status file %s\n", tmp.c_str()); | ||
| 716 | return; | ||
| 717 | } | ||
| 718 | #ifdef _WIN32 | ||
| 719 | remove(path.c_str()); | ||
| 720 | #endif | ||
| 721 | if (rename(tmp.c_str(), path.c_str()) != 0) | ||
| 722 | LogPrint("pool", "[pool] WARNING: could not replace status file %s\n", path.c_str()); | ||
| 723 | } | ||
| 724 | |||
| 648 | // --------------------------------------------------------------------------- | 725 | // --------------------------------------------------------------------------- |
| 649 | // Miner state -- event loop thread only | 726 | // Miner state -- event loop thread only |
| 650 | // --------------------------------------------------------------------------- | 727 | // --------------------------------------------------------------------------- |
| @@ -1314,6 +1391,12 @@ static void RefreshStats(int blocksFoundThisSession, uint64 roundShareTotal) | |||
| 1314 | if (pv.recipients > 0) | 1391 | if (pv.recipients > 0) |
| 1315 | gPayoutViews.push_back(pv); | 1392 | gPayoutViews.push_back(pv); |
| 1316 | } | 1393 | } |
| 1394 | |||
| 1395 | int64 now = GetTime(); | ||
| 1396 | if (now - gLastPoolStatusWrite >= 10) { | ||
| 1397 | WritePoolStatusJsonLocked(); | ||
| 1398 | gLastPoolStatusWrite = now; | ||
| 1399 | } | ||
| 1317 | } | 1400 | } |
| 1318 | 1401 | ||
| 1319 | // --------------------------------------------------------------------------- | 1402 | // --------------------------------------------------------------------------- |