aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/mining.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc/mining.cpp')
-rw-r--r--src/rpc/mining.cpp206
1 files changed, 82 insertions, 124 deletions
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index c22d0ac377..06882c0dfd 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -3,7 +3,6 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <base58.h>
#include <amount.h>
#include <chain.h>
#include <chainparams.h>
@@ -13,6 +12,7 @@
#include <core_io.h>
#include <init.h>
#include <validation.h>
+#include <key_io.h>
#include <miner.h>
#include <net.h>
#include <policy/fees.h>
@@ -201,7 +201,6 @@ UniValue getmininginfo(const JSONRPCRequest& request)
" \"pooledtx\": n (numeric) The size of the mempool\n"
" \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
" \"warnings\": \"...\" (string) any network and blockchain warnings\n"
- " \"errors\": \"...\" (string) DEPRECATED. Same as warnings. Only shown when bitcoind is started with -deprecatedrpc=getmininginfo\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getmininginfo", "")
@@ -212,18 +211,14 @@ UniValue getmininginfo(const JSONRPCRequest& request)
LOCK(cs_main);
UniValue obj(UniValue::VOBJ);
- obj.push_back(Pair("blocks", (int)chainActive.Height()));
- obj.push_back(Pair("currentblockweight", (uint64_t)nLastBlockWeight));
- obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
- obj.push_back(Pair("difficulty", (double)GetDifficulty()));
- obj.push_back(Pair("networkhashps", getnetworkhashps(request)));
- obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
- obj.push_back(Pair("chain", Params().NetworkIDString()));
- if (IsDeprecatedRPCEnabled("getmininginfo")) {
- obj.push_back(Pair("errors", GetWarnings("statusbar")));
- } else {
- obj.push_back(Pair("warnings", GetWarnings("statusbar")));
- }
+ obj.pushKV("blocks", (int)chainActive.Height());
+ obj.pushKV("currentblockweight", (uint64_t)nLastBlockWeight);
+ obj.pushKV("currentblocktx", (uint64_t)nLastBlockTx);
+ obj.pushKV("difficulty", (double)GetDifficulty());
+ obj.pushKV("networkhashps", getnetworkhashps(request));
+ obj.pushKV("pooledtx", (uint64_t)mempool.size());
+ obj.pushKV("chain", Params().NetworkIDString());
+ obj.pushKV("warnings", GetWarnings("statusbar"));
return obj;
}
@@ -269,11 +264,11 @@ static UniValue BIP22ValidationResult(const CValidationState& state)
if (state.IsValid())
return NullUniValue;
- std::string strRejectReason = state.GetRejectReason();
if (state.IsError())
- throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
+ throw JSONRPCError(RPC_VERIFY_ERROR, FormatStateMessage(state));
if (state.IsInvalid())
{
+ std::string strRejectReason = state.GetRejectReason();
if (strRejectReason.empty())
return "rejected";
return strRejectReason;
@@ -401,9 +396,8 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
uint256 hash = block.GetHash();
- BlockMap::iterator mi = mapBlockIndex.find(hash);
- if (mi != mapBlockIndex.end()) {
- CBlockIndex *pindex = mi->second;
+ const CBlockIndex* pindex = LookupBlockIndex(hash);
+ if (pindex) {
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
return "duplicate";
if (pindex->nStatus & BLOCK_FAILED_MASK)
@@ -538,7 +532,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
pblock->nNonce = 0;
// NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration
- const bool fPreSegWit = (THRESHOLD_ACTIVE != VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache));
+ const bool fPreSegWit = (ThresholdState::ACTIVE != VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache));
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
@@ -555,9 +549,9 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
UniValue entry(UniValue::VOBJ);
- entry.push_back(Pair("data", EncodeHexTx(tx)));
- entry.push_back(Pair("txid", txHash.GetHex()));
- entry.push_back(Pair("hash", tx.GetWitnessHash().GetHex()));
+ entry.pushKV("data", EncodeHexTx(tx));
+ entry.pushKV("txid", txHash.GetHex());
+ entry.pushKV("hash", tx.GetWitnessHash().GetHex());
UniValue deps(UniValue::VARR);
for (const CTxIn &in : tx.vin)
@@ -565,23 +559,23 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
if (setTxIndex.count(in.prevout.hash))
deps.push_back(setTxIndex[in.prevout.hash]);
}
- entry.push_back(Pair("depends", deps));
+ entry.pushKV("depends", deps);
int index_in_template = i - 1;
- entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template]));
+ entry.pushKV("fee", pblocktemplate->vTxFees[index_in_template]);
int64_t nTxSigOps = pblocktemplate->vTxSigOpsCost[index_in_template];
if (fPreSegWit) {
assert(nTxSigOps % WITNESS_SCALE_FACTOR == 0);
nTxSigOps /= WITNESS_SCALE_FACTOR;
}
- entry.push_back(Pair("sigops", nTxSigOps));
- entry.push_back(Pair("weight", GetTransactionWeight(tx)));
+ entry.pushKV("sigops", nTxSigOps);
+ entry.pushKV("weight", GetTransactionWeight(tx));
transactions.push_back(entry);
}
UniValue aux(UniValue::VOBJ);
- aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())));
+ aux.pushKV("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end()));
arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
@@ -591,7 +585,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
aMutable.push_back("prevblock");
UniValue result(UniValue::VOBJ);
- result.push_back(Pair("capabilities", aCaps));
+ result.pushKV("capabilities", aCaps);
UniValue aRules(UniValue::VARR);
UniValue vbavailable(UniValue::VOBJ);
@@ -599,18 +593,18 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
Consensus::DeploymentPos pos = Consensus::DeploymentPos(j);
ThresholdState state = VersionBitsState(pindexPrev, consensusParams, pos, versionbitscache);
switch (state) {
- case THRESHOLD_DEFINED:
- case THRESHOLD_FAILED:
+ case ThresholdState::DEFINED:
+ case ThresholdState::FAILED:
// Not exposed to GBT at all
break;
- case THRESHOLD_LOCKED_IN:
+ case ThresholdState::LOCKED_IN:
// Ensure bit is set in block version
pblock->nVersion |= VersionBitsMask(consensusParams, pos);
// FALL THROUGH to get vbavailable set...
- case THRESHOLD_STARTED:
+ case ThresholdState::STARTED:
{
const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
- vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
+ vbavailable.pushKV(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit);
if (setClientRules.find(vbinfo.name) == setClientRules.end()) {
if (!vbinfo.gbt_force) {
// If the client doesn't support this, don't indicate it in the [default] version
@@ -619,7 +613,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
}
break;
}
- case THRESHOLD_ACTIVE:
+ case ThresholdState::ACTIVE:
{
// Add to rules only
const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
@@ -635,10 +629,10 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
}
}
}
- result.push_back(Pair("version", pblock->nVersion));
- result.push_back(Pair("rules", aRules));
- result.push_back(Pair("vbavailable", vbavailable));
- result.push_back(Pair("vbrequired", int(0)));
+ result.pushKV("version", pblock->nVersion);
+ result.pushKV("rules", aRules);
+ result.pushKV("vbavailable", vbavailable);
+ result.pushKV("vbrequired", int(0));
if (nMaxVersionPreVB >= 2) {
// If VB is supported by the client, nMaxVersionPreVB is -1, so we won't get here
@@ -648,15 +642,15 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
aMutable.push_back("version/force");
}
- result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
- result.push_back(Pair("transactions", transactions));
- result.push_back(Pair("coinbaseaux", aux));
- result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue));
- result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)));
- result.push_back(Pair("target", hashTarget.GetHex()));
- result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
- result.push_back(Pair("mutable", aMutable));
- result.push_back(Pair("noncerange", "00000000ffffffff"));
+ result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex());
+ result.pushKV("transactions", transactions);
+ result.pushKV("coinbaseaux", aux);
+ result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue);
+ result.pushKV("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast));
+ result.pushKV("target", hashTarget.GetHex());
+ result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1);
+ result.pushKV("mutable", aMutable);
+ result.pushKV("noncerange", "00000000ffffffff");
int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST;
int64_t nSizeLimit = MAX_BLOCK_SERIALIZED_SIZE;
if (fPreSegWit) {
@@ -665,17 +659,17 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
assert(nSizeLimit % WITNESS_SCALE_FACTOR == 0);
nSizeLimit /= WITNESS_SCALE_FACTOR;
}
- result.push_back(Pair("sigoplimit", nSigOpLimit));
- result.push_back(Pair("sizelimit", nSizeLimit));
+ result.pushKV("sigoplimit", nSigOpLimit);
+ result.pushKV("sizelimit", nSizeLimit);
if (!fPreSegWit) {
- result.push_back(Pair("weightlimit", (int64_t)MAX_BLOCK_WEIGHT));
+ result.pushKV("weightlimit", (int64_t)MAX_BLOCK_WEIGHT);
}
- result.push_back(Pair("curtime", pblock->GetBlockTime()));
- result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
- result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
+ result.pushKV("curtime", pblock->GetBlockTime());
+ result.pushKV("bits", strprintf("%08x", pblock->nBits));
+ result.pushKV("height", (int64_t)(pindexPrev->nHeight+1));
if (!pblocktemplate->vchCoinbaseCommitment.empty() && fSupportsSegwit) {
- result.push_back(Pair("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end())));
+ result.pushKV("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end()));
}
return result;
@@ -732,9 +726,8 @@ UniValue submitblock(const JSONRPCRequest& request)
bool fBlockPresent = false;
{
LOCK(cs_main);
- BlockMap::iterator mi = mapBlockIndex.find(hash);
- if (mi != mapBlockIndex.end()) {
- CBlockIndex *pindex = mi->second;
+ const CBlockIndex* pindex = LookupBlockIndex(hash);
+ if (pindex) {
if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) {
return "duplicate";
}
@@ -748,9 +741,9 @@ UniValue submitblock(const JSONRPCRequest& request)
{
LOCK(cs_main);
- BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
- if (mi != mapBlockIndex.end()) {
- UpdateUncommittedBlockStructures(block, mi->second, Params().GetConsensus());
+ const CBlockIndex* pindex = LookupBlockIndex(block.hashPrevBlock);
+ if (pindex) {
+ UpdateUncommittedBlockStructures(block, pindex, Params().GetConsensus());
}
}
@@ -772,43 +765,8 @@ UniValue submitblock(const JSONRPCRequest& request)
UniValue estimatefee(const JSONRPCRequest& request)
{
- if (request.fHelp || request.params.size() != 1)
- throw std::runtime_error(
- "estimatefee nblocks\n"
- "\nDEPRECATED. Please use estimatesmartfee for more intelligent estimates."
- "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
- "confirmation within nblocks blocks. Uses virtual transaction size of transaction\n"
- "as defined in BIP 141 (witness data is discounted).\n"
- "\nArguments:\n"
- "1. nblocks (numeric, required)\n"
- "\nResult:\n"
- "n (numeric) estimated fee-per-kilobyte\n"
- "\n"
- "A negative value is returned if not enough transactions and blocks\n"
- "have been observed to make an estimate.\n"
- "-1 is always returned for nblocks == 1 as it is impossible to calculate\n"
- "a fee that is high enough to get reliably included in the next block.\n"
- "\nExample:\n"
- + HelpExampleCli("estimatefee", "6")
- );
-
- if (!IsDeprecatedRPCEnabled("estimatefee")) {
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "estimatefee is deprecated and will be fully removed in v0.17. "
- "To use estimatefee in v0.16, restart bitcoind with -deprecatedrpc=estimatefee.\n"
- "Projects should transition to using estimatesmartfee before upgrading to v0.17");
- }
-
- RPCTypeCheck(request.params, {UniValue::VNUM});
-
- int nBlocks = request.params[0].get_int();
- if (nBlocks < 1)
- nBlocks = 1;
-
- CFeeRate feeRate = ::feeEstimator.estimateFee(nBlocks);
- if (feeRate == CFeeRate(0))
- return -1.0;
-
- return ValueFromAmount(feeRate.GetFeePerK());
+ throw JSONRPCError(RPC_METHOD_DEPRECATED, "estimatefee was removed in v0.17.\n"
+ "Clients should use estimatesmartfee.");
}
UniValue estimatesmartfee(const JSONRPCRequest& request)
@@ -863,12 +821,12 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
FeeCalculation feeCalc;
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative);
if (feeRate != CFeeRate(0)) {
- result.push_back(Pair("feerate", ValueFromAmount(feeRate.GetFeePerK())));
+ result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
} else {
errors.push_back("Insufficient data or no feerate found");
- result.push_back(Pair("errors", errors));
+ result.pushKV("errors", errors);
}
- result.push_back(Pair("blocks", feeCalc.returnedTarget));
+ result.pushKV("blocks", feeCalc.returnedTarget);
return result;
}
@@ -939,37 +897,37 @@ UniValue estimaterawfee(const JSONRPCRequest& request)
UniValue horizon_result(UniValue::VOBJ);
UniValue errors(UniValue::VARR);
UniValue passbucket(UniValue::VOBJ);
- passbucket.push_back(Pair("startrange", round(buckets.pass.start)));
- passbucket.push_back(Pair("endrange", round(buckets.pass.end)));
- passbucket.push_back(Pair("withintarget", round(buckets.pass.withinTarget * 100.0) / 100.0));
- passbucket.push_back(Pair("totalconfirmed", round(buckets.pass.totalConfirmed * 100.0) / 100.0));
- passbucket.push_back(Pair("inmempool", round(buckets.pass.inMempool * 100.0) / 100.0));
- passbucket.push_back(Pair("leftmempool", round(buckets.pass.leftMempool * 100.0) / 100.0));
+ passbucket.pushKV("startrange", round(buckets.pass.start));
+ passbucket.pushKV("endrange", round(buckets.pass.end));
+ passbucket.pushKV("withintarget", round(buckets.pass.withinTarget * 100.0) / 100.0);
+ passbucket.pushKV("totalconfirmed", round(buckets.pass.totalConfirmed * 100.0) / 100.0);
+ passbucket.pushKV("inmempool", round(buckets.pass.inMempool * 100.0) / 100.0);
+ passbucket.pushKV("leftmempool", round(buckets.pass.leftMempool * 100.0) / 100.0);
UniValue failbucket(UniValue::VOBJ);
- failbucket.push_back(Pair("startrange", round(buckets.fail.start)));
- failbucket.push_back(Pair("endrange", round(buckets.fail.end)));
- failbucket.push_back(Pair("withintarget", round(buckets.fail.withinTarget * 100.0) / 100.0));
- failbucket.push_back(Pair("totalconfirmed", round(buckets.fail.totalConfirmed * 100.0) / 100.0));
- failbucket.push_back(Pair("inmempool", round(buckets.fail.inMempool * 100.0) / 100.0));
- failbucket.push_back(Pair("leftmempool", round(buckets.fail.leftMempool * 100.0) / 100.0));
+ failbucket.pushKV("startrange", round(buckets.fail.start));
+ failbucket.pushKV("endrange", round(buckets.fail.end));
+ failbucket.pushKV("withintarget", round(buckets.fail.withinTarget * 100.0) / 100.0);
+ failbucket.pushKV("totalconfirmed", round(buckets.fail.totalConfirmed * 100.0) / 100.0);
+ failbucket.pushKV("inmempool", round(buckets.fail.inMempool * 100.0) / 100.0);
+ failbucket.pushKV("leftmempool", round(buckets.fail.leftMempool * 100.0) / 100.0);
// CFeeRate(0) is used to indicate error as a return value from estimateRawFee
if (feeRate != CFeeRate(0)) {
- horizon_result.push_back(Pair("feerate", ValueFromAmount(feeRate.GetFeePerK())));
- horizon_result.push_back(Pair("decay", buckets.decay));
- horizon_result.push_back(Pair("scale", (int)buckets.scale));
- horizon_result.push_back(Pair("pass", passbucket));
+ horizon_result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
+ horizon_result.pushKV("decay", buckets.decay);
+ horizon_result.pushKV("scale", (int)buckets.scale);
+ horizon_result.pushKV("pass", passbucket);
// buckets.fail.start == -1 indicates that all buckets passed, there is no fail bucket to output
- if (buckets.fail.start != -1) horizon_result.push_back(Pair("fail", failbucket));
+ if (buckets.fail.start != -1) horizon_result.pushKV("fail", failbucket);
} else {
// Output only information that is still meaningful in the event of error
- horizon_result.push_back(Pair("decay", buckets.decay));
- horizon_result.push_back(Pair("scale", (int)buckets.scale));
- horizon_result.push_back(Pair("fail", failbucket));
+ horizon_result.pushKV("decay", buckets.decay);
+ horizon_result.pushKV("scale", (int)buckets.scale);
+ horizon_result.pushKV("fail", failbucket);
errors.push_back("Insufficient data or no feerate found which meets threshold");
- horizon_result.push_back(Pair("errors",errors));
+ horizon_result.pushKV("errors",errors);
}
- result.push_back(Pair(StringForFeeEstimateHorizon(horizon), horizon_result));
+ result.pushKV(StringForFeeEstimateHorizon(horizon), horizon_result);
}
return result;
}
@@ -986,7 +944,7 @@ static const CRPCCommand commands[] =
{ "generating", "generatetoaddress", &generatetoaddress, {"nblocks","address","maxtries"} },
- { "util", "estimatefee", &estimatefee, {"nblocks"} },
+ { "hidden", "estimatefee", &estimatefee, {} },
{ "util", "estimatesmartfee", &estimatesmartfee, {"conf_target", "estimate_mode"} },
{ "hidden", "estimaterawfee", &estimaterawfee, {"conf_target", "threshold"} },