Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | static UniValue getmininginfo(const Config &config, | ||||
obj.pushKV("currentblocksize", uint64_t(nLastBlockSize)); | obj.pushKV("currentblocksize", uint64_t(nLastBlockSize)); | ||||
obj.pushKV("currentblocktx", uint64_t(nLastBlockTx)); | obj.pushKV("currentblocktx", uint64_t(nLastBlockTx)); | ||||
obj.pushKV("difficulty", double(GetDifficulty(chainActive.Tip()))); | obj.pushKV("difficulty", double(GetDifficulty(chainActive.Tip()))); | ||||
obj.pushKV("blockprioritypercentage", | obj.pushKV("blockprioritypercentage", | ||||
uint8_t(gArgs.GetArg("-blockprioritypercentage", | uint8_t(gArgs.GetArg("-blockprioritypercentage", | ||||
DEFAULT_BLOCK_PRIORITY_PERCENTAGE))); | DEFAULT_BLOCK_PRIORITY_PERCENTAGE))); | ||||
obj.pushKV("errors", GetWarnings("statusbar")); | obj.pushKV("errors", GetWarnings("statusbar")); | ||||
obj.pushKV("networkhashps", getnetworkhashps(config, request)); | obj.pushKV("networkhashps", getnetworkhashps(config, request)); | ||||
obj.pushKV("pooledtx", uint64_t(mempool.size())); | obj.pushKV("pooledtx", uint64_t(g_mempool.size())); | ||||
obj.pushKV("chain", config.GetChainParams().NetworkIDString()); | obj.pushKV("chain", config.GetChainParams().NetworkIDString()); | ||||
return obj; | return obj; | ||||
} | } | ||||
// NOTE: Unlike wallet RPC (which use BCH values), mining RPCs follow GBT (BIP | // NOTE: Unlike wallet RPC (which use BCH values), mining RPCs follow GBT (BIP | ||||
// 22) in using satoshi amounts | // 22) in using satoshi amounts | ||||
static UniValue prioritisetransaction(const Config &config, | static UniValue prioritisetransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
Show All 23 Lines | if (request.fHelp || request.params.size() != 3) { | ||||
HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")); | HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
uint256 hash = ParseHashStr(request.params[0].get_str(), "txid"); | uint256 hash = ParseHashStr(request.params[0].get_str(), "txid"); | ||||
Amount nAmount = request.params[2].get_int64() * SATOSHI; | Amount nAmount = request.params[2].get_int64() * SATOSHI; | ||||
mempool.PrioritiseTransaction(hash, request.params[0].get_str(), | g_mempool.PrioritiseTransaction(hash, request.params[0].get_str(), | ||||
request.params[1].get_real(), nAmount); | request.params[1].get_real(), nAmount); | ||||
return true; | return true; | ||||
} | } | ||||
// NOTE: Assumes a conclusive result; if result is inconclusive, it must be | // NOTE: Assumes a conclusive result; if result is inconclusive, it must be | ||||
// handled by caller | // handled by caller | ||||
static UniValue BIP22ValidationResult(const Config &config, | static UniValue BIP22ValidationResult(const Config &config, | ||||
const CValidationState &state) { | const CValidationState &state) { | ||||
if (state.IsValid()) { | if (state.IsValid()) { | ||||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | if (!lpval.isNull()) { | ||||
checktxtime = | checktxtime = | ||||
std::chrono::steady_clock::now() + std::chrono::minutes(1); | std::chrono::steady_clock::now() + std::chrono::minutes(1); | ||||
WAIT_LOCK(g_best_block_mutex, lock); | WAIT_LOCK(g_best_block_mutex, lock); | ||||
while (g_best_block == hashWatchedChain && IsRPCRunning()) { | while (g_best_block == hashWatchedChain && IsRPCRunning()) { | ||||
if (g_best_block_cv.wait_until(lock, checktxtime) == | if (g_best_block_cv.wait_until(lock, checktxtime) == | ||||
std::cv_status::timeout) { | std::cv_status::timeout) { | ||||
// Timeout: Check transactions for update | // Timeout: Check transactions for update | ||||
if (mempool.GetTransactionsUpdated() != | if (g_mempool.GetTransactionsUpdated() != | ||||
nTransactionsUpdatedLastLP) { | nTransactionsUpdatedLastLP) { | ||||
break; | break; | ||||
} | } | ||||
checktxtime += std::chrono::seconds(10); | checktxtime += std::chrono::seconds(10); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
ENTER_CRITICAL_SECTION(cs_main); | ENTER_CRITICAL_SECTION(cs_main); | ||||
if (!IsRPCRunning()) { | if (!IsRPCRunning()) { | ||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down"); | throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down"); | ||||
} | } | ||||
// TODO: Maybe recheck connections/IBD and (if something wrong) send an | // TODO: Maybe recheck connections/IBD and (if something wrong) send an | ||||
// expires-immediately template to stop miners? | // expires-immediately template to stop miners? | ||||
} | } | ||||
// Update block | // Update block | ||||
static CBlockIndex *pindexPrev; | static CBlockIndex *pindexPrev; | ||||
static int64_t nStart; | static int64_t nStart; | ||||
static std::unique_ptr<CBlockTemplate> pblocktemplate; | static std::unique_ptr<CBlockTemplate> pblocktemplate; | ||||
if (pindexPrev != chainActive.Tip() || | if (pindexPrev != chainActive.Tip() || | ||||
(mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && | (g_mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && | ||||
GetTime() - nStart > 5)) { | GetTime() - nStart > 5)) { | ||||
// Clear pindexPrev so future calls make a new block, despite any | // Clear pindexPrev so future calls make a new block, despite any | ||||
// failures from here on | // failures from here on | ||||
pindexPrev = nullptr; | pindexPrev = nullptr; | ||||
// Store the pindexBest used before CreateNewBlock, to avoid races | // Store the pindexBest used before CreateNewBlock, to avoid races | ||||
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); | nTransactionsUpdatedLast = g_mempool.GetTransactionsUpdated(); | ||||
CBlockIndex *pindexPrevNew = chainActive.Tip(); | CBlockIndex *pindexPrevNew = chainActive.Tip(); | ||||
nStart = GetTime(); | nStart = GetTime(); | ||||
// Create new block | // Create new block | ||||
CScript scriptDummy = CScript() << OP_TRUE; | CScript scriptDummy = CScript() << OP_TRUE; | ||||
pblocktemplate = BlockAssembler(config).CreateNewBlock(scriptDummy); | pblocktemplate = BlockAssembler(config).CreateNewBlock(scriptDummy); | ||||
if (!pblocktemplate) { | if (!pblocktemplate) { | ||||
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); | throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); | ||||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | static UniValue estimatefee(const Config &config, | ||||
RPCTypeCheck(request.params, {UniValue::VNUM}); | RPCTypeCheck(request.params, {UniValue::VNUM}); | ||||
int nBlocks = request.params[0].get_int(); | int nBlocks = request.params[0].get_int(); | ||||
if (nBlocks < 1) { | if (nBlocks < 1) { | ||||
nBlocks = 1; | nBlocks = 1; | ||||
} | } | ||||
CFeeRate feeRate = mempool.estimateFee(nBlocks); | CFeeRate feeRate = g_mempool.estimateFee(nBlocks); | ||||
if (feeRate == CFeeRate(Amount::zero())) { | if (feeRate == CFeeRate(Amount::zero())) { | ||||
return -1.0; | return -1.0; | ||||
} | } | ||||
return ValueFromAmount(feeRate.GetFeePerK()); | return ValueFromAmount(feeRate.GetFeePerK()); | ||||
} | } | ||||
// clang-format off | // clang-format off | ||||
Show All 19 Lines |