MCPcopy Create free account
hub / github.com/LUX-Core/lux / getwork

Function getwork

src/rpcmining.cpp:820–955  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

818}
819
820UniValue 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;

Callers

nothing calls this directly

Calls 15

JSONRPCErrorFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
GetTimeFunction · 0.85
BlockAssemblerClass · 0.85
UpdateTimeFunction · 0.85
IncrementExtraNonceFunction · 0.85
FormatHashBuffersFunction · 0.85
PairFunction · 0.85
HexStrFunction · 0.85
ParseHexFunction · 0.85
ProcessNewBlockFunction · 0.85
NetworkIDMethod · 0.80

Tested by

no test coverage detected