Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2018 The Bitcoin Core developers | // Copyright (c) 2009-2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <blockvalidity.h> | #include <blockvalidity.h> | ||||
#include <cashaddrenc.h> | |||||
#include <chain.h> | #include <chain.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <consensus/activation.h> | |||||
#include <consensus/consensus.h> | #include <consensus/consensus.h> | ||||
#include <consensus/params.h> | #include <consensus/params.h> | ||||
#include <consensus/validation.h> | #include <consensus/validation.h> | ||||
#include <core_io.h> | #include <core_io.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <miner.h> | #include <miner.h> | ||||
#include <minerfund.h> | |||||
#include <net.h> | #include <net.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <pow/pow.h> | #include <pow/pow.h> | ||||
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <script/script.h> | #include <script/script.h> | ||||
▲ Show 20 Lines • Show All 394 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
" \"coinbaseaux\" : { (json object) data that " | " \"coinbaseaux\" : { (json object) data that " | ||||
"should be included in the coinbase's scriptSig content\n" | "should be included in the coinbase's scriptSig content\n" | ||||
" \"flags\" : \"xx\" (string) key name is to " | " \"flags\" : \"xx\" (string) key name is to " | ||||
"be ignored, and value included in scriptSig\n" | "be ignored, and value included in scriptSig\n" | ||||
" },\n" | " },\n" | ||||
" \"coinbasevalue\" : n, (numeric) maximum allowable " | " \"coinbasevalue\" : n, (numeric) maximum allowable " | ||||
"input to coinbase transaction, including the generation award and " | "input to coinbase transaction, including the generation award and " | ||||
"transaction fees (in satoshis)\n" | "transaction fees (in satoshis)\n" | ||||
" \"coinbasetxn\" : { ... }, (json object) information " | " \"coinbasetxn\" : { (json object) information " | ||||
"for coinbase transaction\n" | "for coinbase transaction\n" | ||||
" \"minerfund\" : { (json object) information " | |||||
"related to the coinbase miner fund\n" | |||||
" \"addresses\" : [ ... ], (array) List of valid " | |||||
"addresses for the miner fund output\n" | |||||
" \"minimumvalue\" : n, (numeric) The minimum " | |||||
"value the miner fund output must pay\n" | |||||
" },\n" | |||||
" },\n" | |||||
" \"target\" : \"xxxx\", (string) The hash target\n" | " \"target\" : \"xxxx\", (string) The hash target\n" | ||||
" \"mintime\" : xxx, (numeric) The minimum " | " \"mintime\" : xxx, (numeric) The minimum " | ||||
"timestamp appropriate for next block time in seconds since epoch " | "timestamp appropriate for next block time in seconds since epoch " | ||||
"(Jan 1 1970 GMT)\n" | "(Jan 1 1970 GMT)\n" | ||||
" \"mutable\" : [ (array of string) list of " | " \"mutable\" : [ (array of string) list of " | ||||
"ways the block template may be changed \n" | "ways the block template may be changed \n" | ||||
" \"value\" (string) A way the block " | " \"value\" (string) A way the block " | ||||
"template may be changed, e.g. 'time', 'transactions', " | "template may be changed, e.g. 'time', 'transactions', " | ||||
"'prevblock'\n" | "'prevblock'\n" | ||||
Show All 13 Lines | RPCHelpMan{ | ||||
"next block\n" | "next block\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("getblocktemplate", "") + | RPCExamples{HelpExampleCli("getblocktemplate", "") + | ||||
HelpExampleRpc("getblocktemplate", "")}, | HelpExampleRpc("getblocktemplate", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CChainParams &chainparams = config.GetChainParams(); | |||||
std::string strMode = "template"; | std::string strMode = "template"; | ||||
UniValue lpval = NullUniValue; | UniValue lpval = NullUniValue; | ||||
std::set<std::string> setClientRules; | std::set<std::string> setClientRules; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
const UniValue &oparam = request.params[0].get_obj(); | const UniValue &oparam = request.params[0].get_obj(); | ||||
const UniValue &modeval = find_value(oparam, "mode"); | const UniValue &modeval = find_value(oparam, "mode"); | ||||
if (modeval.isStr()) { | if (modeval.isStr()) { | ||||
Show All 31 Lines | if (!request.params[0].isNull()) { | ||||
} | } | ||||
CBlockIndex *const pindexPrev = ::ChainActive().Tip(); | CBlockIndex *const pindexPrev = ::ChainActive().Tip(); | ||||
// TestBlockValidity only supports blocks built on the current Tip | // TestBlockValidity only supports blocks built on the current Tip | ||||
if (block.hashPrevBlock != pindexPrev->GetBlockHash()) { | if (block.hashPrevBlock != pindexPrev->GetBlockHash()) { | ||||
return "inconclusive-not-best-prevblk"; | return "inconclusive-not-best-prevblk"; | ||||
} | } | ||||
BlockValidationState state; | BlockValidationState state; | ||||
TestBlockValidity(state, config.GetChainParams(), block, pindexPrev, | TestBlockValidity(state, chainparams, block, pindexPrev, | ||||
BlockValidationOptions(config) | BlockValidationOptions(config) | ||||
.withCheckPoW(false) | .withCheckPoW(false) | ||||
.withCheckMerkleRoot(true)); | .withCheckMerkleRoot(true)); | ||||
return BIP22ValidationResult(config, state); | return BIP22ValidationResult(config, state); | ||||
} | } | ||||
} | } | ||||
if (strMode != "template") { | if (strMode != "template") { | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | if (pindexPrev != ::ChainActive().Tip() || | ||||
pindexPrev = pindexPrevNew; | pindexPrev = pindexPrevNew; | ||||
} | } | ||||
assert(pindexPrev); | assert(pindexPrev); | ||||
// pointer for convenience | // pointer for convenience | ||||
CBlock *pblock = &pblocktemplate->block; | CBlock *pblock = &pblocktemplate->block; | ||||
// Update nTime | // Update nTime | ||||
UpdateTime(pblock, config.GetChainParams(), pindexPrev); | UpdateTime(pblock, chainparams, pindexPrev); | ||||
pblock->nNonce = 0; | pblock->nNonce = 0; | ||||
UniValue aCaps(UniValue::VARR); | UniValue aCaps(UniValue::VARR); | ||||
aCaps.push_back("proposal"); | aCaps.push_back("proposal"); | ||||
Amount coinbasevalue = Amount::zero(); | Amount coinbasevalue = Amount::zero(); | ||||
UniValue transactions(UniValue::VARR); | UniValue transactions(UniValue::VARR); | ||||
Show All 26 Lines | for (const auto &it : pblock->vtx) { | ||||
transactions.push_back(entry); | transactions.push_back(entry); | ||||
index_in_template++; | index_in_template++; | ||||
} | } | ||||
UniValue aux(UniValue::VOBJ); | UniValue aux(UniValue::VOBJ); | ||||
aux.pushKV("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())); | aux.pushKV("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())); | ||||
UniValue minerFundList(UniValue::VARR); | |||||
const Consensus::Params &consensusParams = chainparams.GetConsensus(); | |||||
for (auto fundDestination : | |||||
GetMinerFundWhitelist(consensusParams, pindexPrev)) { | |||||
minerFundList.push_back(EncodeCashAddr(fundDestination, chainparams)); | |||||
} | |||||
int64_t minerFundMinValue = 0; | |||||
if (IsAxionEnabled(consensusParams, pindexPrev)) { | |||||
minerFundMinValue = | |||||
int64_t(GetMinerFundAmount(coinbasevalue) / SATOSHI); | |||||
} | |||||
UniValue minerFund(UniValue::VOBJ); | |||||
minerFund.pushKV("addresses", minerFundList); | |||||
minerFund.pushKV("minimumvalue", minerFundMinValue); | |||||
UniValue coinbasetxn(UniValue::VOBJ); | |||||
coinbasetxn.pushKV("minerfund", minerFund); | |||||
arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); | arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); | ||||
UniValue aMutable(UniValue::VARR); | UniValue aMutable(UniValue::VARR); | ||||
aMutable.push_back("time"); | aMutable.push_back("time"); | ||||
aMutable.push_back("transactions"); | aMutable.push_back("transactions"); | ||||
aMutable.push_back("prevblock"); | aMutable.push_back("prevblock"); | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("capabilities", aCaps); | result.pushKV("capabilities", aCaps); | ||||
result.pushKV("version", pblock->nVersion); | result.pushKV("version", pblock->nVersion); | ||||
result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex()); | result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex()); | ||||
result.pushKV("transactions", transactions); | result.pushKV("transactions", transactions); | ||||
result.pushKV("coinbaseaux", aux); | result.pushKV("coinbaseaux", aux); | ||||
result.pushKV("coinbasetxn", coinbasetxn); | |||||
result.pushKV("coinbasevalue", int64_t(coinbasevalue / SATOSHI)); | result.pushKV("coinbasevalue", int64_t(coinbasevalue / SATOSHI)); | ||||
result.pushKV("longpollid", ::ChainActive().Tip()->GetBlockHash().GetHex() + | result.pushKV("longpollid", ::ChainActive().Tip()->GetBlockHash().GetHex() + | ||||
i64tostr(nTransactionsUpdatedLast)); | i64tostr(nTransactionsUpdatedLast)); | ||||
result.pushKV("target", hashTarget.GetHex()); | result.pushKV("target", hashTarget.GetHex()); | ||||
result.pushKV("mintime", int64_t(pindexPrev->GetMedianTimePast()) + 1); | result.pushKV("mintime", int64_t(pindexPrev->GetMedianTimePast()) + 1); | ||||
result.pushKV("mutable", aMutable); | result.pushKV("mutable", aMutable); | ||||
result.pushKV("noncerange", "00000000ffffffff"); | result.pushKV("noncerange", "00000000ffffffff"); | ||||
result.pushKV("sigoplimit", | result.pushKV("sigoplimit", | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |