| 818 | } |
| 819 | |
| 820 | UniValue getwork(const UniValue& params, bool fHelp) { |
| 821 | if (fHelp || params.size() > 1) |
| 822 | throw runtime_error( |
| 823 | "getwork [data]\n" |
| 824 | "If [data] is not specified, returns formatted hash data to work on:\n" |
| 825 | " \"algo\" : current proof-of-work algorithm name\n" |
| 826 | " \"midstate\" : precomputed hash state after hashing the first half of the data (DEPRECATED)\n" // deprecated |
| 827 | " \"data\" : block data\n" |
| 828 | " \"target\" : little endian hash target\n" |
| 829 | "If [data] is specified, tries to solve the block and returns true if it was successful."); |
| 830 | |
| 831 | |
| 832 | // Disable checking block downloading and number of connected nodes for segwittest network |
| 833 | // because it is tested locally, without any nodes connected, and with significant amount of time between blocks |
| 834 | if (Params().NetworkID() != CBaseChainParams::SEGWITTEST) { |
| 835 | if (vNodes.empty()) |
| 836 | throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Lux is not connected!"); |
| 837 | |
| 838 | if (IsInitialBlockDownload()) |
| 839 | throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Lux is downloading blocks..."); |
| 840 | } |
| 841 | |
| 842 | if (chainActive.Height() >= Params().LAST_POW_BLOCK()) |
| 843 | throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks"); |
| 844 | |
| 845 | typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t; |
| 846 | static mapNewBlock_t mapNewBlock; // FIXME: thread safety |
| 847 | static std::vector<CBlockTemplate*> vNewBlockTemplate; |
| 848 | |
| 849 | if (params.size() == 0) { |
| 850 | // Update block |
| 851 | static unsigned int nTransactionsUpdatedLast; |
| 852 | static CBlockIndex* pindexPrev; |
| 853 | static int64_t nStart; |
| 854 | static std::unique_ptr<CBlockTemplate> pblocktemplate; |
| 855 | |
| 856 | if (pindexPrev != chainActive.Tip() || |
| 857 | (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)) { |
| 858 | if (pindexPrev != chainActive.Tip()) { |
| 859 | // Deallocate old blocks since they're obsolete now |
| 860 | mapNewBlock.clear(); |
| 861 | for (CBlockTemplate* pblocktemplate : vNewBlockTemplate) |
| 862 | delete pblocktemplate; |
| 863 | vNewBlockTemplate.clear(); |
| 864 | } |
| 865 | |
| 866 | // Clear pindexPrev so future getworks make a new block, despite any failures from here on |
| 867 | pindexPrev = nullptr; |
| 868 | |
| 869 | // Store the chainActive.Tip() used before CreateNewBlock, to avoid races |
| 870 | nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); |
| 871 | CBlockIndex* pindexPrevNew = chainActive.Tip(); |
| 872 | nStart = GetTime(); |
| 873 | |
| 874 | // Create new block |
| 875 | CReserveKey reservekey(pwalletMain); |
| 876 | |
| 877 | CPubKey pubkey; |
nothing calls this directly
no test coverage detected